Main program for DMSwarm interpolation using the fdf-curvIB method. More...
#include "interpolation.h"Go to the source code of this file.
Data Structures | |
| struct | CenterInterpolationTarget |
| One cell-centred field interpolated to a particle field in a shared pass. More... | |
| struct | VelocityPointInterpolator |
| The arrays one method's point evaluation reads. More... | |
Macros | |
| #define | NUM_WEIGHTS 8 |
| #define | ERROR_MSG_BUFFER_SIZE 256 |
| #define | PICURV_APPEND(...) |
Typedefs | |
| typedef struct CenterInterpolationTarget | CenterInterpolationTarget |
| One cell-centred field interpolated to a particle field in a shared pass. | |
Functions | |
| PetscErrorCode | InterpolateFieldFromCornerToCenter_Vector (Cmpnts ***field_arr, Cmpnts ***centfield_arr, UserCtx *user) |
| Implementation of InterpolateFieldFromCornerToCenter_Vector(). | |
| PetscErrorCode | InterpolateFieldFromCornerToCenter_Scalar (PetscReal ***field_arr, PetscReal ***centfield_arr, UserCtx *user) |
| Implementation of InterpolateFieldFromCornerToCenter_Scalar(). | |
| PetscErrorCode | TestCornerToCenterInterpolation (UserCtx *user) |
| Implementation of TestCornerToCenterInterpolation(). | |
| PetscErrorCode | InterpolateFieldFromCenterToCorner_Vector (Cmpnts ***centfield_arr, Cmpnts ***corner_arr, UserCtx *user) |
| Implementation of InterpolateFieldFromCenterToCorner_Vector(). | |
| PetscErrorCode | InterpolateFieldFromCenterToCorner_Scalar (PetscReal ***centfield_arr, PetscReal ***corner_arr, UserCtx *user) |
| Implementation of InterpolateFieldFromCenterToCorner_Scalar(). | |
| static void | ComputeTrilinearWeights (PetscReal a1, PetscReal a2, PetscReal a3, PetscReal *w) |
| Compute the eight trilinear interpolation weights for a particle's local coordinates. | |
| static void | ComputeTrilinearWeightsUnclamped (PetscReal a1, PetscReal a2, PetscReal a3, PetscReal *w) |
| Unclamped trilinear weights for boundary extrapolation. | |
| PetscErrorCode | TrilinearInterpolation_Scalar (PetscReal ***fieldScal, PetscInt i, PetscInt j, PetscInt k, PetscReal a1, PetscReal a2, PetscReal a3, PetscReal *val) |
| Implementation of TrilinearInterpolation_Scalar(). | |
| PetscErrorCode | TrilinearInterpolation_Vector (Cmpnts ***fieldVec, PetscInt i, PetscInt j, PetscInt k, PetscReal a1, PetscReal a2, PetscReal a3, Cmpnts *vec) |
| Implementation of TrilinearInterpolation_Vector(). | |
| static PetscErrorCode | InterpolateEulerFieldToSwarmForParticle (void *fieldPtr, Particle *particle, void *swarmOut, PetscInt p, PetscInt blockSize) |
| Interpolate one Eulerian field to a single located swarm particle. | |
| static void | AppendInterpolationTargetText (char *text, size_t size, size_t *used, const CenterInterpolationTarget *tg, PetscInt p, PetscInt bi, PetscInt bj, PetscInt bk) |
| Appends one target's interpolated value and its eight dual-cell corner values to a particle's interpolate line; the text is truncated rather than overrun. | |
| static PetscErrorCode | CenterDualCellWeights (const DMDALocalInfo *info, const FacePlaneArrays *dual, const PetscBool periodic[3], const PetscInt cell[3], const PetscReal weights[3], Cmpnts loc, PetscInt base[3], PetscReal a[3], PetscReal w[8], PetscBool *unclamped, PetscBool *outside) |
| The dual cell of cell centres a point interpolates from, and its trilinear weights. | |
| static PetscErrorCode | CenterInterpolateVector (Cmpnts ***fieldVec, const PetscInt base[3], const PetscReal a[3], const PetscReal w[8], PetscBool unclamped, Cmpnts *vec) |
| A cell-centred vector at a point, from the dual cell CenterDualCellWeights() found. | |
| static PetscErrorCode | CenterInterpolateScalar (PetscReal ***fieldScal, const PetscInt base[3], const PetscReal a[3], const PetscReal w[8], PetscBool unclamped, PetscReal *val) |
| A cell-centred scalar at a point, from the dual cell CenterDualCellWeights() found. | |
| static PetscBool | FaceFluxStencilIsLocal (const DMDALocalInfo *info, const PetscInt cell[3]) |
| Whether the face fluxes of a host cell lie in the ghosted region: in cell-centred numbering (i,j,k) = cell + 1, its faces are i-1 and i along each axis. | |
| static PetscBool | CornerStencilIsLocal (const DMDALocalInfo *info, const PetscInt cell[3]) |
| Whether the eight corners of a host cell (nodes cell to cell + 1) lie in the ghosted region. | |
| static PetscErrorCode | InterpolateEulerFieldFromCenterToSwarm (UserCtx *user, PetscInt ntargets, CenterInterpolationTarget *targets) |
| Direct cell-center trilinear interpolation (second-order on curvilinear grids). | |
| static PetscErrorCode | InterpolateEulerVelocityFromFacesToSwarm (UserCtx *user, const char *swarmOutFieldName) |
| Particle velocity from the host cell's face fluxes (the FaceFlux method). | |
| static PetscErrorCode | StageCellFieldAtCorners (UserCtx *user, Vec cell_local, PetscInt bs, FieldView *corner_view) |
| Stage a ghosted cell-centred field at the grid corners, in the corner workspace for its block size: zeroed, filled with the unweighted average of the surrounding cell centres (InterpolateFieldFromCenterToCorner()), then its ghosts refreshed. | |
| static PetscErrorCode | InterpolateEulerFieldFromCornerToSwarm (UserCtx *user, Vec fieldLocal_cellCentered, const char *fieldName, const char *swarmOutFieldName) |
| Corner-averaged interpolation path (legacy). | |
| PetscErrorCode | InterpolateVelocityAtPointBegin (UserCtx *user, VelocityPointInterpolator **interp) |
| Implementation of InterpolateVelocityAtPointBegin(). | |
| PetscErrorCode | InterpolateVelocityAtPoint (const VelocityPointInterpolator *interp, const PetscInt cell[3], const PetscReal weights[3], Cmpnts point, Cmpnts *u) |
| Implementation of InterpolateVelocityAtPoint(). | |
| PetscErrorCode | InterpolateVelocityAtPointEnd (VelocityPointInterpolator **interp) |
| Implementation of InterpolateVelocityAtPointEnd(). | |
| static PetscErrorCode | ResolveInterpolationPair (UserCtx *user, FieldId source_field_id, ParticleFieldId target_field_id, FieldView *source_view, const ParticleFieldDescriptor **target_descriptor) |
| Check that an Eulerian source can be interpolated to a particle destination. | |
| static PetscErrorCode | InterpolateEulerFieldsToSwarm (UserCtx *user, PetscInt n, const FieldId source_field_ids[], const ParticleFieldId target_field_ids[]) |
| Interpolates several Eulerian fields to their particle fields with the configured method. | |
| PetscErrorCode | InterpolateAllFieldsToSwarm (UserCtx *user) |
| Implementation of InterpolateAllFieldsToSwarm(). | |
| PetscErrorCode | AccumulateParticleField (DM swarm, ParticleFieldId particle_field_id, 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 | ScatterParticleFieldCellMean (UserCtx *user, ParticleFieldId particle_field_id, DM dataDM, Vec countVec, PetscBool recount, Vec meanVec) |
| Cell mean of a particle field: the field summed over each cell's particles, divided by the cell's count. | |
| PetscErrorCode | ScatterParticleFieldToEulerField (UserCtx *user, ParticleFieldId particle_field_id, 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) |
| Implementation of InterpolateCornerToFaceCenter_Scalar(). | |
| PetscErrorCode | InterpolateCornerToFaceCenter_Vector (Cmpnts ***corner_arr, Cmpnts ***faceX_arr, Cmpnts ***faceY_arr, Cmpnts ***faceZ_arr, UserCtx *user) |
| Implementation of InterpolateCornerToFaceCenter_Vector(). | |
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.
| struct CenterInterpolationTarget |
One cell-centred field interpolated to a particle field in a shared pass.
Definition at line 678 of file interpolation.c.
| struct VelocityPointInterpolator |
The arrays one method's point evaluation reads.
Definition at line 1237 of file interpolation.c.
| Data Fields | ||
|---|---|---|
| UserCtx * | user | |
| InterpolationMethod | method | |
| PetscBool | periodic[3] | |
| Cmpnts *** | field | |
| Cmpnts *** | csi | |
| Cmpnts *** | eta | |
| Cmpnts *** | zet | |
| FacePlaneArrays | dual | |
| #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 PICURV_APPEND | ( | ... | ) |
| typedef struct CenterInterpolationTarget CenterInterpolationTarget |
One cell-centred field interpolated to a particle field in a shared pass.
| PetscErrorCode InterpolateFieldFromCornerToCenter_Vector | ( | Cmpnts *** | field_arr, |
| Cmpnts *** | centfield_arr, | ||
| UserCtx * | user | ||
| ) |
Implementation of InterpolateFieldFromCornerToCenter_Vector().
Safely interpolate a vector field from corner nodes (from the coordinate DM) to cell centers (from the cell-centered DM) using the provided UserCtx.
Definition at line 23 of file interpolation.c.
| PetscErrorCode InterpolateFieldFromCornerToCenter_Scalar | ( | PetscReal *** | field_arr, |
| PetscReal *** | centfield_arr, | ||
| UserCtx * | user | ||
| ) |
Implementation of InterpolateFieldFromCornerToCenter_Scalar().
Safely interpolate a scalar field from corner nodes (from the coordinate DM) to cell centers (from the cell-centered DM) using the provided UserCtx.
Definition at line 71 of file interpolation.c.
| PetscErrorCode TestCornerToCenterInterpolation | ( | UserCtx * | user | ) |
Implementation of TestCornerToCenterInterpolation().
Tests the InterpolateFieldFromCornerToCenter function by reproducing the Cent vector.
Definition at line 109 of file interpolation.c.
| PetscErrorCode InterpolateFieldFromCenterToCorner_Vector | ( | Cmpnts *** | centfield_arr, |
| Cmpnts *** | corner_arr, | ||
| UserCtx * | user | ||
| ) |
Implementation of InterpolateFieldFromCenterToCorner_Vector().
Interpolates a vector field from cell centers to corner nodes.
Definition at line 168 of file interpolation.c.
| PetscErrorCode InterpolateFieldFromCenterToCorner_Scalar | ( | PetscReal *** | centfield_arr, |
| PetscReal *** | corner_arr, | ||
| UserCtx * | user | ||
| ) |
Implementation of InterpolateFieldFromCenterToCorner_Scalar().
Interpolates a scalar field from cell centers to corner nodes.
Definition at line 300 of file interpolation.c.
|
inlinestatic |
Compute the eight trilinear interpolation weights for a particle's local coordinates.
Definition at line 427 of file interpolation.c.
|
inlinestatic |
Unclamped trilinear weights for boundary extrapolation.
Identical to ComputeTrilinearWeights() but without clamping a1, a2, a3 to [0,1]. Allows weights outside [0,1] for linear extrapolation at non-periodic boundaries. Weights still sum to 1.0.
Definition at line 453 of file interpolation.c.
| PetscErrorCode TrilinearInterpolation_Scalar | ( | PetscReal *** | fieldScal, |
| PetscInt | i, | ||
| PetscInt | j, | ||
| PetscInt | k, | ||
| PetscReal | a1, | ||
| PetscReal | a2, | ||
| PetscReal | a3, | ||
| PetscReal * | val | ||
| ) |
Implementation of TrilinearInterpolation_Scalar().
Trilinear interpolation of a scalar from the eight entries (i..i+1, j..j+1, k..k+1).
Definition at line 473 of file interpolation.c.
| PetscErrorCode TrilinearInterpolation_Vector | ( | Cmpnts *** | fieldVec, |
| PetscInt | i, | ||
| PetscInt | j, | ||
| PetscInt | k, | ||
| PetscReal | a1, | ||
| PetscReal | a2, | ||
| PetscReal | a3, | ||
| Cmpnts * | vec | ||
| ) |
Implementation of TrilinearInterpolation_Vector().
Trilinear interpolation of a vector from the eight entries (i..i+1, j..j+1, k..k+1).
Definition at line 524 of file interpolation.c.
|
inlinestatic |
Interpolate one Eulerian field to a single located swarm particle.
Definition at line 605 of file interpolation.c.
|
static |
Appends one target's interpolated value and its eight dual-cell corner values to a particle's interpolate line; the text is truncated rather than overrun.
Corners are listed i fastest, then j, then k, from dual base (bi, bj, bk). Local to this translation unit.
Definition at line 693 of file interpolation.c.
|
inlinestatic |
The dual cell of cell centres a point interpolates from, and its trilinear weights.
The octant of the point in its host cell picks the dual cell. At a non-periodic boundary the dual cell is clamped to the physical cells, and the weights then extrapolate. The weights come from the point's distances to the dual cell's face planes. Local to this translation unit.
| [in] | info | Grid layout. |
| [in] | dual | Dual face-plane arrays (MetricGetFacePlaneArrays() with dual set). |
| [in] | periodic | Whether each axis is periodic. |
| [in] | cell | Host cell, geometric indices. |
| [in] | weights | The point's logical coordinates in the host cell. |
| [in] | loc | The point. |
| [out] | base | Dual cell origin, geometric indices. |
| [out] | a | Trilinear coordinates in the dual cell. |
| [out] | w | Corner weights, set only when unclamped is true. |
| [out] | unclamped | PETSC_TRUE when the dual cell was clamped. |
| [out] | outside | PETSC_TRUE when the dual cell lies outside the ghosted region; then nothing else is set. |
Definition at line 737 of file interpolation.c.
|
inlinestatic |
A cell-centred vector at a point, from the dual cell CenterDualCellWeights() found.
Trilinear inside the domain, the unclamped corner weights where the dual cell was clamped. Local to this translation unit.
Definition at line 783 of file interpolation.c.
|
inlinestatic |
A cell-centred scalar at a point, from the dual cell CenterDualCellWeights() found.
The scalar counterpart of CenterInterpolateVector(). Local to this translation unit.
Definition at line 815 of file interpolation.c.
|
inlinestatic |
Whether the face fluxes of a host cell lie in the ghosted region: in cell-centred numbering (i,j,k) = cell + 1, its faces are i-1 and i along each axis.
Definition at line 836 of file interpolation.c.
|
inlinestatic |
Whether the eight corners of a host cell (nodes cell to cell + 1) lie in the ghosted region.
Definition at line 845 of file interpolation.c.
|
static |
Direct cell-center trilinear interpolation (second-order on curvilinear grids).
For each particle, determines the 8 nearest cell centers via octant detection, takes the dual cell they form, computes face-distance-based trilinear weights, and interpolates directly from cell-centered data. At non-periodic boundaries where the dual cell cannot be fully formed, octant clamping with unclamped trilinear extrapolation preserves second-order accuracy. Periodic boundaries use ghost cell data directly. No intermediate corner staging or extra ghost exchange is needed. The dual cell's face planes are precomputed (MetricComputeFacePlanes()), and the octant, dual cell and weights depend only on the particle, so they are computed once per particle for all ntargets fields; each field's value is the one a separate pass would give.
Definition at line 866 of file interpolation.c.
|
static |
Particle velocity from the host cell's face fluxes (the FaceFlux method).
Each contravariant flux varies linearly between the cell's two faces of its family, at the particle's in-cell weights, and is mapped to Cartesian velocity by ContravariantToCartesianInCell(), the cell-centre solve of Contra2Cart(). The field is divergence-free wherever the fluxes are (exactly on rectilinear cells), its wall-normal component vanishes on a wall face, and its components are linear only along their own axis, so it is first-order accurate. Local to this translation unit.
Definition at line 1003 of file interpolation.c.
|
static |
Stage a ghosted cell-centred field at the grid corners, in the corner workspace for its block size: zeroed, filled with the unweighted average of the surrounding cell centres (InterpolateFieldFromCenterToCorner()), then its ghosts refreshed.
Collective.
| [in] | user | Grid context. |
| [in] | cell_local | Ghosted cell-centred field, its ghosts current. |
| [in] | bs | Its block size, 1 or 3. |
| [out] | corner_view | The corner workspace; its local vector holds the result. |
Definition at line 1086 of file interpolation.c.
|
static |
Corner-averaged interpolation path (legacy).
Stages cell-centered data to corners via unweighted averaging, then trilinear interpolation from corners to particles. Local to this translation unit.
Definition at line 1114 of file interpolation.c.
| PetscErrorCode InterpolateVelocityAtPointBegin | ( | UserCtx * | user, |
| VelocityPointInterpolator ** | interp | ||
| ) |
Implementation of InterpolateVelocityAtPointBegin().
Opens the arrays for evaluating the particle velocity at points, with the configured interpolation method.
Definition at line 1250 of file interpolation.c.
| PetscErrorCode InterpolateVelocityAtPoint | ( | const VelocityPointInterpolator * | interp, |
| const PetscInt | cell[3], | ||
| const PetscReal | weights[3], | ||
| Cmpnts | point, | ||
| Cmpnts * | u | ||
| ) |
Implementation of InterpolateVelocityAtPoint().
The velocity a particle at a point would be given: the value the swarm pass of the configured method computes there.
Definition at line 1284 of file interpolation.c.
| PetscErrorCode InterpolateVelocityAtPointEnd | ( | VelocityPointInterpolator ** | interp | ) |
Implementation of InterpolateVelocityAtPointEnd().
Closes the arrays InterpolateVelocityAtPointBegin() opened.
Definition at line 1319 of file interpolation.c.
|
static |
Check that an Eulerian source can be interpolated to a particle destination.
The source must be cell-centred, the destination real-valued, and their component counts equal. Local to this translation unit.
Definition at line 1349 of file interpolation.c.
|
static |
Interpolates several Eulerian fields to their particle fields with the configured method.
FaceFlux takes Ucat from the face fluxes; the corner-averaged method runs one pass per field; the cell-centre method interpolates every remaining field in one pass, sharing each particle's dual cell and weights. Each field's values match a pass of its own. Local to this translation unit.
Definition at line 1381 of file interpolation.c.
| PetscErrorCode InterpolateAllFieldsToSwarm | ( | UserCtx * | user | ) |
Implementation of InterpolateAllFieldsToSwarm().
Interpolates the Eulerian fields the particles carry to every local particle.
Definition at line 1420 of file interpolation.c.
| PetscErrorCode InterpolateCornerToFaceCenter_Scalar | ( | PetscReal *** | corner_arr, |
| PetscReal *** | faceX_arr, | ||
| PetscReal *** | faceY_arr, | ||
| PetscReal *** | faceZ_arr, | ||
| UserCtx * | user | ||
| ) |
Implementation of InterpolateCornerToFaceCenter_Scalar().
Interpolates a scalar field from corner nodes to all face centers.
Definition at line 1910 of file interpolation.c.
| PetscErrorCode InterpolateCornerToFaceCenter_Vector | ( | Cmpnts *** | corner_arr, |
| Cmpnts *** | faceX_arr, | ||
| Cmpnts *** | faceY_arr, | ||
| Cmpnts *** | faceZ_arr, | ||
| UserCtx * | user | ||
| ) |
Implementation of InterpolateCornerToFaceCenter_Vector().
Interpolates a vector field from corner nodes to all face centers.
Definition at line 1998 of file interpolation.c.