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 <petscdmcomposite.h>
#include <petscerror.h>
#include <petscsys.h>
#include "variables.h"
#include "ParticleSwarm.h"
#include "walkingsearch.h"
#include "grid.h"
#include "logging.h"
#include "io.h"
#include "setup.h"
Go to the source code of this file.
Macros | |
#define | NUM_WEIGHTS 8 |
#define | InterpolateFieldFromCornerToCenter(field, centfield, user) |
Generic macro to call the appropriate interpolation function based on the field type. | |
#define | InterpolateFieldFromCenterToCorner(blockSize, centfield_ptr, corner_ptr, user_ctx) |
Macro to dispatch to the correct scalar or vector center-to-corner function based on a runtime block size variable. | |
#define | InterpolateCornerToFaceCenter(corner_arr, faceX_arr, faceY_arr, faceZ_arr, user_ctx) |
A type-generic macro that interpolates a field from corner nodes to all face centers. | |
#define | PieceWiseLinearInterpolation(fieldName, fieldPtr, i, j, k, outPtr) |
Macro that calls either the scalar or vector piecewise interpolation function based on the type of the fieldPtr parameter (3D array). | |
#define | TrilinearInterpolation(fieldName, fieldPtr, i, j, k, a1, a2, a3, outPtr) |
Macro that calls either the scalar or vector trilinear interpolation function based on the type of the fieldPtr parameter (3D array). | |
Functions | |
PetscErrorCode | TrilinearInterpolation_Scalar (const char *fieldName, PetscReal ***fieldScal, PetscInt i, PetscInt j, PetscInt k, PetscReal a1, PetscReal a2, PetscReal a3, PetscReal *val) |
Computes the trilinear interpolated scalar at a given point. | |
PetscErrorCode | TrilinearInterpolation_Vector (const char *fieldName, Cmpnts ***fieldVec, PetscInt i, PetscInt j, PetscInt k, PetscReal a1, PetscReal a2, PetscReal a3, Cmpnts *vec) |
Computes the trilinear interpolated vector (e.g., velocity) at a given point. | |
PetscErrorCode | InterpolateEulerFieldToSwarm (UserCtx *user, Vec fieldLocal_cellCentered, const char *fieldName, const char *swarmOutFieldName) |
Interpolates a cell-centered field (scalar or vector) onto DMSwarm particles, using a robust, PETSc-idiomatic two-stage process. | |
PetscErrorCode | InterpolateAllFieldsToSwarm (UserCtx *user) |
Interpolates all relevant fields from the DMDA to the DMSwarm. | |
PetscErrorCode | InterpolateParticleVelocities (UserCtx *user) |
Interpolates particle velocities using trilinear interpolation. | |
PetscErrorCode | InterpolateFieldFromCornerToCenter_Scalar (PetscReal ***field, PetscReal ***centfield, UserCtx *user) |
Safely interpolate a scalar field from corner nodes (from the coordinate DM) to cell centers (from the cell-centered DM) using the provided UserCtx. | |
PetscErrorCode | InterpolateFieldFromCornerToCenter_Vector (Cmpnts ***field, Cmpnts ***centfield, UserCtx *user) |
Safely interpolate a vector field from corner nodes (from the coordinate DM) to cell centers (from the cell-centered DM) using the provided UserCtx. | |
PetscErrorCode | InterpolateFieldFromCenterToCorner_Scalar (PetscReal ***field_arr, PetscReal ***centfield_arr, UserCtx *user) |
Interpolates a scalar field from cell centers to corner nodes. | |
PetscErrorCode | InterpolateFieldFromCenterToCorner_Vector (Cmpnts ***field_arr, Cmpnts ***centfield_arr, UserCtx *user) |
Interpolates a vector field from cell centers to corner nodes. | |
PetscErrorCode | InterpolateFieldFromCenterToCorner_Vector_Petsc (Cmpnts ***centfield_arr, Cmpnts ***corner_arr, UserCtx *user) |
Interpolates a vector field from cell centers to corner nodes. | |
PetscErrorCode | InterpolateFieldFromCenterToCorner_Scalar_Petsc (PetscReal ***centfield_arr, PetscReal ***corner_arr, UserCtx *user) |
Interpolates a scalar field from cell centers to corner nodes. | |
PetscErrorCode | GetScatterTargetInfo (UserCtx *user, const char *particleFieldName, DM *targetDM, PetscInt *expected_dof) |
Determines the target Eulerian DM and expected DOF for scattering a given particle field. | |
PetscErrorCode | AccumulateParticleField (DM swarm, const char *particleFieldName, DM gridSumDM, Vec gridSumVec) |
Accumulates a particle field (scalar or vector) into a target grid sum vector. | |
PetscErrorCode | NormalizeGridVectorByCount (DM countDM, Vec countVec, DM dataDM, Vec sumVec, Vec avgVec) |
Normalizes a grid vector of sums by a grid vector of counts to produce an average. | |
PetscErrorCode | ScatterParticleFieldToEulerField (UserCtx *user, const char *particleFieldName, Vec eulerFieldAverageVec) |
Scatters a particle field (scalar or vector) to the corresponding Eulerian field average. | |
PetscErrorCode | ScatterAllParticleFieldsToEulerFields (UserCtx *user) |
Scatters a predefined set of particle fields to their corresponding Eulerian fields. | |
PetscErrorCode | InterpolateCornerToFaceCenter_Scalar (PetscReal ***corner_arr, PetscReal ***faceX_arr, PetscReal ***faceY_arr, PetscReal ***faceZ_arr, UserCtx *user) |
Interpolates a scalar field from corner nodes to all face centers. | |
PetscErrorCode | InterpolateCornerToFaceCenter_Vector (Cmpnts ***corner_arr, Cmpnts ***faceX_arr, Cmpnts ***faceY_arr, Cmpnts ***faceZ_arr, UserCtx *user) |
Interpolates a vector field from corner nodes to all face centers. | |
#define NUM_WEIGHTS 8 |
Definition at line 24 of file interpolation.h.
#define InterpolateFieldFromCornerToCenter | ( | field, | |
centfield, | |||
user | |||
) |
Generic macro to call the appropriate interpolation function based on the field type.
This macro will select either the scalar or vector interpolation function based on the type of the 'field' pointer. It also performs a compile-time check that 'centfield' is of the same type as 'field'. If the types are not the same, a compile-time error is produced.
Usage: InterpolateFieldFromCornerToCenter(field, centfield, user);
Definition at line 36 of file interpolation.h.
#define InterpolateFieldFromCenterToCorner | ( | blockSize, | |
centfield_ptr, | |||
corner_ptr, | |||
user_ctx | |||
) |
Macro to dispatch to the correct scalar or vector center-to-corner function based on a runtime block size variable.
This macro uses a ternary operator to inspect the runtime value of 'blockSize' and select the appropriate implementation. It expects the input and output pointers to be void* and handles casting them to the correct, strongly-typed pointers.
blockSize | The runtime block size (1 for scalar, 3 for vector). |
centfield_ptr | The input void* pointer to the 3D cell-centered data array. |
corner_ptr | The output void* pointer to the 3D corner data array. |
user_ctx | The UserCtx structure. |
Definition at line 64 of file interpolation.h.
#define InterpolateCornerToFaceCenter | ( | corner_arr, | |
faceX_arr, | |||
faceY_arr, | |||
faceZ_arr, | |||
user_ctx | |||
) |
A type-generic macro that interpolates a field from corner nodes to all face centers.
This macro uses C11's _Generic feature to dispatch to the appropriate underlying function based on the type of the input corner_arr
.
corner_arr
is of type PetscReal***
, it calls InterpolateCornerToFaceCenter_Scalar
.corner_arr
is of type Cmpnts***
, it calls InterpolateCornerToFaceCenter_Vector
.corner_arr | Ghosted node-centered array (global indexing). The type of this argument determines which function is called. |
faceX_arr | Local array for X-faces. |
faceY_arr | Local array for Y-faces. |
faceZ_arr | Local array for Z-faces. |
user_ctx | User context containing DMDA 'fda'. |
Definition at line 87 of file interpolation.h.
#define PieceWiseLinearInterpolation | ( | fieldName, | |
fieldPtr, | |||
i, | |||
j, | |||
k, | |||
outPtr | |||
) |
Macro that calls either the scalar or vector piecewise interpolation function based on the type of the fieldPtr
parameter (3D array).
Usage example:
// For scalar: PetscReal ***fieldScal; PetscReal outVal; PieceWiseLinearInterpolation(fieldName, fieldScal, i, j, k, &outVal);
// For vector: Cmpnts ***fieldVec; Cmpnts vec; PieceWiseLinearInterpolation(fieldName, fieldVec, i, j, k, &vec);
Definition at line 109 of file interpolation.h.
#define TrilinearInterpolation | ( | fieldName, | |
fieldPtr, | |||
i, | |||
j, | |||
k, | |||
a1, | |||
a2, | |||
a3, | |||
outPtr | |||
) |
Macro that calls either the scalar or vector trilinear interpolation function based on the type of the fieldPtr
parameter (3D array).
Usage example:
PetscReal result; Cmpnts vec;
// For scalars: TrilinearInterpolation(fieldName, fieldScal, i, j, k, a1, a2, a3, &result);
// For vectors: TrilinearInterpolation(fieldName, fieldVec, i, j, k, a1, a2, a3, &vec);
Definition at line 130 of file interpolation.h.
PetscErrorCode TrilinearInterpolation_Scalar | ( | const char * | fieldName, |
PetscReal *** | fieldScal, | ||
PetscInt | i, | ||
PetscInt | j, | ||
PetscInt | k, | ||
PetscReal | a1, | ||
PetscReal | a2, | ||
PetscReal | a3, | ||
PetscReal * | val | ||
) |
Computes the trilinear interpolated scalar at a given point.
[in] | fieldName | A string representing the name of the scalar field (e.g., "temperature"). |
[in] | fieldScal | 3D array of the field from a DMDA (indexed as [k][j][i]), each cell a PetscReal. |
[in] | i,j,k | Integral cell indices (the "lower" corner in each dimension). |
[in] | a1,a2,a3 | Normalized coordinates within the cell ([0,1] range). |
[out] | val | Pointer to a PetscReal that will store the interpolated scalar. |
This function uses the standard 8-corner trilinear formula via ComputeTrilinearWeights()
. If a different scheme is desired, implement a new function with the same interface.
Computes the trilinear interpolated scalar at a given point.
[in] | fieldName | A string representing the name of the scalar field (e.g., "temperature"). |
[in] | fieldScal | 3D array of the field from a DMDA (indexed as [k][j][i]), each cell a PetscReal. |
[in] | i,j,k | Integral cell indices (the "lower" corner in each dimension). |
[in] | a1,a2,a3 | Normalized coordinates within the cell ([0,1] range). |
[out] | val | Pointer to a PetscReal that will store the Interpolateted scalar. |
This function uses the standard 8-corner trilinear formula via ComputeTrilinearWeights()
. If a different scheme is desired, implement a new function with the same PetscInterface.
Definition at line 884 of file interpolation.c.
PetscErrorCode TrilinearInterpolation_Vector | ( | const char * | fieldName, |
Cmpnts *** | fieldVec, | ||
PetscInt | i, | ||
PetscInt | j, | ||
PetscInt | k, | ||
PetscReal | a1, | ||
PetscReal | a2, | ||
PetscReal | a3, | ||
Cmpnts * | vec | ||
) |
Computes the trilinear interpolated vector (e.g., velocity) at a given point.
[in] | fieldName | A string representing the name of the vector field (e.g., "velocity"). |
[in] | fieldVec | 3D array of the field from a DMDA (indexed as [k][j][i]), each cell of type Cmpnts. |
[in] | i,j,k | Integral cell indices (the "lower" corner in each dimension). |
[in] | a1,a2,a3 | Normalized coordinates within the cell ([0,1] range). |
[out] | vec | Pointer to a Cmpnts struct that will store the interpolated vector (x, y, z). |
This function uses the standard 8-corner trilinear formula via ComputeTrilinearWeights()
. If a different scheme is desired, implement a new function with the same interface.
Computes the trilinear interpolated vector (e.g., velocity) at a given point.
[in] | fieldName | A string representing the name of the vector field (e.g., "velocity"). |
[in] | fieldVec | 3D array of the field from a DMDA (indexed as [k][j][i]), each cell of type Cmpnts. |
[in] | i,j,k | Integral cell indices (the "lower" corner in each dimension). |
[in] | a1,a2,a3 | Normalized coordinates within the cell ([0,1] range). |
[out] | vec | Pointer to a Cmpnts struct that will store the Interpolateted vector (x, y, z). |
This function uses the standard 8-corner trilinear formula via ComputeTrilinearWeights()
. If a different scheme is desired, implement a new function with the same PetscInterface.
Computes the trilinear Interpolateted vector at a given point, with partial weighting if corners go out of range.
If any of the 8 corners (i or i+1, j or j+1, k or k+1) is out of [0..mx), [0..my), [0..mz), that corner is skipped and the corresponding weight is omitted. The total is normalized by the sum of used weights, so we get a partial Interpolatetion near boundaries.
Definition at line 962 of file interpolation.c.
PetscErrorCode InterpolateEulerFieldToSwarm | ( | UserCtx * | user, |
Vec | fieldLocal_cellCentered, | ||
const char * | fieldName, | ||
const char * | swarmOutFieldName | ||
) |
Interpolates a cell-centered field (scalar or vector) onto DMSwarm particles, using a robust, PETSc-idiomatic two-stage process.
This function first converts the cell-centered input data to corner-node data, storing this intermediate result in a PETSc Vec to correctly handle the communication of ghost-point information across parallel ranks. It then performs a final trilinear interpolation from the ghosted corner data to each particle's location.
Workflow:
cornerGlobal
, cornerLocal
) to manage the intermediate corner-node data, using the existing nodal DMDA (user->fda
).bs
) to select the correct underlying center-to-corner function, writing results into cornerGlobal
.DMGlobalToLocal
) to transfer the boundary data from cornerGlobal
into the ghost regions of cornerLocal
.cornerLocal
data.[in] | user | User context with DMDA, DMSwarm, etc. |
[in] | fieldGlobal_cellCentered | Vec (from fda) with cell-centered data (e.g., Ucat). |
[in] | fieldName | Human-readable field name for logging (e.g., "Ucat"). |
[in] | swarmOutFieldName | Name of the DMSwarm field where interpolation results go. |
Definition at line 1210 of file interpolation.c.
PetscErrorCode InterpolateAllFieldsToSwarm | ( | UserCtx * | user | ) |
Interpolates all relevant fields from the DMDA to the DMSwarm.
Currently, it interpolates:
To add more fields, duplicate the call to InterpolateOneFieldOverSwarm and provide:
[in,out] | user | Pointer to a UserCtx containing:
|
Currently, it Interpolatetes:
To add more fields, duplicate the call to InterpolateOneFieldOverSwarm and provide:
[in,out] | user | Pointer to a UserCtx containing:
|
Definition at line 1667 of file interpolation.c.
PetscErrorCode InterpolateParticleVelocities | ( | UserCtx * | user | ) |
Interpolates particle velocities using trilinear interpolation.
[in] | user | Pointer to the user-defined context containing grid and swarm information. |
PetscErrorCode InterpolateFieldFromCornerToCenter_Scalar | ( | PetscReal *** | field_arr, |
PetscReal *** | centfield_arr, | ||
UserCtx * | user | ||
) |
Safely interpolate a scalar field from corner nodes (from the coordinate DM) to cell centers (from the cell-centered DM) using the provided UserCtx.
For each cell center in the physical region of the cell-centered DM (fda), this function averages the up to 8 surrounding scalar values from the coordinate DM (da). On boundaries, where fewer corners are available, a partial average is computed.
The coordinate DM (da) is built on corners (IM+1 x JM+1 x KM+1) while the cell-centered DM (fda) covers the physical cells (IM x JM x KM). Index offsets are adjusted via DMDAGetLocalInfo.
[in] | field | 3D array of corner-based scalar data (from user->da). |
[out] | centfield | 3D array for the interpolated cell-center scalar data (for user->fda). |
[in] | user | User context containing:
|
Safely interpolate a scalar field from corner nodes (from the coordinate DM) to cell centers (from the cell-centered DM) using the provided UserCtx.
This function estimates the value of a scalar field at the center of each computational cell (whose origin node is owned by this rank) by averaging the values from the 8 corner nodes defining that cell.
[in] | field_arr | Input: 3D array view (ghosted) of scalar data at nodes, obtained from a Vec associated with user->da. Accessed via GLOBAL node indices. Ghost values must be up-to-date. |
[out] | centfield_arr | Output: 3D local array (0-indexed) where interpolated cell center values are stored. Sized [zm_cell_local][ym_cell_local][xm_cell_local] by the caller. centfield_arr[k_loc][j_loc][i_loc] stores the value for the cell corresponding to the (i_loc, j_loc, k_loc)-th owned cell origin. |
[in] | user | User context containing DMDA information (da, IM, JM, KM). |
Definition at line 157 of file interpolation.c.
PetscErrorCode InterpolateFieldFromCornerToCenter_Vector | ( | Cmpnts *** | field_arr, |
Cmpnts *** | centfield_arr, | ||
UserCtx * | user | ||
) |
Safely interpolate a vector field from corner nodes (from the coordinate DM) to cell centers (from the cell-centered DM) using the provided UserCtx.
For each cell center in the physical region of the cell-centered DM (fda), this function averages the 8 surrounding corner values from the coordinate DM (da). The coordinate DM (da) is built on corners (IM+1 x JM+1 x KM+1) while the cell-centered DM (fda) covers the physical cells (IM x JM x KM). Index offsets are adjusted using DMDAGetLocalInfo.
[in] | field | 3D array of corner-based vector data (from user->da). |
[out] | centfield | 3D array for the interpolated cell-center vector data (for user->fda). |
[in] | user | User context containing:
|
Safely interpolate a vector field from corner nodes (from the coordinate DM) to cell centers (from the cell-centered DM) using the provided UserCtx.
This function estimates the value of a vector field at the center of each computational cell (whose origin node is owned by this rank) by averaging the values from the 8 corner nodes defining that cell.
[in] | field_arr | Input: 3D array view (ghosted) of vector data at nodes, obtained from a Vec associated with user->fda. Accessed via GLOBAL node indices. Ghost values must be up-to-date. |
[out] | centfield_arr | Output: 3D local array (0-indexed) where interpolated cell center values are stored. Sized [zm_cell_local][ym_cell_local][xm_cell_local] by the caller. centfield_arr[k_loc][j_loc][i_loc] stores the value for the cell corresponding to the (i_loc, j_loc, k_loc)-th owned cell origin. |
[in] | user | User context containing DMDA information (fda, IM, JM, KM). |
Definition at line 38 of file interpolation.c.
PetscErrorCode InterpolateFieldFromCenterToCorner_Scalar | ( | PetscReal *** | centfield_arr, |
PetscReal *** | field_arr, | ||
UserCtx * | user | ||
) |
Interpolates a scalar field from cell centers to corner nodes.
This function estimates the value of a scalar field at each grid node by averaging the values from the cell centers of the cells surrounding that node (up to 8). It handles physical boundaries by averaging only the available adjacent cells.
Assumes input centfield_arr
is from a ghosted local vector associated with user->da
(DOF=1, s=2) and output field_arr
is from a ghosted local vector also associated with user->da
(DOF=1, s=2). Input array uses GLOBAL cell indices, output array uses GLOBAL node indices.
[in] | centfield_arr | Input: 3D array (ghosted) of scalar data at cell centers, accessed via GLOBAL cell indices (k=0..KM-1, j=0..JM-1, i=0..IM-1). |
[out] | field_arr | Output: 3D array (ghosted) where interpolated node values are stored, accessed via GLOBAL node indices (k=0..KM, j=0..JM, i=0..IM). |
[in] | user | User context containing DMDA information (da). |
Definition at line 265 of file interpolation.c.
PetscErrorCode InterpolateFieldFromCenterToCorner_Vector | ( | Cmpnts *** | centfield_arr, |
Cmpnts *** | field_arr, | ||
UserCtx * | user | ||
) |
Interpolates a vector field from cell centers to corner nodes.
This function estimates the value of a vector field at each grid node by averaging the vector values from the cell centers of the cells surrounding that node (up to 8). It handles physical boundaries by averaging only the available adjacent cells.
Assumes input centfield_arr
is from a ghosted local vector (e.g., representing ucat, stored using node-indexing convention) and output field_arr
is a ghosted local vector associated with user->fda
(DOF=3, s=2), accessed using global node indices.
[in] | centfield_arr | Input: 3D array (ghosted) of vector data conceptually at cell centers, accessed via GLOBAL indices respecting the storage convention (e.g., ucat[k][j][i] uses node index i but represents cell C(i,j,k) for interior). |
[out] | field_arr | Output: 3D array (ghosted) where interpolated node values are stored, accessed via GLOBAL node indices (k=0..KM, j=0..JM, i=0..IM). |
[in] | user | User context containing DMDA information (da and fda). |
Definition at line 381 of file interpolation.c.
PetscErrorCode InterpolateFieldFromCenterToCorner_Vector_Petsc | ( | Cmpnts *** | centfield_arr, |
Cmpnts *** | corner_arr, | ||
UserCtx * | user | ||
) |
Interpolates a vector field from cell centers to corner nodes.
This version is adapted to write directly into a ghosted local array obtained from DMDAVecGetArray(), which allows using GLOBAL indices for writing to the OWNED portion of the array.
[in] | centfield_arr | Input: 3D array (ghosted) of cell-centered data, accessed via GLOBAL indices. |
[out] | corner_arr | Output: 3D array (ghosted) where interpolated node values are stored, also accessed via GLOBAL indices for the owned part. |
[in] | user | User context containing DMDA information. |
Definition at line 603 of file interpolation.c.
PetscErrorCode InterpolateFieldFromCenterToCorner_Scalar_Petsc | ( | PetscReal *** | centfield_arr, |
PetscReal *** | corner_arr, | ||
UserCtx * | user | ||
) |
Interpolates a scalar field from cell centers to corner nodes.
This version is adapted to write directly into a ghosted local array obtained from DMDAVecGetArray(), which allows using GLOBAL indices for writing to the OWNED portion of the array.
[in] | centfield_arr | Input: 3D array (ghosted) of scalar data at cell centers, accessed via GLOBAL indices. |
[out] | corner_arr | Output: 3D array (ghosted) where interpolated node values are stored, also accessed via GLOBAL indices for the owned part. |
[in] | user | User context containing DMDA information. |
Definition at line 699 of file interpolation.c.
PetscErrorCode InterpolateCornerToFaceCenter_Scalar | ( | PetscReal *** | corner_arr, |
PetscReal *** | faceX_arr, | ||
PetscReal *** | faceY_arr, | ||
PetscReal *** | faceZ_arr, | ||
UserCtx * | user | ||
) |
Interpolates a scalar field from corner nodes to all face centers.
This routine computes the average of the four corner-node values defining each face of a hexahedral cell:
[in] | corner_arr | Ghosted node-centered array (global indexing) from user->fda. |
[out] | faceX_arr | Local array for X-faces sized [zm][ym][xm+1]. |
[out] | faceY_arr | Local array for Y-faces sized [zm][ym+1][xm]. |
[out] | faceZ_arr | Local array for Z-faces sized [zm+1][ym][xm]. |
[in] | user | User context containing DMDA 'fda' and GetOwnedCellRange. |
Definition at line 2348 of file interpolation.c.
PetscErrorCode InterpolateCornerToFaceCenter_Vector | ( | Cmpnts *** | corner_arr, |
Cmpnts *** | faceX_arr, | ||
Cmpnts *** | faceY_arr, | ||
Cmpnts *** | faceZ_arr, | ||
UserCtx * | user | ||
) |
Interpolates a vector field from corner nodes to all face centers.
Identical to the scalar version, except it averages each component of the Cmpnts struct at the four corner-nodes per face.
[in] | corner_arr | Ghosted 3-component array (global node indices). |
[out] | faceX_arr | Local array of Cmpnts for X-faces sized [zm][ym][xm+1]. |
[out] | faceY_arr | Local array of Cmpnts for Y-faces sized [zm][ym+1][xm]. |
[out] | faceZ_arr | Local array of Cmpnts for Z-faces sized [zm+1][ym][xm]. |
[in] | user | User context containing DMDA 'fda'. |
Definition at line 2438 of file interpolation.c.