16 PetscFunctionBeginUser;
21 PetscFunctionReturn(0);
31 PetscBool found = PETSC_FALSE;
33 PetscFunctionBeginUser;
35 PetscCall(PetscOptionsGetString(NULL, NULL,
"-verification_diffusivity_expr", text,
sizeof(text), &found));
37 PetscCall(PetscOptionsGetString(NULL, NULL,
"-verification_scalar_expr", text,
sizeof(text), &found));
40 PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONGSTATE,
41 "verification diffusivity overrides require -euler_field_source \"analytical\".");
43 PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONGSTATE,
44 "verification scalar overrides require -euler_field_source \"analytical\".");
46 PetscFunctionReturn(0);
55 PetscFunctionBeginUser;
60 PetscFunctionReturn(0);
68 PetscReal solver_time, PetscReal *value)
71 PetscReal values[4] = {point.
x * L_ref, point.
y * L_ref, point.
z * L_ref, 0.0};
73 PetscFunctionBeginUser;
78 PetscFunctionReturn(0);
113 PetscReal ***diff_arr = NULL;
114 const Cmpnts ***cent = NULL;
115 DMDALocalInfo info = user->
info;
116 PetscReal min_gamma = PETSC_MAX_REAL;
118 PetscFunctionBeginUser;
124 ierr = DMDAVecGetArray(user->
da, user->
Diffusivity, &diff_arr); CHKERRQ(ierr);
125 ierr = DMDAVecGetArrayRead(user->
fda, user->
Cent, ¢); CHKERRQ(ierr);
127 for (PetscInt k = info.zs; k < info.zs + info.zm; ++k) {
128 for (PetscInt j = info.ys; j < info.ys + info.ym; ++j) {
129 for (PetscInt i = info.xs; i < info.xs + info.xm; ++i) {
133 diff_arr[k][j][i] = gamma;
134 min_gamma = PetscMin(min_gamma, gamma);
139 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
Cent, ¢); CHKERRQ(ierr);
140 ierr = DMDAVecRestoreArray(user->
da, user->
Diffusivity, &diff_arr); CHKERRQ(ierr);
143 PetscReal global_min_gamma = 0.0;
144 ierr = MPI_Allreduce(&min_gamma, &global_min_gamma, 1, MPIU_REAL, MPI_MIN, PETSC_COMM_WORLD); CHKERRMPI(ierr);
146 if (global_min_gamma <= 0.0) {
147 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
148 "verification diffusivity override produced non-positive Gamma values (min=%g).",
149 (
double)global_min_gamma);
162 PetscFunctionReturn(0);
171 PetscFunctionBeginUser;
173 if (!user) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"UserCtx cannot be NULL.");
180 PetscFunctionReturn(0);
193 PetscReal *positions = NULL;
194 PetscReal *scalar_values = NULL;
196 const char *swarm_field_name = NULL;
198 PetscFunctionBeginUser;
200 if (!user) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"UserCtx cannot be NULL.");
201 if (!user->
swarm) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE,
"UserCtx->swarm is NULL.");
205 PETSC_COMM_SELF, PETSC_ERR_ARG_INCOMP,
206 "Verification scalar assignment requires a one-component PETSC_REAL particle field; '%s' has %" PetscInt_FMT
" components and type %s.",
210 ierr = DMSwarmGetLocalSize(user->
swarm, &nlocal); CHKERRQ(ierr);
214 ierr = DMSwarmGetField(user->
swarm, swarm_field_name, NULL, NULL, (
void **)&scalar_values); CHKERRQ(ierr);
216 for (PetscInt p = 0; p < nlocal; ++p) {
217 PetscReal value = 0.0;
218 const Cmpnts point = {positions[3 * p + 0], positions[3 * p + 1], positions[3 * p + 2]};
220 scalar_values[p] = value;
223 ierr = DMSwarmRestoreField(user->
swarm, swarm_field_name, NULL, NULL, (
void **)&scalar_values); CHKERRQ(ierr);
226 PetscFunctionReturn(0);
238 PetscReal ***target = NULL;
239 const Cmpnts ***cent = NULL;
241 PetscInt xs, xe, ys, ye, zs, ze, mx, my, mz;
242 PetscInt lxs, lxe, lys, lye, lzs, lze;
244 PetscFunctionBeginUser;
246 if (!user) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"UserCtx cannot be NULL.");
247 if (!targetVec) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"targetVec cannot be NULL.");
250 xs = info.xs; xe = info.xs + info.xm;
251 ys = info.ys; ye = info.ys + info.ym;
252 zs = info.zs; ze = info.zs + info.zm;
253 mx = info.mx; my = info.my; mz = info.mz;
254 lxs = (xs == 0) ? xs + 1 : xs; lxe = (xe == mx) ? xe - 1 : xe;
255 lys = (ys == 0) ? ys + 1 : ys; lye = (ye == my) ? ye - 1 : ye;
256 lzs = (zs == 0) ? zs + 1 : zs; lze = (ze == mz) ? ze - 1 : ze;
258 ierr = VecSet(targetVec, 0.0); CHKERRQ(ierr);
259 ierr = DMDAVecGetArray(user->
da, targetVec, &target); CHKERRQ(ierr);
260 ierr = DMDAVecGetArrayRead(user->
fda, user->
Cent, ¢); CHKERRQ(ierr);
262 for (PetscInt k = lzs; k < lze; ++k) {
263 for (PetscInt j = lys; j < lye; ++j) {
264 for (PetscInt i = lxs; i < lxe; ++i) {
265 PetscReal value = 0.0;
267 target[k][j][i] = value;
272 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
Cent, ¢); CHKERRQ(ierr);
273 ierr = DMDAVecRestoreArray(user->
da, targetVec, &target); CHKERRQ(ierr);
275 PetscFunctionReturn(0);
PetscErrorCode SynchronizePeriodicCellFields(UserCtx *user, PetscInt num_fields, const FieldId field_ids[])
Synchronizes periodic endpoint cells for a list of cell-centered fields.
The expression language shared by every configured field, the keyed hashes its random draws and other...
PetscErrorCode PicurvExpressionEvaluate(const PicurvExpression *expression, const PetscReal *values, const PicurvExpressionDrawKey *key, PetscReal *result)
Evaluate a compiled expression.
PetscErrorCode PicurvExpressionDestroy(PicurvExpression **expression)
Free a compiled expression.
PetscErrorCode PicurvExpressionCompile(const char *text, const char *const *names, PetscInt name_count, PetscBool allow_random, PicurvExpression **expression)
Compile one expression against a list of variable names.
FieldId
Compile-time identity for a catalogued Eulerian field.
PetscErrorCode PicurvPhysicalTime(const SimCtx *simCtx, PetscReal solver_time, PetscReal *physical)
Convert a solver time to physical seconds, t * L_ref / U_ref.
Logging utilities and macros for PETSc-based applications.
#define GLOBAL
Scope for global logging across all processes.
#define LOG_ALLOW(scope, level, fmt,...)
Logging macro that checks both the log level and whether the calling function is in the allowed-funct...
#define PROFILE_HELPER_BEGIN
Marks the beginning of a profiled helper: timed only when enabled by name.
#define PROFILE_HELPER_END
Alias of PROFILE_FUNCTION_END for a function that began with PROFILE_HELPER_BEGIN.
#define PROFILE_FUNCTION_END
Marks the end of a profiled code block.
@ LOG_DEBUG
Detailed debugging information.
#define PROFILE_FUNCTION_BEGIN
Marks the beginning of a profiled function: an always-on aggregate timer.
const char * ParticleFieldName(ParticleFieldId field_id)
Return the canonical PETSc DMSwarm name for an ID.
ParticleFieldId
Compile-time identity for a persistent solver-particle field.
@ PARTICLE_FIELD_ID_POSITION
PetscErrorCode ParticleFieldGetDescriptor(ParticleFieldId field_id, const ParticleFieldDescriptor **descriptor)
Return immutable metadata for a valid particle field ID.
const char * canonical_name
Immutable metadata for one persistent particle field.
PetscErrorCode UpdateLocalGhosts(UserCtx *user, FieldId field_id)
Updates the local vector (including ghost points) from its corresponding global vector.
SimCtx * simCtx
Back-pointer to the master simulation context.
struct PicurvExpression * expression
Compiled expression, or NULL when the field is not configured.
VerificationFieldConfig verificationDiffusivity
char eulerianSource[PETSC_MAX_PATH_LEN]
VerificationFieldConfig verificationScalar
A 3D point or vector with PetscScalar components.
The master context for the entire simulation.
User-defined context containing data specific to a single computational grid level.
A verification-only prescribed field: an expression in physical x, y, z and t, enabled when set.
PetscErrorCode VerificationFieldCompile(const char *text, VerificationFieldConfig *field)
Compiles a verification field's expression and enables the field.
PetscErrorCode ApplyVerificationDiffusivityOverride(UserCtx *user)
Fills the Eulerian diffusivity field from the configured verification profile.
PetscErrorCode SetVerificationScalarOnParticles(UserCtx *user, ParticleFieldId particle_field_id)
Implementation of SetVerificationScalarOnParticles().
static const char *const kVerificationVariableNames[4]
Names a verification field's expression reads, in the order of its values.
PetscBool VerificationDiffusivityOverrideActive(const SimCtx *simCtx)
Reports whether the verification-only diffusivity override is enabled.
PetscErrorCode VerificationFieldsCreate(SimCtx *simCtx)
Reads and compiles the configured verification fields.
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.
PetscErrorCode VerificationFieldEvaluate(const SimCtx *simCtx, const VerificationFieldConfig *field, Cmpnts point, PetscReal solver_time, PetscReal *value)
Evaluates a verification field at a solver-unit point and time.
PetscErrorCode VerificationFieldsDestroy(SimCtx *simCtx)
Releases the compiled verification fields.
PetscErrorCode SetVerificationScalarAtCellCenters(UserCtx *user, Vec targetVec)
Implementation of SetVerificationScalarAtCellCenters().