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

C unit tests for I/O helpers, parsers, and startup-banner output. More...

#include "test_support.h"
#include "io.h"
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
Include dependency graph for test_io.c:

Go to the source code of this file.

Functions

static PetscErrorCode TestShouldWriteDataOutput (void)
 Tests cadence-based Eulerian output triggering.
 
static PetscErrorCode TestVerifyPathExistence (void)
 Tests filesystem existence checks for files and directories.
 
static PetscErrorCode TestWriteAndReadSimulationFields (void)
 Tests writing and reloading core Eulerian field vectors.
 
static PetscErrorCode TestParsePostProcessingSettings (void)
 Tests parsing of post-processing control settings from a file.
 
static PetscErrorCode TestTrimWhitespace (void)
 Tests trimming of leading and trailing whitespace.
 
static PetscErrorCode TestBoundaryConditionStringParsers (void)
 Tests boundary-condition string parsers for face, type, and handler names.
 
static PetscErrorCode TestValidateBCHandlerForBCType (void)
 Tests validation of boundary-type and handler compatibility.
 
static PetscErrorCode TestParseScalingInformation (void)
 Tests scaling-reference parsing and derived pressure scaling.
 
static PetscErrorCode CaptureBannerOutput (SimCtx *simCtx, char *captured, size_t captured_len)
 Captures the startup banner into a temporary file-backed buffer.
 
static PetscErrorCode AssertCapturedContains (const char *captured, const char *needle, const char *message)
 Asserts that captured banner output contains one expected substring.
 
static PetscErrorCode AssertCapturedOmits (const char *captured, const char *needle, const char *message)
 Asserts that captured banner output omits one forbidden substring.
 
static PetscErrorCode TestDisplayBannerTracksConditionalStartupFields (void)
 Tests conditional startup-banner fields across particle and analytical cases.
 
int main (int argc, char **argv)
 Runs the unit-io PETSc test binary.
 

Detailed Description

C unit tests for I/O helpers, parsers, and startup-banner output.

Definition in file test_io.c.

Function Documentation

◆ TestShouldWriteDataOutput()

static PetscErrorCode TestShouldWriteDataOutput ( void  )
static

Tests cadence-based Eulerian output triggering.

Definition at line 18 of file test_io.c.

19{
20 SimCtx simCtx;
21
22 PetscFunctionBeginUser;
23 PetscCall(PetscMemzero(&simCtx, sizeof(simCtx)));
24 simCtx.tiout = 5;
25
26 PetscCall(PicurvAssertBool((PetscBool)!ShouldWriteDataOutput(NULL, 5), "NULL SimCtx should never request output"));
27 PetscCall(PicurvAssertBool((PetscBool)!ShouldWriteDataOutput(&simCtx, 4), "non-cadence step should not trigger output"));
28 PetscCall(PicurvAssertBool(ShouldWriteDataOutput(&simCtx, 10), "cadence-aligned step should trigger output"));
29 PetscFunctionReturn(0);
30}
PetscBool ShouldWriteDataOutput(const SimCtx *simCtx, PetscInt completed_step)
Returns whether full field/restart output should be written for the.
Definition io.c:70
PetscErrorCode PicurvAssertBool(PetscBool value, const char *context)
Asserts that one boolean condition is true.
PetscInt tiout
Definition variables.h:663
The master context for the entire simulation.
Definition variables.h:651
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestVerifyPathExistence()

static PetscErrorCode TestVerifyPathExistence ( void  )
static

Tests filesystem existence checks for files and directories.

Definition at line 35 of file test_io.c.

36{
37 char tmpdir[PETSC_MAX_PATH_LEN];
38 char filepath[PETSC_MAX_PATH_LEN];
39 FILE *file = NULL;
40 PetscBool exists = PETSC_FALSE;
41
42 PetscFunctionBeginUser;
43 PetscCall(PicurvMakeTempDir(tmpdir, sizeof(tmpdir)));
44 PetscCall(PetscSNPrintf(filepath, sizeof(filepath), "%s/sample.txt", tmpdir));
45
46 file = fopen(filepath, "w");
47 PetscCheck(file != NULL, PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN, "Failed to create temp file '%s'.", filepath);
48 fputs("picurv\n", file);
49 fclose(file);
50
51 PetscCall(VerifyPathExistence(tmpdir, PETSC_TRUE, PETSC_FALSE, "temp directory", &exists));
52 PetscCall(PicurvAssertBool(exists, "VerifyPathExistence should find the temp directory"));
53
54 PetscCall(VerifyPathExistence(filepath, PETSC_FALSE, PETSC_FALSE, "temp file", &exists));
55 PetscCall(PicurvAssertBool(exists, "VerifyPathExistence should find the temp file"));
56 PetscCall(PicurvRemoveTempDir(tmpdir));
57 PetscFunctionReturn(0);
58}
PetscErrorCode VerifyPathExistence(const char *path, PetscBool is_dir, PetscBool is_optional, const char *description, PetscBool *exists)
A parallel-safe helper to verify the existence of a generic file or directory path.
Definition io.c:741
PetscErrorCode PicurvMakeTempDir(char *path, size_t path_len)
Creates a unique temporary directory for one test case.
PetscErrorCode PicurvRemoveTempDir(const char *path)
Recursively removes a temporary directory created by PicurvMakeTempDir.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestWriteAndReadSimulationFields()

static PetscErrorCode TestWriteAndReadSimulationFields ( void  )
static

Tests writing and reloading core Eulerian field vectors.

Definition at line 63 of file test_io.c.

64{
65 SimCtx *simCtx = NULL;
66 UserCtx *user = NULL;
67 char tmpdir[PETSC_MAX_PATH_LEN];
68 char euler_dir[PETSC_MAX_PATH_LEN];
69
70 PetscFunctionBeginUser;
71 PetscCall(PicurvCreateMinimalContexts(&simCtx, &user, 4, 4, 4));
72 PetscCall(PicurvMakeTempDir(tmpdir, sizeof(tmpdir)));
73 PetscCall(PetscSNPrintf(euler_dir, sizeof(euler_dir), "%s/%s", tmpdir, simCtx->euler_subdir));
74 PetscCall(PicurvEnsureDir(euler_dir));
75
76 PetscCall(PetscStrncpy(simCtx->output_dir, tmpdir, sizeof(simCtx->output_dir)));
77 PetscCall(PetscStrncpy(simCtx->restart_dir, tmpdir, sizeof(simCtx->restart_dir)));
78 PetscCall(VecSet(user->P, 4.5));
79 PetscCall(VecSet(user->Nvert, 0.0));
80 PetscCall(VecSet(user->Ucat, 2.0));
81 PetscCall(VecSet(user->Ucont, 3.0));
82 PetscCall(PicurvPopulateIdentityMetrics(user));
83
84 PetscCall(WriteSimulationFields(user));
85 PetscCall(VecZeroEntries(user->P));
86 PetscCall(VecZeroEntries(user->Ucat));
87 PetscCall(VecZeroEntries(user->Ucont));
88
89 PetscCall(ReadSimulationFields(user, simCtx->step));
90 PetscCall(PicurvAssertVecConstant(user->P, 4.5, 1.0e-12, "ReadSimulationFields should restore P"));
91 PetscCall(PicurvAssertVecConstant(user->Ucat, 2.0, 1.0e-12, "ReadSimulationFields should restore Ucat"));
92 PetscCall(PicurvAssertVecConstant(user->Ucont, 3.0, 1.0e-12, "ReadSimulationFields should restore Ucont"));
93
94 PetscCall(PicurvRemoveTempDir(tmpdir));
95 PetscCall(PicurvDestroyMinimalContexts(&simCtx, &user));
96 PetscFunctionReturn(0);
97}
PetscErrorCode ReadSimulationFields(UserCtx *user, PetscInt ti)
Reads binary field data for velocity, pressure, and other required vectors.
Definition io.c:1129
PetscErrorCode WriteSimulationFields(UserCtx *user)
Writes simulation fields to files.
Definition io.c:1571
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 PicurvDestroyMinimalContexts(SimCtx **simCtx_ptr, UserCtx **user_ptr)
Destroys minimal SimCtx/UserCtx fixtures and all owned PETSc objects.
PetscErrorCode PicurvAssertVecConstant(Vec vec, PetscScalar expected, PetscReal tol, const char *context)
Asserts that a PETSc vector is spatially constant within tolerance.
PetscErrorCode PicurvPopulateIdentityMetrics(UserCtx *user)
Populates identity metric vectors on the minimal grid fixture.
char euler_subdir[PETSC_MAX_PATH_LEN]
Definition variables.h:674
char output_dir[PETSC_MAX_PATH_LEN]
Definition variables.h:673
Vec Ucont
Definition variables.h:856
Vec Ucat
Definition variables.h:856
PetscInt step
Definition variables.h:659
Vec Nvert
Definition variables.h:856
char restart_dir[PETSC_MAX_PATH_LEN]
Definition variables.h:672
User-defined context containing data specific to a single computational grid level.
Definition variables.h:830
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestParsePostProcessingSettings()

static PetscErrorCode TestParsePostProcessingSettings ( void  )
static

Tests parsing of post-processing control settings from a file.

Definition at line 102 of file test_io.c.

103{
104 SimCtx *simCtx = NULL;
105 UserCtx *user = NULL;
106 char tmpdir[PETSC_MAX_PATH_LEN];
107 char cfg_path[PETSC_MAX_PATH_LEN];
108 FILE *file = NULL;
109
110 PetscFunctionBeginUser;
111 PetscCall(PicurvCreateMinimalContexts(&simCtx, &user, 4, 4, 4));
112 PetscCall(PetscCalloc1(1, &simCtx->pps));
113 PetscCall(PicurvMakeTempDir(tmpdir, sizeof(tmpdir)));
114 PetscCall(PetscSNPrintf(cfg_path, sizeof(cfg_path), "%s/post.run", tmpdir));
115 PetscCall(PetscStrncpy(simCtx->PostprocessingControlFile, cfg_path, sizeof(simCtx->PostprocessingControlFile)));
116
117 file = fopen(cfg_path, "w");
118 PetscCheck(file != NULL, PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN, "Failed to create temp config file '%s'.", cfg_path);
119 fputs("startTime = 2\n", file);
120 fputs("endTime = 6\n", file);
121 fputs("timeStep = 2\n", file);
122 fputs("output_particles = true\n", file);
123 fputs("output_prefix = SmokeField\n", file);
124 fclose(file);
125
126 PetscCall(ParsePostProcessingSettings(simCtx));
127 PetscCall(PicurvAssertIntEqual(2, simCtx->pps->startTime, "ParsePostProcessingSettings should parse startTime"));
128 PetscCall(PicurvAssertIntEqual(6, simCtx->pps->endTime, "ParsePostProcessingSettings should parse endTime"));
129 PetscCall(PicurvAssertIntEqual(2, simCtx->pps->timeStep, "ParsePostProcessingSettings should parse timeStep"));
130 PetscCall(PicurvAssertBool(simCtx->pps->outputParticles, "ParsePostProcessingSettings should parse output_particles"));
131 PetscCall(PicurvAssertBool((PetscBool)(strcmp(simCtx->pps->output_prefix, "SmokeField") == 0),
132 "ParsePostProcessingSettings should parse output_prefix"));
133
134 PetscCall(PicurvRemoveTempDir(tmpdir));
135 PetscCall(PicurvDestroyMinimalContexts(&simCtx, &user));
136 PetscFunctionReturn(0);
137}
PetscErrorCode ParsePostProcessingSettings(SimCtx *simCtx)
Initializes post-processing settings from a config file and command-line overrides.
Definition io.c:2222
PetscErrorCode PicurvAssertIntEqual(PetscInt expected, PetscInt actual, const char *context)
Asserts that two integer values are equal.
char output_prefix[256]
Definition variables.h:575
PetscInt timeStep
Definition variables.h:568
PetscBool outputParticles
Definition variables.h:569
PostProcessParams * pps
Definition variables.h:817
PetscInt startTime
Definition variables.h:566
char PostprocessingControlFile[PETSC_MAX_PATH_LEN]
Definition variables.h:816
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestTrimWhitespace()

static PetscErrorCode TestTrimWhitespace ( void  )
static

Tests trimming of leading and trailing whitespace.

Definition at line 142 of file test_io.c.

143{
144 char value_a[] = " inlet_value ";
145 char value_b[] = " ";
146
147 PetscFunctionBeginUser;
148 TrimWhitespace(value_a);
149 PetscCall(PicurvAssertBool((PetscBool)(strcmp(value_a, "inlet_value") == 0),
150 "TrimWhitespace should remove leading and trailing whitespace"));
151
152 TrimWhitespace(value_b);
153 PetscCall(PicurvAssertBool((PetscBool)(strcmp(value_b, "") == 0),
154 "TrimWhitespace should reduce all-whitespace strings to empty"));
155 PetscFunctionReturn(0);
156}
void TrimWhitespace(char *str)
Helper function to trim leading/trailing whitespace from a string.
Definition io.c:38
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestBoundaryConditionStringParsers()

static PetscErrorCode TestBoundaryConditionStringParsers ( void  )
static

Tests boundary-condition string parsers for face, type, and handler names.

Definition at line 161 of file test_io.c.

162{
163 BCFace face = BC_FACE_NEG_X;
164 BCType type = WALL;
166
167 PetscFunctionBeginUser;
168 PetscCall(StringToBCFace("+Zeta", &face));
169 PetscCall(PicurvAssertIntEqual(BC_FACE_POS_Z, face, "StringToBCFace should parse +Zeta"));
170
171 PetscCall(StringToBCType("periodic", &type));
172 PetscCall(PicurvAssertIntEqual(PERIODIC, type, "StringToBCType should parse PERIODIC case-insensitively"));
173
174 PetscCall(StringToBCHandlerType("constant_flux", &handler));
176 "StringToBCHandlerType should parse constant_flux"));
177 PetscCall(StringToBCHandlerType("prescribed_flow", &handler));
179 "StringToBCHandlerType should parse prescribed_flow"));
180 PetscFunctionReturn(0);
181}
PetscErrorCode StringToBCHandlerType(const char *str, BCHandlerType *handler_out)
Converts a BC handler token (implementation strategy) to BCHandlerType.
Definition io.c:347
PetscErrorCode StringToBCFace(const char *str, BCFace *face_out)
Converts a face-token string (e.g., "-Xi", "+Eta") to the internal BCFace enum.
Definition io.c:317
PetscErrorCode StringToBCType(const char *str, BCType *type_out)
Converts a mathematical BC type string (e.g., "PERIODIC", "WALL") to BCType.
Definition io.c:332
BCType
Defines the general mathematical/physical Category of a boundary.
Definition variables.h:251
@ PERIODIC
Definition variables.h:260
@ WALL
Definition variables.h:254
BCHandlerType
Defines the specific computational "strategy" for a boundary handler.
Definition variables.h:271
@ BC_HANDLER_PERIODIC_DRIVEN_CONSTANT_FLUX
Definition variables.h:286
@ BC_HANDLER_INLET_PROFILE_FROM_FILE
Definition variables.h:278
@ BC_HANDLER_WALL_NOSLIP
Definition variables.h:273
BCFace
Identifies the six logical faces of a structured computational block.
Definition variables.h:244
@ BC_FACE_NEG_X
Definition variables.h:245
@ BC_FACE_POS_Z
Definition variables.h:247
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestValidateBCHandlerForBCType()

static PetscErrorCode TestValidateBCHandlerForBCType ( void  )
static

Tests validation of boundary-type and handler compatibility.

Definition at line 186 of file test_io.c.

187{
188 PetscFunctionBeginUser;
190 "WALL + noslip should be a valid combination"));
192 "PERIODIC + geometric should be a valid combination"));
194 "INLET + prescribed_flow should be a valid combination"));
196 "INLET + noslip should be rejected"));
197 PetscFunctionReturn(0);
198}
PetscErrorCode ValidateBCHandlerForBCType(BCType type, BCHandlerType handler)
Validates that a selected handler is compatible with a mathematical BC type.
Definition io.c:365
@ INLET
Definition variables.h:258
@ BC_HANDLER_PERIODIC_GEOMETRIC
Definition variables.h:284
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestParseScalingInformation()

static PetscErrorCode TestParseScalingInformation ( void  )
static

Tests scaling-reference parsing and derived pressure scaling.

Definition at line 203 of file test_io.c.

204{
205 SimCtx simCtx;
206
207 PetscFunctionBeginUser;
208 PetscCall(PetscMemzero(&simCtx, sizeof(simCtx)));
209
210 PetscCall(PetscOptionsClearValue(NULL, "-scaling_L_ref"));
211 PetscCall(PetscOptionsClearValue(NULL, "-scaling_U_ref"));
212 PetscCall(PetscOptionsClearValue(NULL, "-scaling_rho_ref"));
213
214 PetscCall(ParseScalingInformation(&simCtx));
215 PetscCall(PicurvAssertRealNear(1.0, simCtx.scaling.L_ref, 1.0e-12, "Default scaling_L_ref should be 1.0"));
216 PetscCall(PicurvAssertRealNear(1.0, simCtx.scaling.U_ref, 1.0e-12, "Default scaling_U_ref should be 1.0"));
217 PetscCall(PicurvAssertRealNear(1.0, simCtx.scaling.rho_ref, 1.0e-12, "Default scaling_rho_ref should be 1.0"));
218 PetscCall(PicurvAssertRealNear(1.0, simCtx.scaling.P_ref, 1.0e-12, "Default scaling_P_ref should be 1.0"));
219
220 PetscCall(PetscOptionsSetValue(NULL, "-scaling_L_ref", "2.5"));
221 PetscCall(PetscOptionsSetValue(NULL, "-scaling_U_ref", "4.0"));
222 PetscCall(PetscOptionsSetValue(NULL, "-scaling_rho_ref", "1.2"));
223
224 PetscCall(ParseScalingInformation(&simCtx));
225 PetscCall(PicurvAssertRealNear(2.5, simCtx.scaling.L_ref, 1.0e-12, "scaling_L_ref should honor options"));
226 PetscCall(PicurvAssertRealNear(4.0, simCtx.scaling.U_ref, 1.0e-12, "scaling_U_ref should honor options"));
227 PetscCall(PicurvAssertRealNear(1.2, simCtx.scaling.rho_ref, 1.0e-12, "scaling_rho_ref should honor options"));
228 PetscCall(PicurvAssertRealNear(19.2, simCtx.scaling.P_ref, 1.0e-12, "scaling_P_ref should be rho_ref*U_ref^2"));
229
230 PetscCall(PetscOptionsClearValue(NULL, "-scaling_L_ref"));
231 PetscCall(PetscOptionsClearValue(NULL, "-scaling_U_ref"));
232 PetscCall(PetscOptionsClearValue(NULL, "-scaling_rho_ref"));
233 PetscFunctionReturn(0);
234}
PetscErrorCode ParseScalingInformation(SimCtx *simCtx)
Parses physical scaling parameters from command-line options.
Definition io.c:2370
PetscErrorCode PicurvAssertRealNear(PetscReal expected, PetscReal actual, PetscReal tol, const char *context)
Asserts that two real values agree within tolerance.
PetscReal L_ref
Definition variables.h:633
ScalingCtx scaling
Definition variables.h:721
PetscReal P_ref
Definition variables.h:636
PetscReal rho_ref
Definition variables.h:635
PetscReal U_ref
Definition variables.h:634
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CaptureBannerOutput()

static PetscErrorCode CaptureBannerOutput ( SimCtx simCtx,
char *  captured,
size_t  captured_len 
)
static

Captures the startup banner into a temporary file-backed buffer.

Definition at line 238 of file test_io.c.

239{
240 char tmpdir[PETSC_MAX_PATH_LEN];
241 char capture_path[PETSC_MAX_PATH_LEN];
242 FILE *capture_file = NULL;
243 int saved_stdout = -1;
244 int capture_fd = -1;
245 size_t bytes_read = 0;
246 PetscErrorCode ierr;
247
248 PetscFunctionBeginUser;
249 PetscCheck(simCtx != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "SimCtx cannot be NULL.");
250 PetscCheck(captured != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "Capture buffer cannot be NULL.");
251 PetscCheck(captured_len > 0, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "Capture buffer must be non-empty.");
252
253 PetscCall(PicurvMakeTempDir(tmpdir, sizeof(tmpdir)));
254 PetscCall(PetscSNPrintf(capture_path, sizeof(capture_path), "%s/banner.log", tmpdir));
255
256 fflush(stdout);
257 saved_stdout = dup(STDOUT_FILENO);
258 PetscCheck(saved_stdout >= 0, PETSC_COMM_SELF, PETSC_ERR_SYS, "dup(STDOUT_FILENO) failed.");
259 capture_fd = open(capture_path, O_CREAT | O_TRUNC | O_WRONLY, 0600);
260 PetscCheck(capture_fd >= 0, PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN, "Failed to open capture file '%s'.", capture_path);
261 PetscCheck(dup2(capture_fd, STDOUT_FILENO) >= 0, PETSC_COMM_SELF, PETSC_ERR_SYS, "dup2() failed while redirecting stdout.");
262 close(capture_fd);
263 capture_fd = -1;
264
265 ierr = DisplayBanner(simCtx);
266 fflush(stdout);
267 PetscCheck(dup2(saved_stdout, STDOUT_FILENO) >= 0, PETSC_COMM_SELF, PETSC_ERR_SYS, "dup2() failed while restoring stdout.");
268 close(saved_stdout);
269 saved_stdout = -1;
270 PetscCall(ierr);
271
272 capture_file = fopen(capture_path, "r");
273 PetscCheck(capture_file != NULL, PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN, "Failed to read capture file '%s'.", capture_path);
274 bytes_read = fread(captured, 1, captured_len - 1, capture_file);
275 captured[bytes_read] = '\0';
276 fclose(capture_file);
277 PetscCall(PicurvRemoveTempDir(tmpdir));
278 PetscFunctionReturn(0);
279}
PetscErrorCode DisplayBanner(SimCtx *simCtx)
Displays a structured banner summarizing the simulation configuration.
Definition io.c:2034
Here is the call graph for this function:
Here is the caller graph for this function:

◆ AssertCapturedContains()

static PetscErrorCode AssertCapturedContains ( const char *  captured,
const char *  needle,
const char *  message 
)
static

Asserts that captured banner output contains one expected substring.

Definition at line 283 of file test_io.c.

284{
285 PetscFunctionBeginUser;
286 PetscCall(PicurvAssertBool((PetscBool)(strstr(captured, needle) != NULL), message));
287 PetscFunctionReturn(0);
288}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ AssertCapturedOmits()

static PetscErrorCode AssertCapturedOmits ( const char *  captured,
const char *  needle,
const char *  message 
)
static

Asserts that captured banner output omits one forbidden substring.

Definition at line 292 of file test_io.c.

293{
294 PetscFunctionBeginUser;
295 PetscCall(PicurvAssertBool((PetscBool)(strstr(captured, needle) == NULL), message));
296 PetscFunctionReturn(0);
297}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestDisplayBannerTracksConditionalStartupFields()

static PetscErrorCode TestDisplayBannerTracksConditionalStartupFields ( void  )
static

Tests conditional startup-banner fields across particle and analytical cases.

Definition at line 302 of file test_io.c.

303{
304 SimCtx *simCtx = NULL;
305 UserCtx *user = NULL;
306 char captured[16384];
307
308 PetscFunctionBeginUser;
309 PetscCall(PicurvCreateMinimalContexts(&simCtx, &user, 4, 4, 4));
310 simCtx->OnlySetup = PETSC_FALSE;
311 simCtx->StepsToRun = 5;
312 simCtx->immersed = PETSC_FALSE;
313 PetscCall(PetscStrncpy(simCtx->eulerianSource, "solve", sizeof(simCtx->eulerianSource)));
314 simCtx->particleConsoleOutputFreq = 7;
315 simCtx->LoggingFrequency = 4;
317
318 PetscCall(CaptureBannerOutput(simCtx, captured, sizeof(captured)));
319 PetscCall(AssertCapturedContains(captured, "Run Mode : Full Simulation",
320 "DisplayBanner should include the run mode"));
321 PetscCall(AssertCapturedContains(captured, "Field/Restart Cadence : every 2 step(s)",
322 "DisplayBanner should include field/restart cadence"));
323 PetscCall(AssertCapturedContains(captured, "Immersed Boundary : DISABLED",
324 "DisplayBanner should include immersed-boundary state"));
325 PetscCall(AssertCapturedContains(captured, "Number of Particles : 0",
326 "DisplayBanner should include the total particle count"));
327 PetscCall(AssertCapturedOmits(captured, "Particle Console Cadence",
328 "DisplayBanner should omit particle console cadence when no particles are configured"));
329 PetscCall(AssertCapturedOmits(captured, "Particle Log Row Sampling",
330 "DisplayBanner should omit particle row sampling when no particles are configured"));
331 PetscCall(AssertCapturedOmits(captured, "Particle Restart Mode",
332 "DisplayBanner should omit particle restart mode when no particles are configured"));
333 PetscCall(AssertCapturedOmits(captured, "Particle Initialization Mode",
334 "DisplayBanner should omit particle initialization mode when no particles are configured"));
335 PetscCall(AssertCapturedOmits(captured, "Interpolation Method",
336 "DisplayBanner should omit interpolation method when no particles are configured"));
337
338 simCtx->StartStep = 3;
339 simCtx->np = 8;
340 simCtx->particleConsoleOutputFreq = 0;
341 simCtx->LoggingFrequency = 4;
342 PetscCall(PetscStrncpy(simCtx->particleRestartMode, "load", sizeof(simCtx->particleRestartMode)));
343 PetscCall(CaptureBannerOutput(simCtx, captured, sizeof(captured)));
344 PetscCall(AssertCapturedContains(captured, "Number of Particles : 8",
345 "DisplayBanner should include the active particle count"));
346 PetscCall(AssertCapturedContains(captured, "Particle Console Cadence : DISABLED",
347 "DisplayBanner should show disabled particle console cadence when particles are configured"));
348 PetscCall(AssertCapturedContains(captured, "Particle Log Row Sampling : every 4 particle(s)",
349 "DisplayBanner should include particle row sampling when particles are configured"));
350 PetscCall(AssertCapturedContains(captured, "Particle Restart Mode : load",
351 "DisplayBanner should include particle restart mode for restarted particle runs"));
352 PetscCall(AssertCapturedContains(captured, "Particle Initialization Mode: Point Source",
353 "DisplayBanner should include particle initialization mode when particles are configured"));
354 PetscCall(AssertCapturedContains(captured, "Interpolation Method : Trilinear (direct cell-center)",
355 "DisplayBanner should include default interpolation method when particles are configured"));
356 PetscCall(AssertCapturedOmits(captured, "Particles Initialized At",
357 "DisplayBanner should omit inlet-face placement details for point-source particle initialization"));
358
359 simCtx->StartStep = 0;
360 simCtx->particleConsoleOutputFreq = 6;
362 user->inletFaceDefined = PETSC_TRUE;
363 user->identifiedInletBCFace = (BCFace)0;
364 PetscCall(PetscStrncpy(simCtx->eulerianSource, "analytical", sizeof(simCtx->eulerianSource)));
365 PetscCall(PetscStrncpy(simCtx->AnalyticalSolutionType, "ZERO_FLOW", sizeof(simCtx->AnalyticalSolutionType)));
366 PetscCall(CaptureBannerOutput(simCtx, captured, sizeof(captured)));
367 PetscCall(AssertCapturedContains(captured, "Analytical Solution Type : ZERO_FLOW",
368 "DisplayBanner should include the analytical solution type for analytical runs"));
369 PetscCall(AssertCapturedContains(captured, "Particle Console Cadence : every 6 step(s)",
370 "DisplayBanner should include active particle console cadence when particles are configured"));
371 PetscCall(AssertCapturedContains(captured, "Particle Initialization Mode: Surface: Random",
372 "DisplayBanner should include particle initialization mode for analytical particle runs"));
373 PetscCall(AssertCapturedContains(captured, "Particles Initialized At",
374 "DisplayBanner should include inlet-face placement details for surface particle initialization"));
375
376 PetscCall(PicurvDestroyMinimalContexts(&simCtx, &user));
377 PetscFunctionReturn(0);
378}
static PetscErrorCode AssertCapturedOmits(const char *captured, const char *needle, const char *message)
Asserts that captured banner output omits one forbidden substring.
Definition test_io.c:292
static PetscErrorCode AssertCapturedContains(const char *captured, const char *needle, const char *message)
Asserts that captured banner output contains one expected substring.
Definition test_io.c:283
static PetscErrorCode CaptureBannerOutput(SimCtx *simCtx, char *captured, size_t captured_len)
Captures the startup banner into a temporary file-backed buffer.
Definition test_io.c:238
PetscBool inletFaceDefined
Definition variables.h:849
BCFace identifiedInletBCFace
Definition variables.h:850
@ PARTICLE_INIT_SURFACE_RANDOM
Random placement on the inlet face.
Definition variables.h:517
@ PARTICLE_INIT_POINT_SOURCE
All particles at a fixed (psrc_x,psrc_y,psrc_z) — for validation.
Definition variables.h:519
PetscInt StepsToRun
Definition variables.h:662
PetscInt np
Definition variables.h:753
PetscInt StartStep
Definition variables.h:661
PetscBool OnlySetup
Definition variables.h:667
char particleRestartMode[16]
Definition variables.h:759
char eulerianSource[PETSC_MAX_PATH_LEN]
Definition variables.h:671
ParticleInitializationType ParticleInitialization
Definition variables.h:757
char AnalyticalSolutionType[PETSC_MAX_PATH_LEN]
Definition variables.h:684
PetscInt particleConsoleOutputFreq
Definition variables.h:664
PetscInt immersed
Definition variables.h:681
PetscInt LoggingFrequency
Definition variables.h:783
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-io PETSc test binary.

Definition at line 383 of file test_io.c.

384{
385 PetscErrorCode ierr;
386 const PicurvTestCase cases[] = {
387 {"should-write-data-output", TestShouldWriteDataOutput},
388 {"verify-path-existence", TestVerifyPathExistence},
389 {"write-and-read-simulation-fields", TestWriteAndReadSimulationFields},
390 {"parse-post-processing-settings", TestParsePostProcessingSettings},
391 {"trim-whitespace", TestTrimWhitespace},
392 {"bc-string-parsers", TestBoundaryConditionStringParsers},
393 {"validate-bc-handler-for-type", TestValidateBCHandlerForBCType},
394 {"parse-scaling-information", TestParseScalingInformation},
395 {"display-banner-startup-summary", TestDisplayBannerTracksConditionalStartupFields},
396 };
397
398 ierr = PetscInitialize(&argc, &argv, NULL, "PICurv I/O tests");
399 if (ierr) {
400 return (int)ierr;
401 }
402
403 ierr = PicurvRunTests("unit-io", cases, sizeof(cases) / sizeof(cases[0]));
404 if (ierr) {
405 PetscFinalize();
406 return (int)ierr;
407 }
408
409 ierr = PetscFinalize();
410 return (int)ierr;
411}
static PetscErrorCode TestParseScalingInformation(void)
Tests scaling-reference parsing and derived pressure scaling.
Definition test_io.c:203
static PetscErrorCode TestValidateBCHandlerForBCType(void)
Tests validation of boundary-type and handler compatibility.
Definition test_io.c:186
static PetscErrorCode TestParsePostProcessingSettings(void)
Tests parsing of post-processing control settings from a file.
Definition test_io.c:102
static PetscErrorCode TestDisplayBannerTracksConditionalStartupFields(void)
Tests conditional startup-banner fields across particle and analytical cases.
Definition test_io.c:302
static PetscErrorCode TestVerifyPathExistence(void)
Tests filesystem existence checks for files and directories.
Definition test_io.c:35
static PetscErrorCode TestTrimWhitespace(void)
Tests trimming of leading and trailing whitespace.
Definition test_io.c:142
static PetscErrorCode TestShouldWriteDataOutput(void)
Tests cadence-based Eulerian output triggering.
Definition test_io.c:18
static PetscErrorCode TestBoundaryConditionStringParsers(void)
Tests boundary-condition string parsers for face, type, and handler names.
Definition test_io.c:161
static PetscErrorCode TestWriteAndReadSimulationFields(void)
Tests writing and reloading core Eulerian field vectors.
Definition test_io.c:63
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: