|
PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
|
#include <petscpf.h>#include <petscdmswarm.h>#include <stdlib.h>#include <time.h>#include <math.h>#include <petsctime.h>#include <petscsys.h>#include <petscdmcomposite.h>#include <petscsystypes.h>#include "variables.h"#include "ParticleSwarm.h"#include "walkingsearch.h"#include "grid.h"#include "logging.h"#include "io.h"#include "interpolation.h"#include "ParticleMotion.h"#include "Boundaries.h"Go to the source code of this file.
Macros | |
| #define | Allocate3DArray(array, nz, ny, nx) |
| #define | Deallocate3DArray(array, nz, ny) |
Functions | |
| PetscErrorCode | CreateSimulationContext (int argc, char **argv, SimCtx **p_simCtx) |
| Allocates and populates the master SimulationContext object. | |
| PetscBool | RuntimeWalltimeGuardParsePositiveSeconds (const char *text, PetscReal *seconds_out) |
| Parse a positive floating-point seconds value from runtime metadata. | |
| PetscErrorCode | SetupSimulationEnvironment (SimCtx *simCtx) |
| Verifies and prepares the complete I/O environment for a simulation run. | |
| PetscErrorCode | SetupGridAndSolvers (SimCtx *simCtx) |
| The main orchestrator for setting up all grid-related components. | |
| PetscErrorCode | CreateAndInitializeAllVectors (SimCtx *simCtx) |
| Creates and initializes all PETSc Vec objects for all fields. | |
| PetscErrorCode | UpdateLocalGhosts (UserCtx *user, const char *fieldName) |
| Updates the local vector (including ghost points) from its corresponding global vector. | |
| PetscErrorCode | SetupBoundaryConditions (SimCtx *simCtx) |
| (Orchestrator) Sets up all boundary conditions for the simulation. | |
| PetscErrorCode | Allocate3DArrayScalar (PetscReal ****array, PetscInt nz, PetscInt ny, PetscInt nx) |
| Allocates a 3D array of PetscReal values using PetscCalloc. | |
| PetscErrorCode | Deallocate3DArrayScalar (PetscReal ***array, PetscInt nz, PetscInt ny) |
| Deallocates a 3D array of PetscReal values allocated by Allocate3DArrayScalar. | |
| PetscErrorCode | Allocate3DArrayVector (Cmpnts ****array, PetscInt nz, PetscInt ny, PetscInt nx) |
Allocates a contiguous 3D array of Cmpnts values. | |
| PetscErrorCode | Deallocate3DArrayVector (Cmpnts ***array, PetscInt nz, PetscInt ny) |
| Deallocates a 3D array of Cmpnts structures allocated by Allocate3DArrayVector. | |
| PetscErrorCode | GetOwnedCellRange (const DMDALocalInfo *info_nodes, PetscInt dim, PetscInt *xs_cell_global_out, PetscInt *xm_cell_local_out) |
| Determines the global starting index and number of CELLS owned by the current processor in a specified dimension. | |
| PetscErrorCode | ComputeAndStoreNeighborRanks (UserCtx *user) |
| Computes and stores the Cartesian neighbor ranks for the DMDA decomposition. | |
| PetscErrorCode | SetDMDAProcLayout (DM dm, UserCtx *user) |
| Sets the processor layout for a given DMDA based on PETSc options. | |
| PetscErrorCode | SetupDomainRankInfo (SimCtx *simCtx) |
| Sets up the full rank communication infrastructure, including neighbor ranks and bounding box exchange. | |
| PetscErrorCode | Contra2Cart (UserCtx *user) |
| Reconstructs Cartesian velocity (Ucat) at cell centers from contravariant velocity (Ucont) defined on cell faces. | |
| PetscErrorCode | SetupDomainCellDecompositionMap (UserCtx *user) |
| Creates and distributes a map of the domain's cell decomposition to all ranks. | |
| PetscErrorCode | BinarySearchInt64 (PetscInt n, const PetscInt64 arr[], PetscInt64 key, PetscBool *found) |
| Performs a binary search for a key in a sorted array of PetscInt64. | |
| PetscErrorCode | ComputeDivergence (UserCtx *user) |
| Computes the discrete divergence of the contravariant velocity field. | |
| PetscErrorCode | InitializeRandomGenerators (UserCtx *user, PetscRandom *randx, PetscRandom *randy, PetscRandom *randz) |
| Initializes random number generators for assigning particle properties. | |
| PetscErrorCode | InitializeLogicalSpaceRNGs (PetscRandom *rand_logic_i, PetscRandom *rand_logic_j, PetscRandom *rand_logic_k) |
| Initializes random number generators for logical space operations [0.0, 1.0). | |
| PetscErrorCode | InitializeBrownianRNG (SimCtx *simCtx) |
| Initializes a single master RNG for time-stepping physics (Brownian motion). | |
| void | TransformScalarDerivativesToPhysical (PetscReal jacobian, Cmpnts csi_metrics, Cmpnts eta_metrics, Cmpnts zet_metrics, PetscReal dPhi_dcsi, PetscReal dPhi_deta, PetscReal dPhi_dzet, Cmpnts *gradPhi) |
| Transforms scalar derivatives from computational space to physical space. | |
| PetscErrorCode | ComputeScalarFieldDerivatives (UserCtx *user, PetscInt i, PetscInt j, PetscInt k, PetscReal ***field_data, Cmpnts *grad) |
| Computes the gradient of a cell-centered SCALAR field at a specific grid point. | |
| PetscErrorCode | ComputeVectorFieldDerivatives (UserCtx *user, PetscInt i, PetscInt j, PetscInt k, Cmpnts ***field_data, Cmpnts *dudx, Cmpnts *dvdx, Cmpnts *dwdx) |
| Computes the derivatives of a cell-centered vector field at a specific grid point. | |
| PetscErrorCode | DestroyUserVectors (UserCtx *user) |
| Destroys all PETSc Vec objects within a single UserCtx structure. | |
| PetscErrorCode | DestroyUserContext (UserCtx *user) |
| Destroys all resources allocated within a single UserCtx structure. | |
| PetscErrorCode | FinalizeSimulation (SimCtx *simCtx) |
| Main cleanup function for the entire simulation context. | |
| #define Allocate3DArray | ( | array, | |
| nz, | |||
| ny, | |||
| nx | |||
| ) |
| #define Deallocate3DArray | ( | array, | |
| nz, | |||
| ny | |||
| ) |
| PetscErrorCode CreateSimulationContext | ( | int | argc, |
| char ** | argv, | ||
| SimCtx ** | p_simCtx | ||
| ) |
Allocates and populates the master SimulationContext object.
This function serves as the single, authoritative entry point for all simulation configuration. It merges the setup logic from both the legacy FSI/IBM solver and the modern particle solver into a unified, robust process.
The function follows a strict sequence:
SimulationContext and populates every field with a sane, hardcoded default value. This ensures the simulation starts from a known, predictable state.-func_config_file option to load a list of function names allowed to produce log output. This configuration (the file path and the list of function names) is stored within the SimulationContext for later reference and cleanup.PetscOptionsGet... calls for every possible command-line flag, overriding the default values set in step 1.| [in] | argc | Argument count passed from main. |
| [in] | argv | Argument vector passed from main. |
| [out] | p_simCtx | On success, this will point to the newly created and fully configured SimulationContext pointer. The caller is responsible for eventually destroying this object by calling FinalizeSimulation(). |
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 50 of file setup.c.
| PetscBool RuntimeWalltimeGuardParsePositiveSeconds | ( | const char * | text, |
| PetscReal * | seconds_out | ||
| ) |
Parse a positive floating-point seconds value from runtime metadata.
This helper is used for shell-exported walltime metadata such as PICURV_JOB_START_EPOCH and PICURV_WALLTIME_LIMIT_SECONDS.
| [in] | text | String to parse. |
| [out] | seconds_out | Parsed positive seconds value when successful. |
PETSC_TRUE when parsing succeeds, else PETSC_FALSE.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 18 of file setup.c.
| PetscErrorCode SetupSimulationEnvironment | ( | SimCtx * | simCtx | ) |
Verifies and prepares the complete I/O environment for a simulation run.
This function performs a comprehensive series of checks and setup actions to ensure a valid and clean environment. It is parallel-safe; all filesystem operations and checks are performed by Rank 0, with collective error handling.
The function's responsibilities include:
restart_dir or post-processing source directories exist when needed.| [in] | simCtx | The fully configured SimulationContext object. |
Verifies and prepares the complete I/O environment for a simulation run.
Local to this translation unit.
Definition at line 813 of file setup.c.
| PetscErrorCode SetupGridAndSolvers | ( | SimCtx * | simCtx | ) |
The main orchestrator for setting up all grid-related components.
This function is the high-level driver for creating the entire computational domain, including the multigrid hierarchy, PETSc DMDA and Vec objects, and calculating all necessary grid metrics.
| simCtx | The fully configured SimulationContext. |
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 1132 of file setup.c.
| PetscErrorCode CreateAndInitializeAllVectors | ( | SimCtx * | simCtx | ) |
Creates and initializes all PETSc Vec objects for all fields.
This function iterates through every UserCtx in the multigrid and multi-block hierarchy. For each context, it creates the comprehensive set of global and local PETSc Vecs required by the flow solver (e.g., Ucont, P, Nvert, metrics, turbulence fields, etc.). Each vector is initialized to zero.
Creates and initializes all PETSc Vec objects for all fields.
Local to this translation unit.
Definition at line 1168 of file setup.c.
| PetscErrorCode UpdateLocalGhosts | ( | UserCtx * | user, |
| const char * | fieldName | ||
| ) |
Updates the local vector (including ghost points) from its corresponding global vector.
This function identifies the correct global vector, local vector, and DM based on the provided fieldName and performs the standard PETSc DMGlobalToLocalBegin/End sequence. Includes optional debugging output (max norms before/after).
| user | The UserCtx structure containing the vectors and DMs. |
| fieldName | The name of the field to update ("Ucat", "Ucont", "P", "Nvert", etc.). |
Updates the local vector (including ghost points) from its corresponding global vector.
Local to this translation unit.
Definition at line 1361 of file setup.c.
| PetscErrorCode SetupBoundaryConditions | ( | SimCtx * | simCtx | ) |
(Orchestrator) Sets up all boundary conditions for the simulation.
| simCtx | Simulation context controlling the operation. |
(Orchestrator) Sets up all boundary conditions for the simulation.
Local to this translation unit.
Definition at line 1633 of file setup.c.
| PetscErrorCode Allocate3DArrayScalar | ( | PetscReal **** | array, |
| PetscInt | nz, | ||
| PetscInt | ny, | ||
| PetscInt | nx | ||
| ) |
Allocates a 3D array of PetscReal values using PetscCalloc.
This function dynamically allocates memory for a 3D array of PetscReal values with dimensions nz (layers) x ny (rows) x nx (columns). It uses PetscCalloc1 to ensure the memory is zero-initialized.
The allocation is done in three steps:
This setup allows the array to be accessed as array[k][j][i], and the memory for the data is contiguous, which improves cache efficiency.
| [out] | array | Pointer to the 3D array to be allocated. |
| [in] | nz | Number of layers (z-direction). |
| [in] | ny | Number of rows (y-direction). |
| [in] | nx | Number of columns (x-direction). |
Allocates a 3D array of PetscReal values using PetscCalloc.
Local to this translation unit.
Definition at line 1689 of file setup.c.
| PetscErrorCode Deallocate3DArrayScalar | ( | PetscReal *** | array, |
| PetscInt | nz, | ||
| PetscInt | ny | ||
| ) |
Deallocates a 3D array of PetscReal values allocated by Allocate3DArrayScalar.
This function frees the memory allocated for a 3D array of PetscReal values. It assumes the memory was allocated using Allocate3DArrayScalar, which allocated three separate memory blocks: one for the contiguous data, one for the row pointers, and one for the layer pointers.
| [in] | array | Pointer to the 3D array to be deallocated. |
| [in] | nz | Number of layers (z-direction). |
| [in] | ny | Number of rows (y-direction). |
Deallocates a 3D array of PetscReal values allocated by Allocate3DArrayScalar.
Local to this translation unit.
Definition at line 1724 of file setup.c.
| PetscErrorCode Allocate3DArrayVector | ( | Cmpnts **** | array, |
| PetscInt | nz, | ||
| PetscInt | ny, | ||
| PetscInt | nx | ||
| ) |
Allocates a contiguous 3D array of Cmpnts values.
The memory layout mirrors Allocate3DArrayScalar: layer pointers, row pointers, and contiguous payload are allocated such that indexing as array[k][j][i] is valid while keeping payload data contiguous.
| [out] | array | Pointer to the 3D vector array to allocate. |
| [in] | nz | Number of layers in the z-direction. |
| [in] | ny | Number of rows in the y-direction. |
| [in] | nx | Number of columns in the x-direction. |
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 1767 of file setup.c.
| PetscErrorCode Deallocate3DArrayVector | ( | Cmpnts *** | array, |
| PetscInt | nz, | ||
| PetscInt | ny | ||
| ) |
Deallocates a 3D array of Cmpnts structures allocated by Allocate3DArrayVector.
This function frees the memory allocated for a 3D array of Cmpnts structures. It assumes the memory was allocated using Allocate3DArrayVector, which created three separate memory blocks: one for the contiguous vector data, one for the row pointers, and one for the layer pointers.
| [in] | array | Pointer to the 3D array to be deallocated. |
| [in] | nz | Number of layers in the z-direction. |
| [in] | ny | Number of rows in the y-direction. |
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 1817 of file setup.c.
| PetscErrorCode GetOwnedCellRange | ( | const DMDALocalInfo * | info_nodes, |
| PetscInt | dim, | ||
| PetscInt * | xs_cell_global_out, | ||
| PetscInt * | xm_cell_local_out | ||
| ) |
Determines the global starting index and number of CELLS owned by the current processor in a specified dimension.
Ownership is defined by the rank owning the cell's origin node (min i,j,k corner).
| [in] | info_nodes | Pointer to the DMDALocalInfo struct obtained from the NODE-based DMDA (e.g., user->da or user->fda, assuming they have consistent nodal partitioning for defining cell origins). |
| [in] | dim | The dimension to compute the range for (0 for x/i, 1 for y/j, 2 for z/k). |
| [out] | xs_cell_global_out | Pointer to store the starting global cell index owned by this process. |
| [out] | xm_cell_local_out | Pointer to store the number of owned cells in this dimension. |
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 1883 of file setup.c.
| PetscErrorCode ComputeAndStoreNeighborRanks | ( | UserCtx * | user | ) |
Computes and stores the Cartesian neighbor ranks for the DMDA decomposition.
This function retrieves the neighbor information from the primary DMDA (user->da) and stores the face neighbors (xm, xp, ym, yp, zm, zp) in the user->neighbors structure. It assumes a standard PETSc ordering for the neighbors array returned by DMDAGetNeighbors. Logs warnings if the assumed indices seem incorrect (e.g., center rank mismatch).
| [in,out] | user | Pointer to the UserCtx structure where neighbor info will be stored. |
Computes and stores the Cartesian neighbor ranks for the DMDA decomposition.
Local to this translation unit.
Definition at line 1980 of file setup.c.
| PetscErrorCode SetDMDAProcLayout | ( | DM | dm, |
| UserCtx * | user | ||
| ) |
Sets the processor layout for a given DMDA based on PETSc options.
Reads the desired number of processors in x, y, and z directions using PETSc options (e.g., -dm_processors_x, -dm_processors_y, -dm_processors_z). If an option is not provided for a direction, PETSC_DECIDE is used for that direction. Applies the layout using DMDASetNumProcs.
Also stores the retrieved/decided values in user->procs_x/y/z if user context is provided.
| dm | The DMDA object to configure the layout for. |
| user | Pointer to the UserCtx structure (optional, used to store layout values). |
Sets the processor layout for a given DMDA based on PETSc options.
Local to this translation unit.
Definition at line 2096 of file setup.c.
| PetscErrorCode SetupDomainRankInfo | ( | SimCtx * | simCtx | ) |
Sets up the full rank communication infrastructure, including neighbor ranks and bounding box exchange.
This function orchestrates the following steps:
The final result is that each rank has access to its immediate neighbors and the bounding box information of all ranks.
| [in,out] | simCtx | Pointer to initialized simulation context that owns all block UserCtx objects. |
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 2174 of file setup.c.
| PetscErrorCode Contra2Cart | ( | UserCtx * | user | ) |
Reconstructs Cartesian velocity (Ucat) at cell centers from contravariant velocity (Ucont) defined on cell faces.
This function performs the transformation from a contravariant velocity representation (which is natural on a curvilinear grid) to a Cartesian (x,y,z) representation. For each interior computational cell owned by the rank, it performs the following:
[MetricTensor] * [ucat] = [ucont] for the Cartesian velocity vector ucat = (u,v,w) using Cramer's rule.user->Ucat vector.The function operates on local, ghosted versions of the input vectors (user->lUcont, user->lCsi, etc.) to ensure stencils are valid across processor boundaries.
| [in,out] | user | Pointer to the UserCtx structure. The function reads from user->lUcont, user->lCsi, user->lEta, user->lZet, user->lNvert and writes to the global user->Ucat vector. |
user->lUcont and all local metric vectors (user->lCsi, etc.) have been populated with up-to-date ghost values via UpdateLocalGhosts.Ucat for interior cells (not on physical boundaries) and for cells not marked as solid/blanked by user->lNvert.user->Ucat and calling UpdateLocalGhosts(user, "Ucat") to populate user->lUcat.Reconstructs Cartesian velocity (Ucat) at cell centers from contravariant velocity (Ucont) defined on cell faces.
Local to this translation unit.
Definition at line 2247 of file setup.c.
| PetscErrorCode SetupDomainCellDecompositionMap | ( | UserCtx * | user | ) |
Creates and distributes a map of the domain's cell decomposition to all ranks.
This function is a critical part of the simulation setup. It determines the global cell ownership for each MPI rank and makes this information available to all other ranks. This "decomposition map" is essential for the robust "Walk and Handoff" particle migration strategy, allowing any rank to quickly identify the owner of a target cell.
The process involves:
GetOwnedCellRange helper function.MPI_Allgather collective operation to build a complete array (user->RankCellInfoMap) containing the ownership information for every rank.This function should be called once during initialization after the primary DMDA (user->da) has been set up.
| [in,out] | user | Pointer to the UserCtx structure. The function will allocate and populate user->RankCellInfoMap and set user->num_ranks. |
Creates and distributes a map of the domain's cell decomposition to all ranks.
Local to this translation unit.
Definition at line 2383 of file setup.c.
| PetscErrorCode BinarySearchInt64 | ( | PetscInt | n, |
| const PetscInt64 | arr[], | ||
| PetscInt64 | key, | ||
| PetscBool * | found | ||
| ) |
Performs a binary search for a key in a sorted array of PetscInt64.
This is a standard binary search algorithm implemented as a PETSc-style helper function. It efficiently determines if a given key exists within a sorted array.
| [in] | n | The number of elements in the array. |
| [in] | arr | A pointer to the sorted array of PetscInt64 values to be searched. |
| [in] | key | The PetscInt64 value to search for. |
| [out] | found | A pointer to a PetscBool that will be set to PETSC_TRUE if the key is found, and PETSC_FALSE otherwise. |
arr must be sorted in ascending order for the algorithm to work correctly.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 2448 of file setup.c.
| PetscErrorCode ComputeDivergence | ( | UserCtx * | user | ) |
Computes the discrete divergence of the contravariant velocity field.
This diagnostic/kernel routine evaluates continuity residuals on the local block and writes the resulting divergence field into the configured output vector(s).
| [in,out] | user | Block-level context containing velocity and metric fields. |
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 2518 of file setup.c.
| PetscErrorCode InitializeRandomGenerators | ( | UserCtx * | user, |
| PetscRandom * | randx, | ||
| PetscRandom * | randy, | ||
| PetscRandom * | randz | ||
| ) |
Initializes random number generators for assigning particle properties.
This function creates and configures separate PETSc random number generators for the x, y, and z coordinates.
| [in,out] | user | Pointer to the UserCtx structure containing simulation context. |
| [out] | randx | Pointer to store the RNG for the x-coordinate. |
| [out] | randy | Pointer to store the RNG for the y-coordinate. |
| [out] | randz | Pointer to store the RNG for the z-coordinate. |
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 2684 of file setup.c.
| PetscErrorCode InitializeLogicalSpaceRNGs | ( | PetscRandom * | rand_logic_i, |
| PetscRandom * | rand_logic_j, | ||
| PetscRandom * | rand_logic_k | ||
| ) |
Initializes random number generators for logical space operations [0.0, 1.0).
This function creates and configures three separate PETSc random number generators, one for each logical dimension (i, j, k or xi, eta, zeta equivalent). Each RNG is configured to produce uniformly distributed real numbers in the interval [0.0, 1.0). These are typically used for selecting owned cells or generating intra-cell logical coordinates.
| [out] | rand_logic_i | Pointer to store the RNG for the i-logical dimension. |
| [out] | rand_logic_j | Pointer to store the RNG for the j-logical dimension. |
| [out] | rand_logic_k | Pointer to store the RNG for the k-logical dimension. |
Initializes random number generators for logical space operations [0.0, 1.0).
Local to this translation unit.
Definition at line 2725 of file setup.c.
| PetscErrorCode InitializeBrownianRNG | ( | SimCtx * | simCtx | ) |
Initializes a single master RNG for time-stepping physics (Brownian motion).
Configures it for Uniform [0, 1) which is required for Box-Muller transformation.
| [in,out] | simCtx | Pointer to the Simulation Context. |
Initializes a single master RNG for time-stepping physics (Brownian motion).
Local to this translation unit.
Definition at line 2769 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 | ||
| ) |
Transforms scalar derivatives from computational space to physical space.
using the chain rule. Formula: dPhi/dx = J * ( dPhi/dCsi * dCsi/dx + dPhi/dEta * dEta/dx + ... )
| jacobian | Parameter jacobian passed to TransformScalarDerivativesToPhysical(). |
| csi_metrics | Parameter csi_metrics passed to TransformScalarDerivativesToPhysical(). |
| eta_metrics | Parameter eta_metrics passed to TransformScalarDerivativesToPhysical(). |
| zet_metrics | Parameter zet_metrics passed to TransformScalarDerivativesToPhysical(). |
| dPhi_dcsi | Parameter dPhi_dcsi passed to TransformScalarDerivativesToPhysical(). |
| dPhi_deta | Parameter dPhi_deta passed to TransformScalarDerivativesToPhysical(). |
| dPhi_dzet | Parameter dPhi_dzet passed to TransformScalarDerivativesToPhysical(). |
| gradPhi | Parameter gradPhi passed to 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 2808 of file setup.c.
| PetscErrorCode ComputeScalarFieldDerivatives | ( | UserCtx * | user, |
| PetscInt | i, | ||
| PetscInt | j, | ||
| PetscInt | k, | ||
| PetscReal *** | field_data, | ||
| Cmpnts * | grad | ||
| ) |
Computes the gradient of a cell-centered SCALAR field at a specific grid point.
| user | The |
| i | Parameter i passed to ComputeScalarFieldDerivatives(). |
| j | Parameter j passed to ComputeScalarFieldDerivatives(). |
| k | Parameter k passed to ComputeScalarFieldDerivatives(). |
| field_data | 3D |
| grad | Output: |
Computes the gradient of a cell-centered SCALAR field at a specific grid point.
Local to this translation unit.
Definition at line 2857 of file setup.c.
| PetscErrorCode ComputeVectorFieldDerivatives | ( | UserCtx * | user, |
| PetscInt | i, | ||
| PetscInt | j, | ||
| PetscInt | k, | ||
| Cmpnts *** | field_data, | ||
| Cmpnts * | dudx, | ||
| Cmpnts * | dvdx, | ||
| Cmpnts * | dwdx | ||
| ) |
Computes the derivatives of a cell-centered vector field at a specific grid point.
This function orchestrates the calculation of spatial derivatives. It first computes the derivatives in computational space (d/dcsi, d/deta, d/dzet) using a central difference scheme and then transforms them into physical space (d/dx, d/dy, d/dz).
| user | The |
| i | Parameter i passed to ComputeVectorFieldDerivatives(). |
| j | Parameter j passed to ComputeVectorFieldDerivatives(). |
| k | Parameter k passed to ComputeVectorFieldDerivatives(). |
| field_data | A |
| dudx | Output: |
| dvdx | Output: |
| dwdx | Output: |
Computes the derivatives of a cell-centered vector field at a specific grid point.
Local to this translation unit.
Definition at line 2900 of file setup.c.
| PetscErrorCode DestroyUserVectors | ( | UserCtx * | user | ) |
Destroys all PETSc Vec objects within a single UserCtx structure.
This helper function systematically destroys all ~74 Vec objects stored in a UserCtx. The vectors are organized into 14 groups (A-N) for clarity:
All destroys are protected with NULL checks to handle conditional allocations safely.
| [in,out] | user | Pointer to the UserCtx containing the vectors to destroy. |
Destroys all PETSc Vec objects within a single UserCtx structure.
Local to this translation unit.
Definition at line 2954 of file setup.c.
| PetscErrorCode DestroyUserContext | ( | UserCtx * | user | ) |
Destroys all resources allocated within a single UserCtx structure.
This function cleans up all memory and PETSc objects associated with a single UserCtx (grid level). It calls the helper functions and destroys remaining objects in the proper dependency order:
This function should be called for each UserCtx in the multigrid hierarchy.
| [in,out] | user | Pointer to the UserCtx to be destroyed. |
Destroys all resources allocated within a single UserCtx structure.
Local to this translation unit.
Definition at line 3089 of file setup.c.
| PetscErrorCode FinalizeSimulation | ( | SimCtx * | simCtx | ) |
Main cleanup function for the entire simulation context.
This function is responsible for destroying ALL memory and PETSc objects allocated during the simulation, including:
This function should be called ONCE at the end of the simulation, after all computation is complete, but BEFORE PetscFinalize().
Call order in main:
| [in,out] | simCtx | Pointer to the master SimulationContext to be destroyed. |
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 3188 of file setup.c.