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