|
PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
|
Main program for DMSwarm interpolation using the fdf-curvIB method. More...
#include "interpolation.h"Go to the source code of this file.
Macros | |
| #define | NUM_WEIGHTS 8 |
| #define | ERROR_MSG_BUFFER_SIZE 256 |
| #define | __FUNCT__ "InterpolateFieldFromCornerToCenter_Vector" |
| #define | __FUNCT__ "InterpolateFieldFromCornerToCenter_Scalar" |
| #define | __FUNCT__ "InterpolateFieldFromCenterToCorner_Vector_Petsc" |
| #define | __FUNCT__ "InterpolateFieldFromCenterToCorner_Scalar_Petsc" |
| #define | __FUNCT "PiecWiseLinearInterpolation_Scalar" |
| #define | __FUNCT "PiecWiseLinearInterpolation_Vector" |
| #define | __FUNCT "ComputeTrilinearWeights" |
| #define | __FUNCT "TrilinearInterpolation_Scalar" |
| #define | __FUNCT "TrilinearInterpolation_Vector" |
| #define | __FUNCT "InterpolateEulerFieldToSwarmForParticle" |
| #define | __FUNCT__ "InterpolateEulerFieldToSwarm" |
| #define | __FUNCT__ "InterpolateAllFieldsToSwarm" |
| #define | __FUNCT__ "GetScatterTargetInfo" |
| #define | __FUNCT__ "AccumulateParticleField" |
| #define | __FUNCT__ "NormalizeGridVectorByCount" |
| #define | __FUNCT__ "ScatterParticleFieldToEulerField_Internal" |
| #define | __FUNCT__ "ScatterParticleFieldToEulerField" |
| #define | __FUNCT__ "ScatterAllParticleFieldsToEulerFields" |
| #define | __FUNCT__ "InterpolateCornerToFaceCenter_Scalar" |
| #define | __FUNCT__ "InterpolateCornerToFaceCenter_Vector" |
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_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 interpolation weights from the interpolation 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. | |
Main program for DMSwarm interpolation using the fdf-curvIB method.
Provides routines for interpolation between corner-based and center-based fields in the cell-centered DM (fda), plus partial usage examples for DMSwarm-based field sampling.
Definition in file interpolation.c.
| #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.
| #define __FUNCT "PiecWiseLinearInterpolation_Scalar" |
Definition at line 488 of file interpolation.c.
| #define __FUNCT "PiecWiseLinearInterpolation_Vector" |
Definition at line 488 of file interpolation.c.
| #define __FUNCT "ComputeTrilinearWeights" |
Definition at line 488 of file interpolation.c.
| #define __FUNCT "TrilinearInterpolation_Scalar" |
Definition at line 488 of file interpolation.c.
| #define __FUNCT "TrilinearInterpolation_Vector" |
Definition at line 488 of file interpolation.c.
| #define __FUNCT "InterpolateEulerFieldToSwarmForParticle" |
Definition at line 488 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 39 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 166 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.
| [in] | centfield_arr | Input: 3D array (ghosted) of cell-centered data, accessed via GLOBAL indices. |
| [out] | corner_arr | Output: 3D array 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 270 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 424 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) interpolation 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 502 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 539 of file interpolation.c.
|
inlinestatic |
Computes the trilinear interpolation weights from the interpolation coefficients.
This function computes the weights for trilinear interpolation at the eight corners of a cell using the interpolation 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 579 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 622 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 interpolation near boundaries.
Definition at line 702 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 822 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 958 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 1276 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 2004 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 2104 of file interpolation.c.