PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
Loading...
Searching...
No Matches
verification_sources.c
Go to the documentation of this file.
2
4#include "logging.h"
5#include "setup.h"
6
7/**
8 * @brief Reports whether the verification-only diffusivity override is enabled.
9 * @details See `include/verification_sources.h` for the public parameter and return contract.
10 */
12{
13 if (!simCtx) return PETSC_FALSE;
14 return simCtx->verificationDiffusivity.enabled;
15}
16
17/**
18 * @brief Reports whether the verification-only scalar override is enabled.
19 * @details See `include/verification_sources.h` for the public parameter and return contract.
20 */
22{
23 if (!simCtx) return PETSC_FALSE;
24 return simCtx->verificationScalar.enabled;
25}
26
27/**
28 * @brief Fills the Eulerian diffusivity field from the configured verification profile.
29 * @details See `include/verification_sources.h` for the public parameter and return contract.
30 */
32{
33 PetscErrorCode ierr;
34 SimCtx *simCtx = user->simCtx;
35 PetscReal ***diff_arr = NULL;
36 const Cmpnts ***cent = NULL;
37 DMDALocalInfo info = user->info;
38 PetscReal min_gamma = PETSC_MAX_REAL;
39
40 PetscFunctionBeginUser;
41
42 if (!VerificationDiffusivityOverrideActive(simCtx)) PetscFunctionReturn(0);
43
44 ierr = DMDAVecGetArray(user->da, user->Diffusivity, &diff_arr); CHKERRQ(ierr);
45 ierr = DMDAVecGetArrayRead(user->fda, user->Cent, &cent); CHKERRQ(ierr);
46
47 for (PetscInt k = info.zs; k < info.zs + info.zm; ++k) {
48 for (PetscInt j = info.ys; j < info.ys + info.ym; ++j) {
49 for (PetscInt i = info.xs; i < info.xs + info.xm; ++i) {
50 const PetscReal gamma =
52 simCtx->verificationDiffusivity.slope_x * cent[k][j][i].x;
53 diff_arr[k][j][i] = gamma;
54 min_gamma = PetscMin(min_gamma, gamma);
55 }
56 }
57 }
58
59 ierr = DMDAVecRestoreArrayRead(user->fda, user->Cent, &cent); CHKERRQ(ierr);
60 ierr = DMDAVecRestoreArray(user->da, user->Diffusivity, &diff_arr); CHKERRQ(ierr);
61
62 {
63 PetscReal global_min_gamma = 0.0;
64 ierr = MPI_Allreduce(&min_gamma, &global_min_gamma, 1, MPIU_REAL, MPI_MIN, PETSC_COMM_WORLD); CHKERRMPI(ierr);
65 if (global_min_gamma <= 0.0) {
66 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
67 "verification diffusivity override produced non-positive Gamma values (min=%g).",
68 (double)global_min_gamma);
69 }
70 }
71
72 ierr = UpdateLocalGhosts(user, "Diffusivity"); CHKERRQ(ierr);
74 "Applied verification diffusivity override profile '%s' (gamma0=%g, slope_x=%g).\n",
76 (double)simCtx->verificationDiffusivity.gamma0,
77 (double)simCtx->verificationDiffusivity.slope_x);
78
79 PetscFunctionReturn(0);
80}
81
82/**
83 * @brief Fills the particle `Psi` field from the configured verification scalar profile.
84 * @details See `include/verification_sources.h` for the public parameter and return contract.
85 */
87{
88 PetscFunctionBeginUser;
89 if (!user) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "UserCtx cannot be NULL.");
90 if (!VerificationScalarOverrideActive(user->simCtx)) PetscFunctionReturn(0);
91
92 PetscCall(SetAnalyticalScalarFieldOnParticles(user, "Psi"));
94 "Applied verification scalar override profile '%s' to particle field 'Psi'.\n",
96 PetscFunctionReturn(0);
97}
PetscErrorCode SetAnalyticalScalarFieldOnParticles(UserCtx *user, const char *swarm_field_name)
Writes the configured verification scalar profile onto a particle swarm scalar field.
Logging utilities and macros for PETSc-based applications.
#define GLOBAL
Scope for global logging across all processes.
Definition logging.h:45
#define LOG_ALLOW(scope, level, fmt,...)
Logging macro that checks both the log level and whether the calling function is in the allowed-funct...
Definition logging.h:199
@ LOG_DEBUG
Detailed debugging information.
Definition logging.h:31
PetscErrorCode UpdateLocalGhosts(UserCtx *user, const char *fieldName)
Updates the local vector (including ghost points) from its corresponding global vector.
Definition setup.c:1510
SimCtx * simCtx
Back-pointer to the master simulation context.
Definition variables.h:833
PetscScalar x
Definition variables.h:101
VerificationScalarConfig verificationScalar
Definition variables.h:714
Vec Diffusivity
Definition variables.h:859
DMDALocalInfo info
Definition variables.h:837
Vec Cent
Definition variables.h:879
VerificationDiffusivityConfig verificationDiffusivity
Definition variables.h:713
A 3D point or vector with PetscScalar components.
Definition variables.h:100
The master context for the entire simulation.
Definition variables.h:651
User-defined context containing data specific to a single computational grid level.
Definition variables.h:830
PetscErrorCode ApplyVerificationDiffusivityOverride(UserCtx *user)
Fills the Eulerian diffusivity field from the configured verification profile.
PetscBool VerificationDiffusivityOverrideActive(const SimCtx *simCtx)
Reports whether the verification-only diffusivity override is enabled.
PetscErrorCode ApplyVerificationScalarOverrideToParticles(UserCtx *user)
Fills the particle Psi field from the configured verification scalar profile.
PetscBool VerificationScalarOverrideActive(const SimCtx *simCtx)
Reports whether the verification-only scalar override is enabled.