|
PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
|
Public interface for grid, solver, and metric setup routines. More...
#include "variables.h"#include "logging.h"#include "io.h"#include "setup.h"#include "AnalyticalSolutions.h"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 | 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. | |
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. |
Definition at line 68 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.
Definition at line 260 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.Definition at line 356 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. |
This function calculates the minimum and maximum coordinates (x, y, z) of the local grid points owned by the current MPI process. It iterates over the local portion of the grid, examines each grid point's coordinates, and updates the minimum and maximum values accordingly.
The computed bounding box is stored in the provided localBBox structure, and the user->bbox field is also updated with this bounding box for consistency within the user context.
| [in] | user | Pointer to the user-defined context containing grid information. This context must be properly initialized before calling this function. |
| [out] | localBBox | Pointer to the BoundingBox structure where the computed local bounding box will be stored. The structure should be allocated by the caller. |
0 on success, non-zero on failure. Definition at line 800 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. |
Each rank computes its local bounding box, then all ranks participate in an MPI_Gather to send their BoundingBox to rank 0. Rank 0 allocates the result array and returns it via allBBoxes.
| [in] | user | Pointer to UserCtx (must be non-NULL). |
| [out] | allBBoxes | On rank 0, receives malloc’d array of size size. On other ranks, set to NULL. |
Definition at line 948 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.
After GatherAllBoundingBoxes, rank 0 has an array of size boxes. This routine makes sure every rank ends up with its own malloc’d copy.
| [in] | user | Pointer to UserCtx (unused here, but kept for signature). |
| [in,out] | bboxlist | On entry: rank 0’s array; on exit: every rank’s array. |
Definition at line 1016 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. |
Definition at line 1069 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. |
Definition at line 1125 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 |
< 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 1276 of file grid.c.