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 Reads binary field data for velocity, pressure, and other required vectors.
65 *
66 * Reads contravariant velocity (`Ucont`) from `vfield`, Cartesian velocity (`Ucat`) from `ufield`,
67 * pressure (`P`), node state (`Nvert_o`), and optionally statistical quantities, LES, and RANS fields
68 * from binary files. Logs missing files but continues execution.
69 *
70 * @param[in,out] user Pointer to the UserCtx structure containing the simulation context.
71 * @param[in] The timestep at which the simulation field data needs to be read.
72 *
73 * @return PetscErrorCode Returns 0 on success, non-zero on failure.
74 */
75PetscErrorCode ReadSimulationFields(UserCtx *user, PetscInt ti);
76
77
78/**
79 * @brief Reads data for a specific field from a file into the provided vector.
80 *
81 * This function uses the field name to construct the file path and reads the data
82 * from the corresponding file into the provided PETSc vector.
83 *
84 * @param[in] user Pointer to the UserCtx structure containing simulation context.
85 * @param[in] field_name Name of the field (e.g., "ufield", "vfield", "pfield").
86 * @param[out] field_vec PETSc vector to store the field data.
87 * @param[in] ti Time index for constructing the file name.
88 * @param[in] ext File extension (e.g., "dat").
89 *
90 * @return PetscErrorCode Returns 0 on success, non-zero on failure.
91 */
92PetscErrorCode ReadFieldData(UserCtx *user, const char *field_name, Vec field_vec, PetscInt ti, const char *ext);
93
94
95/**
96 * @brief Reads statistical fields used for time-averaged simulations.
97 *
98 * Reads statistical quantities such as velocity sums and pressure sums. Logs missing files and initializes
99 * fields to zero if files are unavailable.
100 *
101 * @param[in,out] user Pointer to the UserCtx structure containing the simulation context.
102 * @param[in] The timestep at which the simulation field data needs to be read.
103 *
104 * @return PetscErrorCode Returns 0 on success, non-zero on failure.
105 */
106PetscErrorCode ReadStatisticalFields(UserCtx *user,PetscInt ti);
107
108/**
109 * @brief Reads LES-related fields used in turbulence modeling.
110 *
111 * Reads the Smagorinsky constant (`Cs`) and transfers data to local vectors. Logs missing files and
112 * initializes fields to zero if files are unavailable.
113 *
114 * @param[in,out] user Pointer to the UserCtx structure containing the simulation context.
115 * @param[in] ti Time index for constructing the file name.
116 *
117 * @return PetscErrorCode Returns 0 on success, non-zero on failure.
118 */
119PetscErrorCode ReadLESFields(UserCtx *user, PetscInt ti);
120
121/**
122 * @brief Reads RANS-related fields for turbulence modeling.
123 *
124 * Reads `K_Omega` fields (used in RANS modeling) and initializes them if files are unavailable.
125 *
126 * @param[in,out] user Pointer to the UserCtx structure containing the simulation context.
127 * @param[in] ti Time index for constructing the file name.
128 *
129 * @return PetscErrorCode Returns 0 on success, non-zero on failure.
130 */
131PetscErrorCode ReadRANSFields(UserCtx *user, PetscInt ti);
132
133/**
134 * @brief Writes data from a specific PETSc vector to a file.
135 *
136 * This function uses the field name to construct the file path and writes the data
137 * from the provided PETSc vector to the corresponding file.
138 *
139 * @param[in] user Pointer to the UserCtx structure containing simulation context.
140 * @param[in] field_name Name of the field (e.g., "ufield", "vfield", "pfield").
141 * @param[in] field_vec PETSc vector containing the field data to write.
142 * @param[in] ti Time index for constructing the file name.
143 * @param[in] ext File extension (e.g., "dat").
144 *
145 * @return PetscErrorCode Returns 0 on success, non-zero on failure.
146 */
147PetscErrorCode WriteFieldData(UserCtx *user, const char *field_name, Vec field_vec, PetscInt ti, const char *ext);
148
149
150/**
151 * @brief Writes simulation fields to files.
152 *
153 * This function writes contravariant velocity, Cartesian velocity, pressure, and node state
154 * fields to their respective binary files. It also conditionally writes LES, RANS, and
155 * statistical fields if they are enabled.
156 *
157 * @param[in] user Pointer to the UserCtx structure containing simulation context.
158 *
159 * @return PetscErrorCode Returns 0 on success, non-zero on failure.
160 */
161PetscErrorCode WriteSimulationFields(UserCtx *user);
162
163
164/**
165 * @brief Writes statistical fields for averaging purposes.
166 *
167 * This function writes data for fields such as Ucat_sum, Ucat_cross_sum, Ucat_square_sum,
168 * and P_sum to their respective binary files.
169 *
170 * @param[in] user Pointer to the UserCtx structure containing simulation context.
171 *
172 * @return PetscErrorCode Returns 0 on success, non-zero on failure.
173 */
174PetscErrorCode WriteStatisticalFields(UserCtx *user);
175
176/**
177 * @brief Writes LES-related fields.
178 *
179 * This function writes LES-related fields such as Cs (Smagorinsky constant)
180 * to their respective binary files.
181 *
182 * @param[in] user Pointer to the UserCtx structure containing simulation context.
183 *
184 * @return PetscErrorCode Returns 0 on success, non-zero on failure.
185 */
186PetscErrorCode WriteLESFields(UserCtx *user);
187
188/**
189 * @brief Writes RANS-related fields.
190 *
191 * This function writes RANS-related fields such as K_Omega to their respective
192 * binary files.
193 *
194 * @param[in] user Pointer to the UserCtx structure containing simulation context.
195 *
196 * @return PetscErrorCode Returns 0 on success, non-zero on failure.
197 */
198PetscErrorCode WriteRANSFields(UserCtx *user);
199
200/**
201 * @brief Writes data from a specific field in a PETSc Swarm to a file.
202 *
203 * This function retrieves the Swarm from the UserCtx (i.e., `user->swarm`) and
204 * creates a global PETSc vector from the specified Swarm field. It then calls
205 * the existing WriteFieldData() function to handle the actual I/O operation.
206 * After writing the data, the function destroys the temporary global vector
207 * to avoid memory leaks.
208 *
209 * @param[in] user Pointer to the UserCtx structure containing simulation context
210 * and the PetscSwarm (as `user->swarm`).
211 * @param[in] field_name Name of the Swarm field to be written (e.g., "my_field").
212 * @param[in] ti Time index used to construct the output file name.
213 * @param[in] ext File extension (e.g., "dat", "bin").
214 *
215 * @return PetscErrorCode Returns 0 on success, non-zero on failure.
216 *
217 * @note Compatible with PETSc 3.14.4.
218 */
219PetscErrorCode WriteSwarmField(UserCtx *user, const char *field_name, PetscInt ti, const char *ext);
220
221/**
222 * @brief Writes integer data from a specific PETSc Swarm field to a file.
223 *
224 * This function is designed for swarm fields that store integer data (e.g.,
225 * DMSwarm_CellID), which cannot be converted to a standard PETSc Vec of
226 * PetscScalars. It accesses the raw data pointer for the field on each rank
227 * using DMSwarmGetField(), writes the local data to a rank-specific binary file,
228 * and then restores the field access.
229 *
230 * @param[in] user Pointer to the UserCtx structure containing the PetscSwarm.
231 * @param[in] field_name Name of the integer Swarm field to be written.
232 * @param[in] ti Time index used to construct the output file name.
233 * @param[in] ext File extension (e.g., "dat", "bin").
234 *
235 * @return PetscErrorCode Returns 0 on success, non-zero on failure.
236 */
237PetscErrorCode WriteSwarmIntField(UserCtx *user, const char *field_name, PetscInt ti, const char *ext);
238
239/**
240 * @brief Writes a predefined set of PETSc Swarm fields to files.
241 *
242 * This function iterates through a hardcoded list of common swarm fields
243 * (position, velocity, etc.) and calls the WriteSwarmField() helper function
244 * for each one. This provides a straightforward way to output essential particle
245 * data at a given simulation step.
246 *
247 * This function will only execute if particles are enabled in the simulation
248 * (i.e., `user->simCtx->np > 0` and `user->swarm` is not NULL).
249 *
250 * @param[in] user Pointer to the UserCtx structure containing the simulation context
251 * and the PetscSwarm.
252 *
253 * @return PetscErrorCode Returns 0 on success, non-zero on failure.
254 */
255PetscErrorCode WriteAllSwarmFields(UserCtx *user);
256
257/* --------------------------------------------------------------------
258 ReadDataFileToArray
259
260 Reads a simple ASCII .dat file containing one numeric value per line.
261
262 PARAMETERS:
263 filename - (input) path to the .dat file
264 data_out - (output) pointer to newly allocated array (rank 0
265 broadcasts to all ranks so each rank gets a copy)
266 Nout - (output) number of values read; same on all ranks
267 comm - (input) MPI communicator (we use rank 0 for I/O)
268
269 RETURN:
270 PetscErrorCode (0 = success, or error code on failure)
271
272 NOTES:
273 1) This function checks file existence on rank 0 and broadcasts
274 the result. If the file doesn't exist, it sets an error.
275 2) The array is allocated on all ranks, and the data is
276 broadcast so each rank has a local copy.
277 3) If your file format is more complex (e.g. multiple columns,
278 binary, etc.), you can adapt the reading logic here.
279-------------------------------------------------------------------- */
280PetscInt ReadDataFileToArray(const char *filename,
281 double **data_out,
282 PetscInt *Nout,
283 MPI_Comm comm);
284
285/* --------------------------------------------------------------------
286 CreateVTKFileFromMetadata
287
288 Creates a .vts (if fileType=VTK_STRUCTURED) or .vtp (if fileType=VTK_POLYDATA),
289 writing out the data contained in the VTKMetaData structure.
290
291 PARAMETERS:
292 filename - (input) path to the output file, e.g. "myfile.vts" or "myfile.vtp"
293 meta - (input) pointer to the VTKMetaData struct with all geometry/fields
294 comm - (input) MPI communicator (only rank 0 writes the file)
295
296 RETURN:
297 PetscErrorCode (0 = success, or error code on failure)
298
299 NOTES:
300 1) The function writes an XML header, the appended binary data blocks
301 (coordinates, scalar field, connectivity if needed), and the closing tags.
302 2) If meta->fileType = VTK_STRUCTURED, it calls .vts-specific logic.
303 If meta->fileType = VTK_POLYDATA, it calls .vtp logic.
304 3) Coordinates and field arrays must be properly sized. For instance,
305 if fileType=VTK_STRUCTURED, coords => length=3*nnodes, field=>nnodes.
306 If fileType=VTK_POLYDATA, coords => length=3*npoints, field=>npoints,
307 plus connectivity/offsets => length=npoints each.
308-------------------------------------------------------------------- */
309PetscInt CreateVTKFileFromMetadata(const char *filename,
310 const VTKMetaData *meta,
311 MPI_Comm comm);
312
313/**
314 * @brief Gathers the contents of a distributed PETSc Vec into a single array on rank 0.
315 *
316 * @param[in] inVec The input (possibly distributed) Vec.
317 * @param[out] N The global size of the vector.
318 * @param[out] arrayOut On rank 0, points to the newly allocated array holding all data.
319 * On other ranks, it is set to NULL.
320 *
321 * @return PetscErrorCode Return 0 on success, nonzero on failure.
322 */
323PetscErrorCode VecToArrayOnRank0(Vec inVec, PetscInt *N, double **arrayOut);
324
325/**
326 * @brief Gathers any DMSwarm field from all ranks to a single, contiguous array on rank 0.
327 *
328 * This is a generic, type-aware version of SwarmFieldToArrayOnRank0.
329 * It is a COLLECTIVE operation.
330 *
331 * @param[in] swarm The DMSwarm to gather from.
332 * @param[in] field_name The name of the field to gather.
333 * @param[out] n_total_particles (Output on rank 0) Total number of particles in the global swarm.
334 * @param[out] n_components (Output on rank 0) Number of components for the field.
335 * @param[out] gathered_array (Output on rank 0) A newly allocated array containing the full, gathered data.
336 * The caller is responsible for freeing this memory and for casting it to the correct type.
337 * @return PetscErrorCode
338 */
339PetscErrorCode SwarmFieldToArrayOnRank0(DM swarm, const char *field_name, PetscInt *n_total_particles, PetscInt *n_components, void **gathered_array);
340
341/**
342 * @brief Reads data from a file into a specified field of a PETSc DMSwarm.
343 *
344 * This function is the counterpart to WriteSwarmField(). It creates a global PETSc vector
345 * that references the specified DMSwarm field, uses ReadFieldData() to read the data from
346 * a file, and then destroys the global vector reference.
347 *
348 * @param[in] user Pointer to the UserCtx structure (containing `user->swarm`).
349 * @param[in] field_name Name of the DMSwarm field to read into (must be previously declared/allocated).
350 * @param[in] ti Time index used to construct the input file name.
351 * @param[in] ext File extension (e.g., "dat" or "bin").
352 *
353 * @return PetscErrorCode Returns 0 on success, non-zero on failure.
354 *
355 * @note Compatible with PETSc 3.14.x.
356 */
357PetscErrorCode ReadSwarmField(UserCtx *user, const char *field_name, PetscInt ti, const char *ext);
358
359/**
360 * @brief Reads integer swarm data by using ReadFieldData and casting the result.
361 *
362 * This function is the counterpart to WriteSwarmIntField. It reads a file
363 * containing floating-point data (that was originally integer) into a temporary
364 * Vec and then casts it back to the integer swarm field. It works by:
365 * 1. Creating a temporary parallel Vec.
366 * 2. Calling the standard ReadFieldData() to populate this Vec.
367 * 3. Accessing the local data of both the Vec and the swarm field.
368 * 4. Populating the swarm's integer field by casting each PetscScalar back to a PetscInt.
369 * 5. Destroying the temporary Vec.
370 *
371 * @param[in] user Pointer to the UserCtx structure.
372 * @param[in] field_name Name of the integer Swarm field to be read.
373 * @param[in] ti Time index for the input file.
374 * @param[in] ext File extension.
375 *
376 * @return PetscErrorCode Returns 0 on success, non-zero on failure.
377 */
378PetscErrorCode ReadSwarmIntField(UserCtx *user, const char *field_name, PetscInt ti, const char *ext);
379
380/**
381 * @brief Reads multiple fields (positions, velocity, CellID, and weight) into a DMSwarm.
382 *
383 * This function is analogous to ReadSimulationFields() but targets a DMSwarm.
384 * Each Swarm field is read from a separate file using ReadSwarmField().
385 *
386 * @param[in,out] user Pointer to the UserCtx structure containing the DMSwarm (user->swarm).
387 * @param[in] ti Time index for constructing the file name.
388 *
389 * @return PetscErrorCode Returns 0 on success, non-zero on failure.
390 */
391PetscErrorCode ReadAllSwarmFields(UserCtx *user, PetscInt ti);
392
393/**
394 * @brief Reads coordinate data (for particles) from file into a PETSc Vec, then gathers it to rank 0.
395 *
396 * This function uses \c ReadFieldData to fill a PETSc Vec with coordinate data,
397 * then leverages \c VecToArrayOnRank0 to gather that data into a contiguous array
398 * (valid on rank 0 only).
399 *
400 * @param[in] timeIndex The time index used to construct file names.
401 * @param[in] user Pointer to the user context.
402 * @param[out] coordsArray On rank 0, will point to a newly allocated array holding the coordinates.
403 * @param[out] Ncoords On rank 0, the length of \p coordsArray. On other ranks, 0.
404 *
405 * @return PetscErrorCode Returns 0 on success, or non-zero on failures.
406 */
407PetscErrorCode ReadPositionsFromFile(PetscInt timeIndex,
408 UserCtx *user,
409 double **coordsArray,
410 PetscInt *Ncoords);
411
412
413/**
414 * @brief Reads a named field from file into a PETSc Vec, then gathers it to rank 0.
415 *
416 * This function wraps \c ReadFieldData and \c VecToArrayOnRank0 into a single step.
417 * The gathered data is stored in \p scalarArray on rank 0, with its length in \p Nscalars.
418 *
419 * @param[in] timeIndex The time index used to construct file names.
420 * @param[in] fieldName Name of the field to be read (e.g., "velocity").
421 * @param[in] user Pointer to the user context.
422 * @param[out] scalarArray On rank 0, a newly allocated array holding the field data.
423 * @param[out] Nscalars On rank 0, length of \p scalarArray. On other ranks, 0.
424 *
425 * @return PetscErrorCode Returns 0 on success, or non-zero on failures.
426 */
427PetscErrorCode ReadFieldDataToRank0(PetscInt timeIndex,
428 const char *fieldName,
429 UserCtx *user,
430 double **scalarArray,
431 PetscInt *Nscalars);
432
433/**
434 * @brief Displays a structured banner summarizing the simulation configuration.
435 *
436 * This function prints key simulation parameters to standard output.
437 * It is intended to be called ONLY by MPI rank 0.
438 * It retrieves global domain bounds from `user->global_domain_bbox` and boundary
439 * conditions for all faces from `user->face_bc_types`.
440 *
441 * @param[in] user Pointer to `UserCtx` structure.
442 * @param[in] bboxlist (If rank 0 needed to compute global_domain_bbox here, otherwise NULL)
443 *
444 * @return PetscErrorCode Returns `0` on success.
445 */
446PetscErrorCode DisplayBanner(SimCtx *simCtx);
447
448
449// --- Conversion and Validation Utilities ---
450// These are now public and can be used by other parts of the application.
451
452PetscErrorCode StringToBCFace(const char* str, BCFace* face_out);
453PetscErrorCode StringToBCType(const char* str, BCType* type_out);
454PetscErrorCode StringToBCHandlerType(const char* str, BCHandlerType* handler_out);
455PetscErrorCode ValidateBCHandlerForBCType(BCType type, BCHandlerType handler);
456
457// --- Memory Management ---
458
459void FreeBC_ParamList(BC_Param *head);
460
461/**
462 * @brief Searches a BC_Param linked list for a key and returns its value as a double.
463 * @param params The head of the BC_Param linked list.
464 * @param key The key to search for (case-insensitive).
465 * @param[out] value_out The found value, converted to a PetscReal.
466 * @param[out] found Set to PETSC_TRUE if the key was found, PETSC_FALSE otherwise.
467 * @return 0 on success.
468 */
469PetscErrorCode GetBCParamReal(BC_Param *params, const char *key, PetscReal *value_out, PetscBool *found);
470
471/**
472 * @brief Parses the boundary conditions file to configure the type, handler, and
473 * any associated parameters for all 6 global faces of the domain.
474 *
475 * This function performs the following steps:
476 * 1. On MPI rank 0, it reads the specified configuration file line-by-line.
477 * 2. It parses each line for `<Face> <Type> <Handler> [param=value]...` format.
478 * 3. It validates the parsed strings and stores the configuration, including a
479 * linked list of parameters, in a temporary array.
480 * 4. It then serializes this configuration and broadcasts it to all other MPI ranks.
481 * 5. All ranks (including rank 0) then deserialize the broadcasted data to populate
482 * their local `user->boundary_faces` array identically.
483 * 6. It also sets legacy fields in UserCtx for compatibility with other modules.
484 *
485 * @param[in,out] user The main UserCtx struct where the final configuration
486 * for all ranks will be stored.
487 * @param[in] bcs_input_filename The path to the boundary conditions configuration file.
488 * @return PetscErrorCode 0 on success, error code on failure.
489 */
490PetscErrorCode ParseAllBoundaryConditions(UserCtx *user, const char *bcs_input_filename);
491
492/**
493 * @brief Helper function to trim leading/trailing whitespace from a string.
494 * @param str The string to trim in-place.
495 */
496void TrimWhitespace(char *str);
497
498/**
499 * @brief Initializes post-processing settings from a config file and command-line overrides.
500 *
501 * This function establishes the configuration for a post-processing run by:
502 * 1. Setting hardcoded default values in the PostProcessParams struct.
503 * 2. Reading a configuration file to override the defaults.
504 * 3. Parsing command-line options (-startTime, -endTime, etc.) which can override
505 * both the defaults and the file settings.
506 *
507 * @param simCtx The pointer to the simulation context that contains the postprocessing file and struct.
508 * @return PetscErrorCode
509 */
510PetscErrorCode ParsePostProcessingSettings(SimCtx *simCtx);
511
512/**
513 * @brief Parses physical scaling parameters from command-line options.
514 *
515 * This function reads the reference length, velocity, and density from the
516 * PETSc options database (provided via -scaling_L_ref, etc.). It populates
517 * the simCtx->scaling struct and calculates the derived reference pressure.
518 * It sets default values of 1.0 for a fully non-dimensional case if the
519 * options are not provided.
520 *
521 * @param[in,out] simCtx The simulation context whose 'scaling' member will be populated.
522 * @return PetscErrorCode
523 */
524PetscErrorCode ParseScalingInformation(SimCtx *simCtx);
525
526#endif // IO_H
PetscErrorCode ReadStatisticalFields(UserCtx *user, PetscInt ti)
Reads statistical fields used for time-averaged simulations.
Definition io.c:1104
PetscErrorCode ParsePostProcessingSettings(SimCtx *simCtx)
Initializes post-processing settings from a config file and command-line overrides.
Definition io.c:2199
PetscErrorCode WriteAllSwarmFields(UserCtx *user)
Writes a predefined set of PETSc Swarm fields to files.
Definition io.c:1836
PetscErrorCode SwarmFieldToArrayOnRank0(DM swarm, const char *field_name, PetscInt *n_total_particles, PetscInt *n_components, void **gathered_array)
Gathers any DMSwarm field from all ranks to a single, contiguous array on rank 0.
Definition io.c:1989
PetscErrorCode ParseScalingInformation(SimCtx *simCtx)
Parses physical scaling parameters from command-line options.
Definition io.c:2334
PetscInt ReadDataFileToArray(const char *filename, double **data_out, PetscInt *Nout, MPI_Comm comm)
Definition io.c:2384
PetscErrorCode ReadGridFile(UserCtx *user)
Sets grid dimensions from a file for a SINGLE block using a one-time read cache.
Definition io.c:177
PetscErrorCode StringToBCHandlerType(const char *str, BCHandlerType *handler_out)
Converts a string representation of a handler to a BCHandlerType enum.
Definition io.c:314
PetscErrorCode ReadRANSFields(UserCtx *user, PetscInt ti)
Reads RANS-related fields for turbulence modeling.
Definition io.c:1162
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:356
PetscErrorCode ReadSwarmIntField(UserCtx *user, const char *field_name, PetscInt ti, const char *ext)
Reads integer swarm data by using ReadFieldData and casting the result.
Definition io.c:1249
PetscErrorCode WriteSwarmField(UserCtx *user, const char *field_name, PetscInt ti, const char *ext)
Writes data from a specific field in a PETSc Swarm to a file.
Definition io.c:1695
PetscErrorCode WriteStatisticalFields(UserCtx *user)
Writes statistical fields for averaging purposes.
Definition io.c:1599
PetscErrorCode ReadSimulationFields(UserCtx *user, PetscInt ti)
Reads binary field data for velocity, pressure, and other required vectors.
Definition io.c:1024
PetscErrorCode WriteFieldData(UserCtx *user, const char *field_name, Vec field_vec, PetscInt ti, const char *ext)
Writes data from a specific PETSc vector to a file.
Definition io.c:1429
PetscErrorCode ReadLESFields(UserCtx *user, PetscInt ti)
Reads LES-related fields used in turbulence modeling.
Definition io.c:1131
PetscErrorCode ReadFieldData(UserCtx *user, const char *field_name, Vec field_vec, PetscInt ti, const char *ext)
Reads data for a specific field from a file into the provided vector.
Definition io.c:823
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:399
PetscErrorCode ValidateBCHandlerForBCType(BCType type, BCHandlerType handler)
Validates that a specific handler is compatible with a general BC type.
Definition io.c:331
void TrimWhitespace(char *str)
Helper function to trim leading/trailing whitespace from a string.
Definition io.c:36
PetscErrorCode WriteSimulationFields(UserCtx *user)
Writes simulation fields to files.
Definition io.c:1536
PetscErrorCode ReadAllSwarmFields(UserCtx *user, PetscInt ti)
Reads multiple fields (positions, velocity, CellID, and weight) into a DMSwarm.
Definition io.c:1327
PetscErrorCode ReadGridGenerationInputs(UserCtx *user)
Parses command-line options for a programmatically generated grid for a SINGLE block.
Definition io.c:77
PetscErrorCode ReadSwarmField(UserCtx *user, const char *field_name, PetscInt ti, const char *ext)
Reads data from a file into a specified field of a PETSc DMSwarm.
Definition io.c:1204
PetscErrorCode WriteRANSFields(UserCtx *user)
Writes RANS-related fields.
Definition io.c:1661
PetscErrorCode ReadFieldDataToRank0(PetscInt timeIndex, const char *fieldName, UserCtx *user, double **scalarArray, PetscInt *Nscalars)
Reads a named field from file into a PETSc Vec, then gathers it to rank 0.
Definition io.c:2574
PetscErrorCode VecToArrayOnRank0(Vec inVec, PetscInt *N, double **arrayOut)
Gathers the contents of a distributed PETSc Vec into a single array on rank 0.
Definition io.c:1894
PetscErrorCode WriteSwarmIntField(UserCtx *user, const char *field_name, PetscInt ti, const char *ext)
Writes integer data from a specific PETSc Swarm field to a file.
Definition io.c:1764
PetscErrorCode WriteLESFields(UserCtx *user)
Writes LES-related fields.
Definition io.c:1627
PetscErrorCode StringToBCFace(const char *str, BCFace *face_out)
Converts a string representation of a face to a BCFace enum.
Definition io.c:280
PetscErrorCode ReadPositionsFromFile(PetscInt timeIndex, UserCtx *user, double **coordsArray, PetscInt *Ncoords)
Reads coordinate data (for particles) from file into a PETSc Vec, then gathers it to rank 0.
Definition io.c:2526
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:590
void FreeBC_ParamList(BC_Param *head)
Frees the memory allocated for a linked list of BC_Param structs.
Definition io.c:263
PetscInt CreateVTKFileFromMetadata(const char *filename, const VTKMetaData *meta, MPI_Comm comm)
Definition vtk_io.c:128
PetscErrorCode StringToBCType(const char *str, BCType *type_out)
Converts a string representation of a BC type to a BCType enum.
Definition io.c:297
PetscErrorCode DisplayBanner(SimCtx *simCtx)
Displays a structured banner summarizing the simulation configuration.
Definition io.c:2082
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:207
BCHandlerType
Defines the specific computational "strategy" for a boundary handler.
Definition variables.h:228
BCFace
Identifies the six logical faces of a structured computational block.
Definition variables.h:200
A node in a linked list for storing key-value parameters from the bcs.dat file.
Definition variables.h:245
The master context for the entire simulation.
Definition variables.h:538
User-defined context containing data specific to a single computational grid level.
Definition variables.h:661