PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
 
Loading...
Searching...
No Matches
io.h
Go to the documentation of this file.
1#ifndef IO_H
2#define IO_H
3
4#include "variables.h" // Essential for SimCtx and UserCtx definitions
5#include "logging.h" // For logging macros.
6#include "Boundaries.h"
7/**
8 * @file io.h
9 * @brief Public interface for data input/output routines.
10 *
11 * This header declares functions responsible for parsing grid geometry
12 * information, either from command-line options for programmatically
13 * generated grids or by reading the header of a grid definition file.
14 */
15
16/**
17 * @brief Parses command-line options for a programmatically generated grid for a SINGLE block.
18 *
19 * This function reads all per-block array options related to grid geometry,
20 * such as dimensions (-im), domain bounds (-xMins), and stretching ratios (-rxs).
21 * It then populates the fields of the provided `UserCtx` struct using its
22 * internal block index `user->_this`.
23 *
24 * @param user Pointer to the `UserCtx` for a specific block. The function will
25 * populate the geometric fields (`IM`, `Min_X`, `rx`, etc.) within this struct.
26 * @return PetscErrorCode 0 on success, or a PETSc error code on failure.
27 */
28PetscErrorCode ReadGridGenerationInputs(UserCtx *user);
29
30/**
31 * @brief Sets grid dimensions from a file for a SINGLE block using a one-time read cache.
32 *
33 * This function uses a static-variable pattern to ensure the grid file header
34 * is read only once, collectively, by all processes on the first call.
35 * Subsequent calls simply retrieve the pre-loaded and broadcasted data for
36 * the specified block.
37 *
38 * @param user Pointer to the `UserCtx` for a specific block. This function will
39 * populate the `IM`, `JM`, and `KM` fields.
40 * @return PetscErrorCode 0 on success, or a PETSc error code on failure.
41 */
42PetscErrorCode ReadGridFile(UserCtx *user);
43
44/**
45 * @brief A parallel-safe helper to verify the existence of a generic file or directory path.
46 *
47 * This function centralizes the logic for checking arbitrary paths. Only Rank 0 performs the
48 * filesystem check, and the result is broadcast to all other processes. This ensures
49 * collective and synchronized decision-making across all ranks. It is intended for
50 * configuration files, source directories, etc., where the path is known completely.
51 *
52 * @param[in] path The full path to the file or directory to check.
53 * @param[in] is_dir PETSC_TRUE if checking for a directory, PETSC_FALSE for a file.
54 * @param[in] is_optional PETSC_TRUE if the path is optional (results in a warning),
55 * PETSC_FALSE if mandatory (results in an error).
56 * @param[in] description A user-friendly description of the path for logging (e.g., "Grid file").
57 * @param[out] exists The result of the check (identical on all ranks).
58 *
59 * @return PetscErrorCode
60 */
61PetscErrorCode VerifyPathExistence(const char *path, PetscBool is_dir, PetscBool is_optional, const char *description, PetscBool *exists);
62
63/**
64 * @brief Returns whether full field/restart output should be written for the
65 *
66 * completed timestep.
67 *
68 * @param simCtx Simulation context controlling the operation.
69 * @param completed_step Completed step index used by the decision helper.
70 * @return PetscBool indicating the result of `ShouldWriteDataOutput()`.
71 */
72PetscBool ShouldWriteDataOutput(const SimCtx *simCtx, PetscInt completed_step);
73
74/**
75 * @brief Write and atomically publish one complete checkpoint bundle.
76 * @param[in,out] simCtx Simulation context owning all enabled checkpoint state.
77 * @param[in] reason Stable lifecycle reason such as `initial`, `cadence`, `final`, or `signal`.
78 * @return Zero on success or a PETSc/MPI/filesystem error.
79 */
80PetscErrorCode WriteCheckpointBundle(SimCtx *simCtx, const char *reason);
81
82/**
83 * @brief Reads binary field data for velocity, pressure, and other required vectors.
84 *
85 * Validates one committed checkpoint bundle and reads every enabled Eulerian
86 * checkpoint field through the field catalog.
87 *
88 * @param[in,out] user Pointer to the UserCtx structure containing the simulation context.
89 * @param[in] ti Checkpoint step resolved below the configured source root.
90 *
91 * @return PetscErrorCode Returns 0 on success, non-zero on failure.
92 */
93PetscErrorCode ReadSimulationFields(UserCtx *user, PetscInt ti);
94
95/**
96 * @brief Restores field-statistics window state and accumulators from a checkpoint.
97 *
98 * Resumes every configured window from the bundle at @p ti when continuation was
99 * requested, per @ref p58_checkpoint_sec. Window scalars come from the bundle
100 * manifest and accumulator payloads
101 * through the same natural-ordering vector reader Eulerian fields use, so a restart
102 * on a different MPI rank count restores identical state.
103 *
104 * Does nothing when statistics are disabled, no window is configured, or
105 * continuation was not requested. Anything else is fatal rather than silently
106 * zeroed: a window count mismatch, a renamed window, a changed definition hash, a
107 * requested end earlier than the represented span, or missing state.
108 *
109 * Under EXEC_MODE_RESTART_CHECK it needs no grid: it validates the bundle and every
110 * window against the manifest, skipping only the geometry comparison and the payload
111 * reads, and returns. The CLI runs that before staging a carried restart, so an
112 * incompatible window is refused before a job is queued.
113 *
114 * @param[in,out] simCtx Simulation context carrying the windows and accumulators.
115 * @param[in] ti Step whose committed bundle supplies the state.
116 * @return Zero on success, or a PETSc error when continuation cannot be honored.
117 */
118PetscErrorCode RestoreFieldStatisticsState(SimCtx *simCtx, PetscInt ti);
119
120
121/**
122 * @brief Reads data for a specific field from a file into the provided vector.
123 *
124 * This function uses the field name to construct the file path and reads the data
125 * from the corresponding file into the provided PETSc vector.
126 *
127 * @param[in] user Pointer to the UserCtx structure containing simulation context.
128 * @param[in] field_name Name of the field (e.g., "ufield", "vfield", "pfield").
129 * @param[out] field_vec PETSc vector to store the field data.
130 * @param[in] ext File extension (e.g., "dat").
131 *
132 * @return PetscErrorCode Returns 0 on success, non-zero on failure.
133 */
134PetscErrorCode ReadFieldData(UserCtx *user, const char *field_name, Vec field_vec, const char *ext);
135
136
137/**
138 * @brief Writes data from a specific PETSc vector to a file.
139 *
140 * This function uses the field name to construct the file path and writes the data
141 * from the provided PETSc vector to the corresponding file.
142 *
143 * @param[in] user Pointer to the UserCtx structure containing simulation context.
144 * @param[in] field_name Name of the field (e.g., "ufield", "vfield", "pfield").
145 * @param[in] field_vec PETSc vector containing the field data to write.
146 * @param[in] ext File extension (e.g., "dat").
147 *
148 * @return PetscErrorCode Returns 0 on success, non-zero on failure.
149 */
150PetscErrorCode WriteFieldData(UserCtx *user, const char *field_name, Vec field_vec, const char *ext);
151
152
153/**
154 * @brief Writes simulation fields to files.
155 *
156 * This function writes contravariant velocity, Cartesian velocity, pressure, and node state
157 * fields to their respective binary files. It also conditionally writes LES
158 * model fields when those models are enabled.
159 *
160 * @param[in] user Pointer to the UserCtx structure containing simulation context.
161 * @param[in] checkpoint_directory Root of the in-progress checkpoint bundle.
162 *
163 * @return PetscErrorCode Returns 0 on success, non-zero on failure.
164 */
165PetscErrorCode WriteSimulationFields(UserCtx *user, const char *checkpoint_directory);
166
167/**
168 * @brief Writes data from a specific field in a PETSc Swarm to a file.
169 *
170 * This function retrieves the Swarm from the UserCtx (i.e., `user->swarm`) and
171 * creates a global PETSc vector from the specified Swarm field. It then calls
172 * the existing WriteFieldData() function to handle the actual I/O operation.
173 * After writing the data, the function destroys the temporary global vector
174 * to avoid memory leaks.
175 *
176 * @param[in] user Pointer to the UserCtx structure containing simulation context
177 * and the PetscSwarm (as `user->swarm`).
178 * @param[in] field_name Name of the Swarm field to be written (e.g., "my_field").
179 * @param[in] ext File extension (e.g., "dat", "bin").
180 *
181 * @return PetscErrorCode Returns 0 on success, non-zero on failure.
182 *
183 * @note Compatible with PETSc 3.14.4.
184 */
185PetscErrorCode WriteSwarmField(UserCtx *user, const char *field_name, const char *ext);
186
187/**
188 * @brief Writes integer data from a specific PETSc Swarm field to a file.
189 *
190 * This function is designed for swarm fields that store integer data (e.g.,
191 * DMSwarm_CellID), which cannot be converted to a standard PETSc Vec of
192 * PetscScalars. It accesses the raw data pointer for the field on each rank
193 * using DMSwarmGetField(), writes the local data to a rank-specific binary file,
194 * and then restores the field access.
195 *
196 * @param[in] user Pointer to the UserCtx structure containing the PetscSwarm.
197 * @param[in] field_name Name of the integer Swarm field to be written.
198 * @param[in] ext File extension (e.g., "dat", "bin").
199 *
200 * @return PetscErrorCode Returns 0 on success, non-zero on failure.
201 */
202PetscErrorCode WriteSwarmIntField(UserCtx *user, const char *field_name, const char *ext);
203
204/**
205 * @brief Writes a predefined set of PETSc Swarm fields to files.
206 *
207 * This function iterates through checkpoint-capable particle catalog entries
208 * and delegates each payload to the existing generic swarm writer.
209 *
210 * This function will only execute if particles are enabled in the simulation
211 * (i.e., `user->simCtx->np > 0` and `user->swarm` is not NULL).
212 *
213 * @param[in] user Pointer to the UserCtx structure containing the simulation context
214 * and the PetscSwarm.
215 * @param[in] checkpoint_directory Root of the in-progress checkpoint bundle.
216 * @return PetscErrorCode Returns 0 on success, non-zero on failure.
217 */
218PetscErrorCode WriteAllSwarmFields(UserCtx *user, const char *checkpoint_directory);
219
220/**
221 * @brief Reads a simple ASCII data file containing one numeric value per line.
222 *
223 * This helper performs rank-0 file I/O, broadcasts the parsed result to the rest
224 * of the communicator, and returns a replicated array on every rank.
225 *
226 * @param filename Path to the input data file.
227 * @param data_out Output pointer to the allocated scalar array.
228 * @param Nout Output pointer storing the number of values read.
229 * @param comm MPI communicator used for the coordinated read/broadcast sequence.
230 * @return Integer value produced by `ReadDataFileToArray()`.
231 */
232PetscInt ReadDataFileToArray(const char *filename,
233 double **data_out,
234 PetscInt *Nout,
235 MPI_Comm comm);
236
237/**
238 * @brief Creates a VTK file from prepared metadata and field payloads.
239 *
240 * This helper dispatches to the structured-grid or polydata writer based on the
241 * metadata contents and emits the assembled VTK file on the requested communicator.
242 *
243 * @param filename Path to the output VTK file.
244 * @param meta VTK metadata describing the output geometry and field payloads.
245 * @param comm MPI communicator used by the write operation.
246 * @return Integer value produced by `CreateVTKFileFromMetadata()`.
247 */
248PetscErrorCode CreateVTKFileFromMetadata(const char *filename,
249 const VTKMetaData *meta,
250 MPI_Comm comm);
251
252/**
253 * @brief Reads data from a file into a specified field of a PETSc DMSwarm.
254 *
255 * This function is the counterpart to WriteSwarmField(). It creates a global PETSc vector
256 * that references the specified DMSwarm field, uses ReadFieldData() to read the data from
257 * a file, and then destroys the global vector reference.
258 *
259 * @param[in] user Pointer to the UserCtx structure (containing `user->swarm`).
260 * @param[in] field_name Name of the DMSwarm field to read into (must be previously declared/allocated).
261 * @param[in] ext File extension (e.g., "dat" or "bin").
262 *
263 * @return PetscErrorCode Returns 0 on success, non-zero on failure.
264 *
265 * @note Compatible with PETSc 3.14.x.
266 */
267PetscErrorCode ReadSwarmField(UserCtx *user, const char *field_name, const char *ext);
268
269/**
270 * @brief Reads integer swarm data by using ReadFieldData and casting the result.
271 *
272 * This function is the counterpart to WriteSwarmIntField. It reads a file
273 * containing floating-point data (that was originally integer) into a temporary
274 * Vec and then casts it back to the integer swarm field. It works by:
275 * 1. Creating a temporary parallel Vec.
276 * 2. Calling the standard ReadFieldData() to populate this Vec.
277 * 3. Accessing the local data of both the Vec and the swarm field.
278 * 4. Populating the swarm's integer field by casting each PetscScalar back to a PetscInt.
279 * 5. Destroying the temporary Vec.
280 *
281 * @param[in] user Pointer to the UserCtx structure.
282 * @param[in] field_name Name of the integer Swarm field to be read.
283 * @param[in] ext File extension.
284 *
285 * @return PetscErrorCode Returns 0 on success, non-zero on failure.
286 */
287PetscErrorCode ReadSwarmIntField(UserCtx *user, const char *field_name, const char *ext);
288
289/**
290 * @brief Reads multiple fields (positions, velocity, CellID, and weight) into a DMSwarm.
291 *
292 * This function is analogous to ReadSimulationFields() but targets a DMSwarm.
293 * Each Swarm field is read from a separate file using ReadSwarmField().
294 *
295 * @param[in,out] user Pointer to the UserCtx structure containing the DMSwarm (user->swarm).
296 * @param[in] ti Time index for constructing the file name.
297 *
298 * @return PetscErrorCode Returns 0 on success, non-zero on failure.
299 */
300PetscErrorCode ReadAllSwarmFields(UserCtx *user, PetscInt ti);
301
302/**
303 * @brief Read the particle count from a validated committed checkpoint.
304 *
305 * @param[in,out] user Simulation context and active grid used for validation.
306 * @param[in] ti Checkpoint step resolved below the configured source root.
307 * @param[out] particle_count Number of particles recorded by the bundle.
308 * @return Zero on success or a checkpoint-validation error.
309 */
310PetscErrorCode ReadCheckpointParticleCount(UserCtx *user, PetscInt ti, PetscInt *particle_count);
311
312/**
313 * @brief Displays a structured banner summarizing the simulation configuration.
314 *
315 * This function prints effective key simulation parameters to standard output
316 * on MPI rank 0. It retrieves global domain bounds and block metadata from
317 * `simCtx`, and suppresses settings that do not apply to the selected mode.
318 * For example, `Initial Pseudo-CFL (Courant)` appears only for the Dual Time
319 * Picard--Jameson RK momentum solver; it is not a Newton--Krylov control.
320 * The report also identifies active logging, profiling, runtime-memory, and
321 * solution-convergence modes so the startup log records the effective
322 * observability contract.
323 *
324 * @param[in] simCtx Pointer to the master simulation context.
325 *
326 * @return PetscErrorCode Returns `0` on success.
327 */
328PetscErrorCode DisplayBanner(SimCtx *simCtx);
329
330
331// --- Conversion and Validation Utilities ---
332// These are now public and can be used by other parts of the application.
333
334/**
335 * @brief Converts a face-token string (e.g., "-Xi", "+Eta") to the internal `BCFace` enum.
336 *
337 * @param[in] str Input token from configuration.
338 * @param[out] face_out Parsed enum value on success.
339 * @return PetscErrorCode 0 on success, non-zero for invalid tokens or null pointers.
340 */
341PetscErrorCode StringToBCFace(const char* str, BCFace* face_out);
342
343/**
344 * @brief Converts a mathematical BC type string (e.g., "PERIODIC", "WALL") to `BCType`.
345 *
346 * @param[in] str Input token from configuration.
347 * @param[out] type_out Parsed enum value on success.
348 * @return PetscErrorCode 0 on success, non-zero for invalid tokens or null pointers.
349 */
350PetscErrorCode StringToBCType(const char* str, BCType* type_out);
351
352/**
353 * @brief Converts a BC handler token (implementation strategy) to `BCHandlerType`.
354 *
355 * @param[in] str Input handler token from configuration.
356 * @param[out] handler_out Parsed enum value on success.
357 * @return PetscErrorCode 0 on success, non-zero for invalid tokens or null pointers.
358 */
359PetscErrorCode StringToBCHandlerType(const char* str, BCHandlerType* handler_out);
360
361/**
362 * @brief Validates that a selected handler is compatible with a mathematical BC type.
363 *
364 * @param[in] type Mathematical BC type (e.g., WALL, PERIODIC).
365 * @param[in] handler Selected handler implementation enum.
366 * @return PetscErrorCode 0 if compatible, non-zero if the combination is invalid.
367 */
368PetscErrorCode ValidateBCHandlerForBCType(BCType type, BCHandlerType handler);
369
370// --- Memory Management ---
371
372/**
373 * @brief Frees an entire linked list of boundary-condition parameters.
374 *
375 * @param[in,out] head Head pointer of the `BC_Param` list to destroy.
376 */
377void FreeBC_ParamList(BC_Param *head);
378
379/**
380 * @brief Searches a BC_Param linked list for a key and returns its value as a double.
381 * @param params The head of the BC_Param linked list.
382 * @param key The key to search for (case-insensitive).
383 * @param[out] value_out The found value, converted to a PetscReal.
384 * @param[out] found Set to PETSC_TRUE if the key was found, PETSC_FALSE otherwise.
385 * @return 0 on success.
386 */
387PetscErrorCode GetBCParamReal(BC_Param *params, const char *key, PetscReal *value_out, PetscBool *found);
388
389/**
390 * @brief Searches a BC_Param linked list for a key and returns its value as a bool.
391 * @param params The head of the BC_Param linked list.
392 * @param key The key to search for (case-insensitive).
393 * @param[out] value_out The found value, converted to a PetscBool.
394 * @param[out] found Set to PETSC_TRUE if the key was found, PETSC_FALSE otherwise.
395 * @return 0 on success.
396 */
397PetscErrorCode GetBCParamBool(BC_Param *params, const char *key, PetscBool *value_out, PetscBool *found);
398
399/**
400 * @brief Searches a BC_Param linked list for a key and returns its value as a string.
401 * @param params The head of the BC_Param linked list.
402 * @param key The key to search for (case-insensitive).
403 * @param[out] value_out Borrowed pointer to the matching value string, or NULL if absent.
404 * @param[out] found Set to PETSC_TRUE if the key was found, PETSC_FALSE otherwise.
405 * @return 0 on success.
406 */
407PetscErrorCode GetBCParamString(BC_Param *params, const char *key, const char **value_out, PetscBool *found);
408
409/**
410 * @brief Read the driven-flow seam-flux flag, accepting its deprecated `apply_trim` spelling.
411 * @param[in] params Parameter list for the face.
412 * @param[out] value_out Resolved flag value.
413 * @param[out] found Whether either spelling was present.
414 * @return PetscErrorCode 0 on success.
415 */
416PetscErrorCode GetDrivenSeamFluxFlag(BC_Param *params, PetscBool *value_out, PetscBool *found);
417
418/**
419 * @brief Parses the boundary conditions file to configure the type, handler, and
420 * any associated parameters for all 6 global faces of the domain.
421 *
422 * This function performs the following steps:
423 * 1. On MPI rank 0, it reads the specified configuration file line-by-line.
424 * 2. It parses each line for `<Face> <Type> <Handler> [param=value]...` format.
425 * 3. It validates the parsed strings and stores the configuration, including a
426 * linked list of parameters, in a temporary array.
427 * 4. It then serializes this configuration and broadcasts it to all other MPI ranks.
428 * 5. All ranks (including rank 0) then deserialize the broadcasted data to populate
429 * their local `user->boundary_faces` array identically.
430 * 6. It also sets the particle inlet lookup fields in `UserCtx`.
431 *
432 * @param[in,out] user The main UserCtx struct where the final configuration
433 * for all ranks will be stored.
434 * @param[in] bcs_input_filename The path to the boundary conditions configuration file.
435 * @return PetscErrorCode 0 on success, error code on failure.
436 */
437PetscErrorCode ParseAllBoundaryConditions(UserCtx *user, const char *bcs_input_filename);
438
439/**
440 * @brief Scans all block-specific boundary condition files to determine a globally
441 * consistent periodicity for each dimension, reusing the core type parser.
442 *
443 * This is a lightweight pre-parser intended to be called before DMDA creation.
444 * It ensures that the periodicity setting is consistent across all blocks, which is a
445 * physical requirement for the domain.
446 *
447 * 1. It collectively verifies that the mandatory BCS file for each block exists.
448 * 2. On MPI rank 0, it then iterates through the files.
449 * 3. For each line, it attempts to convert the type string to a BCType enum using the
450 * standard `StringToBCType` helper.
451 * 4. If the conversion is successful AND the type is PERIODIC, it flags the corresponding face.
452 * 5. If the conversion fails (e.g., for "WALL", "INLET", etc.), the error is cleared
453 * and the line is simply ignored, as it's not relevant to periodicity.
454 * 6. It validates consistency (e.g., -Xi and +Xi match) and ensures all block files
455 * specify the same global periodicity.
456 * 7. It broadcasts the final three flags (as integers 0 or 1) to all MPI ranks.
457 * 8. All ranks update the i_periodic, j_periodic, and k_periodic fields in their SimCtx.
458 *
459 * @param[in,out] simCtx The master SimCtx struct, containing the bcs_files list and
460 * where the final periodicity flags will be stored.
461 * @return PetscErrorCode 0 on success, error code on failure.
462 */
463PetscErrorCode DeterminePeriodicity(SimCtx *simCtx);
464
465/**
466 * @brief Removes leading and trailing ASCII whitespace from a mutable string.
467 * @param[in,out] str NUL-terminated string compacted in place.
468 */
469void TrimWhitespace(char *str);
470
471/**
472 * @brief Return whether a catalogued field belongs in the current checkpoint.
473 * @details A checkpointed field whose subsystem is active (turbulence, dynamic LES,
474 * particles, wall model). These are exactly the fields a checkpoint read can
475 * load, so consumers of loaded state use the same predicate.
476 * @param[in] simCtx Run context whose active subsystems decide availability.
477 * @param[in] descriptor Catalog entry to test.
478 * @return `PETSC_TRUE` when the field is checkpointed in this run.
479 */
480PetscBool CheckpointFieldIsEnabled(const SimCtx *simCtx, const FieldDescriptor *descriptor);
481
482/**
483 * @brief Convert a solver time to physical seconds, `t * L_ref / U_ref`.
484 * @details Runtime diagnostics record solver time; each also reports this physical time
485 * so a history can be plotted in seconds without the case's scales at hand.
486 * @param[in] simCtx Context carrying the reference scales.
487 * @param[in] solver_time Time in solver units.
488 * @param[out] physical Time in seconds.
489 * @return Zero on success.
490 */
491PetscErrorCode PicurvPhysicalTime(const SimCtx *simCtx, PetscReal solver_time, PetscReal *physical);
492
493/**
494 * @brief Physical scale one field is multiplied by to leave non-dimensional form.
495 *
496 * Each field's dimension is recorded once, on its entry in the Eulerian or particle
497 * field catalog; this resolves a name against both and applies the run's reference
498 * scales. Field dimensionalization, derived field statistics, and anything else needing
499 * a physical scale read it from here.
500 *
501 * @param[in] simCtx Context carrying the resolved reference scales.
502 * @param[in] field_name Case-insensitive catalogued field name or alias.
503 * @param[out] scale Multiplicative factor.
504 * @param[out] description Optional human-readable dimension, may be NULL.
505 * @param[in] description_length Capacity of `description`.
506 * @return 0 on success; `PETSC_ERR_ARG_UNKNOWN_TYPE` for a name in neither catalog, and
507 * `PETSC_ERR_ARG_WRONGSTATE` for a field without a fixed dimension (bookkeeping,
508 * or staging storage whose dimension is its source's).
509 */
510PetscErrorCode PicurvFieldReferenceScale(SimCtx *simCtx, const char *field_name,
511 PetscReal *scale, char *description,
512 size_t description_length);
513
514/**
515 * @brief Initializes post-processing settings from a config file and command-line overrides.
516 *
517 * This function establishes the configuration for a post-processing run by:
518 * 1. Setting hardcoded default values in the PostProcessParams struct.
519 * 2. Reading a configuration file to override the defaults.
520 * 3. Parsing command-line options (-startTime, -endTime, etc.) which can override
521 * both the defaults and the file settings.
522 *
523 * @param simCtx The pointer to the simulation context that contains the postprocessing file and struct.
524 * @return PetscErrorCode
525 */
526PetscErrorCode ParsePostProcessingSettings(SimCtx *simCtx);
527
528/**
529 * @brief Parses physical scaling parameters from command-line options.
530 *
531 * This function reads the reference length, velocity, and density from the
532 * PETSc options database (provided via -scaling_L_ref, etc.). It populates
533 * the simCtx->scaling struct and calculates the derived reference pressure.
534 * It sets default values of 1.0 for a fully non-dimensional case if the
535 * options are not provided.
536 *
537 * @param[in,out] simCtx The simulation context whose 'scaling' member will be populated.
538 * @return PetscErrorCode
539 */
540PetscErrorCode ParseScalingInformation(SimCtx *simCtx);
541
542#endif // IO_H
Immutable metadata for one field identity.
PetscErrorCode ParsePostProcessingSettings(SimCtx *simCtx)
Initializes post-processing settings from a config file and command-line overrides.
Definition io.c:3051
PetscErrorCode CreateVTKFileFromMetadata(const char *filename, const VTKMetaData *meta, MPI_Comm comm)
Creates a VTK file from prepared metadata and field payloads.
Definition vtk_io.c:172
PetscErrorCode ParseScalingInformation(SimCtx *simCtx)
Parses physical scaling parameters from command-line options.
Definition io.c:3256
PetscInt ReadDataFileToArray(const char *filename, double **data_out, PetscInt *Nout, MPI_Comm comm)
Reads a simple ASCII data file containing one numeric value per line.
Definition io.c:3300
PetscErrorCode ReadGridFile(UserCtx *user)
Sets grid dimensions from a file for a SINGLE block using a one-time read cache.
Definition io.c:636
PetscErrorCode StringToBCHandlerType(const char *str, BCHandlerType *handler_out)
Converts a BC handler token (implementation strategy) to BCHandlerType.
Definition io.c:773
PetscErrorCode ReadSwarmField(UserCtx *user, const char *field_name, const char *ext)
Reads data from a file into a specified field of a PETSc DMSwarm.
Definition io.c:1714
PetscErrorCode GetBCParamReal(BC_Param *params, const char *key, PetscReal *value_out, PetscBool *found)
Searches a BC_Param linked list for a key and returns its value as a double.
Definition io.c:819
PetscErrorCode WriteAllSwarmFields(UserCtx *user, const char *checkpoint_directory)
Writes a predefined set of PETSc Swarm fields to files.
Definition io.c:2155
PetscErrorCode WriteSwarmIntField(UserCtx *user, const char *field_name, const char *ext)
Writes integer data from a specific PETSc Swarm field to a file.
Definition io.c:2088
PetscErrorCode ReadCheckpointParticleCount(UserCtx *user, PetscInt ti, PetscInt *particle_count)
Read the particle count from a validated committed checkpoint.
Definition io.c:1868
PetscErrorCode ReadSimulationFields(UserCtx *user, PetscInt ti)
Reads binary field data for velocity, pressure, and other required vectors.
Definition io.c:1387
PetscBool ShouldWriteDataOutput(const SimCtx *simCtx, PetscInt completed_step)
Returns whether full field/restart output should be written for the.
Definition io.c:521
PetscErrorCode PicurvFieldReferenceScale(SimCtx *simCtx, const char *field_name, PetscReal *scale, char *description, size_t description_length)
Physical scale one field is multiplied by to leave non-dimensional form.
Definition io.c:3006
PetscErrorCode GetDrivenSeamFluxFlag(BC_Param *params, PetscBool *value_out, PetscBool *found)
Read the driven-flow seam-flux flag, accepting its deprecated apply_trim spelling.
Definition io.c:888
PetscErrorCode ParseAllBoundaryConditions(UserCtx *user, const char *bcs_input_filename)
Parses the boundary conditions file to configure the type, handler, and any associated parameters for...
Definition io.c:911
PetscErrorCode ValidateBCHandlerForBCType(BCType type, BCHandlerType handler)
Validates that a selected handler is compatible with a mathematical BC type.
Definition io.c:793
void TrimWhitespace(char *str)
Removes leading and trailing ASCII whitespace from a mutable string.
Definition io.c:486
PetscErrorCode ReadAllSwarmFields(UserCtx *user, PetscInt ti)
Reads multiple fields (positions, velocity, CellID, and weight) into a DMSwarm.
Definition io.c:1815
PetscErrorCode WriteSimulationFields(UserCtx *user, const char *checkpoint_directory)
Writes simulation fields to files.
Definition io.c:1954
PetscBool CheckpointFieldIsEnabled(const SimCtx *simCtx, const FieldDescriptor *descriptor)
Return whether a catalogued field belongs in the current checkpoint.
Definition io.c:75
PetscErrorCode ReadGridGenerationInputs(UserCtx *user)
Parses command-line options for a programmatically generated grid for a SINGLE block.
Definition io.c:537
PetscErrorCode ReadFieldData(UserCtx *user, const char *field_name, Vec field_vec, const char *ext)
Reads data for a specific field from a file into the provided vector.
Definition io.c:1248
PetscErrorCode DeterminePeriodicity(SimCtx *simCtx)
Scans all block-specific boundary condition files to determine a globally consistent periodicity for ...
Definition io.c:1096
PetscErrorCode RestoreFieldStatisticsState(SimCtx *simCtx, PetscInt ti)
Restores field-statistics window state and accumulators from a checkpoint.
Definition io.c:1604
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:736
PetscErrorCode GetBCParamString(BC_Param *params, const char *key, const char **value_out, PetscBool *found)
Searches a BC_Param linked list for a key and returns its value as a string.
Definition io.c:859
PetscErrorCode WriteSwarmField(UserCtx *user, const char *field_name, const char *ext)
Writes data from a specific field in a PETSc Swarm to a file.
Definition io.c:2031
PetscErrorCode ReadSwarmIntField(UserCtx *user, const char *field_name, const char *ext)
Reads integer swarm data by using ReadFieldData and casting the result.
Definition io.c:1746
PetscErrorCode WriteFieldData(UserCtx *user, const char *field_name, Vec field_vec, const char *ext)
Writes data from a specific PETSc vector to a file.
Definition io.c:1901
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:1202
PetscErrorCode GetBCParamBool(BC_Param *params, const char *key, PetscBool *value_out, PetscBool *found)
Searches a BC_Param linked list for a key and returns its value as a bool.
Definition io.c:836
void FreeBC_ParamList(BC_Param *head)
Frees an entire linked list of boundary-condition parameters.
Definition io.c:719
PetscErrorCode StringToBCType(const char *str, BCType *type_out)
Converts a mathematical BC type string (e.g., "PERIODIC", "WALL") to BCType.
Definition io.c:753
PetscErrorCode DisplayBanner(SimCtx *simCtx)
Displays a structured banner summarizing the simulation configuration.
Definition io.c:2635
PetscErrorCode WriteCheckpointBundle(SimCtx *simCtx, const char *reason)
Write and atomically publish one complete checkpoint bundle.
Definition io.c:2501
PetscErrorCode PicurvPhysicalTime(const SimCtx *simCtx, PetscReal solver_time, PetscReal *physical)
Convert a solver time to physical seconds, t * L_ref / U_ref.
Definition io.c:2986
Logging utilities and macros for PETSc-based applications.
Main header file for a complex fluid dynamics solver.
BCType
Defines the general mathematical/physical Category of a boundary.
Definition variables.h:316
BCHandlerType
Defines the specific computational "strategy" for a boundary handler.
Definition variables.h:343
BCFace
Identifies the six logical faces of a structured computational block.
Definition variables.h:308
A node in a linked list for storing key-value parameters from the bcs.dat file.
Definition variables.h:372
The master context for the entire simulation.
Definition variables.h:916
User-defined context containing data specific to a single computational grid level.
Definition variables.h:1157
One VTK file being assembled collectively.
Definition variables.h:871