5#include <petscdmswarm.h>
11#include <petscdmcomposite.h>
12#include <petscsystypes.h>
71#define Allocate3DArray(array, nz, ny, nx) \
73 PetscReal ****: Allocate3DArrayScalar, \
74 Cmpnts ****: Allocate3DArrayVector \
78#define Deallocate3DArray(array, nz, ny) \
80 PetscReal ***: Deallocate3DArrayScalar, \
81 Cmpnts ***: Deallocate3DArrayVector \
349 PetscInt *xs_cell_global_out,
350 PetscInt *xm_cell_local_out);
363 periodic[0] = (PetscBool)(simCtx->
i_periodic != 0);
364 periodic[1] = (PetscBool)(simCtx->
j_periodic != 0);
365 periodic[2] = (PetscBool)(simCtx->
k_periodic != 0);
380 const PetscInt m[3] = {info->mx, info->my, info->mz};
381 const PetscInt start[3] = {info->xs, info->ys, info->zs};
382 const PetscInt end[3] = {info->xs + info->xm, info->ys + info->ym, info->zs + info->zm};
384 for (PetscInt a = 0; a < 3; a++) {
385 lo[a] = (start[a] == 0) ? 1 : start[a];
386 hi[a] = (end[a] == m[a]) ? m[a] - 1 : end[a];
504 PetscInt i, PetscInt j, PetscInt k,
Cmpnts w,
Cmpnts *ucat)
506 PetscFunctionBeginUser;
511 mat[0][0] = (1.0 - w.
x) * lcsi[k][j][i-1].x + w.
x * lcsi[k][j][i].
x;
512 mat[0][1] = (1.0 - w.
x) * lcsi[k][j][i-1].y + w.
x * lcsi[k][j][i].
y;
513 mat[0][2] = (1.0 - w.
x) * lcsi[k][j][i-1].z + w.
x * lcsi[k][j][i].
z;
515 mat[1][0] = (1.0 - w.
y) * leta[k][j-1][i].x + w.
y * leta[k][j][i].
x;
516 mat[1][1] = (1.0 - w.
y) * leta[k][j-1][i].y + w.
y * leta[k][j][i].
y;
517 mat[1][2] = (1.0 - w.
y) * leta[k][j-1][i].z + w.
y * leta[k][j][i].
z;
519 mat[2][0] = (1.0 - w.
z) * lzet[k-1][j][i].x + w.
z * lzet[k][j][i].
x;
520 mat[2][1] = (1.0 - w.
z) * lzet[k-1][j][i].y + w.
z * lzet[k][j][i].
y;
521 mat[2][2] = (1.0 - w.
z) * lzet[k-1][j][i].z + w.
z * lzet[k][j][i].
z;
525 q[0] = (1.0 - w.
x) * lucont[k][j][i-1].x + w.
x * lucont[k][j][i].
x;
526 q[1] = (1.0 - w.
y) * lucont[k][j-1][i].y + w.
y * lucont[k][j][i].
y;
527 q[2] = (1.0 - w.
z) * lucont[k-1][j][i].z + w.
z * lucont[k][j][i].
z;
530 PetscReal det = mat[0][0] * (mat[1][1] * mat[2][2] - mat[1][2] * mat[2][1]) -
531 mat[0][1] * (mat[1][0] * mat[2][2] - mat[1][2] * mat[2][0]) +
532 mat[0][2] * (mat[1][0] * mat[2][1] - mat[1][1] * mat[2][0]);
534 if (PetscAbsReal(det) < 1.0e-18) {
535 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FLOP_COUNT,
"Transformation matrix determinant is near zero at cell (%" PetscInt_FMT
",%" PetscInt_FMT
",%" PetscInt_FMT
") \n", i, j, k);
538 PetscReal det_inv = 1.0 / det;
540 PetscReal det0 = q[0] * (mat[1][1] * mat[2][2] - mat[1][2] * mat[2][1]) -
541 q[1] * (mat[0][1] * mat[2][2] - mat[0][2] * mat[2][1]) +
542 q[2] * (mat[0][1] * mat[1][2] - mat[0][2] * mat[1][1]);
544 PetscReal det1 = -q[0] * (mat[1][0] * mat[2][2] - mat[1][2] * mat[2][0]) +
545 q[1] * (mat[0][0] * mat[2][2] - mat[0][2] * mat[2][0]) -
546 q[2] * (mat[0][0] * mat[1][2] - mat[0][2] * mat[1][0]);
548 PetscReal det2 = q[0] * (mat[1][0] * mat[2][1] - mat[1][1] * mat[2][0]) -
549 q[1] * (mat[0][0] * mat[2][1] - mat[0][1] * mat[2][0]) +
550 q[2] * (mat[0][0] * mat[1][1] - mat[0][1] * mat[1][0]);
552 ucat->
x = det0 * det_inv;
553 ucat->
y = det1 * det_inv;
554 ucat->
z = det2 * det_inv;
555 PetscFunctionReturn(0);
618PetscErrorCode
BinarySearchInt64(PetscInt n,
const PetscInt64 arr[], PetscInt64 key, PetscBool *found);
668 PetscReal ***field_data,
Cmpnts *grad);
Header file for Particle Motion and migration related functions.
Header file for Particle Swarm management functions.
Authoritative identities and storage metadata for persistent Eulerian fields.
FieldId
Compile-time identity for a catalogued Eulerian field.
Non-owning runtime objects resolved for one field and UserCtx.
Public interface for grid, solver, and metric setup routines.
Public interface for data input/output routines.
Logging utilities and macros for PETSc-based applications.
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.
int PicurvCheckLinkedPetscIndexWidth(int argc, char **argv, const char *executable_name)
Refuse to start when the loaded libpetsc's PetscInt width differs from this build's.
PetscErrorCode DestroyUserContext(UserCtx *user)
Destroys all resources allocated within a single UserCtx structure.
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 specifie...
static void GetOwnedInteriorCellBounds(const DMDALocalInfo *info, PetscInt lo[3], PetscInt hi[3])
Index bounds of the interior cells this rank owns in the solver's cell-centred layout: the owned rang...
PetscErrorCode SetupDomainRankInfo(SimCtx *simCtx)
Sets up the full rank communication infrastructure, including neighbor ranks and bounding box exchang...
PetscErrorCode Deallocate3DArrayVector(Cmpnts ***array, PetscInt nz, PetscInt ny)
Deallocates a 3D array of Cmpnts structures allocated by Allocate3DArrayVector.
PetscErrorCode SetupGridAndSolvers(SimCtx *simCtx)
The main orchestrator for setting up all grid-related components.
static PetscErrorCode ContravariantToCartesianInCell(Cmpnts ***lucont, Cmpnts ***lcsi, Cmpnts ***leta, Cmpnts ***lzet, PetscInt i, PetscInt j, PetscInt k, Cmpnts w, Cmpnts *ucat)
Cartesian velocity at a point of one cell from the cell's face fluxes.
PetscErrorCode SetupSimulationEnvironment(SimCtx *simCtx)
Verifies and prepares the complete I/O environment for a simulation run.
PetscErrorCode CreateAndInitializeAllVectors(SimCtx *simCtx)
Creates and initializes all PETSc Vec objects for all fields.
PetscErrorCode ComputeAndStoreNeighborRanks(UserCtx *user)
Computes and stores the Cartesian neighbor ranks for the DMDA decomposition.
PetscErrorCode Contra2Cart(UserCtx *user)
Reconstructs Cartesian velocity (Ucat) at cell centers from contravariant velocity (Ucont) defined on...
PetscErrorCode PicurvCheckPetscIntRange(MPI_Comm comm, PetscInt64 entries, const char *object)
Refuse a PETSc object whose global size this build's PetscInt cannot index.
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.
int PicurvHandleVersionArgument(int argc, char **argv, const char *executable_name)
Print the shared native build identity when a version flag is present.
PetscErrorCode DestroySolutionConvergenceState(SimCtx *simCtx)
Frees any runtime storage allocated for solution-convergence logging.
PetscErrorCode Allocate3DArrayScalar(PetscReal ****array, PetscInt nz, PetscInt ny, PetscInt nx)
Allocates a 3D array of PetscReal values using PetscCalloc.
PetscErrorCode CreateSimulationContext(int argc, char **argv, SimCtx **p_simCtx)
Allocates and populates the master SimulationContext object.
PetscErrorCode InitializeSolutionConvergenceState(SimCtx *simCtx)
Allocates any runtime storage required by solution-convergence logging.
PetscErrorCode SetDMDAProcLayout(DM dm, UserCtx *user)
Sets the processor layout for a given DMDA based on PETSc options.
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 ComputeDivergence(UserCtx *user)
Computes the discrete divergence of the contravariant velocity field.
PetscErrorCode UpdateLocalGhosts(UserCtx *user, FieldId field_id)
Updates the local vector (including ghost points) from its corresponding global vector.
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 Cart2Contra(UserCtx *user)
Convert the ghosted Cartesian velocity field to contravariant face fluxes.
PetscErrorCode DestroyUserVectors(UserCtx *user)
Destroys all PETSc Vec objects within a single UserCtx structure.
PetscErrorCode Allocate3DArrayVector(Cmpnts ****array, PetscInt nz, PetscInt ny, PetscInt nx)
Allocates a contiguous 3D array of Cmpnts values.
PetscErrorCode SetupBoundaryConditions(SimCtx *simCtx)
(Orchestrator) Sets up all boundary conditions for the simulation.
static void GetPeriodicAxes(const SimCtx *simCtx, PetscBool periodic[3])
Which grid axes are periodic.
PetscErrorCode LESConfigSetDefaults(LESConfig *config)
Installs the shipped defaults for every LES closure parameter.
PetscErrorCode SetupDomainCellDecompositionMap(UserCtx *user)
Creates and distributes a map of the domain's cell decomposition to all ranks.
PetscErrorCode FinalizeSimulation(SimCtx *simCtx)
Main cleanup function for the entire simulation context.
PetscErrorCode RepairPeriodicFieldGhosts(UserCtx *user, const FieldView *view, Vec local_vec)
Applies a catalogued field's periodic normal-face ghost repair to a local vector.
PetscErrorCode Deallocate3DArrayScalar(PetscReal ***array, PetscInt nz, PetscInt ny)
Deallocates a 3D array of PetscReal values allocated by Allocate3DArrayScalar.
PetscBool RuntimeWalltimeGuardParsePositiveSeconds(const char *text, PetscReal *seconds_out)
Parse a positive floating-point seconds value from runtime metadata.
Main header file for a complex fluid dynamics solver.
A 3D point or vector with PetscScalar components.
Every user-selectable parameter of the LES closure.
The master context for the entire simulation.
User-defined context containing data specific to a single computational grid level.
Header file for particle location functions using the walking search algorithm.