PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
Loading...
Searching...
No Matches
test_support.c
Go to the documentation of this file.
1/**
2 * @file test_support.c
3 * @brief Shared C test fixtures, assertions, and PETSc helper utilities.
4 */
5
6#include "test_support.h"
7
8#include "grid.h"
9#include "io.h"
10#include "setup.h"
11
12#include <errno.h>
13#include <stdio.h>
14#include <stdlib.h>
15#include <string.h>
16#include <sys/stat.h>
17#include <sys/types.h>
18#include <unistd.h>
19/**
20 * @brief Destroys a PETSc vector only when the handle is non-null.
21 */
22
23static PetscErrorCode DestroyVecIfSet(Vec *vec)
24{
25 PetscFunctionBeginUser;
26 if (vec && *vec) {
27 PetscCall(VecDestroy(vec));
28 }
29 PetscFunctionReturn(0);
30}
31/**
32 * @brief Destroys a PETSc DM only when the handle is non-null.
33 */
34
35static PetscErrorCode DestroyDMIfSet(DM *dm)
36{
37 PetscFunctionBeginUser;
38 if (dm && *dm) {
39 PetscCall(DMDestroy(dm));
40 }
41 PetscFunctionReturn(0);
42}
43/**
44 * @brief Destroys a PETSc matrix only when the handle is non-null.
45 */
46
47static PetscErrorCode DestroyMatIfSet(Mat *mat)
48{
49 PetscFunctionBeginUser;
50 if (mat && *mat) {
51 PetscCall(MatDestroy(mat));
52 }
53 PetscFunctionReturn(0);
54}
55/**
56 * @brief Destroys a PETSc KSP only when the handle is non-null.
57 */
58
59static PetscErrorCode DestroyKSPIfSet(KSP *ksp)
60{
61 PetscFunctionBeginUser;
62 if (ksp && *ksp) {
63 PetscCall(KSPDestroy(ksp));
64 }
65 PetscFunctionReturn(0);
66}
67/**
68 * @brief Destroys a PETSc nullspace only when the handle is non-null.
69 */
70
71static PetscErrorCode DestroyNullSpaceIfSet(MatNullSpace *nullsp)
72{
73 PetscFunctionBeginUser;
74 if (nullsp && *nullsp) {
75 PetscCall(MatNullSpaceDestroy(nullsp));
76 }
77 PetscFunctionReturn(0);
78}
79/**
80 * @brief Destroys a PETSc random generator only when the handle is non-null.
81 */
82
83static PetscErrorCode DestroyRandomIfSet(PetscRandom *rand_ctx)
84{
85 PetscFunctionBeginUser;
86 if (rand_ctx && *rand_ctx) {
87 PetscCall(PetscRandomDestroy(rand_ctx));
88 }
89 PetscFunctionReturn(0);
90}
91/**
92 * @brief Registers one DMSwarm field used by the C test fixtures.
93 */
94
95static PetscErrorCode RegisterSwarmFieldForTests(DM swarm, const char *field_name, PetscInt field_dim, PetscDataType dtype)
96{
97 PetscFunctionBeginUser;
98 PetscCall(DMSwarmRegisterPetscDatatypeField(swarm, field_name, field_dim, dtype));
99 PetscFunctionReturn(0);
100}
101/**
102 * @brief Allocates and zeroes a global vector from the provided DM.
103 */
104
105static PetscErrorCode CreateZeroedGlobalVector(DM dm, Vec *vec)
106{
107 PetscFunctionBeginUser;
108 PetscCall(DMCreateGlobalVector(dm, vec));
109 PetscCall(VecSet(*vec, 0.0));
110 PetscFunctionReturn(0);
111}
112/**
113 * @brief Allocates and zeroes a local vector from the provided DM.
114 */
115
116static PetscErrorCode CreateZeroedLocalVector(DM dm, Vec *vec)
117{
118 PetscFunctionBeginUser;
119 PetscCall(DMCreateLocalVector(dm, vec));
120 PetscCall(VecSet(*vec, 0.0));
121 PetscFunctionReturn(0);
122}
123/**
124 * @brief Duplicates and zeroes a vector.
125 */
126
127static PetscErrorCode CreateZeroedDuplicate(Vec src, Vec *vec)
128{
129 PetscFunctionBeginUser;
130 PetscCall(VecDuplicate(src, vec));
131 PetscCall(VecSet(*vec, 0.0));
132 PetscFunctionReturn(0);
133}
134/**
135 * @brief Runs a named C test suite and prints pass/fail progress markers.
136 */
137
138PetscErrorCode PicurvRunTests(const char *suite_name, const PicurvTestCase *cases, size_t case_count)
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}
152/**
153 * @brief Ensures a directory exists for test output.
154 */
155
156PetscErrorCode PicurvEnsureDir(const char *path)
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}
164/**
165 * @brief Creates a unique temporary directory for one test case.
166 */
167
168PetscErrorCode PicurvMakeTempDir(char *path, size_t path_len)
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}
181/**
182 * @brief Recursively removes a temporary directory created by PicurvMakeTempDir.
183 */
184
185PetscErrorCode PicurvRemoveTempDir(const char *path)
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}
202/**
203 * @brief Writes one small temporary text file used by the richer runtime fixtures.
204 */
205
206static PetscErrorCode WriteTextFileForTests(const char *path, const char *contents)
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}
217/**
218 * @brief Creates a tiny control-file bundle used by richer runtime fixtures built through the setup path.
219 */
220
221static PetscErrorCode PrepareTinyRuntimeConfig(const char *bcs_contents,
222 PetscBool enable_particles,
223 char *tmpdir,
224 size_t tmpdir_len,
225 char *control_path,
226 size_t control_path_len)
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}
322/**
323 * @brief Builds minimal SimCtx and UserCtx fixtures for C unit tests with configurable periodicity.
324 */
326 UserCtx **user_out,
327 PetscInt mx,
328 PetscInt my,
329 PetscInt mz,
330 PetscBool x_periodic,
331 PetscBool y_periodic,
332 PetscBool z_periodic)
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->solutionConvergenceEnabled = PETSC_TRUE;
363 simCtx->poisson = 0;
364 simCtx->ren = 1.0;
365 simCtx->schmidt_number = 1.0;
366 simCtx->StartStep = 0;
367 simCtx->StepsToRun = 1;
368 simCtx->step = 1;
369 simCtx->np = 0;
370 simCtx->i_periodic = x_periodic ? 1 : 0;
371 simCtx->j_periodic = y_periodic ? 1 : 0;
372 simCtx->k_periodic = z_periodic ? 1 : 0;
376 PetscCall(PetscStrncpy(simCtx->initialConditionDirectory, "/tmp", sizeof(simCtx->initialConditionDirectory)));
377 simCtx->icVelocityPhysical = 0.0;
378 PetscCall(PetscStrncpy(simCtx->output_dir, "/tmp", sizeof(simCtx->output_dir)));
379 PetscCall(PetscStrncpy(simCtx->restart_dir, "/tmp", sizeof(simCtx->restart_dir)));
380 PetscCall(PetscStrncpy(simCtx->log_dir, "/tmp", sizeof(simCtx->log_dir)));
381 simCtx->mglevels = 1;
382 simCtx->usermg.mglevels = 1;
383 PetscCall(PetscCalloc1(1, &simCtx->usermg.mgctx));
384 simCtx->usermg.mgctx[0].thislevel = 0;
385 PetscCall(PetscCalloc1(simCtx->size, &simCtx->bboxlist));
386 PetscCall(PetscRandomCreate(PETSC_COMM_WORLD, &simCtx->BrownianMotionRNG));
387 PetscCall(PetscRandomSetType(simCtx->BrownianMotionRNG, PETSCRAND48));
388 PetscCall(PetscRandomSetInterval(simCtx->BrownianMotionRNG, 0.0, 1.0));
389 PetscCall(PetscRandomSetSeed(simCtx->BrownianMotionRNG, 12345));
390 PetscCall(PetscRandomSeed(simCtx->BrownianMotionRNG));
391
392 user->simCtx = simCtx;
393 user->_this = 0;
394 user->thislevel = 0;
395 user->mglevels = 1;
396 user->IM = mx;
397 user->JM = my;
398 user->KM = mz;
399 user->Min_X = 0.0;
400 user->Min_Y = 0.0;
401 user->Min_Z = 0.0;
402 user->Max_X = 1.0;
403 user->Max_Y = 1.0;
404 user->Max_Z = 1.0;
405 user->rx = 1.0;
406 user->ry = 1.0;
407 user->rz = 1.0;
408 user->bbox.min_coords.x = 0.0;
409 user->bbox.min_coords.y = 0.0;
410 user->bbox.min_coords.z = 0.0;
411 user->bbox.max_coords.x = 1.0;
412 user->bbox.max_coords.y = 1.0;
413 user->bbox.max_coords.z = 1.0;
414 simCtx->usermg.mgctx[0].user = user;
415 for (PetscMPIInt rank_idx = 0; rank_idx < simCtx->size; ++rank_idx) {
416 simCtx->bboxlist[rank_idx].min_coords.x = 0.0;
417 simCtx->bboxlist[rank_idx].min_coords.y = 0.0;
418 simCtx->bboxlist[rank_idx].min_coords.z = 0.0;
419 simCtx->bboxlist[rank_idx].max_coords.x = 1.0;
420 simCtx->bboxlist[rank_idx].max_coords.y = 1.0;
421 simCtx->bboxlist[rank_idx].max_coords.z = 1.0;
422 }
423
424 PetscCall(DMDACreate3d(PETSC_COMM_WORLD,
425 x_boundary, y_boundary, z_boundary,
426 DMDA_STENCIL_BOX,
427 da_mx, da_my, da_mz,
428 PETSC_DECIDE, PETSC_DECIDE, PETSC_DECIDE,
429 1, stencil_width,
430 NULL, NULL, NULL,
431 &user->da));
432 PetscCall(DMSetUp(user->da));
433 PetscCall(DMGetCoordinateDM(user->da, &user->fda));
434 /* The fixture builds the same DM set the real factory does, through the same
435 * helper, so a test cannot pass against a decomposition production never uses. */
436 PetscCall(CreateCompatibleBlockDM(user->da, 6, &user->fda6));
437
438 /* Post-processing staging pair, matching the factory's Group N. Production gates
439 * these on statistics being active; the fixture builds them unconditionally so a
440 * test can exercise the derived-output path without a resolved window list. */
441 PetscCall(DMCreateGlobalVector(user->da, &user->PostScalar));
442 PetscCall(VecSet(user->PostScalar, 0.0));
443 PetscCall(DMCreateLocalVector(user->da, &user->lPostScalar));
444 PetscCall(VecSet(user->lPostScalar, 0.0));
445 PetscCall(DMCreateGlobalVector(user->da, &user->PostScalarNodal));
446 PetscCall(VecSet(user->PostScalarNodal, 0.0));
447 PetscCall(DMCreateGlobalVector(user->fda, &user->PostVector));
448 PetscCall(VecSet(user->PostVector, 0.0));
449 PetscCall(DMCreateLocalVector(user->fda, &user->lPostVector));
450 PetscCall(VecSet(user->lPostVector, 0.0));
451 PetscCall(DMCreateGlobalVector(user->fda, &user->PostVectorNodal));
452 PetscCall(VecSet(user->PostVectorNodal, 0.0));
453 PetscCall(PetscObjectReference((PetscObject)user->fda));
454 PetscCall(DMDASetUniformCoordinates(user->da, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0));
455 PetscCall(DMDAGetLocalInfo(user->da, &user->info));
456 PetscCall(ComputeLocalBoundingBox(user, &user->bbox));
457 PetscCall(GatherAllBoundingBoxes(user, &boxes));
458 PetscCall(BroadcastAllBoundingBoxes(user, &boxes));
459 for (PetscMPIInt rank_idx = 0; rank_idx < simCtx->size; ++rank_idx) {
460 simCtx->bboxlist[rank_idx] = boxes[rank_idx];
461 }
462 free(boxes);
463
464 PetscCall(CreateZeroedGlobalVector(user->da, &user->P));
465 PetscCall(CreateZeroedLocalVector(user->da, &user->lP));
466 PetscCall(CreateZeroedGlobalVector(user->da, &user->Phi));
467 PetscCall(CreateZeroedLocalVector(user->da, &user->lPhi));
468 PetscCall(CreateZeroedGlobalVector(user->da, &user->Nvert));
469 PetscCall(CreateZeroedLocalVector(user->da, &user->lNvert));
470 PetscCall(CreateZeroedGlobalVector(user->da, &user->ParticleCount));
471 PetscCall(CreateZeroedLocalVector(user->da, &user->lParticleCount));
472 PetscCall(CreateZeroedGlobalVector(user->da, &user->Psi));
473 PetscCall(CreateZeroedLocalVector(user->da, &user->lPsi));
474 PetscCall(CreateZeroedGlobalVector(user->da, &user->Qcrit));
475 PetscCall(CreateZeroedGlobalVector(user->da, &user->P_nodal));
476 PetscCall(CreateZeroedGlobalVector(user->da, &user->Psi_nodal));
477 PetscCall(CreateZeroedGlobalVector(user->da, &user->Aj));
478 PetscCall(CreateZeroedLocalVector(user->da, &user->lAj));
479 PetscCall(CreateZeroedGlobalVector(user->da, &user->Diffusivity));
480 PetscCall(CreateZeroedLocalVector(user->da, &user->lDiffusivity));
481 PetscCall(CreateZeroedGlobalVector(user->da, &user->B));
482 PetscCall(CreateZeroedGlobalVector(user->da, &user->R));
483
484 PetscCall(CreateZeroedGlobalVector(user->fda, &user->Ucat));
485 PetscCall(CreateZeroedLocalVector(user->fda, &user->lUcat));
486 /* Corner-staging workspace, mirroring the finest-level group the real
487 * vector factory creates, so catalog lookups resolve in fixtures too. */
488 PetscCall(CreateZeroedGlobalVector(user->da, &user->CellScalarAtCorner));
489 PetscCall(CreateZeroedLocalVector(user->da, &user->lCellScalarAtCorner));
490 PetscCall(CreateZeroedGlobalVector(user->fda, &user->CellVectorAtCorner));
491 PetscCall(CreateZeroedLocalVector(user->fda, &user->lCellVectorAtCorner));
492 PetscCall(CreateZeroedGlobalVector(user->fda, &user->Ucont));
493 PetscCall(CreateZeroedLocalVector(user->fda, &user->lUcont));
494 PetscCall(CreateZeroedGlobalVector(user->fda, &user->Csi));
495 PetscCall(CreateZeroedLocalVector(user->fda, &user->lCsi));
496 PetscCall(CreateZeroedDuplicate(user->Csi, &user->Eta));
497 PetscCall(CreateZeroedDuplicate(user->lCsi, &user->lEta));
498 PetscCall(CreateZeroedDuplicate(user->Csi, &user->Zet));
499 PetscCall(CreateZeroedDuplicate(user->lCsi, &user->lZet));
500 PetscCall(CreateZeroedGlobalVector(user->fda, &user->Cent));
501 PetscCall(CreateZeroedLocalVector(user->fda, &user->lCent));
502 PetscCall(CreateZeroedGlobalVector(user->fda, &user->GridSpace));
503 PetscCall(CreateZeroedLocalVector(user->fda, &user->lGridSpace));
504 PetscCall(CreateZeroedGlobalVector(user->fda, &user->Centx));
505 PetscCall(CreateZeroedGlobalVector(user->fda, &user->Centy));
506 PetscCall(CreateZeroedGlobalVector(user->fda, &user->Centz));
507 PetscCall(CreateZeroedLocalVector(user->fda, &user->lCentx));
508 PetscCall(CreateZeroedLocalVector(user->fda, &user->lCenty));
509 PetscCall(CreateZeroedLocalVector(user->fda, &user->lCentz));
510 PetscCall(CreateZeroedGlobalVector(user->fda, &user->Ucat_nodal));
511 PetscCall(CreateZeroedGlobalVector(user->fda, &user->DiffusivityGradient));
512 PetscCall(CreateZeroedLocalVector(user->fda, &user->lDiffusivityGradient));
513 PetscCall(CreateZeroedGlobalVector(user->fda, &user->Rhs));
514 PetscCall(CreateZeroedGlobalVector(user->fda, &user->dUcont));
515 PetscCall(CreateZeroedGlobalVector(user->fda, &user->pUcont));
516 PetscCall(CreateZeroedGlobalVector(user->fda, &user->Bcs.Ubcs));
517 PetscCall(CreateZeroedGlobalVector(user->fda, &user->Bcs.Uch));
518
519 PetscCall(CreateZeroedDuplicate(user->Ucont, &user->Ucont_o));
520 PetscCall(CreateZeroedDuplicate(user->lUcont, &user->lUcont_o));
521 PetscCall(CreateZeroedDuplicate(user->Ucont, &user->Ucont_rm1));
522 PetscCall(CreateZeroedDuplicate(user->lUcont, &user->lUcont_rm1));
523 PetscCall(CreateZeroedDuplicate(user->Ucat, &user->Ucat_o));
524 PetscCall(CreateZeroedDuplicate(user->P, &user->P_o));
525 PetscCall(CreateZeroedDuplicate(user->Nvert, &user->Nvert_o));
526 PetscCall(CreateZeroedLocalVector(user->da, &user->lNvert_o));
527 PetscCall(CreateZeroedDuplicate(user->Csi, &user->ICsi));
528 PetscCall(CreateZeroedDuplicate(user->lCsi, &user->lICsi));
529 PetscCall(CreateZeroedDuplicate(user->Csi, &user->IEta));
530 PetscCall(CreateZeroedDuplicate(user->lCsi, &user->lIEta));
531 PetscCall(CreateZeroedDuplicate(user->Csi, &user->IZet));
532 PetscCall(CreateZeroedDuplicate(user->lCsi, &user->lIZet));
533 PetscCall(CreateZeroedDuplicate(user->Csi, &user->JCsi));
534 PetscCall(CreateZeroedDuplicate(user->lCsi, &user->lJCsi));
535 PetscCall(CreateZeroedDuplicate(user->Csi, &user->JEta));
536 PetscCall(CreateZeroedDuplicate(user->lCsi, &user->lJEta));
537 PetscCall(CreateZeroedDuplicate(user->Csi, &user->JZet));
538 PetscCall(CreateZeroedDuplicate(user->lCsi, &user->lJZet));
539 PetscCall(CreateZeroedDuplicate(user->Csi, &user->KCsi));
540 PetscCall(CreateZeroedDuplicate(user->lCsi, &user->lKCsi));
541 PetscCall(CreateZeroedDuplicate(user->Csi, &user->KEta));
542 PetscCall(CreateZeroedDuplicate(user->lCsi, &user->lKEta));
543 PetscCall(CreateZeroedDuplicate(user->Csi, &user->KZet));
544 PetscCall(CreateZeroedDuplicate(user->lCsi, &user->lKZet));
545 PetscCall(CreateZeroedDuplicate(user->Aj, &user->IAj));
546 PetscCall(CreateZeroedDuplicate(user->lAj, &user->lIAj));
547 PetscCall(CreateZeroedDuplicate(user->Aj, &user->JAj));
548 PetscCall(CreateZeroedDuplicate(user->lAj, &user->lJAj));
549 PetscCall(CreateZeroedDuplicate(user->Aj, &user->KAj));
550 PetscCall(CreateZeroedDuplicate(user->lAj, &user->lKAj));
551
552 PetscCall(PicurvPopulateUniformCellCenters(user));
553 PetscCall(PicurvPopulateIdentityMetrics(user));
554
555 *simCtx_out = simCtx;
556 *user_out = user;
557 PetscFunctionReturn(0);
558}
559
560/**
561 * @brief Builds minimal SimCtx and UserCtx fixtures for C unit tests.
562 */
563PetscErrorCode PicurvCreateMinimalContexts(SimCtx **simCtx_out, UserCtx **user_out, PetscInt mx, PetscInt my, PetscInt mz)
564{
565 PetscFunctionBeginUser;
566 PetscCall(PicurvCreateMinimalContextsWithPeriodicity(simCtx_out, user_out, mx, my, mz, PETSC_FALSE, PETSC_FALSE, PETSC_FALSE));
567 PetscFunctionReturn(0);
568}
569
570/**
571 * @brief Populates cell center coordinates for a uniform grid on [0,1]^3.
572 *
573 * Uses the shifted-index convention: cell (i,j,k) is stored at array index
574 * (i+1, j+1, k+1). For mx cells on [0,1], cell i has center at (i+0.5)/mx.
575 */
577{
578 Cmpnts ***cent = NULL;
579 PetscInt mx = user->IM;
580 PetscInt my = user->JM;
581 PetscInt mz = user->KM;
582
583 PetscFunctionBeginUser;
584 PetscCall(DMDAVecGetArray(user->fda, user->Cent, &cent));
585 for (PetscInt k = user->info.zs; k < user->info.zs + user->info.zm; k++) {
586 for (PetscInt j = user->info.ys; j < user->info.ys + user->info.ym; j++) {
587 for (PetscInt i = user->info.xs; i < user->info.xs + user->info.xm; i++) {
588 cent[k][j][i].x = (i - 0.5) / (PetscReal)mx;
589 cent[k][j][i].y = (j - 0.5) / (PetscReal)my;
590 cent[k][j][i].z = (k - 0.5) / (PetscReal)mz;
591 }
592 }
593 }
594 PetscCall(DMDAVecRestoreArray(user->fda, user->Cent, &cent));
595 PetscCall(DMGlobalToLocalBegin(user->fda, user->Cent, INSERT_VALUES, user->lCent));
596 PetscCall(DMGlobalToLocalEnd(user->fda, user->Cent, INSERT_VALUES, user->lCent));
597 PetscFunctionReturn(0);
598}
599
600/**
601 * @brief Populates identity metric vectors on the minimal grid fixture.
602 */
603
605{
606 Cmpnts ***csi = NULL;
607 Cmpnts ***eta = NULL;
608 Cmpnts ***zet = NULL;
609 Cmpnts ***icsi = NULL;
610 Cmpnts ***ieta = NULL;
611 Cmpnts ***izet = NULL;
612 Cmpnts ***jcsi = NULL;
613 Cmpnts ***jeta = NULL;
614 Cmpnts ***jzet = NULL;
615 Cmpnts ***kcsi = NULL;
616 Cmpnts ***keta = NULL;
617 Cmpnts ***kzet = NULL;
618 PetscReal ***aj = NULL;
619 PetscReal ***iaj = NULL;
620 PetscReal ***jaj = NULL;
621 PetscReal ***kaj = NULL;
622
623 PetscFunctionBeginUser;
624 PetscCall(DMDAVecGetArray(user->fda, user->Csi, &csi));
625 PetscCall(DMDAVecGetArray(user->fda, user->Eta, &eta));
626 PetscCall(DMDAVecGetArray(user->fda, user->Zet, &zet));
627 PetscCall(DMDAVecGetArray(user->fda, user->ICsi, &icsi));
628 PetscCall(DMDAVecGetArray(user->fda, user->IEta, &ieta));
629 PetscCall(DMDAVecGetArray(user->fda, user->IZet, &izet));
630 PetscCall(DMDAVecGetArray(user->fda, user->JCsi, &jcsi));
631 PetscCall(DMDAVecGetArray(user->fda, user->JEta, &jeta));
632 PetscCall(DMDAVecGetArray(user->fda, user->JZet, &jzet));
633 PetscCall(DMDAVecGetArray(user->fda, user->KCsi, &kcsi));
634 PetscCall(DMDAVecGetArray(user->fda, user->KEta, &keta));
635 PetscCall(DMDAVecGetArray(user->fda, user->KZet, &kzet));
636 PetscCall(DMDAVecGetArray(user->da, user->Aj, &aj));
637 PetscCall(DMDAVecGetArray(user->da, user->IAj, &iaj));
638 PetscCall(DMDAVecGetArray(user->da, user->JAj, &jaj));
639 PetscCall(DMDAVecGetArray(user->da, user->KAj, &kaj));
640
641 for (PetscInt k = user->info.zs; k < user->info.zs + user->info.zm; ++k) {
642 for (PetscInt j = user->info.ys; j < user->info.ys + user->info.ym; ++j) {
643 for (PetscInt i = user->info.xs; i < user->info.xs + user->info.xm; ++i) {
644 csi[k][j][i].x = 1.0; csi[k][j][i].y = 0.0; csi[k][j][i].z = 0.0;
645 eta[k][j][i].x = 0.0; eta[k][j][i].y = 1.0; eta[k][j][i].z = 0.0;
646 zet[k][j][i].x = 0.0; zet[k][j][i].y = 0.0; zet[k][j][i].z = 1.0;
647 icsi[k][j][i] = csi[k][j][i];
648 ieta[k][j][i] = eta[k][j][i];
649 izet[k][j][i] = zet[k][j][i];
650 jcsi[k][j][i] = csi[k][j][i];
651 jeta[k][j][i] = eta[k][j][i];
652 jzet[k][j][i] = zet[k][j][i];
653 kcsi[k][j][i] = csi[k][j][i];
654 keta[k][j][i] = eta[k][j][i];
655 kzet[k][j][i] = zet[k][j][i];
656 aj[k][j][i] = 1.0;
657 iaj[k][j][i] = 1.0;
658 jaj[k][j][i] = 1.0;
659 kaj[k][j][i] = 1.0;
660 }
661 }
662 }
663
664 PetscCall(DMDAVecRestoreArray(user->fda, user->Csi, &csi));
665 PetscCall(DMDAVecRestoreArray(user->fda, user->Eta, &eta));
666 PetscCall(DMDAVecRestoreArray(user->fda, user->Zet, &zet));
667 PetscCall(DMDAVecRestoreArray(user->fda, user->ICsi, &icsi));
668 PetscCall(DMDAVecRestoreArray(user->fda, user->IEta, &ieta));
669 PetscCall(DMDAVecRestoreArray(user->fda, user->IZet, &izet));
670 PetscCall(DMDAVecRestoreArray(user->fda, user->JCsi, &jcsi));
671 PetscCall(DMDAVecRestoreArray(user->fda, user->JEta, &jeta));
672 PetscCall(DMDAVecRestoreArray(user->fda, user->JZet, &jzet));
673 PetscCall(DMDAVecRestoreArray(user->fda, user->KCsi, &kcsi));
674 PetscCall(DMDAVecRestoreArray(user->fda, user->KEta, &keta));
675 PetscCall(DMDAVecRestoreArray(user->fda, user->KZet, &kzet));
676 PetscCall(DMDAVecRestoreArray(user->da, user->Aj, &aj));
677 PetscCall(DMDAVecRestoreArray(user->da, user->IAj, &iaj));
678 PetscCall(DMDAVecRestoreArray(user->da, user->JAj, &jaj));
679 PetscCall(DMDAVecRestoreArray(user->da, user->KAj, &kaj));
680
681 PetscCall(DMGlobalToLocalBegin(user->fda, user->Csi, INSERT_VALUES, user->lCsi));
682 PetscCall(DMGlobalToLocalEnd(user->fda, user->Csi, INSERT_VALUES, user->lCsi));
683 PetscCall(DMGlobalToLocalBegin(user->fda, user->Eta, INSERT_VALUES, user->lEta));
684 PetscCall(DMGlobalToLocalEnd(user->fda, user->Eta, INSERT_VALUES, user->lEta));
685 PetscCall(DMGlobalToLocalBegin(user->fda, user->Zet, INSERT_VALUES, user->lZet));
686 PetscCall(DMGlobalToLocalEnd(user->fda, user->Zet, INSERT_VALUES, user->lZet));
687 PetscCall(DMGlobalToLocalBegin(user->fda, user->ICsi, INSERT_VALUES, user->lICsi));
688 PetscCall(DMGlobalToLocalEnd(user->fda, user->ICsi, INSERT_VALUES, user->lICsi));
689 PetscCall(DMGlobalToLocalBegin(user->fda, user->IEta, INSERT_VALUES, user->lIEta));
690 PetscCall(DMGlobalToLocalEnd(user->fda, user->IEta, INSERT_VALUES, user->lIEta));
691 PetscCall(DMGlobalToLocalBegin(user->fda, user->IZet, INSERT_VALUES, user->lIZet));
692 PetscCall(DMGlobalToLocalEnd(user->fda, user->IZet, INSERT_VALUES, user->lIZet));
693 PetscCall(DMGlobalToLocalBegin(user->fda, user->JCsi, INSERT_VALUES, user->lJCsi));
694 PetscCall(DMGlobalToLocalEnd(user->fda, user->JCsi, INSERT_VALUES, user->lJCsi));
695 PetscCall(DMGlobalToLocalBegin(user->fda, user->JEta, INSERT_VALUES, user->lJEta));
696 PetscCall(DMGlobalToLocalEnd(user->fda, user->JEta, INSERT_VALUES, user->lJEta));
697 PetscCall(DMGlobalToLocalBegin(user->fda, user->JZet, INSERT_VALUES, user->lJZet));
698 PetscCall(DMGlobalToLocalEnd(user->fda, user->JZet, INSERT_VALUES, user->lJZet));
699 PetscCall(DMGlobalToLocalBegin(user->fda, user->KCsi, INSERT_VALUES, user->lKCsi));
700 PetscCall(DMGlobalToLocalEnd(user->fda, user->KCsi, INSERT_VALUES, user->lKCsi));
701 PetscCall(DMGlobalToLocalBegin(user->fda, user->KEta, INSERT_VALUES, user->lKEta));
702 PetscCall(DMGlobalToLocalEnd(user->fda, user->KEta, INSERT_VALUES, user->lKEta));
703 PetscCall(DMGlobalToLocalBegin(user->fda, user->KZet, INSERT_VALUES, user->lKZet));
704 PetscCall(DMGlobalToLocalEnd(user->fda, user->KZet, INSERT_VALUES, user->lKZet));
705 PetscCall(DMGlobalToLocalBegin(user->da, user->Nvert, INSERT_VALUES, user->lNvert));
706 PetscCall(DMGlobalToLocalEnd(user->da, user->Nvert, INSERT_VALUES, user->lNvert));
707 PetscCall(DMGlobalToLocalBegin(user->da, user->Aj, INSERT_VALUES, user->lAj));
708 PetscCall(DMGlobalToLocalEnd(user->da, user->Aj, INSERT_VALUES, user->lAj));
709 PetscCall(DMGlobalToLocalBegin(user->da, user->IAj, INSERT_VALUES, user->lIAj));
710 PetscCall(DMGlobalToLocalEnd(user->da, user->IAj, INSERT_VALUES, user->lIAj));
711 PetscCall(DMGlobalToLocalBegin(user->da, user->JAj, INSERT_VALUES, user->lJAj));
712 PetscCall(DMGlobalToLocalEnd(user->da, user->JAj, INSERT_VALUES, user->lJAj));
713 PetscCall(DMGlobalToLocalBegin(user->da, user->KAj, INSERT_VALUES, user->lKAj));
714 PetscCall(DMGlobalToLocalEnd(user->da, user->KAj, INSERT_VALUES, user->lKAj));
715 PetscCall(DMGlobalToLocalBegin(user->da, user->P, INSERT_VALUES, user->lP));
716 PetscCall(DMGlobalToLocalEnd(user->da, user->P, INSERT_VALUES, user->lP));
717 PetscCall(DMGlobalToLocalBegin(user->da, user->Psi, INSERT_VALUES, user->lPsi));
718 PetscCall(DMGlobalToLocalEnd(user->da, user->Psi, INSERT_VALUES, user->lPsi));
719 PetscCall(DMGlobalToLocalBegin(user->fda, user->Ucat, INSERT_VALUES, user->lUcat));
720 PetscCall(DMGlobalToLocalEnd(user->fda, user->Ucat, INSERT_VALUES, user->lUcat));
721 PetscCall(DMGlobalToLocalBegin(user->fda, user->Ucont, INSERT_VALUES, user->lUcont));
722 PetscCall(DMGlobalToLocalEnd(user->fda, user->Ucont, INSERT_VALUES, user->lUcont));
723 PetscCall(DMGlobalToLocalBegin(user->fda, user->Cent, INSERT_VALUES, user->lCent));
724 PetscCall(DMGlobalToLocalEnd(user->fda, user->Cent, INSERT_VALUES, user->lCent));
725 PetscFunctionReturn(0);
726}
727/**
728 * @brief Creates matched solver and post-processing swarms for tests.
729 */
730
731PetscErrorCode PicurvCreateSwarmPair(UserCtx *user, PetscInt nlocal, const char *post_field_name)
732{
733 PetscFunctionBeginUser;
734 if (!user) {
735 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "UserCtx cannot be NULL.");
736 }
737
738 PetscCall(DMCreate(PETSC_COMM_WORLD, &user->swarm));
739 PetscCall(DMSetType(user->swarm, DMSWARM));
740 PetscCall(DMSetDimension(user->swarm, 3));
741 PetscCall(DMSwarmSetType(user->swarm, DMSWARM_BASIC));
742 PetscCall(DMSwarmSetCellDM(user->swarm, user->da));
743 PetscCall(RegisterSwarmFieldForTests(user->swarm, "position", 3, PETSC_REAL));
744 PetscCall(RegisterSwarmFieldForTests(user->swarm, "velocity", 3, PETSC_REAL));
745 PetscCall(RegisterSwarmFieldForTests(user->swarm, "DMSwarm_CellID", 3, PETSC_INT));
746 PetscCall(RegisterSwarmFieldForTests(user->swarm, "weight", 3, PETSC_REAL));
747 PetscCall(RegisterSwarmFieldForTests(user->swarm, "Diffusivity", 1, PETSC_REAL));
748 PetscCall(RegisterSwarmFieldForTests(user->swarm, "DiffusivityGradient", 3, PETSC_REAL));
749 PetscCall(RegisterSwarmFieldForTests(user->swarm, "Psi", 1, PETSC_REAL));
750 PetscCall(RegisterSwarmFieldForTests(user->swarm, "DMSwarm_location_status", 1, PETSC_INT));
751 PetscCall(DMSwarmFinalizeFieldRegister(user->swarm));
752 PetscCall(DMSwarmSetLocalSizes(user->swarm, nlocal, 0));
753
754 PetscCall(DMCreate(PETSC_COMM_WORLD, &user->post_swarm));
755 PetscCall(DMSetType(user->post_swarm, DMSWARM));
756 PetscCall(DMSetDimension(user->post_swarm, 3));
757 PetscCall(DMSwarmSetType(user->post_swarm, DMSWARM_BASIC));
758 PetscCall(DMSwarmSetCellDM(user->post_swarm, user->da));
759 PetscCall(RegisterSwarmFieldForTests(user->post_swarm, post_field_name, 1, PETSC_REAL));
760 PetscCall(DMSwarmFinalizeFieldRegister(user->post_swarm));
761 PetscCall(DMSwarmSetLocalSizes(user->post_swarm, nlocal, 0));
762 PetscFunctionReturn(0);
763}
764/**
765 * @brief Builds a tiny runtime context through the real setup path for behavior-level tests.
766 */
767
768PetscErrorCode PicurvBuildTinyRuntimeContext(const char *bcs_contents,
769 PetscBool enable_particles,
770 SimCtx **simCtx_out,
771 UserCtx **user_out,
772 char *tmpdir,
773 size_t tmpdir_len)
774{
775 char control_path[PETSC_MAX_PATH_LEN];
776 SimCtx *simCtx = NULL;
777
778 PetscFunctionBeginUser;
779 PetscCheck(simCtx_out != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "SimCtx output cannot be NULL.");
780
781 PetscCall(PetscOptionsClear(NULL));
782 PetscCall(PrepareTinyRuntimeConfig(bcs_contents, enable_particles, tmpdir, tmpdir_len, control_path, sizeof(control_path)));
783 PetscCall(PetscOptionsSetValue(NULL, "-control_file", control_path));
784 PetscCall(CreateSimulationContext(0, NULL, &simCtx));
785 simCtx->exec_mode = EXEC_MODE_SOLVER;
786 PetscCall(SetupSimulationEnvironment(simCtx));
787 PetscCall(SetupGridAndSolvers(simCtx));
788 PetscCall(SetupBoundaryConditions(simCtx));
789 PetscCall(SetupDomainRankInfo(simCtx));
790
791 *simCtx_out = simCtx;
792 if (user_out) {
793 *user_out = simCtx->usermg.mgctx[simCtx->usermg.mglevels - 1].user;
794 }
795 PetscFunctionReturn(0);
796}
797
798/**
799 * @brief Builds the production-sized straight-duct fixture used only by the
800 * opt-in Newton residual-purity diagnostic.
801 */
802PetscErrorCode PicurvBuildMomentumPurityRuntimeContext(const char *bcs_contents,
803 SimCtx **simCtx_out,
804 UserCtx **user_out,
805 char *tmpdir,
806 size_t tmpdir_len)
807{
808 char bcs_path[PETSC_MAX_PATH_LEN];
809 char post_path[PETSC_MAX_PATH_LEN];
810 char output_dir[PETSC_MAX_PATH_LEN];
811 char log_dir[PETSC_MAX_PATH_LEN];
812 char control_path[PETSC_MAX_PATH_LEN];
813 char control_buffer[8192];
814 SimCtx *simCtx = NULL;
815 const char *default_bcs =
816 "-Xi WALL noslip\n"
817 "+Xi WALL noslip\n"
818 "-Eta WALL noslip\n"
819 "+Eta WALL noslip\n"
820 "-Zeta INLET constant_velocity vx=0.0 vy=0.0 vz=0.1\n"
821 "+Zeta OUTLET conservation\n";
822
823 PetscFunctionBeginUser;
824 PetscCheck(simCtx_out != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
825 "SimCtx output cannot be NULL.");
826 PetscCall(PetscOptionsClear(NULL));
827 PetscCall(PicurvMakeTempDir(tmpdir, tmpdir_len));
828 PetscCall(PetscSNPrintf(bcs_path, sizeof(bcs_path), "%s/bcs.run", tmpdir));
829 PetscCall(PetscSNPrintf(post_path, sizeof(post_path), "%s/post.run", tmpdir));
830 PetscCall(PetscSNPrintf(output_dir, sizeof(output_dir), "%s/results", tmpdir));
831 PetscCall(PetscSNPrintf(log_dir, sizeof(log_dir), "%s/logs", tmpdir));
832 PetscCall(PetscSNPrintf(control_path, sizeof(control_path), "%s/test.control", tmpdir));
833 PetscCall(WriteTextFileForTests(bcs_path, bcs_contents ? bcs_contents : default_bcs));
834 PetscCall(WriteTextFileForTests(post_path,
835 "startTime = 0\nendTime = 1\ntimeStep = 1\noutput_particles = false\n"));
836 PetscCall(PetscSNPrintf(control_buffer, sizeof(control_buffer),
837 "-start_step 0\n"
838 "-totalsteps 2\n"
839 "-ren 10.0\n"
840 "-dt 0.001\n"
841 "-finit 1\n"
842 "-ucont_x 0.0\n-ucont_y 0.0\n-ucont_z 0.1\n"
843 "-bcs_files %s\n"
844 "-profiling_timestep_mode off\n-profiling_final_summary true\n"
845 "-postprocessing_config_file %s\n"
846 /* PICurv's programmatic grid counts include the leading physical node;
847 * 17x17x65 therefore represents 16x16x64 Cartesian cells. */
848 "-grid\n-im 17\n-jm 17\n-km 65\n"
849 "-xMins 0.0\n-xMaxs 1.0\n-yMins 0.0\n-yMaxs 1.0\n-zMins 0.0\n-zMaxs 4.0\n"
850 "-rxs 1.0\n-rys 1.0\n-rzs 1.0\n-cgrids 0\n-nblk 1\n"
851 "-euler_field_source solve\n-mom_solver_type newton_krylov\n"
852 "-mg_level 1\n-poisson 0\n-tio 0\n-numParticles 0\n-pinit 2\n"
853 "-particle_console_output_freq 0\n-logfreq 1\n"
854 "-output_dir %s\n-restart_dir %s\n-log_dir %s\n",
855 bcs_path, post_path, output_dir, output_dir, log_dir));
856 PetscCall(WriteTextFileForTests(control_path, control_buffer));
857 PetscCall(PetscOptionsSetValue(NULL, "-control_file", control_path));
858 PetscCall(CreateSimulationContext(0, NULL, &simCtx));
859 simCtx->exec_mode = EXEC_MODE_SOLVER;
860 PetscCall(SetupSimulationEnvironment(simCtx));
861 PetscCall(SetupGridAndSolvers(simCtx));
862 PetscCall(SetupBoundaryConditions(simCtx));
863 PetscCall(SetupDomainRankInfo(simCtx));
864 *simCtx_out = simCtx;
865 if (user_out) *user_out = simCtx->usermg.mgctx[simCtx->usermg.mglevels - 1].user;
866 PetscFunctionReturn(0);
867}
868/**
869 * @brief Finalizes and frees a runtime context built by `PicurvBuildTinyRuntimeContext`.
870 */
871
872PetscErrorCode PicurvDestroyRuntimeContext(SimCtx **simCtx_ptr)
873{
874 PetscFunctionBeginUser;
875 if (simCtx_ptr && *simCtx_ptr) {
876 PetscCall(FinalizeSimulation(*simCtx_ptr));
877 *simCtx_ptr = NULL;
878 }
879 PetscCall(PetscOptionsClear(NULL));
880 PetscFunctionReturn(0);
881}
882/**
883 * @brief Destroys minimal SimCtx/UserCtx fixtures and all owned PETSc objects.
884 */
885
886PetscErrorCode PicurvDestroyMinimalContexts(SimCtx **simCtx_ptr, UserCtx **user_ptr)
887{
888 UserCtx *user = NULL;
889 SimCtx *simCtx = NULL;
890
891 PetscFunctionBeginUser;
892 if (user_ptr) {
893 user = *user_ptr;
894 }
895 if (simCtx_ptr) {
896 simCtx = *simCtx_ptr;
897 }
898
899 if (simCtx) {
900 PetscCall(DestroySolutionConvergenceState(simCtx));
901 }
902
903 if (user) {
904 PetscCall(DestroyDMIfSet(&user->swarm));
905 PetscCall(DestroyDMIfSet(&user->post_swarm));
906
907 PetscCall(DestroyVecIfSet(&user->P));
908 PetscCall(DestroyVecIfSet(&user->lP));
909 PetscCall(DestroyVecIfSet(&user->Phi));
910 PetscCall(DestroyVecIfSet(&user->lPhi));
911 PetscCall(DestroyVecIfSet(&user->Nvert));
912 PetscCall(DestroyVecIfSet(&user->lNvert));
913 PetscCall(DestroyVecIfSet(&user->ParticleCount));
914 PetscCall(DestroyVecIfSet(&user->lParticleCount));
915 PetscCall(DestroyVecIfSet(&user->Psi));
916 PetscCall(DestroyVecIfSet(&user->lPsi));
917 PetscCall(DestroyVecIfSet(&user->Qcrit));
918 PetscCall(DestroyVecIfSet(&user->P_nodal));
919 PetscCall(DestroyVecIfSet(&user->Psi_nodal));
920 PetscCall(DestroyVecIfSet(&user->Ucat));
921 PetscCall(DestroyVecIfSet(&user->lUcat));
922 PetscCall(DestroyVecIfSet(&user->Ucont));
923 PetscCall(DestroyVecIfSet(&user->lUcont));
924 PetscCall(DestroyVecIfSet(&user->Csi));
925 PetscCall(DestroyVecIfSet(&user->lCsi));
926 PetscCall(DestroyVecIfSet(&user->Eta));
927 PetscCall(DestroyVecIfSet(&user->lEta));
928 PetscCall(DestroyVecIfSet(&user->Zet));
929 PetscCall(DestroyVecIfSet(&user->lZet));
930 PetscCall(DestroyVecIfSet(&user->Aj));
931 PetscCall(DestroyVecIfSet(&user->lAj));
932 PetscCall(DestroyVecIfSet(&user->IAj));
933 PetscCall(DestroyVecIfSet(&user->lIAj));
934 PetscCall(DestroyVecIfSet(&user->JAj));
935 PetscCall(DestroyVecIfSet(&user->lJAj));
936 PetscCall(DestroyVecIfSet(&user->KAj));
937 PetscCall(DestroyVecIfSet(&user->lKAj));
938 PetscCall(DestroyVecIfSet(&user->Diffusivity));
939 PetscCall(DestroyVecIfSet(&user->lDiffusivity));
940 PetscCall(DestroyVecIfSet(&user->DiffusivityGradient));
941 PetscCall(DestroyVecIfSet(&user->lDiffusivityGradient));
942 PetscCall(DestroyVecIfSet(&user->CS));
943 PetscCall(DestroyVecIfSet(&user->lCs));
944 PetscCall(DestroyVecIfSet(&user->Nu_t));
945 PetscCall(DestroyVecIfSet(&user->lNu_t));
946 PetscCall(DestroyVecIfSet(&user->Ucont_o));
947 PetscCall(DestroyVecIfSet(&user->lUcont_o));
948 PetscCall(DestroyVecIfSet(&user->Ucat_o));
949 PetscCall(DestroyVecIfSet(&user->P_o));
950 PetscCall(DestroyVecIfSet(&user->Nvert_o));
951 PetscCall(DestroyVecIfSet(&user->lNvert_o));
952 PetscCall(DestroyVecIfSet(&user->Ucont_rm1));
953 PetscCall(DestroyVecIfSet(&user->lUcont_rm1));
954 PetscCall(DestroyVecIfSet(&user->Rhs));
955 PetscCall(DestroyVecIfSet(&user->dUcont));
956 PetscCall(DestroyVecIfSet(&user->pUcont));
957 PetscCall(DestroyVecIfSet(&user->CellScalarAtCorner));
958 PetscCall(DestroyVecIfSet(&user->lCellScalarAtCorner));
959 PetscCall(DestroyVecIfSet(&user->CellVectorAtCorner));
960 PetscCall(DestroyVecIfSet(&user->lCellVectorAtCorner));
961 PetscCall(DestroyVecIfSet(&user->B));
962 PetscCall(DestroyVecIfSet(&user->R));
963 PetscCall(DestroyVecIfSet(&user->Cent));
964 PetscCall(DestroyVecIfSet(&user->lCent));
965 PetscCall(DestroyVecIfSet(&user->GridSpace));
966 PetscCall(DestroyVecIfSet(&user->lGridSpace));
967 PetscCall(DestroyVecIfSet(&user->Centx));
968 PetscCall(DestroyVecIfSet(&user->Centy));
969 PetscCall(DestroyVecIfSet(&user->Centz));
970 PetscCall(DestroyVecIfSet(&user->lCentx));
971 PetscCall(DestroyVecIfSet(&user->lCenty));
972 PetscCall(DestroyVecIfSet(&user->lCentz));
973 PetscCall(DestroyVecIfSet(&user->Ucat_nodal));
974 PetscCall(DestroyVecIfSet(&user->Bcs.Ubcs));
975 PetscCall(DestroyVecIfSet(&user->Bcs.Uch));
976 PetscCall(DestroyMatIfSet(&user->A));
977 PetscCall(DestroyMatIfSet(&user->C));
978 PetscCall(DestroyKSPIfSet(&user->ksp));
979 PetscCall(DestroyNullSpaceIfSet(&user->nullsp));
980 PetscCall(PetscFree(user->RankCellInfoMap));
981 user->RankCellInfoMap = NULL;
982 for (PetscInt face = BC_FACE_NEG_X; face <= BC_FACE_POS_Z; ++face) {
983 if (user->boundary_faces[face].params) {
985 user->boundary_faces[face].params = NULL;
986 }
987 }
988
989 PetscCall(DestroyVecIfSet(&user->PostScalar));
990 PetscCall(DestroyVecIfSet(&user->lPostScalar));
991 PetscCall(DestroyVecIfSet(&user->PostScalarNodal));
992 PetscCall(DestroyVecIfSet(&user->PostVector));
993 PetscCall(DestroyVecIfSet(&user->lPostVector));
994 PetscCall(DestroyVecIfSet(&user->PostVectorNodal));
995 PetscCall(DestroyDMIfSet(&user->fda6));
996 PetscCall(DestroyDMIfSet(&user->fda));
997 PetscCall(DestroyDMIfSet(&user->da));
998 PetscCall(PetscFree(user));
999 if (user_ptr) {
1000 *user_ptr = NULL;
1001 }
1002 }
1003
1004 if (simCtx) {
1005 PetscCall(DestroyRandomIfSet(&simCtx->BrownianMotionRNG));
1006 PetscCall(PetscFree(simCtx->bboxlist));
1007 PetscCall(PetscFree(simCtx->usermg.mgctx));
1008 PetscCall(PetscFree(simCtx->pps));
1009 PetscCall(PetscFree(simCtx));
1010 if (simCtx_ptr) {
1011 *simCtx_ptr = NULL;
1012 }
1013 }
1014
1015 PetscFunctionReturn(0);
1016}
1017/**
1018 * @brief Asserts that two real values agree within tolerance.
1019 */
1020
1021PetscErrorCode PicurvAssertRealNear(PetscReal expected, PetscReal actual, PetscReal tol, const char *context)
1022{
1023 PetscFunctionBeginUser;
1024 if (PetscAbsReal(expected - actual) > tol) {
1025 PetscCall(PetscPrintf(PETSC_COMM_WORLD,
1026 "[FAIL] %s | expected=%0.12e actual=%0.12e tol=%0.12e\n",
1027 context, (double)expected, (double)actual, (double)tol));
1028 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_PLIB, "Assertion failed.");
1029 }
1030 PetscFunctionReturn(0);
1031}
1032/**
1033 * @brief Asserts that two integer values are equal.
1034 */
1035
1036PetscErrorCode PicurvAssertIntEqual(PetscInt expected, PetscInt actual, const char *context)
1037{
1038 PetscFunctionBeginUser;
1039 if (expected != actual) {
1040 PetscCall(PetscPrintf(PETSC_COMM_WORLD,
1041 "[FAIL] %s | expected=%" PetscInt_FMT " actual=%" PetscInt_FMT "\n",
1042 context, expected, actual));
1043 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_PLIB, "Assertion failed.");
1044 }
1045 PetscFunctionReturn(0);
1046}
1047/**
1048 * @brief Asserts that one boolean condition is true.
1049 */
1050
1051PetscErrorCode PicurvAssertBool(PetscBool value, const char *context)
1052{
1053 PetscFunctionBeginUser;
1054 if (!value) {
1055 PetscCall(PetscPrintf(PETSC_COMM_WORLD, "[FAIL] %s\n", context));
1056 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_PLIB, "Assertion failed.");
1057 }
1058 PetscFunctionReturn(0);
1059}
1060/**
1061 * @brief Asserts that a filesystem path exists as a readable file.
1062 */
1063
1064PetscErrorCode PicurvAssertFileExists(const char *path, const char *context)
1065{
1066 PetscBool exists = PETSC_FALSE;
1067
1068 PetscFunctionBeginUser;
1069 PetscCall(PetscTestFile(path, 'r', &exists));
1070 if (!exists) {
1071 PetscCall(PetscPrintf(PETSC_COMM_WORLD, "[FAIL] %s | missing file: %s\n", context, path));
1072 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN, "Expected file is missing.");
1073 }
1074 PetscFunctionReturn(0);
1075}
1076/**
1077 * @brief Asserts that a PETSc vector is spatially constant within tolerance.
1078 */
1079
1080PetscErrorCode PicurvAssertVecConstant(Vec vec, PetscScalar expected, PetscReal tol, const char *context)
1081{
1082 PetscReal vmin = 0.0;
1083 PetscReal vmax = 0.0;
1084
1085 PetscFunctionBeginUser;
1086 PetscCall(VecMin(vec, NULL, &vmin));
1087 PetscCall(VecMax(vec, NULL, &vmax));
1088 PetscCall(PicurvAssertRealNear((PetscReal)expected, vmin, tol, context));
1089 PetscCall(PicurvAssertRealNear((PetscReal)expected, vmax, tol, context));
1090 PetscFunctionReturn(0);
1091}
Public interface for grid, solver, and metric setup routines.
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
Public interface for data input/output routines.
void FreeBC_ParamList(BC_Param *head)
Frees an entire linked list of boundary-condition parameters.
Definition io.c:664
PetscErrorCode SetupDomainRankInfo(SimCtx *simCtx)
Sets up the full rank communication infrastructure, including neighbor ranks and bounding box exchang...
Definition setup.c:2576
PetscErrorCode SetupGridAndSolvers(SimCtx *simCtx)
The main orchestrator for setting up all grid-related components.
Definition setup.c:1364
PetscErrorCode SetupSimulationEnvironment(SimCtx *simCtx)
Verifies and prepares the complete I/O environment for a simulation run.
Definition setup.c:1063
PetscErrorCode DestroySolutionConvergenceState(SimCtx *simCtx)
Frees any runtime storage allocated for solution-convergence logging.
Definition setup.c:101
PetscErrorCode CreateSimulationContext(int argc, char **argv, SimCtx **p_simCtx)
Allocates and populates the master SimulationContext object.
Definition setup.c:160
PetscErrorCode SetupBoundaryConditions(SimCtx *simCtx)
(Orchestrator) Sets up all boundary conditions for the simulation.
Definition setup.c:2027
PetscErrorCode FinalizeSimulation(SimCtx *simCtx)
Main cleanup function for the entire simulation context.
Definition setup.c:3721
static PetscErrorCode DestroyKSPIfSet(KSP *ksp)
Destroys a PETSc KSP only when the handle is non-null.
PetscErrorCode PicurvMakeTempDir(char *path, size_t path_len)
Creates a unique temporary directory for one test case.
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 PicurvEnsureDir(const char *path)
Ensures a directory exists for test output.
PetscErrorCode PicurvAssertRealNear(PetscReal expected, PetscReal actual, PetscReal tol, const char *context)
Asserts that two real values agree within tolerance.
static PetscErrorCode DestroyDMIfSet(DM *dm)
Destroys a PETSc DM only when the handle is non-null.
PetscErrorCode PicurvDestroyMinimalContexts(SimCtx **simCtx_ptr, UserCtx **user_ptr)
Destroys minimal SimCtx/UserCtx fixtures and all owned PETSc objects.
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.
static PetscErrorCode DestroyNullSpaceIfSet(MatNullSpace *nullsp)
Destroys a PETSc nullspace only when the handle is non-null.
static PetscErrorCode CreateZeroedLocalVector(DM dm, Vec *vec)
Allocates and zeroes a local vector from the provided DM.
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 diag...
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 PicurvCreateSwarmPair(UserCtx *user, PetscInt nlocal, const char *post_field_name)
Creates matched solver and post-processing swarms for tests.
static PetscErrorCode WriteTextFileForTests(const char *path, const char *contents)
Writes one small temporary text file used by the richer runtime fixtures.
static PetscErrorCode DestroyRandomIfSet(PetscRandom *rand_ctx)
Destroys a PETSc random generator only when the handle is non-null.
PetscErrorCode PicurvDestroyRuntimeContext(SimCtx **simCtx_ptr)
Finalizes and frees a runtime context built by PicurvBuildTinyRuntimeContext.
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 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.
static PetscErrorCode CreateZeroedDuplicate(Vec src, Vec *vec)
Duplicates and zeroes a vector.
static PetscErrorCode DestroyVecIfSet(Vec *vec)
Destroys a PETSc vector only when the handle is non-null.
PetscErrorCode PicurvPopulateUniformCellCenters(UserCtx *user)
Populates cell center coordinates for a uniform grid on [0,1]^3.
PetscErrorCode PicurvAssertFileExists(const char *path, const char *context)
Asserts that a filesystem path exists as a readable file.
static PetscErrorCode RegisterSwarmFieldForTests(DM swarm, const char *field_name, PetscInt field_dim, PetscDataType dtype)
Registers one DMSwarm field used by the C test fixtures.
PetscErrorCode PicurvAssertVecConstant(Vec vec, PetscScalar expected, PetscReal tol, const char *context)
Asserts that a PETSc vector is spatially constant within tolerance.
PetscErrorCode PicurvAssertIntEqual(PetscInt expected, PetscInt actual, const char *context)
Asserts that two integer values are equal.
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.
static PetscErrorCode DestroyMatIfSet(Mat *mat)
Destroys a PETSc matrix only when the handle is non-null.
PetscErrorCode PicurvAssertBool(PetscBool value, const char *context)
Asserts that one boolean condition is true.
PetscErrorCode PicurvRemoveTempDir(const char *path)
Recursively removes a temporary directory created by PicurvMakeTempDir.
Shared declarations for the PICurv C test fixture and assertion layer.
Named test case descriptor consumed by PicurvRunTests.
PetscReal icVelocityPhysical
Definition variables.h:759
Vec lDiffusivityGradient
Definition variables.h:943
Vec lPostScalar
Definition variables.h:959
Vec lCent
Definition variables.h:974
Vec GridSpace
Definition variables.h:974
Vec P_nodal
Definition variables.h:1001
Vec JCsi
Definition variables.h:978
Vec KAj
Definition variables.h:979
UserCtx * user
Definition variables.h:571
Vec JEta
Definition variables.h:978
Vec Zet
Definition variables.h:974
Vec Rhs
Definition variables.h:947
PetscReal schmidt_number
Definition variables.h:787
PetscMPIInt rank
Definition variables.h:698
PetscInt mglevels
Definition variables.h:988
BoundaryFaceConfig boundary_faces[6]
Definition variables.h:931
MatNullSpace nullsp
Definition variables.h:965
PetscInt block_number
Definition variables.h:790
Vec lIEta
Definition variables.h:977
Vec lIZet
Definition variables.h:977
Vec lNvert
Definition variables.h:939
Vec Phi
Definition variables.h:939
PetscReal forceScalingFactor
Definition variables.h:801
InitialConditionMode initialConditionMode
Definition variables.h:754
SimCtx * simCtx
Back-pointer to the master simulation context.
Definition variables.h:909
Vec IZet
Definition variables.h:977
FlowDirection flowDirection
Definition variables.h:758
Vec Centz
Definition variables.h:975
Vec IEta
Definition variables.h:977
PetscReal Min_X
Definition variables.h:921
PetscInt KM
Definition variables.h:920
PetscInt tiout
Definition variables.h:707
Vec lZet
Definition variables.h:974
UserMG usermg
Definition variables.h:852
Vec Csi
Definition variables.h:974
PetscReal ren
Definition variables.h:744
DM post_swarm
Definition variables.h:1000
Vec lUcont_rm1
Definition variables.h:947
Vec lIAj
Definition variables.h:977
Cmpnts max_coords
Maximum x, y, z coordinates of the bounding box.
Definition variables.h:173
PetscInt _this
Definition variables.h:924
Vec lKEta
Definition variables.h:979
char output_dir[PETSC_MAX_PATH_LEN]
Definition variables.h:717
PetscBool solutionConvergenceEnabled
Definition variables.h:761
PetscReal dt
Definition variables.h:710
PetscReal ry
Definition variables.h:925
PetscInt StepsToRun
Definition variables.h:706
PetscInt k_periodic
Definition variables.h:791
Vec Ucat_nodal
Definition variables.h:1002
Vec lPsi
Definition variables.h:997
PetscInt np
Definition variables.h:827
Vec PostScalarNodal
Definition variables.h:959
PetscReal Max_Y
Definition variables.h:921
PetscInt thislevel
Definition variables.h:572
Vec DiffusivityGradient
Definition variables.h:943
Vec lJCsi
Definition variables.h:978
Vec lCs
Definition variables.h:982
Vec Ucont
Definition variables.h:939
PetscInt StartStep
Definition variables.h:705
Cmpnts min_coords
Minimum x, y, z coordinates of the bounding box.
Definition variables.h:172
Vec PostScalar
Definition variables.h:959
Vec Ubcs
Physical Cartesian velocity at boundary faces. Full 3D array but only boundary-face entries are meani...
Definition variables.h:123
@ MOMENTUM_SOLVER_EXPLICIT_RK
Definition variables.h:535
Vec Qcrit
Definition variables.h:1003
PetscScalar x
Definition variables.h:103
Vec JZet
Definition variables.h:978
Vec CellScalarAtCorner
Definition variables.h:952
Vec Centx
Definition variables.h:975
BCS Bcs
Definition variables.h:934
Vec lPhi
Definition variables.h:939
Vec lParticleCount
Definition variables.h:996
Vec lUcont_o
Definition variables.h:946
RankCellInfo * RankCellInfoMap
Definition variables.h:995
Vec CellVectorAtCorner
Definition variables.h:953
Vec Ucat_o
Definition variables.h:946
PetscInt poisson
Definition variables.h:740
BoundingBox * bboxlist
Definition variables.h:830
Vec lKZet
Definition variables.h:979
Vec Eta
Definition variables.h:974
char log_dir[PETSC_MAX_PATH_LEN]
Definition variables.h:718
Vec lNu_t
Definition variables.h:982
Vec Nu_t
Definition variables.h:982
PetscReal rz
Definition variables.h:925
Vec lCellScalarAtCorner
Definition variables.h:952
Vec lJEta
Definition variables.h:978
Vec lCsi
Definition variables.h:974
Vec lGridSpace
Definition variables.h:974
PetscInt thislevel
Definition variables.h:988
BC_Param * params
Definition variables.h:370
Vec ICsi
Definition variables.h:977
PetscScalar z
Definition variables.h:103
Vec pUcont
Definition variables.h:947
Vec lKCsi
Definition variables.h:979
Vec Ucat
Definition variables.h:939
Vec ParticleCount
Definition variables.h:996
Vec Ucont_o
Definition variables.h:946
PetscInt JM
Definition variables.h:920
Vec lCenty
Definition variables.h:976
Vec PostVectorNodal
Definition variables.h:960
PetscInt mglevels
Definition variables.h:578
PetscReal Min_Z
Definition variables.h:921
PetscInt mglevels
Definition variables.h:739
Vec lJZet
Definition variables.h:978
Vec Nvert_o
Definition variables.h:946
@ FLOW_DIR_UNSET
Definition variables.h:279
Vec IAj
Definition variables.h:977
Vec lCellVectorAtCorner
Definition variables.h:953
char initialConditionDirectory[PETSC_MAX_PATH_LEN]
Definition variables.h:756
Vec Psi_nodal
Definition variables.h:1004
Vec JAj
Definition variables.h:978
Vec lPostVector
Definition variables.h:960
Vec KEta
Definition variables.h:979
@ IC_MODE_ZERO
Definition variables.h:152
PetscReal Max_X
Definition variables.h:921
Vec lCentx
Definition variables.h:976
Vec Ucont_rm1
Definition variables.h:947
PetscReal Min_Y
Definition variables.h:921
PetscInt i_periodic
Definition variables.h:791
Vec lUcont
Definition variables.h:939
PetscInt step
Definition variables.h:703
Vec Diffusivity
Definition variables.h:942
Vec lAj
Definition variables.h:974
PetscRandom BrownianMotionRNG
Definition variables.h:841
Vec lICsi
Definition variables.h:977
DMDALocalInfo info
Definition variables.h:918
Vec dUcont
Definition variables.h:947
Vec lUcat
Definition variables.h:939
PostProcessParams * pps
Definition variables.h:890
PetscScalar y
Definition variables.h:103
@ IC_FIELD_UCAT
Definition variables.h:161
PetscMPIInt size
Definition variables.h:699
@ EXEC_MODE_SOLVER
Definition variables.h:668
PetscInt IM
Definition variables.h:920
Vec lEta
Definition variables.h:974
KSP ksp
Definition variables.h:965
Vec PostVector
Definition variables.h:960
Vec KZet
Definition variables.h:979
Vec Cent
Definition variables.h:974
Vec Nvert
Definition variables.h:939
Vec KCsi
Definition variables.h:979
MGCtx * mgctx
Definition variables.h:581
Vec lDiffusivity
Definition variables.h:942
Vec lNvert_o
Definition variables.h:946
Vec Centy
Definition variables.h:975
PetscReal rx
Definition variables.h:925
Vec lCentz
Definition variables.h:976
InitialConditionField initialConditionField
Definition variables.h:755
ExecutionMode exec_mode
Definition variables.h:714
Vec lJAj
Definition variables.h:978
BoundingBox bbox
Definition variables.h:922
PetscReal Max_Z
Definition variables.h:921
MomentumSolverType mom_solver_type
Definition variables.h:736
Vec lKAj
Definition variables.h:979
char restart_dir[PETSC_MAX_PATH_LEN]
Definition variables.h:716
PetscInt LoggingFrequency
Definition variables.h:857
Vec Psi
Definition variables.h:997
Vec P_o
Definition variables.h:946
Vec Uch
Characteristic velocity for boundary conditions.
Definition variables.h:124
@ BC_FACE_NEG_X
Definition variables.h:262
@ BC_FACE_POS_Z
Definition variables.h:264
PetscInt j_periodic
Definition variables.h:791
Defines a 3D axis-aligned bounding box.
Definition variables.h:171
A 3D point or vector with PetscScalar components.
Definition variables.h:102
The master context for the entire simulation.
Definition variables.h:695
User-defined context containing data specific to a single computational grid level.
Definition variables.h:906