PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
 
Loading...
Searching...
No Matches
interpolation.h
Go to the documentation of this file.
1#ifndef INTERPOLATION_H
2#define INTERPOLATION_H
3
4#include <petscpf.h>
5#include <petscdmswarm.h>
6#include <stdlib.h>
7#include <time.h>
8#include <math.h>
9#include <petsctime.h>
10#include <petscdmcomposite.h>
11#include <petscerror.h>
12#include <petscsys.h>
13
14// Include additional headers
15#include "variables.h" // Shared type definitions
16#include "ParticleSwarm.h" // Particle swarm functions
17#include "walkingsearch.h" // Particle location functions
18#include "grid.h" // Grid functions
19#include "logging.h" // Logging macros
20#include "io.h" // Data Input and Output functions
21#include "setup.h" // Setup functions that are used across the codebase
22
23// Macros and constants
24#define NUM_WEIGHTS 8 // Number of weights in trilinear interpolation
25
26/**
27 * @brief Generic macro to call the appropriate interpolation function based on the field type.
28 *
29 * This macro will select either the scalar or vector interpolation function based on
30 * the type of the 'field' pointer. It also performs a compile-time check that 'centfield'
31 * is of the same type as 'field'. If the types are not the same, a compile-time error is produced.
32 *
33 * Usage:
34 * InterpolateFieldFromCornerToCenter(field, centfield, user);
35 */
36#define InterpolateFieldFromCornerToCenter(field, centfield, user) \
37 ( (void)sizeof(char[1 - 2*!!(!__builtin_types_compatible_p(typeof(field), typeof(centfield)))]),\
38 _Generic((field), \
39 PetscReal ***: InterpolateFieldFromCornerToCenter_Scalar, \
40 Cmpnts ***: InterpolateFieldFromCornerToCenter_Vector \
41 )(field, centfield, user) )
42
43/**
44 * @brief Macro to dispatch to the correct scalar or vector center-to-corner function
45 * based on a runtime block size variable.
46 *
47 * This macro uses a ternary operator to inspect the runtime value of 'blockSize' and
48 * select the appropriate implementation. It expects the input and output pointers to be void*
49 * and handles casting them to the correct, strongly-typed pointers.
50 *
51 * @param blockSize The runtime block size (1 for scalar, 3 for vector).
52 * @param centfield_ptr The input void* pointer to the 3D cell-centered data array.
53 * @param corner_ptr The output void* pointer to the 3D corner data array.
54 * @param user_ctx The UserCtx structure.
55 */
56#define InterpolateFieldFromCenterToCorner(blockSize, centfield_ptr, corner_ptr, user_ctx) \
57 ( (blockSize) == 1 ? \
58 InterpolateFieldFromCenterToCorner_Scalar((PetscReal***)(centfield_ptr), (PetscReal***)(corner_ptr), (user_ctx)) : \
59 InterpolateFieldFromCenterToCorner_Vector((Cmpnts***)(centfield_ptr), (Cmpnts***)(corner_ptr), (user_ctx)) \
60 )
61
62
63/**
64 * @brief A type-generic macro that interpolates a field from corner nodes to all face centers.
65 *
66 * This macro uses C11's _Generic feature to dispatch to the appropriate underlying
67 * function based on the type of the input `corner_arr`.
68 *
69 * - If `corner_arr` is of type `PetscReal***`, it calls `InterpolateCornerToFaceCenter_Scalar`.
70 * - If `corner_arr` is of type `Cmpnts***`, it calls `InterpolateCornerToFaceCenter_Vector`.
71 *
72 * @param corner_arr Ghosted node-centered array (global indexing). The type of this
73 * argument determines which function is called.
74 * @param faceX_arr Local array for X-faces.
75 * @param faceY_arr Local array for Y-faces.
76 * @param faceZ_arr Local array for Z-faces.
77 * @param user_ctx User context containing DMDA 'fda'.
78 */
79#define InterpolateCornerToFaceCenter(corner_arr, faceX_arr, faceY_arr, faceZ_arr, user_ctx) \
80 _Generic((corner_arr), \
81 PetscReal***: InterpolateCornerToFaceCenter_Scalar, \
82 Cmpnts***: InterpolateCornerToFaceCenter_Vector \
83 )(corner_arr, faceX_arr, faceY_arr, faceZ_arr, user_ctx)
84
85/**
86 * @brief Macro that calls either the scalar or vector trilinear interpolation function
87 * based on the type of the `fieldPtr` parameter (3D array).
88 *
89 * Usage example:
90 *
91 * PetscReal result;
92 * Cmpnts vec;
93 *
94 * // For scalars:
95 * TrilinearInterpolation(fieldScal, i, j, k, a1, a2, a3, &result);
96 *
97 * // For vectors:
98 * TrilinearInterpolation(fieldVec, i, j, k, a1, a2, a3, &vec);
99 */
100#define TrilinearInterpolation(fieldPtr, i, j, k, a1, a2, a3, outPtr) \
101 _Generic((fieldPtr), \
102 PetscReal ***: TrilinearInterpolation_Scalar, \
103 Cmpnts ***: TrilinearInterpolation_Vector \
104 )(fieldPtr, i, j, k, a1, a2, a3, outPtr)
105
106// Function declarations
107
108/**
109 * @brief Trilinear interpolation of a scalar from the eight entries (i..i+1, j..j+1, k..k+1).
110 *
111 * The weights come from `ComputeTrilinearWeights()`, which clamps the coordinates to [0,1].
112 *
113 * @param[in] fieldScal Scalar array indexed [k][j][i].
114 * @param[in] i i index of the lowest of the eight entries.
115 * @param[in] j j index of the lowest of the eight entries.
116 * @param[in] k k index of the lowest of the eight entries.
117 * @param[in] a1 Coordinate in the eight-entry cell along i, in [0,1].
118 * @param[in] a2 Coordinate along j, in [0,1].
119 * @param[in] a3 Coordinate along k, in [0,1].
120 * @param[out] val The interpolated value.
121 * @return PetscErrorCode 0 on success.
122 */
123PetscErrorCode TrilinearInterpolation_Scalar(
124 PetscReal ***fieldScal,
125 PetscInt i,
126 PetscInt j,
127 PetscInt k,
128 PetscReal a1,
129 PetscReal a2,
130 PetscReal a3,
131 PetscReal *val);
132
133/**
134 * @brief Trilinear interpolation of a vector from the eight entries (i..i+1, j..j+1, k..k+1).
135 *
136 * The weights come from `ComputeTrilinearWeights()`, which clamps the coordinates to [0,1];
137 * the weighted sum is divided by the weights' sum, and is zero when that sum is below 1e-14.
138 *
139 * @param[in] fieldVec Vector array indexed [k][j][i].
140 * @param[in] i i index of the lowest of the eight entries.
141 * @param[in] j j index of the lowest of the eight entries.
142 * @param[in] k k index of the lowest of the eight entries.
143 * @param[in] a1 Coordinate in the eight-entry cell along i, in [0,1].
144 * @param[in] a2 Coordinate along j, in [0,1].
145 * @param[in] a3 Coordinate along k, in [0,1].
146 * @param[out] vec The interpolated vector.
147 * @return PetscErrorCode 0 on success.
148 */
149PetscErrorCode TrilinearInterpolation_Vector(
150 Cmpnts ***fieldVec,
151 PetscInt i,
152 PetscInt j,
153 PetscInt k,
154 PetscReal a1,
155 PetscReal a2,
156 PetscReal a3,
157 Cmpnts *vec);
158
159/** @brief The arrays InterpolateVelocityAtPoint() reads, held from Begin to End. */
161
162/**
163 * @brief Opens the arrays for evaluating the particle velocity at points, with the configured
164 * interpolation method.
165 * @details Collective: the corner-averaged method stages Ucat at the corners, as its swarm
166 * pass does, which overwrites the vector corner workspace.
167 * @param[in] user Grid context; its Ucat, Ucont and metrics must be current.
168 * @param[out] interp Close with InterpolateVelocityAtPointEnd().
169 * @return PetscErrorCode 0 on success.
170 */
172
173/**
174 * @brief The velocity a particle at a point would be given: the value the swarm pass of the
175 * configured method computes there.
176 * @param[in] interp From InterpolateVelocityAtPointBegin().
177 * @param[in] cell Host cell, geometric indices; the point must be in a cell this rank owns.
178 * @param[in] weights The point's logical coordinates in the host cell.
179 * @param[in] point The point.
180 * @param[out] u The velocity; zero, as in the swarm pass, if the stencil lies outside
181 * the ghosted region.
182 * @return PetscErrorCode 0 on success.
183 */
184PetscErrorCode InterpolateVelocityAtPoint(const VelocityPointInterpolator *interp, const PetscInt cell[3],
185 const PetscReal weights[3], Cmpnts point, Cmpnts *u);
186
187/**
188 * @brief Closes the arrays InterpolateVelocityAtPointBegin() opened.
189 * @param[in,out] interp Set to NULL.
190 * @return PetscErrorCode 0 on success.
191 */
193
194/**
195 * @brief Interpolates the Eulerian fields the particles carry to every local particle.
196 *
197 * Interpolates `Ucat` to the particle `velocity`, `Diffusivity` to `Diffusivity` and
198 * `DiffusivityGradient` to `DiffusivityGradient`, with the method in
199 * `simCtx->interpolationMethod`:
200 * - Trilinear: from the dual cell of the eight nearest cell centres, in one pass that
201 * shares each particle's dual cell and weights across the fields;
202 * - CornerAveraged: cell centres averaged to the corners, then trilinear from the host
203 * cell's corners, one pass per field;
204 * - FaceFlux: velocity from the host cell's face fluxes; the other fields as Trilinear.
205 *
206 * Reads the ghosted local vectors of the source fields, which must be current. A particle
207 * whose stencil lies outside the ghosted region gets zero. Collective.
208 *
209 * @param[in,out] user Block context holding the swarm and the source fields.
210 *
211 * @return PetscErrorCode Returns 0 on success, non-zero on failure.
212 */
214
215/**
216 * @brief Safely interpolate a scalar field from corner nodes (from the coordinate DM)
217 * to cell centers (from the cell-centered DM) using the provided UserCtx.
218 *
219 * For each cell center in the physical region of the cell-centered DM (fda), this function
220 * averages the up to 8 surrounding scalar values from the coordinate DM (da). On boundaries,
221 * where fewer corners are available, a partial average is computed.
222 *
223 * The coordinate DM (da) is built on corners (IM+1 x JM+1 x KM+1) while the cell-centered DM (fda)
224 * covers the physical cells (IM x JM x KM). Index offsets are adjusted via DMDAGetLocalInfo.
225 *
226 * @param[in] field_arr 3D array of corner-based scalar data (from user->da).
227 * @param[out] centfield_arr 3D array for interpolated cell-center scalar data (for user->fda).
228 * @param[in] user User context containing:
229 * - da : DM for the coordinate (corner) data.
230 * - fda : DM for the cell-centered data.
231 *
232 * @return PetscErrorCode 0 on success.
233 */
235 PetscReal ***field_arr,
236 PetscReal ***centfield_arr,
237 UserCtx *user);
238
239/**
240 * @brief Safely interpolate a vector field from corner nodes (from the coordinate DM)
241 * to cell centers (from the cell-centered DM) using the provided UserCtx.
242 *
243 * For each cell center in the physical region of the cell-centered DM (fda), this function
244 * averages the 8 surrounding corner values from the coordinate DM (da). The coordinate DM
245 * (da) is built on corners (IM+1 x JM+1 x KM+1) while the cell-centered DM (fda) covers
246 * the physical cells (IM x JM x KM). Index offsets are adjusted using DMDAGetLocalInfo.
247 *
248 * @param[in] field_arr 3D array of corner-based vector data (from user->da).
249 * @param[out] centfield_arr 3D array for interpolated cell-center vector data (for user->fda).
250 * @param[in] user User context containing:
251 * - da : DM for the coordinate (corner) data.
252 * - fda : DM for the cell-centered data.
253 *
254 * @return PetscErrorCode 0 on success.
255 */
257 Cmpnts ***field_arr,
258 Cmpnts ***centfield_arr,
259 UserCtx *user);
260
261/**
262 * @brief Tests the InterpolateFieldFromCornerToCenter function by reproducing the Cent vector.
263 *
264 * This function serves as a unit test. It performs the following steps:
265 * 1. Takes the corner-centered nodal coordinates (from DMGetCoordinatesLocal) as input.
266 * 2. Uses the `InterpolateFieldFromCornerToCenter` macro to interpolate these coordinates to
267 * the cell centers, storing the result in a new temporary vector.
268 * 3. Compares this new vector with the `user->Cent` vector, which is assumed to have been
269 * computed by `ComputeCellCenters` and serves as the ground truth.
270 * 4. A 2-norm of the difference is computed. If it is below a small tolerance, the test passes.
271 *
272 * @note This function should be called immediately after `ComputeCellCenters` has
273 * been successfully executed.
274 *
275 * @param user The UserCtx for a specific grid level.
276 * @return PetscErrorCode 0 on success, or a PETSc error code on failure.
277 */
279
280
281/**
282 * @brief Interpolates a vector field from cell centers to corner nodes.
283 *
284 * This version is adapted to write directly into a ghosted local array obtained from DMDAVecGetArray(),
285 * which allows using GLOBAL indices for writing to the OWNED portion of the array.
286 *
287 * @param[in] centfield_arr Input: 3D array (ghosted) of cell-centered data, accessed via GLOBAL indices.
288 * @param[out] corner_arr Output: 3D array (ghosted) where interpolated node values are stored,
289 * also accessed via GLOBAL indices for the owned part.
290 * @param[in] user User context containing DMDA information.
291 *
292 * @return PetscErrorCode 0 on success.
293 */
295 Cmpnts ***centfield_arr, /* Input: Ghosted local array from Vec (read) */
296 Cmpnts ***corner_arr, /* Output: Ghosted local array from Vec (write) */
297 UserCtx *user);
298
299/**
300 * @brief Interpolates a scalar field from cell centers to corner nodes.
301 *
302 * This version is adapted to write directly into a ghosted local array obtained from DMDAVecGetArray(),
303 * which allows using GLOBAL indices for writing to the OWNED portion of the array.
304 *
305 * @param[in] centfield_arr Input: 3D array (ghosted) of scalar data at cell centers, accessed via GLOBAL indices.
306 * @param[out] corner_arr Output: 3D array (ghosted) where interpolated node values are stored,
307 * also accessed via GLOBAL indices for the owned part.
308 * @param[in] user User context containing DMDA information.
309 *
310 * @return PetscErrorCode 0 on success.
311 */
313 PetscReal ***centfield_arr, /* Input: Ghosted local array from Vec (read) */
314 PetscReal ***corner_arr, /* Output: Ghosted local array from Vec (write) */
315 UserCtx *user);
316
317/**
318 * @brief Accumulates a particle field (scalar or vector) into a target grid sum vector.
319 * @ingroup scatter_module_internal
320 *
321 * This function iterates through local particles, identifies their cell using the
322 * "DMSwarm_CellID" field, and adds the particle's field value (`particleFieldName`)
323 * to the corresponding cell location in the `gridSumVec`. It handles both scalar
324 * (DOF=1) and vector (DOF=3) fields automatically based on the DOF of `gridSumDM`.
325 *
326 * IMPORTANT: The caller must ensure `gridSumVec` is zeroed before calling this
327 * function if a fresh sum calculation is desired.
328 *
329 * @param[in] swarm The DMSwarm containing particles.
330 * @param[in] particle_field_id Typed identity of the particle field (must match DOF).
331 * @param[in] gridSumDM The DMDA associated with `gridSumVec`. Its DOF determines
332 * how many components are accumulated.
333 * @param[in,out] gridSumVec The Vec (associated with `gridSumDM`) to accumulate sums into.
334 *
335 * @return PetscErrorCode 0 on success. Errors if fields don't exist or DMs are incompatible.
336 */
337PetscErrorCode AccumulateParticleField(DM swarm, ParticleFieldId particle_field_id,
338 DM gridSumDM, Vec gridSumVec);
339
340/**
341 * @brief Normalizes a grid vector of sums by a grid vector of counts to produce an average.
342 * @ingroup scatter_module_internal
343 *
344 * Calculates avgVec[i] = sumVec[i] / countVec[i] for each component of each
345 * OWNED cell where countVec[i] > 0. Sets avgVec[i] = 0 otherwise.
346 * Handles both scalar (DOF=1) and vector (DOF=3) data fields based on `dataDM`.
347 * Uses basic `VecGetArray`/`VecGetArrayRead` and manual index calculation.
348 *
349 * @param[in] countDM The DMDA associated with `countVec` (must have DOF=1).
350 * @param[in] countVec The Vec containing particle counts per cell (read-only).
351 * @param[in] dataDM The DMDA associated with `sumVec` and `avgVec` (must have DOF=1 or DOF=3).
352 * @param[in] sumVec The Vec containing the accumulated sums per cell (read-only).
353 * @param[in,out] avgVec The Vec where the calculated averages will be stored (overwritten).
354 *
355 * @return PetscErrorCode 0 on success.
356 */
357PetscErrorCode NormalizeGridVectorByCount(DM countDM, Vec countVec,
358 DM dataDM, Vec sumVec, Vec avgVec);
359
360/**
361 * @brief Cell mean of a particle field: the field summed over each cell's particles, divided by
362 * the cell's count.
363 * @ingroup scatter_module
364 *
365 * Zeroes a ghosted accumulator, adds every local particle into its cell with
366 * AccumulateParticleField(), sums the ranks' copies into the owners (local-to-global ADD), and
367 * divides by `countVec` with NormalizeGridVectorByCount(); an empty cell's mean is zero.
368 * Collective.
369 *
370 * @param[in] user Context holding the swarm and the cell DM `da`.
371 * @param[in] particle_field_id PETSC_REAL particle field to average.
372 * @param[in] dataDM DMDA of the mean, with as many DOF as the field has components.
373 * @param[in] countVec Global particles-per-cell vector on `user->da`; only its owned
374 * entries are read.
375 * @param[in] recount PETSC_TRUE to recount `user->ParticleCount` (and reset
376 * `user->lParticleCount`) with CalculateParticleCountPerCell()
377 * before dividing; `countVec` is then normally `user->ParticleCount`.
378 * @param[in,out] meanVec Global vector on `dataDM` receiving the owned means.
379 *
380 * @return PetscErrorCode 0 on success.
381 */
382PetscErrorCode ScatterParticleFieldCellMean(UserCtx *user, ParticleFieldId particle_field_id, DM dataDM,
383 Vec countVec, PetscBool recount, Vec meanVec);
384
385/**
386 * @brief Scatters a particle field (scalar or vector) to the corresponding Eulerian field average.
387 * @ingroup scatter_module
388 *
389 * This is the main user-facing function. It determines the target Eulerian DM
390 * from the particle catalog, validates the provided `eulerFieldAverageVec`
391 * against the target DM, and then orchestrates the scatter operation by calling
392 * ScatterParticleFieldCellMean(), recounting the particles per cell first.
393 * The final averaged result is stored IN-PLACE in `eulerFieldAverageVec`.
394 *
395 * @param[in] user Pointer to UserCtx containing da, fda, swarm, ParticleCount.
396 * @param[in] particle_field_id Typed identity of the DMSwarm field.
397 * @param[in,out] eulerFieldAverageVec Pre-created Vec associated with the correct target DM
398 * (implicitly da or fda). Result stored here.
399 *
400 * @return PetscErrorCode 0 on success. Errors on NULL input, unrecognized field name,
401 * or incompatible target vector.
402 */
404 ParticleFieldId particle_field_id,
405 Vec eulerFieldAverageVec);
406
407/**
408 * @brief Scatters a predefined set of particle fields to their corresponding Eulerian fields.
409 * @ingroup scatter_module
410 *
411 * This convenience function calls the unified `ScatterParticleFieldToEulerField`
412 * for a standard set of fields ("P", potentially others). It assumes the target
413 * Eulerian Vec objects (e.g., `user->P`, `user->Ucat`) exist in the UserCtx structure
414 * and are correctly associated with their respective DMs (`user->da` or `user->fda`).
415 * It zeros the target Vecs before scattering.
416 *
417 * @param[in,out] user Pointer to the UserCtx structure containing all required DMs,
418 * Vecs (`ParticleCount`, target Eulerian fields like `P`, `Ucat`), and `swarm`.
419 *
420 * @return PetscErrorCode 0 on success. Errors if prerequisites (like ParticleCount)
421 * are missing or if underlying scatter calls fail.
422 */
424
425/**
426 * @brief Interpolates a scalar field from corner nodes to all face centers.
427 *
428 * This routine computes the average of the four corner-node values
429 * defining each face of a hexahedral cell:
430 * - X-faces (perpendicular to X): face between (i-1,i) in X-dir
431 * - Y-faces (perpendicular to Y): face between (j-1,j) in Y-dir
432 * - Z-faces (perpendicular to Z): face between (k-1,k) in Z-dir
433 *
434 * @param[in] corner_arr Ghosted node-centered array (global indexing) from user->fda.
435 * @param[out] faceX_arr Local array for X-faces sized [zm][ym][xm+1].
436 * @param[out] faceY_arr Local array for Y-faces sized [zm][ym+1][xm].
437 * @param[out] faceZ_arr Local array for Z-faces sized [zm+1][ym][xm].
438 * @param[in] user User context containing DMDA 'fda' and GetOwnedCellRange.
439 *
440 * @return PetscErrorCode 0 on success, non-zero on failure.
441 */
443 PetscReal ***corner_arr,
444 PetscReal ***faceX_arr,
445 PetscReal ***faceY_arr,
446 PetscReal ***faceZ_arr,
447 UserCtx *user);
448
449/**
450 * @brief Interpolates a vector field from corner nodes to all face centers.
451 *
452 * Identical to the scalar version, except it averages each component of the
453 * Cmpnts struct at the four corner-nodes per face.
454 *
455 * @param[in] corner_arr Ghosted 3-component array (global node indices).
456 * @param[out] faceX_arr Local array of Cmpnts for X-faces sized [zm][ym][xm+1].
457 * @param[out] faceY_arr Local array of Cmpnts for Y-faces sized [zm][ym+1][xm].
458 * @param[out] faceZ_arr Local array of Cmpnts for Z-faces sized [zm+1][ym][xm].
459 * @param[in] user User context containing DMDA 'fda'.
460 *
461 * @return PetscErrorCode 0 on success.
462 */
464 Cmpnts ***corner_arr,
465 Cmpnts ***faceX_arr,
466 Cmpnts ***faceY_arr,
467 Cmpnts ***faceZ_arr,
468 UserCtx *user);
469
470#endif // INTERPOLATION_H
Header file for Particle Swarm management functions.
Public interface for grid, solver, and metric setup routines.
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 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 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 cou...
The arrays one method's point evaluation reads.
PetscErrorCode TrilinearInterpolation_Vector(Cmpnts ***fieldVec, PetscInt i, PetscInt j, PetscInt k, PetscReal a1, PetscReal a2, PetscReal a3, Cmpnts *vec)
Trilinear interpolation of a vector from the eight entries (i..i+1, j..j+1, k..k+1).
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 th...
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.
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 th...
PetscErrorCode InterpolateAllFieldsToSwarm(UserCtx *user)
Interpolates the Eulerian fields the particles carry to every local particle.
PetscErrorCode InterpolateVelocityAtPoint(const VelocityPointInterpolator *interp, const PetscInt cell[3], const PetscReal weights[3], Cmpnts point, Cmpnts *u)
The velocity a particle at a point would be given: the value the swarm pass of the configured method ...
PetscErrorCode InterpolateVelocityAtPointEnd(VelocityPointInterpolator **interp)
Closes the arrays InterpolateVelocityAtPointBegin() opened.
PetscErrorCode TestCornerToCenterInterpolation(UserCtx *user)
Tests the InterpolateFieldFromCornerToCenter function by reproducing the Cent vector.
PetscErrorCode TrilinearInterpolation_Scalar(PetscReal ***fieldScal, PetscInt i, PetscInt j, PetscInt k, PetscReal a1, PetscReal a2, PetscReal a3, PetscReal *val)
Trilinear interpolation of a scalar from the eight entries (i..i+1, j..j+1, k..k+1).
PetscErrorCode InterpolateFieldFromCenterToCorner_Vector(Cmpnts ***centfield_arr, Cmpnts ***corner_arr, UserCtx *user)
Interpolates a vector field from cell centers to corner nodes.
PetscErrorCode InterpolateVelocityAtPointBegin(UserCtx *user, VelocityPointInterpolator **interp)
Opens the arrays for evaluating the particle velocity at points, with the configured interpolation me...
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 InterpolateFieldFromCenterToCorner_Scalar(PetscReal ***centfield_arr, PetscReal ***corner_arr, UserCtx *user)
Interpolates a scalar field from cell centers to corner nodes.
Public interface for data input/output routines.
Logging utilities and macros for PETSc-based applications.
ParticleFieldId
Compile-time identity for a persistent solver-particle field.
Main header file for a complex fluid dynamics solver.
A 3D point or vector with PetscScalar components.
Definition variables.h:144
User-defined context containing data specific to a single computational grid level.
Definition variables.h:1157
Header file for particle location functions using the walking search algorithm.