#include <petsc.h>#include "variables.h"#include "logging.h"#include <stdlib.h>#include "io.h"#include "setup.h"Go to the source code of this file.
Data Structures | |
| struct | FacePlaneArrays |
| Read-only flat arrays of one family of face planes (grid cells or dual cells). More... | |
Typedefs | |
| typedef struct FacePlaneArrays | FacePlaneArrays |
| Read-only flat arrays of one family of face planes (grid cells or dual cells). | |
Functions | |
| PetscErrorCode | MetricLogicalToPhysical (UserCtx *user, const Cmpnts ***X, PetscInt i, PetscInt j, PetscInt k, PetscReal xi, PetscReal eta, PetscReal zta, Cmpnts *Xp) |
| Maps a logical point inside one hexahedral cell to physical space. | |
| PetscErrorCode | MetricGetCellVertices (UserCtx *user, const Cmpnts ***X, PetscInt i, PetscInt j, PetscInt k, Cmpnts V[8]) |
| Collects the eight node coordinates of one logical hexahedral cell. | |
| PetscErrorCode | MetricJacobian (UserCtx *user, const Cmpnts ***X, PetscInt i, PetscInt j, PetscInt k, PetscReal xi, PetscReal eta, PetscReal zta, PetscReal J[3][3], PetscReal *detJ) |
| Evaluates the trilinear mapping Jacobian and its determinant in one cell. | |
| PetscErrorCode | MetricVelocityContravariant (const PetscReal J[3][3], PetscReal detJ, const PetscReal u[3], PetscReal uc[3]) |
| Converts a Cartesian velocity vector to contravariant logical components. | |
| static Cmpnts | RemoveFaceNormalComponent (Cmpnts velocity, Cmpnts metric) |
velocity less its component along the face metric metric, which leaves it tangent to the face. | |
| PetscErrorCode | CalculateFaceNormalAndArea (Cmpnts csi, Cmpnts eta, Cmpnts zet, double ni[3], double nj[3], double nk[3], double *Ai, double *Aj, double *Ak) |
| Computes the unit normal vectors and areas of the three faces of a computational cell. | |
| PetscErrorCode | InvertCovariantMetricTensor (double covariantTensor[3][3], double contravariantTensor[3][3]) |
| Inverts the 3x3 matrix of face-area vectors to obtain the covariant directions. | |
| PetscErrorCode | ComputeCellCharacteristicLengthScale (PetscReal ajc, Cmpnts csi, Cmpnts eta, Cmpnts zet, double *dx, double *dy, double *dz) |
| Computes characteristic length scales (dx, dy, dz) for a curvilinear cell. | |
| PetscErrorCode | ComputeCellDirectionalExtents (PetscReal ajc, Cmpnts csi, Cmpnts eta, Cmpnts zet, double *l_xi, double *l_eta, double *l_zeta) |
| Computes a cell's extent along each of its own grid directions. | |
| PetscErrorCode | ComputeCellEdgeVectors (PetscReal ajc, Cmpnts csi, Cmpnts eta, Cmpnts zet, Cmpnts edges[3]) |
| Computes a cell's edge vectors along its three grid directions. | |
| PetscErrorCode | ApplyPeriodicCorrectionsToCellCenters (UserCtx *user) |
| Builds translated periodic images for the dummy cell centers of periodic axes. | |
| PetscErrorCode | ApplyPeriodicCorrectionsToIFaceCenter (UserCtx *user) |
| Builds translated periodic images for i-face centers (Centx). | |
| PetscErrorCode | ApplyPeriodicCorrectionsToJFaceCenter (UserCtx *user) |
| Builds translated periodic images for j-face centers (Centy). | |
| PetscErrorCode | ApplyPeriodicCorrectionsToKFaceCenter (UserCtx *user) |
| Builds translated periodic images for k-face centers (Centz). | |
| PetscErrorCode | ComputeFaceMetrics (UserCtx *user) |
| Computes the primary face metric components (Csi, Eta, Zet), including boundary extrapolation, and stores them in the corresponding global Vec members of the UserCtx structure (user->Csi, user->Eta, user->Zet). | |
| PetscErrorCode | ComputeCellCenteredJacobianInverse (UserCtx *user) |
Calculates the cell-centered inverse Jacobian determinant (1/J) for INTERIOR cells and stores it in user->Aj. | |
| PetscErrorCode | CheckAndFixGridOrientation (UserCtx *user) |
Verify and, when consistently inverted, repair the right-handed metric basis (Csi, Eta, Zet) and a positive Jacobian (Aj) over the whole domain. | |
| PetscErrorCode | ComputeCellCenters (UserCtx *user) |
| Computes the physical location of each cell's center from the nodal coordinates. | |
| PetscErrorCode | ComputeGridLineFractions (UserCtx *user, Vec fraction, Vec length) |
| Arc-length position of every owned cell centre along its three grid lines. | |
| PetscErrorCode | ComputeIFaceMetrics (UserCtx *user) |
| Computes metrics centered on constant-i faces (i-faces). | |
| PetscErrorCode | ComputeJFaceMetrics (UserCtx *user) |
| Computes metrics centered on constant-j faces (j-faces). | |
| PetscErrorCode | ComputeKFaceMetrics (UserCtx *user) |
| Computes metrics centered on constant-k faces (k-faces). | |
| PetscErrorCode | ComputeMetricsDivergence (UserCtx *user) |
| Performs a diagnostic check on the divergence of the face area metric vectors. | |
| PetscErrorCode | ComputeMetricNorms (UserCtx *user) |
| Computes the max-min values of the grid metrics. | |
| PetscErrorCode | CalculateAllGridMetrics (SimCtx *simCtx) |
| Orchestrates the calculation of all grid metrics. | |
| PetscBool | MetricFacePlane (const Cmpnts v1, const Cmpnts v2, const Cmpnts v3, const Cmpnts v4, const Cmpnts cell_centroid, FacePlane *plane, PetscBool *degenerate) |
| Builds one face plane: the unit outward normal of (v2 - v1) x (v4 - v1) and the vertex mean. | |
| void | MetricBuildCellFacePlanes (const Cell *cell, CellFacePlanes *planes) |
| Builds the six face planes of a hexahedron, as the particle search tests them. | |
| PetscErrorCode | MetricComputeFacePlanes (UserCtx *user) |
| Builds the block's particle face planes once, as catalogued per-face fields. | |
| PetscErrorCode | MetricDestroyFacePlanes (UserCtx *user) |
| Frees the face-plane fields MetricComputeFacePlanes() built, if any. | |
| PetscErrorCode | MetricGetFacePlaneArrays (UserCtx *user, PetscBool dual, FacePlaneArrays *arrays) |
| Opens a family's face-plane arrays for reading; MetricComputeFacePlanes() must have run. | |
| PetscErrorCode | MetricRestoreFacePlaneArrays (UserCtx *user, FacePlaneArrays *arrays) |
| Closes arrays opened by MetricGetFacePlaneArrays(). | |
| void | MetricGatherCellFacePlanes (const FacePlaneArrays *arrays, const DMDALocalInfo *info, PetscInt i, PetscInt j, PetscInt k, CellFacePlanes *planes) |
| Assembles one cell's six outward face planes from the shared per-face planes. | |
| static PetscInt | MetricCellFacePlanesIndex (const DMDALocalInfo *info, PetscInt i, PetscInt j, PetscInt k) |
| Index of point (i, j, k) in a block's ghosted local arrays (coordinates, lCent, planes). | |
| struct FacePlaneArrays |
Read-only flat arrays of one family of face planes (grid cells or dual cells).
| Data Fields | ||
|---|---|---|
| PetscBool | dual | Dual-cell planes (from lCent) rather than grid-cell planes. |
| const Cmpnts * | normal[3] | Unit normals toward +i, +j, +k; zero where there is no plane. |
| const Cmpnts * | centroid[3] | Face vertex means. |
| const PetscReal * | size | Grid-cell sizes; NULL for dual cells. |
| typedef struct FacePlaneArrays FacePlaneArrays |
Read-only flat arrays of one family of face planes (grid cells or dual cells).
| PetscErrorCode MetricLogicalToPhysical | ( | UserCtx * | user, |
| const Cmpnts *** | X, | ||
| PetscInt | i, | ||
| PetscInt | j, | ||
| PetscInt | k, | ||
| PetscReal | xi, | ||
| PetscReal | eta, | ||
| PetscReal | zta, | ||
| Cmpnts * | Xp | ||
| ) |
Maps a logical point inside one hexahedral cell to physical space.
Uses trilinear interpolation of the eight cell vertices. Logical coordinates are measured from the cell's lower logical corner and normally lie in [0, 1].
| user | Grid context used for cell indexing. | |
| X | Ghosted node-coordinate array for the block. | |
| i | Cell index in the xi direction. | |
| j | Cell index in the eta direction. | |
| k | Cell index in the zeta direction. | |
| xi | Local xi coordinate within the cell. | |
| eta | Local eta coordinate within the cell. | |
| zta | Local zeta coordinate within the cell. | |
| [out] | Xp | Physical Cartesian position evaluated at the logical point. |
Maps a logical point inside one hexahedral cell to physical space.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/Metric.h.
Definition at line 475 of file Metric.c.
| PetscErrorCode MetricGetCellVertices | ( | UserCtx * | user, |
| const Cmpnts *** | X, | ||
| PetscInt | i, | ||
| PetscInt | j, | ||
| PetscInt | k, | ||
| Cmpnts | V[8] | ||
| ) |
Collects the eight node coordinates of one logical hexahedral cell.
Vertex ordering matches the trilinear metric kernels in this module.
| user | Grid context used for cell indexing. | |
| X | Ghosted node-coordinate array for the block. | |
| i | Cell index in the xi direction. | |
| j | Cell index in the eta direction. | |
| k | Cell index in the zeta direction. | |
| [out] | V | Eight physical vertex coordinates in metric-kernel order. |
Collects the eight node coordinates of one logical hexahedral cell.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/Metric.h.
Definition at line 24 of file Metric.c.
| PetscErrorCode MetricJacobian | ( | UserCtx * | user, |
| const Cmpnts *** | X, | ||
| PetscInt | i, | ||
| PetscInt | j, | ||
| PetscInt | k, | ||
| PetscReal | xi, | ||
| PetscReal | eta, | ||
| PetscReal | zta, | ||
| PetscReal | J[3][3], | ||
| PetscReal * | detJ | ||
| ) |
Evaluates the trilinear mapping Jacobian and its determinant in one cell.
The returned matrix is \(\partial(x,y,z)/\partial(\xi,\eta,\zeta)\); callers use its determinant to reject degenerate or inverted cells.
| user | Grid context used for cell indexing. | |
| X | Ghosted node-coordinate array for the block. | |
| i | Cell index in the xi direction. | |
| j | Cell index in the eta direction. | |
| k | Cell index in the zeta direction. | |
| xi | Local xi coordinate within the cell. | |
| eta | Local eta coordinate within the cell. | |
| zta | Local zeta coordinate within the cell. | |
| [out] | J | Mapping Jacobian in row-major Cartesian/logical form. |
| [out] | detJ | Determinant of J. |
Evaluates the trilinear mapping Jacobian and its determinant in one cell.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/Metric.h.
Definition at line 502 of file Metric.c.
| PetscErrorCode MetricVelocityContravariant | ( | const PetscReal | J[3][3], |
| PetscReal | detJ, | ||
| const PetscReal | u[3], | ||
| PetscReal | uc[3] | ||
| ) |
Converts a Cartesian velocity vector to contravariant logical components.
Uses the inverse of the physical-to-logical Jacobian; detJ must describe the same mapping as J and must be nonzero.
| J | Mapping Jacobian at the evaluation point. | |
| detJ | Determinant of J. | |
| u | Cartesian velocity components. | |
| [out] | uc | Contravariant xi/eta/zeta velocity components. |
Converts a Cartesian velocity vector to contravariant logical components.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/Metric.h.
Definition at line 560 of file Metric.c.
velocity less its component along the face metric metric, which leaves it tangent to the face.
A face of zero area has no normal, and velocity is returned unchanged. Shared by the boundary handlers and the wall model, which both need the wall-parallel part of a velocity on a curvilinear face.
| velocity | Velocity to project. |
| metric | The face's area vector (any length, any orientation). |
velocity. Definition at line 99 of file Metric.h.
| PetscErrorCode CalculateFaceNormalAndArea | ( | Cmpnts | csi, |
| Cmpnts | eta, | ||
| Cmpnts | zet, | ||
| double | ni[3], | ||
| double | nj[3], | ||
| double | nk[3], | ||
| double * | Ai, | ||
| double * | Aj, | ||
| double * | Ak | ||
| ) |
Computes the unit normal vectors and areas of the three faces of a computational cell.
Given the metric vectors (csi, eta, zet), this function calculates the geometric properties of the cell faces aligned with the i, j, and k directions.
| csi | Covariant xi metric vector. | |
| eta | Covariant eta metric vector. | |
| zet | Covariant zeta metric vector. | |
| [out] | ni | Unit normal of the xi-normal face. |
| [out] | nj | Unit normal of the eta-normal face. |
| [out] | nk | Unit normal of the zeta-normal face. |
| [out] | Ai | Area of the xi-normal face. |
| [out] | Aj | Area of the eta-normal face. |
| [out] | Ak | Area of the zeta-normal face. |
Computes the unit normal vectors and areas of the three faces of a computational cell.
Definition at line 644 of file Metric.c.
| PetscErrorCode InvertCovariantMetricTensor | ( | double | covariantTensor[3][3], |
| double | contravariantTensor[3][3] | ||
| ) |
Inverts the 3x3 matrix of face-area vectors to obtain the covariant directions.
The caller fills the rows with csi, eta and zet - the face-area vectors, which are the contravariant basis scaled by the cell Jacobian. The inverse's columns are the covariant (tangent) directions dx/dxi, dx/deta, dx/dzeta divided by that Jacobian, which is what CalculateFaceNormalAndArea() normalizes.
Degeneracy is judged relative to the rows' own magnitude, because the determinant of area vectors scales as the square of the cell volume: an absolute floor would reject a well-formed cell purely for being small.
| covariantTensor | Input: rows are the three face-area vectors. | |
| [out] | contravariantTensor | Inverse written in place. |
PETSC_ERR_MAT_LU_ZRPVT when the rows are coplanar or one of them vanishes.Inverts the 3x3 matrix of face-area vectors to obtain the covariant directions.
Definition at line 595 of file Metric.c.
| PetscErrorCode ComputeCellCharacteristicLengthScale | ( | PetscReal | ajc, |
| Cmpnts | csi, | ||
| Cmpnts | eta, | ||
| Cmpnts | zet, | ||
| double * | dx, | ||
| double * | dy, | ||
| double * | dz | ||
| ) |
Computes characteristic length scales (dx, dy, dz) for a curvilinear cell.
For a non-uniform, non-orthogonal cell, there is no single "dx". This function computes an effective length scale in each Cartesian direction based on the cell volume and the areas of its faces: the three outputs are the Cartesian components of the cell diagonal, so they change when an otherwise identical cell is rotated. Use ComputeCellDirectionalExtents for a measure of the cell itself.
| ajc | Cell Jacobian/volume metric at the cell center. | |
| csi | Covariant xi metric vector. | |
| eta | Covariant eta metric vector. | |
| zet | Covariant zeta metric vector. | |
| [out] | dx | Effective physical length associated with xi variation. |
| [out] | dy | Effective physical length associated with eta variation. |
| [out] | dz | Effective physical length associated with zeta variation. |
Computes characteristic length scales (dx, dy, dz) for a curvilinear cell.
Definition at line 688 of file Metric.c.
| PetscErrorCode ComputeCellDirectionalExtents | ( | PetscReal | ajc, |
| Cmpnts | csi, | ||
| Cmpnts | eta, | ||
| Cmpnts | zet, | ||
| double * | l_xi, | ||
| double * | l_eta, | ||
| double * | l_zeta | ||
| ) |
Computes a cell's extent along each of its own grid directions.
Each extent is the cell volume divided by the area of the face pair it crosses, which is the distance between those two faces. Unlike ComputeCellCharacteristicLengthScale, whose outputs are the Cartesian components of the cell diagonal and so change when the same cell is rotated, these depend on the cell alone: a filter width built from them is the same for a cell in a straight section and for an identical cell turned by a bend.
| ajc | Inverse cell volume at the cell center. | |
| csi | Face-area vector of the xi faces. | |
| eta | Face-area vector of the eta faces. | |
| zet | Face-area vector of the zeta faces. | |
| [out] | l_xi | Extent across the xi faces. |
| [out] | l_eta | Extent across the eta faces. |
| [out] | l_zeta | Extent across the zeta faces. |
PETSC_ERR_ARG_OUTOFRANGE for a non-positive Jacobian or a face of zero area.Computes a cell's extent along each of its own grid directions.
Full API contract is documented with the header declaration in include/Metric.h.
Definition at line 717 of file Metric.c.
| PetscErrorCode ComputeCellEdgeVectors | ( | PetscReal | ajc, |
| Cmpnts | csi, | ||
| Cmpnts | eta, | ||
| Cmpnts | zet, | ||
| Cmpnts | edges[3] | ||
| ) |
Computes a cell's edge vectors along its three grid directions.
Each is the covariant basis vector dx/dxi_k over one index step: the physical displacement from one cell to the next along that grid line, with both its direction and its length. Projecting a velocity gradient onto it gives the change in velocity across the cell in that direction, which is what a direction-resolved subgrid model needs and what does not depend on how the grid is oriented.
| ajc | Inverse cell volume at the cell center. | |
| csi | Face-area vector of the xi faces. | |
| eta | Face-area vector of the eta faces. | |
| zet | Face-area vector of the zeta faces. | |
| [out] | edges | Edge vectors along xi, eta and zeta, in that order. |
PETSC_ERR_ARG_OUTOFRANGE for a non-positive Jacobian.Computes a cell's edge vectors along its three grid directions.
Full API contract is documented with the header declaration in include/Metric.h.
Definition at line 749 of file Metric.c.
| PetscErrorCode ApplyPeriodicCorrectionsToCellCenters | ( | UserCtx * | user | ) |
Builds translated periodic images for the dummy cell centers of periodic axes.
PETSc wraps field indices but does not translate coordinates. This routine sets the dummy slot before the first cell of each periodic axis to the last cell's center minus the validated seam translation, and the slot after the last cell to the first cell's center plus it, axis by axis with a ghost refresh in between, so edge and corner dummies carry the translation of every periodic axis they cross. Grid spacing is not modified.
| user | The UserCtx containing grid and field data. |
Builds translated periodic images for the dummy cell centers of periodic axes.
Definition at line 831 of file Metric.c.
| PetscErrorCode ApplyPeriodicCorrectionsToIFaceCenter | ( | UserCtx * | user | ) |
Builds translated periodic images for i-face centers (Centx).
Every active periodic axis can affect the ghost images of Centx. This must be called after Centx is computed and before it is used for metric calculations.
| user | The UserCtx containing grid and field data. |
Builds translated periodic images for i-face centers (Centx).
Definition at line 890 of file Metric.c.
| PetscErrorCode ApplyPeriodicCorrectionsToJFaceCenter | ( | UserCtx * | user | ) |
Builds translated periodic images for j-face centers (Centy).
Every active periodic axis can affect the ghost images of Centy. This must be called after Centy is computed and before it is used for metric calculations.
| user | The UserCtx containing grid and field data. |
Builds translated periodic images for j-face centers (Centy).
Definition at line 906 of file Metric.c.
| PetscErrorCode ApplyPeriodicCorrectionsToKFaceCenter | ( | UserCtx * | user | ) |
Builds translated periodic images for k-face centers (Centz).
Every active periodic axis can affect the ghost images of Centz. This must be called after Centz is computed and before it is used for metric calculations.
| user | The UserCtx containing grid and field data. |
Builds translated periodic images for k-face centers (Centz).
Definition at line 922 of file Metric.c.
| PetscErrorCode ComputeFaceMetrics | ( | UserCtx * | user | ) |
Computes the primary face metric components (Csi, Eta, Zet), including boundary extrapolation, and stores them in the corresponding global Vec members of the UserCtx structure (user->Csi, user->Eta, user->Zet).
This is a self-contained routine that performs the following steps:
user->Csi, user->Eta, user->Zet Vecs.user->lCsi, user->lEta, user->lZet Vecs.| [in,out] | user | Pointer to the UserCtx structure. |
VecZeroEntries on user->Csi, Eta, Zet before this if they might contain old data.Computes the primary face metric components (Csi, Eta, Zet), including boundary extrapolation, and stores them in the corresponding global Vec members of the UserCtx structure (user->Csi, user->Eta, user->Zet).
Definition at line 937 of file Metric.c.
| PetscErrorCode ComputeCellCenteredJacobianInverse | ( | UserCtx * | user | ) |
Calculates the cell-centered inverse Jacobian determinant (1/J) for INTERIOR cells and stores it in user->Aj.
This version includes boundary extrapolation.
Nodal coordinates are obtained internally. Refer to previous Doxygen comments for details on physical locations and storage convention (aj_arr[k_n][j_n][i_n] for cell C(i_n-1,j_n-1,k_n-1)).
| [in,out] | user | Pointer to the UserCtx structure. |
Calculates the cell-centered inverse Jacobian determinant (1/J) for INTERIOR cells and stores it in user->Aj.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/Metric.h.
Definition at line 1147 of file Metric.c.
| PetscErrorCode CheckAndFixGridOrientation | ( | UserCtx * | user | ) |
Verify and, when consistently inverted, repair the right-handed metric basis (Csi, Eta, Zet) and a positive Jacobian (Aj) over the whole domain.
The metric-generation kernels are completely algebraic, so they will happily deliver a left-handed basis if the mesh file enumerates nodes in the opposite ζ-direction.
This routine makes the orientation explicit and—if needed—repairs it once per run:
| Step | Action |
|---|---|
| 1 | Compute global Aj_min, Aj_max. |
| 2 | Mixed signs (Aj_min < 0 && Aj_max > 0) → abort: the mesh is topologically inconsistent. |
| 3 | All negative (Aj_max < 0) → abort: the grid is left-handed. Negating the metric vectors is not a valid repair (a mirrored duct solved that way was wrong by a factor of forty), so the grid must be renumbered along one logical axis instead. |
| 4 | Store user->GridOrientation = +1, the only orientation the solver accepts. |
| [in,out] | user | Fully initialised UserCtx that already contains Csi, Eta, Zet, Aj, their local ghosts, and valid distributed DMs. |
0 on success or a PETSc error code on failure.ComputeCellCenteredJacobianInverse() and before any routine that differentiates or applies BCs.Verify and, when consistently inverted, repair the right-handed metric basis (Csi, Eta, Zet) and a positive Jacobian (Aj) over the whole domain.
Definition at line 778 of file Metric.c.
| PetscErrorCode ComputeCellCenters | ( | UserCtx * | user | ) |
Computes the physical location of each cell's center from the nodal coordinates.
| user | The UserCtx for a specific grid level. The function populates user->Cent. |
Computes the physical location of each cell's center from the nodal coordinates.
Definition at line 1291 of file Metric.c.
| PetscErrorCode ComputeGridLineFractions | ( | UserCtx * | user, |
| Vec | fraction, | ||
| Vec | length | ||
| ) |
Arc-length position of every owned cell centre along its three grid lines.
For each grid line through an interior cell, the line's length is the sum of the cell edge lengths along it (ComputeCellEdgeVectors()), and a cell's fraction is the length before it plus half its own, over that total: 0 at the line's negative face and 1 at its positive face, proportional to distance along the line, so it is the same on uniform and stretched grids. Lines that cross ranks are summed with a scan along the line. Collective on PETSC_COMM_WORLD; needs the face metrics and the Jacobian with their local ghosts.
| [in] | user | Block and level whose grid lines are measured. |
| [out] | fraction | Global vector on user->fda: the xi, eta, zeta fractions in .x, .y, .z at interior cells; other entries are untouched. |
| [out] | length | Global vector on user->fda: the lengths of the same three lines, in solver units. |
Arc-length position of every owned cell centre along its three grid lines.
Full API contract is documented with the header declaration in include/Metric.h.
Definition at line 1362 of file Metric.c.
| PetscErrorCode ComputeIFaceMetrics | ( | UserCtx * | user | ) |
Computes metrics centered on constant-i faces (i-faces).
This function calculates the metric terms (ICsi, IEta, IZet) and the inverse Jacobian (IAj) located at the center of each i-face. The stencils use i-face-centered coordinates (Centx) which must be computed first. The logic is a direct adaptation of the legacy FormMetrics function.
| user | The UserCtx for a specific grid level. Populates user->ICsi, etc. |
Computes metrics centered on constant-i faces (i-faces).
Definition at line 1439 of file Metric.c.
| PetscErrorCode ComputeJFaceMetrics | ( | UserCtx * | user | ) |
Computes metrics centered on constant-j faces (j-faces).
This function calculates the metric terms (JCsi, JEta, JZet) and the inverse Jacobian (JAj) located at the geometric center of each constant-j face. This is a critical step for staggered-grid finite difference schemes.
The process is a direct and faithful refactoring of the corresponding logic from the legacy FormMetrics function:
user->Centy vector.Centy field to compute the derivatives (e.g., d(x)/d(csi)).Vec objects.| user | The UserCtx for a specific grid level. This function populates the user->JCsi, user->JEta, user->JZet, and user->JAj vectors. |
Computes metrics centered on constant-j faces (j-faces).
Definition at line 1646 of file Metric.c.
| PetscErrorCode ComputeKFaceMetrics | ( | UserCtx * | user | ) |
Computes metrics centered on constant-k faces (k-faces).
This function calculates the metric terms (KCsi, KEta, KZet) and the inverse Jacobian (KAj) located at the geometric center of each constant-j face. This is a critical step for staggered-grid finite difference schemes.
The process is a direct and faithful refactoring of the corresponding logic from the legacy FormMetrics function:
user->Centz vector.Centz field to compute the derivatives (e.g., d(x)/d(csi)).Vec objects.| user | The UserCtx for a specific grid level. This function populates the user->KCsi, user->KEta, user->KZet, and user->KAj vectors. |
Computes metrics centered on constant-k faces (k-faces).
Definition at line 1837 of file Metric.c.
| PetscErrorCode ComputeMetricsDivergence | ( | UserCtx * | user | ) |
Performs a diagnostic check on the divergence of the face area metric vectors.
For a closed cell, the sum of the face area vectors should be zero (Gauss's divergence theorem). This function computes a measure of this divergence and reports the maximum value over the domain. A small value indicates a well-formed grid. This is a direct adaptation of the legacy function.
| user | The UserCtx for a specific grid level (typically the finest). |
Performs a diagnostic check on the divergence of the face area metric vectors.
Definition at line 2047 of file Metric.c.
| PetscErrorCode ComputeMetricNorms | ( | UserCtx * | user | ) |
Computes the max-min values of the grid metrics.
This function serves as a diagnostic tool to assess the quality of the grid metrics. It calculates the bounds of the face metrics (Csi, Eta, Zet).
| user | The UserCtx, containing all necessary grid data. |
Computes the max-min values of the grid metrics.
Definition at line 2137 of file Metric.c.
| PetscErrorCode CalculateAllGridMetrics | ( | SimCtx * | simCtx | ) |
Orchestrates the calculation of all grid metrics.
This function iterates through every UserCtx in the multigrid and multi-block hierarchy. For each context, it calls a series of modern, modular helper functions to compute the face metrics (Csi, Eta, Zet), the cell-centered inverse Jacobian (Aj), and to validate the grid's orientation.
Orchestrates the calculation of all grid metrics.
Definition at line 2267 of file Metric.c.
| PetscBool MetricFacePlane | ( | const Cmpnts | v1, |
| const Cmpnts | v2, | ||
| const Cmpnts | v3, | ||
| const Cmpnts | v4, | ||
| const Cmpnts | cell_centroid, | ||
| FacePlane * | plane, | ||
| PetscBool * | degenerate | ||
| ) |
Builds one face plane: the unit outward normal of (v2 - v1) x (v4 - v1) and the vertex mean.
The single definition of a cell face plane: the per-cell planes of MetricBuildCellFacePlanes() and the precomputed per-face planes both use it, so their distances are bit-identical. The normal points away from cell_centroid. A degenerate face (normal magnitude below 1e-12) is reported through degenerate and left unnormalised.
| [in] | v1 | First face vertex; the normal's origin. |
| [in] | v2 | Second face vertex; the normal's first edge is v2 - v1. |
| [in] | v3 | Third face vertex; it enters only the centroid. |
| [in] | v4 | Fourth face vertex; the normal's second edge is v4 - v1. |
| [in] | cell_centroid | Centroid of the cell the face belongs to, which fixes the outward side. |
| [out] | plane | The face plane. |
| [out] | degenerate | Whether the normal magnitude is below 1e-12. |
Builds one face plane: the unit outward normal of (v2 - v1) x (v4 - v1) and the vertex mean.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/Metric.h.
Definition at line 47 of file Metric.c.
| void MetricBuildCellFacePlanes | ( | const Cell * | cell, |
| CellFacePlanes * | planes | ||
| ) |
Builds the six face planes of a hexahedron, as the particle search tests them.
Face vertex orders and orientation are those CalculateDistancesToCellFaces() has always used; degenerate faces set their bit in degenerate. size is set to 0. This per-cell form serves callers holding only a Cell; MetricComputeFacePlanes() precomputes the shared per-face form.
| [in] | cell | The cell, vertices in RetrieveCurrentCell() order. |
| [out] | planes | The cell's face planes. |
Builds the six face planes of a hexahedron, as the particle search tests them.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/Metric.h.
Definition at line 108 of file Metric.c.
| PetscErrorCode MetricComputeFacePlanes | ( | UserCtx * | user | ) |
Builds the block's particle face planes once, as catalogued per-face fields.
Each face carries one plane, shared by the two cells on either side: a unit normal pointing toward +i, +j or +k and the mean of its four vertices, built by MetricFacePlane() in the vertex order of the minus face (LEFT, BOTTOM, BACK) of the cell above it and oriented by that cell (by the cell below where only it is local). Grid-cell faces come from the node coordinates and are stored in the I/J/K-face layouts (PlaneNormal*, PlaneCentroid*: the face whose lower corner is node (i,j,k) sits at [k+1][j+1][i] for I, [k+1][j][i+1] for J, [k][j+1][i+1] for K); dual-cell faces come from lCent and sit at their lower-corner cell centre (DualPlaneNormal*, DualPlaneCentroid*). SearchCellSize holds each cell's GetCellCharacteristicSize() at its shifted cell-centred index. A face with no plane (degenerate, or beyond the ghosted region) has a zero normal. Owned values are the global fields; the locals are their ghost update through UpdateLocalGhosts() and the fields' catalogued sync classes. Collective. Built by CalculateAllGridMetrics() on the finest level of a particle run, after the coordinates and lCent are final; a no-op once built. Coordinates are fixed thereafter (there are no moving grids); a grid that changes must MetricDestroyFacePlanes() and rebuild.
| [in,out] | user | Block whose planes are built; MetricDestroyFacePlanes() frees them. |
Builds the block's particle face planes once, as catalogued per-face fields.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/Metric.h.
Definition at line 208 of file Metric.c.
| PetscErrorCode MetricDestroyFacePlanes | ( | UserCtx * | user | ) |
Frees the face-plane fields MetricComputeFacePlanes() built, if any.
| [in,out] | user | Block whose planes are freed; their Vecs are reset to NULL. |
Frees the face-plane fields MetricComputeFacePlanes() built, if any.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/Metric.h.
Definition at line 355 of file Metric.c.
| PetscErrorCode MetricGetFacePlaneArrays | ( | UserCtx * | user, |
| PetscBool | dual, | ||
| FacePlaneArrays * | arrays | ||
| ) |
Opens a family's face-plane arrays for reading; MetricComputeFacePlanes() must have run.
| [in] | user | Block whose planes are read. |
| [in] | dual | PETSC_TRUE for the dual-cell planes, PETSC_FALSE for the grid-cell planes. |
| [out] | arrays | The open arrays; close with MetricRestoreFacePlaneArrays(). |
Opens a family's face-plane arrays for reading; MetricComputeFacePlanes() must have run.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/Metric.h.
Definition at line 376 of file Metric.c.
| PetscErrorCode MetricRestoreFacePlaneArrays | ( | UserCtx * | user, |
| FacePlaneArrays * | arrays | ||
| ) |
Closes arrays opened by MetricGetFacePlaneArrays().
| [in] | user | Block whose planes were read. |
| [in,out] | arrays | The arrays to close. |
Closes arrays opened by MetricGetFacePlaneArrays().
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/Metric.h.
Definition at line 401 of file Metric.c.
| void MetricGatherCellFacePlanes | ( | const FacePlaneArrays * | arrays, |
| const DMDALocalInfo * | info, | ||
| PetscInt | i, | ||
| PetscInt | j, | ||
| PetscInt | k, | ||
| CellFacePlanes * | planes | ||
| ) |
Assembles one cell's six outward face planes from the shared per-face planes.
A cell's plus faces use the stored normals and its minus faces their exact negation; a face whose stored normal is zero sets its degenerate bit. For a grid cell (i, j, k) is its origin node; for a dual cell, the lower-corner cell centre.
| [in] | arrays | Open plane arrays. |
| [in] | info | The block's DMDA local info, for its ghosted extents. |
| [in] | i | Cell origin i index. |
| [in] | j | Cell origin j index. |
| [in] | k | Cell origin k index. |
| [out] | planes | The cell's planes, with size from SearchCellSize (0 for dual cells). |
Assembles one cell's six outward face planes from the shared per-face planes.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/Metric.h.
Definition at line 421 of file Metric.c.
|
inlinestatic |
Index of point (i, j, k) in a block's ghosted local arrays (coordinates, lCent, planes).
| [in] | info | The block's DMDA local info, for its ghosted extents. |
| [in] | i | Global i index, within the ghosted range. |
| [in] | j | Global j index, within the ghosted range. |
| [in] | k | Global k index, within the ghosted range. |
Definition at line 577 of file Metric.h.