Public interface for grid, solver, and metric setup routines. More...
Go to the source code of this file.
Functions | |
| PetscErrorCode | DefineAllGridDimensions (SimCtx *simCtx) |
| Orchestrates the parsing and setting of grid dimensions for all blocks. | |
| PetscErrorCode | InitializeAllGridDMs (SimCtx *simCtx) |
| Orchestrates the creation of DMDA objects for every block and multigrid level. | |
| PetscErrorCode | AssignAllGridCoordinates (SimCtx *simCtx) |
| Orchestrates the assignment of physical coordinates to all DMDA objects. | |
| PetscErrorCode | ValidatePeriodicGeometry (UserCtx *user) |
| Validates that configured geometric periodic seams match by translation. | |
| PetscErrorCode | ComputeLocalBoundingBox (UserCtx *user, BoundingBox *localBBox) |
| Computes the local bounding box of the grid on the current process. | |
| PetscErrorCode | GatherAllBoundingBoxes (UserCtx *user, BoundingBox **allBBoxes) |
| Gathers local bounding boxes from all MPI processes to rank 0. | |
| PetscErrorCode | BroadcastAllBoundingBoxes (UserCtx *user, BoundingBox **bboxlist) |
| Broadcasts the bounding box information collected on rank 0 to all other ranks. | |
| PetscErrorCode | CalculateInletProperties (UserCtx *user) |
| Calculates the center and area of the primary INLET face. | |
| PetscErrorCode | CalculateOutletProperties (UserCtx *user) |
| Calculates the center and area of the primary OUTLET face. | |
| PetscErrorCode | CalculateFaceCenterAndArea (UserCtx *user, BCFace face_id, Cmpnts *face_center, PetscReal *face_area) |
| Calculates the geometric center and total area of a specified boundary face. | |
| PetscErrorCode | CreateCompatibleBlockDM (DM source, PetscInt dof, DM *result) |
| Creates a DMDA sharing a block's decomposition at a different degree of freedom. | |
| PetscErrorCode | BalanceCoarsestOwnership (PetscInt coarse_nodes, PetscInt fine_cells, PetscInt refinements, PetscInt ranks, PetscInt *l) |
| Split one axis of the coarsest level so the finest level's owned cells balance. | |
Public interface for grid, solver, and metric setup routines.
Definition in file grid.h.
| PetscErrorCode DefineAllGridDimensions | ( | SimCtx * | simCtx | ) |
Orchestrates the parsing and setting of grid dimensions for all blocks.
This function serves as the high-level entry point for defining the geometric properties of each grid block in the simulation. It iterates through every block defined by simCtx->block_number.
For each block, it performs two key actions:
_this) in the corresponding UserCtx struct for the finest multigrid level. This makes the context "self-aware".ParseAndSetGridInputs) to handle the detailed work of parsing options or files to populate the rest of the geometric properties for that specific block (e.g., IM, Min_X, rx).| simCtx | The master SimCtx, which contains the number of blocks and the UserCtx hierarchy to be configured. |
Orchestrates the parsing and setting of grid dimensions for all blocks.
Definition at line 38 of file grid.c.
| PetscErrorCode InitializeAllGridDMs | ( | SimCtx * | simCtx | ) |
Orchestrates the creation of DMDA objects for every block and multigrid level.
This function systematically builds the entire DMDA hierarchy. It first calculates the dimensions (IM, JM, KM) for all coarse grids based on the finest grid's dimensions and the semi-coarsening flags. It then iterates from the coarsest to the finest level, calling a powerful helper function (InitializeSingleGridDM) to create the DMs for each block, ensuring that finer grids are properly aligned with their coarser parents for multigrid efficiency.
Orchestrates the creation of DMDA objects for every block and multigrid level.
Definition at line 309 of file grid.c.
| PetscErrorCode AssignAllGridCoordinates | ( | SimCtx * | simCtx | ) |
Orchestrates the assignment of physical coordinates to all DMDA objects.
This function manages the entire process of populating the coordinate vectors for every DMDA across all multigrid levels and blocks. It follows a two-part strategy that is essential for multigrid methods:
SetFinestLevelCoordinates) to set the physical coordinates for the highest-resolution grid (the finest multigrid level).RestrictCoordinates) to copy the coordinate values from the fine grid nodes to their corresponding parent nodes on the coarser grids. This ensures all levels represent the exact same geometry.Orchestrates the assignment of physical coordinates to all DMDA objects.
Definition at line 389 of file grid.c.
| PetscErrorCode ValidatePeriodicGeometry | ( | UserCtx * | user | ) |
Validates that configured geometric periodic seams match by translation.
Each active periodic direction is checked independently using the physical nodal coordinates. On success, the constant seam translation is stored in the UserCtx.
| user | Grid/block context with assigned coordinates and boundary configuration. |
Validates that configured geometric periodic seams match by translation.
Full API contract is documented with the header declaration in include/grid.h.
Definition at line 450 of file grid.c.
| PetscErrorCode ComputeLocalBoundingBox | ( | UserCtx * | user, |
| BoundingBox * | localBBox | ||
| ) |
Computes the local bounding box of the grid on the current process.
This function calculates the minimum and maximum coordinates of the local grid points owned by the current MPI process and stores the computed bounding box in the provided structure.
| [in] | user | Pointer to the user-defined context containing grid information. |
| [out] | localBBox | Pointer to the BoundingBox structure to store the computed bounding box. |
Computes the local bounding box of the grid on the current process.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/grid.h.
Definition at line 869 of file grid.c.
| PetscErrorCode GatherAllBoundingBoxes | ( | UserCtx * | user, |
| BoundingBox ** | allBBoxes | ||
| ) |
Gathers local bounding boxes from all MPI processes to rank 0.
This function computes the local bounding box on each process, then collects all local bounding boxes on the root process (rank 0) using MPI. The result is stored in an array of BoundingBox structures on rank 0.
| [in] | user | Pointer to the user-defined context containing grid information. |
| [out] | allBBoxes | Pointer to a pointer where the array of gathered bounding boxes will be stored on rank 0. The caller on rank 0 must free this array. |
Gathers local bounding boxes from all MPI processes to rank 0.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/grid.h.
Definition at line 1011 of file grid.c.
| PetscErrorCode BroadcastAllBoundingBoxes | ( | UserCtx * | user, |
| BoundingBox ** | bboxlist | ||
| ) |
Broadcasts the bounding box information collected on rank 0 to all other ranks.
This function assumes that GatherAllBoundingBoxes() was previously called, so bboxlist is allocated and populated on rank 0. All other ranks will allocate memory for bboxlist, and this function will use MPI_Bcast to distribute the bounding box data to them.
| [in] | user | Pointer to the UserCtx structure. (Currently unused in this function, but kept for consistency.) |
| [in,out] | bboxlist | Pointer to the array of BoundingBoxes. On rank 0, this should point to a valid array of size 'size' (where size is the number of MPI ranks). On non-root ranks, this function will allocate memory for bboxlist. |
Broadcasts the bounding box information collected on rank 0 to all other ranks.
Definition at line 1071 of file grid.c.
| PetscErrorCode CalculateInletProperties | ( | UserCtx * | user | ) |
Calculates the center and area of the primary INLET face.
This function identifies the primary INLET face from the boundary face configurations, computes its geometric center and total area using a generic utility function, and stores these results in the simulation context.
| user | Pointer to the UserCtx containing boundary face information. |
Calculates the center and area of the primary INLET face.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/grid.h.
Definition at line 1119 of file grid.c.
| PetscErrorCode CalculateOutletProperties | ( | UserCtx * | user | ) |
Calculates the center and area of the primary OUTLET face.
This function identifies the primary OUTLET face from the boundary face configurations, computes its geometric center and total area using a generic utility function, and stores these results in the simulation context.
| user | Pointer to the UserCtx containing boundary face information. |
Calculates the center and area of the primary OUTLET face.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/grid.h.
Definition at line 1170 of file grid.c.
| PetscErrorCode CalculateFaceCenterAndArea | ( | UserCtx * | user, |
| BCFace | face_id, | ||
| Cmpnts * | face_center, | ||
| PetscReal * | face_area | ||
| ) |
Calculates the geometric center and total area of a specified boundary face.
This function computes two key properties of a boundary face in the computational domain:
The solver uses different indexing conventions for different field types:
Node-Centered Fields (Coordinates):
Face-Centered Fields (Metrics: csi, eta, zet):
Cell-Centered Fields (nvert):
Example for a domain with mx=26, my=26, mz=98:
| Face ID | Node Index | Face Metric | Adjacent Cell (shifted) | Physical Extent |
|---|---|---|---|---|
| BC_FACE_NEG_X | i=0 | csi[k][j][0] | nvert[k][j][1] (Cell 0) | j∈[0,24], k∈[0,96] |
| BC_FACE_POS_X | i=24 | csi[k][j][24] | nvert[k][j][24] (Cell 23) | j∈[0,24], k∈[0,96] |
| BC_FACE_NEG_Y | j=0 | eta[k][0][i] | nvert[k][1][i] (Cell 0) | i∈[0,24], k∈[0,96] |
| BC_FACE_POS_Y | j=24 | eta[k][24][i] | nvert[k][24][i] (Cell 23) | i∈[0,24], k∈[0,96] |
| BC_FACE_NEG_Z | k=0 | zet[0][j][i] | nvert[1][j][i] (Cell 0) | i∈[0,24], j∈[0,24] |
| BC_FACE_POS_Z | k=96 | zet[96][j][i] | nvert[96][j][i] (Cell 95) | i∈[0,24], j∈[0,24] |
The function performs two separate computations with different loop bounds:
1. Center Calculation (uses ALL physical nodes):
2. Area Calculation (uses INTERIOR cells only):
Why different bounds for center vs. area?
For BC_FACE_NEG_X at i=0 with my=26, mz=98:
Center calculation (coordinates):
Area calculation (nvert checks):
Face area contributions are computed from metric tensor magnitudes:
| [in] | user | Pointer to UserCtx containing grid info, DMs, and field vectors |
| [in] | face_id | Enum identifying which boundary face to analyze (BC_FACE_NEG_X, etc.) |
| [out] | face_center | Pointer to Cmpnts structure to store computed geometric center (x,y,z) |
| [out] | face_area | Pointer to PetscReal to store computed total face area |
Calculates the geometric center and total area of a specified boundary face.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/grid.h.
< Local sum of (x,y,z) coordinates
< Local sum of face area magnitudes
< Local count of nodes
< Global sum of coordinates
< Global sum of areas
< Global count of nodes
< i-range: [xs, xe)
< j-range: [ys, ye)
< k-range: [zs, ze)
< Physical domain size in i (exclude dummy)
< Physical domain size in j (exclude dummy)
< Physical domain size in k (exclude dummy)
< Start at 1 if on -Xi boundary
< End at mx-1 if on +Xi boundary
< Start at 1 if on -Eta boundary
< End at my-1 if on +Eta boundary
< Start at 1 if on -Zeta boundary
< End at mz-1 if on +Zeta boundary
< Exclude dummy at i=mx-1 (e.g., i=25)
< Exclude dummy at j=my-1 (e.g., j=25)
< Exclude dummy at k=mz-1 (e.g., k=97)
< Local ghosted coordinate vector
< Nodal coordinates [k][j][i]
< Face metric tensors [k][j][i]
< Cell blanking field [k][j][i] (shifted +1)
Definition at line 1211 of file grid.c.
| PetscErrorCode CreateCompatibleBlockDM | ( | DM | source, |
| PetscInt | dof, | ||
| DM * | result | ||
| ) |
Creates a DMDA sharing a block's decomposition at a different degree of freedom.
Fields whose component count is neither one nor three still have to live on the same index space as the block, so a pointwise loop can read da and write them at the same (i,j,k). Copying the source DM's sizes, boundary types, stencil, and — critically — its explicit per-rank ownership ranges makes the decomposition identical rather than merely similar. Letting PETSc re-decide the split would be free to disagree, and the loop would misalign silently.
| [in] | source | Existing block DMDA whose decomposition is mirrored. |
| [in] | dof | Degrees of freedom the new DM carries; must be positive. |
| [out] | result | Created DM; the caller owns it and must destroy it. |
Creates a DMDA sharing a block's decomposition at a different degree of freedom.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/grid.h.
Definition at line 81 of file grid.c.
| PetscErrorCode BalanceCoarsestOwnership | ( | PetscInt | coarse_nodes, |
| PetscInt | fine_cells, | ||
| PetscInt | refinements, | ||
| PetscInt | ranks, | ||
| PetscInt * | l | ||
| ) |
Split one axis of the coarsest level so the finest level's owned cells balance.
The finer levels inherit their ownership by refinement (InitializeSingleGridDM): each refinement maps a coarse rank boundary at node c to 2c - 1, so a boundary at coarsest node c lands at finest node 2^R (c - 1) + 1. Refining PETSc's default coarsest split compounds its remainder, e.g. 128 cells on 4 ranks at 3 levels own 33/36/32/27 cells. A rank owns the cells whose lower-corner node it owns, and the last node is padding. Every rank keeps at least PETSc's floor width, so every stencil-width check on the default split still holds, and the spare points go where they minimise the largest finest-level share, by dynamic programming over (rank, spare points used so far): O(ranks x spare^2) once per axis at setup. A rank may take several: unrefined, 128 cells on 4 ranks split 32/32/32/34 nodes, 32 cells each. The share counted is the particles' (GetOwnedCellRange); cell-centred Eulerian storage puts cell c at node c + 1, so it differs by one cell at each end and is not balanced with it (GitHub #21).
| [in] | coarse_nodes | Coarsest-level DA points on the axis. |
| [in] | fine_cells | Finest-level physical cells on the axis. |
| [in] | refinements | Refinements of the axis between the coarsest and finest levels. |
| [in] | ranks | Ranks on the axis. |
| [out] | l | Coarsest-level DA points owned by each rank on the axis. |
Split one axis of the coarsest level so the finest level's owned cells balance.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/grid.h.
Definition at line 121 of file grid.c.