PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
 
Loading...
Searching...
No Matches
Functions
test_support.c File Reference

Shared C test fixtures, assertions, and PETSc helper utilities. More...

#include "test_support.h"
#include "grid.h"
#include "io.h"
#include "setup.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
Include dependency graph for test_support.c:

Go to the source code of this file.

Functions

static PetscErrorCode DestroyVecIfSet (Vec *vec)
 Destroys a PETSc vector only when the handle is non-null.
 
static PetscErrorCode DestroyDMIfSet (DM *dm)
 Destroys a PETSc DM only when the handle is non-null.
 
static PetscErrorCode DestroyMatIfSet (Mat *mat)
 Destroys a PETSc matrix only when the handle is non-null.
 
static PetscErrorCode DestroyKSPIfSet (KSP *ksp)
 Destroys a PETSc KSP only when the handle is non-null.
 
static PetscErrorCode DestroyNullSpaceIfSet (MatNullSpace *nullsp)
 Destroys a PETSc nullspace only when the handle is non-null.
 
static PetscErrorCode DestroyRandomIfSet (PetscRandom *rand_ctx)
 Destroys a PETSc random generator only when the handle is non-null.
 
static PetscErrorCode RegisterSwarmFieldForTests (DM swarm, const char *field_name, PetscInt field_dim, PetscDataType dtype)
 Registers one DMSwarm field used by the C test fixtures.
 
static PetscErrorCode CreateZeroedGlobalVector (DM dm, Vec *vec)
 Allocates and zeroes a global vector from the provided DM.
 
static PetscErrorCode CreateZeroedLocalVector (DM dm, Vec *vec)
 Allocates and zeroes a local vector from the provided DM.
 
static PetscErrorCode CreateZeroedDuplicate (Vec src, Vec *vec)
 Duplicates and zeroes a vector.
 
PetscErrorCode PicurvRunTests (const char *suite_name, const PicurvTestCase *cases, size_t case_count)
 Runs a named C test suite and prints pass/fail progress markers.
 
PetscErrorCode PicurvEnsureDir (const char *path)
 Ensures a directory exists for test output.
 
PetscErrorCode PicurvMakeTempDir (char *path, size_t path_len)
 Creates a unique temporary directory for one test case.
 
PetscErrorCode PicurvRemoveTempDir (const char *path)
 Recursively removes a temporary directory created by PicurvMakeTempDir.
 
static PetscErrorCode WriteTextFileForTests (const char *path, const char *contents)
 Writes one small temporary text file used by the richer runtime fixtures.
 
static PetscErrorCode PrepareTinyRuntimeConfig (const char *bcs_contents, PetscBool enable_particles, const char *extra_options, char *tmpdir, size_t tmpdir_len, char *control_path, size_t control_path_len)
 Creates a tiny control-file bundle used by richer runtime fixtures built through the setup path.
 
PetscErrorCode PicurvCreateMinimalContextsWithPeriodicity (SimCtx **simCtx_out, UserCtx **user_out, PetscInt mx, PetscInt my, PetscInt mz, PetscBool x_periodic, PetscBool y_periodic, PetscBool z_periodic)
 Builds minimal SimCtx and UserCtx fixtures for C unit tests with configurable periodicity.
 
PetscErrorCode PicurvCreateMinimalContexts (SimCtx **simCtx_out, UserCtx **user_out, PetscInt mx, PetscInt my, PetscInt mz)
 Builds minimal SimCtx and UserCtx fixtures for C unit tests.
 
PetscErrorCode PicurvPopulateUniformCellCenters (UserCtx *user)
 Populates cell center coordinates for a uniform grid on [0,1]^3.
 
PetscErrorCode PicurvPopulateIdentityMetrics (UserCtx *user)
 Populates identity metric vectors on the minimal grid fixture.
 
PetscErrorCode PicurvCreateSwarmPair (UserCtx *user, PetscInt nlocal, const char *post_field_name)
 Creates matched solver and post-processing swarms for tests.
 
PetscErrorCode PicurvBuildTinyRuntimeContext (const char *bcs_contents, PetscBool enable_particles, SimCtx **simCtx_out, UserCtx **user_out, char *tmpdir, size_t tmpdir_len)
 Builds a tiny runtime context through the real setup path for behavior-level tests.
 
PetscErrorCode PicurvBuildTinyRuntimeContextWithOptions (const char *bcs_contents, PetscBool enable_particles, const char *extra_options, SimCtx **simCtx_out, UserCtx **user_out, char *tmpdir, size_t tmpdir_len)
 Builds the tiny runtime context with extra control-file options appended.
 
PetscErrorCode PicurvBuildMomentumPurityRuntimeContext (const char *bcs_contents, SimCtx **simCtx_out, UserCtx **user_out, char *tmpdir, size_t tmpdir_len)
 Builds the production-sized straight-duct fixture used only by the opt-in Newton residual-purity diagnostic.
 
PetscErrorCode PicurvDestroyRuntimeContext (SimCtx **simCtx_ptr)
 Finalizes and frees a runtime context built by PicurvBuildTinyRuntimeContext.
 
PetscErrorCode PicurvDestroyMinimalContexts (SimCtx **simCtx_ptr, UserCtx **user_ptr)
 Destroys minimal SimCtx/UserCtx fixtures and all owned PETSc objects.
 
PetscErrorCode PicurvAssertRealNear (PetscReal expected, PetscReal actual, PetscReal tol, const char *context)
 Asserts that two real values agree within tolerance.
 
PetscErrorCode PicurvAssertIntEqual (PetscInt expected, PetscInt actual, const char *context)
 Asserts that two integer values are equal.
 
PetscErrorCode PicurvAssertBool (PetscBool value, const char *context)
 Asserts that one boolean condition is true.
 
PetscErrorCode PicurvAssertFileExists (const char *path, const char *context)
 Asserts that a filesystem path exists as a readable file.
 
PetscErrorCode PicurvAssertVecConstant (Vec vec, PetscScalar expected, PetscReal tol, const char *context)
 Asserts that a PETSc vector is spatially constant within tolerance.
 

Detailed Description

Shared C test fixtures, assertions, and PETSc helper utilities.

Definition in file test_support.c.

Function Documentation

◆ DestroyVecIfSet()

static PetscErrorCode DestroyVecIfSet ( Vec *  vec)
static

Destroys a PETSc vector only when the handle is non-null.

Definition at line 23 of file test_support.c.

24{
25 PetscFunctionBeginUser;
26 if (vec && *vec) {
27 PetscCall(VecDestroy(vec));
28 }
29 PetscFunctionReturn(0);
30}
Here is the caller graph for this function:

◆ DestroyDMIfSet()

static PetscErrorCode DestroyDMIfSet ( DM *  dm)
static

Destroys a PETSc DM only when the handle is non-null.

Definition at line 35 of file test_support.c.

36{
37 PetscFunctionBeginUser;
38 if (dm && *dm) {
39 PetscCall(DMDestroy(dm));
40 }
41 PetscFunctionReturn(0);
42}
Here is the caller graph for this function:

◆ DestroyMatIfSet()

static PetscErrorCode DestroyMatIfSet ( Mat *  mat)
static

Destroys a PETSc matrix only when the handle is non-null.

Definition at line 47 of file test_support.c.

48{
49 PetscFunctionBeginUser;
50 if (mat && *mat) {
51 PetscCall(MatDestroy(mat));
52 }
53 PetscFunctionReturn(0);
54}
Here is the caller graph for this function:

◆ DestroyKSPIfSet()

static PetscErrorCode DestroyKSPIfSet ( KSP *  ksp)
static

Destroys a PETSc KSP only when the handle is non-null.

Definition at line 59 of file test_support.c.

60{
61 PetscFunctionBeginUser;
62 if (ksp && *ksp) {
63 PetscCall(KSPDestroy(ksp));
64 }
65 PetscFunctionReturn(0);
66}
Here is the caller graph for this function:

◆ DestroyNullSpaceIfSet()

static PetscErrorCode DestroyNullSpaceIfSet ( MatNullSpace *  nullsp)
static

Destroys a PETSc nullspace only when the handle is non-null.

Definition at line 71 of file test_support.c.

72{
73 PetscFunctionBeginUser;
74 if (nullsp && *nullsp) {
75 PetscCall(MatNullSpaceDestroy(nullsp));
76 }
77 PetscFunctionReturn(0);
78}
Here is the caller graph for this function:

◆ DestroyRandomIfSet()

static PetscErrorCode DestroyRandomIfSet ( PetscRandom *  rand_ctx)
static

Destroys a PETSc random generator only when the handle is non-null.

Definition at line 83 of file test_support.c.

84{
85 PetscFunctionBeginUser;
86 if (rand_ctx && *rand_ctx) {
87 PetscCall(PetscRandomDestroy(rand_ctx));
88 }
89 PetscFunctionReturn(0);
90}
Here is the caller graph for this function:

◆ RegisterSwarmFieldForTests()

static PetscErrorCode RegisterSwarmFieldForTests ( DM  swarm,
const char *  field_name,
PetscInt  field_dim,
PetscDataType  dtype 
)
static

Registers one DMSwarm field used by the C test fixtures.

Definition at line 95 of file test_support.c.

96{
97 PetscFunctionBeginUser;
98 PetscCall(DMSwarmRegisterPetscDatatypeField(swarm, field_name, field_dim, dtype));
99 PetscFunctionReturn(0);
100}
Here is the caller graph for this function:

◆ CreateZeroedGlobalVector()

static PetscErrorCode CreateZeroedGlobalVector ( DM  dm,
Vec *  vec 
)
static

Allocates and zeroes a global vector from the provided DM.

Definition at line 105 of file test_support.c.

106{
107 PetscFunctionBeginUser;
108 PetscCall(DMCreateGlobalVector(dm, vec));
109 PetscCall(VecSet(*vec, 0.0));
110 PetscFunctionReturn(0);
111}
Here is the caller graph for this function:

◆ CreateZeroedLocalVector()

static PetscErrorCode CreateZeroedLocalVector ( DM  dm,
Vec *  vec 
)
static

Allocates and zeroes a local vector from the provided DM.

Definition at line 116 of file test_support.c.

117{
118 PetscFunctionBeginUser;
119 PetscCall(DMCreateLocalVector(dm, vec));
120 PetscCall(VecSet(*vec, 0.0));
121 PetscFunctionReturn(0);
122}
Here is the caller graph for this function:

◆ CreateZeroedDuplicate()

static PetscErrorCode CreateZeroedDuplicate ( Vec  src,
Vec *  vec 
)
static

Duplicates and zeroes a vector.

Definition at line 127 of file test_support.c.

128{
129 PetscFunctionBeginUser;
130 PetscCall(VecDuplicate(src, vec));
131 PetscCall(VecSet(*vec, 0.0));
132 PetscFunctionReturn(0);
133}
Here is the caller graph for this function:

◆ PicurvRunTests()

PetscErrorCode PicurvRunTests ( const char *  suite_name,
const PicurvTestCase *  cases,
size_t  case_count 
)

Runs a named C test suite and prints pass/fail progress markers.

Executes a table of unit tests and reports aggregated pass/fail status.

Definition at line 138 of file test_support.c.

139{
140 PetscFunctionBeginUser;
141
142 PetscCall(PetscPrintf(PETSC_COMM_WORLD, "==> Running %s (%zu tests)\n", suite_name, case_count));
143 for (size_t i = 0; i < case_count; ++i) {
144 PetscCall(PetscPrintf(PETSC_COMM_WORLD, " -> %s\n", cases[i].name));
145 PetscCall(cases[i].fn());
146 PetscCall(PetscPrintf(PETSC_COMM_WORLD, " [PASS] %s\n", cases[i].name));
147 }
148
149 PetscCall(PetscPrintf(PETSC_COMM_WORLD, "==> %s complete\n", suite_name));
150 PetscFunctionReturn(0);
151}
Here is the caller graph for this function:

◆ PicurvEnsureDir()

PetscErrorCode PicurvEnsureDir ( const char *  path)

Ensures a directory exists for test output.

Ensures a directory exists, creating it if required.

Definition at line 156 of file test_support.c.

157{
158 PetscFunctionBeginUser;
159 if (mkdir(path, 0777) != 0 && errno != EEXIST) {
160 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN, "Failed to create directory '%s': %s", path, strerror(errno));
161 }
162 PetscFunctionReturn(0);
163}
Here is the caller graph for this function:

◆ PicurvMakeTempDir()

PetscErrorCode PicurvMakeTempDir ( char *  path,
size_t  path_len 
)

Creates a unique temporary directory for one test case.

Creates a unique temporary directory path and materializes the directory.

Definition at line 168 of file test_support.c.

169{
170 PetscFunctionBeginUser;
171 if (!path || path_len < 24) {
172 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "Temp directory buffer is missing or too small.");
173 }
174
175 PetscCall(PetscSNPrintf(path, path_len, "/tmp/picurv-test-XXXXXX"));
176 if (!mkdtemp(path)) {
177 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN, "mkdtemp failed for '%s': %s", path, strerror(errno));
178 }
179 PetscFunctionReturn(0);
180}
Here is the caller graph for this function:

◆ PicurvRemoveTempDir()

PetscErrorCode PicurvRemoveTempDir ( const char *  path)

Recursively removes a temporary directory created by PicurvMakeTempDir.

Definition at line 185 of file test_support.c.

186{
187 char cmd[512];
188
189 PetscFunctionBeginUser;
190 if (!path || path[0] == '\0') PetscFunctionReturn(0);
191 /* Safety: only remove paths under /tmp/picurv-test- */
192 if (strncmp(path, "/tmp/picurv-test-", 17) != 0) {
193 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG,
194 "Refusing to remove path outside /tmp/picurv-test-*: '%s'", path);
195 }
196 PetscCall(PetscSNPrintf(cmd, sizeof(cmd), "rm -rf '%s'", path));
197 if (system(cmd) != 0) {
198 PetscCall(PetscPrintf(PETSC_COMM_SELF, "Warning: failed to remove temp dir '%s'\n", path));
199 }
200 PetscFunctionReturn(0);
201}
Here is the caller graph for this function:

◆ WriteTextFileForTests()

static PetscErrorCode WriteTextFileForTests ( const char *  path,
const char *  contents 
)
static

Writes one small temporary text file used by the richer runtime fixtures.

Definition at line 206 of file test_support.c.

207{
208 FILE *file = NULL;
209
210 PetscFunctionBeginUser;
211 file = fopen(path, "w");
212 PetscCheck(file != NULL, PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN, "Failed to open '%s' for writing.", path);
213 fputs(contents, file);
214 fclose(file);
215 PetscFunctionReturn(0);
216}
Here is the caller graph for this function:

◆ PrepareTinyRuntimeConfig()

static PetscErrorCode PrepareTinyRuntimeConfig ( const char *  bcs_contents,
PetscBool  enable_particles,
const char *  extra_options,
char *  tmpdir,
size_t  tmpdir_len,
char *  control_path,
size_t  control_path_len 
)
static

Creates a tiny control-file bundle used by richer runtime fixtures built through the setup path.

Definition at line 221 of file test_support.c.

228{
229 char bcs_path[PETSC_MAX_PATH_LEN];
230 char post_path[PETSC_MAX_PATH_LEN];
231 char output_dir[PETSC_MAX_PATH_LEN];
232 char log_dir[PETSC_MAX_PATH_LEN];
233 char analysis_dir[PETSC_MAX_PATH_LEN];
234 char control_buffer[8192];
235 const char *particle_block = NULL;
236 const char *default_bcs =
237 "-Xi WALL noslip\n"
238 "+Xi WALL noslip\n"
239 "-Eta WALL noslip\n"
240 "+Eta WALL noslip\n"
241 "-Zeta INLET constant_velocity vx=0.0 vy=0.0 vz=1.5\n"
242 "+Zeta OUTLET conservation\n";
243
244 PetscFunctionBeginUser;
245 PetscCall(PicurvMakeTempDir(tmpdir, tmpdir_len));
246 PetscCall(PetscSNPrintf(bcs_path, sizeof(bcs_path), "%s/bcs.run", tmpdir));
247 PetscCall(PetscSNPrintf(post_path, sizeof(post_path), "%s/post.run", tmpdir));
248 PetscCall(PetscSNPrintf(output_dir, sizeof(output_dir), "%s/results", tmpdir));
249 PetscCall(PetscSNPrintf(log_dir, sizeof(log_dir), "%s/logs", tmpdir));
250 /* The analysis home defaults to a run-relative path, which would resolve against
251 * the harness's working directory instead of this fixture's tree. */
252 PetscCall(PetscSNPrintf(analysis_dir, sizeof(analysis_dir), "%s/results/analysis/metrics", tmpdir));
253 PetscCall(PetscSNPrintf(control_path, control_path_len, "%s/test.control", tmpdir));
254
255 PetscCall(WriteTextFileForTests(bcs_path, bcs_contents ? bcs_contents : default_bcs));
256 PetscCall(WriteTextFileForTests(
257 post_path,
258 "startTime = 0\n"
259 "endTime = 1\n"
260 "timeStep = 1\n"
261 "output_particles = false\n"));
262
263 if (enable_particles) {
264 particle_block =
265 "-numParticles 8\n"
266 "-pinit 2\n"
267 "-psrc_x 0.5\n"
268 "-psrc_y 0.5\n"
269 "-psrc_z 0.5\n"
270 "-particle_restart_mode init\n";
271 } else {
272 particle_block =
273 "-numParticles 0\n"
274 "-pinit 2\n";
275 }
276
277 PetscCall(PetscSNPrintf(
278 control_buffer,
279 sizeof(control_buffer),
280 "-start_step 0\n"
281 "-totalsteps 2\n"
282 "-ren 100.0\n"
283 "-dt 0.001\n"
284 "-finit 1\n"
285 "-ucont_x 0.0\n"
286 "-ucont_y 0.0\n"
287 "-ucont_z 1.5\n"
288 "-bcs_files %s\n"
289 "-profiling_timestep_mode off\n"
290 "-profiling_final_summary true\n"
291 "-postprocessing_config_file %s\n"
292 "-grid\n"
293 "-im 6\n"
294 "-jm 6\n"
295 "-km 6\n"
296 "-xMins 0.0\n"
297 "-xMaxs 1.0\n"
298 "-yMins 0.0\n"
299 "-yMaxs 1.0\n"
300 "-zMins 0.0\n"
301 "-zMaxs 1.0\n"
302 "-rxs 1.0\n"
303 "-rys 1.0\n"
304 "-rzs 1.0\n"
305 "-cgrids 0\n"
306 "-nblk 1\n"
307 "-euler_field_source solve\n"
308 "-mom_solver_type EXPLICIT_RK\n"
309 "-mg_level 1\n"
310 "-poisson 0\n"
311 "-tio 0\n"
312 "-particle_console_output_freq 0\n"
313 "-logfreq 1\n"
314 "-output_dir %s\n"
315 "-restart_dir %s\n"
316 /* The harness owns this temporary tree and wants it wiped between runs. That is
317 * an external absolute path, so it must authorize the delete the same way a user
318 * would - the runtime guard makes no exception for tests. */
319 "-allow_unsafe_log_dir true\n"
320 "-log_dir %s\n"
321 "-analysis_dir %s\n"
322 "%s"
323 /* Appended last: a later occurrence of an option overrides the defaults above. */
324 "%s",
325 bcs_path,
326 post_path,
327 output_dir,
328 output_dir,
329 log_dir,
330 analysis_dir,
331 particle_block,
332 extra_options ? extra_options : ""));
333 PetscCall(WriteTextFileForTests(control_path, control_buffer));
334 PetscFunctionReturn(0);
335}
PetscErrorCode PicurvMakeTempDir(char *path, size_t path_len)
Creates a unique temporary directory for one test case.
static PetscErrorCode WriteTextFileForTests(const char *path, const char *contents)
Writes one small temporary text file used by the richer runtime fixtures.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PicurvCreateMinimalContextsWithPeriodicity()

PetscErrorCode PicurvCreateMinimalContextsWithPeriodicity ( SimCtx **  simCtx_out,
UserCtx **  user_out,
PetscInt  mx,
PetscInt  my,
PetscInt  mz,
PetscBool  x_periodic,
PetscBool  y_periodic,
PetscBool  z_periodic 
)

Builds minimal SimCtx and UserCtx fixtures for C unit tests with configurable periodicity.

Creates minimal PETSc/solver contexts with optional periodic DM boundaries.

Definition at line 339 of file test_support.c.

347{
348 SimCtx *simCtx = NULL;
349 UserCtx *user = NULL;
350 BoundingBox *boxes = NULL;
351 PetscInt da_mx = mx + 1;
352 PetscInt da_my = my + 1;
353 PetscInt da_mz = mz + 1;
354 DMBoundaryType x_boundary = x_periodic ? DM_BOUNDARY_PERIODIC : DM_BOUNDARY_NONE;
355 DMBoundaryType y_boundary = y_periodic ? DM_BOUNDARY_PERIODIC : DM_BOUNDARY_NONE;
356 DMBoundaryType z_boundary = z_periodic ? DM_BOUNDARY_PERIODIC : DM_BOUNDARY_NONE;
357 PetscInt stencil_width = (x_periodic || y_periodic || z_periodic) ? 3 : 1;
358
359 PetscFunctionBeginUser;
360 if (!simCtx_out || !user_out) {
361 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "Output pointers cannot be NULL.");
362 }
363
364 PetscCall(PetscCalloc1(1, &simCtx));
365 PetscCall(PetscCalloc1(1, &user));
366
367 PetscCallMPI(MPI_Comm_rank(PETSC_COMM_WORLD, &simCtx->rank));
368 PetscCallMPI(MPI_Comm_size(PETSC_COMM_WORLD, &simCtx->size));
369 simCtx->block_number = 1;
370 simCtx->dt = 0.1;
371 simCtx->tiout = 2;
372 simCtx->forceScalingFactor = 1.0;
373 simCtx->LoggingFrequency = 1;
374 simCtx->exec_mode = EXEC_MODE_SOLVER;
376 simCtx->solutionConvergenceEnabled = PETSC_TRUE;
377 simCtx->poisson = 0;
378 simCtx->ren = 1.0;
379 PetscCall(LESConfigSetDefaults(&simCtx->les_config));
380 simCtx->schmidt_number = 1.0;
381 simCtx->StartStep = 0;
382 simCtx->StepsToRun = 1;
383 simCtx->step = 1;
384 simCtx->np = 0;
385 simCtx->i_periodic = x_periodic ? 1 : 0;
386 simCtx->j_periodic = y_periodic ? 1 : 0;
387 simCtx->k_periodic = z_periodic ? 1 : 0;
391 PetscCall(PetscStrncpy(simCtx->initialConditionDirectory, "/tmp", sizeof(simCtx->initialConditionDirectory)));
392 simCtx->icVelocityPhysical = 0.0;
393 PetscCall(PetscStrncpy(simCtx->output_dir, "/tmp", sizeof(simCtx->output_dir)));
394 PetscCall(PetscStrncpy(simCtx->restart_dir, "/tmp", sizeof(simCtx->restart_dir)));
395 PetscCall(PetscStrncpy(simCtx->log_dir, "/tmp", sizeof(simCtx->log_dir)));
396 simCtx->mglevels = 1;
397 simCtx->usermg.mglevels = 1;
398 PetscCall(PetscCalloc1(1, &simCtx->usermg.mgctx));
399 simCtx->usermg.mgctx[0].thislevel = 0;
400 PetscCall(PetscCalloc1(simCtx->size, &simCtx->bboxlist));
401 PetscCall(PetscRandomCreate(PETSC_COMM_WORLD, &simCtx->BrownianMotionRNG));
402 PetscCall(PetscRandomSetType(simCtx->BrownianMotionRNG, PETSCRAND48));
403 PetscCall(PetscRandomSetInterval(simCtx->BrownianMotionRNG, 0.0, 1.0));
404 PetscCall(PetscRandomSetSeed(simCtx->BrownianMotionRNG, 12345));
405 PetscCall(PetscRandomSeed(simCtx->BrownianMotionRNG));
406
407 user->simCtx = simCtx;
408 user->_this = 0;
409 user->thislevel = 0;
410 user->mglevels = 1;
411 user->IM = mx;
412 user->JM = my;
413 user->KM = mz;
414 user->Min_X = 0.0;
415 user->Min_Y = 0.0;
416 user->Min_Z = 0.0;
417 user->Max_X = 1.0;
418 user->Max_Y = 1.0;
419 user->Max_Z = 1.0;
420 user->rx = 1.0;
421 user->ry = 1.0;
422 user->rz = 1.0;
423 user->bbox.min_coords.x = 0.0;
424 user->bbox.min_coords.y = 0.0;
425 user->bbox.min_coords.z = 0.0;
426 user->bbox.max_coords.x = 1.0;
427 user->bbox.max_coords.y = 1.0;
428 user->bbox.max_coords.z = 1.0;
429 simCtx->usermg.mgctx[0].user = user;
430 for (PetscMPIInt rank_idx = 0; rank_idx < simCtx->size; ++rank_idx) {
431 simCtx->bboxlist[rank_idx].min_coords.x = 0.0;
432 simCtx->bboxlist[rank_idx].min_coords.y = 0.0;
433 simCtx->bboxlist[rank_idx].min_coords.z = 0.0;
434 simCtx->bboxlist[rank_idx].max_coords.x = 1.0;
435 simCtx->bboxlist[rank_idx].max_coords.y = 1.0;
436 simCtx->bboxlist[rank_idx].max_coords.z = 1.0;
437 }
438
439 PetscCall(DMDACreate3d(PETSC_COMM_WORLD,
440 x_boundary, y_boundary, z_boundary,
441 DMDA_STENCIL_BOX,
442 da_mx, da_my, da_mz,
443 PETSC_DECIDE, PETSC_DECIDE, PETSC_DECIDE,
444 1, stencil_width,
445 NULL, NULL, NULL,
446 &user->da));
447 PetscCall(DMSetUp(user->da));
448 PetscCall(DMGetCoordinateDM(user->da, &user->fda));
449 /* The fixture builds the same DM set the real factory does, through the same
450 * helper, so a test cannot pass against a decomposition production never uses. */
451 PetscCall(CreateCompatibleBlockDM(user->da, 6, &user->fda6));
452
453 /* Post-processing staging pair, matching the factory's Group N. Production gates
454 * these on statistics being active; the fixture builds them unconditionally so a
455 * test can exercise the derived-output path without a resolved window list. */
456 PetscCall(DMCreateGlobalVector(user->da, &user->PostScalar));
457 PetscCall(VecSet(user->PostScalar, 0.0));
458 PetscCall(DMCreateLocalVector(user->da, &user->lPostScalar));
459 PetscCall(VecSet(user->lPostScalar, 0.0));
460 PetscCall(DMCreateGlobalVector(user->da, &user->PostScalarNodal));
461 PetscCall(VecSet(user->PostScalarNodal, 0.0));
462 PetscCall(DMCreateGlobalVector(user->fda, &user->PostVector));
463 PetscCall(VecSet(user->PostVector, 0.0));
464 PetscCall(DMCreateLocalVector(user->fda, &user->lPostVector));
465 PetscCall(VecSet(user->lPostVector, 0.0));
466 PetscCall(DMCreateGlobalVector(user->fda, &user->PostVectorNodal));
467 PetscCall(VecSet(user->PostVectorNodal, 0.0));
468 PetscCall(PetscObjectReference((PetscObject)user->fda));
469 PetscCall(DMDASetUniformCoordinates(user->da, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0));
470 PetscCall(DMDAGetLocalInfo(user->da, &user->info));
471 PetscCall(ComputeLocalBoundingBox(user, &user->bbox));
472 PetscCall(GatherAllBoundingBoxes(user, &boxes));
473 PetscCall(BroadcastAllBoundingBoxes(user, &boxes));
474 for (PetscMPIInt rank_idx = 0; rank_idx < simCtx->size; ++rank_idx) {
475 simCtx->bboxlist[rank_idx] = boxes[rank_idx];
476 }
477 free(boxes);
478
479 PetscCall(CreateZeroedGlobalVector(user->da, &user->P));
480 PetscCall(CreateZeroedLocalVector(user->da, &user->lP));
481 PetscCall(CreateZeroedGlobalVector(user->da, &user->Phi));
482 PetscCall(CreateZeroedLocalVector(user->da, &user->lPhi));
483 PetscCall(CreateZeroedGlobalVector(user->da, &user->Nvert));
484 PetscCall(CreateZeroedLocalVector(user->da, &user->lNvert));
485 PetscCall(CreateZeroedGlobalVector(user->da, &user->ParticleCount));
486 PetscCall(CreateZeroedLocalVector(user->da, &user->lParticleCount));
487 PetscCall(CreateZeroedGlobalVector(user->da, &user->Psi));
488 PetscCall(CreateZeroedLocalVector(user->da, &user->lPsi));
489 PetscCall(CreateZeroedGlobalVector(user->da, &user->Qcrit));
490 PetscCall(CreateZeroedLocalVector(user->da, &user->lQcrit));
491 PetscCall(CreateZeroedGlobalVector(user->da, &user->Qcrit_nodal));
492 PetscCall(CreateZeroedGlobalVector(user->da, &user->P_nodal));
493 PetscCall(CreateZeroedGlobalVector(user->da, &user->Psi_nodal));
494 PetscCall(CreateZeroedGlobalVector(user->da, &user->Aj));
495 PetscCall(CreateZeroedLocalVector(user->da, &user->lAj));
496 PetscCall(CreateZeroedGlobalVector(user->da, &user->Diffusivity));
497 PetscCall(CreateZeroedLocalVector(user->da, &user->lDiffusivity));
498 PetscCall(CreateZeroedGlobalVector(user->da, &user->B));
499 PetscCall(CreateZeroedGlobalVector(user->da, &user->R));
500
501 PetscCall(CreateZeroedGlobalVector(user->fda, &user->Ucat));
502 PetscCall(CreateZeroedLocalVector(user->fda, &user->lUcat));
503 /* Corner-staging workspace, mirroring the finest-level group the real
504 * vector factory creates, so catalog lookups resolve in fixtures too. */
505 PetscCall(CreateZeroedGlobalVector(user->da, &user->CellScalarAtCorner));
506 PetscCall(CreateZeroedLocalVector(user->da, &user->lCellScalarAtCorner));
507 PetscCall(CreateZeroedGlobalVector(user->fda, &user->CellVectorAtCorner));
508 PetscCall(CreateZeroedLocalVector(user->fda, &user->lCellVectorAtCorner));
509 PetscCall(CreateZeroedGlobalVector(user->fda, &user->Ucont));
510 PetscCall(CreateZeroedLocalVector(user->fda, &user->lUcont));
511 PetscCall(CreateZeroedGlobalVector(user->fda, &user->Csi));
512 PetscCall(CreateZeroedLocalVector(user->fda, &user->lCsi));
513 PetscCall(CreateZeroedDuplicate(user->Csi, &user->Eta));
514 PetscCall(CreateZeroedDuplicate(user->lCsi, &user->lEta));
515 PetscCall(CreateZeroedDuplicate(user->Csi, &user->Zet));
516 PetscCall(CreateZeroedDuplicate(user->lCsi, &user->lZet));
517 PetscCall(CreateZeroedGlobalVector(user->fda, &user->Cent));
518 PetscCall(CreateZeroedLocalVector(user->fda, &user->lCent));
519 PetscCall(CreateZeroedGlobalVector(user->fda, &user->GridSpace));
520 PetscCall(CreateZeroedLocalVector(user->fda, &user->lGridSpace));
521 PetscCall(CreateZeroedGlobalVector(user->fda, &user->Centx));
522 PetscCall(CreateZeroedGlobalVector(user->fda, &user->Centy));
523 PetscCall(CreateZeroedGlobalVector(user->fda, &user->Centz));
524 PetscCall(CreateZeroedLocalVector(user->fda, &user->lCentx));
525 PetscCall(CreateZeroedLocalVector(user->fda, &user->lCenty));
526 PetscCall(CreateZeroedLocalVector(user->fda, &user->lCentz));
527 PetscCall(CreateZeroedGlobalVector(user->fda, &user->Ucat_nodal));
528 PetscCall(CreateZeroedGlobalVector(user->fda, &user->DiffusivityGradient));
529 PetscCall(CreateZeroedLocalVector(user->fda, &user->lDiffusivityGradient));
530 PetscCall(CreateZeroedGlobalVector(user->fda, &user->Rhs));
531 PetscCall(CreateZeroedGlobalVector(user->fda, &user->dUcont));
532 PetscCall(CreateZeroedGlobalVector(user->fda, &user->pUcont));
533 PetscCall(CreateZeroedGlobalVector(user->fda, &user->Bcs.Ubcs));
534 PetscCall(CreateZeroedGlobalVector(user->fda, &user->Bcs.Uch));
535
536 PetscCall(CreateZeroedDuplicate(user->Ucont, &user->Ucont_o));
537 PetscCall(CreateZeroedDuplicate(user->lUcont, &user->lUcont_o));
538 PetscCall(CreateZeroedDuplicate(user->Ucont, &user->Ucont_rm1));
539 PetscCall(CreateZeroedDuplicate(user->lUcont, &user->lUcont_rm1));
540 PetscCall(CreateZeroedDuplicate(user->Ucat, &user->Ucat_o));
541 PetscCall(CreateZeroedDuplicate(user->P, &user->P_o));
542 PetscCall(CreateZeroedDuplicate(user->Nvert, &user->Nvert_o));
543 PetscCall(CreateZeroedLocalVector(user->da, &user->lNvert_o));
544 PetscCall(CreateZeroedDuplicate(user->Csi, &user->ICsi));
545 PetscCall(CreateZeroedDuplicate(user->lCsi, &user->lICsi));
546 PetscCall(CreateZeroedDuplicate(user->Csi, &user->IEta));
547 PetscCall(CreateZeroedDuplicate(user->lCsi, &user->lIEta));
548 PetscCall(CreateZeroedDuplicate(user->Csi, &user->IZet));
549 PetscCall(CreateZeroedDuplicate(user->lCsi, &user->lIZet));
550 PetscCall(CreateZeroedDuplicate(user->Csi, &user->JCsi));
551 PetscCall(CreateZeroedDuplicate(user->lCsi, &user->lJCsi));
552 PetscCall(CreateZeroedDuplicate(user->Csi, &user->JEta));
553 PetscCall(CreateZeroedDuplicate(user->lCsi, &user->lJEta));
554 PetscCall(CreateZeroedDuplicate(user->Csi, &user->JZet));
555 PetscCall(CreateZeroedDuplicate(user->lCsi, &user->lJZet));
556 PetscCall(CreateZeroedDuplicate(user->Csi, &user->KCsi));
557 PetscCall(CreateZeroedDuplicate(user->lCsi, &user->lKCsi));
558 PetscCall(CreateZeroedDuplicate(user->Csi, &user->KEta));
559 PetscCall(CreateZeroedDuplicate(user->lCsi, &user->lKEta));
560 PetscCall(CreateZeroedDuplicate(user->Csi, &user->KZet));
561 PetscCall(CreateZeroedDuplicate(user->lCsi, &user->lKZet));
562 PetscCall(CreateZeroedDuplicate(user->Aj, &user->IAj));
563 PetscCall(CreateZeroedDuplicate(user->lAj, &user->lIAj));
564 PetscCall(CreateZeroedDuplicate(user->Aj, &user->JAj));
565 PetscCall(CreateZeroedDuplicate(user->lAj, &user->lJAj));
566 PetscCall(CreateZeroedDuplicate(user->Aj, &user->KAj));
567 PetscCall(CreateZeroedDuplicate(user->lAj, &user->lKAj));
568
569 PetscCall(PicurvPopulateUniformCellCenters(user));
570 PetscCall(PicurvPopulateIdentityMetrics(user));
571
572 *simCtx_out = simCtx;
573 *user_out = user;
574 PetscFunctionReturn(0);
575}
PetscErrorCode BroadcastAllBoundingBoxes(UserCtx *user, BoundingBox **bboxlist)
Broadcasts the bounding box information collected on rank 0 to all other ranks.
Definition grid.c:1061
PetscErrorCode CreateCompatibleBlockDM(DM source, PetscInt dof, DM *result)
Creates a DMDA sharing a block's decomposition at a different degree of freedom.
Definition grid.c:109
PetscErrorCode ComputeLocalBoundingBox(UserCtx *user, BoundingBox *localBBox)
Computes the local bounding box of the grid on the current process.
Definition grid.c:850
PetscErrorCode GatherAllBoundingBoxes(UserCtx *user, BoundingBox **allBBoxes)
Gathers local bounding boxes from all MPI processes to rank 0.
Definition grid.c:999
PetscErrorCode LESConfigSetDefaults(LESConfig *config)
Installs the shipped defaults for every LES closure parameter.
Definition setup.c:206
static PetscErrorCode CreateZeroedLocalVector(DM dm, Vec *vec)
Allocates and zeroes a local vector from the provided DM.
static PetscErrorCode CreateZeroedDuplicate(Vec src, Vec *vec)
Duplicates and zeroes a vector.
PetscErrorCode PicurvPopulateUniformCellCenters(UserCtx *user)
Populates cell center coordinates for a uniform grid on [0,1]^3.
static PetscErrorCode CreateZeroedGlobalVector(DM dm, Vec *vec)
Allocates and zeroes a global vector from the provided DM.
PetscErrorCode PicurvPopulateIdentityMetrics(UserCtx *user)
Populates identity metric vectors on the minimal grid fixture.
PetscReal icVelocityPhysical
Definition variables.h:921
Vec lDiffusivityGradient
Definition variables.h:1117
Vec Qcrit_nodal
Q-criterion averaged to grid nodes; the field a .vts can place correctly.
Definition variables.h:1179
Vec lPostScalar
Definition variables.h:1133
Vec lCent
Definition variables.h:1148
Vec GridSpace
Definition variables.h:1148
Vec P_nodal
Definition variables.h:1176
UserCtx * user
Definition variables.h:729
PetscReal schmidt_number
Definition variables.h:948
PetscMPIInt rank
Definition variables.h:862
PetscInt mglevels
Definition variables.h:1165
PetscInt block_number
Definition variables.h:952
Vec lIEta
Definition variables.h:1151
Vec lIZet
Definition variables.h:1151
Vec lNvert
Definition variables.h:1113
LESConfig les_config
Parameters of the LES closure selected by les.
Definition variables.h:987
PetscReal forceScalingFactor
Definition variables.h:961
InitialConditionMode initialConditionMode
Definition variables.h:916
SimCtx * simCtx
Back-pointer to the master simulation context.
Definition variables.h:1077
FlowDirection flowDirection
Definition variables.h:920
Vec Centz
Definition variables.h:1149
PetscReal Min_X
Definition variables.h:1089
PetscInt KM
Definition variables.h:1088
PetscInt tiout
Definition variables.h:871
UserMG usermg
Definition variables.h:1015
PetscReal ren
Definition variables.h:906
Vec lUcont_rm1
Definition variables.h:1121
Cmpnts max_coords
Maximum x, y, z coordinates of the bounding box.
Definition variables.h:199
PetscInt _this
Definition variables.h:1092
Vec lKEta
Definition variables.h:1153
char output_dir[PETSC_MAX_PATH_LEN]
Definition variables.h:881
PetscBool solutionConvergenceEnabled
Definition variables.h:923
PetscReal dt
Definition variables.h:874
PetscReal ry
Definition variables.h:1093
PetscInt StepsToRun
Definition variables.h:870
PetscInt k_periodic
Definition variables.h:953
Vec Ucat_nodal
Definition variables.h:1177
PetscInt np
Definition variables.h:990
Vec PostScalarNodal
Definition variables.h:1133
PetscReal Max_Y
Definition variables.h:1089
PetscInt thislevel
Definition variables.h:730
Vec DiffusivityGradient
Definition variables.h:1117
Vec lJCsi
Definition variables.h:1152
Vec Ucont
Definition variables.h:1113
PetscInt StartStep
Definition variables.h:869
Cmpnts min_coords
Minimum x, y, z coordinates of the bounding box.
Definition variables.h:198
Vec PostScalar
Definition variables.h:1133
Vec Ubcs
Physical Cartesian velocity at boundary faces. Full 3D array but only boundary-face entries are meani...
Definition variables.h:149
@ MOMENTUM_SOLVER_EXPLICIT_RK
Definition variables.h:693
Vec Qcrit
Definition variables.h:1178
PetscScalar x
Definition variables.h:122
Vec CellScalarAtCorner
Definition variables.h:1126
Vec Centx
Definition variables.h:1149
Vec lParticleCount
Definition variables.h:1171
Vec lUcont_o
Definition variables.h:1120
Vec CellVectorAtCorner
Definition variables.h:1127
Vec Ucat_o
Definition variables.h:1120
PetscInt poisson
Definition variables.h:903
BoundingBox * bboxlist
Definition variables.h:993
Vec lKZet
Definition variables.h:1153
char log_dir[PETSC_MAX_PATH_LEN]
Definition variables.h:882
PetscReal rz
Definition variables.h:1093
Vec lCellScalarAtCorner
Definition variables.h:1126
Vec lJEta
Definition variables.h:1152
Vec lGridSpace
Definition variables.h:1148
PetscInt thislevel
Definition variables.h:1165
PetscScalar z
Definition variables.h:122
Vec pUcont
Definition variables.h:1121
Vec lKCsi
Definition variables.h:1153
Vec ParticleCount
Definition variables.h:1171
Vec Ucont_o
Definition variables.h:1120
PetscInt JM
Definition variables.h:1088
Vec lCenty
Definition variables.h:1150
Vec PostVectorNodal
Definition variables.h:1134
PetscInt mglevels
Definition variables.h:736
PetscReal Min_Z
Definition variables.h:1089
PetscInt mglevels
Definition variables.h:902
Vec lJZet
Definition variables.h:1152
Vec Nvert_o
Definition variables.h:1120
@ FLOW_DIR_UNSET
Definition variables.h:305
Vec lCellVectorAtCorner
Definition variables.h:1127
char initialConditionDirectory[PETSC_MAX_PATH_LEN]
Definition variables.h:918
Vec Psi_nodal
Definition variables.h:1180
Vec lPostVector
Definition variables.h:1134
@ IC_MODE_ZERO
Definition variables.h:178
PetscReal Max_X
Definition variables.h:1089
Vec lCentx
Definition variables.h:1150
Vec Ucont_rm1
Definition variables.h:1121
PetscReal Min_Y
Definition variables.h:1089
PetscInt i_periodic
Definition variables.h:953
Vec lUcont
Definition variables.h:1113
PetscInt step
Definition variables.h:867
Vec Diffusivity
Definition variables.h:1116
PetscRandom BrownianMotionRNG
Definition variables.h:1006
Vec lICsi
Definition variables.h:1151
DMDALocalInfo info
Definition variables.h:1086
Vec dUcont
Definition variables.h:1121
Vec lUcat
Definition variables.h:1113
PetscScalar y
Definition variables.h:122
@ IC_FIELD_UCAT
Definition variables.h:187
PetscMPIInt size
Definition variables.h:863
@ EXEC_MODE_SOLVER
Definition variables.h:832
PetscInt IM
Definition variables.h:1088
Vec PostVector
Definition variables.h:1134
Vec lQcrit
Cell-centred Q-criterion and its ghosted copy for nodal averaging.
Definition variables.h:1178
Vec Nvert
Definition variables.h:1113
MGCtx * mgctx
Definition variables.h:739
Vec lDiffusivity
Definition variables.h:1116
Vec lNvert_o
Definition variables.h:1120
Vec Centy
Definition variables.h:1149
PetscReal rx
Definition variables.h:1093
Vec lCentz
Definition variables.h:1150
InitialConditionField initialConditionField
Definition variables.h:917
ExecutionMode exec_mode
Definition variables.h:878
BoundingBox bbox
Definition variables.h:1090
PetscReal Max_Z
Definition variables.h:1089
MomentumSolverType mom_solver_type
Definition variables.h:899
char restart_dir[PETSC_MAX_PATH_LEN]
Definition variables.h:880
PetscInt LoggingFrequency
Definition variables.h:1020
Vec Uch
Characteristic velocity for boundary conditions.
Definition variables.h:150
PetscInt j_periodic
Definition variables.h:953
Defines a 3D axis-aligned bounding box.
Definition variables.h:197
The master context for the entire simulation.
Definition variables.h:859
User-defined context containing data specific to a single computational grid level.
Definition variables.h:1074
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PicurvCreateMinimalContexts()

PetscErrorCode PicurvCreateMinimalContexts ( SimCtx **  simCtx_out,
UserCtx **  user_out,
PetscInt  mx,
PetscInt  my,
PetscInt  mz 
)

Builds minimal SimCtx and UserCtx fixtures for C unit tests.

Creates minimal PETSc/solver contexts used by isolated kernel tests.

Definition at line 580 of file test_support.c.

581{
582 PetscFunctionBeginUser;
583 PetscCall(PicurvCreateMinimalContextsWithPeriodicity(simCtx_out, user_out, mx, my, mz, PETSC_FALSE, PETSC_FALSE, PETSC_FALSE));
584 PetscFunctionReturn(0);
585}
PetscErrorCode PicurvCreateMinimalContextsWithPeriodicity(SimCtx **simCtx_out, UserCtx **user_out, PetscInt mx, PetscInt my, PetscInt mz, PetscBool x_periodic, PetscBool y_periodic, PetscBool z_periodic)
Builds minimal SimCtx and UserCtx fixtures for C unit tests with configurable periodicity.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PicurvPopulateUniformCellCenters()

PetscErrorCode PicurvPopulateUniformCellCenters ( UserCtx *  user)

Populates cell center coordinates for a uniform grid on [0,1]^3.

Uses the shifted-index convention: cell (i,j,k) is stored at array index (i+1, j+1, k+1). For mx cells on [0,1], cell i has center at (i+0.5)/mx.

Definition at line 593 of file test_support.c.

594{
595 Cmpnts ***cent = NULL;
596 PetscInt mx = user->IM;
597 PetscInt my = user->JM;
598 PetscInt mz = user->KM;
599
600 PetscFunctionBeginUser;
601 PetscCall(DMDAVecGetArray(user->fda, user->Cent, &cent));
602 for (PetscInt k = user->info.zs; k < user->info.zs + user->info.zm; k++) {
603 for (PetscInt j = user->info.ys; j < user->info.ys + user->info.ym; j++) {
604 for (PetscInt i = user->info.xs; i < user->info.xs + user->info.xm; i++) {
605 cent[k][j][i].x = (i - 0.5) / (PetscReal)mx;
606 cent[k][j][i].y = (j - 0.5) / (PetscReal)my;
607 cent[k][j][i].z = (k - 0.5) / (PetscReal)mz;
608 }
609 }
610 }
611 PetscCall(DMDAVecRestoreArray(user->fda, user->Cent, &cent));
612 PetscCall(DMGlobalToLocalBegin(user->fda, user->Cent, INSERT_VALUES, user->lCent));
613 PetscCall(DMGlobalToLocalEnd(user->fda, user->Cent, INSERT_VALUES, user->lCent));
614 PetscFunctionReturn(0);
615}
A 3D point or vector with PetscScalar components.
Definition variables.h:121
Here is the caller graph for this function:

◆ PicurvPopulateIdentityMetrics()

PetscErrorCode PicurvPopulateIdentityMetrics ( UserCtx *  user)

Populates identity metric vectors on the minimal grid fixture.

Fills metric vectors with identity metrics for Cartesian-reference tests.

Definition at line 621 of file test_support.c.

622{
623 Cmpnts ***csi = NULL;
624 Cmpnts ***eta = NULL;
625 Cmpnts ***zet = NULL;
626 Cmpnts ***icsi = NULL;
627 Cmpnts ***ieta = NULL;
628 Cmpnts ***izet = NULL;
629 Cmpnts ***jcsi = NULL;
630 Cmpnts ***jeta = NULL;
631 Cmpnts ***jzet = NULL;
632 Cmpnts ***kcsi = NULL;
633 Cmpnts ***keta = NULL;
634 Cmpnts ***kzet = NULL;
635 PetscReal ***aj = NULL;
636 PetscReal ***iaj = NULL;
637 PetscReal ***jaj = NULL;
638 PetscReal ***kaj = NULL;
639
640 PetscFunctionBeginUser;
641 PetscCall(DMDAVecGetArray(user->fda, user->Csi, &csi));
642 PetscCall(DMDAVecGetArray(user->fda, user->Eta, &eta));
643 PetscCall(DMDAVecGetArray(user->fda, user->Zet, &zet));
644 PetscCall(DMDAVecGetArray(user->fda, user->ICsi, &icsi));
645 PetscCall(DMDAVecGetArray(user->fda, user->IEta, &ieta));
646 PetscCall(DMDAVecGetArray(user->fda, user->IZet, &izet));
647 PetscCall(DMDAVecGetArray(user->fda, user->JCsi, &jcsi));
648 PetscCall(DMDAVecGetArray(user->fda, user->JEta, &jeta));
649 PetscCall(DMDAVecGetArray(user->fda, user->JZet, &jzet));
650 PetscCall(DMDAVecGetArray(user->fda, user->KCsi, &kcsi));
651 PetscCall(DMDAVecGetArray(user->fda, user->KEta, &keta));
652 PetscCall(DMDAVecGetArray(user->fda, user->KZet, &kzet));
653 PetscCall(DMDAVecGetArray(user->da, user->Aj, &aj));
654 PetscCall(DMDAVecGetArray(user->da, user->IAj, &iaj));
655 PetscCall(DMDAVecGetArray(user->da, user->JAj, &jaj));
656 PetscCall(DMDAVecGetArray(user->da, user->KAj, &kaj));
657
658 for (PetscInt k = user->info.zs; k < user->info.zs + user->info.zm; ++k) {
659 for (PetscInt j = user->info.ys; j < user->info.ys + user->info.ym; ++j) {
660 for (PetscInt i = user->info.xs; i < user->info.xs + user->info.xm; ++i) {
661 csi[k][j][i].x = 1.0; csi[k][j][i].y = 0.0; csi[k][j][i].z = 0.0;
662 eta[k][j][i].x = 0.0; eta[k][j][i].y = 1.0; eta[k][j][i].z = 0.0;
663 zet[k][j][i].x = 0.0; zet[k][j][i].y = 0.0; zet[k][j][i].z = 1.0;
664 icsi[k][j][i] = csi[k][j][i];
665 ieta[k][j][i] = eta[k][j][i];
666 izet[k][j][i] = zet[k][j][i];
667 jcsi[k][j][i] = csi[k][j][i];
668 jeta[k][j][i] = eta[k][j][i];
669 jzet[k][j][i] = zet[k][j][i];
670 kcsi[k][j][i] = csi[k][j][i];
671 keta[k][j][i] = eta[k][j][i];
672 kzet[k][j][i] = zet[k][j][i];
673 aj[k][j][i] = 1.0;
674 iaj[k][j][i] = 1.0;
675 jaj[k][j][i] = 1.0;
676 kaj[k][j][i] = 1.0;
677 }
678 }
679 }
680
681 PetscCall(DMDAVecRestoreArray(user->fda, user->Csi, &csi));
682 PetscCall(DMDAVecRestoreArray(user->fda, user->Eta, &eta));
683 PetscCall(DMDAVecRestoreArray(user->fda, user->Zet, &zet));
684 PetscCall(DMDAVecRestoreArray(user->fda, user->ICsi, &icsi));
685 PetscCall(DMDAVecRestoreArray(user->fda, user->IEta, &ieta));
686 PetscCall(DMDAVecRestoreArray(user->fda, user->IZet, &izet));
687 PetscCall(DMDAVecRestoreArray(user->fda, user->JCsi, &jcsi));
688 PetscCall(DMDAVecRestoreArray(user->fda, user->JEta, &jeta));
689 PetscCall(DMDAVecRestoreArray(user->fda, user->JZet, &jzet));
690 PetscCall(DMDAVecRestoreArray(user->fda, user->KCsi, &kcsi));
691 PetscCall(DMDAVecRestoreArray(user->fda, user->KEta, &keta));
692 PetscCall(DMDAVecRestoreArray(user->fda, user->KZet, &kzet));
693 PetscCall(DMDAVecRestoreArray(user->da, user->Aj, &aj));
694 PetscCall(DMDAVecRestoreArray(user->da, user->IAj, &iaj));
695 PetscCall(DMDAVecRestoreArray(user->da, user->JAj, &jaj));
696 PetscCall(DMDAVecRestoreArray(user->da, user->KAj, &kaj));
697
698 PetscCall(DMGlobalToLocalBegin(user->fda, user->Csi, INSERT_VALUES, user->lCsi));
699 PetscCall(DMGlobalToLocalEnd(user->fda, user->Csi, INSERT_VALUES, user->lCsi));
700 PetscCall(DMGlobalToLocalBegin(user->fda, user->Eta, INSERT_VALUES, user->lEta));
701 PetscCall(DMGlobalToLocalEnd(user->fda, user->Eta, INSERT_VALUES, user->lEta));
702 PetscCall(DMGlobalToLocalBegin(user->fda, user->Zet, INSERT_VALUES, user->lZet));
703 PetscCall(DMGlobalToLocalEnd(user->fda, user->Zet, INSERT_VALUES, user->lZet));
704 PetscCall(DMGlobalToLocalBegin(user->fda, user->ICsi, INSERT_VALUES, user->lICsi));
705 PetscCall(DMGlobalToLocalEnd(user->fda, user->ICsi, INSERT_VALUES, user->lICsi));
706 PetscCall(DMGlobalToLocalBegin(user->fda, user->IEta, INSERT_VALUES, user->lIEta));
707 PetscCall(DMGlobalToLocalEnd(user->fda, user->IEta, INSERT_VALUES, user->lIEta));
708 PetscCall(DMGlobalToLocalBegin(user->fda, user->IZet, INSERT_VALUES, user->lIZet));
709 PetscCall(DMGlobalToLocalEnd(user->fda, user->IZet, INSERT_VALUES, user->lIZet));
710 PetscCall(DMGlobalToLocalBegin(user->fda, user->JCsi, INSERT_VALUES, user->lJCsi));
711 PetscCall(DMGlobalToLocalEnd(user->fda, user->JCsi, INSERT_VALUES, user->lJCsi));
712 PetscCall(DMGlobalToLocalBegin(user->fda, user->JEta, INSERT_VALUES, user->lJEta));
713 PetscCall(DMGlobalToLocalEnd(user->fda, user->JEta, INSERT_VALUES, user->lJEta));
714 PetscCall(DMGlobalToLocalBegin(user->fda, user->JZet, INSERT_VALUES, user->lJZet));
715 PetscCall(DMGlobalToLocalEnd(user->fda, user->JZet, INSERT_VALUES, user->lJZet));
716 PetscCall(DMGlobalToLocalBegin(user->fda, user->KCsi, INSERT_VALUES, user->lKCsi));
717 PetscCall(DMGlobalToLocalEnd(user->fda, user->KCsi, INSERT_VALUES, user->lKCsi));
718 PetscCall(DMGlobalToLocalBegin(user->fda, user->KEta, INSERT_VALUES, user->lKEta));
719 PetscCall(DMGlobalToLocalEnd(user->fda, user->KEta, INSERT_VALUES, user->lKEta));
720 PetscCall(DMGlobalToLocalBegin(user->fda, user->KZet, INSERT_VALUES, user->lKZet));
721 PetscCall(DMGlobalToLocalEnd(user->fda, user->KZet, INSERT_VALUES, user->lKZet));
722 PetscCall(DMGlobalToLocalBegin(user->da, user->Nvert, INSERT_VALUES, user->lNvert));
723 PetscCall(DMGlobalToLocalEnd(user->da, user->Nvert, INSERT_VALUES, user->lNvert));
724 PetscCall(DMGlobalToLocalBegin(user->da, user->Aj, INSERT_VALUES, user->lAj));
725 PetscCall(DMGlobalToLocalEnd(user->da, user->Aj, INSERT_VALUES, user->lAj));
726 PetscCall(DMGlobalToLocalBegin(user->da, user->IAj, INSERT_VALUES, user->lIAj));
727 PetscCall(DMGlobalToLocalEnd(user->da, user->IAj, INSERT_VALUES, user->lIAj));
728 PetscCall(DMGlobalToLocalBegin(user->da, user->JAj, INSERT_VALUES, user->lJAj));
729 PetscCall(DMGlobalToLocalEnd(user->da, user->JAj, INSERT_VALUES, user->lJAj));
730 PetscCall(DMGlobalToLocalBegin(user->da, user->KAj, INSERT_VALUES, user->lKAj));
731 PetscCall(DMGlobalToLocalEnd(user->da, user->KAj, INSERT_VALUES, user->lKAj));
732 PetscCall(DMGlobalToLocalBegin(user->da, user->P, INSERT_VALUES, user->lP));
733 PetscCall(DMGlobalToLocalEnd(user->da, user->P, INSERT_VALUES, user->lP));
734 PetscCall(DMGlobalToLocalBegin(user->da, user->Psi, INSERT_VALUES, user->lPsi));
735 PetscCall(DMGlobalToLocalEnd(user->da, user->Psi, INSERT_VALUES, user->lPsi));
736 PetscCall(DMGlobalToLocalBegin(user->fda, user->Ucat, INSERT_VALUES, user->lUcat));
737 PetscCall(DMGlobalToLocalEnd(user->fda, user->Ucat, INSERT_VALUES, user->lUcat));
738 PetscCall(DMGlobalToLocalBegin(user->fda, user->Ucont, INSERT_VALUES, user->lUcont));
739 PetscCall(DMGlobalToLocalEnd(user->fda, user->Ucont, INSERT_VALUES, user->lUcont));
740 PetscCall(DMGlobalToLocalBegin(user->fda, user->Cent, INSERT_VALUES, user->lCent));
741 PetscCall(DMGlobalToLocalEnd(user->fda, user->Cent, INSERT_VALUES, user->lCent));
742 PetscFunctionReturn(0);
743}
Here is the caller graph for this function:

◆ PicurvCreateSwarmPair()

PetscErrorCode PicurvCreateSwarmPair ( UserCtx *  user,
PetscInt  nlocal,
const char *  post_field_name 
)

Creates matched solver and post-processing swarms for tests.

Creates paired runtime/post swarms with optional extra post-processing field registration.

Definition at line 748 of file test_support.c.

749{
750 PetscFunctionBeginUser;
751 if (!user) {
752 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "UserCtx cannot be NULL.");
753 }
754
755 PetscCall(DMCreate(PETSC_COMM_WORLD, &user->swarm));
756 PetscCall(DMSetType(user->swarm, DMSWARM));
757 PetscCall(DMSetDimension(user->swarm, 3));
758 PetscCall(DMSwarmSetType(user->swarm, DMSWARM_BASIC));
759 PetscCall(DMSwarmSetCellDM(user->swarm, user->da));
760 PetscCall(RegisterSwarmFieldForTests(user->swarm, "position", 3, PETSC_REAL));
761 PetscCall(RegisterSwarmFieldForTests(user->swarm, "velocity", 3, PETSC_REAL));
762 PetscCall(RegisterSwarmFieldForTests(user->swarm, "DMSwarm_CellID", 3, PETSC_INT));
763 PetscCall(RegisterSwarmFieldForTests(user->swarm, "weight", 3, PETSC_REAL));
764 PetscCall(RegisterSwarmFieldForTests(user->swarm, "Diffusivity", 1, PETSC_REAL));
765 PetscCall(RegisterSwarmFieldForTests(user->swarm, "DiffusivityGradient", 3, PETSC_REAL));
766 PetscCall(RegisterSwarmFieldForTests(user->swarm, "Psi", 1, PETSC_REAL));
767 PetscCall(RegisterSwarmFieldForTests(user->swarm, "DMSwarm_location_status", 1, PETSC_INT));
768 PetscCall(DMSwarmFinalizeFieldRegister(user->swarm));
769 PetscCall(DMSwarmSetLocalSizes(user->swarm, nlocal, 0));
770
771 PetscCall(DMCreate(PETSC_COMM_WORLD, &user->post_swarm));
772 PetscCall(DMSetType(user->post_swarm, DMSWARM));
773 PetscCall(DMSetDimension(user->post_swarm, 3));
774 PetscCall(DMSwarmSetType(user->post_swarm, DMSWARM_BASIC));
775 PetscCall(DMSwarmSetCellDM(user->post_swarm, user->da));
776 PetscCall(RegisterSwarmFieldForTests(user->post_swarm, post_field_name, 1, PETSC_REAL));
777 PetscCall(DMSwarmFinalizeFieldRegister(user->post_swarm));
778 PetscCall(DMSwarmSetLocalSizes(user->post_swarm, nlocal, 0));
779 PetscFunctionReturn(0);
780}
static PetscErrorCode RegisterSwarmFieldForTests(DM swarm, const char *field_name, PetscInt field_dim, PetscDataType dtype)
Registers one DMSwarm field used by the C test fixtures.
DM post_swarm
Definition variables.h:1175
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PicurvBuildTinyRuntimeContext()

PetscErrorCode PicurvBuildTinyRuntimeContext ( const char *  bcs_contents,
PetscBool  enable_particles,
SimCtx **  simCtx_out,
UserCtx **  user_out,
char *  tmpdir,
size_t  tmpdir_len 
)

Builds a tiny runtime context through the real setup path for behavior-level tests.

Definition at line 785 of file test_support.c.

791{
792 PetscFunctionBeginUser;
793 PetscCall(PicurvBuildTinyRuntimeContextWithOptions(bcs_contents, enable_particles, NULL,
794 simCtx_out, user_out, tmpdir, tmpdir_len));
795 PetscFunctionReturn(0);
796}
PetscErrorCode PicurvBuildTinyRuntimeContextWithOptions(const char *bcs_contents, PetscBool enable_particles, const char *extra_options, SimCtx **simCtx_out, UserCtx **user_out, char *tmpdir, size_t tmpdir_len)
Builds the tiny runtime context with extra control-file options appended.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PicurvBuildTinyRuntimeContextWithOptions()

PetscErrorCode PicurvBuildTinyRuntimeContextWithOptions ( const char *  bcs_contents,
PetscBool  enable_particles,
const char *  extra_options,
SimCtx **  simCtx_out,
UserCtx **  user_out,
char *  tmpdir,
size_t  tmpdir_len 
)

Builds the tiny runtime context with extra control-file options appended.

Builds the tiny runtime context with extra control-file options that override its defaults.

Definition at line 801 of file test_support.c.

808{
809 char control_path[PETSC_MAX_PATH_LEN];
810 SimCtx *simCtx = NULL;
811
812 PetscFunctionBeginUser;
813 PetscCheck(simCtx_out != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "SimCtx output cannot be NULL.");
814
815 PetscCall(PetscOptionsClear(NULL));
816 PetscCall(PrepareTinyRuntimeConfig(bcs_contents, enable_particles, extra_options, tmpdir, tmpdir_len,
817 control_path, sizeof(control_path)));
818 PetscCall(PetscOptionsSetValue(NULL, "-control_file", control_path));
819 PetscCall(CreateSimulationContext(0, NULL, &simCtx));
820 simCtx->exec_mode = EXEC_MODE_SOLVER;
821 PetscCall(SetupSimulationEnvironment(simCtx));
822 PetscCall(SetupGridAndSolvers(simCtx));
823 PetscCall(SetupBoundaryConditions(simCtx));
824 PetscCall(SetupDomainRankInfo(simCtx));
825
826 *simCtx_out = simCtx;
827 if (user_out) {
828 *user_out = simCtx->usermg.mgctx[simCtx->usermg.mglevels - 1].user;
829 }
830 PetscFunctionReturn(0);
831}
PetscErrorCode SetupDomainRankInfo(SimCtx *simCtx)
Sets up the full rank communication infrastructure, including neighbor ranks and bounding box exchang...
Definition setup.c:3227
PetscErrorCode SetupGridAndSolvers(SimCtx *simCtx)
The main orchestrator for setting up all grid-related components.
Definition setup.c:2001
PetscErrorCode SetupSimulationEnvironment(SimCtx *simCtx)
Verifies and prepares the complete I/O environment for a simulation run.
Definition setup.c:1685
PetscErrorCode CreateSimulationContext(int argc, char **argv, SimCtx **p_simCtx)
Allocates and populates the master SimulationContext object.
Definition setup.c:371
PetscErrorCode SetupBoundaryConditions(SimCtx *simCtx)
(Orchestrator) Sets up all boundary conditions for the simulation.
Definition setup.c:2678
static PetscErrorCode PrepareTinyRuntimeConfig(const char *bcs_contents, PetscBool enable_particles, const char *extra_options, char *tmpdir, size_t tmpdir_len, char *control_path, size_t control_path_len)
Creates a tiny control-file bundle used by richer runtime fixtures built through the setup path.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PicurvBuildMomentumPurityRuntimeContext()

PetscErrorCode PicurvBuildMomentumPurityRuntimeContext ( const char *  bcs_contents,
SimCtx **  simCtx_out,
UserCtx **  user_out,
char *  tmpdir,
size_t  tmpdir_len 
)

Builds the production-sized straight-duct fixture used only by the opt-in Newton residual-purity diagnostic.

Builds the production-sized straight-duct fixture used by the opt-in residual-purity diagnostic.

Definition at line 837 of file test_support.c.

842{
843 char bcs_path[PETSC_MAX_PATH_LEN];
844 char post_path[PETSC_MAX_PATH_LEN];
845 char output_dir[PETSC_MAX_PATH_LEN];
846 char log_dir[PETSC_MAX_PATH_LEN];
847 char analysis_dir[PETSC_MAX_PATH_LEN];
848 char control_path[PETSC_MAX_PATH_LEN];
849 char control_buffer[8192];
850 SimCtx *simCtx = NULL;
851 const char *default_bcs =
852 "-Xi WALL noslip\n"
853 "+Xi WALL noslip\n"
854 "-Eta WALL noslip\n"
855 "+Eta WALL noslip\n"
856 "-Zeta INLET constant_velocity vx=0.0 vy=0.0 vz=0.1\n"
857 "+Zeta OUTLET conservation\n";
858
859 PetscFunctionBeginUser;
860 PetscCheck(simCtx_out != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
861 "SimCtx output cannot be NULL.");
862 PetscCall(PetscOptionsClear(NULL));
863 PetscCall(PicurvMakeTempDir(tmpdir, tmpdir_len));
864 PetscCall(PetscSNPrintf(bcs_path, sizeof(bcs_path), "%s/bcs.run", tmpdir));
865 PetscCall(PetscSNPrintf(post_path, sizeof(post_path), "%s/post.run", tmpdir));
866 PetscCall(PetscSNPrintf(output_dir, sizeof(output_dir), "%s/results", tmpdir));
867 PetscCall(PetscSNPrintf(log_dir, sizeof(log_dir), "%s/logs", tmpdir));
868 /* The analysis home defaults to a run-relative path, which would resolve against
869 * the harness's working directory instead of this fixture's tree. */
870 PetscCall(PetscSNPrintf(analysis_dir, sizeof(analysis_dir), "%s/results/analysis/metrics", tmpdir));
871 PetscCall(PetscSNPrintf(control_path, sizeof(control_path), "%s/test.control", tmpdir));
872 PetscCall(WriteTextFileForTests(bcs_path, bcs_contents ? bcs_contents : default_bcs));
873 PetscCall(WriteTextFileForTests(post_path,
874 "startTime = 0\nendTime = 1\ntimeStep = 1\noutput_particles = false\n"));
875 PetscCall(PetscSNPrintf(control_buffer, sizeof(control_buffer),
876 "-start_step 0\n"
877 "-totalsteps 2\n"
878 "-ren 10.0\n"
879 "-dt 0.001\n"
880 "-finit 1\n"
881 "-ucont_x 0.0\n-ucont_y 0.0\n-ucont_z 0.1\n"
882 "-bcs_files %s\n"
883 "-profiling_timestep_mode off\n-profiling_final_summary true\n"
884 "-postprocessing_config_file %s\n"
885 /* PICurv's programmatic grid counts include the leading physical node;
886 * 17x17x65 therefore represents 16x16x64 Cartesian cells. */
887 "-grid\n-im 17\n-jm 17\n-km 65\n"
888 "-xMins 0.0\n-xMaxs 1.0\n-yMins 0.0\n-yMaxs 1.0\n-zMins 0.0\n-zMaxs 4.0\n"
889 "-rxs 1.0\n-rys 1.0\n-rzs 1.0\n-cgrids 0\n-nblk 1\n"
890 "-euler_field_source solve\n-mom_solver_type newton_krylov\n"
891 "-mg_level 1\n-poisson 0\n-tio 0\n-numParticles 0\n-pinit 2\n"
892 "-particle_console_output_freq 0\n-logfreq 1\n"
893 /* See the note above: the harness authorizes deletion of its own temp tree. */
894 "-output_dir %s\n-restart_dir %s\n-allow_unsafe_log_dir true\n-log_dir %s\n"
895 "-analysis_dir %s\n",
896 bcs_path, post_path, output_dir, output_dir, log_dir, analysis_dir));
897 PetscCall(WriteTextFileForTests(control_path, control_buffer));
898 PetscCall(PetscOptionsSetValue(NULL, "-control_file", control_path));
899 PetscCall(CreateSimulationContext(0, NULL, &simCtx));
900 simCtx->exec_mode = EXEC_MODE_SOLVER;
901 PetscCall(SetupSimulationEnvironment(simCtx));
902 PetscCall(SetupGridAndSolvers(simCtx));
903 PetscCall(SetupBoundaryConditions(simCtx));
904 PetscCall(SetupDomainRankInfo(simCtx));
905 *simCtx_out = simCtx;
906 if (user_out) *user_out = simCtx->usermg.mgctx[simCtx->usermg.mglevels - 1].user;
907 PetscFunctionReturn(0);
908}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PicurvDestroyRuntimeContext()

PetscErrorCode PicurvDestroyRuntimeContext ( SimCtx **  simCtx_ptr)

Finalizes and frees a runtime context built by PicurvBuildTinyRuntimeContext.

Definition at line 913 of file test_support.c.

914{
915 PetscFunctionBeginUser;
916 if (simCtx_ptr && *simCtx_ptr) {
917 PetscCall(FinalizeSimulation(*simCtx_ptr));
918 *simCtx_ptr = NULL;
919 }
920 PetscCall(PetscOptionsClear(NULL));
921 PetscFunctionReturn(0);
922}
PetscErrorCode FinalizeSimulation(SimCtx *simCtx)
Main cleanup function for the entire simulation context.
Definition setup.c:4368
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PicurvDestroyMinimalContexts()

PetscErrorCode PicurvDestroyMinimalContexts ( SimCtx **  simCtx_ptr,
UserCtx **  user_ptr 
)

Destroys minimal SimCtx/UserCtx fixtures and all owned PETSc objects.

Destroys contexts previously created by PicurvCreateMinimalContexts.

Definition at line 927 of file test_support.c.

928{
929 UserCtx *user = NULL;
930 SimCtx *simCtx = NULL;
931
932 PetscFunctionBeginUser;
933 if (user_ptr) {
934 user = *user_ptr;
935 }
936 if (simCtx_ptr) {
937 simCtx = *simCtx_ptr;
938 }
939
940 if (simCtx) {
941 PetscCall(DestroySolutionConvergenceState(simCtx));
942 }
943
944 if (user) {
945 PetscCall(DestroyDMIfSet(&user->swarm));
946 PetscCall(DestroyDMIfSet(&user->post_swarm));
947
948 PetscCall(DestroyVecIfSet(&user->P));
949 PetscCall(DestroyVecIfSet(&user->lP));
950 PetscCall(DestroyVecIfSet(&user->Phi));
951 PetscCall(DestroyVecIfSet(&user->lPhi));
952 PetscCall(DestroyVecIfSet(&user->Nvert));
953 PetscCall(DestroyVecIfSet(&user->lNvert));
954 PetscCall(DestroyVecIfSet(&user->ParticleCount));
955 PetscCall(DestroyVecIfSet(&user->lParticleCount));
956 PetscCall(DestroyVecIfSet(&user->Psi));
957 PetscCall(DestroyVecIfSet(&user->lPsi));
958 PetscCall(DestroyVecIfSet(&user->Qcrit));
959 PetscCall(DestroyVecIfSet(&user->lQcrit));
960 PetscCall(DestroyVecIfSet(&user->Qcrit_nodal));
961 PetscCall(DestroyVecIfSet(&user->P_nodal));
962 PetscCall(DestroyVecIfSet(&user->Psi_nodal));
963 PetscCall(DestroyVecIfSet(&user->Ucat));
964 PetscCall(DestroyVecIfSet(&user->lUcat));
965 PetscCall(DestroyVecIfSet(&user->Ucont));
966 PetscCall(DestroyVecIfSet(&user->lUcont));
967 PetscCall(DestroyVecIfSet(&user->Csi));
968 PetscCall(DestroyVecIfSet(&user->lCsi));
969 PetscCall(DestroyVecIfSet(&user->Eta));
970 PetscCall(DestroyVecIfSet(&user->lEta));
971 PetscCall(DestroyVecIfSet(&user->Zet));
972 PetscCall(DestroyVecIfSet(&user->lZet));
973 PetscCall(DestroyVecIfSet(&user->Aj));
974 PetscCall(DestroyVecIfSet(&user->lAj));
975 PetscCall(DestroyVecIfSet(&user->IAj));
976 PetscCall(DestroyVecIfSet(&user->lIAj));
977 PetscCall(DestroyVecIfSet(&user->JAj));
978 PetscCall(DestroyVecIfSet(&user->lJAj));
979 PetscCall(DestroyVecIfSet(&user->KAj));
980 PetscCall(DestroyVecIfSet(&user->lKAj));
981 PetscCall(DestroyVecIfSet(&user->Diffusivity));
982 PetscCall(DestroyVecIfSet(&user->lDiffusivity));
983 PetscCall(DestroyVecIfSet(&user->DiffusivityGradient));
984 PetscCall(DestroyVecIfSet(&user->lDiffusivityGradient));
985 PetscCall(DestroyVecIfSet(&user->CS));
986 PetscCall(DestroyVecIfSet(&user->lCs));
987 PetscCall(DestroyVecIfSet(&user->Nu_t));
988 PetscCall(DestroyVecIfSet(&user->lNu_t));
989 PetscCall(DestroyVecIfSet(&user->Ucont_o));
990 PetscCall(DestroyVecIfSet(&user->lUcont_o));
991 PetscCall(DestroyVecIfSet(&user->Ucat_o));
992 PetscCall(DestroyVecIfSet(&user->P_o));
993 PetscCall(DestroyVecIfSet(&user->Nvert_o));
994 PetscCall(DestroyVecIfSet(&user->lNvert_o));
995 PetscCall(DestroyVecIfSet(&user->Ucont_rm1));
996 PetscCall(DestroyVecIfSet(&user->lUcont_rm1));
997 PetscCall(DestroyVecIfSet(&user->Rhs));
998 PetscCall(DestroyVecIfSet(&user->dUcont));
999 PetscCall(DestroyVecIfSet(&user->pUcont));
1000 PetscCall(DestroyVecIfSet(&user->CellScalarAtCorner));
1001 PetscCall(DestroyVecIfSet(&user->lCellScalarAtCorner));
1002 PetscCall(DestroyVecIfSet(&user->CellVectorAtCorner));
1003 PetscCall(DestroyVecIfSet(&user->lCellVectorAtCorner));
1004 PetscCall(DestroyVecIfSet(&user->B));
1005 PetscCall(DestroyVecIfSet(&user->R));
1006 PetscCall(DestroyVecIfSet(&user->Cent));
1007 PetscCall(DestroyVecIfSet(&user->lCent));
1008 PetscCall(DestroyVecIfSet(&user->GridSpace));
1009 PetscCall(DestroyVecIfSet(&user->lGridSpace));
1010 PetscCall(DestroyVecIfSet(&user->Centx));
1011 PetscCall(DestroyVecIfSet(&user->Centy));
1012 PetscCall(DestroyVecIfSet(&user->Centz));
1013 PetscCall(DestroyVecIfSet(&user->lCentx));
1014 PetscCall(DestroyVecIfSet(&user->lCenty));
1015 PetscCall(DestroyVecIfSet(&user->lCentz));
1016 PetscCall(DestroyVecIfSet(&user->Ucat_nodal));
1017 PetscCall(DestroyVecIfSet(&user->Bcs.Ubcs));
1018 PetscCall(DestroyVecIfSet(&user->Bcs.Uch));
1019 PetscCall(DestroyMatIfSet(&user->A));
1020 PetscCall(DestroyKSPIfSet(&user->ksp));
1021 PetscCall(DestroyNullSpaceIfSet(&user->nullsp));
1022 PetscCall(PetscFree(user->RankCellInfoMap));
1023 user->RankCellInfoMap = NULL;
1024 for (PetscInt face = BC_FACE_NEG_X; face <= BC_FACE_POS_Z; ++face) {
1025 if (user->boundary_faces[face].params) {
1027 user->boundary_faces[face].params = NULL;
1028 }
1029 }
1030
1031 PetscCall(DestroyVecIfSet(&user->PostScalar));
1032 PetscCall(DestroyVecIfSet(&user->lPostScalar));
1033 PetscCall(DestroyVecIfSet(&user->PostScalarNodal));
1034 PetscCall(DestroyVecIfSet(&user->PostVector));
1035 PetscCall(DestroyVecIfSet(&user->lPostVector));
1036 PetscCall(DestroyVecIfSet(&user->PostVectorNodal));
1037 PetscCall(DestroyDMIfSet(&user->fda6));
1038 PetscCall(DestroyDMIfSet(&user->fda));
1039 PetscCall(DestroyDMIfSet(&user->da));
1040 PetscCall(PetscFree(user));
1041 if (user_ptr) {
1042 *user_ptr = NULL;
1043 }
1044 }
1045
1046 if (simCtx) {
1047 PetscCall(DestroyRandomIfSet(&simCtx->BrownianMotionRNG));
1048 PetscCall(PetscFree(simCtx->bboxlist));
1049 PetscCall(PetscFree(simCtx->usermg.mgctx));
1050 PetscCall(PetscFree(simCtx->pps));
1051 PetscCall(PetscFree(simCtx));
1052 if (simCtx_ptr) {
1053 *simCtx_ptr = NULL;
1054 }
1055 }
1056
1057 PetscFunctionReturn(0);
1058}
void FreeBC_ParamList(BC_Param *head)
Frees an entire linked list of boundary-condition parameters.
Definition io.c:672
PetscErrorCode DestroySolutionConvergenceState(SimCtx *simCtx)
Frees any runtime storage allocated for solution-convergence logging.
Definition setup.c:148
static PetscErrorCode DestroyKSPIfSet(KSP *ksp)
Destroys a PETSc KSP only when the handle is non-null.
static PetscErrorCode DestroyDMIfSet(DM *dm)
Destroys a PETSc DM only when the handle is non-null.
static PetscErrorCode DestroyNullSpaceIfSet(MatNullSpace *nullsp)
Destroys a PETSc nullspace only when the handle is non-null.
static PetscErrorCode DestroyRandomIfSet(PetscRandom *rand_ctx)
Destroys a PETSc random generator only when the handle is non-null.
static PetscErrorCode DestroyVecIfSet(Vec *vec)
Destroys a PETSc vector only when the handle is non-null.
static PetscErrorCode DestroyMatIfSet(Mat *mat)
Destroys a PETSc matrix only when the handle is non-null.
BoundaryFaceConfig boundary_faces[6]
Definition variables.h:1099
MatNullSpace nullsp
Definition variables.h:1142
RankCellInfo * RankCellInfoMap
Definition variables.h:1170
Vec lNu_t
Definition variables.h:1156
BC_Param * params
Definition variables.h:394
PostProcessParams * pps
Definition variables.h:1058
@ BC_FACE_NEG_X
Definition variables.h:288
@ BC_FACE_POS_Z
Definition variables.h:290
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PicurvAssertRealNear()

PetscErrorCode PicurvAssertRealNear ( PetscReal  expected,
PetscReal  actual,
PetscReal  tol,
const char *  context 
)

Asserts that two real values agree within tolerance.

Asserts two real values are within tolerance for test validation.

Definition at line 1063 of file test_support.c.

1064{
1065 PetscFunctionBeginUser;
1066 /* Written so that a NaN fails: every comparison with NaN is false, so the form
1067 "difference > tol" let a NaN result pass silently. */
1068 if (!(PetscAbsReal(expected - actual) <= tol)) {
1069 PetscCall(PetscPrintf(PETSC_COMM_WORLD,
1070 "[FAIL] %s | expected=%0.12e actual=%0.12e tol=%0.12e\n",
1071 context, (double)expected, (double)actual, (double)tol));
1072 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_PLIB, "Assertion failed.");
1073 }
1074 PetscFunctionReturn(0);
1075}
Here is the caller graph for this function:

◆ PicurvAssertIntEqual()

PetscErrorCode PicurvAssertIntEqual ( PetscInt  expected,
PetscInt  actual,
const char *  context 
)

Asserts that two integer values are equal.

Asserts two integer values are exactly equal for test validation.

Definition at line 1080 of file test_support.c.

1081{
1082 PetscFunctionBeginUser;
1083 if (expected != actual) {
1084 PetscCall(PetscPrintf(PETSC_COMM_WORLD,
1085 "[FAIL] %s | expected=%" PetscInt_FMT " actual=%" PetscInt_FMT "\n",
1086 context, expected, actual));
1087 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_PLIB, "Assertion failed.");
1088 }
1089 PetscFunctionReturn(0);
1090}
Here is the caller graph for this function:

◆ PicurvAssertBool()

PetscErrorCode PicurvAssertBool ( PetscBool  value,
const char *  context 
)

Asserts that one boolean condition is true.

Asserts a boolean condition is true for test validation.

Definition at line 1095 of file test_support.c.

1096{
1097 PetscFunctionBeginUser;
1098 if (!value) {
1099 PetscCall(PetscPrintf(PETSC_COMM_WORLD, "[FAIL] %s\n", context));
1100 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_PLIB, "Assertion failed.");
1101 }
1102 PetscFunctionReturn(0);
1103}
Here is the caller graph for this function:

◆ PicurvAssertFileExists()

PetscErrorCode PicurvAssertFileExists ( const char *  path,
const char *  context 
)

Asserts that a filesystem path exists as a readable file.

Asserts a filesystem path exists.

Definition at line 1108 of file test_support.c.

1109{
1110 PetscBool exists = PETSC_FALSE;
1111
1112 PetscFunctionBeginUser;
1113 PetscCall(PetscTestFile(path, 'r', &exists));
1114 if (!exists) {
1115 PetscCall(PetscPrintf(PETSC_COMM_WORLD, "[FAIL] %s | missing file: %s\n", context, path));
1116 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN, "Expected file is missing.");
1117 }
1118 PetscFunctionReturn(0);
1119}
Here is the caller graph for this function:

◆ PicurvAssertVecConstant()

PetscErrorCode PicurvAssertVecConstant ( Vec  vec,
PetscScalar  expected,
PetscReal  tol,
const char *  context 
)

Asserts that a PETSc vector is spatially constant within tolerance.

Asserts every entry of a vector equals a constant within tolerance.

Definition at line 1124 of file test_support.c.

1125{
1126 PetscReal vmin = 0.0;
1127 PetscReal vmax = 0.0;
1128
1129 PetscFunctionBeginUser;
1130 PetscCall(VecMin(vec, NULL, &vmin));
1131 PetscCall(VecMax(vec, NULL, &vmax));
1132 PetscCall(PicurvAssertRealNear((PetscReal)expected, vmin, tol, context));
1133 PetscCall(PicurvAssertRealNear((PetscReal)expected, vmax, tol, context));
1134 PetscFunctionReturn(0);
1135}
PetscErrorCode PicurvAssertRealNear(PetscReal expected, PetscReal actual, PetscReal tol, const char *context)
Asserts that two real values agree within tolerance.
Here is the call graph for this function:
Here is the caller graph for this function: