20 PetscFunctionBeginUser;
21 PetscCall(PetscMemzero(&simCtx,
sizeof(simCtx)));
27 PetscFunctionReturn(0);
35 char tmpdir[PETSC_MAX_PATH_LEN];
36 char filepath[PETSC_MAX_PATH_LEN];
38 PetscBool exists = PETSC_FALSE;
40 PetscFunctionBeginUser;
42 PetscCall(PetscSNPrintf(filepath,
sizeof(filepath),
"%s/sample.txt", tmpdir));
44 file = fopen(filepath,
"w");
45 PetscCheck(file != NULL, PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN,
"Failed to create temp file '%s'.", filepath);
46 fputs(
"picurv\n", file);
50 PetscCall(
PicurvAssertBool(exists,
"VerifyPathExistence should find the temp directory"));
53 PetscCall(
PicurvAssertBool(exists,
"VerifyPathExistence should find the temp file"));
54 PetscFunctionReturn(0);
64 char tmpdir[PETSC_MAX_PATH_LEN];
65 char euler_dir[PETSC_MAX_PATH_LEN];
67 PetscFunctionBeginUser;
70 PetscCall(PetscSNPrintf(euler_dir,
sizeof(euler_dir),
"%s/%s", tmpdir, simCtx->
euler_subdir));
75 PetscCall(VecSet(user->
P, 4.5));
76 PetscCall(VecSet(user->
Nvert, 0.0));
77 PetscCall(VecSet(user->
Ucat, 2.0));
78 PetscCall(VecSet(user->
Ucont, 3.0));
82 PetscCall(VecZeroEntries(user->
P));
83 PetscCall(VecZeroEntries(user->
Ucat));
84 PetscCall(VecZeroEntries(user->
Ucont));
92 PetscFunctionReturn(0);
102 char tmpdir[PETSC_MAX_PATH_LEN];
103 char cfg_path[PETSC_MAX_PATH_LEN];
106 PetscFunctionBeginUser;
108 PetscCall(PetscCalloc1(1, &simCtx->
pps));
110 PetscCall(PetscSNPrintf(cfg_path,
sizeof(cfg_path),
"%s/post.run", tmpdir));
113 file = fopen(cfg_path,
"w");
114 PetscCheck(file != NULL, PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN,
"Failed to create temp config file '%s'.", cfg_path);
115 fputs(
"startTime = 2\n", file);
116 fputs(
"endTime = 6\n", file);
117 fputs(
"timeStep = 2\n", file);
118 fputs(
"output_particles = true\n", file);
119 fputs(
"output_prefix = SmokeField\n", file);
128 "ParsePostProcessingSettings should parse output_prefix"));
131 PetscFunctionReturn(0);
139 char value_a[] =
" inlet_value ";
140 char value_b[] =
" ";
142 PetscFunctionBeginUser;
144 PetscCall(
PicurvAssertBool((PetscBool)(strcmp(value_a,
"inlet_value") == 0),
145 "TrimWhitespace should remove leading and trailing whitespace"));
149 "TrimWhitespace should reduce all-whitespace strings to empty"));
150 PetscFunctionReturn(0);
162 PetscFunctionBeginUser;
171 "StringToBCHandlerType should parse constant_flux"));
172 PetscFunctionReturn(0);
180 PetscFunctionBeginUser;
182 "WALL + noslip should be a valid combination"));
184 "PERIODIC + geometric should be a valid combination"));
186 "INLET + noslip should be rejected"));
187 PetscFunctionReturn(0);
197 PetscFunctionBeginUser;
198 PetscCall(PetscMemzero(&simCtx,
sizeof(simCtx)));
200 PetscCall(PetscOptionsClearValue(NULL,
"-scaling_L_ref"));
201 PetscCall(PetscOptionsClearValue(NULL,
"-scaling_U_ref"));
202 PetscCall(PetscOptionsClearValue(NULL,
"-scaling_rho_ref"));
210 PetscCall(PetscOptionsSetValue(NULL,
"-scaling_L_ref",
"2.5"));
211 PetscCall(PetscOptionsSetValue(NULL,
"-scaling_U_ref",
"4.0"));
212 PetscCall(PetscOptionsSetValue(NULL,
"-scaling_rho_ref",
"1.2"));
220 PetscCall(PetscOptionsClearValue(NULL,
"-scaling_L_ref"));
221 PetscCall(PetscOptionsClearValue(NULL,
"-scaling_U_ref"));
222 PetscCall(PetscOptionsClearValue(NULL,
"-scaling_rho_ref"));
223 PetscFunctionReturn(0);
243 ierr = PetscInitialize(&argc, &argv, NULL,
"PICurv I/O tests");
248 ierr =
PicurvRunTests(
"unit-io", cases,
sizeof(cases) /
sizeof(cases[0]));
254 ierr = PetscFinalize();
Public interface for data input/output routines.
PetscErrorCode ParsePostProcessingSettings(SimCtx *simCtx)
Initializes post-processing settings from a config file and command-line overrides.
PetscErrorCode ParseScalingInformation(SimCtx *simCtx)
Parses physical scaling parameters from command-line options.
PetscErrorCode StringToBCHandlerType(const char *str, BCHandlerType *handler_out)
Converts a BC handler token (implementation strategy) to BCHandlerType.
PetscErrorCode ReadSimulationFields(UserCtx *user, PetscInt ti)
Reads binary field data for velocity, pressure, and other required vectors.
PetscBool ShouldWriteDataOutput(const SimCtx *simCtx, PetscInt completed_step)
Returns whether full field/restart output should be written for the completed timestep.
PetscErrorCode ValidateBCHandlerForBCType(BCType type, BCHandlerType handler)
Validates that a selected handler is compatible with a mathematical BC type.
void TrimWhitespace(char *str)
Helper function to trim leading/trailing whitespace from a string.
PetscErrorCode WriteSimulationFields(UserCtx *user)
Writes simulation fields to files.
PetscErrorCode StringToBCFace(const char *str, BCFace *face_out)
Converts a face-token string (e.g., "-Xi", "+Eta") to the internal BCFace enum.
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.
PetscErrorCode StringToBCType(const char *str, BCType *type_out)
Converts a mathematical BC type string (e.g., "PERIODIC", "WALL") to BCType.
static PetscErrorCode TestParseScalingInformation(void)
Test-local routine.
int main(int argc, char **argv)
Entry point for this unit-test binary.
static PetscErrorCode TestValidateBCHandlerForBCType(void)
Test-local routine.
static PetscErrorCode TestParsePostProcessingSettings(void)
Test-local routine.
static PetscErrorCode TestVerifyPathExistence(void)
Test-local routine.
static PetscErrorCode TestTrimWhitespace(void)
Test-local routine.
static PetscErrorCode TestShouldWriteDataOutput(void)
Test-local routine.
static PetscErrorCode TestBoundaryConditionStringParsers(void)
Test-local routine.
static PetscErrorCode TestWriteAndReadSimulationFields(void)
Test-local routine.
PetscErrorCode PicurvMakeTempDir(char *path, size_t path_len)
Shared test-support routine.
PetscErrorCode PicurvCreateMinimalContexts(SimCtx **simCtx_out, UserCtx **user_out, PetscInt mx, PetscInt my, PetscInt mz)
Shared test-support routine.
PetscErrorCode PicurvEnsureDir(const char *path)
Shared test-support routine.
PetscErrorCode PicurvAssertRealNear(PetscReal expected, PetscReal actual, PetscReal tol, const char *context)
Shared test-support routine.
PetscErrorCode PicurvDestroyMinimalContexts(SimCtx **simCtx_ptr, UserCtx **user_ptr)
Shared test-support routine.
PetscErrorCode PicurvRunTests(const char *suite_name, const PicurvTestCase *cases, size_t case_count)
Shared test-support routine.
PetscErrorCode PicurvAssertVecConstant(Vec vec, PetscScalar expected, PetscReal tol, const char *context)
Shared test-support routine.
PetscErrorCode PicurvAssertIntEqual(PetscInt expected, PetscInt actual, const char *context)
Shared test-support routine.
PetscErrorCode PicurvPopulateIdentityMetrics(UserCtx *user)
Shared test-support routine.
PetscErrorCode PicurvAssertBool(PetscBool value, const char *context)
Shared test-support routine.
C test module for PICurv.
Named test case descriptor consumed by PicurvRunTests.
BCType
Defines the general mathematical/physical Category of a boundary.
char euler_subdir[PETSC_MAX_PATH_LEN]
BCHandlerType
Defines the specific computational "strategy" for a boundary handler.
@ BC_HANDLER_PERIODIC_GEOMETRIC
@ BC_HANDLER_PERIODIC_DRIVEN_CONSTANT_FLUX
char output_dir[PETSC_MAX_PATH_LEN]
PetscBool outputParticles
char PostprocessingControlFile[PETSC_MAX_PATH_LEN]
char restart_dir[PETSC_MAX_PATH_LEN]
BCFace
Identifies the six logical faces of a structured computational block.
The master context for the entire simulation.
User-defined context containing data specific to a single computational grid level.