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 piecewise interpolation function
87 * based on the type of the `fieldPtr` parameter (3D array).
88 *
89 * Usage example:
90 *
91 * // For scalar:
92 * PetscReal ***fieldScal;
93 * PetscReal outVal;
94 * PieceWiseLinearInterpolation(fieldName, fieldScal, i, j, k, &outVal);
95 *
96 * // For vector:
97 * Cmpnts ***fieldVec;
98 * Cmpnts vec;
99 * PieceWiseLinearInterpolation(fieldName, fieldVec, i, j, k, &vec);
100 */
101#define PieceWiseLinearInterpolation(fieldName, fieldPtr, i, j, k, outPtr) \
102 _Generic((fieldPtr), \
103 PetscReal ***: PieceWiseLinearInterpolation_Scalar, \
104 Cmpnts ***: PieceWiseLinearInterpolation_Vector \
105 )(fieldName, fieldPtr, i, j, k, outPtr)
106
107/**
108 * @brief Macro that calls either the scalar or vector trilinear interpolation function
109 * based on the type of the `fieldPtr` parameter (3D array).
110 *
111 * Usage example:
112 *
113 * PetscReal result;
114 * Cmpnts vec;
115 *
116 * // For scalars:
117 * TrilinearInterpolation(fieldName, fieldScal, i, j, k, a1, a2, a3, &result);
118 *
119 * // For vectors:
120 * TrilinearInterpolation(fieldName, fieldVec, i, j, k, a1, a2, a3, &vec);
121 */
122#define TrilinearInterpolation(fieldName, fieldPtr, i, j, k, a1, a2, a3, outPtr) \
123 _Generic((fieldPtr), \
124 PetscReal ***: TrilinearInterpolation_Scalar, \
125 Cmpnts ***: TrilinearInterpolation_Vector \
126 )(fieldName, fieldPtr, i, j, k, a1, a2, a3, outPtr)
127
128// Function declarations
129
130/**
131 * @brief Computes the trilinear interpolated scalar at a given point.
132 *
133 * @param[in] fieldName A string representing the name of the scalar field (e.g., "temperature").
134 * @param[in] fieldScal 3D array of the field from a DMDA (indexed as [k][j][i]),
135 * each cell a PetscReal.
136 * @param[in] i, j, k Integral cell indices (the "lower" corner in each dimension).
137 * @param[in] a1, a2, a3 Normalized coordinates within the cell ([0,1] range).
138 * @param[out] val Pointer to a PetscReal that will store the interpolated scalar.
139 *
140 * This function uses the standard 8-corner trilinear formula via `ComputeTrilinearWeights()`.
141 * If a different scheme is desired, implement a new function with the same interface.
142 */
143PetscErrorCode TrilinearInterpolation_Scalar(
144 const char *fieldName,
145 PetscReal ***fieldScal,
146 PetscInt i,
147 PetscInt j,
148 PetscInt k,
149 PetscReal a1,
150 PetscReal a2,
151 PetscReal a3,
152 PetscReal *val);
153
154/**
155 * @brief Computes the trilinear interpolated vector (e.g., velocity) at a given point.
156 *
157 * @param[in] fieldName A string representing the name of the vector field (e.g., "velocity").
158 * @param[in] fieldVec 3D array of the field from a DMDA (indexed as [k][j][i]),
159 * each cell of type Cmpnts.
160 * @param[in] i, j, k Integral cell indices (the "lower" corner in each dimension).
161 * @param[in] a1, a2, a3 Normalized coordinates within the cell ([0,1] range).
162 * @param[out] vec Pointer to a Cmpnts struct that will store the interpolated vector (x, y, z).
163 *
164 * This function uses the standard 8-corner trilinear formula via `ComputeTrilinearWeights()`.
165 * If a different scheme is desired, implement a new function with the same interface.
166 */
167PetscErrorCode TrilinearInterpolation_Vector(
168 const char *fieldName,
169 Cmpnts ***fieldVec,
170 PetscInt i,
171 PetscInt j,
172 PetscInt k,
173 PetscReal a1,
174 PetscReal a2,
175 PetscReal a3,
176 Cmpnts *vec);
177
178/**
179 * @brief Interpolates a cell-centered field (scalar or vector) onto DMSwarm particles,
180 * using a robust, PETSc-idiomatic two-stage process.
181 *
182 * This function first converts the cell-centered input data to corner-node data,
183 * storing this intermediate result in a PETSc Vec to correctly handle the communication
184 * of ghost-point information across parallel ranks. It then performs a final trilinear
185 * interpolation from the ghosted corner data to each particle's location.
186 *
187 * Workflow:
188 * 1. Create temporary PETSc Vecs (`cornerGlobal`, `cornerLocal`) to manage the
189 * intermediate corner-node data, using the existing nodal DMDA (`user->fda`).
190 * 2. Call a dispatch macro that uses the runtime block size (`bs`) to select the
191 * correct underlying center-to-corner function, writing results into `cornerGlobal`.
192 * 3. Perform a ghost-point exchange (`DMGlobalToLocal`) to transfer the boundary
193 * data from `cornerGlobal` into the ghost regions of `cornerLocal`.
194 * 4. Loop over all local particles. For each particle:
195 * a. Convert its global cell index to a local index relative to the ghosted array.
196 * b. Check if the particle's interpolation stencil is fully contained within
197 * the owned+ghost region. If not, log a warning and set the result to zero.
198 * c. Perform the final trilinear interpolation using the ghosted `cornerLocal` data.
199 * 5. Restore all PETSc objects to prevent memory leaks.
200 *
201 * @param[in] user User context with DMDA, DMSwarm, etc.
202 * @param[in] fieldGlobal_cellCentered Vec (from fda) with cell-centered data (e.g., Ucat).
203 * @param[in] fieldName Human-readable field name for logging (e.g., "Ucat").
204 * @param[in] swarmOutFieldName Name of the DMSwarm field where interpolation results go.
205 *
206 * @return PetscErrorCode 0 on success.
207 */
208PetscErrorCode InterpolateEulerFieldToSwarm(
209 UserCtx *user,
210 Vec fieldLocal_cellCentered,
211 const char *fieldName,
212 const char *swarmOutFieldName);
213
214
215/**
216 * @brief Interpolates all relevant fields from the DMDA to the DMSwarm.
217 *
218 * Currently, it interpolates:
219 * - user->Ucat (vector field) into the DMSwarm field "swarmVelocity".
220 *
221 * To add more fields, duplicate the call to InterpolateOneFieldOverSwarm and provide:
222 * - The global Vec for that field (e.g. user->Tcat for temperature),
223 * - A human-readable field name (for logging),
224 * - A DMSwarm output field name (e.g. "swarmTemperature").
225 *
226 * @param[in,out] user Pointer to a UserCtx containing:
227 * - user->da (DM for the grid),
228 * - user->swarm (DMSwarm for particles),
229 * - user->Ucat (Vec for the vector field),
230 * - possibly more fields like user->Tcat, user->Pcat, etc.
231 *
232 * @return PetscErrorCode Returns 0 on success, non-zero on failure.
233 */
234PetscErrorCode InterpolateAllFieldsToSwarm(UserCtx *user);
235
236/**
237 * @brief Interpolates particle velocities using trilinear interpolation.
238 *
239 * @param[in] user Pointer to the user-defined context containing grid and swarm information.
240 * @return PetscErrorCode Returns 0 on success, non-zero on failure.
241 */
242
244
245/**
246 * @brief Safely interpolate a scalar field from corner nodes (from the coordinate DM)
247 * to cell centers (from the cell-centered DM) using the provided UserCtx.
248 *
249 * For each cell center in the physical region of the cell-centered DM (fda), this function
250 * averages the up to 8 surrounding scalar values from the coordinate DM (da). On boundaries,
251 * where fewer corners are available, a partial average is computed.
252 *
253 * The coordinate DM (da) is built on corners (IM+1 x JM+1 x KM+1) while the cell-centered DM (fda)
254 * covers the physical cells (IM x JM x KM). Index offsets are adjusted via DMDAGetLocalInfo.
255 *
256 * @param[in] field 3D array of corner-based scalar data (from user->da).
257 * @param[out] centfield 3D array for the interpolated cell-center scalar data (for user->fda).
258 * @param[in] user User context containing:
259 * - da : DM for the coordinate (corner) data.
260 * - fda : DM for the cell-centered data.
261 *
262 * @return PetscErrorCode 0 on success.
263 */
265 PetscReal ***field,
266 PetscReal ***centfield,
267 UserCtx *user);
268
269/**
270 * @brief Safely interpolate a vector field from corner nodes (from the coordinate DM)
271 * to cell centers (from the cell-centered DM) using the provided UserCtx.
272 *
273 * For each cell center in the physical region of the cell-centered DM (fda), this function
274 * averages the 8 surrounding corner values from the coordinate DM (da). The coordinate DM
275 * (da) is built on corners (IM+1 x JM+1 x KM+1) while the cell-centered DM (fda) covers
276 * the physical cells (IM x JM x KM). Index offsets are adjusted using DMDAGetLocalInfo.
277 *
278 * @param[in] field 3D array of corner-based vector data (from user->da).
279 * @param[out] centfield 3D array for the interpolated cell-center vector data (for user->fda).
280 * @param[in] user User context containing:
281 * - da : DM for the coordinate (corner) data.
282 * - fda : DM for the cell-centered data.
283 *
284 * @return PetscErrorCode 0 on success.
285 */
287 Cmpnts ***field,
288 Cmpnts ***centfield,
289 UserCtx *user);
290
291/**
292 * @brief Tests the InterpolateFieldFromCornerToCenter function by reproducing the Cent vector.
293 *
294 * This function serves as a unit test. It performs the following steps:
295 * 1. Takes the corner-centered nodal coordinates (from DMGetCoordinatesLocal) as input.
296 * 2. Uses the `InterpolateFieldFromCornerToCenter` macro to interpolate these coordinates to
297 * the cell centers, storing the result in a new temporary vector.
298 * 3. Compares this new vector with the `user->Cent` vector, which is assumed to have been
299 * computed by `ComputeCellCentersAndSpacing` and serves as the ground truth.
300 * 4. A 2-norm of the difference is computed. If it is below a small tolerance, the test passes.
301 *
302 * @note This function should be called immediately after `ComputeCellCentersAndSpacing` has
303 * been successfully executed.
304 *
305 * @param user The UserCtx for a specific grid level.
306 * @return PetscErrorCode 0 on success, or a PETSc error code on failure.
307 */
308PetscErrorCode TestCornerToCenterInterpolation(UserCtx *user);
309
310
311/**
312 * @brief Interpolates a vector field from cell centers to corner nodes.
313 *
314 * This version is adapted to write directly into a ghosted local array obtained from DMDAVecGetArray(),
315 * which allows using GLOBAL indices for writing to the OWNED portion of the array.
316 *
317 * @param[in] centfield_arr Input: 3D array (ghosted) of cell-centered data, accessed via GLOBAL indices.
318 * @param[out] corner_arr Output: 3D array (ghosted) where interpolated node values are stored,
319 * also accessed via GLOBAL indices for the owned part.
320 * @param[in] user User context containing DMDA information.
321 *
322 * @return PetscErrorCode 0 on success.
323 */
325 Cmpnts ***centfield_arr, /* Input: Ghosted local array from Vec (read) */
326 Cmpnts ***corner_arr, /* Output: Ghosted local array from Vec (write) */
327 UserCtx *user);
328
329/**
330 * @brief Interpolates a scalar field from cell centers to corner nodes.
331 *
332 * This version is adapted to write directly into a ghosted local array obtained from DMDAVecGetArray(),
333 * which allows using GLOBAL indices for writing to the OWNED portion of the array.
334 *
335 * @param[in] centfield_arr Input: 3D array (ghosted) of scalar data at cell centers, accessed via GLOBAL indices.
336 * @param[out] corner_arr Output: 3D array (ghosted) where interpolated node values are stored,
337 * also accessed via GLOBAL indices for the owned part.
338 * @param[in] user User context containing DMDA information.
339 *
340 * @return PetscErrorCode 0 on success.
341 */
343 PetscReal ***centfield_arr, /* Input: Ghosted local array from Vec (read) */
344 PetscReal ***corner_arr, /* Output: Ghosted local array from Vec (write) */
345 UserCtx *user);
346
347/**
348 * @brief Determines the target Eulerian DM and expected DOF for scattering a given particle field.
349 * @ingroup scatter_module
350 *
351 * Based on hardcoded rules mapping particle field names to user context DMs (da/fda).
352 * This function encapsulates the policy of where different fields should be scattered.
353 *
354 * @param[in] user Pointer to the UserCtx containing da and fda.
355 * @param[in] particleFieldName Name of the particle field (e.g., "P", "Ucat").
356 * @param[out] targetDM Pointer to store the determined target DM (da or fda).
357 * @param[out] expected_dof Pointer to store the expected DOF (1 or 3) for this field.
358 *
359 * @return PetscErrorCode Returns 0 on success, PETSC_ERR_ARG_UNKNOWN if field name is not recognized,
360 * or PETSC_ERR_ARG_NULL for NULL inputs.
361 */
362PetscErrorCode GetScatterTargetInfo(UserCtx *user, const char *particleFieldName,
363 DM *targetDM, PetscInt *expected_dof);
364
365/**
366 * @brief Retrieves the persistent local vector (e.g., lPsi, lUcat) for a given field name.
367 *
368 * @param user User context containing the persistent vectors.
369 * @param fieldName Name of the field ("Psi", "Ucat", etc.).
370 * @param localVec Output pointer to the vector.
371 * @return PetscErrorCode
372 */
373PetscErrorCode GetPersistentLocalVector(UserCtx *user, const char *fieldName, Vec *localVec);
374
375/**
376 * @brief Accumulates a particle field (scalar or vector) into a target grid sum vector.
377 * @ingroup scatter_module_internal
378 *
379 * This function iterates through local particles, identifies their cell using the
380 * "DMSwarm_CellID" field, and adds the particle's field value (`particleFieldName`)
381 * to the corresponding cell location in the `gridSumVec`. It handles both scalar
382 * (DOF=1) and vector (DOF=3) fields automatically based on the DOF of `gridSumDM`.
383 *
384 * IMPORTANT: The caller must ensure `gridSumVec` is zeroed before calling this
385 * function if a fresh sum calculation is desired.
386 *
387 * @param[in] swarm The DMSwarm containing particles.
388 * @param[in] particleFieldName Name of the field on the particles (must match DOF).
389 * @param[in] gridSumDM The DMDA associated with `gridSumVec`. Its DOF determines
390 * how many components are accumulated.
391 * @param[in,out] gridSumVec The Vec (associated with `gridSumDM`) to accumulate sums into.
392 *
393 * @return PetscErrorCode 0 on success. Errors if fields don't exist or DMs are incompatible.
394 */
395PetscErrorCode AccumulateParticleField(DM swarm, const char *particleFieldName,
396 DM gridSumDM, Vec gridSumVec);
397
398/**
399 * @brief Normalizes a grid vector of sums by a grid vector of counts to produce an average.
400 * @ingroup scatter_module_internal
401 *
402 * Calculates avgVec[i] = sumVec[i] / countVec[i] for each component of each
403 * OWNED cell where countVec[i] > 0. Sets avgVec[i] = 0 otherwise.
404 * Handles both scalar (DOF=1) and vector (DOF=3) data fields based on `dataDM`.
405 * Uses basic `VecGetArray`/`VecGetArrayRead` and manual index calculation.
406 *
407 * @param[in] countDM The DMDA associated with `countVec` (must have DOF=1).
408 * @param[in] countVec The Vec containing particle counts per cell (read-only).
409 * @param[in] dataDM The DMDA associated with `sumVec` and `avgVec` (must have DOF=1 or DOF=3).
410 * @param[in] sumVec The Vec containing the accumulated sums per cell (read-only).
411 * @param[in,out] avgVec The Vec where the calculated averages will be stored (overwritten).
412 *
413 * @return PetscErrorCode 0 on success.
414 */
415PetscErrorCode NormalizeGridVectorByCount(DM countDM, Vec countVec,
416 DM dataDM, Vec sumVec, Vec avgVec);
417
418/**
419 * @brief Scatters a particle field (scalar or vector) to the corresponding Eulerian field average.
420 * @ingroup scatter_module
421 *
422 * This is the main user-facing function. It determines the target Eulerian DM
423 * based on the `particleFieldName`, validates the provided `eulerFieldAverageVec`
424 * against the target DM, and then orchestrates the scatter operation by calling
425 * the internal helper function `ScatterParticleFieldToEulerField_Internal`.
426 * The final averaged result is stored IN-PLACE in `eulerFieldAverageVec`.
427 *
428 * @param[in] user Pointer to UserCtx containing da, fda, swarm, ParticleCount.
429 * @param[in] particleFieldName Name of the field in the DMSwarm (e.g., "P", "Ucat").
430 * @param[in,out] eulerFieldAverageVec Pre-created Vec associated with the correct target DM
431 * (implicitly da or fda). Result stored here.
432 *
433 * @return PetscErrorCode 0 on success. Errors on NULL input, unrecognized field name,
434 * or incompatible target vector.
435 */
436PetscErrorCode ScatterParticleFieldToEulerField(UserCtx *user,
437 const char *particleFieldName,
438 Vec eulerFieldAverageVec);
439
440/**
441 * @brief Scatters a predefined set of particle fields to their corresponding Eulerian fields.
442 * @ingroup scatter_module
443 *
444 * This convenience function calls the unified `ScatterParticleFieldToEulerField`
445 * for a standard set of fields ("P", potentially others). It assumes the target
446 * Eulerian Vec objects (e.g., `user->P`, `user->Ucat`) exist in the UserCtx structure
447 * and are correctly associated with their respective DMs (`user->da` or `user->fda`).
448 * It zeros the target Vecs before scattering.
449 *
450 * @param[in,out] user Pointer to the UserCtx structure containing all required DMs,
451 * Vecs (`ParticleCount`, target Eulerian fields like `P`, `Ucat`), and `swarm`.
452 *
453 * @return PetscErrorCode 0 on success. Errors if prerequisites (like ParticleCount)
454 * are missing or if underlying scatter calls fail.
455 */
457
458/**
459 * @brief Interpolates a scalar field from corner nodes to all face centers.
460 *
461 * This routine computes the average of the four corner-node values
462 * defining each face of a hexahedral cell:
463 * - X-faces (perpendicular to X): face between (i-1,i) in X-dir
464 * - Y-faces (perpendicular to Y): face between (j-1,j) in Y-dir
465 * - Z-faces (perpendicular to Z): face between (k-1,k) in Z-dir
466 *
467 * @param[in] corner_arr Ghosted node-centered array (global indexing) from user->fda.
468 * @param[out] faceX_arr Local array for X-faces sized [zm][ym][xm+1].
469 * @param[out] faceY_arr Local array for Y-faces sized [zm][ym+1][xm].
470 * @param[out] faceZ_arr Local array for Z-faces sized [zm+1][ym][xm].
471 * @param[in] user User context containing DMDA 'fda' and GetOwnedCellRange.
472 *
473 * @return PetscErrorCode 0 on success, non-zero on failure.
474 */
476 PetscReal ***corner_arr,
477 PetscReal ***faceX_arr,
478 PetscReal ***faceY_arr,
479 PetscReal ***faceZ_arr,
480 UserCtx *user);
481
482/**
483 * @brief Interpolates a vector field from corner nodes to all face centers.
484 *
485 * Identical to the scalar version, except it averages each component of the
486 * Cmpnts struct at the four corner-nodes per face.
487 *
488 * @param[in] corner_arr Ghosted 3-component array (global node indices).
489 * @param[out] faceX_arr Local array of Cmpnts for X-faces sized [zm][ym][xm+1].
490 * @param[out] faceY_arr Local array of Cmpnts for Y-faces sized [zm][ym+1][xm].
491 * @param[out] faceZ_arr Local array of Cmpnts for Z-faces sized [zm+1][ym][xm].
492 * @param[in] user User context containing DMDA 'fda'.
493 *
494 * @return PetscErrorCode 0 on success.
495 */
497 Cmpnts ***corner_arr,
498 Cmpnts ***faceX_arr,
499 Cmpnts ***faceY_arr,
500 Cmpnts ***faceZ_arr,
501 UserCtx *user);
502
503#endif // INTERPOLATION_H
504
Header file for Particle Swarm management functions.
Public interface for grid, solver, and metric setup routines.
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 GetPersistentLocalVector(UserCtx *user, const char *fieldName, Vec *localVec)
Retrieves the persistent local vector (e.g., lPsi, lUcat) for a given field name.
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 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 ScatterAllParticleFieldsToEulerFields(UserCtx *user)
Scatters a predefined set of particle fields to their corresponding Eulerian fields.
PetscErrorCode ScatterParticleFieldToEulerField(UserCtx *user, const char *particleFieldName, Vec eulerFieldAverageVec)
Scatters a particle field (scalar or vector) to the corresponding Eulerian field average.
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 InterpolateAllFieldsToSwarm(UserCtx *user)
Interpolates all relevant fields from the DMDA to the DMSwarm.
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 InterpolateParticleVelocities(UserCtx *user)
Interpolates particle velocities using trilinear interpolation.
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 InterpolateFieldFromCornerToCenter_Vector(Cmpnts ***field, Cmpnts ***centfield, UserCtx *user)
Safely interpolate a vector field from corner nodes (from the coordinate DM) to cell centers (from th...
PetscErrorCode TestCornerToCenterInterpolation(UserCtx *user)
Tests the InterpolateFieldFromCornerToCenter function by reproducing the Cent vector.
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 th...
PetscErrorCode InterpolateFieldFromCenterToCorner_Vector(Cmpnts ***centfield_arr, Cmpnts ***corner_arr, UserCtx *user)
Interpolates a vector field from cell centers to corner nodes.
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 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,...
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.
Main header file for a complex fluid dynamics solver.
A 3D point or vector with PetscScalar components.
Definition variables.h:100
User-defined context containing data specific to a single computational grid level.
Definition variables.h:728
Header file for particle location functions using the walking search algorithm.