|
PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
|
// Setup code for running any simulation More...
#include <ctype.h>#include <errno.h>#include "setup.h"#include "statistics_config.h"#include "statistics_accumulator.h"Go to the source code of this file.
Macros | |
| #define | __FUNCT__ "CreateSimulationContext" |
| #define | __FUNCT__ "PetscMkdirRecursive" |
| #define | __FUNCT__ "SetupSimulationEnvironment" |
| #define | __FUNCT__ "AllocateContextHeirarchy" |
| #define | __FUNCT__ "SetupSolverParameters" |
| #define | __FUNCT__ "SetupGridAndSolvers" |
| #define | __FUNCT__ "CreateAndInitializeAllVectors" |
| #define | __FUNCT__ "RepairPeriodicNormalFaceGhosts" |
| #define | __FUNCT__ "UpdateLocalGhosts" |
| #define | __FUNCT__ "SetupBoundaryConditions" |
| #define | __FUNCT__ "GetOwnedCellRange" |
| #define | __FUNCT__ "ComputeAndStoreNeighborRanks" |
| #define | __FUNCT__ "SetDMDAProcLayout" |
| #define | __FUNCT__ "SetupDomainRankInfo" |
| #define | __FUNCT__ "Contra2Cart" |
| #define | __FUNCT__ "Cart2Contra" |
| #define | __FUNCT__ "UniformCart2Contra" |
| #define | __FUNCT__ "SetupDomainCellDecompositionMap" |
| #define | __FUNCT__ "BinarySearchInt64" |
| #define | __FUNCT__ "ComputeDivergence" |
| #define | __FUNCT__ "InitializeRandomGenerators" |
| #define | __FUNCT__ "InitializeLogicalSpaceRNGs" |
| #define | __FUNCT__ "InitializeBrownianRNG" |
| #define | __FUNCT__ "TransformScalarDerivativesToPhysical" |
| #define | __FUNCT__ "TransformDerivativesToPhysical" |
| #define | __FUNCT__ "ComputeScalarFieldDerivatives" |
| #define | __FUNCT__ "ComputeVectorFieldDerivatives" |
| #define | __FUNCT__ "DestroyUserVectors" |
| #define | __FUNCT__ "DestroyUserContext" |
| #define | __FUNCT__ "FinalizeSimulation" |
Functions | |
| PetscBool | RuntimeWalltimeGuardParsePositiveSeconds (const char *text, PetscReal *seconds_out) |
| Implementation of RuntimeWalltimeGuardParsePositiveSeconds(). | |
| PetscErrorCode | InitializeSolutionConvergenceState (SimCtx *simCtx) |
| Implementation of InitializeSolutionConvergenceState(). | |
| PetscErrorCode | DestroySolutionConvergenceState (SimCtx *simCtx) |
| Implementation of DestroySolutionConvergenceState(). | |
| PetscErrorCode | CreateSimulationContext (int argc, char **argv, SimCtx **p_simCtx) |
| Implementation of CreateSimulationContext(). | |
| static PetscErrorCode | PetscMkdirRecursive (const char *path) |
| Create a directory path recursively using PETSc-compatible error handling. | |
| PetscErrorCode | SetupSimulationEnvironment (SimCtx *simCtx) |
Internal helper implementation: SetupSimulationEnvironment(). | |
| static PetscErrorCode | AllocateContextHierarchy (SimCtx *simCtx) |
| Allocate the user-context objects required by every multigrid level. | |
| static PetscErrorCode | SetupSolverParameters (SimCtx *simCtx) |
| Configure solver tolerances, operators, and time-integration controls from the context. | |
| PetscErrorCode | SetupGridAndSolvers (SimCtx *simCtx) |
| Implementation of SetupGridAndSolvers(). | |
| PetscErrorCode | CreateAndInitializeAllVectors (SimCtx *simCtx) |
Internal helper implementation: CreateAndInitializeAllVectors(). | |
| static PetscErrorCode | RepairPeriodicNormalFaceGhosts (UserCtx *user, DM dm, Vec local_vec, PetscInt dof, char face_direction, PetscBool component_staggered) |
| Repairs the adjacent normal ghost layer for periodic face-staggered data. | |
| PetscErrorCode | UpdateLocalGhosts (UserCtx *user, FieldId field_id) |
| Updates a catalogued field's local ghost representation. | |
| PetscErrorCode | SetupBoundaryConditions (SimCtx *simCtx) |
Internal helper implementation: SetupBoundaryConditions(). | |
| PetscErrorCode | Allocate3DArrayScalar (PetscReal ****array, PetscInt nz, PetscInt ny, PetscInt nx) |
Internal helper implementation: Allocate3DArrayScalar(). | |
| PetscErrorCode | Deallocate3DArrayScalar (PetscReal ***array, PetscInt nz, PetscInt ny) |
Internal helper implementation: Deallocate3DArrayScalar(). | |
| PetscErrorCode | Allocate3DArrayVector (Cmpnts ****array, PetscInt nz, PetscInt ny, PetscInt nx) |
| Implementation of Allocate3DArrayVector(). | |
| PetscErrorCode | Deallocate3DArrayVector (Cmpnts ***array, PetscInt nz, PetscInt ny) |
| Implementation of Deallocate3DArrayVector(). | |
| PetscErrorCode | GetOwnedCellRange (const DMDALocalInfo *info_nodes, PetscInt dim, PetscInt *xs_cell_global_out, PetscInt *xm_cell_local_out) |
Internal helper implementation: GetOwnedCellRange(). | |
| PetscErrorCode | ComputeAndStoreNeighborRanks (UserCtx *user) |
Internal helper implementation: ComputeAndStoreNeighborRanks(). | |
| PetscErrorCode | SetDMDAProcLayout (DM dm, UserCtx *user) |
Internal helper implementation: SetDMDAProcLayout(). | |
| PetscErrorCode | SetupDomainRankInfo (SimCtx *simCtx) |
| Implementation of SetupDomainRankInfo(). | |
| PetscErrorCode | Contra2Cart (UserCtx *user) |
Internal helper implementation: Contra2Cart(). | |
| PetscErrorCode | Cart2Contra (UserCtx *user) |
| Convert a spatially varying Cartesian velocity field to contravariant fluxes. | |
| PetscErrorCode | UniformCart2Contra (UserCtx *user, PetscReal u, PetscReal v, PetscReal w) |
| Populate contravariant fluxes from one uniform Cartesian velocity. | |
| PetscErrorCode | SetupDomainCellDecompositionMap (UserCtx *user) |
Internal helper implementation: SetupDomainCellDecompositionMap(). | |
| PetscErrorCode | BinarySearchInt64 (PetscInt n, const PetscInt64 arr[], PetscInt64 key, PetscBool *found) |
| Implementation of BinarySearchInt64(). | |
| static PetscInt | Gidx (PetscInt i, PetscInt j, PetscInt k, UserCtx *user) |
| Convert logical indices into the flattened global index used by setup helpers. | |
| PetscErrorCode | ComputeDivergence (UserCtx *user) |
| Implementation of ComputeDivergence(). | |
| PetscErrorCode | InitializeRandomGenerators (UserCtx *user, PetscRandom *randx, PetscRandom *randy, PetscRandom *randz) |
| Implementation of InitializeRandomGenerators(). | |
| PetscErrorCode | InitializeLogicalSpaceRNGs (PetscRandom *rand_logic_i, PetscRandom *rand_logic_j, PetscRandom *rand_logic_k) |
Internal helper implementation: InitializeLogicalSpaceRNGs(). | |
| PetscErrorCode | InitializeBrownianRNG (SimCtx *simCtx) |
Internal helper implementation: InitializeBrownianRNG(). | |
| void | TransformScalarDerivativesToPhysical (PetscReal jacobian, Cmpnts csi_metrics, Cmpnts eta_metrics, Cmpnts zet_metrics, PetscReal dPhi_dcsi, PetscReal dPhi_deta, PetscReal dPhi_dzet, Cmpnts *gradPhi) |
| Implementation of TransformScalarDerivativesToPhysical(). | |
| static void | TransformDerivativesToPhysical (PetscReal jacobian, Cmpnts csi_metrics, Cmpnts eta_metrics, Cmpnts zet_metrics, Cmpnts deriv_csi, Cmpnts deriv_eta, Cmpnts deriv_zet, Cmpnts *dudx, Cmpnts *dvdx, Cmpnts *dwdx) |
| Transform contravariant vector derivatives into physical Cartesian derivatives. | |
| PetscErrorCode | ComputeScalarFieldDerivatives (UserCtx *user, PetscInt i, PetscInt j, PetscInt k, PetscReal ***field_data, Cmpnts *grad) |
Internal helper implementation: ComputeScalarFieldDerivatives(). | |
| PetscErrorCode | ComputeVectorFieldDerivatives (UserCtx *user, PetscInt i, PetscInt j, PetscInt k, Cmpnts ***field_data, Cmpnts *dudx, Cmpnts *dvdx, Cmpnts *dwdx) |
Internal helper implementation: ComputeVectorFieldDerivatives(). | |
| PetscErrorCode | DestroyUserVectors (UserCtx *user) |
Internal helper implementation: DestroyUserVectors(). | |
| PetscErrorCode | DestroyUserContext (UserCtx *user) |
Internal helper implementation: DestroyUserContext(). | |
| PetscErrorCode | FinalizeSimulation (SimCtx *simCtx) |
| Implementation of FinalizeSimulation(). | |
// Setup code for running any simulation
Test program for DMSwarm interpolation using the fdf-curvIB method. Provides the setup to start any simulation with DMSwarm and DMDAs.
Definition in file setup.c.
| PetscBool RuntimeWalltimeGuardParsePositiveSeconds | ( | const char * | text, |
| PetscReal * | seconds_out | ||
| ) |
Implementation of RuntimeWalltimeGuardParsePositiveSeconds().
Parse a positive floating-point seconds value from runtime metadata.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/setup.h.
Definition at line 20 of file setup.c.
| PetscErrorCode InitializeSolutionConvergenceState | ( | SimCtx * | simCtx | ) |
Implementation of InitializeSolutionConvergenceState().
Allocates any runtime storage required by solution-convergence logging.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/setup.h.
Definition at line 49 of file setup.c.
| PetscErrorCode DestroySolutionConvergenceState | ( | SimCtx * | simCtx | ) |
Implementation of DestroySolutionConvergenceState().
Frees any runtime storage allocated for solution-convergence logging.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/setup.h.
Definition at line 101 of file setup.c.
| PetscErrorCode CreateSimulationContext | ( | int | argc, |
| char ** | argv, | ||
| SimCtx ** | p_simCtx | ||
| ) |
Implementation of CreateSimulationContext().
Allocates and populates the master SimulationContext object.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/setup.h.
Definition at line 160 of file setup.c.
|
static |
Create a directory path recursively using PETSc-compatible error handling.
Definition at line 1011 of file setup.c.
| PetscErrorCode SetupSimulationEnvironment | ( | SimCtx * | simCtx | ) |
Internal helper implementation: SetupSimulationEnvironment().
Verifies and prepares the complete I/O environment for a simulation run.
Local to this translation unit.
Definition at line 1063 of file setup.c.
|
static |
Allocate the user-context objects required by every multigrid level.
Definition at line 1230 of file setup.c.
|
static |
Configure solver tolerances, operators, and time-integration controls from the context.
Definition at line 1332 of file setup.c.
| PetscErrorCode SetupGridAndSolvers | ( | SimCtx * | simCtx | ) |
Implementation of SetupGridAndSolvers().
The main orchestrator for setting up all grid-related components.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/setup.h.
Definition at line 1364 of file setup.c.
| PetscErrorCode CreateAndInitializeAllVectors | ( | SimCtx * | simCtx | ) |
Internal helper implementation: CreateAndInitializeAllVectors().
Creates and initializes all PETSc Vec objects for all fields.
Local to this translation unit.
Definition at line 1400 of file setup.c.
|
static |
Repairs the adjacent normal ghost layer for periodic face-staggered data.
PETSc wraps every component with cell-style indexing. A face family instead needs its adjacent normal ghost shifted by one additional physical face. With the width-three periodic DMDA, the required value is available in the deeper PETSc ghost at -3 or n+2. Tangential ghosts retain PETSc's native wraparound.
Definition at line 1668 of file setup.c.
Updates a catalogued field's local ghost representation.
Updates the local vector (including ghost points) from its corresponding global vector.
Resolves the typed field view, performs the existing PETSc scatter, and applies the established periodic normal-face repair when needed.
Definition at line 1838 of file setup.c.
| PetscErrorCode SetupBoundaryConditions | ( | SimCtx * | simCtx | ) |
Internal helper implementation: SetupBoundaryConditions().
(Orchestrator) Sets up all boundary conditions for the simulation.
Local to this translation unit.
Definition at line 2027 of file setup.c.
| PetscErrorCode Allocate3DArrayScalar | ( | PetscReal **** | array, |
| PetscInt | nz, | ||
| PetscInt | ny, | ||
| PetscInt | nx | ||
| ) |
Internal helper implementation: Allocate3DArrayScalar().
Allocates a 3D array of PetscReal values using PetscCalloc.
Local to this translation unit.
Definition at line 2091 of file setup.c.
| PetscErrorCode Deallocate3DArrayScalar | ( | PetscReal *** | array, |
| PetscInt | nz, | ||
| PetscInt | ny | ||
| ) |
Internal helper implementation: Deallocate3DArrayScalar().
Deallocates a 3D array of PetscReal values allocated by Allocate3DArrayScalar.
Local to this translation unit.
Definition at line 2126 of file setup.c.
| PetscErrorCode Allocate3DArrayVector | ( | Cmpnts **** | array, |
| PetscInt | nz, | ||
| PetscInt | ny, | ||
| PetscInt | nx | ||
| ) |
Implementation of Allocate3DArrayVector().
Allocates a contiguous 3D array of Cmpnts values.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/setup.h.
Definition at line 2169 of file setup.c.
| PetscErrorCode Deallocate3DArrayVector | ( | Cmpnts *** | array, |
| PetscInt | nz, | ||
| PetscInt | ny | ||
| ) |
Implementation of Deallocate3DArrayVector().
Deallocates a 3D array of Cmpnts structures allocated by Allocate3DArrayVector.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/setup.h.
Definition at line 2219 of file setup.c.
| PetscErrorCode GetOwnedCellRange | ( | const DMDALocalInfo * | info_nodes, |
| PetscInt | dim, | ||
| PetscInt * | xs_cell_global_out, | ||
| PetscInt * | xm_cell_local_out | ||
| ) |
Internal helper implementation: GetOwnedCellRange().
Determines the global starting index and number of CELLS owned by the current processor in a specified dimension.
Local to this translation unit.
Definition at line 2285 of file setup.c.
| PetscErrorCode ComputeAndStoreNeighborRanks | ( | UserCtx * | user | ) |
Internal helper implementation: ComputeAndStoreNeighborRanks().
Computes and stores the Cartesian neighbor ranks for the DMDA decomposition.
Local to this translation unit.
Definition at line 2382 of file setup.c.
| PetscErrorCode SetDMDAProcLayout | ( | DM | dm, |
| UserCtx * | user | ||
| ) |
Internal helper implementation: SetDMDAProcLayout().
Sets the processor layout for a given DMDA based on PETSc options.
Local to this translation unit.
Definition at line 2498 of file setup.c.
| PetscErrorCode SetupDomainRankInfo | ( | SimCtx * | simCtx | ) |
Implementation of SetupDomainRankInfo().
Sets up the full rank communication infrastructure, including neighbor ranks and bounding box exchange.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/setup.h.
Definition at line 2576 of file setup.c.
| PetscErrorCode Contra2Cart | ( | UserCtx * | user | ) |
Internal helper implementation: Contra2Cart().
Reconstructs Cartesian velocity (Ucat) at cell centers from contravariant velocity (Ucont) defined on cell faces.
Local to this translation unit.
Definition at line 2649 of file setup.c.
| PetscErrorCode Cart2Contra | ( | UserCtx * | user | ) |
Convert a spatially varying Cartesian velocity field to contravariant fluxes.
Convert the ghosted Cartesian velocity field to contravariant face fluxes.
Definition at line 2784 of file setup.c.
| PetscErrorCode UniformCart2Contra | ( | UserCtx * | user, |
| PetscReal | u, | ||
| PetscReal | v, | ||
| PetscReal | w | ||
| ) |
Populate contravariant fluxes from one uniform Cartesian velocity.
| [in,out] | user | UserCtx for the block; Ucont is written in place. |
| [in] | u | Physical x-velocity component. |
| [in] | v | Physical y-velocity component. |
| [in] | w | Physical z-velocity component. |
Definition at line 2853 of file setup.c.
| PetscErrorCode SetupDomainCellDecompositionMap | ( | UserCtx * | user | ) |
Internal helper implementation: SetupDomainCellDecompositionMap().
Creates and distributes a map of the domain's cell decomposition to all ranks.
Local to this translation unit.
Definition at line 2900 of file setup.c.
| PetscErrorCode BinarySearchInt64 | ( | PetscInt | n, |
| const PetscInt64 | arr[], | ||
| PetscInt64 | key, | ||
| PetscBool * | found | ||
| ) |
Implementation of BinarySearchInt64().
Performs a binary search for a key in a sorted array of PetscInt64.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/setup.h.
Definition at line 2965 of file setup.c.
|
static |
Convert logical indices into the flattened global index used by setup helpers.
Definition at line 3008 of file setup.c.
| PetscErrorCode ComputeDivergence | ( | UserCtx * | user | ) |
Implementation of ComputeDivergence().
Computes the discrete divergence of the contravariant velocity field.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/setup.h.
Definition at line 3034 of file setup.c.
| PetscErrorCode InitializeRandomGenerators | ( | UserCtx * | user, |
| PetscRandom * | randx, | ||
| PetscRandom * | randy, | ||
| PetscRandom * | randz | ||
| ) |
Implementation of InitializeRandomGenerators().
Initializes random number generators for assigning particle properties.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/setup.h.
Definition at line 3200 of file setup.c.
| PetscErrorCode InitializeLogicalSpaceRNGs | ( | PetscRandom * | rand_logic_i, |
| PetscRandom * | rand_logic_j, | ||
| PetscRandom * | rand_logic_k | ||
| ) |
Internal helper implementation: InitializeLogicalSpaceRNGs().
Initializes random number generators for logical space operations [0.0, 1.0).
Local to this translation unit.
Definition at line 3241 of file setup.c.
| PetscErrorCode InitializeBrownianRNG | ( | SimCtx * | simCtx | ) |
Internal helper implementation: InitializeBrownianRNG().
Initializes a single master RNG for time-stepping physics (Brownian motion).
Local to this translation unit.
Definition at line 3285 of file setup.c.
| void TransformScalarDerivativesToPhysical | ( | PetscReal | jacobian, |
| Cmpnts | csi_metrics, | ||
| Cmpnts | eta_metrics, | ||
| Cmpnts | zet_metrics, | ||
| PetscReal | dPhi_dcsi, | ||
| PetscReal | dPhi_deta, | ||
| PetscReal | dPhi_dzet, | ||
| Cmpnts * | gradPhi | ||
| ) |
Implementation of TransformScalarDerivativesToPhysical().
Transforms scalar derivatives from computational space to physical space.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/setup.h.
Definition at line 3324 of file setup.c.
|
static |
Transform contravariant vector derivatives into physical Cartesian derivatives.
Definition at line 3348 of file setup.c.
| PetscErrorCode ComputeScalarFieldDerivatives | ( | UserCtx * | user, |
| PetscInt | i, | ||
| PetscInt | j, | ||
| PetscInt | k, | ||
| PetscReal *** | field_data, | ||
| Cmpnts * | grad | ||
| ) |
Internal helper implementation: ComputeScalarFieldDerivatives().
Computes the gradient of a cell-centered SCALAR field at a specific grid point.
Local to this translation unit.
Definition at line 3372 of file setup.c.
| PetscErrorCode ComputeVectorFieldDerivatives | ( | UserCtx * | user, |
| PetscInt | i, | ||
| PetscInt | j, | ||
| PetscInt | k, | ||
| Cmpnts *** | field_data, | ||
| Cmpnts * | dudx, | ||
| Cmpnts * | dvdx, | ||
| Cmpnts * | dwdx | ||
| ) |
Internal helper implementation: ComputeVectorFieldDerivatives().
Computes the derivatives of a cell-centered vector field at a specific grid point.
Local to this translation unit.
Definition at line 3415 of file setup.c.
| PetscErrorCode DestroyUserVectors | ( | UserCtx * | user | ) |
Internal helper implementation: DestroyUserVectors().
Destroys all PETSc Vec objects within a single UserCtx structure.
Local to this translation unit.
Definition at line 3469 of file setup.c.
| PetscErrorCode DestroyUserContext | ( | UserCtx * | user | ) |
Internal helper implementation: DestroyUserContext().
Destroys all resources allocated within a single UserCtx structure.
Local to this translation unit.
Definition at line 3618 of file setup.c.
| PetscErrorCode FinalizeSimulation | ( | SimCtx * | simCtx | ) |
Implementation of FinalizeSimulation().
Main cleanup function for the entire simulation context.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/setup.h.
Definition at line 3721 of file setup.c.