zoomy_core.mesh.lsq_mesh module

zoomy_core.mesh.lsq_mesh module#

LSQMesh — FVMMesh with precomputed least-squares reconstruction stencils.

This is the highest-fidelity mesh class: it caches the LSQ derivative operators so that compute_derivatives is a single matrix–vector product per cell instead of building the stencil on every call.

class zoomy_core.mesh.lsq_mesh.LSQMesh(**kwargs)#

Bases: FVMMesh

FVMMesh + precomputed LSQ derivative operators.

property lsq_gradQ#
property lsq_neighbors#
property lsq_boundary_face_neighbors#
property lsq_monomial_multi_index#
property lsq_scale_factors#
property face_neighbors#
compute_derivatives(u, degree=1, derivatives_multi_index=None, *, u_boundary_face)#

Compute derivatives using precomputed LSQ stencil.

Parameters:
  • u_boundary_face (ndarray | 'extrapolation') – Required. Either (n_boundary_faces,) array of face values (from a prescribed BC kernel), or the string 'extrapolation' for Neumann-zero / face = inner-cell. See zoomy_core.mesh.lsq_reconstruction.compute_derivatives() for the rationale: silent extrapolation was deprecated because it masks Dirichlet BCs as Neumann-zero.

  • u (ndarray) –

  • degree (int) –

Return type:

ndarray

derivative_operator(multi_index)#

Sparse-matrix realisation of the LSQ derivative stencil.

Returns a (n_inner_cells, n_inner_cells) sparse matrix D such that D @ u equals the cell-wise estimate of the derivative ∂^multi_index u — the same quantity compute_derivatives() produces for that multi_index, but as an explicit linear operator.

compute_derivatives applies the stencil to a known field; derivative_operator exposes the stencil itself, for assembling implicit / elliptic systems where the field is the unknown (e.g. the Chorin pressure-projection A·P = rhs, where ∂_xx P must enter the matrix, not be evaluated).

Per cell i the stencil is deriv[i] = Σ_j w_j·(u[nbr_j] u[i]) with w_j = sf[idx]·A_loc[j, idx] — so D[i, nbr_j] += w_j and D[i, i] -= w_j.

Parameters:

multi_index (tuple[int]) – Spatial-derivative orders per axis, e.g. (1,) for ∂_x or (2,) for ∂_xx in 1D — the same convention as compute_derivatives() and the aux_registry multi_index field.

Raises:

ValueError – If multi_index is not in the mesh’s monomial set — i.e. the mesh was built with too low an lsq_degree.

Return type:

csr_matrix

classmethod from_fvm(fvm)#

Build an LSQMesh shell from an FVMMesh, populating the LSQ stencil at degree 1 (the minimum that supports any derivative reconstruction).

The LSQ polynomial degree is not a hand-adjustable knob here — use zoomy_core.mesh.ensure_lsq_mesh(mesh, model)() for any solver setup, which sizes the stencil from the model’s NumericalSystemModel. This factory exists for low-level mesh construction; the degree is set by the model in the higher layers.

Parameters:

fvm (FVMMesh) –

Return type:

LSQMesh

classmethod from_msh(filepath)#

Load .msh and build FVMMesh with precomputed geometry.

Parameters:

filepath (str) –

Return type:

LSQMesh

classmethod from_hdf5(filepath)#

Load BaseMesh from H5 and compute geometry.

Parameters:

filepath (str) –

Return type:

LSQMesh

classmethod create_1d(domain, n_inner_cells)#

Build a uniform 1D interval mesh.

Parameters:
  • domain (tuple) –

  • n_inner_cells (int) –

Return type:

LSQMesh

classmethod create_2d(domain, nx, ny)#

Build a uniform 2D quad mesh.

Parameters:
  • domain ((x_min, x_max, y_min, y_max)) –

  • nx (number of inner cells in x and y directions) –

  • ny (number of inner cells in x and y directions) –

Return type:

LSQMesh

classmethod create_3d(domain, nx, ny, nz)#

Build a uniform 3D hexahedral mesh.

Parameters:
  • domain ((x_min, x_max, y_min, y_max, z_min, z_max)) –

  • nx (number of inner cells in each direction) –

  • ny (number of inner cells in each direction) –

  • nz (number of inner cells in each direction) –

Return type:

LSQMesh

name = 'LSQMesh'#