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
3#include "logging.h"
4#include "setup.h"
5
6/**
7 * @brief Reports whether the verification-only diffusivity override is enabled.
8 *
9 * @param[in] simCtx Simulation context carrying parsed verification settings.
10 * @return PETSC_TRUE when `verification.sources.diffusivity` is active.
11 */
13{
14 if (!simCtx) return PETSC_FALSE;
15 return simCtx->verificationDiffusivity.enabled;
16}
17
18/**
19 * @brief Fills the Eulerian diffusivity field from the configured verification profile.
20 *
21 * @param[in,out] user Block-local user context whose `Diffusivity` field is overridden.
22 * @return PetscErrorCode 0 on success.
23 */
25{
26 PetscErrorCode ierr;
27 SimCtx *simCtx = user->simCtx;
28 PetscReal ***diff_arr = NULL;
29 const Cmpnts ***cent = NULL;
30 DMDALocalInfo info = user->info;
31 PetscReal min_gamma = PETSC_MAX_REAL;
32
33 PetscFunctionBeginUser;
34
35 if (!VerificationDiffusivityOverrideActive(simCtx)) PetscFunctionReturn(0);
36
37 ierr = DMDAVecGetArray(user->da, user->Diffusivity, &diff_arr); CHKERRQ(ierr);
38 ierr = DMDAVecGetArrayRead(user->fda, user->Cent, &cent); CHKERRQ(ierr);
39
40 for (PetscInt k = info.zs; k < info.zs + info.zm; ++k) {
41 for (PetscInt j = info.ys; j < info.ys + info.ym; ++j) {
42 for (PetscInt i = info.xs; i < info.xs + info.xm; ++i) {
43 const PetscReal gamma =
45 simCtx->verificationDiffusivity.slope_x * cent[k][j][i].x;
46 diff_arr[k][j][i] = gamma;
47 min_gamma = PetscMin(min_gamma, gamma);
48 }
49 }
50 }
51
52 ierr = DMDAVecRestoreArrayRead(user->fda, user->Cent, &cent); CHKERRQ(ierr);
53 ierr = DMDAVecRestoreArray(user->da, user->Diffusivity, &diff_arr); CHKERRQ(ierr);
54
55 {
56 PetscReal global_min_gamma = 0.0;
57 ierr = MPI_Allreduce(&min_gamma, &global_min_gamma, 1, MPIU_REAL, MPI_MIN, PETSC_COMM_WORLD); CHKERRMPI(ierr);
58 if (global_min_gamma <= 0.0) {
59 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
60 "verification diffusivity override produced non-positive Gamma values (min=%g).",
61 (double)global_min_gamma);
62 }
63 }
64
65 ierr = UpdateLocalGhosts(user, "Diffusivity"); CHKERRQ(ierr);
67 "Applied verification diffusivity override profile '%s' (gamma0=%g, slope_x=%g).\n",
69 (double)simCtx->verificationDiffusivity.gamma0,
70 (double)simCtx->verificationDiffusivity.slope_x);
71
72 PetscFunctionReturn(0);
73}
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:1265
SimCtx * simCtx
Back-pointer to the master simulation context.
Definition variables.h:779
PetscScalar x
Definition variables.h:101
Vec Diffusivity
Definition variables.h:805
DMDALocalInfo info
Definition variables.h:783
Vec Cent
Definition variables.h:823
VerificationDiffusivityConfig verificationDiffusivity
Definition variables.h:667
A 3D point or vector with PetscScalar components.
Definition variables.h:100
The master context for the entire simulation.
Definition variables.h:611
User-defined context containing data specific to a single computational grid level.
Definition variables.h:776
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.