PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
|
#include "interpolation.h"
Go to the source code of this file.
Macros | |
#define | NUM_WEIGHTS 8 |
#define | ERROR_MSG_BUFFER_SIZE 256 |
#define | __FUNCT__ "InterpolateAllFieldsToSwarm" |
Interpolates a cell-centered field (scalar or vector) onto DMSwarm particles, converting the cell-center data to corner data first, then looping over particles. | |
#define | __FUNCT__ "ScatterAllParticleFieldsToEulerFields" |
Interpolates a cell-centered field (scalar or vector) onto DMSwarm particles, converting the cell-center data to corner data first, then looping over particles. | |
Functions | |
PetscErrorCode | InterpolateFieldFromCornerToCenter_Vector (Cmpnts ***field_arr, Cmpnts ***centfield_arr, UserCtx *user) |
Interpolates a vector field from corner nodes to cell centers. | |
PetscErrorCode | InterpolateFieldFromCornerToCenter_Scalar (PetscReal ***field_arr, PetscReal ***centfield_arr, UserCtx *user) |
Interpolates a scalar field from corner nodes to cell centers. | |
PetscErrorCode | InterpolateFieldFromCenterToCorner_Scalar (PetscReal ***centfield_arr, PetscReal ***field_arr, UserCtx *user) |
Interpolates a scalar field from cell centers to corner nodes. | |
PetscErrorCode | InterpolateFieldFromCenterToCorner_Vector (Cmpnts ***centfield_arr, Cmpnts ***field_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 | PieceWiseLinearInterpolation_Scalar (const char *fieldName, PetscReal ***fieldScal, PetscInt iCell, PetscInt jCell, PetscInt kCell, PetscReal *val) |
Retrieves the scalar value at the cell (iCell, jCell, kCell). | |
PetscErrorCode | PieceWiseLinearInterpolation_Vector (const char *fieldName, Cmpnts ***fieldVec, PetscInt iCell, PetscInt jCell, PetscInt kCell, Cmpnts *vec) |
Retrieves the vector (Cmpnts) at the cell (iCell, jCell, kCell). | |
static void | ComputeTrilinearWeights (PetscReal a1, PetscReal a2, PetscReal a3, PetscReal *w) |
Computes the trilinear Interpolatetion weights from the Interpolatetion coefficients. | |
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 Interpolateted 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 Interpolateted vector (e.g., velocity) at a given point. | |
static PetscErrorCode | InterpolateEulerFieldToSwarmForParticle (const char *fieldName, void *fieldPtr, PetscInt iCell, PetscInt jCell, PetscInt kCell, PetscReal a1, PetscReal a2, PetscReal a3, void *swarmOut, PetscInt p, PetscInt blockSize) |
Interpolates a single field (scalar or vector) for one particle, storing the result in a swarm array. | |
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 | 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. | |
static PetscErrorCode | ScatterParticleFieldToEulerField_Internal (UserCtx *user, const char *particleFieldName, DM targetDM, PetscInt expected_dof, Vec eulerFieldAverageVec) |
Internal helper function to orchestrate the scatter operation (accumulate + normalize). | |
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 13 of file interpolation.c.
#define ERROR_MSG_BUFFER_SIZE 256 |
Definition at line 16 of file interpolation.c.
PetscErrorCode InterpolateFieldFromCornerToCenter_Vector | ( | Cmpnts *** | field_arr, |
Cmpnts *** | centfield_arr, | ||
UserCtx * | user | ||
) |
Interpolates a vector field from corner nodes to cell centers.
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 InterpolateFieldFromCornerToCenter_Scalar | ( | PetscReal *** | field_arr, |
PetscReal *** | centfield_arr, | ||
UserCtx * | user | ||
) |
Interpolates a scalar field from corner nodes to cell centers.
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 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 PieceWiseLinearInterpolation_Scalar | ( | const char * | fieldName, |
PetscReal *** | fieldScal, | ||
PetscInt | iCell, | ||
PetscInt | jCell, | ||
PetscInt | kCell, | ||
PetscReal * | val | ||
) |
Retrieves the scalar value at the cell (iCell, jCell, kCell).
This function does a simple piecewise (zeroth‐order) Interpolatetion by returning fieldScal[kCell][jCell][iCell], ignoring any fractional coordinates.
[in] | fieldName | A string identifying the field (e.g. "temperature"). |
[in] | fieldScal | 3D array of PetscReal (indexed as [k][j][i]). |
[in] | iCell,jCell,kCell | Integral cell indices to sample. |
[out] | val | Pointer to a PetscReal that receives the sampled scalar. |
Definition at line 772 of file interpolation.c.
PetscErrorCode PieceWiseLinearInterpolation_Vector | ( | const char * | fieldName, |
Cmpnts *** | fieldVec, | ||
PetscInt | iCell, | ||
PetscInt | jCell, | ||
PetscInt | kCell, | ||
Cmpnts * | vec | ||
) |
Retrieves the vector (Cmpnts) at the cell (iCell, jCell, kCell).
This function simply sets: vec->x = fieldVec[kCell][jCell][iCell].x vec->y = fieldVec[kCell][jCell][iCell].y vec->z = fieldVec[kCell][jCell][iCell].z effectively a nearest‐cell or piecewise approach.
[in] | fieldName | String identifying the field (e.g. "velocity"). |
[in] | fieldVec | 3D array of Cmpnts (indexed as [k][j][i]). |
[in] | iCell,jCell,kCell | Integral cell indices to sample. |
[out] | vec | Pointer to a Cmpnts struct that receives the sampled vector. |
Definition at line 808 of file interpolation.c.
|
inlinestatic |
Computes the trilinear Interpolatetion weights from the Interpolatetion coefficients.
This function computes the weights for trilinear Interpolatetion at the eight corners of a cell using the Interpolatetion coefficients provided along the x, y, and z directions.
[in] | a1 | Interpolation coefficient along the x-direction (normalized coordinate within the cell). |
[in] | a2 | Interpolation coefficient along the y-direction (normalized coordinate within the cell). |
[in] | a3 | Interpolation coefficient along the z-direction (normalized coordinate within the cell). |
[out] | w | Array of 8 weights, each corresponding to one corner of the cell. |
a1
, a2
, and a3
should be in the range [0, 1].Definition at line 844 of file interpolation.c.
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 Interpolateted scalar at a given point.
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 Interpolateted vector (e.g., velocity) at a given point.
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.
|
inlinestatic |
Interpolates a single field (scalar or vector) for one particle, storing the result in a swarm array.
This helper function is used inside a larger loop over local particles.
[in] | fieldName | A string identifying the field (e.g. "velocity", "temperature", etc.). |
[in] | fieldPtr | A Pointer to the local DMDA array for the field:
|
[in] | iCell,jCell,kCell | The cell indices for this particle (already clamped if needed). |
[in] | a1,a2,a3 | Interpolation coefficients in [0..1]. If using PiecewiseLinearInterpolation, these are currently ignored. |
[out] | swarmOut | A Pointer to the DMSwarm output array:
|
[in] | p | The local particle index (used to compute the correct offset in swarmOut). |
[in] | blockSize | The number of degrees of freedom (1 => scalar, 3 => vector). |
This routine demonstrates a switch between:
By default, PiecewiseLinearInterpolation is active, while the TrilinearInterpolation calls are commented out. To switch to trilinear, simply comment/uncomment appropriately.
Logging calls are provided (LOG_ALLOW) that you can adapt to your existing logging system.
Definition at line 1080 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 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 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.