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

C unit tests for setup, initialization, and cleanup lifecycle entry points. More...

#include "test_support.h"
#include "ParticleSwarm.h"
#include "initialcondition.h"
#include "runloop.h"
#include "setup.h"
#include <stdio.h>
#include <string.h>
Include dependency graph for test_setup_lifecycle.c:

Go to the source code of this file.

Functions

static PetscErrorCode AssertDirectoryExists (const char *path, const char *context)
 Asserts that a directory path exists and is readable.
 
static PetscErrorCode WriteContextOnlyFile (const char *path, const char *contents)
 Writes one small temporary text file used by the partial-lifecycle context-only fixture.
 
static PetscErrorCode PrepareContextOnlyConfig (char *tmpdir, size_t tmpdir_len, char *control_path, size_t control_path_len)
 Creates the control-file bundle needed for the context-only cleanup test.
 
static PetscErrorCode FreeLifecycleContext (SimCtx **simCtx_ptr)
 Finalizes and frees one lifecycle test context, then clears any PETSc options used to build it.
 
static PetscErrorCode BuildLifecycleContext (PetscBool enable_particles, SimCtx **simCtx_out, char *tmpdir, size_t tmpdir_len)
 Builds a full setup fixture through environment, grid, BC, and domain-rank initialization.
 
static PetscErrorCode BuildContextOnly (SimCtx **simCtx_out, char *tmpdir, size_t tmpdir_len)
 Builds only the top-level simulation context used by partial-initialization cleanup tests.
 
static PetscErrorCode TestSharedRuntimeFixtureContracts (void)
 Tests that the shared richer runtime fixture mirrors normalized production setup contracts.
 
static PetscErrorCode TestSetupLifecycleCoreSolverSetup (void)
 Tests the core setup lifecycle through environment, grid, BC, rank-info, and Eulerian-state initialization.
 
static PetscErrorCode TestSetupLifecycleParticleInitialization (void)
 Tests particle-swarm initialization and deterministic settlement on a tiny fully initialized case.
 
static PetscErrorCode TestSetupLifecycleScatterMetricsAtStepZero (void)
 Tests that step-zero scalar verification emits scatter_metrics.csv during initialized setup.
 
static PetscErrorCode TestSetupLifecycleRandomGeneratorsAndCleanup (void)
 Tests standalone RNG initialization helpers and minimal-context cleanup.
 
static PetscErrorCode TestSetupLifecycleCleanupAcrossInitializationStates (void)
 Tests cleanup after partial and fuller setup states without requiring unsupported double-finalization behavior.
 
int main (int argc, char **argv)
 Runs the unit-setup PETSc test binary.
 

Detailed Description

C unit tests for setup, initialization, and cleanup lifecycle entry points.

Definition in file test_setup_lifecycle.c.

Function Documentation

◆ AssertDirectoryExists()

static PetscErrorCode AssertDirectoryExists ( const char *  path,
const char *  context 
)
static

Asserts that a directory path exists and is readable.

Definition at line 19 of file test_setup_lifecycle.c.

20{
21 PetscBool exists = PETSC_FALSE;
22
23 PetscFunctionBeginUser;
24 PetscCall(PetscTestDirectory(path, 'r', &exists));
25 PetscCall(PicurvAssertBool(exists, context));
26 PetscFunctionReturn(0);
27}
PetscErrorCode PicurvAssertBool(PetscBool value, const char *context)
Asserts that one boolean condition is true.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteContextOnlyFile()

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

Writes one small temporary text file used by the partial-lifecycle context-only fixture.

Definition at line 32 of file test_setup_lifecycle.c.

33{
34 FILE *file = NULL;
35
36 PetscFunctionBeginUser;
37 file = fopen(path, "w");
38 PetscCheck(file != NULL, PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN, "Failed to open '%s' for writing.", path);
39 fputs(contents, file);
40 fclose(file);
41 PetscFunctionReturn(0);
42}
Here is the caller graph for this function:

◆ PrepareContextOnlyConfig()

static PetscErrorCode PrepareContextOnlyConfig ( char *  tmpdir,
size_t  tmpdir_len,
char *  control_path,
size_t  control_path_len 
)
static

Creates the control-file bundle needed for the context-only cleanup test.

Definition at line 47 of file test_setup_lifecycle.c.

51{
52 char bcs_path[PETSC_MAX_PATH_LEN];
53 char post_path[PETSC_MAX_PATH_LEN];
54 char output_dir[PETSC_MAX_PATH_LEN];
55 char log_dir[PETSC_MAX_PATH_LEN];
56 char control_buffer[8192];
57
58 PetscFunctionBeginUser;
59 PetscCall(PicurvMakeTempDir(tmpdir, tmpdir_len));
60 PetscCall(PetscSNPrintf(bcs_path, sizeof(bcs_path), "%s/bcs.run", tmpdir));
61 PetscCall(PetscSNPrintf(post_path, sizeof(post_path), "%s/post.run", tmpdir));
62 PetscCall(PetscSNPrintf(output_dir, sizeof(output_dir), "%s/results", tmpdir));
63 PetscCall(PetscSNPrintf(log_dir, sizeof(log_dir), "%s/logs", tmpdir));
64 PetscCall(PetscSNPrintf(control_path, control_path_len, "%s/test.control", tmpdir));
65
66 PetscCall(WriteContextOnlyFile(
67 bcs_path,
68 "-Xi WALL noslip\n"
69 "+Xi WALL noslip\n"
70 "-Eta WALL noslip\n"
71 "+Eta WALL noslip\n"
72 "-Zeta INLET constant_velocity vx=0.0 vy=0.0 vz=1.5\n"
73 "+Zeta OUTLET conservation\n"));
74 PetscCall(WriteContextOnlyFile(
75 post_path,
76 "startTime = 0\n"
77 "endTime = 1\n"
78 "timeStep = 1\n"
79 "output_particles = false\n"));
80 PetscCall(PetscSNPrintf(
81 control_buffer,
82 sizeof(control_buffer),
83 "-start_step 0\n"
84 "-totalsteps 2\n"
85 "-ren 100.0\n"
86 "-dt 0.001\n"
87 "-finit 1\n"
88 "-ucont_x 0.0\n"
89 "-ucont_y 0.0\n"
90 "-ucont_z 1.5\n"
91 "-bcs_files %s\n"
92 "-profiling_timestep_mode off\n"
93 "-profiling_final_summary true\n"
94 "-postprocessing_config_file %s\n"
95 "-grid\n"
96 "-im 6\n"
97 "-jm 6\n"
98 "-km 6\n"
99 "-xMins 0.0\n"
100 "-xMaxs 1.0\n"
101 "-yMins 0.0\n"
102 "-yMaxs 1.0\n"
103 "-zMins 0.0\n"
104 "-zMaxs 1.0\n"
105 "-rxs 1.0\n"
106 "-rys 1.0\n"
107 "-rzs 1.0\n"
108 "-cgrids 0\n"
109 "-nblk 1\n"
110 "-euler_field_source solve\n"
111 "-mom_solver_type DUALTIME_PICARD_RK4\n"
112 "-mom_dt_rk4_residual_norm_noise_allowance_factor 1.07\n"
113 "-mom_resid_atol 1.0e-8\n"
114 "-mom_resid_rtol 1.0e-3\n"
115 "-mom_nk_pic_monitor\n"
116 "-mg_level 1\n"
117 "-poisson 0\n"
118 "-tio 0\n"
119 "-particle_console_output_freq 0\n"
120 "-logfreq 1\n"
121 "-output_dir %s\n"
122 "-restart_dir %s\n"
123 "-log_dir %s\n"
124 "-numParticles 0\n"
125 "-pinit 2\n",
126 bcs_path,
127 post_path,
128 output_dir,
129 output_dir,
130 log_dir));
131 PetscCall(WriteContextOnlyFile(control_path, control_buffer));
132 PetscFunctionReturn(0);
133}
static PetscErrorCode WriteContextOnlyFile(const char *path, const char *contents)
Writes one small temporary text file used by the partial-lifecycle context-only fixture.
PetscErrorCode PicurvMakeTempDir(char *path, size_t path_len)
Creates a unique temporary directory for one test case.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FreeLifecycleContext()

static PetscErrorCode FreeLifecycleContext ( SimCtx **  simCtx_ptr)
static

Finalizes and frees one lifecycle test context, then clears any PETSc options used to build it.

Definition at line 138 of file test_setup_lifecycle.c.

139{
140 PetscFunctionBeginUser;
141 PetscCall(PicurvDestroyRuntimeContext(simCtx_ptr));
142 PetscFunctionReturn(0);
143}
PetscErrorCode PicurvDestroyRuntimeContext(SimCtx **simCtx_ptr)
Finalizes and frees a runtime context built by PicurvBuildTinyRuntimeContext.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BuildLifecycleContext()

static PetscErrorCode BuildLifecycleContext ( PetscBool  enable_particles,
SimCtx **  simCtx_out,
char *  tmpdir,
size_t  tmpdir_len 
)
static

Builds a full setup fixture through environment, grid, BC, and domain-rank initialization.

Definition at line 148 of file test_setup_lifecycle.c.

149{
150 PetscFunctionBeginUser;
151 PetscCall(PicurvBuildTinyRuntimeContext(NULL, enable_particles, simCtx_out, NULL, tmpdir, tmpdir_len));
152 PetscFunctionReturn(0);
153}
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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BuildContextOnly()

static PetscErrorCode BuildContextOnly ( SimCtx **  simCtx_out,
char *  tmpdir,
size_t  tmpdir_len 
)
static

Builds only the top-level simulation context used by partial-initialization cleanup tests.

Definition at line 158 of file test_setup_lifecycle.c.

159{
160 char control_path[PETSC_MAX_PATH_LEN];
161 SimCtx *simCtx = NULL;
162
163 PetscFunctionBeginUser;
164 PetscCall(PetscOptionsClear(NULL));
165 PetscCall(PrepareContextOnlyConfig(tmpdir, tmpdir_len, control_path, sizeof(control_path)));
166 PetscCall(PetscOptionsSetValue(NULL, "-control_file", control_path));
167 PetscCall(CreateSimulationContext(0, NULL, &simCtx));
168 simCtx->exec_mode = EXEC_MODE_SOLVER;
169 *simCtx_out = simCtx;
170 PetscFunctionReturn(0);
171}
PetscErrorCode CreateSimulationContext(int argc, char **argv, SimCtx **p_simCtx)
Allocates and populates the master SimulationContext object.
Definition setup.c:151
static PetscErrorCode PrepareContextOnlyConfig(char *tmpdir, size_t tmpdir_len, char *control_path, size_t control_path_len)
Creates the control-file bundle needed for the context-only cleanup test.
@ EXEC_MODE_SOLVER
Definition variables.h:657
ExecutionMode exec_mode
Definition variables.h:703
The master context for the entire simulation.
Definition variables.h:684
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestSharedRuntimeFixtureContracts()

static PetscErrorCode TestSharedRuntimeFixtureContracts ( void  )
static

Tests that the shared richer runtime fixture mirrors normalized production setup contracts.

Definition at line 176 of file test_setup_lifecycle.c.

177{
178 SimCtx *simCtx = NULL;
179 UserCtx *user = NULL;
180 char tmpdir[PETSC_MAX_PATH_LEN];
181
182 PetscFunctionBeginUser;
183 PetscCall(PicurvBuildTinyRuntimeContext(NULL, PETSC_FALSE, &simCtx, &user, tmpdir, sizeof(tmpdir)));
184
185 PetscCall(PicurvAssertBool((PetscBool)(user->bbox.min_coords.x >= -2.0e-6), "runtime fixture bbox xmin should stay inside normalized domain tolerance"));
186 PetscCall(PicurvAssertBool((PetscBool)(user->bbox.max_coords.x <= 1.0 + 2.0e-6), "runtime fixture bbox xmax should stay inside normalized domain tolerance"));
187 PetscCall(PicurvAssertBool((PetscBool)(user->bbox.max_coords.y <= 1.0 + 2.0e-6), "runtime fixture bbox ymax should stay inside normalized domain tolerance"));
188 PetscCall(PicurvAssertBool((PetscBool)(user->bbox.max_coords.z <= 1.0 + 2.0e-6), "runtime fixture bbox zmax should stay inside normalized domain tolerance"));
189 PetscCall(PicurvAssertBool((PetscBool)(simCtx->bboxlist != NULL), "runtime fixture should gather bboxlist through SetupDomainRankInfo"));
190 PetscCall(PicurvAssertBool((PetscBool)(user->RankCellInfoMap != NULL), "runtime fixture should gather rank-cell ownership metadata"));
191 PetscCall(PicurvAssertBool((PetscBool)(simCtx->bboxlist[simCtx->rank].max_coords.x >= user->bbox.max_coords.x - 1.0e-10),
192 "runtime fixture rank bbox entry should include the local bbox extent"));
193
194 PetscCall(PicurvRemoveTempDir(tmpdir));
195 PetscCall(FreeLifecycleContext(&simCtx));
196 PetscFunctionReturn(0);
197}
static PetscErrorCode FreeLifecycleContext(SimCtx **simCtx_ptr)
Finalizes and frees one lifecycle test context, then clears any PETSc options used to build it.
PetscErrorCode PicurvRemoveTempDir(const char *path)
Recursively removes a temporary directory created by PicurvMakeTempDir.
PetscMPIInt rank
Definition variables.h:687
Cmpnts max_coords
Maximum x, y, z coordinates of the bounding box.
Definition variables.h:171
Cmpnts min_coords
Minimum x, y, z coordinates of the bounding box.
Definition variables.h:170
PetscScalar x
Definition variables.h:101
RankCellInfo * RankCellInfoMap
Definition variables.h:951
BoundingBox * bboxlist
Definition variables.h:799
PetscScalar z
Definition variables.h:101
PetscScalar y
Definition variables.h:101
BoundingBox bbox
Definition variables.h:887
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:

◆ TestSetupLifecycleCoreSolverSetup()

static PetscErrorCode TestSetupLifecycleCoreSolverSetup ( void  )
static

Tests the core setup lifecycle through environment, grid, BC, rank-info, and Eulerian-state initialization.

Definition at line 202 of file test_setup_lifecycle.c.

203{
204 SimCtx *simCtx = NULL;
205 UserCtx *user = NULL;
206 char tmpdir[PETSC_MAX_PATH_LEN];
207 char results_dir[PETSC_MAX_PATH_LEN];
208 char logs_dir[PETSC_MAX_PATH_LEN];
209 Cmpnts ***ucont = NULL;
210
211 PetscFunctionBeginUser;
212 PetscCall(BuildLifecycleContext(PETSC_FALSE, &simCtx, tmpdir, sizeof(tmpdir)));
213 user = simCtx->usermg.mgctx[simCtx->usermg.mglevels - 1].user;
214
215 PetscCall(PetscSNPrintf(results_dir, sizeof(results_dir), "%s/results", tmpdir));
216 PetscCall(PetscSNPrintf(logs_dir, sizeof(logs_dir), "%s/logs", tmpdir));
217 PetscCall(PicurvAssertBool((PetscBool)(user->da != NULL), "SetupGridAndSolvers should allocate da"));
218 PetscCall(PicurvAssertBool((PetscBool)(user->fda != NULL), "SetupGridAndSolvers should allocate coordinate DM"));
219 PetscCall(PicurvAssertIntEqual(user->IM + 1, user->info.mx, "DM node count should match IM+1"));
220 PetscCall(PicurvAssertBool(user->inletFaceDefined, "SetupBoundaryConditions should identify the inlet face"));
221 PetscCall(PicurvAssertIntEqual(BC_FACE_NEG_Z, user->identifiedInletBCFace, "NEG_Z should be the configured inlet face"));
222 PetscCall(PicurvAssertBool((PetscBool)(simCtx->bboxlist != NULL), "SetupDomainRankInfo should build bboxlist"));
223 PetscCall(PicurvAssertBool((PetscBool)(user->RankCellInfoMap != NULL), "SetupDomainRankInfo should build rank-cell decomposition map"));
224 PetscCall(AssertDirectoryExists(results_dir, "SetupSimulationEnvironment should create the output directory"));
225 PetscCall(AssertDirectoryExists(logs_dir, "SetupSimulationEnvironment should create the log directory"));
226
227 PetscCall(InitializeEulerianState(simCtx));
228 PetscCall(DMDAVecGetArrayRead(user->fda, user->Ucont, &ucont));
229 PetscCall(PicurvAssertBool((PetscBool)(ucont[1][1][1].z > 0.0),
230 "InitializeEulerianState should seed a positive inlet-aligned interior field"));
231 PetscCall(PicurvAssertRealNear(ucont[1][1][1].z, ucont[2][2][2].z, 1.0e-12,
232 "InitializeEulerianState should initialize a spatially consistent interior field"));
233 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Ucont, &ucont));
234
235 PetscCall(PicurvRemoveTempDir(tmpdir));
236 PetscCall(FreeLifecycleContext(&simCtx));
237 PetscFunctionReturn(0);
238}
PetscErrorCode InitializeEulerianState(SimCtx *simCtx)
High-level orchestrator to set the complete initial state of the Eulerian solver.
static PetscErrorCode AssertDirectoryExists(const char *path, const char *context)
Asserts that a directory path exists and is readable.
static PetscErrorCode BuildLifecycleContext(PetscBool enable_particles, SimCtx **simCtx_out, char *tmpdir, size_t tmpdir_len)
Builds a full setup fixture through environment, grid, BC, and domain-rank initialization.
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.
UserCtx * user
Definition variables.h:569
PetscBool inletFaceDefined
Definition variables.h:897
BCFace identifiedInletBCFace
Definition variables.h:898
UserMG usermg
Definition variables.h:821
Vec Ucont
Definition variables.h:904
PetscInt mglevels
Definition variables.h:576
DMDALocalInfo info
Definition variables.h:883
PetscInt IM
Definition variables.h:885
MGCtx * mgctx
Definition variables.h:579
@ BC_FACE_NEG_Z
Definition variables.h:262
A 3D point or vector with PetscScalar components.
Definition variables.h:100
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestSetupLifecycleParticleInitialization()

static PetscErrorCode TestSetupLifecycleParticleInitialization ( void  )
static

Tests particle-swarm initialization and deterministic settlement on a tiny fully initialized case.

Definition at line 243 of file test_setup_lifecycle.c.

244{
245 SimCtx *simCtx = NULL;
246 UserCtx *user = NULL;
247 char tmpdir[PETSC_MAX_PATH_LEN];
248 PetscInt nlocal = 0;
249 PetscInt *cell_ids = NULL;
250 PetscInt *status = NULL;
251
252 PetscFunctionBeginUser;
253 PetscCall(BuildLifecycleContext(PETSC_TRUE, &simCtx, tmpdir, sizeof(tmpdir)));
254 PetscCall(InitializeEulerianState(simCtx));
255 PetscCall(InitializeParticleSwarm(simCtx));
256 PetscCall(PerformInitializedParticleSetup(simCtx));
257
258 user = simCtx->usermg.mgctx[simCtx->usermg.mglevels - 1].user;
259 PetscCall(PicurvAssertBool((PetscBool)(user->swarm != NULL), "InitializeParticleSwarm should allocate the solver swarm"));
260 PetscCall(DMSwarmGetLocalSize(user->swarm, &nlocal));
261 PetscCall(PicurvAssertIntEqual(8, nlocal, "single-rank lifecycle particle setup should own all seeded particles"));
262
263 PetscCall(DMSwarmGetField(user->swarm, "DMSwarm_CellID", NULL, NULL, (void **)&cell_ids));
264 PetscCall(DMSwarmGetField(user->swarm, "DMSwarm_location_status", NULL, NULL, (void **)&status));
265 for (PetscInt p = 0; p < nlocal; ++p) {
266 PetscCall(PicurvAssertBool((PetscBool)(cell_ids[3 * p + 0] >= 0), "settled particles should have a valid i cell id"));
267 PetscCall(PicurvAssertBool((PetscBool)(cell_ids[3 * p + 1] >= 0), "settled particles should have a valid j cell id"));
268 PetscCall(PicurvAssertBool((PetscBool)(cell_ids[3 * p + 2] >= 0), "settled particles should have a valid k cell id"));
269 PetscCall(PicurvAssertIntEqual(ACTIVE_AND_LOCATED, status[p], "settled particles should be marked ACTIVE_AND_LOCATED"));
270 }
271 PetscCall(DMSwarmRestoreField(user->swarm, "DMSwarm_CellID", NULL, NULL, (void **)&cell_ids));
272 PetscCall(DMSwarmRestoreField(user->swarm, "DMSwarm_location_status", NULL, NULL, (void **)&status));
273
274 PetscCall(PicurvRemoveTempDir(tmpdir));
275 PetscCall(FreeLifecycleContext(&simCtx));
276 PetscFunctionReturn(0);
277}
PetscErrorCode InitializeParticleSwarm(SimCtx *simCtx)
High-level particle initialization orchestrator for a simulation run.
PetscErrorCode PerformInitializedParticleSetup(SimCtx *simCtx)
Finalizes the simulation setup at t=0, ensuring a consistent state before time marching.
Definition runloop.c:377
@ ACTIVE_AND_LOCATED
Definition variables.h:137
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestSetupLifecycleScatterMetricsAtStepZero()

static PetscErrorCode TestSetupLifecycleScatterMetricsAtStepZero ( void  )
static

Tests that step-zero scalar verification emits scatter_metrics.csv during initialized setup.

Definition at line 282 of file test_setup_lifecycle.c.

283{
284 SimCtx *simCtx = NULL;
285 UserCtx *user = NULL;
286 char tmpdir[PETSC_MAX_PATH_LEN];
287 char metrics_path[PETSC_MAX_PATH_LEN];
288
289 PetscFunctionBeginUser;
290 PetscCall(BuildLifecycleContext(PETSC_TRUE, &simCtx, tmpdir, sizeof(tmpdir)));
291 user = simCtx->usermg.mgctx[simCtx->usermg.mglevels - 1].user;
292 PetscCall(PetscStrncpy(simCtx->eulerianSource, "analytical", sizeof(simCtx->eulerianSource)));
293 PetscCall(PetscStrncpy(simCtx->AnalyticalSolutionType, "ZERO_FLOW", sizeof(simCtx->AnalyticalSolutionType)));
294 simCtx->StepsToRun = 0;
295 simCtx->StartStep = 0;
296 simCtx->verificationScalar.enabled = PETSC_TRUE;
297 PetscCall(PetscStrncpy(simCtx->verificationScalar.mode,
298 "analytical",
299 sizeof(simCtx->verificationScalar.mode)));
300 PetscCall(PetscStrncpy(simCtx->verificationScalar.profile,
301 "CONSTANT",
302 sizeof(simCtx->verificationScalar.profile)));
303 simCtx->verificationScalar.value = 1.25;
304
305 PetscCall(InitializeEulerianState(simCtx));
306 PetscCall(InitializeParticleSwarm(simCtx));
307 PetscCall(PerformInitializedParticleSetup(simCtx));
308
309 PetscCall(PetscSNPrintf(metrics_path, sizeof(metrics_path), "%s/logs/scatter_metrics.csv", tmpdir));
310 PetscCall(PicurvAssertFileExists(metrics_path,
311 "PerformInitializedParticleSetup should emit scatter_metrics.csv for a zero-step scalar verification run"));
312 PetscCall(PicurvAssertBool((PetscBool)(user->swarm != NULL),
313 "zero-step scalar verification setup should leave the swarm initialized"));
314
315 PetscCall(PicurvRemoveTempDir(tmpdir));
316 PetscCall(FreeLifecycleContext(&simCtx));
317 PetscFunctionReturn(0);
318}
PetscErrorCode PicurvAssertFileExists(const char *path, const char *context)
Asserts that a filesystem path exists as a readable file.
PetscInt StepsToRun
Definition variables.h:695
PetscInt StartStep
Definition variables.h:694
VerificationScalarConfig verificationScalar
Definition variables.h:756
char eulerianSource[PETSC_MAX_PATH_LEN]
Definition variables.h:704
char AnalyticalSolutionType[PETSC_MAX_PATH_LEN]
Definition variables.h:717
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestSetupLifecycleRandomGeneratorsAndCleanup()

static PetscErrorCode TestSetupLifecycleRandomGeneratorsAndCleanup ( void  )
static

Tests standalone RNG initialization helpers and minimal-context cleanup.

Definition at line 323 of file test_setup_lifecycle.c.

324{
325 SimCtx *simCtx = NULL;
326 UserCtx *user = NULL;
327 PetscRandom randx = NULL, randy = NULL, randz = NULL;
328 PetscRandom rand_i = NULL, rand_j = NULL, rand_k = NULL;
329 PetscScalar sample_x = 0.0, sample_i = 0.0;
330 PetscReal seconds = 0.0;
331
332 PetscFunctionBeginUser;
333 PetscCall(PicurvCreateMinimalContexts(&simCtx, &user, 4, 4, 4));
334 user->bbox.min_coords.x = 0.0;
335 user->bbox.min_coords.y = 0.0;
336 user->bbox.min_coords.z = 0.0;
337 user->bbox.max_coords.x = 1.0;
338 user->bbox.max_coords.y = 2.0;
339 user->bbox.max_coords.z = 3.0;
340
341 PetscCall(InitializeRandomGenerators(user, &randx, &randy, &randz));
342 PetscCall(InitializeLogicalSpaceRNGs(&rand_i, &rand_j, &rand_k));
343 PetscCall(InitializeBrownianRNG(simCtx));
344 PetscCall(PicurvAssertBool((PetscBool)(simCtx->BrownianMotionRNG != NULL), "InitializeBrownianRNG should allocate the Brownian RNG"));
345 PetscCall(PicurvAssertBool(RuntimeWalltimeGuardParsePositiveSeconds("12.5", &seconds), "RuntimeWalltimeGuardParsePositiveSeconds should parse positive numeric strings"));
346 PetscCall(PicurvAssertRealNear(12.5, seconds, 1.0e-12, "RuntimeWalltimeGuardParsePositiveSeconds parsed value"));
347
348 PetscCall(PetscRandomGetValue(randx, &sample_x));
349 PetscCall(PetscRandomGetValue(rand_i, &sample_i));
350 PetscCall(PicurvAssertBool((PetscBool)(PetscRealPart(sample_x) >= 0.0 && PetscRealPart(sample_x) <= 1.0),
351 "InitializeRandomGenerators should honor the configured bbox interval"));
352 PetscCall(PicurvAssertBool((PetscBool)(PetscRealPart(sample_i) >= 0.0 && PetscRealPart(sample_i) <= 1.0),
353 "InitializeLogicalSpaceRNGs should generate logical coordinates in [0,1]"));
354
355 PetscCall(PetscRandomDestroy(&randx));
356 PetscCall(PetscRandomDestroy(&randy));
357 PetscCall(PetscRandomDestroy(&randz));
358 PetscCall(PetscRandomDestroy(&rand_i));
359 PetscCall(PetscRandomDestroy(&rand_j));
360 PetscCall(PetscRandomDestroy(&rand_k));
361 PetscCall(PicurvDestroyMinimalContexts(&simCtx, &user));
362 PetscFunctionReturn(0);
363}
PetscErrorCode InitializeRandomGenerators(UserCtx *user, PetscRandom *randx, PetscRandom *randy, PetscRandom *randz)
Initializes random number generators for assigning particle properties.
Definition setup.c:3301
PetscErrorCode InitializeBrownianRNG(SimCtx *simCtx)
Initializes a single master RNG for time-stepping physics (Brownian motion).
Definition setup.c:3386
PetscErrorCode InitializeLogicalSpaceRNGs(PetscRandom *rand_logic_i, PetscRandom *rand_logic_j, PetscRandom *rand_logic_k)
Initializes random number generators for logical space operations [0.0, 1.0).
Definition setup.c:3342
PetscBool RuntimeWalltimeGuardParsePositiveSeconds(const char *text, PetscReal *seconds_out)
Parse a positive floating-point seconds value from runtime metadata.
Definition setup.c:18
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 PicurvDestroyMinimalContexts(SimCtx **simCtx_ptr, UserCtx **user_ptr)
Destroys minimal SimCtx/UserCtx fixtures and all owned PETSc objects.
PetscRandom BrownianMotionRNG
Definition variables.h:810
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestSetupLifecycleCleanupAcrossInitializationStates()

static PetscErrorCode TestSetupLifecycleCleanupAcrossInitializationStates ( void  )
static

Tests cleanup after partial and fuller setup states without requiring unsupported double-finalization behavior.

Definition at line 368 of file test_setup_lifecycle.c.

369{
370 SimCtx *context_only = NULL;
371 SimCtx *grid_only = NULL;
372 char context_tmpdir[PETSC_MAX_PATH_LEN];
373 char grid_tmpdir[PETSC_MAX_PATH_LEN];
374
375 PetscFunctionBeginUser;
376 PetscCall(BuildContextOnly(&context_only, context_tmpdir, sizeof(context_tmpdir)));
377 PetscCall(PicurvAssertBool((PetscBool)(context_only != NULL), "CreateSimulationContext should allocate the top-level SimCtx"));
378 PetscCall(PicurvAssertIntEqual(1, context_only->block_number, "CreateSimulationContext should parse the configured block count"));
380 "deprecated RK4 selector should normalize to the Jameson solver enum"));
382 "deprecated RK4 residual-noise option should populate the Jameson control"));
383 PetscCall(PicurvAssertRealNear(1.0e-8, context_only->mom_resid_atol, 1.0e-12,
384 "momentum absolute residual tolerance should be parsed"));
385 PetscCall(PicurvAssertRealNear(1.0e-3, context_only->mom_resid_rtol, 1.0e-12,
386 "momentum relative residual tolerance should be parsed"));
387 PetscCall(PicurvAssertBool(context_only->mom_nk_monitor_history,
388 "Newton structured history monitor should be parsed"));
389 PetscCall(PetscOptionsClear(NULL));
390 PetscCall(PicurvRemoveTempDir(context_tmpdir));
391 PetscCall(FreeLifecycleContext(&context_only));
392
393 PetscCall(BuildContextOnly(&grid_only, grid_tmpdir, sizeof(grid_tmpdir)));
394 PetscCall(SetupSimulationEnvironment(grid_only));
395 PetscCall(SetupGridAndSolvers(grid_only));
396 PetscCall(PicurvAssertBool((PetscBool)(grid_only->usermg.mgctx[grid_only->usermg.mglevels - 1].user->Ucont != NULL),
397 "SetupGridAndSolvers should allocate baseline Eulerian vectors"));
398 PetscCall(PicurvRemoveTempDir(grid_tmpdir));
399 PetscCall(FreeLifecycleContext(&grid_only));
400 PetscFunctionReturn(0);
401}
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
static PetscErrorCode BuildContextOnly(SimCtx **simCtx_out, char *tmpdir, size_t tmpdir_len)
Builds only the top-level simulation context used by partial-initialization cleanup tests.
PetscBool mom_nk_monitor_history
Definition variables.h:740
PetscInt block_number
Definition variables.h:768
@ MOMENTUM_SOLVER_DUALTIME_PICARD_JAMESON_RK
Definition variables.h:534
PetscReal mom_dt_jameson_residual_norm_noise_allowance_factor
Definition variables.h:735
PetscReal mom_resid_rtol
Definition variables.h:726
PetscReal mom_resid_atol
Definition variables.h:726
MomentumSolverType mom_solver_type
Definition variables.h:724
Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char **  argv 
)

Runs the unit-setup PETSc test binary.

Definition at line 406 of file test_setup_lifecycle.c.

407{
408 PetscErrorCode ierr;
409 const PicurvTestCase cases[] = {
410 {"setup-lifecycle-core-solver-setup", TestSetupLifecycleCoreSolverSetup},
411 {"setup-lifecycle-particle-initialization", TestSetupLifecycleParticleInitialization},
412 {"setup-lifecycle-scatter-metrics-step-zero", TestSetupLifecycleScatterMetricsAtStepZero},
413 {"setup-lifecycle-random-generators-and-cleanup", TestSetupLifecycleRandomGeneratorsAndCleanup},
414 {"setup-lifecycle-cleanup-across-initialization-states", TestSetupLifecycleCleanupAcrossInitializationStates},
415 {"shared-runtime-fixture-contracts", TestSharedRuntimeFixtureContracts},
416 };
417
418 ierr = PetscInitialize(&argc, &argv, NULL, "PICurv setup lifecycle tests");
419 if (ierr) {
420 return (int)ierr;
421 }
422
423 ierr = PicurvRunTests("unit-setup", cases, sizeof(cases) / sizeof(cases[0]));
424 if (ierr) {
425 PetscFinalize();
426 return (int)ierr;
427 }
428
429 ierr = PetscFinalize();
430 return (int)ierr;
431}
static PetscErrorCode TestSetupLifecycleScatterMetricsAtStepZero(void)
Tests that step-zero scalar verification emits scatter_metrics.csv during initialized setup.
static PetscErrorCode TestSetupLifecycleRandomGeneratorsAndCleanup(void)
Tests standalone RNG initialization helpers and minimal-context cleanup.
static PetscErrorCode TestSetupLifecycleParticleInitialization(void)
Tests particle-swarm initialization and deterministic settlement on a tiny fully initialized case.
static PetscErrorCode TestSetupLifecycleCoreSolverSetup(void)
Tests the core setup lifecycle through environment, grid, BC, rank-info, and Eulerian-state initializ...
static PetscErrorCode TestSharedRuntimeFixtureContracts(void)
Tests that the shared richer runtime fixture mirrors normalized production setup contracts.
static PetscErrorCode TestSetupLifecycleCleanupAcrossInitializationStates(void)
Tests cleanup after partial and fuller setup states without requiring unsupported double-finalization...
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.
Named test case descriptor consumed by PicurvRunTests.
Here is the call graph for this function: