PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
Loading...
Searching...
No Matches
test_io.c
Go to the documentation of this file.
1/**
2 * @file test_io.c
3 * @brief C unit tests for I/O helpers, parsers, and startup-banner output.
4 */
5
6#include "test_support.h"
7
8#include "io.h"
9
10#include <fcntl.h>
11#include <stdio.h>
12#include <string.h>
13#include <unistd.h>
14/**
15 * @brief Tests cadence-based Eulerian output triggering.
16 */
17
18static PetscErrorCode TestShouldWriteDataOutput(void)
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}
31/**
32 * @brief Tests filesystem existence checks for files and directories.
33 */
34
35static PetscErrorCode TestVerifyPathExistence(void)
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}
59/**
60 * @brief Tests writing and reloading core Eulerian field vectors.
61 */
62
63static PetscErrorCode TestWriteAndReadSimulationFields(void)
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}
98/**
99 * @brief Tests parsing of post-processing control settings from a file.
100 */
101
102static PetscErrorCode TestParsePostProcessingSettings(void)
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}
138/**
139 * @brief Tests trimming of leading and trailing whitespace.
140 */
141
142static PetscErrorCode TestTrimWhitespace(void)
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}
157/**
158 * @brief Tests boundary-condition string parsers for face, type, and handler names.
159 */
160
161static PetscErrorCode TestBoundaryConditionStringParsers(void)
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 PetscFunctionReturn(0);
178}
179/**
180 * @brief Tests validation of boundary-type and handler compatibility.
181 */
182
183static PetscErrorCode TestValidateBCHandlerForBCType(void)
184{
185 PetscFunctionBeginUser;
187 "WALL + noslip should be a valid combination"));
189 "PERIODIC + geometric should be a valid combination"));
191 "INLET + noslip should be rejected"));
192 PetscFunctionReturn(0);
193}
194/**
195 * @brief Tests scaling-reference parsing and derived pressure scaling.
196 */
197
198static PetscErrorCode TestParseScalingInformation(void)
199{
200 SimCtx simCtx;
201
202 PetscFunctionBeginUser;
203 PetscCall(PetscMemzero(&simCtx, sizeof(simCtx)));
204
205 PetscCall(PetscOptionsClearValue(NULL, "-scaling_L_ref"));
206 PetscCall(PetscOptionsClearValue(NULL, "-scaling_U_ref"));
207 PetscCall(PetscOptionsClearValue(NULL, "-scaling_rho_ref"));
208
209 PetscCall(ParseScalingInformation(&simCtx));
210 PetscCall(PicurvAssertRealNear(1.0, simCtx.scaling.L_ref, 1.0e-12, "Default scaling_L_ref should be 1.0"));
211 PetscCall(PicurvAssertRealNear(1.0, simCtx.scaling.U_ref, 1.0e-12, "Default scaling_U_ref should be 1.0"));
212 PetscCall(PicurvAssertRealNear(1.0, simCtx.scaling.rho_ref, 1.0e-12, "Default scaling_rho_ref should be 1.0"));
213 PetscCall(PicurvAssertRealNear(1.0, simCtx.scaling.P_ref, 1.0e-12, "Default scaling_P_ref should be 1.0"));
214
215 PetscCall(PetscOptionsSetValue(NULL, "-scaling_L_ref", "2.5"));
216 PetscCall(PetscOptionsSetValue(NULL, "-scaling_U_ref", "4.0"));
217 PetscCall(PetscOptionsSetValue(NULL, "-scaling_rho_ref", "1.2"));
218
219 PetscCall(ParseScalingInformation(&simCtx));
220 PetscCall(PicurvAssertRealNear(2.5, simCtx.scaling.L_ref, 1.0e-12, "scaling_L_ref should honor options"));
221 PetscCall(PicurvAssertRealNear(4.0, simCtx.scaling.U_ref, 1.0e-12, "scaling_U_ref should honor options"));
222 PetscCall(PicurvAssertRealNear(1.2, simCtx.scaling.rho_ref, 1.0e-12, "scaling_rho_ref should honor options"));
223 PetscCall(PicurvAssertRealNear(19.2, simCtx.scaling.P_ref, 1.0e-12, "scaling_P_ref should be rho_ref*U_ref^2"));
224
225 PetscCall(PetscOptionsClearValue(NULL, "-scaling_L_ref"));
226 PetscCall(PetscOptionsClearValue(NULL, "-scaling_U_ref"));
227 PetscCall(PetscOptionsClearValue(NULL, "-scaling_rho_ref"));
228 PetscFunctionReturn(0);
229}
230/**
231 * @brief Captures the startup banner into a temporary file-backed buffer.
232 */
233static PetscErrorCode CaptureBannerOutput(SimCtx *simCtx, char *captured, size_t captured_len)
234{
235 char tmpdir[PETSC_MAX_PATH_LEN];
236 char capture_path[PETSC_MAX_PATH_LEN];
237 FILE *capture_file = NULL;
238 int saved_stdout = -1;
239 int capture_fd = -1;
240 size_t bytes_read = 0;
241 PetscErrorCode ierr;
242
243 PetscFunctionBeginUser;
244 PetscCheck(simCtx != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "SimCtx cannot be NULL.");
245 PetscCheck(captured != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "Capture buffer cannot be NULL.");
246 PetscCheck(captured_len > 0, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "Capture buffer must be non-empty.");
247
248 PetscCall(PicurvMakeTempDir(tmpdir, sizeof(tmpdir)));
249 PetscCall(PetscSNPrintf(capture_path, sizeof(capture_path), "%s/banner.log", tmpdir));
250
251 fflush(stdout);
252 saved_stdout = dup(STDOUT_FILENO);
253 PetscCheck(saved_stdout >= 0, PETSC_COMM_SELF, PETSC_ERR_SYS, "dup(STDOUT_FILENO) failed.");
254 capture_fd = open(capture_path, O_CREAT | O_TRUNC | O_WRONLY, 0600);
255 PetscCheck(capture_fd >= 0, PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN, "Failed to open capture file '%s'.", capture_path);
256 PetscCheck(dup2(capture_fd, STDOUT_FILENO) >= 0, PETSC_COMM_SELF, PETSC_ERR_SYS, "dup2() failed while redirecting stdout.");
257 close(capture_fd);
258 capture_fd = -1;
259
260 ierr = DisplayBanner(simCtx);
261 fflush(stdout);
262 PetscCheck(dup2(saved_stdout, STDOUT_FILENO) >= 0, PETSC_COMM_SELF, PETSC_ERR_SYS, "dup2() failed while restoring stdout.");
263 close(saved_stdout);
264 saved_stdout = -1;
265 PetscCall(ierr);
266
267 capture_file = fopen(capture_path, "r");
268 PetscCheck(capture_file != NULL, PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN, "Failed to read capture file '%s'.", capture_path);
269 bytes_read = fread(captured, 1, captured_len - 1, capture_file);
270 captured[bytes_read] = '\0';
271 fclose(capture_file);
272 PetscCall(PicurvRemoveTempDir(tmpdir));
273 PetscFunctionReturn(0);
274}
275/**
276 * @brief Asserts that captured banner output contains one expected substring.
277 */
278static PetscErrorCode AssertCapturedContains(const char *captured, const char *needle, const char *message)
279{
280 PetscFunctionBeginUser;
281 PetscCall(PicurvAssertBool((PetscBool)(strstr(captured, needle) != NULL), message));
282 PetscFunctionReturn(0);
283}
284/**
285 * @brief Asserts that captured banner output omits one forbidden substring.
286 */
287static PetscErrorCode AssertCapturedOmits(const char *captured, const char *needle, const char *message)
288{
289 PetscFunctionBeginUser;
290 PetscCall(PicurvAssertBool((PetscBool)(strstr(captured, needle) == NULL), message));
291 PetscFunctionReturn(0);
292}
293/**
294 * @brief Tests conditional startup-banner fields across particle and analytical cases.
295 */
296
298{
299 SimCtx *simCtx = NULL;
300 UserCtx *user = NULL;
301 char captured[16384];
302
303 PetscFunctionBeginUser;
304 PetscCall(PicurvCreateMinimalContexts(&simCtx, &user, 4, 4, 4));
305 simCtx->OnlySetup = PETSC_FALSE;
306 simCtx->StepsToRun = 5;
307 simCtx->immersed = PETSC_FALSE;
308 PetscCall(PetscStrncpy(simCtx->eulerianSource, "solve", sizeof(simCtx->eulerianSource)));
309 simCtx->particleConsoleOutputFreq = 7;
310 simCtx->LoggingFrequency = 4;
312
313 PetscCall(CaptureBannerOutput(simCtx, captured, sizeof(captured)));
314 PetscCall(AssertCapturedContains(captured, "Run Mode : Full Simulation",
315 "DisplayBanner should include the run mode"));
316 PetscCall(AssertCapturedContains(captured, "Field/Restart Cadence : every 2 step(s)",
317 "DisplayBanner should include field/restart cadence"));
318 PetscCall(AssertCapturedContains(captured, "Immersed Boundary : DISABLED",
319 "DisplayBanner should include immersed-boundary state"));
320 PetscCall(AssertCapturedContains(captured, "Number of Particles : 0",
321 "DisplayBanner should include the total particle count"));
322 PetscCall(AssertCapturedOmits(captured, "Particle Console Cadence",
323 "DisplayBanner should omit particle console cadence when no particles are configured"));
324 PetscCall(AssertCapturedOmits(captured, "Particle Log Row Sampling",
325 "DisplayBanner should omit particle row sampling when no particles are configured"));
326 PetscCall(AssertCapturedOmits(captured, "Particle Restart Mode",
327 "DisplayBanner should omit particle restart mode when no particles are configured"));
328 PetscCall(AssertCapturedOmits(captured, "Particle Initialization Mode",
329 "DisplayBanner should omit particle initialization mode when no particles are configured"));
330 PetscCall(AssertCapturedOmits(captured, "Interpolation Method",
331 "DisplayBanner should omit interpolation method when no particles are configured"));
332
333 simCtx->StartStep = 3;
334 simCtx->np = 8;
335 simCtx->particleConsoleOutputFreq = 0;
336 simCtx->LoggingFrequency = 4;
337 PetscCall(PetscStrncpy(simCtx->particleRestartMode, "load", sizeof(simCtx->particleRestartMode)));
338 PetscCall(CaptureBannerOutput(simCtx, captured, sizeof(captured)));
339 PetscCall(AssertCapturedContains(captured, "Number of Particles : 8",
340 "DisplayBanner should include the active particle count"));
341 PetscCall(AssertCapturedContains(captured, "Particle Console Cadence : DISABLED",
342 "DisplayBanner should show disabled particle console cadence when particles are configured"));
343 PetscCall(AssertCapturedContains(captured, "Particle Log Row Sampling : every 4 particle(s)",
344 "DisplayBanner should include particle row sampling when particles are configured"));
345 PetscCall(AssertCapturedContains(captured, "Particle Restart Mode : load",
346 "DisplayBanner should include particle restart mode for restarted particle runs"));
347 PetscCall(AssertCapturedContains(captured, "Particle Initialization Mode: Point Source",
348 "DisplayBanner should include particle initialization mode when particles are configured"));
349 PetscCall(AssertCapturedContains(captured, "Interpolation Method : Trilinear (direct cell-center)",
350 "DisplayBanner should include default interpolation method when particles are configured"));
351 PetscCall(AssertCapturedOmits(captured, "Particles Initialized At",
352 "DisplayBanner should omit inlet-face placement details for point-source particle initialization"));
353
354 simCtx->StartStep = 0;
355 simCtx->particleConsoleOutputFreq = 6;
357 user->inletFaceDefined = PETSC_TRUE;
358 user->identifiedInletBCFace = (BCFace)0;
359 PetscCall(PetscStrncpy(simCtx->eulerianSource, "analytical", sizeof(simCtx->eulerianSource)));
360 PetscCall(PetscStrncpy(simCtx->AnalyticalSolutionType, "ZERO_FLOW", sizeof(simCtx->AnalyticalSolutionType)));
361 PetscCall(CaptureBannerOutput(simCtx, captured, sizeof(captured)));
362 PetscCall(AssertCapturedContains(captured, "Analytical Solution Type : ZERO_FLOW",
363 "DisplayBanner should include the analytical solution type for analytical runs"));
364 PetscCall(AssertCapturedContains(captured, "Particle Console Cadence : every 6 step(s)",
365 "DisplayBanner should include active particle console cadence when particles are configured"));
366 PetscCall(AssertCapturedContains(captured, "Particle Initialization Mode: Surface: Random",
367 "DisplayBanner should include particle initialization mode for analytical particle runs"));
368 PetscCall(AssertCapturedContains(captured, "Particles Initialized At",
369 "DisplayBanner should include inlet-face placement details for surface particle initialization"));
370
371 PetscCall(PicurvDestroyMinimalContexts(&simCtx, &user));
372 PetscFunctionReturn(0);
373}
374/**
375 * @brief Runs the unit-io PETSc test binary.
376 */
377
378int main(int argc, char **argv)
379{
380 PetscErrorCode ierr;
381 const PicurvTestCase cases[] = {
382 {"should-write-data-output", TestShouldWriteDataOutput},
383 {"verify-path-existence", TestVerifyPathExistence},
384 {"write-and-read-simulation-fields", TestWriteAndReadSimulationFields},
385 {"parse-post-processing-settings", TestParsePostProcessingSettings},
386 {"trim-whitespace", TestTrimWhitespace},
387 {"bc-string-parsers", TestBoundaryConditionStringParsers},
388 {"validate-bc-handler-for-type", TestValidateBCHandlerForBCType},
389 {"parse-scaling-information", TestParseScalingInformation},
390 {"display-banner-startup-summary", TestDisplayBannerTracksConditionalStartupFields},
391 };
392
393 ierr = PetscInitialize(&argc, &argv, NULL, "PICurv I/O tests");
394 if (ierr) {
395 return (int)ierr;
396 }
397
398 ierr = PicurvRunTests("unit-io", cases, sizeof(cases) / sizeof(cases[0]));
399 if (ierr) {
400 PetscFinalize();
401 return (int)ierr;
402 }
403
404 ierr = PetscFinalize();
405 return (int)ierr;
406}
Public interface for data input/output routines.
PetscErrorCode ParsePostProcessingSettings(SimCtx *simCtx)
Initializes post-processing settings from a config file and command-line overrides.
Definition io.c:2209
PetscErrorCode ParseScalingInformation(SimCtx *simCtx)
Parses physical scaling parameters from command-line options.
Definition io.c:2357
PetscErrorCode StringToBCHandlerType(const char *str, BCHandlerType *handler_out)
Converts a BC handler token (implementation strategy) to BCHandlerType.
Definition io.c:347
PetscErrorCode ReadSimulationFields(UserCtx *user, PetscInt ti)
Reads binary field data for velocity, pressure, and other required vectors.
Definition io.c:1126
PetscBool ShouldWriteDataOutput(const SimCtx *simCtx, PetscInt completed_step)
Returns whether full field/restart output should be written for the.
Definition io.c:70
PetscErrorCode ValidateBCHandlerForBCType(BCType type, BCHandlerType handler)
Validates that a selected handler is compatible with a mathematical BC type.
Definition io.c:364
void TrimWhitespace(char *str)
Helper function to trim leading/trailing whitespace from a string.
Definition io.c:38
PetscErrorCode WriteSimulationFields(UserCtx *user)
Writes simulation fields to files.
Definition io.c:1568
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 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:738
PetscErrorCode StringToBCType(const char *str, BCType *type_out)
Converts a mathematical BC type string (e.g., "PERIODIC", "WALL") to BCType.
Definition io.c:332
PetscErrorCode DisplayBanner(SimCtx *simCtx)
Displays a structured banner summarizing the simulation configuration.
Definition io.c:2031
static PetscErrorCode TestParseScalingInformation(void)
Tests scaling-reference parsing and derived pressure scaling.
Definition test_io.c:198
int main(int argc, char **argv)
Runs the unit-io PETSc test binary.
Definition test_io.c:378
static PetscErrorCode TestValidateBCHandlerForBCType(void)
Tests validation of boundary-type and handler compatibility.
Definition test_io.c:183
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:287
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:297
static PetscErrorCode TestVerifyPathExistence(void)
Tests filesystem existence checks for files and directories.
Definition test_io.c:35
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:278
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 CaptureBannerOutput(SimCtx *simCtx, char *captured, size_t captured_len)
Captures the startup banner into a temporary file-backed buffer.
Definition test_io.c:233
static PetscErrorCode TestWriteAndReadSimulationFields(void)
Tests writing and reloading core Eulerian field vectors.
Definition test_io.c:63
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.
PetscErrorCode PicurvDestroyMinimalContexts(SimCtx **simCtx_ptr, UserCtx **user_ptr)
Destroys minimal SimCtx/UserCtx fixtures and all owned PETSc objects.
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 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.
PetscErrorCode PicurvPopulateIdentityMetrics(UserCtx *user)
Populates identity metric vectors on the minimal grid fixture.
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.
BCType
Defines the general mathematical/physical Category of a boundary.
Definition variables.h:251
@ INLET
Definition variables.h:258
@ PERIODIC
Definition variables.h:260
@ WALL
Definition variables.h:254
PetscBool inletFaceDefined
Definition variables.h:830
BCFace identifiedInletBCFace
Definition variables.h:831
char euler_subdir[PETSC_MAX_PATH_LEN]
Definition variables.h:666
@ PARTICLE_INIT_SURFACE_RANDOM
Random placement on the inlet face.
Definition variables.h:509
@ PARTICLE_INIT_POINT_SOURCE
All particles at a fixed (psrc_x,psrc_y,psrc_z) — for validation.
Definition variables.h:511
char output_prefix[256]
Definition variables.h:567
PetscInt tiout
Definition variables.h:655
PetscReal L_ref
Definition variables.h:625
BCHandlerType
Defines the specific computational "strategy" for a boundary handler.
Definition variables.h:271
@ BC_HANDLER_PERIODIC_GEOMETRIC
Definition variables.h:284
@ BC_HANDLER_PERIODIC_DRIVEN_CONSTANT_FLUX
Definition variables.h:286
@ BC_HANDLER_WALL_NOSLIP
Definition variables.h:273
char output_dir[PETSC_MAX_PATH_LEN]
Definition variables.h:665
PetscInt StepsToRun
Definition variables.h:654
PetscInt timeStep
Definition variables.h:560
PetscInt np
Definition variables.h:739
Vec Ucont
Definition variables.h:837
PetscInt StartStep
Definition variables.h:653
PetscBool OnlySetup
Definition variables.h:659
char particleRestartMode[16]
Definition variables.h:745
char eulerianSource[PETSC_MAX_PATH_LEN]
Definition variables.h:663
ParticleInitializationType ParticleInitialization
Definition variables.h:743
Vec Ucat
Definition variables.h:837
ScalingCtx scaling
Definition variables.h:707
PetscBool outputParticles
Definition variables.h:561
char AnalyticalSolutionType[PETSC_MAX_PATH_LEN]
Definition variables.h:676
PetscInt particleConsoleOutputFreq
Definition variables.h:656
PetscInt step
Definition variables.h:651
PostProcessParams * pps
Definition variables.h:798
Vec Nvert
Definition variables.h:837
PetscReal P_ref
Definition variables.h:628
PetscInt startTime
Definition variables.h:558
PetscReal rho_ref
Definition variables.h:627
PetscReal U_ref
Definition variables.h:626
PetscInt immersed
Definition variables.h:673
char PostprocessingControlFile[PETSC_MAX_PATH_LEN]
Definition variables.h:797
char restart_dir[PETSC_MAX_PATH_LEN]
Definition variables.h:664
PetscInt LoggingFrequency
Definition variables.h:769
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
The master context for the entire simulation.
Definition variables.h:643
User-defined context containing data specific to a single computational grid level.
Definition variables.h:811