25 PetscFunctionBeginUser;
27 PetscCall(VecDestroy(vec));
29 PetscFunctionReturn(0);
37 PetscFunctionBeginUser;
39 PetscCall(DMDestroy(dm));
41 PetscFunctionReturn(0);
49 PetscFunctionBeginUser;
51 PetscCall(MatDestroy(mat));
53 PetscFunctionReturn(0);
61 PetscFunctionBeginUser;
63 PetscCall(KSPDestroy(ksp));
65 PetscFunctionReturn(0);
73 PetscFunctionBeginUser;
74 if (nullsp && *nullsp) {
75 PetscCall(MatNullSpaceDestroy(nullsp));
77 PetscFunctionReturn(0);
85 PetscFunctionBeginUser;
86 if (rand_ctx && *rand_ctx) {
87 PetscCall(PetscRandomDestroy(rand_ctx));
89 PetscFunctionReturn(0);
97 PetscFunctionBeginUser;
98 PetscCall(DMSwarmRegisterPetscDatatypeField(swarm, field_name, field_dim, dtype));
99 PetscFunctionReturn(0);
107 PetscFunctionBeginUser;
108 PetscCall(DMCreateGlobalVector(dm, vec));
109 PetscCall(VecSet(*vec, 0.0));
110 PetscFunctionReturn(0);
118 PetscFunctionBeginUser;
119 PetscCall(DMCreateLocalVector(dm, vec));
120 PetscCall(VecSet(*vec, 0.0));
121 PetscFunctionReturn(0);
129 PetscFunctionBeginUser;
130 PetscCall(VecDuplicate(src, vec));
131 PetscCall(VecSet(*vec, 0.0));
132 PetscFunctionReturn(0);
140 PetscFunctionBeginUser;
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));
149 PetscCall(PetscPrintf(PETSC_COMM_WORLD,
"==> %s complete\n", suite_name));
150 PetscFunctionReturn(0);
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));
162 PetscFunctionReturn(0);
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.");
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));
179 PetscFunctionReturn(0);
189 PetscFunctionBeginUser;
190 if (!path || path[0] ==
'\0') PetscFunctionReturn(0);
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);
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));
200 PetscFunctionReturn(0);
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);
215 PetscFunctionReturn(0);
222 PetscBool enable_particles,
226 size_t control_path_len)
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 =
239 "-Zeta INLET constant_velocity vx=0.0 vy=0.0 vz=1.5\n"
240 "+Zeta OUTLET conservation\n";
242 PetscFunctionBeginUser;
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));
256 "output_particles = false\n"));
258 if (enable_particles) {
265 "-particle_restart_mode init\n";
272 PetscCall(PetscSNPrintf(
274 sizeof(control_buffer),
284 "-profiling_timestep_mode off\n"
285 "-profiling_final_summary true\n"
286 "-postprocessing_config_file %s\n"
302 "-euler_field_source solve\n"
303 "-mom_solver_type EXPLICIT_RK\n"
307 "-particle_console_output_freq 0\n"
320 PetscFunctionReturn(0);
330 PetscBool x_periodic,
331 PetscBool y_periodic,
332 PetscBool z_periodic)
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;
345 PetscFunctionBeginUser;
346 if (!simCtx_out || !user_out) {
347 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"Output pointers cannot be NULL.");
350 PetscCall(PetscCalloc1(1, &simCtx));
351 PetscCall(PetscCalloc1(1, &user));
353 PetscCallMPI(MPI_Comm_rank(PETSC_COMM_WORLD, &simCtx->
rank));
354 PetscCallMPI(MPI_Comm_size(PETSC_COMM_WORLD, &simCtx->
size));
380 PetscCall(PetscCalloc1(simCtx->
size, &simCtx->
bboxlist));
410 for (PetscMPIInt rank_idx = 0; rank_idx < simCtx->
size; ++rank_idx) {
419 PetscCall(DMDACreate3d(PETSC_COMM_WORLD,
420 x_boundary, y_boundary, z_boundary,
423 PETSC_DECIDE, PETSC_DECIDE, PETSC_DECIDE,
427 PetscCall(DMSetUp(user->
da));
428 PetscCall(DMGetCoordinateDM(user->
da, &user->
fda));
429 PetscCall(PetscObjectReference((PetscObject)user->
fda));
430 PetscCall(DMDASetUniformCoordinates(user->
da, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0));
431 PetscCall(DMDAGetLocalInfo(user->
da, &user->
info));
435 for (PetscMPIInt rank_idx = 0; rank_idx < simCtx->
size; ++rank_idx) {
436 simCtx->
bboxlist[rank_idx] = boxes[rank_idx];
522 *simCtx_out = simCtx;
524 PetscFunctionReturn(0);
532 PetscFunctionBeginUser;
534 PetscFunctionReturn(0);
546 PetscInt mx = user->
IM;
547 PetscInt my = user->
JM;
548 PetscInt mz = user->
KM;
550 PetscFunctionBeginUser;
551 PetscCall(DMDAVecGetArray(user->
fda, user->
Cent, ¢));
552 for (PetscInt k = user->
info.zs; k < user->
info.zs + user->
info.zm; k++) {
553 for (PetscInt j = user->
info.ys; j < user->
info.ys + user->
info.ym; j++) {
554 for (PetscInt i = user->
info.xs; i < user->
info.xs + user->
info.xm; i++) {
555 cent[k][j][i].
x = (i - 0.5) / (PetscReal)mx;
556 cent[k][j][i].
y = (j - 0.5) / (PetscReal)my;
557 cent[k][j][i].
z = (k - 0.5) / (PetscReal)mz;
561 PetscCall(DMDAVecRestoreArray(user->
fda, user->
Cent, ¢));
562 PetscCall(DMGlobalToLocalBegin(user->
fda, user->
Cent, INSERT_VALUES, user->
lCent));
563 PetscCall(DMGlobalToLocalEnd(user->
fda, user->
Cent, INSERT_VALUES, user->
lCent));
564 PetscFunctionReturn(0);
585 PetscReal ***aj = NULL;
586 PetscReal ***iaj = NULL;
587 PetscReal ***jaj = NULL;
588 PetscReal ***kaj = NULL;
590 PetscFunctionBeginUser;
591 PetscCall(DMDAVecGetArray(user->
fda, user->
Csi, &csi));
592 PetscCall(DMDAVecGetArray(user->
fda, user->
Eta, &eta));
593 PetscCall(DMDAVecGetArray(user->
fda, user->
Zet, &zet));
594 PetscCall(DMDAVecGetArray(user->
fda, user->
ICsi, &icsi));
595 PetscCall(DMDAVecGetArray(user->
fda, user->
IEta, &ieta));
596 PetscCall(DMDAVecGetArray(user->
fda, user->
IZet, &izet));
597 PetscCall(DMDAVecGetArray(user->
fda, user->
JCsi, &jcsi));
598 PetscCall(DMDAVecGetArray(user->
fda, user->
JEta, &jeta));
599 PetscCall(DMDAVecGetArray(user->
fda, user->
JZet, &jzet));
600 PetscCall(DMDAVecGetArray(user->
fda, user->
KCsi, &kcsi));
601 PetscCall(DMDAVecGetArray(user->
fda, user->
KEta, &keta));
602 PetscCall(DMDAVecGetArray(user->
fda, user->
KZet, &kzet));
603 PetscCall(DMDAVecGetArray(user->
da, user->
Aj, &aj));
604 PetscCall(DMDAVecGetArray(user->
da, user->
IAj, &iaj));
605 PetscCall(DMDAVecGetArray(user->
da, user->
JAj, &jaj));
606 PetscCall(DMDAVecGetArray(user->
da, user->
KAj, &kaj));
608 for (PetscInt k = user->
info.zs; k < user->
info.zs + user->
info.zm; ++k) {
609 for (PetscInt j = user->
info.ys; j < user->
info.ys + user->
info.ym; ++j) {
610 for (PetscInt i = user->
info.xs; i < user->
info.xs + user->
info.xm; ++i) {
611 csi[k][j][i].
x = 1.0; csi[k][j][i].
y = 0.0; csi[k][j][i].
z = 0.0;
612 eta[k][j][i].
x = 0.0; eta[k][j][i].
y = 1.0; eta[k][j][i].
z = 0.0;
613 zet[k][j][i].
x = 0.0; zet[k][j][i].
y = 0.0; zet[k][j][i].
z = 1.0;
614 icsi[k][j][i] = csi[k][j][i];
615 ieta[k][j][i] = eta[k][j][i];
616 izet[k][j][i] = zet[k][j][i];
617 jcsi[k][j][i] = csi[k][j][i];
618 jeta[k][j][i] = eta[k][j][i];
619 jzet[k][j][i] = zet[k][j][i];
620 kcsi[k][j][i] = csi[k][j][i];
621 keta[k][j][i] = eta[k][j][i];
622 kzet[k][j][i] = zet[k][j][i];
631 PetscCall(DMDAVecRestoreArray(user->
fda, user->
Csi, &csi));
632 PetscCall(DMDAVecRestoreArray(user->
fda, user->
Eta, &eta));
633 PetscCall(DMDAVecRestoreArray(user->
fda, user->
Zet, &zet));
634 PetscCall(DMDAVecRestoreArray(user->
fda, user->
ICsi, &icsi));
635 PetscCall(DMDAVecRestoreArray(user->
fda, user->
IEta, &ieta));
636 PetscCall(DMDAVecRestoreArray(user->
fda, user->
IZet, &izet));
637 PetscCall(DMDAVecRestoreArray(user->
fda, user->
JCsi, &jcsi));
638 PetscCall(DMDAVecRestoreArray(user->
fda, user->
JEta, &jeta));
639 PetscCall(DMDAVecRestoreArray(user->
fda, user->
JZet, &jzet));
640 PetscCall(DMDAVecRestoreArray(user->
fda, user->
KCsi, &kcsi));
641 PetscCall(DMDAVecRestoreArray(user->
fda, user->
KEta, &keta));
642 PetscCall(DMDAVecRestoreArray(user->
fda, user->
KZet, &kzet));
643 PetscCall(DMDAVecRestoreArray(user->
da, user->
Aj, &aj));
644 PetscCall(DMDAVecRestoreArray(user->
da, user->
IAj, &iaj));
645 PetscCall(DMDAVecRestoreArray(user->
da, user->
JAj, &jaj));
646 PetscCall(DMDAVecRestoreArray(user->
da, user->
KAj, &kaj));
648 PetscCall(DMGlobalToLocalBegin(user->
fda, user->
Csi, INSERT_VALUES, user->
lCsi));
649 PetscCall(DMGlobalToLocalEnd(user->
fda, user->
Csi, INSERT_VALUES, user->
lCsi));
650 PetscCall(DMGlobalToLocalBegin(user->
fda, user->
Eta, INSERT_VALUES, user->
lEta));
651 PetscCall(DMGlobalToLocalEnd(user->
fda, user->
Eta, INSERT_VALUES, user->
lEta));
652 PetscCall(DMGlobalToLocalBegin(user->
fda, user->
Zet, INSERT_VALUES, user->
lZet));
653 PetscCall(DMGlobalToLocalEnd(user->
fda, user->
Zet, INSERT_VALUES, user->
lZet));
654 PetscCall(DMGlobalToLocalBegin(user->
fda, user->
ICsi, INSERT_VALUES, user->
lICsi));
655 PetscCall(DMGlobalToLocalEnd(user->
fda, user->
ICsi, INSERT_VALUES, user->
lICsi));
656 PetscCall(DMGlobalToLocalBegin(user->
fda, user->
IEta, INSERT_VALUES, user->
lIEta));
657 PetscCall(DMGlobalToLocalEnd(user->
fda, user->
IEta, INSERT_VALUES, user->
lIEta));
658 PetscCall(DMGlobalToLocalBegin(user->
fda, user->
IZet, INSERT_VALUES, user->
lIZet));
659 PetscCall(DMGlobalToLocalEnd(user->
fda, user->
IZet, INSERT_VALUES, user->
lIZet));
660 PetscCall(DMGlobalToLocalBegin(user->
fda, user->
JCsi, INSERT_VALUES, user->
lJCsi));
661 PetscCall(DMGlobalToLocalEnd(user->
fda, user->
JCsi, INSERT_VALUES, user->
lJCsi));
662 PetscCall(DMGlobalToLocalBegin(user->
fda, user->
JEta, INSERT_VALUES, user->
lJEta));
663 PetscCall(DMGlobalToLocalEnd(user->
fda, user->
JEta, INSERT_VALUES, user->
lJEta));
664 PetscCall(DMGlobalToLocalBegin(user->
fda, user->
JZet, INSERT_VALUES, user->
lJZet));
665 PetscCall(DMGlobalToLocalEnd(user->
fda, user->
JZet, INSERT_VALUES, user->
lJZet));
666 PetscCall(DMGlobalToLocalBegin(user->
fda, user->
KCsi, INSERT_VALUES, user->
lKCsi));
667 PetscCall(DMGlobalToLocalEnd(user->
fda, user->
KCsi, INSERT_VALUES, user->
lKCsi));
668 PetscCall(DMGlobalToLocalBegin(user->
fda, user->
KEta, INSERT_VALUES, user->
lKEta));
669 PetscCall(DMGlobalToLocalEnd(user->
fda, user->
KEta, INSERT_VALUES, user->
lKEta));
670 PetscCall(DMGlobalToLocalBegin(user->
fda, user->
KZet, INSERT_VALUES, user->
lKZet));
671 PetscCall(DMGlobalToLocalEnd(user->
fda, user->
KZet, INSERT_VALUES, user->
lKZet));
672 PetscCall(DMGlobalToLocalBegin(user->
da, user->
Nvert, INSERT_VALUES, user->
lNvert));
673 PetscCall(DMGlobalToLocalEnd(user->
da, user->
Nvert, INSERT_VALUES, user->
lNvert));
674 PetscCall(DMGlobalToLocalBegin(user->
da, user->
Aj, INSERT_VALUES, user->
lAj));
675 PetscCall(DMGlobalToLocalEnd(user->
da, user->
Aj, INSERT_VALUES, user->
lAj));
676 PetscCall(DMGlobalToLocalBegin(user->
da, user->
IAj, INSERT_VALUES, user->
lIAj));
677 PetscCall(DMGlobalToLocalEnd(user->
da, user->
IAj, INSERT_VALUES, user->
lIAj));
678 PetscCall(DMGlobalToLocalBegin(user->
da, user->
JAj, INSERT_VALUES, user->
lJAj));
679 PetscCall(DMGlobalToLocalEnd(user->
da, user->
JAj, INSERT_VALUES, user->
lJAj));
680 PetscCall(DMGlobalToLocalBegin(user->
da, user->
KAj, INSERT_VALUES, user->
lKAj));
681 PetscCall(DMGlobalToLocalEnd(user->
da, user->
KAj, INSERT_VALUES, user->
lKAj));
682 PetscCall(DMGlobalToLocalBegin(user->
da, user->
P, INSERT_VALUES, user->
lP));
683 PetscCall(DMGlobalToLocalEnd(user->
da, user->
P, INSERT_VALUES, user->
lP));
684 PetscCall(DMGlobalToLocalBegin(user->
da, user->
Psi, INSERT_VALUES, user->
lPsi));
685 PetscCall(DMGlobalToLocalEnd(user->
da, user->
Psi, INSERT_VALUES, user->
lPsi));
686 PetscCall(DMGlobalToLocalBegin(user->
fda, user->
Ucat, INSERT_VALUES, user->
lUcat));
687 PetscCall(DMGlobalToLocalEnd(user->
fda, user->
Ucat, INSERT_VALUES, user->
lUcat));
688 PetscCall(DMGlobalToLocalBegin(user->
fda, user->
Ucont, INSERT_VALUES, user->
lUcont));
689 PetscCall(DMGlobalToLocalEnd(user->
fda, user->
Ucont, INSERT_VALUES, user->
lUcont));
690 PetscCall(DMGlobalToLocalBegin(user->
fda, user->
Cent, INSERT_VALUES, user->
lCent));
691 PetscCall(DMGlobalToLocalEnd(user->
fda, user->
Cent, INSERT_VALUES, user->
lCent));
692 PetscFunctionReturn(0);
700 PetscFunctionBeginUser;
702 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"UserCtx cannot be NULL.");
705 PetscCall(DMCreate(PETSC_COMM_WORLD, &user->
swarm));
706 PetscCall(DMSetType(user->
swarm, DMSWARM));
707 PetscCall(DMSetDimension(user->
swarm, 3));
708 PetscCall(DMSwarmSetType(user->
swarm, DMSWARM_BASIC));
709 PetscCall(DMSwarmSetCellDM(user->
swarm, user->
da));
718 PetscCall(DMSwarmFinalizeFieldRegister(user->
swarm));
719 PetscCall(DMSwarmSetLocalSizes(user->
swarm, nlocal, 0));
721 PetscCall(DMCreate(PETSC_COMM_WORLD, &user->
post_swarm));
722 PetscCall(DMSetType(user->
post_swarm, DMSWARM));
723 PetscCall(DMSetDimension(user->
post_swarm, 3));
724 PetscCall(DMSwarmSetType(user->
post_swarm, DMSWARM_BASIC));
725 PetscCall(DMSwarmSetCellDM(user->
post_swarm, user->
da));
727 PetscCall(DMSwarmFinalizeFieldRegister(user->
post_swarm));
728 PetscCall(DMSwarmSetLocalSizes(user->
post_swarm, nlocal, 0));
729 PetscFunctionReturn(0);
736 PetscBool enable_particles,
742 char control_path[PETSC_MAX_PATH_LEN];
745 PetscFunctionBeginUser;
746 PetscCheck(simCtx_out != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"SimCtx output cannot be NULL.");
748 PetscCall(PetscOptionsClear(NULL));
749 PetscCall(
PrepareTinyRuntimeConfig(bcs_contents, enable_particles, tmpdir, tmpdir_len, control_path,
sizeof(control_path)));
750 PetscCall(PetscOptionsSetValue(NULL,
"-control_file", control_path));
758 *simCtx_out = simCtx;
762 PetscFunctionReturn(0);
770 PetscFunctionBeginUser;
771 if (simCtx_ptr && *simCtx_ptr) {
773 PetscCall(PetscFree(*simCtx_ptr));
776 PetscCall(PetscOptionsClear(NULL));
777 PetscFunctionReturn(0);
788 PetscFunctionBeginUser;
793 simCtx = *simCtx_ptr;
879 PetscCall(PetscFree(user));
887 PetscCall(PetscFree(simCtx->
bboxlist));
889 PetscCall(PetscFree(simCtx->
pps));
890 PetscCall(PetscFree(simCtx));
896 PetscFunctionReturn(0);
904 PetscFunctionBeginUser;
905 if (PetscAbsReal(expected - actual) > tol) {
906 PetscCall(PetscPrintf(PETSC_COMM_WORLD,
907 "[FAIL] %s | expected=%0.12e actual=%0.12e tol=%0.12e\n",
908 context, (
double)expected, (
double)actual, (
double)tol));
909 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_PLIB,
"Assertion failed.");
911 PetscFunctionReturn(0);
919 PetscFunctionBeginUser;
920 if (expected != actual) {
921 PetscCall(PetscPrintf(PETSC_COMM_WORLD,
922 "[FAIL] %s | expected=%" PetscInt_FMT
" actual=%" PetscInt_FMT
"\n",
923 context, expected, actual));
924 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_PLIB,
"Assertion failed.");
926 PetscFunctionReturn(0);
934 PetscFunctionBeginUser;
936 PetscCall(PetscPrintf(PETSC_COMM_WORLD,
"[FAIL] %s\n", context));
937 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_PLIB,
"Assertion failed.");
939 PetscFunctionReturn(0);
947 PetscBool exists = PETSC_FALSE;
949 PetscFunctionBeginUser;
950 PetscCall(PetscTestFile(path,
'r', &exists));
952 PetscCall(PetscPrintf(PETSC_COMM_WORLD,
"[FAIL] %s | missing file: %s\n", context, path));
953 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN,
"Expected file is missing.");
955 PetscFunctionReturn(0);
963 PetscReal vmin = 0.0;
964 PetscReal vmax = 0.0;
966 PetscFunctionBeginUser;
967 PetscCall(VecMin(vec, NULL, &vmin));
968 PetscCall(VecMax(vec, NULL, &vmax));
971 PetscFunctionReturn(0);
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.
PetscErrorCode ComputeLocalBoundingBox(UserCtx *user, BoundingBox *localBBox)
Computes the local bounding box of the grid on the current process.
PetscErrorCode GatherAllBoundingBoxes(UserCtx *user, BoundingBox **allBBoxes)
Gathers local bounding boxes from all MPI processes to rank 0.
Public interface for data input/output routines.
void FreeBC_ParamList(BC_Param *head)
Frees an entire linked list of boundary-condition parameters.
PetscErrorCode SetupDomainRankInfo(SimCtx *simCtx)
Sets up the full rank communication infrastructure, including neighbor ranks and bounding box exchang...
PetscErrorCode SetupGridAndSolvers(SimCtx *simCtx)
The main orchestrator for setting up all grid-related components.
PetscErrorCode SetupSimulationEnvironment(SimCtx *simCtx)
Verifies and prepares the complete I/O environment for a simulation run.
PetscErrorCode CreateSimulationContext(int argc, char **argv, SimCtx **p_simCtx)
Allocates and populates the master SimulationContext object.
PetscErrorCode SetupBoundaryConditions(SimCtx *simCtx)
(Orchestrator) Sets up all boundary conditions for the simulation.
PetscErrorCode FinalizeSimulation(SimCtx *simCtx)
Main cleanup function for the entire simulation context.
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.
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.
BoundaryFaceConfig boundary_faces[6]
char euler_subdir[PETSC_MAX_PATH_LEN]
PetscReal forceScalingFactor
SimCtx * simCtx
Back-pointer to the master simulation context.
Cmpnts max_coords
Maximum x, y, z coordinates of the bounding box.
char output_dir[PETSC_MAX_PATH_LEN]
Cmpnts min_coords
Minimum x, y, z coordinates of the bounding box.
Vec Ubcs
Physical Cartesian velocity at boundary faces. Full 3D array but only boundary-face entries are meani...
@ MOMENTUM_SOLVER_EXPLICIT_RK
RankCellInfo * RankCellInfoMap
char particle_subdir[PETSC_MAX_PATH_LEN]
PetscRandom BrownianMotionRNG
MomentumSolverType mom_solver_type
char restart_dir[PETSC_MAX_PATH_LEN]
PetscInt LoggingFrequency
Vec Uch
Characteristic velocity for boundary conditions.
Defines a 3D axis-aligned bounding box.
A 3D point or vector with PetscScalar components.
The master context for the entire simulation.
User-defined context containing data specific to a single computational grid level.