PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
Loading...
Searching...
No Matches
AnalyticalSolutions.h
Go to the documentation of this file.
1#ifndef ANALYTICALSOLUTIONS_H
2#define ANALYTICALSOLUTIONS_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
12// Include additional headers
13#include "variables.h" // Shared type definitions
14#include "ParticleSwarm.h" // Particle swarm functions
15#include "walkingsearch.h" // Particle location functions
16#include "grid.h" // Grid functions
17#include "logging.h" // Logging macros
18#include "io.h" // Data Input and Output functions
19#include "setup.h" // Setup Module required for array allocation and deallocation
20#include "interpolation.h" // All the different interpolation routines required
21
22/**
23 * @brief Sets the grid domain and resolution for analytical solution cases.
24 *
25 * @details This function is called when `eulerianSource` is "analytical". It is responsible for
26 * automatically configuring the grid based on the chosen `AnalyticalSolutionType`.
27 *
28 * @par TGV3D Multi-Block Decomposition
29 * If the analytical solution is "TGV3D", this function automatically decomposes the
30 * required `[0, 2*PI]` physical domain among the available blocks.
31 * - **Single Block (`nblk=1`):** The single block is assigned the full `[0, 2*PI]` domain.
32 * - **Multiple Blocks (`nblk>1`):** It requires that the number of blocks be a **perfect square**
33 * (e.g., 4, 9, 16). It then arranges the blocks in a `sqrt(nblk)` by `sqrt(nblk)` grid in the
34 * X-Y plane, partitioning the `[0, 2*PI]` domain in X and Y accordingly. The Z domain for all
35 * blocks remains `[0, 2*PI]`. If `nblk` is not a perfect square, the simulation is aborted
36 * with an error.
37 *
38 * Grid resolution (`IM/JM/KM`) is expected to be pre-populated in `user`
39 * before this function is called.
40 *
41 * @param user Pointer to the `UserCtx` for a specific block. The function will
42 * populate the geometric fields (`IM`, `JM`, `KM`, `Min_X`, `Max_X`, etc.)
43 * within this struct.
44 * @return PetscErrorCode 0 on success, or a PETSc error code on failure.
45 */
46PetscErrorCode SetAnalyticalGridInfo(UserCtx *user);
47
48/**
49 * @brief Reports whether an analytical type requires custom geometry/decomposition logic.
50 *
51 * Analytical types returning PETSC_TRUE are expected to route through
52 * `SetAnalyticalGridInfo`. Types returning PETSC_FALSE should use the standard
53 * programmatic grid parser fallback.
54 *
55 * @param analytical_type Analytical solution type string.
56 * @return PETSC_TRUE if custom geometry is required, PETSC_FALSE otherwise.
57 */
58PetscBool AnalyticalTypeRequiresCustomGeometry(const char *analytical_type);
59
60/**
61 * @brief Reports whether an analytical type has a non-trivial velocity field
62 * for which interpolation error measurement is meaningful.
63 *
64 * Types with identically zero velocity (e.g. ZERO_FLOW) return PETSC_FALSE
65 * because the interpolation error is trivially zero and uninformative.
66 *
67 * @param analytical_type Analytical solution type string.
68 * @return PETSC_TRUE if interpolation error is meaningful, PETSC_FALSE otherwise.
69 */
70PetscBool AnalyticalTypeSupportsInterpolationError(const char *analytical_type);
71
72#undef __FUNCT__
73#define __FUNCT__ "AnalyticalSolutionEngine"
74/**
75 * @brief Dispatches to the appropriate analytical solution function based on simulation settings.
76 *
77 * This function acts as a router. It reads the `AnalyticalSolutionType` from the
78 * simulation context and calls the corresponding private implementation function
79 * (e.g., for Taylor-Green Vortex, lid-driven cavity, etc.). This design keeps
80 * the main simulation code clean and makes it easy to add new analytical test cases.
81 *
82 * @param simCtx The main simulation context, containing configuration and state.
83 * @return PetscErrorCode 0 on success.
84 */
85PetscErrorCode AnalyticalSolutionEngine(SimCtx *simCtx);
86
87/**
88@brief Applies the analytical solution to particle velocity vector.
89
90@details Dispatcher function that calls the appropriate analytical solution based on
91 simCtx->AnalyticalSolutionType. Supports multiple solution types.
92
93@param tempVec The PETSc Vec containing particle positions which will be used to store velocities.
94@param simCtx The simulation context.
95@return PetscErrorCode Returns 0 on success.
96*/
97PetscErrorCode SetAnalyticalSolutionForParticles(Vec tempVec, SimCtx *simCtx);
98
99/**
100 * @brief Evaluates the configured verification scalar profile at one physical point.
101 *
102 * @param[in] simCtx Simulation context providing the scalar verification profile.
103 * @param[in] x Physical x coordinate.
104 * @param[in] y Physical y coordinate.
105 * @param[in] z Physical z coordinate.
106 * @param[in] t Simulation time.
107 * @param[out] value Evaluated scalar value.
108 * @return PetscErrorCode 0 on success.
109 */
110PetscErrorCode EvaluateAnalyticalScalarProfile(const SimCtx *simCtx,
111 PetscReal x,
112 PetscReal y,
113 PetscReal z,
114 PetscReal t,
115 PetscReal *value);
116
117/**
118 * @brief Writes the configured verification scalar profile onto a particle swarm scalar field.
119 *
120 * @param[in,out] user Block-local context providing particle positions.
121 * @param[in] swarm_field_name Name of the scalar swarm field to overwrite.
122 * @return PetscErrorCode 0 on success.
123 */
124PetscErrorCode SetAnalyticalScalarFieldOnParticles(UserCtx *user, const char *swarm_field_name);
125
126/**
127 * @brief Writes the configured verification scalar profile at physical cell centers into a scalar Vec.
128 *
129 * @param[in] user Block-local context providing the cell-center coordinates.
130 * @param[in,out] targetVec Scalar Vec on `user->da` storage to fill with analytical reference values.
131 * @return PetscErrorCode 0 on success.
132 */
133PetscErrorCode SetAnalyticalScalarFieldAtCellCenters(UserCtx *user, Vec targetVec);
134
135#endif // ANALYTICALSOLUTIONS_H
PetscErrorCode SetAnalyticalScalarFieldOnParticles(UserCtx *user, const char *swarm_field_name)
Writes the configured verification scalar profile onto a particle swarm scalar field.
PetscErrorCode EvaluateAnalyticalScalarProfile(const SimCtx *simCtx, PetscReal x, PetscReal y, PetscReal z, PetscReal t, PetscReal *value)
Evaluates the configured verification scalar profile at one physical point.
PetscErrorCode SetAnalyticalScalarFieldAtCellCenters(UserCtx *user, Vec targetVec)
Writes the configured verification scalar profile at physical cell centers into a scalar Vec.
PetscErrorCode AnalyticalSolutionEngine(SimCtx *simCtx)
Dispatches to the appropriate analytical solution function based on simulation settings.
PetscBool AnalyticalTypeRequiresCustomGeometry(const char *analytical_type)
Reports whether an analytical type requires custom geometry/decomposition logic.
PetscBool AnalyticalTypeSupportsInterpolationError(const char *analytical_type)
Reports whether an analytical type has a non-trivial velocity field for which interpolation error mea...
PetscErrorCode SetAnalyticalSolutionForParticles(Vec tempVec, SimCtx *simCtx)
Applies the analytical solution to particle velocity vector.
PetscErrorCode SetAnalyticalGridInfo(UserCtx *user)
Sets the grid domain and resolution for analytical solution cases.
Header file for Particle Swarm management functions.
Public interface for grid, solver, and metric setup routines.
Public interface for data input/output routines.
Logging utilities and macros for PETSc-based applications.
Main header file for a complex fluid dynamics solver.
The master context for the entire simulation.
Definition variables.h:643
User-defined context containing data specific to a single computational grid level.
Definition variables.h:811
Header file for particle location functions using the walking search algorithm.