PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
Loading...
Searching...
No Matches
Functions
verification_sources.c File Reference
#include "verification_sources.h"
#include "AnalyticalSolutions.h"
#include "logging.h"
#include "setup.h"
Include dependency graph for verification_sources.c:

Go to the source code of this file.

Functions

PetscBool VerificationDiffusivityOverrideActive (const SimCtx *simCtx)
 Reports whether the verification-only diffusivity override is enabled.
 
PetscBool VerificationScalarOverrideActive (const SimCtx *simCtx)
 Reports whether the verification-only scalar override is enabled.
 
PetscErrorCode ApplyVerificationDiffusivityOverride (UserCtx *user)
 Fills the Eulerian diffusivity field from the configured verification profile.
 
PetscErrorCode ApplyVerificationScalarOverrideToParticles (UserCtx *user)
 Fills the particle Psi field from the configured verification scalar profile.
 

Function Documentation

◆ VerificationDiffusivityOverrideActive()

PetscBool VerificationDiffusivityOverrideActive ( const SimCtx simCtx)

Reports whether the verification-only diffusivity override is enabled.

Reports whether a verification-only diffusivity override is active.

See include/verification_sources.h for the public parameter and return contract.

Definition at line 11 of file verification_sources.c.

12{
13 if (!simCtx) return PETSC_FALSE;
14 return simCtx->verificationDiffusivity.enabled;
15}
VerificationDiffusivityConfig verificationDiffusivity
Definition variables.h:755
Here is the caller graph for this function:

◆ VerificationScalarOverrideActive()

PetscBool VerificationScalarOverrideActive ( const SimCtx simCtx)

Reports whether the verification-only scalar override is enabled.

Reports whether a verification-only scalar override is active.

See include/verification_sources.h for the public parameter and return contract.

Definition at line 21 of file verification_sources.c.

22{
23 if (!simCtx) return PETSC_FALSE;
24 return simCtx->verificationScalar.enabled;
25}
VerificationScalarConfig verificationScalar
Definition variables.h:756
Here is the caller graph for this function:

◆ ApplyVerificationDiffusivityOverride()

PetscErrorCode ApplyVerificationDiffusivityOverride ( UserCtx user)

Fills the Eulerian diffusivity field from the configured verification profile.

Populates the Eulerian diffusivity field from a verification-only source override.

See include/verification_sources.h for the public parameter and return contract.

Definition at line 31 of file verification_sources.c.

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 // Leave the production diffusivity untouched unless this verification mode is selected.
43 if (!VerificationDiffusivityOverrideActive(simCtx)) PetscFunctionReturn(0);
44
45 ierr = DMDAVecGetArray(user->da, user->Diffusivity, &diff_arr); CHKERRQ(ierr);
46 ierr = DMDAVecGetArrayRead(user->fda, user->Cent, &cent); CHKERRQ(ierr);
47
48 for (PetscInt k = info.zs; k < info.zs + info.zm; ++k) {
49 for (PetscInt j = info.ys; j < info.ys + info.ym; ++j) {
50 for (PetscInt i = info.xs; i < info.xs + info.xm; ++i) {
51 // The manufactured profile is affine in the physical x coordinate.
52 const PetscReal gamma =
54 simCtx->verificationDiffusivity.slope_x * cent[k][j][i].x;
55 diff_arr[k][j][i] = gamma;
56 min_gamma = PetscMin(min_gamma, gamma);
57 }
58 }
59 }
60
61 ierr = DMDAVecRestoreArrayRead(user->fda, user->Cent, &cent); CHKERRQ(ierr);
62 ierr = DMDAVecRestoreArray(user->da, user->Diffusivity, &diff_arr); CHKERRQ(ierr);
63
64 {
65 PetscReal global_min_gamma = 0.0;
66 ierr = MPI_Allreduce(&min_gamma, &global_min_gamma, 1, MPIU_REAL, MPI_MIN, PETSC_COMM_WORLD); CHKERRMPI(ierr);
67 // Diffusivity must remain positive on every rank for the PDE operator to be valid.
68 if (global_min_gamma <= 0.0) {
69 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
70 "verification diffusivity override produced non-positive Gamma values (min=%g).",
71 (double)global_min_gamma);
72 }
73 }
74
75 {
76 const char *periodic_fields[] = {"Diffusivity"};
77 // Make the analytic field coherent across periodic seams before ghost updates.
78 ierr = SynchronizePeriodicCellFields(user, 1, periodic_fields); CHKERRQ(ierr);
79 ierr = UpdateLocalGhosts(user, "Diffusivity"); CHKERRQ(ierr);
80 }
82 "Applied verification diffusivity override profile '%s' (gamma0=%g, slope_x=%g).\n",
84 (double)simCtx->verificationDiffusivity.gamma0,
85 (double)simCtx->verificationDiffusivity.slope_x);
86
87 PetscFunctionReturn(0);
88}
PetscErrorCode SynchronizePeriodicCellFields(UserCtx *user, PetscInt num_fields, const char *field_names[])
Synchronizes periodic endpoint cells for a list of cell-centered fields.
#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:1752
SimCtx * simCtx
Back-pointer to the master simulation context.
Definition variables.h:879
PetscScalar x
Definition variables.h:101
Vec Diffusivity
Definition variables.h:907
DMDALocalInfo info
Definition variables.h:883
Vec Cent
Definition variables.h:927
A 3D point or vector with PetscScalar components.
Definition variables.h:100
The master context for the entire simulation.
Definition variables.h:684
PetscBool VerificationDiffusivityOverrideActive(const SimCtx *simCtx)
Reports whether the verification-only diffusivity override is enabled.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ApplyVerificationScalarOverrideToParticles()

PetscErrorCode ApplyVerificationScalarOverrideToParticles ( UserCtx user)

Fills the particle Psi field from the configured verification scalar profile.

Populates the particle Psi field from a verification-only source override.

See include/verification_sources.h for the public parameter and return contract.

Definition at line 94 of file verification_sources.c.

95{
96 PetscFunctionBeginUser;
97 if (!user) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "UserCtx cannot be NULL.");
98 // The normal particle model owns Psi unless the verification override is enabled.
99 if (!VerificationScalarOverrideActive(user->simCtx)) PetscFunctionReturn(0);
100
101 PetscCall(SetAnalyticalScalarFieldOnParticles(user, "Psi"));
103 "Applied verification scalar override profile '%s' to particle field 'Psi'.\n",
105 PetscFunctionReturn(0);
106}
PetscErrorCode SetAnalyticalScalarFieldOnParticles(UserCtx *user, const char *swarm_field_name)
Writes the configured verification scalar profile onto a particle swarm scalar field.
PetscBool VerificationScalarOverrideActive(const SimCtx *simCtx)
Reports whether the verification-only scalar override is enabled.
Here is the call graph for this function:
Here is the caller graph for this function: