Skip to content

Conversation

@lmoresi
Copy link
Member

@lmoresi lmoresi commented Nov 18, 2025

The full release of UW3 should be at 3.0 ... when we do this, I would like to introduce some new coding patterns that are more conducive to the having and AI-bot (AI-Bat ?) give advice.

So that means there is a lot to review in here.

lmoresi and others added 30 commits August 8, 2025 20:45
Wrapper function for the access manager to improve usability
Minor deetails.
Attempting to fix up the evaluation to be internally consistent, adding the wrappers for the access manager (and calling it `array` for now).

Fix up tests to account for changes to evaluation array sizes on return (mostly squeezes)

Fix a couple of other evaluation bugs (like the need to add a zero vector to some nearly-constant matrices).

Repairing the quickstart guide here and there.
Fix for the first comment by @jcgraciosa.

Also needed to update the JIT code to understand the MATRIX variable type and removing the other types that are (currently) not used. These cause compilation errors if they are lit up by mistake (even if that variable is not in any expression).

Solvers: Navier Stokes / Advection-Diffusion - fix the projection terms and how they pack up their data.
Adding global evaluation routines to compute values anywhere in the distributed domain (also with extrapolation using rbf)
Fixing broken test (array shape)
Not setting initial rank - this has problems when the particle is located on the correct rank because it automatically, always gets migrated to rank 0 and we start hunting for it again (but always in the wrong place).
Missed one !
Nodal Point Swarm also had the issue of uninitialised rank. This causes particles on rank > 1 to be migrated to rank 0 on the first call to migrate. They then get lost ...

Potential fix @jcgraciosa but maybe not the only issue here.
Fixing lack of rank initialisation in swarm.populate.

Also: some changes to the derivative expressions code:
  - .where relevant sym returns the inner expression derived by the diff_variable inner expression in symbolic form (which is closer to the intent of .sym) and does not return the evaluated form.
  - .doit function returns the evaluated form (so this is like the sympy deferred derivative).
This code is *probably* no longer needed
And leaving NodalPointPICSwarm alone
Shortening some monster-sized files.
Imports etc should not change
…t in a more user friendly form attached to the swarm
lmoresi and others added 30 commits January 9, 2026 14:16
Lightweight binder configuration that bootstraps pixi in postBuild:
- requirements.txt: Minimal bootstrap (empty)
- postBuild: Installs pixi, runtime environment, builds uw3, registers kernel
- start: Activates pixi environment before Jupyter sessions

This avoids slow conda petsc builds by using pixi's fast resolver.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The symlink pointed to non-existent LICENCE.md, causing Docker
build failures on mybinder.org.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
MyBinder launches will use the separate uw-demo-launcher repository
which has pre-built conda environments for faster startup.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit updates ~45 example files to use the modern coordinate
access patterns:

- mesh.data → mesh.X.coords (deprecated coordinate access)
- var.data with mesh.data indexing → var.data with var.coords
- Removed unnecessary mesh.access() wrappers where safe

Key changes:
- Use var.coords for DOF coordinates (works for all element degrees)
- Use mesh.X.coords for mesh vertex coordinates
- Direct .data/.array access without access context manager

Note: Some mesh.access() patterns with multiple variables remain
for future review with uw.synchronised_array_update().

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Part of the migration to simplified data access patterns:
- Removed mesh.access() wrappers for single-variable assignments
- Removed empty mesh.access() wrappers (read-only patterns)
- Added TODO comments for multi-variable patterns to consider
  uw.synchronised_array_update()
- Added TODO comments for complex patterns requiring review

The access manager is no longer required for basic data operations.
Multi-variable synchronisation may still benefit from the new
uw.synchronised_array_update() context manager.

Files updated: 20 examples across heat_transfer, fluid_mechanics,
porous_flow, solid_mechanics, utilities, and free_surface categories.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Continue removing deprecated access manager patterns from examples:
- Single variable swarm.access(var): remove wrapper
- Empty swarm.access() for read: remove wrapper
- Multi-variable patterns: add TODO comment for uw.synchronised_array_update()

Affected patterns across 15 files:
- Material initialization with swarm data
- Visualization code reading material.data.copy()
- Particle coordinate updates (manual advection)
- Swarm-based function evaluation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit completes the migration away from deprecated access patterns:

Examples fixed (25 files):
- Removed with mesh.access() and swarm.access() wrappers
- Added TODO comments for multi-variable patterns
- Fixed mesh.data → mesh.X.coords for coordinate access
- Fixed meshbox.data → meshbox.X.coords deprecation

CLAUDE.md updates:
- Added "Access Context Managers NOT Required" section
- Documented deprecated vs current patterns
- Added coordinate access examples (mesh.X.coords, var.coords)
- Clarified swarm.data access patterns

Files modified:
- 14 main example files (fluid_mechanics, free_surface, porous_flow, utilities)
- 11 WIP/developer_tools files
- CLAUDE.md documentation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add 7 portable slash commands with relative paths for version control
- Simplify Data Access Patterns in CLAUDE.md to reference style guide
- Update .gitignore to track .claude/commands/*.md files
- Commands: check-patterns, test-units, test-solvers, test-regression,
  test-tier-a, test-tier-ab, test-units-classify

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add NumPy/Sphinx docstrings to 16 SNES solver properties:
  - SNES_Stokes: strainrate, stress, bodyforce, penalty, etc.
  - SNES_Poisson: f (source term)
  - SNES_AdvectionDiffusion: f, V_fn, delta_t
- Add "Docstring Health Checks" section to /check-patterns command
- Regenerate docstring inventory (159→143 undocumented)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- ViscousFlowModel: Add Parameters, Attributes, Examples, See Also
- ViscoPlasticFlowModel: Add Parameters, Attributes, Notes, See Also
- DiffusionModel: Add Parameters, Attributes, Examples, See Also
- DarcyFlowModel: Add Parameters, Attributes, Examples, See Also
- Constitutive_Model base: Add docstrings to Unknowns, K, u, grad_u, DuDt

Docstring coverage: 143→139 undocumented, 63→68 partial

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Mesh properties (discretisation_mesh.py):
- dim, cdim, element: Add Returns sections
- N, Gamma_N, Gamma: Add coordinate system docs
- X, r, rvec: Add coordinate access docs

Swarm properties (swarm.py):
- local_size, data, vars: Add Returns sections
- SwarmVariable.sym, sym_1d: Add symbolic representation docs

Docstring coverage (mesh/swarm files): 47→41 undocumented, 91→104 partial

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Full docstrings for cylindrical coordinate methods (divergence, gradient, curl, strain_tensor)
- Full docstrings for spherical coordinate methods
- Full docstrings for 2D spherical surface methods
- Enhanced class docstrings with Parameters and Notes sections
- Fixed incorrect deprecation message in swarm.data (was incorrectly referencing swarm variable data)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- UWDerivativeExpression: Parameters, Examples, Returns
- simplify_units: Parameters, Returns
- is_constant_expr: Parameters, Returns
- extract_expressions: Parameters, Returns
- extract_expressions_and_functions: Parameters, Returns

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- divergence, gradient, curl, jacobian: Vector calculus methods
- clone: Create copy with new name/symbol
- rbf_interpolate: RBF interpolation to new coordinates

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Properties: mesh, data, particle_coordinates, particle_cellid, vars
- Methods: read_timestep, add_variable, advection (both classes)
- All include Parameters and Returns sections

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Module docstring added
- initialise: PyVista initialization
- mesh_to_pv_mesh: Mesh conversion
- coords_to_pv_coords, swarm_to_pv_cloud: Coordinate conversions
- meshVariable_to_pv_cloud/mesh_object: Variable visualization
- scalar_fn_to_pv_points, vector_fn_to_pv_points: Function evaluation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Adds brief docstrings to setter methods across solver classes:
- SNES_Projection: smoothing, uw_weighting_function
- SNES_Vector_Projection: smoothing, penalty, uw_weighting_function
- SNES_Tensor_Projection: uw_scalar_function
- SNES_AdvectionDiffusion: f, delta_t
- SNES_Diffusion: f, delta_t (with property docstrings)
- SNES_NavierStokes: delta_t, rho, f, DuDt, DFDt, constraints,
  bodyforce, saddle_preconditioner, penalty

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Adds brief docstrings to:
- problem_description methods (poisson, darcy, stokes, projection,
  advection-diffusion, navier_stokes)
- F0/F1/PF0 template properties for FEM assembly
- Getter properties (smoothing, penalty, uw_weighting_function,
  delta_t, div_u, strainrate, uw_scalar_function)
- SNES_Tensor_Projection.solve method

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Documents that the symmetric strain rate tensor includes the 1/2 factor:
ε_ij = (1/2)(∂u_i/∂x_j + ∂u_j/∂x_i)

This clarifies the convention used, which is important since some codes
omit the 1/2 factor.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Phase 1 of the docstring audit covering:

constitutive_models.py:
- DarcyFlowModel: s property getter/setter, K property
- TransverseIsotropicFlowModel: grad_u property with math formula
- GenericFluxModel: flux property getter/setter
- AnisotropicDiffusionModel: diffusivity getter/setter
- Various validate_parameters and setter methods

systems/ddt.py:
- Symbolic class: psi_fn getter/setter, update methods, adams_moulton_flux
- Eulerian class: all public methods with consistent docstrings
- SemiLagrangian class: update methods, bdf, adams_moulton_flux
- Lagrangian and Lagrangian_Swarm: update methods and flux approximations

swarm.py:
- SwarmVariable.rbf_interpolate method with full parameter documentation

All docstrings follow NumPy format with RST math notation where
appropriate, documenting mathematical formulas for strain rate
tensors, BDF schemes, and Adams-Moulton flux approximations.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Phase 2 docstring additions for coordinates module:

CoordinateSystem class:
- X, x, N, R, r, xR coordinate properties with brief descriptions
- rRotN, xRotN rotation matrix properties with math notation
- unit_e_0/1/2 natural basis vectors with math notation
- unit_i/j/k Cartesian basis vectors
- unit_ijk method

All properties now have one-liner docstrings clarifying their purpose
and relationship to the coordinate system geometry.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…solvers)

- _function.pyx: UnderworldAppliedFunction, UnderworldAppliedFunctionDeriv,
  dm_swarm_get/set_migrate_type, fdiff methods (as SymPy protocol methods)
- ckdtree.pyx: n, ndim properties, rbf_interpolator_local method
- petsc_maths.pyx: Fixed CellWiseIntegral docstring, added evaluate docstring
- petsc_generic_snes_solvers.pyx: _Unknowns class and properties (u, DuDt,
  DFDt, E, L, W, Einv2), solver properties (u, DuDt, DFDt, constitutive_model),
  improved BC method docstrings (add_dirichlet_bc, add_natural_bc, add_essential_bc)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
IndexSwarmVariable:
- sym_1d: One-dimensional symbolic mask array property
- createMask: Create material-weighted symbolic expressions (improved)
- viewMask: Decompose masked expressions (noted as not implemented)
- visMask: Create visualization mask showing material indices

Swarm:
- clip_to_mesh: Property for particle clipping control

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
MeshVariable (discretisation_mesh_variables.py):
- .sym: Symbolic representation for equations with examples
- .array: Primary data interface with shape/unit documentation
- .data: Canonical storage explaining when to use vs .array
- .coords: DOF coordinates with unit handling explanation

SwarmVariable (swarm.py):
- .data: Canonical storage with variable transfer guidance
- .array: Primary particle data interface with examples

CoordinateSystem (coordinates.py):
- mesh.X: Comprehensive symbolic/numerical access documentation
- mesh.X.coords: Mesh vertex coordinates with examples
- mesh.X.units: Physical coordinate units

These docstrings clarify the three-domain access pattern:
- Symbolic (.sym) for equations
- Numerical (.array/.data) for data manipulation
- Coordinate (.coords) for spatial positions

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- SNES_Scalar.solve(): Parameters, examples, collective operation note
- SNES_Vector.solve(): Parameters, return docs, see-also references
- SNES_Stokes_SaddlePt.solve(): Picard iteration docs, nonlinear usage examples

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- SNES_Scalar.tolerance: Explains auto-config of snes_rtol, ksp_rtol, ksp_atol
- SNES_Vector.tolerance: Same documentation pattern
- SNES_Stokes_SaddlePt.tolerance: Documents fieldsplit tolerances and EW adaptive
- SNES_Stokes_SaddlePt.strategy: Documents preconditioner strategy options
- SNES_Stokes_SaddlePt.PF0: Pressure constraint term (incompressibility)
- SNES_Stokes_SaddlePt.p: Pressure solution variable
- SNES_Stokes_SaddlePt.saddle_preconditioner: Custom Schur complement preconditioner

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- add_essential_bc: Scalar/vector/symbolic examples, See Also references
- add_natural_bc: Flux and traction examples, mathematical notes
- add_dirichlet_bc: Common patterns (no-slip, free-slip, lid-driven cavity)
- All methods: Case-sensitive boundary name warnings, Raises section

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Documents the common pattern for free-slip boundary conditions on
curved surfaces (spherical models) using penalty method with mesh.Gamma
surface normal vector.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- SNES_Scalar: Parameters, Attributes, Examples, See Also sections
- SNES_Vector: Parameters, Attributes, Examples, See Also sections
- SNES_Stokes_SaddlePt: Parameters, Attributes, Examples, See Also sections

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Enhanced docstrings for all five time history manager classes:
- Symbolic: Purely symbolic history manager for understanding BDF/AM formulas
- Eulerian: Mesh-based history for fixed-grid time-stepping
- SemiLagrangian: Nodal-swarm approach for advection-dominated problems
- Lagrangian: Full material tracking with internal swarm management
- Lagrangian_Swarm: User-provided swarm variant with step averaging

Each docstring now includes Parameters, Attributes, Notes, and See Also
sections following NumPy docstring conventions.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants