Weighted least-squares gradient method for structured and unstructured grids.
More...
This class implements a least-squares gradient reconstruction for use on both structured and unstructured grids. For each cell, it precomputes and caches a gradient reconstruction matrix using the Moore-Penrose pseudoinverse, based on the geometry and connectivity of the mesh. The operator is created once during initialization and can then be efficiently applied to any scalar field to compute the gradient in each cell. The gradient can then be computed by multiplying the reconstruction matrix with the difference vector. ∇ɸ = R * ∑(ɸ_i - ɸ_up), where i are the neighboring cells.
Usage:
- Create the gradient object with the discretization
- Set the scalar field using
set_field(phi)
where phi is the field for which gradients are computed
- Retrieve gradients for any cell using the
get(n)
method
- The gradient operator is constructed using normalized direction vectors between cell centers, scaled by the inverse of the distance.
- The least-squares approach ensures robust gradients even for irregular or rank-deficient stencils.
- The operator is cached for each cell, so gradient computation is efficient for repeated queries.
- The
set_field
method establishes a pointer to the scalar field data.
- The
get
method computes the gradient for any cell using the current scalar field.
- Note
- Boundary cells are not handled in a special manner. This may impact the quality of the gradient near boundaries, especially if a cell does not have enough neighbors (fewer than three in 3D).
Definition at line 43 of file LeastSquaresGradient.f90.