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, 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 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,
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.

227{
228 char bcs_path[PETSC_MAX_PATH_LEN];
229 char post_path[PETSC_MAX_PATH_LEN];
230 char output_dir[PETSC_MAX_PATH_LEN];
231 char log_dir[PETSC_MAX_PATH_LEN];
232 char control_buffer[8192];
233 const char *particle_block = NULL;
234 const char *default_bcs =
235 "-Xi WALL noslip\n"
236 "+Xi WALL noslip\n"
237 "-Eta WALL noslip\n"
238 "+Eta WALL noslip\n"
239 "-Zeta INLET constant_velocity vx=0.0 vy=0.0 vz=1.5\n"
240 "+Zeta OUTLET conservation\n";
241
242 PetscFunctionBeginUser;
243 PetscCall(PicurvMakeTempDir(tmpdir, tmpdir_len));
244 PetscCall(PetscSNPrintf(bcs_path, sizeof(bcs_path), "%s/bcs.run", tmpdir));
245 PetscCall(PetscSNPrintf(post_path, sizeof(post_path), "%s/post.run", tmpdir));
246 PetscCall(PetscSNPrintf(output_dir, sizeof(output_dir), "%s/results", tmpdir));
247 PetscCall(PetscSNPrintf(log_dir, sizeof(log_dir), "%s/logs", tmpdir));
248 PetscCall(PetscSNPrintf(control_path, control_path_len, "%s/test.control", tmpdir));
249
250 PetscCall(WriteTextFileForTests(bcs_path, bcs_contents ? bcs_contents : default_bcs));
251 PetscCall(WriteTextFileForTests(
252 post_path,
253 "startTime = 0\n"
254 "endTime = 1\n"
255 "timeStep = 1\n"
256 "output_particles = false\n"));
257
258 if (enable_particles) {
259 particle_block =
260 "-numParticles 8\n"
261 "-pinit 2\n"
262 "-psrc_x 0.5\n"
263 "-psrc_y 0.5\n"
264 "-psrc_z 0.5\n"
265 "-particle_restart_mode init\n";
266 } else {
267 particle_block =
268 "-numParticles 0\n"
269 "-pinit 2\n";
270 }
271
272 PetscCall(PetscSNPrintf(
273 control_buffer,
274 sizeof(control_buffer),
275 "-start_step 0\n"
276 "-totalsteps 2\n"
277 "-ren 100.0\n"
278 "-dt 0.001\n"
279 "-finit 1\n"
280 "-ucont_x 0.0\n"
281 "-ucont_y 0.0\n"
282 "-ucont_z 1.5\n"
283 "-bcs_files %s\n"
284 "-profiling_timestep_mode off\n"
285 "-profiling_final_summary true\n"
286 "-postprocessing_config_file %s\n"
287 "-grid\n"
288 "-im 6\n"
289 "-jm 6\n"
290 "-km 6\n"
291 "-xMins 0.0\n"
292 "-xMaxs 1.0\n"
293 "-yMins 0.0\n"
294 "-yMaxs 1.0\n"
295 "-zMins 0.0\n"
296 "-zMaxs 1.0\n"
297 "-rxs 1.0\n"
298 "-rys 1.0\n"
299 "-rzs 1.0\n"
300 "-cgrids 0\n"
301 "-nblk 1\n"
302 "-euler_field_source solve\n"
303 "-mom_solver_type EXPLICIT_RK\n"
304 "-mg_level 1\n"
305 "-poisson 0\n"
306 "-tio 0\n"
307 "-particle_console_output_freq 0\n"
308 "-logfreq 1\n"
309 "-output_dir %s\n"
310 "-restart_dir %s\n"
311 "-log_dir %s\n"
312 "%s",
313 bcs_path,
314 post_path,
315 output_dir,
316 output_dir,
317 log_dir,
318 particle_block));
319 PetscCall(WriteTextFileForTests(control_path, control_buffer));
320 PetscFunctionReturn(0);
321}
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 325 of file test_support.c.

333{
334 SimCtx *simCtx = NULL;
335 UserCtx *user = NULL;
336 BoundingBox *boxes = NULL;
337 PetscInt da_mx = mx + 1;
338 PetscInt da_my = my + 1;
339 PetscInt da_mz = mz + 1;
340 DMBoundaryType x_boundary = x_periodic ? DM_BOUNDARY_PERIODIC : DM_BOUNDARY_NONE;
341 DMBoundaryType y_boundary = y_periodic ? DM_BOUNDARY_PERIODIC : DM_BOUNDARY_NONE;
342 DMBoundaryType z_boundary = z_periodic ? DM_BOUNDARY_PERIODIC : DM_BOUNDARY_NONE;
343 PetscInt stencil_width = (x_periodic || y_periodic || z_periodic) ? 3 : 1;
344
345 PetscFunctionBeginUser;
346 if (!simCtx_out || !user_out) {
347 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "Output pointers cannot be NULL.");
348 }
349
350 PetscCall(PetscCalloc1(1, &simCtx));
351 PetscCall(PetscCalloc1(1, &user));
352
353 PetscCallMPI(MPI_Comm_rank(PETSC_COMM_WORLD, &simCtx->rank));
354 PetscCallMPI(MPI_Comm_size(PETSC_COMM_WORLD, &simCtx->size));
355 simCtx->block_number = 1;
356 simCtx->dt = 0.1;
357 simCtx->tiout = 2;
358 simCtx->forceScalingFactor = 1.0;
359 simCtx->LoggingFrequency = 1;
360 simCtx->exec_mode = EXEC_MODE_SOLVER;
362 simCtx->poisson = 0;
363 simCtx->ren = 1.0;
364 simCtx->schmidt_number = 1.0;
365 simCtx->StartStep = 0;
366 simCtx->StepsToRun = 1;
367 simCtx->step = 1;
368 simCtx->np = 0;
369 simCtx->i_periodic = x_periodic ? 1 : 0;
370 simCtx->j_periodic = y_periodic ? 1 : 0;
371 simCtx->k_periodic = z_periodic ? 1 : 0;
375 PetscCall(PetscStrncpy(simCtx->initialConditionDirectory, "/tmp", sizeof(simCtx->initialConditionDirectory)));
376 simCtx->icVelocityPhysical = 0.0;
377 PetscCall(PetscStrncpy(simCtx->euler_subdir, "euler", sizeof(simCtx->euler_subdir)));
378 PetscCall(PetscStrncpy(simCtx->particle_subdir, "particles", sizeof(simCtx->particle_subdir)));
379 PetscCall(PetscStrncpy(simCtx->output_dir, "/tmp", sizeof(simCtx->output_dir)));
380 PetscCall(PetscStrncpy(simCtx->restart_dir, "/tmp", sizeof(simCtx->restart_dir)));
381 PetscCall(PetscStrncpy(simCtx->log_dir, "/tmp", sizeof(simCtx->log_dir)));
382 simCtx->mglevels = 1;
383 simCtx->usermg.mglevels = 1;
384 PetscCall(PetscCalloc1(1, &simCtx->usermg.mgctx));
385 simCtx->usermg.mgctx[0].thislevel = 0;
386 PetscCall(PetscCalloc1(simCtx->size, &simCtx->bboxlist));
387 PetscCall(PetscRandomCreate(PETSC_COMM_WORLD, &simCtx->BrownianMotionRNG));
388 PetscCall(PetscRandomSetType(simCtx->BrownianMotionRNG, PETSCRAND48));
389 PetscCall(PetscRandomSetInterval(simCtx->BrownianMotionRNG, 0.0, 1.0));
390 PetscCall(PetscRandomSetSeed(simCtx->BrownianMotionRNG, 12345));
391 PetscCall(PetscRandomSeed(simCtx->BrownianMotionRNG));
392
393 user->simCtx = simCtx;
394 user->_this = 0;
395 user->thislevel = 0;
396 user->mglevels = 1;
397 user->IM = mx;
398 user->JM = my;
399 user->KM = mz;
400 user->Min_X = 0.0;
401 user->Min_Y = 0.0;
402 user->Min_Z = 0.0;
403 user->Max_X = 1.0;
404 user->Max_Y = 1.0;
405 user->Max_Z = 1.0;
406 user->rx = 1.0;
407 user->ry = 1.0;
408 user->rz = 1.0;
409 user->bbox.min_coords.x = 0.0;
410 user->bbox.min_coords.y = 0.0;
411 user->bbox.min_coords.z = 0.0;
412 user->bbox.max_coords.x = 1.0;
413 user->bbox.max_coords.y = 1.0;
414 user->bbox.max_coords.z = 1.0;
415 simCtx->usermg.mgctx[0].user = user;
416 for (PetscMPIInt rank_idx = 0; rank_idx < simCtx->size; ++rank_idx) {
417 simCtx->bboxlist[rank_idx].min_coords.x = 0.0;
418 simCtx->bboxlist[rank_idx].min_coords.y = 0.0;
419 simCtx->bboxlist[rank_idx].min_coords.z = 0.0;
420 simCtx->bboxlist[rank_idx].max_coords.x = 1.0;
421 simCtx->bboxlist[rank_idx].max_coords.y = 1.0;
422 simCtx->bboxlist[rank_idx].max_coords.z = 1.0;
423 }
424
425 PetscCall(DMDACreate3d(PETSC_COMM_WORLD,
426 x_boundary, y_boundary, z_boundary,
427 DMDA_STENCIL_BOX,
428 da_mx, da_my, da_mz,
429 PETSC_DECIDE, PETSC_DECIDE, PETSC_DECIDE,
430 1, stencil_width,
431 NULL, NULL, NULL,
432 &user->da));
433 PetscCall(DMSetUp(user->da));
434 PetscCall(DMGetCoordinateDM(user->da, &user->fda));
435 PetscCall(PetscObjectReference((PetscObject)user->fda));
436 PetscCall(DMDASetUniformCoordinates(user->da, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0));
437 PetscCall(DMDAGetLocalInfo(user->da, &user->info));
438 PetscCall(ComputeLocalBoundingBox(user, &user->bbox));
439 PetscCall(GatherAllBoundingBoxes(user, &boxes));
440 PetscCall(BroadcastAllBoundingBoxes(user, &boxes));
441 for (PetscMPIInt rank_idx = 0; rank_idx < simCtx->size; ++rank_idx) {
442 simCtx->bboxlist[rank_idx] = boxes[rank_idx];
443 }
444 free(boxes);
445
446 PetscCall(CreateZeroedGlobalVector(user->da, &user->P));
447 PetscCall(CreateZeroedLocalVector(user->da, &user->lP));
448 PetscCall(CreateZeroedGlobalVector(user->da, &user->Phi));
449 PetscCall(CreateZeroedLocalVector(user->da, &user->lPhi));
450 PetscCall(CreateZeroedGlobalVector(user->da, &user->Nvert));
451 PetscCall(CreateZeroedLocalVector(user->da, &user->lNvert));
452 PetscCall(CreateZeroedGlobalVector(user->da, &user->ParticleCount));
453 PetscCall(CreateZeroedLocalVector(user->da, &user->lParticleCount));
454 PetscCall(CreateZeroedGlobalVector(user->da, &user->Psi));
455 PetscCall(CreateZeroedLocalVector(user->da, &user->lPsi));
456 PetscCall(CreateZeroedGlobalVector(user->da, &user->Qcrit));
457 PetscCall(CreateZeroedGlobalVector(user->da, &user->P_nodal));
458 PetscCall(CreateZeroedGlobalVector(user->da, &user->Psi_nodal));
459 PetscCall(CreateZeroedGlobalVector(user->da, &user->Aj));
460 PetscCall(CreateZeroedLocalVector(user->da, &user->lAj));
461 PetscCall(CreateZeroedGlobalVector(user->da, &user->Diffusivity));
462 PetscCall(CreateZeroedLocalVector(user->da, &user->lDiffusivity));
463 PetscCall(CreateZeroedGlobalVector(user->da, &user->B));
464 PetscCall(CreateZeroedGlobalVector(user->da, &user->R));
465
466 PetscCall(CreateZeroedGlobalVector(user->fda, &user->Ucat));
467 PetscCall(CreateZeroedLocalVector(user->fda, &user->lUcat));
468 PetscCall(CreateZeroedGlobalVector(user->fda, &user->Ucont));
469 PetscCall(CreateZeroedLocalVector(user->fda, &user->lUcont));
470 PetscCall(CreateZeroedGlobalVector(user->fda, &user->Csi));
471 PetscCall(CreateZeroedLocalVector(user->fda, &user->lCsi));
472 PetscCall(CreateZeroedDuplicate(user->Csi, &user->Eta));
473 PetscCall(CreateZeroedDuplicate(user->lCsi, &user->lEta));
474 PetscCall(CreateZeroedDuplicate(user->Csi, &user->Zet));
475 PetscCall(CreateZeroedDuplicate(user->lCsi, &user->lZet));
476 PetscCall(CreateZeroedGlobalVector(user->fda, &user->Cent));
477 PetscCall(CreateZeroedLocalVector(user->fda, &user->lCent));
478 PetscCall(CreateZeroedGlobalVector(user->fda, &user->GridSpace));
479 PetscCall(CreateZeroedLocalVector(user->fda, &user->lGridSpace));
480 PetscCall(CreateZeroedGlobalVector(user->fda, &user->Centx));
481 PetscCall(CreateZeroedGlobalVector(user->fda, &user->Centy));
482 PetscCall(CreateZeroedGlobalVector(user->fda, &user->Centz));
483 PetscCall(CreateZeroedLocalVector(user->fda, &user->lCentx));
484 PetscCall(CreateZeroedLocalVector(user->fda, &user->lCenty));
485 PetscCall(CreateZeroedLocalVector(user->fda, &user->lCentz));
486 PetscCall(CreateZeroedGlobalVector(user->fda, &user->Ucat_nodal));
487 PetscCall(CreateZeroedGlobalVector(user->fda, &user->DiffusivityGradient));
488 PetscCall(CreateZeroedLocalVector(user->fda, &user->lDiffusivityGradient));
489 PetscCall(CreateZeroedGlobalVector(user->fda, &user->Rhs));
490 PetscCall(CreateZeroedGlobalVector(user->fda, &user->dUcont));
491 PetscCall(CreateZeroedGlobalVector(user->fda, &user->pUcont));
492 PetscCall(CreateZeroedGlobalVector(user->fda, &user->Bcs.Ubcs));
493 PetscCall(CreateZeroedGlobalVector(user->fda, &user->Bcs.Uch));
494
495 PetscCall(CreateZeroedDuplicate(user->Ucont, &user->Ucont_o));
496 PetscCall(CreateZeroedDuplicate(user->lUcont, &user->lUcont_o));
497 PetscCall(CreateZeroedDuplicate(user->Ucont, &user->Ucont_rm1));
498 PetscCall(CreateZeroedDuplicate(user->lUcont, &user->lUcont_rm1));
499 PetscCall(CreateZeroedDuplicate(user->Ucat, &user->Ucat_o));
500 PetscCall(CreateZeroedDuplicate(user->P, &user->P_o));
501 PetscCall(CreateZeroedDuplicate(user->Nvert, &user->Nvert_o));
502 PetscCall(CreateZeroedLocalVector(user->da, &user->lNvert_o));
503 PetscCall(CreateZeroedDuplicate(user->Csi, &user->ICsi));
504 PetscCall(CreateZeroedDuplicate(user->lCsi, &user->lICsi));
505 PetscCall(CreateZeroedDuplicate(user->Csi, &user->IEta));
506 PetscCall(CreateZeroedDuplicate(user->lCsi, &user->lIEta));
507 PetscCall(CreateZeroedDuplicate(user->Csi, &user->IZet));
508 PetscCall(CreateZeroedDuplicate(user->lCsi, &user->lIZet));
509 PetscCall(CreateZeroedDuplicate(user->Csi, &user->JCsi));
510 PetscCall(CreateZeroedDuplicate(user->lCsi, &user->lJCsi));
511 PetscCall(CreateZeroedDuplicate(user->Csi, &user->JEta));
512 PetscCall(CreateZeroedDuplicate(user->lCsi, &user->lJEta));
513 PetscCall(CreateZeroedDuplicate(user->Csi, &user->JZet));
514 PetscCall(CreateZeroedDuplicate(user->lCsi, &user->lJZet));
515 PetscCall(CreateZeroedDuplicate(user->Csi, &user->KCsi));
516 PetscCall(CreateZeroedDuplicate(user->lCsi, &user->lKCsi));
517 PetscCall(CreateZeroedDuplicate(user->Csi, &user->KEta));
518 PetscCall(CreateZeroedDuplicate(user->lCsi, &user->lKEta));
519 PetscCall(CreateZeroedDuplicate(user->Csi, &user->KZet));
520 PetscCall(CreateZeroedDuplicate(user->lCsi, &user->lKZet));
521 PetscCall(CreateZeroedDuplicate(user->Aj, &user->IAj));
522 PetscCall(CreateZeroedDuplicate(user->lAj, &user->lIAj));
523 PetscCall(CreateZeroedDuplicate(user->Aj, &user->JAj));
524 PetscCall(CreateZeroedDuplicate(user->lAj, &user->lJAj));
525 PetscCall(CreateZeroedDuplicate(user->Aj, &user->KAj));
526 PetscCall(CreateZeroedDuplicate(user->lAj, &user->lKAj));
527
528 PetscCall(PicurvPopulateUniformCellCenters(user));
529 PetscCall(PicurvPopulateIdentityMetrics(user));
530
531 *simCtx_out = simCtx;
532 *user_out = user;
533 PetscFunctionReturn(0);
534}
PetscErrorCode BroadcastAllBoundingBoxes(UserCtx *user, BoundingBox **bboxlist)
Broadcasts the bounding box information collected on rank 0 to all other ranks.
Definition grid.c:1016
PetscErrorCode ComputeLocalBoundingBox(UserCtx *user, BoundingBox *localBBox)
Computes the local bounding box of the grid on the current process.
Definition grid.c:812
PetscErrorCode GatherAllBoundingBoxes(UserCtx *user, BoundingBox **allBBoxes)
Gathers local bounding boxes from all MPI processes to rank 0.
Definition grid.c:954
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:747
Vec lDiffusivityGradient
Definition variables.h:908
Vec lCent
Definition variables.h:927
Vec GridSpace
Definition variables.h:927
Vec P_nodal
Definition variables.h:957
Vec JCsi
Definition variables.h:931
Vec KAj
Definition variables.h:932
UserCtx * user
Definition variables.h:569
Vec JEta
Definition variables.h:931
Vec Zet
Definition variables.h:927
Vec Rhs
Definition variables.h:912
PetscReal schmidt_number
Definition variables.h:765
PetscMPIInt rank
Definition variables.h:687
PetscInt mglevels
Definition variables.h:944
PetscInt block_number
Definition variables.h:768
Vec lIEta
Definition variables.h:930
Vec lIZet
Definition variables.h:930
Vec lNvert
Definition variables.h:904
Vec Phi
Definition variables.h:904
char euler_subdir[PETSC_MAX_PATH_LEN]
Definition variables.h:707
PetscReal forceScalingFactor
Definition variables.h:779
InitialConditionMode initialConditionMode
Definition variables.h:742
SimCtx * simCtx
Back-pointer to the master simulation context.
Definition variables.h:879
Vec IZet
Definition variables.h:930
FlowDirection flowDirection
Definition variables.h:746
Vec Centz
Definition variables.h:928
Vec IEta
Definition variables.h:930
PetscReal Min_X
Definition variables.h:886
PetscInt KM
Definition variables.h:885
PetscInt tiout
Definition variables.h:696
Vec lZet
Definition variables.h:927
UserMG usermg
Definition variables.h:821
Vec Csi
Definition variables.h:927
PetscReal ren
Definition variables.h:732
Vec lUcont_rm1
Definition variables.h:912
Vec lIAj
Definition variables.h:930
Cmpnts max_coords
Maximum x, y, z coordinates of the bounding box.
Definition variables.h:171
PetscInt _this
Definition variables.h:889
Vec lKEta
Definition variables.h:932
char output_dir[PETSC_MAX_PATH_LEN]
Definition variables.h:706
PetscReal dt
Definition variables.h:699
PetscReal ry
Definition variables.h:890
PetscInt StepsToRun
Definition variables.h:695
PetscInt k_periodic
Definition variables.h:769
Vec Ucat_nodal
Definition variables.h:958
Vec lPsi
Definition variables.h:953
PetscInt np
Definition variables.h:796
PetscReal Max_Y
Definition variables.h:886
PetscInt thislevel
Definition variables.h:570
Vec DiffusivityGradient
Definition variables.h:908
Vec lJCsi
Definition variables.h:931
Vec Ucont
Definition variables.h:904
PetscInt StartStep
Definition variables.h:694
Cmpnts min_coords
Minimum x, y, z coordinates of the bounding box.
Definition variables.h:170
Vec Ubcs
Physical Cartesian velocity at boundary faces. Full 3D array but only boundary-face entries are meani...
Definition variables.h:121
@ MOMENTUM_SOLVER_EXPLICIT_RK
Definition variables.h:533
Vec Qcrit
Definition variables.h:959
PetscScalar x
Definition variables.h:101
Vec JZet
Definition variables.h:931
Vec Centx
Definition variables.h:928
BCS Bcs
Definition variables.h:899
Vec lPhi
Definition variables.h:904
Vec lParticleCount
Definition variables.h:952
Vec lUcont_o
Definition variables.h:911
Vec Ucat_o
Definition variables.h:911
PetscInt poisson
Definition variables.h:728
char particle_subdir[PETSC_MAX_PATH_LEN]
Definition variables.h:708
BoundingBox * bboxlist
Definition variables.h:799
Vec lKZet
Definition variables.h:932
Vec Eta
Definition variables.h:927
char log_dir[PETSC_MAX_PATH_LEN]
Definition variables.h:709
PetscReal rz
Definition variables.h:890
Vec lJEta
Definition variables.h:931
Vec lCsi
Definition variables.h:927
Vec lGridSpace
Definition variables.h:927
PetscInt thislevel
Definition variables.h:944
Vec ICsi
Definition variables.h:930
PetscScalar z
Definition variables.h:101
Vec pUcont
Definition variables.h:912
Vec lKCsi
Definition variables.h:932
Vec Ucat
Definition variables.h:904
Vec ParticleCount
Definition variables.h:952
Vec Ucont_o
Definition variables.h:911
PetscInt JM
Definition variables.h:885
Vec lCenty
Definition variables.h:929
PetscInt mglevels
Definition variables.h:576
PetscReal Min_Z
Definition variables.h:886
PetscInt mglevels
Definition variables.h:727
Vec lJZet
Definition variables.h:931
Vec Nvert_o
Definition variables.h:911
@ FLOW_DIR_UNSET
Definition variables.h:277
Vec IAj
Definition variables.h:930
char initialConditionDirectory[PETSC_MAX_PATH_LEN]
Definition variables.h:744
Vec Psi_nodal
Definition variables.h:960
Vec JAj
Definition variables.h:931
Vec KEta
Definition variables.h:932
@ IC_MODE_ZERO
Definition variables.h:150
PetscReal Max_X
Definition variables.h:886
Vec lCentx
Definition variables.h:929
Vec Ucont_rm1
Definition variables.h:912
PetscReal Min_Y
Definition variables.h:886
PetscInt i_periodic
Definition variables.h:769
Vec lUcont
Definition variables.h:904
PetscInt step
Definition variables.h:692
Vec Diffusivity
Definition variables.h:907
Vec lAj
Definition variables.h:927
PetscRandom BrownianMotionRNG
Definition variables.h:810
Vec lICsi
Definition variables.h:930
DMDALocalInfo info
Definition variables.h:883
Vec dUcont
Definition variables.h:912
Vec lUcat
Definition variables.h:904
PetscScalar y
Definition variables.h:101
@ IC_FIELD_UCAT
Definition variables.h:159
PetscMPIInt size
Definition variables.h:688
@ EXEC_MODE_SOLVER
Definition variables.h:657
PetscInt IM
Definition variables.h:885
Vec lEta
Definition variables.h:927
Vec KZet
Definition variables.h:932
Vec Cent
Definition variables.h:927
Vec Nvert
Definition variables.h:904
Vec KCsi
Definition variables.h:932
MGCtx * mgctx
Definition variables.h:579
Vec lDiffusivity
Definition variables.h:907
Vec lNvert_o
Definition variables.h:911
Vec Centy
Definition variables.h:928
PetscReal rx
Definition variables.h:890
Vec lCentz
Definition variables.h:929
InitialConditionField initialConditionField
Definition variables.h:743
ExecutionMode exec_mode
Definition variables.h:703
Vec lJAj
Definition variables.h:931
BoundingBox bbox
Definition variables.h:887
PetscReal Max_Z
Definition variables.h:886
MomentumSolverType mom_solver_type
Definition variables.h:724
Vec lKAj
Definition variables.h:932
char restart_dir[PETSC_MAX_PATH_LEN]
Definition variables.h:705
PetscInt LoggingFrequency
Definition variables.h:826
Vec Psi
Definition variables.h:953
Vec P_o
Definition variables.h:911
Vec Uch
Characteristic velocity for boundary conditions.
Definition variables.h:122
PetscInt j_periodic
Definition variables.h:769
Defines a 3D axis-aligned bounding box.
Definition variables.h:169
The master context for the entire simulation.
Definition variables.h:684
User-defined context containing data specific to a single computational grid level.
Definition variables.h:876
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 539 of file test_support.c.

540{
541 PetscFunctionBeginUser;
542 PetscCall(PicurvCreateMinimalContextsWithPeriodicity(simCtx_out, user_out, mx, my, mz, PETSC_FALSE, PETSC_FALSE, PETSC_FALSE));
543 PetscFunctionReturn(0);
544}
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 552 of file test_support.c.

553{
554 Cmpnts ***cent = NULL;
555 PetscInt mx = user->IM;
556 PetscInt my = user->JM;
557 PetscInt mz = user->KM;
558
559 PetscFunctionBeginUser;
560 PetscCall(DMDAVecGetArray(user->fda, user->Cent, &cent));
561 for (PetscInt k = user->info.zs; k < user->info.zs + user->info.zm; k++) {
562 for (PetscInt j = user->info.ys; j < user->info.ys + user->info.ym; j++) {
563 for (PetscInt i = user->info.xs; i < user->info.xs + user->info.xm; i++) {
564 cent[k][j][i].x = (i - 0.5) / (PetscReal)mx;
565 cent[k][j][i].y = (j - 0.5) / (PetscReal)my;
566 cent[k][j][i].z = (k - 0.5) / (PetscReal)mz;
567 }
568 }
569 }
570 PetscCall(DMDAVecRestoreArray(user->fda, user->Cent, &cent));
571 PetscCall(DMGlobalToLocalBegin(user->fda, user->Cent, INSERT_VALUES, user->lCent));
572 PetscCall(DMGlobalToLocalEnd(user->fda, user->Cent, INSERT_VALUES, user->lCent));
573 PetscFunctionReturn(0);
574}
A 3D point or vector with PetscScalar components.
Definition variables.h:100
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 580 of file test_support.c.

581{
582 Cmpnts ***csi = NULL;
583 Cmpnts ***eta = NULL;
584 Cmpnts ***zet = NULL;
585 Cmpnts ***icsi = NULL;
586 Cmpnts ***ieta = NULL;
587 Cmpnts ***izet = NULL;
588 Cmpnts ***jcsi = NULL;
589 Cmpnts ***jeta = NULL;
590 Cmpnts ***jzet = NULL;
591 Cmpnts ***kcsi = NULL;
592 Cmpnts ***keta = NULL;
593 Cmpnts ***kzet = NULL;
594 PetscReal ***aj = NULL;
595 PetscReal ***iaj = NULL;
596 PetscReal ***jaj = NULL;
597 PetscReal ***kaj = NULL;
598
599 PetscFunctionBeginUser;
600 PetscCall(DMDAVecGetArray(user->fda, user->Csi, &csi));
601 PetscCall(DMDAVecGetArray(user->fda, user->Eta, &eta));
602 PetscCall(DMDAVecGetArray(user->fda, user->Zet, &zet));
603 PetscCall(DMDAVecGetArray(user->fda, user->ICsi, &icsi));
604 PetscCall(DMDAVecGetArray(user->fda, user->IEta, &ieta));
605 PetscCall(DMDAVecGetArray(user->fda, user->IZet, &izet));
606 PetscCall(DMDAVecGetArray(user->fda, user->JCsi, &jcsi));
607 PetscCall(DMDAVecGetArray(user->fda, user->JEta, &jeta));
608 PetscCall(DMDAVecGetArray(user->fda, user->JZet, &jzet));
609 PetscCall(DMDAVecGetArray(user->fda, user->KCsi, &kcsi));
610 PetscCall(DMDAVecGetArray(user->fda, user->KEta, &keta));
611 PetscCall(DMDAVecGetArray(user->fda, user->KZet, &kzet));
612 PetscCall(DMDAVecGetArray(user->da, user->Aj, &aj));
613 PetscCall(DMDAVecGetArray(user->da, user->IAj, &iaj));
614 PetscCall(DMDAVecGetArray(user->da, user->JAj, &jaj));
615 PetscCall(DMDAVecGetArray(user->da, user->KAj, &kaj));
616
617 for (PetscInt k = user->info.zs; k < user->info.zs + user->info.zm; ++k) {
618 for (PetscInt j = user->info.ys; j < user->info.ys + user->info.ym; ++j) {
619 for (PetscInt i = user->info.xs; i < user->info.xs + user->info.xm; ++i) {
620 csi[k][j][i].x = 1.0; csi[k][j][i].y = 0.0; csi[k][j][i].z = 0.0;
621 eta[k][j][i].x = 0.0; eta[k][j][i].y = 1.0; eta[k][j][i].z = 0.0;
622 zet[k][j][i].x = 0.0; zet[k][j][i].y = 0.0; zet[k][j][i].z = 1.0;
623 icsi[k][j][i] = csi[k][j][i];
624 ieta[k][j][i] = eta[k][j][i];
625 izet[k][j][i] = zet[k][j][i];
626 jcsi[k][j][i] = csi[k][j][i];
627 jeta[k][j][i] = eta[k][j][i];
628 jzet[k][j][i] = zet[k][j][i];
629 kcsi[k][j][i] = csi[k][j][i];
630 keta[k][j][i] = eta[k][j][i];
631 kzet[k][j][i] = zet[k][j][i];
632 aj[k][j][i] = 1.0;
633 iaj[k][j][i] = 1.0;
634 jaj[k][j][i] = 1.0;
635 kaj[k][j][i] = 1.0;
636 }
637 }
638 }
639
640 PetscCall(DMDAVecRestoreArray(user->fda, user->Csi, &csi));
641 PetscCall(DMDAVecRestoreArray(user->fda, user->Eta, &eta));
642 PetscCall(DMDAVecRestoreArray(user->fda, user->Zet, &zet));
643 PetscCall(DMDAVecRestoreArray(user->fda, user->ICsi, &icsi));
644 PetscCall(DMDAVecRestoreArray(user->fda, user->IEta, &ieta));
645 PetscCall(DMDAVecRestoreArray(user->fda, user->IZet, &izet));
646 PetscCall(DMDAVecRestoreArray(user->fda, user->JCsi, &jcsi));
647 PetscCall(DMDAVecRestoreArray(user->fda, user->JEta, &jeta));
648 PetscCall(DMDAVecRestoreArray(user->fda, user->JZet, &jzet));
649 PetscCall(DMDAVecRestoreArray(user->fda, user->KCsi, &kcsi));
650 PetscCall(DMDAVecRestoreArray(user->fda, user->KEta, &keta));
651 PetscCall(DMDAVecRestoreArray(user->fda, user->KZet, &kzet));
652 PetscCall(DMDAVecRestoreArray(user->da, user->Aj, &aj));
653 PetscCall(DMDAVecRestoreArray(user->da, user->IAj, &iaj));
654 PetscCall(DMDAVecRestoreArray(user->da, user->JAj, &jaj));
655 PetscCall(DMDAVecRestoreArray(user->da, user->KAj, &kaj));
656
657 PetscCall(DMGlobalToLocalBegin(user->fda, user->Csi, INSERT_VALUES, user->lCsi));
658 PetscCall(DMGlobalToLocalEnd(user->fda, user->Csi, INSERT_VALUES, user->lCsi));
659 PetscCall(DMGlobalToLocalBegin(user->fda, user->Eta, INSERT_VALUES, user->lEta));
660 PetscCall(DMGlobalToLocalEnd(user->fda, user->Eta, INSERT_VALUES, user->lEta));
661 PetscCall(DMGlobalToLocalBegin(user->fda, user->Zet, INSERT_VALUES, user->lZet));
662 PetscCall(DMGlobalToLocalEnd(user->fda, user->Zet, INSERT_VALUES, user->lZet));
663 PetscCall(DMGlobalToLocalBegin(user->fda, user->ICsi, INSERT_VALUES, user->lICsi));
664 PetscCall(DMGlobalToLocalEnd(user->fda, user->ICsi, INSERT_VALUES, user->lICsi));
665 PetscCall(DMGlobalToLocalBegin(user->fda, user->IEta, INSERT_VALUES, user->lIEta));
666 PetscCall(DMGlobalToLocalEnd(user->fda, user->IEta, INSERT_VALUES, user->lIEta));
667 PetscCall(DMGlobalToLocalBegin(user->fda, user->IZet, INSERT_VALUES, user->lIZet));
668 PetscCall(DMGlobalToLocalEnd(user->fda, user->IZet, INSERT_VALUES, user->lIZet));
669 PetscCall(DMGlobalToLocalBegin(user->fda, user->JCsi, INSERT_VALUES, user->lJCsi));
670 PetscCall(DMGlobalToLocalEnd(user->fda, user->JCsi, INSERT_VALUES, user->lJCsi));
671 PetscCall(DMGlobalToLocalBegin(user->fda, user->JEta, INSERT_VALUES, user->lJEta));
672 PetscCall(DMGlobalToLocalEnd(user->fda, user->JEta, INSERT_VALUES, user->lJEta));
673 PetscCall(DMGlobalToLocalBegin(user->fda, user->JZet, INSERT_VALUES, user->lJZet));
674 PetscCall(DMGlobalToLocalEnd(user->fda, user->JZet, INSERT_VALUES, user->lJZet));
675 PetscCall(DMGlobalToLocalBegin(user->fda, user->KCsi, INSERT_VALUES, user->lKCsi));
676 PetscCall(DMGlobalToLocalEnd(user->fda, user->KCsi, INSERT_VALUES, user->lKCsi));
677 PetscCall(DMGlobalToLocalBegin(user->fda, user->KEta, INSERT_VALUES, user->lKEta));
678 PetscCall(DMGlobalToLocalEnd(user->fda, user->KEta, INSERT_VALUES, user->lKEta));
679 PetscCall(DMGlobalToLocalBegin(user->fda, user->KZet, INSERT_VALUES, user->lKZet));
680 PetscCall(DMGlobalToLocalEnd(user->fda, user->KZet, INSERT_VALUES, user->lKZet));
681 PetscCall(DMGlobalToLocalBegin(user->da, user->Nvert, INSERT_VALUES, user->lNvert));
682 PetscCall(DMGlobalToLocalEnd(user->da, user->Nvert, INSERT_VALUES, user->lNvert));
683 PetscCall(DMGlobalToLocalBegin(user->da, user->Aj, INSERT_VALUES, user->lAj));
684 PetscCall(DMGlobalToLocalEnd(user->da, user->Aj, INSERT_VALUES, user->lAj));
685 PetscCall(DMGlobalToLocalBegin(user->da, user->IAj, INSERT_VALUES, user->lIAj));
686 PetscCall(DMGlobalToLocalEnd(user->da, user->IAj, INSERT_VALUES, user->lIAj));
687 PetscCall(DMGlobalToLocalBegin(user->da, user->JAj, INSERT_VALUES, user->lJAj));
688 PetscCall(DMGlobalToLocalEnd(user->da, user->JAj, INSERT_VALUES, user->lJAj));
689 PetscCall(DMGlobalToLocalBegin(user->da, user->KAj, INSERT_VALUES, user->lKAj));
690 PetscCall(DMGlobalToLocalEnd(user->da, user->KAj, INSERT_VALUES, user->lKAj));
691 PetscCall(DMGlobalToLocalBegin(user->da, user->P, INSERT_VALUES, user->lP));
692 PetscCall(DMGlobalToLocalEnd(user->da, user->P, INSERT_VALUES, user->lP));
693 PetscCall(DMGlobalToLocalBegin(user->da, user->Psi, INSERT_VALUES, user->lPsi));
694 PetscCall(DMGlobalToLocalEnd(user->da, user->Psi, INSERT_VALUES, user->lPsi));
695 PetscCall(DMGlobalToLocalBegin(user->fda, user->Ucat, INSERT_VALUES, user->lUcat));
696 PetscCall(DMGlobalToLocalEnd(user->fda, user->Ucat, INSERT_VALUES, user->lUcat));
697 PetscCall(DMGlobalToLocalBegin(user->fda, user->Ucont, INSERT_VALUES, user->lUcont));
698 PetscCall(DMGlobalToLocalEnd(user->fda, user->Ucont, INSERT_VALUES, user->lUcont));
699 PetscCall(DMGlobalToLocalBegin(user->fda, user->Cent, INSERT_VALUES, user->lCent));
700 PetscCall(DMGlobalToLocalEnd(user->fda, user->Cent, INSERT_VALUES, user->lCent));
701 PetscFunctionReturn(0);
702}
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 707 of file test_support.c.

708{
709 PetscFunctionBeginUser;
710 if (!user) {
711 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "UserCtx cannot be NULL.");
712 }
713
714 PetscCall(DMCreate(PETSC_COMM_WORLD, &user->swarm));
715 PetscCall(DMSetType(user->swarm, DMSWARM));
716 PetscCall(DMSetDimension(user->swarm, 3));
717 PetscCall(DMSwarmSetType(user->swarm, DMSWARM_BASIC));
718 PetscCall(DMSwarmSetCellDM(user->swarm, user->da));
719 PetscCall(RegisterSwarmFieldForTests(user->swarm, "position", 3, PETSC_REAL));
720 PetscCall(RegisterSwarmFieldForTests(user->swarm, "velocity", 3, PETSC_REAL));
721 PetscCall(RegisterSwarmFieldForTests(user->swarm, "DMSwarm_CellID", 3, PETSC_INT));
722 PetscCall(RegisterSwarmFieldForTests(user->swarm, "weight", 3, PETSC_REAL));
723 PetscCall(RegisterSwarmFieldForTests(user->swarm, "Diffusivity", 1, PETSC_REAL));
724 PetscCall(RegisterSwarmFieldForTests(user->swarm, "DiffusivityGradient", 3, PETSC_REAL));
725 PetscCall(RegisterSwarmFieldForTests(user->swarm, "Psi", 1, PETSC_REAL));
726 PetscCall(RegisterSwarmFieldForTests(user->swarm, "DMSwarm_location_status", 1, PETSC_INT));
727 PetscCall(DMSwarmFinalizeFieldRegister(user->swarm));
728 PetscCall(DMSwarmSetLocalSizes(user->swarm, nlocal, 0));
729
730 PetscCall(DMCreate(PETSC_COMM_WORLD, &user->post_swarm));
731 PetscCall(DMSetType(user->post_swarm, DMSWARM));
732 PetscCall(DMSetDimension(user->post_swarm, 3));
733 PetscCall(DMSwarmSetType(user->post_swarm, DMSWARM_BASIC));
734 PetscCall(DMSwarmSetCellDM(user->post_swarm, user->da));
735 PetscCall(RegisterSwarmFieldForTests(user->post_swarm, post_field_name, 1, PETSC_REAL));
736 PetscCall(DMSwarmFinalizeFieldRegister(user->post_swarm));
737 PetscCall(DMSwarmSetLocalSizes(user->post_swarm, nlocal, 0));
738 PetscFunctionReturn(0);
739}
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:956
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 744 of file test_support.c.

750{
751 char control_path[PETSC_MAX_PATH_LEN];
752 SimCtx *simCtx = NULL;
753
754 PetscFunctionBeginUser;
755 PetscCheck(simCtx_out != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "SimCtx output cannot be NULL.");
756
757 PetscCall(PetscOptionsClear(NULL));
758 PetscCall(PrepareTinyRuntimeConfig(bcs_contents, enable_particles, tmpdir, tmpdir_len, control_path, sizeof(control_path)));
759 PetscCall(PetscOptionsSetValue(NULL, "-control_file", control_path));
760 PetscCall(CreateSimulationContext(0, NULL, &simCtx));
761 simCtx->exec_mode = EXEC_MODE_SOLVER;
762 PetscCall(SetupSimulationEnvironment(simCtx));
763 PetscCall(SetupGridAndSolvers(simCtx));
764 PetscCall(SetupBoundaryConditions(simCtx));
765 PetscCall(SetupDomainRankInfo(simCtx));
766
767 *simCtx_out = simCtx;
768 if (user_out) {
769 *user_out = simCtx->usermg.mgctx[simCtx->usermg.mglevels - 1].user;
770 }
771 PetscFunctionReturn(0);
772}
PetscErrorCode SetupDomainRankInfo(SimCtx *simCtx)
Sets up the full rank communication infrastructure, including neighbor ranks and bounding box exchang...
Definition setup.c:2673
PetscErrorCode SetupGridAndSolvers(SimCtx *simCtx)
The main orchestrator for setting up all grid-related components.
Definition setup.c:1350
PetscErrorCode SetupSimulationEnvironment(SimCtx *simCtx)
Verifies and prepares the complete I/O environment for a simulation run.
Definition setup.c:1026
PetscErrorCode CreateSimulationContext(int argc, char **argv, SimCtx **p_simCtx)
Allocates and populates the master SimulationContext object.
Definition setup.c:151
PetscErrorCode SetupBoundaryConditions(SimCtx *simCtx)
(Orchestrator) Sets up all boundary conditions for the simulation.
Definition setup.c:2124
static PetscErrorCode PrepareTinyRuntimeConfig(const char *bcs_contents, PetscBool enable_particles, 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 778 of file test_support.c.

783{
784 char bcs_path[PETSC_MAX_PATH_LEN];
785 char post_path[PETSC_MAX_PATH_LEN];
786 char output_dir[PETSC_MAX_PATH_LEN];
787 char log_dir[PETSC_MAX_PATH_LEN];
788 char control_path[PETSC_MAX_PATH_LEN];
789 char control_buffer[8192];
790 SimCtx *simCtx = NULL;
791 const char *default_bcs =
792 "-Xi WALL noslip\n"
793 "+Xi WALL noslip\n"
794 "-Eta WALL noslip\n"
795 "+Eta WALL noslip\n"
796 "-Zeta INLET constant_velocity vx=0.0 vy=0.0 vz=0.1\n"
797 "+Zeta OUTLET conservation\n";
798
799 PetscFunctionBeginUser;
800 PetscCheck(simCtx_out != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
801 "SimCtx output cannot be NULL.");
802 PetscCall(PetscOptionsClear(NULL));
803 PetscCall(PicurvMakeTempDir(tmpdir, tmpdir_len));
804 PetscCall(PetscSNPrintf(bcs_path, sizeof(bcs_path), "%s/bcs.run", tmpdir));
805 PetscCall(PetscSNPrintf(post_path, sizeof(post_path), "%s/post.run", tmpdir));
806 PetscCall(PetscSNPrintf(output_dir, sizeof(output_dir), "%s/results", tmpdir));
807 PetscCall(PetscSNPrintf(log_dir, sizeof(log_dir), "%s/logs", tmpdir));
808 PetscCall(PetscSNPrintf(control_path, sizeof(control_path), "%s/test.control", tmpdir));
809 PetscCall(WriteTextFileForTests(bcs_path, bcs_contents ? bcs_contents : default_bcs));
810 PetscCall(WriteTextFileForTests(post_path,
811 "startTime = 0\nendTime = 1\ntimeStep = 1\noutput_particles = false\n"));
812 PetscCall(PetscSNPrintf(control_buffer, sizeof(control_buffer),
813 "-start_step 0\n"
814 "-totalsteps 2\n"
815 "-ren 10.0\n"
816 "-dt 0.001\n"
817 "-finit 1\n"
818 "-ucont_x 0.0\n-ucont_y 0.0\n-ucont_z 0.1\n"
819 "-bcs_files %s\n"
820 "-profiling_timestep_mode off\n-profiling_final_summary true\n"
821 "-postprocessing_config_file %s\n"
822 /* PICurv's programmatic grid counts include the leading physical node;
823 * 17x17x65 therefore represents 16x16x64 Cartesian cells. */
824 "-grid\n-im 17\n-jm 17\n-km 65\n"
825 "-xMins 0.0\n-xMaxs 1.0\n-yMins 0.0\n-yMaxs 1.0\n-zMins 0.0\n-zMaxs 4.0\n"
826 "-rxs 1.0\n-rys 1.0\n-rzs 1.0\n-cgrids 0\n-nblk 1\n"
827 "-euler_field_source solve\n-mom_solver_type newton_krylov\n"
828 "-mg_level 1\n-poisson 0\n-tio 0\n-numParticles 0\n-pinit 2\n"
829 "-particle_console_output_freq 0\n-logfreq 1\n"
830 "-output_dir %s\n-restart_dir %s\n-log_dir %s\n",
831 bcs_path, post_path, output_dir, output_dir, log_dir));
832 PetscCall(WriteTextFileForTests(control_path, control_buffer));
833 PetscCall(PetscOptionsSetValue(NULL, "-control_file", control_path));
834 PetscCall(CreateSimulationContext(0, NULL, &simCtx));
835 simCtx->exec_mode = EXEC_MODE_SOLVER;
836 PetscCall(SetupSimulationEnvironment(simCtx));
837 PetscCall(SetupGridAndSolvers(simCtx));
838 PetscCall(SetupBoundaryConditions(simCtx));
839 PetscCall(SetupDomainRankInfo(simCtx));
840 *simCtx_out = simCtx;
841 if (user_out) *user_out = simCtx->usermg.mgctx[simCtx->usermg.mglevels - 1].user;
842 PetscFunctionReturn(0);
843}
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 848 of file test_support.c.

849{
850 PetscFunctionBeginUser;
851 if (simCtx_ptr && *simCtx_ptr) {
852 PetscCall(FinalizeSimulation(*simCtx_ptr));
853 *simCtx_ptr = NULL;
854 }
855 PetscCall(PetscOptionsClear(NULL));
856 PetscFunctionReturn(0);
857}
PetscErrorCode FinalizeSimulation(SimCtx *simCtx)
Main cleanup function for the entire simulation context.
Definition setup.c:3808
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 862 of file test_support.c.

863{
864 UserCtx *user = NULL;
865 SimCtx *simCtx = NULL;
866
867 PetscFunctionBeginUser;
868 if (user_ptr) {
869 user = *user_ptr;
870 }
871 if (simCtx_ptr) {
872 simCtx = *simCtx_ptr;
873 }
874
875 if (simCtx) {
876 PetscCall(DestroySolutionConvergenceState(simCtx));
877 }
878
879 if (user) {
880 PetscCall(DestroyDMIfSet(&user->swarm));
881 PetscCall(DestroyDMIfSet(&user->post_swarm));
882
883 PetscCall(DestroyVecIfSet(&user->P));
884 PetscCall(DestroyVecIfSet(&user->lP));
885 PetscCall(DestroyVecIfSet(&user->Phi));
886 PetscCall(DestroyVecIfSet(&user->lPhi));
887 PetscCall(DestroyVecIfSet(&user->Nvert));
888 PetscCall(DestroyVecIfSet(&user->lNvert));
889 PetscCall(DestroyVecIfSet(&user->ParticleCount));
890 PetscCall(DestroyVecIfSet(&user->lParticleCount));
891 PetscCall(DestroyVecIfSet(&user->Psi));
892 PetscCall(DestroyVecIfSet(&user->lPsi));
893 PetscCall(DestroyVecIfSet(&user->Qcrit));
894 PetscCall(DestroyVecIfSet(&user->P_nodal));
895 PetscCall(DestroyVecIfSet(&user->Psi_nodal));
896 PetscCall(DestroyVecIfSet(&user->Ucat));
897 PetscCall(DestroyVecIfSet(&user->lUcat));
898 PetscCall(DestroyVecIfSet(&user->Ucont));
899 PetscCall(DestroyVecIfSet(&user->lUcont));
900 PetscCall(DestroyVecIfSet(&user->Csi));
901 PetscCall(DestroyVecIfSet(&user->lCsi));
902 PetscCall(DestroyVecIfSet(&user->Eta));
903 PetscCall(DestroyVecIfSet(&user->lEta));
904 PetscCall(DestroyVecIfSet(&user->Zet));
905 PetscCall(DestroyVecIfSet(&user->lZet));
906 PetscCall(DestroyVecIfSet(&user->Aj));
907 PetscCall(DestroyVecIfSet(&user->lAj));
908 PetscCall(DestroyVecIfSet(&user->IAj));
909 PetscCall(DestroyVecIfSet(&user->lIAj));
910 PetscCall(DestroyVecIfSet(&user->JAj));
911 PetscCall(DestroyVecIfSet(&user->lJAj));
912 PetscCall(DestroyVecIfSet(&user->KAj));
913 PetscCall(DestroyVecIfSet(&user->lKAj));
914 PetscCall(DestroyVecIfSet(&user->Diffusivity));
915 PetscCall(DestroyVecIfSet(&user->lDiffusivity));
916 PetscCall(DestroyVecIfSet(&user->DiffusivityGradient));
917 PetscCall(DestroyVecIfSet(&user->lDiffusivityGradient));
918 PetscCall(DestroyVecIfSet(&user->CS));
919 PetscCall(DestroyVecIfSet(&user->lCs));
920 PetscCall(DestroyVecIfSet(&user->Nu_t));
921 PetscCall(DestroyVecIfSet(&user->lNu_t));
922 PetscCall(DestroyVecIfSet(&user->Ucont_o));
923 PetscCall(DestroyVecIfSet(&user->lUcont_o));
924 PetscCall(DestroyVecIfSet(&user->Ucat_o));
925 PetscCall(DestroyVecIfSet(&user->P_o));
926 PetscCall(DestroyVecIfSet(&user->Nvert_o));
927 PetscCall(DestroyVecIfSet(&user->lNvert_o));
928 PetscCall(DestroyVecIfSet(&user->Ucont_rm1));
929 PetscCall(DestroyVecIfSet(&user->lUcont_rm1));
930 PetscCall(DestroyVecIfSet(&user->Rhs));
931 PetscCall(DestroyVecIfSet(&user->dUcont));
932 PetscCall(DestroyVecIfSet(&user->pUcont));
933 PetscCall(DestroyVecIfSet(&user->CellFieldAtCorner));
934 PetscCall(DestroyVecIfSet(&user->lCellFieldAtCorner));
935 PetscCall(DestroyVecIfSet(&user->B));
936 PetscCall(DestroyVecIfSet(&user->R));
937 PetscCall(DestroyVecIfSet(&user->Cent));
938 PetscCall(DestroyVecIfSet(&user->lCent));
939 PetscCall(DestroyVecIfSet(&user->GridSpace));
940 PetscCall(DestroyVecIfSet(&user->lGridSpace));
941 PetscCall(DestroyVecIfSet(&user->Centx));
942 PetscCall(DestroyVecIfSet(&user->Centy));
943 PetscCall(DestroyVecIfSet(&user->Centz));
944 PetscCall(DestroyVecIfSet(&user->lCentx));
945 PetscCall(DestroyVecIfSet(&user->lCenty));
946 PetscCall(DestroyVecIfSet(&user->lCentz));
947 PetscCall(DestroyVecIfSet(&user->Ucat_nodal));
948 PetscCall(DestroyVecIfSet(&user->Bcs.Ubcs));
949 PetscCall(DestroyVecIfSet(&user->Bcs.Uch));
950 PetscCall(DestroyMatIfSet(&user->A));
951 PetscCall(DestroyMatIfSet(&user->C));
952 PetscCall(DestroyKSPIfSet(&user->ksp));
953 PetscCall(DestroyNullSpaceIfSet(&user->nullsp));
954 PetscCall(PetscFree(user->RankCellInfoMap));
955 user->RankCellInfoMap = NULL;
956 for (PetscInt face = BC_FACE_NEG_X; face <= BC_FACE_POS_Z; ++face) {
957 if (user->boundary_faces[face].params) {
959 user->boundary_faces[face].params = NULL;
960 }
961 }
962
963 PetscCall(DestroyDMIfSet(&user->fda));
964 PetscCall(DestroyDMIfSet(&user->da));
965 PetscCall(PetscFree(user));
966 if (user_ptr) {
967 *user_ptr = NULL;
968 }
969 }
970
971 if (simCtx) {
972 PetscCall(DestroyRandomIfSet(&simCtx->BrownianMotionRNG));
973 PetscCall(PetscFree(simCtx->bboxlist));
974 PetscCall(PetscFree(simCtx->usermg.mgctx));
975 PetscCall(PetscFree(simCtx->pps));
976 PetscCall(PetscFree(simCtx));
977 if (simCtx_ptr) {
978 *simCtx_ptr = NULL;
979 }
980 }
981
982 PetscFunctionReturn(0);
983}
void FreeBC_ParamList(BC_Param *head)
Frees an entire linked list of boundary-condition parameters.
Definition io.c:302
PetscErrorCode DestroySolutionConvergenceState(SimCtx *simCtx)
Frees any runtime storage allocated for solution-convergence logging.
Definition setup.c:98
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:896
MatNullSpace nullsp
Definition variables.h:918
Vec lCellFieldAtCorner
Definition variables.h:915
Vec lCs
Definition variables.h:935
RankCellInfo * RankCellInfoMap
Definition variables.h:951
Vec lNu_t
Definition variables.h:935
Vec Nu_t
Definition variables.h:935
BC_Param * params
Definition variables.h:368
Vec CellFieldAtCorner
Definition variables.h:915
PostProcessParams * pps
Definition variables.h:860
KSP ksp
Definition variables.h:918
@ BC_FACE_NEG_X
Definition variables.h:260
@ BC_FACE_POS_Z
Definition variables.h:262
Here is the call 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 988 of file test_support.c.

989{
990 PetscFunctionBeginUser;
991 if (PetscAbsReal(expected - actual) > tol) {
992 PetscCall(PetscPrintf(PETSC_COMM_WORLD,
993 "[FAIL] %s | expected=%0.12e actual=%0.12e tol=%0.12e\n",
994 context, (double)expected, (double)actual, (double)tol));
995 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_PLIB, "Assertion failed.");
996 }
997 PetscFunctionReturn(0);
998}
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 1003 of file test_support.c.

1004{
1005 PetscFunctionBeginUser;
1006 if (expected != actual) {
1007 PetscCall(PetscPrintf(PETSC_COMM_WORLD,
1008 "[FAIL] %s | expected=%" PetscInt_FMT " actual=%" PetscInt_FMT "\n",
1009 context, expected, actual));
1010 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_PLIB, "Assertion failed.");
1011 }
1012 PetscFunctionReturn(0);
1013}
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 1018 of file test_support.c.

1019{
1020 PetscFunctionBeginUser;
1021 if (!value) {
1022 PetscCall(PetscPrintf(PETSC_COMM_WORLD, "[FAIL] %s\n", context));
1023 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_PLIB, "Assertion failed.");
1024 }
1025 PetscFunctionReturn(0);
1026}
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 1031 of file test_support.c.

1032{
1033 PetscBool exists = PETSC_FALSE;
1034
1035 PetscFunctionBeginUser;
1036 PetscCall(PetscTestFile(path, 'r', &exists));
1037 if (!exists) {
1038 PetscCall(PetscPrintf(PETSC_COMM_WORLD, "[FAIL] %s | missing file: %s\n", context, path));
1039 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN, "Expected file is missing.");
1040 }
1041 PetscFunctionReturn(0);
1042}
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 1047 of file test_support.c.

1048{
1049 PetscReal vmin = 0.0;
1050 PetscReal vmax = 0.0;
1051
1052 PetscFunctionBeginUser;
1053 PetscCall(VecMin(vec, NULL, &vmin));
1054 PetscCall(VecMax(vec, NULL, &vmax));
1055 PetscCall(PicurvAssertRealNear((PetscReal)expected, vmin, tol, context));
1056 PetscCall(PicurvAssertRealNear((PetscReal)expected, vmax, tol, context));
1057 PetscFunctionReturn(0);
1058}
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: