|
PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
|
Implementation of data input/output routines, focusing on grid configuration. More...
#include "io.h"Go to the source code of this file.
Macros | |
| #define | __FUNCT__ "ReadGridGenerationInputs" |
| #define | __FUNCT__ "ReadGridFile" |
| #define | __FUNCT__ "ParseAllBoundaryConditions" |
| #define | __FUNCT__ "ReadFieldData" |
| #define | __FUNCT__ "WriteFieldData" |
| #define | __FUNCT__ "ParsePostProcessingSettings" |
| #define | __FUNCT__ "ParseScalingInformation" |
Functions | |
| void | TrimWhitespace (char *str) |
| Trims leading and trailing whitespace from a string in-place. | |
| PetscErrorCode | ReadGridGenerationInputs (UserCtx *user) |
| Parses command-line options for a programmatically generated grid for a SINGLE block. | |
| PetscErrorCode | ReadGridFile (UserCtx *user) |
| Sets grid dimensions from a file for a SINGLE block using a one-time read cache. | |
| void | FreeBC_ParamList (BC_Param *head) |
| Frees the memory allocated for a linked list of BC_Param structs. | |
| PetscErrorCode | StringToBCFace (const char *str, BCFace *face_out) |
| Converts a string representation of a face to a BCFace enum. | |
| PetscErrorCode | StringToBCType (const char *str, BCType *type_out) |
| Converts a string representation of a BC type to a BCType enum. | |
| PetscErrorCode | StringToBCHandlerType (const char *str, BCHandlerType *handler_out) |
| Converts a string representation of a handler to a BCHandlerType enum. | |
| PetscErrorCode | ValidateBCHandlerForBCType (BCType type, BCHandlerType handler) |
| Validates that a specific handler is compatible with a general BC type. | |
| 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. | |
| PetscErrorCode | ParseAllBoundaryConditions (UserCtx *user, const char *bcs_input_filename) |
| Parses the boundary conditions file to configure the type, handler, and any associated parameters for all 6 global faces of the domain. | |
| 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. | |
| static PetscErrorCode | CheckDataFile (UserCtx *user, PetscInt ti, const char *fieldName, const char *ext, PetscBool *fileExists) |
| Checks for a data file's existence in a parallel-safe manner. | |
| static PetscErrorCode | ReadOptionalField (UserCtx *user, const char *field_name, const char *field_label, Vec field_vec, PetscInt ti, const char *ext) |
| Checks for and reads an optional Eulerian field from a file into a Vec. | |
| static PetscErrorCode | ReadOptionalSwarmField (UserCtx *user, const char *field_name, const char *field_label, PetscInt ti, const char *ext) |
| Checks for and reads an optional DMSwarm field from a file. | |
| 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. | |
| PetscErrorCode | ReadSimulationFields (UserCtx *user, PetscInt ti) |
| Reads simulation fields from files into their respective PETSc vectors. | |
| PetscErrorCode | ReadStatisticalFields (UserCtx *user, PetscInt ti) |
| Reads statistical fields for averaging purposes. | |
| PetscErrorCode | ReadLESFields (UserCtx *user, PetscInt ti) |
| Reads LES-related fields. | |
| PetscErrorCode | ReadRANSFields (UserCtx *user, PetscInt ti) |
| Reads RANS-related fields. | |
| 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. | |
| PetscErrorCode | ReadSwarmIntField (UserCtx *user, const char *field_name, PetscInt ti, const char *ext) |
| Reads integer swarm data by using ReadFieldData and casting the result. | |
| PetscErrorCode | ReadAllSwarmFields (UserCtx *user, PetscInt ti) |
| Reads multiple fields into a DMSwarm, gracefully handling missing optional files. | |
| 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 single, sequential file. | |
| PetscErrorCode | WriteSimulationFields (UserCtx *user) |
| Writes simulation fields to files. | |
| PetscErrorCode | WriteStatisticalFields (UserCtx *user) |
| Writes statistical fields for averaging purposes. | |
| PetscErrorCode | WriteLESFields (UserCtx *user) |
| Writes LES-related fields. | |
| PetscErrorCode | WriteRANSFields (UserCtx *user) |
| Writes RANS-related fields. | |
| 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. | |
| PetscErrorCode | WriteSwarmIntField (UserCtx *user, const char *field_name, PetscInt ti, const char *ext) |
| Writes integer swarm data by casting it to a temporary Vec and using WriteFieldData. | |
| PetscErrorCode | WriteAllSwarmFields (UserCtx *user) |
| Writes a predefined set of PETSc Swarm fields to files. | |
| PetscErrorCode | VecToArrayOnRank0 (Vec inVec, PetscInt *N, double **arrayOut) |
| Gather a (possibly distributed) PETSc Vec onto rank 0 as a contiguous C array. | |
| 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. | |
| PetscErrorCode | DisplayBanner (SimCtx *simCtx) |
| Displays a structured banner summarizing the simulation configuration. | |
| PetscErrorCode | ParsePostProcessingSettings (SimCtx *simCtx) |
| Initializes post-processing settings from a config file and command-line overrides. | |
| PetscErrorCode | ParseScalingInformation (SimCtx *simCtx) |
| Parses physical scaling parameters from command-line options. | |
| PetscInt | ReadDataFileToArray (const char *filename, double **data_out, PetscInt *Nout, MPI_Comm comm) |
| 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. | |
| 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. | |
Variables | |
| static PetscInt | g_nblk_from_file = 0 |
| Stores the number of blocks read from the grid file. | |
| static PetscInt * | g_IMs_from_file = NULL |
| Caches the IM dimensions for all blocks read from the grid file. | |
| static PetscInt * | g_JMs_from_file = NULL |
| Caches the JM dimensions for all blocks read from the grid file. | |
| static PetscInt * | g_KMs_from_file = NULL |
| Caches the KM dimensions for all blocks read from the grid file. | |
| static PetscBool | g_file_has_been_read = PETSC_FALSE |
| A flag to ensure the grid file is read only once. | |
Implementation of data input/output routines, focusing on grid configuration.
This module provides functions to parse grid geometry information, either from command-line options for programmatically generated grids or by reading the header of a grid definition file.
Definition in file io.c.
| void TrimWhitespace | ( | char * | str | ) |
Trims leading and trailing whitespace from a string in-place.
Helper function to trim leading/trailing whitespace from a string.
| str | The string to be trimmed. |
Definition at line 36 of file io.c.
| PetscErrorCode ReadGridGenerationInputs | ( | UserCtx * | user | ) |
Parses command-line options for a programmatically generated grid for a SINGLE block.
This function is responsible for reading all per-block array options related to grid geometry, such as dimensions (-im), domain bounds (-xMins, -xMaxs), and stretching ratios (-rxs). It reads the entire array for each option, then uses the block index stored in user->_this to select the correct value and populate the fields of the provided UserCtx struct.
| user | Pointer to the UserCtx for a specific block. The function will populate the geometric fields (IM, Min_X, rx, etc.) within this struct. |
Definition at line 77 of file io.c.
| PetscErrorCode ReadGridFile | ( | UserCtx * | user | ) |
Sets grid dimensions from a file for a SINGLE block using a one-time read cache.
This function uses a static-variable pattern to ensure the grid file header is read only once, collectively, by all processes. The first time any process calls this function, it triggers a collective operation where rank 0 reads the file and broadcasts the dimensions for all blocks. This data is stored in static "cached" arrays.
On every call (including the first), the function retrieves the dimensions for the specific block (identified by user->_this) from the cached arrays and populates the IM, JM, and KM fields of the provided UserCtx.
| user | Pointer to the UserCtx for a specific block. |
Definition at line 177 of file io.c.
| void FreeBC_ParamList | ( | BC_Param * | head | ) |
Frees the memory allocated for a linked list of BC_Param structs.
| head | A pointer to the head of the linked list to be freed. |
Definition at line 263 of file io.c.
| PetscErrorCode StringToBCFace | ( | const char * | str, |
| BCFace * | face_out | ||
| ) |
Converts a string representation of a face to a BCFace enum.
| str | The input string (e.g., "-Xi", "+Zeta"). Case-insensitive. | |
| [out] | face_out | The resulting BCFace enum. |
Definition at line 280 of file io.c.
| PetscErrorCode StringToBCType | ( | const char * | str, |
| BCType * | type_out | ||
| ) |
Converts a string representation of a BC type to a BCType enum.
| str | The input string (e.g., "WALL", "INLET"). Case-insensitive. | |
| [out] | type_out | The resulting BCType enum. |
Definition at line 297 of file io.c.
| PetscErrorCode StringToBCHandlerType | ( | const char * | str, |
| BCHandlerType * | handler_out | ||
| ) |
Converts a string representation of a handler to a BCHandlerType enum.
| str | The input string (e.g., "noslip", "constant_velocity"). Case-insensitive. | |
| [out] | handler_out | The resulting BCHandlerType enum. |
Definition at line 314 of file io.c.
| PetscErrorCode ValidateBCHandlerForBCType | ( | BCType | type, |
| BCHandlerType | handler | ||
| ) |
Validates that a specific handler is compatible with a general BC type.
| type | The general BCType. |
| handler | The specific BCHandlerType. |
Definition at line 331 of file io.c.
| 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.
| params | The head of the BC_Param linked list. | |
| key | The key to search for (case-insensitive). | |
| [out] | value_out | The found value, converted to a PetscReal. |
| [out] | found | Set to PETSC_TRUE if the key was found, PETSC_FALSE otherwise. |
Definition at line 356 of file io.c.
| PetscErrorCode ParseAllBoundaryConditions | ( | UserCtx * | user, |
| const char * | bcs_input_filename | ||
| ) |
Parses the boundary conditions file to configure the type, handler, and any associated parameters for all 6 global faces of the domain.
This function performs the following steps:
<Face> <Type> <Handler> [param=value]... format.user->boundary_faces array identically.| [in,out] | user | The main UserCtx struct where the final configuration for all ranks will be stored. |
| [in] | bcs_input_filename | The path to the boundary conditions configuration file. |
Definition at line 399 of file io.c.
| 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.
This function centralizes the logic for checking arbitrary paths. Only Rank 0 performs the filesystem check, and the result is broadcast to all other processes. This ensures collective and synchronized decision-making across all ranks. It is intended for configuration files, source directories, etc., where the path is known completely.
| [in] | path | The full path to the file or directory to check. |
| [in] | is_dir | PETSC_TRUE if checking for a directory, PETSC_FALSE for a file. |
| [in] | is_optional | PETSC_TRUE if the path is optional (results in a warning), PETSC_FALSE if mandatory (results in an error). |
| [in] | description | A user-friendly description of the path for logging (e.g., "Grid file"). |
| [out] | exists | The result of the check (identical on all ranks). |
Definition at line 590 of file io.c.
|
static |
Checks for a data file's existence in a parallel-safe manner.
This function's signature and behavior have been updated to use the "Directory Context Pointer" pattern. The high-level calling function (e.g., ReadSimulationFields) must set the simCtx->current_io_directory context before this function is called.
| [in] | user | Pointer to the UserCtx structure to access SimCtx. |
| ti | The time index of the file. | |
| fieldName | The name of the field. | |
| ext | The file extension. | |
| fileExists | [out] The result, which will be identical on all ranks. |
Definition at line 645 of file io.c.
|
static |
Checks for and reads an optional Eulerian field from a file into a Vec.
This helper function first checks if the corresponding data file exists in a parallel-safe manner using CheckDataFile().
| [in] | user | Pointer to the UserCtx structure. |
| [in] | field_name | Internal name of the field for the filename (e.g., "cs"). |
| [in] | field_label | A user-friendly name for logging (e.g., "Smagorinsky Constant"). |
| [in,out] | field_vec | The PETSc Vec to load the data into. |
| [in] | ti | Time index for the file name. |
| [in] | ext | File extension. |
Definition at line 703 of file io.c.
|
static |
Checks for and reads an optional DMSwarm field from a file.
This helper function first checks if the corresponding data file exists.
| [in] | user | Pointer to the UserCtx structure. |
| [in] | field_name | Internal name of the DMSwarm field (e.g., "DMSwarm_CellID"). |
| [in] | field_label | A user-friendly name for logging (e.g., "Cell ID"). |
| [in] | ti | Time index for the file name. |
| [in] | ext | File extension. |
Definition at line 753 of file io.c.
| 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.
This function uses the field name to construct the file path and reads the data from the corresponding file into the provided PETSc vector.
| [in] | user | Pointer to the UserCtx structure containing simulation context. |
| [in] | field_name | Name of the field (e.g., "ufield", "vfield", "pfield"). |
| [out] | field_vec | PETSc vector to store the field data. |
| [in] | ti | Time index for constructing the file name. |
| [in] | ext | File extension (e.g., "dat"). |
Definition at line 823 of file io.c.
| PetscErrorCode ReadSimulationFields | ( | UserCtx * | user, |
| PetscInt | ti | ||
| ) |
Reads simulation fields from files into their respective PETSc vectors.
Reads binary field data for velocity, pressure, and other required vectors.
This function reads contravariant velocity, Cartesian velocity, pressure, and node state fields from their respective binary files. It also conditionally reads LES, RANS, and statistical fields if they are enabled.
| [in,out] | user | Pointer to the UserCtx structure containing simulation context. |
| [in] | ti | Time index for constructing the file name. |
Definition at line 1024 of file io.c.
| PetscErrorCode ReadStatisticalFields | ( | UserCtx * | user, |
| PetscInt | ti | ||
| ) |
Reads statistical fields for averaging purposes.
Reads statistical fields used for time-averaged simulations.
This function reads data for fields such as Ucat_sum, Ucat_cross_sum, Ucat_square_sum, and P_sum, used for statistical analysis during simulation.
| [in,out] | user | Pointer to the UserCtx structure containing simulation context. |
| [in] | ti | Time index for constructing the file name. |
Definition at line 1104 of file io.c.
| PetscErrorCode ReadLESFields | ( | UserCtx * | user, |
| PetscInt | ti | ||
| ) |
Reads LES-related fields.
Reads LES-related fields used in turbulence modeling.
This function reads LES-related fields such as Cs (Smagorinsky constant) into their respective PETSc vectors.
| [in,out] | user | Pointer to the UserCtx structure containing simulation context. |
| [in] | ti | Time index for constructing the file name. |
Definition at line 1131 of file io.c.
| PetscErrorCode ReadRANSFields | ( | UserCtx * | user, |
| PetscInt | ti | ||
| ) |
Reads RANS-related fields.
Reads RANS-related fields for turbulence modeling.
This function reads RANS-related fields such as K_Omega into their respective PETSc vectors.
| [in,out] | user | Pointer to the UserCtx structure containing simulation context. |
| [in] | ti | Time index for constructing the file name. |
Definition at line 1162 of file io.c.
| 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.
This function is the counterpart to WriteSwarmField(). It creates a global PETSc vector that references the specified DMSwarm field, uses ReadFieldData() to read the data from a file, and then destroys the global vector reference.
| [in] | user | Pointer to the UserCtx structure (containing user->swarm). |
| [in] | field_name | Name of the DMSwarm field to read into (must be previously declared/allocated). |
| [in] | ti | Time index used to construct the input file name. |
| [in] | ext | File extension (e.g., "dat" or "bin"). |
Definition at line 1204 of file io.c.
| PetscErrorCode ReadSwarmIntField | ( | UserCtx * | user, |
| const char * | field_name, | ||
| PetscInt | ti, | ||
| const char * | ext | ||
| ) |
Reads integer swarm data by using ReadFieldData and casting the result.
This function is the counterpart to WriteSwarmIntField. It reads a file containing floating-point data (that was originally integer) into a temporary Vec and then casts it back to the integer swarm field. It works by:
| [in] | user | Pointer to the UserCtx structure. |
| [in] | field_name | Name of the integer Swarm field to be read. |
| [in] | ti | Time index for the input file. |
| [in] | ext | File extension. |
Definition at line 1249 of file io.c.
| PetscErrorCode ReadAllSwarmFields | ( | UserCtx * | user, |
| PetscInt | ti | ||
| ) |
Reads multiple fields into a DMSwarm, gracefully handling missing optional files.
Reads multiple fields (positions, velocity, CellID, and weight) into a DMSwarm.
This function reads all necessary and optional fields for a DMSwarm for a given timestep. It assumes the swarm has already been resized to match the particle count in the input files.
The 'position' field is considered MANDATORY. If its file is missing or corrupt, the function will return a fatal error.
All other fields (velocity, CellID, weight, etc.) are OPTIONAL. If their corresponding files are not found, a warning is logged, and the function continues without error. If an optional file IS found but is corrupt or has a size mismatch, it is treated as a fatal error.
| [in,out] | user | Pointer to the UserCtx structure containing the DMSwarm (user->swarm). |
| [in] | ti | Time index for constructing the file names. |
Definition at line 1327 of file io.c.
| 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 single, sequential file.
Writes data from a specific PETSc vector to a file.
This function is now parallel-safe.
This ensures the output file is always in a simple, portable format.
| [in] | user | Pointer to the UserCtx structure. |
| [in] | field_name | Name of the field (e.g., "position"). |
| [in] | field_vec | The parallel PETSc vector containing the data to write. |
| [in] | ti | Time index for constructing the file name. |
| [in] | ext | File extension (e.g., "dat"). |
Dump a distributed PETSc Vec to the single sequential file format used by our restart / post-processing tools.
The companion of ReadFieldData(): it always produces one file (e.g. results/ufield00006_0.dat) regardless of how many MPI ranks are running.
Behaviour
| # MPI ranks | Strategy |
|---|---|
| 1 | Direct VecView() into the file. |
| > 1 | VecScatterCreateToZero() gathers the distributed Vec onto rank 0. |
| Rank 0 writes the sequential Vec; all other ranks allocate no storage. |
The routine never alters or destroys the parallel Vec passed in; the gather buffer is created and freed internally.
| [in] | user | Simulation context (used only for logging). |
| [in] | field_name | Logical field name (forms part of the filename). |
| [in] | field_vec | Distributed PETSc Vec to write. |
| [in] | ti | Timestep index used in the filename. |
| [in] | ext | File extension ("dat" in our workflow). |
0 on success or a PETSc error code. Definition at line 1429 of file io.c.
| PetscErrorCode WriteSimulationFields | ( | UserCtx * | user | ) |
Writes simulation fields to files.
This function writes contravariant velocity, Cartesian velocity, pressure, and node state fields to their respective binary files. It also conditionally writes LES, RANS, and statistical fields if they are enabled.
| [in] | user | Pointer to the UserCtx structure containing simulation context. |
Definition at line 1536 of file io.c.
| PetscErrorCode WriteStatisticalFields | ( | UserCtx * | user | ) |
Writes statistical fields for averaging purposes.
This function writes data for fields such as Ucat_sum, Ucat_cross_sum, Ucat_square_sum, and P_sum to their respective binary files.
| [in] | user | Pointer to the UserCtx structure containing simulation context. |
Definition at line 1599 of file io.c.
| PetscErrorCode WriteLESFields | ( | UserCtx * | user | ) |
Writes LES-related fields.
This function writes LES-related fields such as Cs (Smagorinsky constant) to their respective binary files.
| [in] | user | Pointer to the UserCtx structure containing simulation context. |
Definition at line 1627 of file io.c.
| PetscErrorCode WriteRANSFields | ( | UserCtx * | user | ) |
Writes RANS-related fields.
This function writes RANS-related fields such as K_Omega to their respective binary files.
| [in] | user | Pointer to the UserCtx structure containing simulation context. |
Definition at line 1661 of file io.c.
| 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.
This function retrieves the Swarm from the UserCtx (i.e., user->swarm) and creates a global PETSc vector from the specified Swarm field. It then calls the existing WriteFieldData() function to handle the actual I/O operation. After writing the data, the function destroys the temporary global vector to avoid memory leaks.
| [in] | user | Pointer to the UserCtx structure containing simulation context and the PetscSwarm (as user->swarm). |
| [in] | field_name | Name of the Swarm field to be written (e.g., "my_field"). |
| [in] | ti | Time index used to construct the output file name. |
| [in] | ext | File extension (e.g., "dat", "bin"). |
Definition at line 1695 of file io.c.
| PetscErrorCode WriteSwarmIntField | ( | UserCtx * | user, |
| const char * | field_name, | ||
| PetscInt | ti, | ||
| const char * | ext | ||
| ) |
Writes integer swarm data by casting it to a temporary Vec and using WriteFieldData.
Writes integer data from a specific PETSc Swarm field to a file.
This function provides a bridge to write integer-based swarm fields (like DMSwarm_CellID) using the existing Vec-based I/O routine (WriteFieldData). It works by:
| [in] | user | Pointer to the UserCtx structure. |
| [in] | field_name | Name of the integer Swarm field to be written. |
| [in] | ti | Time index for the output file. |
| [in] | ext | File extension. |
Definition at line 1764 of file io.c.
| PetscErrorCode WriteAllSwarmFields | ( | UserCtx * | user | ) |
Writes a predefined set of PETSc Swarm fields to files.
This function iterates through a hardcoded list of common swarm fields (position, velocity, etc.) and calls the WriteSwarmField() helper function for each one. This provides a straightforward way to output essential particle data at a given simulation step.
This function will only execute if particles are enabled in the simulation (i.e., user->simCtx->np > 0 and user->swarm is not NULL).
| [in] | user | Pointer to the UserCtx structure containing the simulation context and the PetscSwarm. |
Definition at line 1836 of file io.c.
| PetscErrorCode VecToArrayOnRank0 | ( | Vec | inVec, |
| PetscInt * | N, | ||
| double ** | arrayOut | ||
| ) |
Gather a (possibly distributed) PETSc Vec onto rank 0 as a contiguous C array.
Gathers the contents of a distributed PETSc Vec into a single array on rank 0.
If the Vec has a DMDA attached, the gather is performed in DMDA "natural" ordering.
| [in] | inVec | The PETSc Vec (may be distributed). |
| [out] | N | Global length of the Vec (includes dof). |
| [out] | arrayOut | On rank 0, newly allocated buffer with the gathered values (PetscScalar-sized). On other ranks, set to NULL. |
Definition at line 1894 of file io.c.
| 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.
This is a generic, type-aware version of SwarmFieldToArrayOnRank0. It is a COLLECTIVE operation.
| [in] | swarm | The DMSwarm to gather from. |
| [in] | field_name | The name of the field to gather. |
| [out] | n_total_particles | (Output on rank 0) Total number of particles in the global swarm. |
| [out] | n_components | (Output on rank 0) Number of components for the field. |
| [out] | gathered_array | (Output on rank 0) A newly allocated array containing the full, gathered data. The caller is responsible for freeing this memory and for casting it to the correct type. |
Definition at line 1989 of file io.c.
| PetscErrorCode DisplayBanner | ( | SimCtx * | simCtx | ) |
Displays a structured banner summarizing the simulation configuration.
This function prints key simulation parameters to standard output. It is intended to be called ONLY by MPI rank 0. It retrieves global domain bounds from user->global_domain_bbox and boundary conditions for all faces from user->face_bc_types.
| [in] | user | Pointer to UserCtx structure. |
| [in] | StartTime | Initial simulation time. |
| [in] | StartStep | Starting timestep index. |
| [in] | StepsToRun | Total number of timesteps to run. |
| [in] | num_mpi_procs | Total number of MPI processes. |
| [in] | total_num_particles | Total number of particles. |
| [in] | bboxlist | (If rank 0 needed to compute global_domain_bbox here, otherwise NULL) |
0 on success. Definition at line 2082 of file io.c.
| PetscErrorCode ParsePostProcessingSettings | ( | SimCtx * | simCtx | ) |
Initializes post-processing settings from a config file and command-line overrides.
This function establishes the configuration for a post-processing run by:
| configFile | The path to the configuration file to parse. |
| pps | Pointer to the PostProcessParams struct to be populated. |
Definition at line 2199 of file io.c.
| PetscErrorCode ParseScalingInformation | ( | SimCtx * | simCtx | ) |
Parses physical scaling parameters from command-line options.
This function reads the reference length, velocity, and density from the PETSc options database (provided via -scaling_L_ref, etc.). It populates the simCtx->scaling struct and calculates the derived reference pressure. It sets default values of 1.0 for a fully non-dimensional case if the options are not provided.
| [in,out] | simCtx | The simulation context whose 'scaling' member will be populated. |
Definition at line 2334 of file io.c.
| PetscInt ReadDataFileToArray | ( | const char * | filename, |
| double ** | data_out, | ||
| PetscInt * | Nout, | ||
| MPI_Comm | comm | ||
| ) |
Definition at line 2384 of file io.c.
| 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.
This function uses ReadFieldData to fill a PETSc Vec with coordinate data, then leverages VecToArrayOnRank0 to gather that data into a contiguous array (valid on rank 0 only).
| [in] | timeIndex | The time index used to construct file names. |
| [in] | user | Pointer to the user context. |
| [out] | coordsArray | On rank 0, will point to a newly allocated array holding the coordinates. |
| [out] | Ncoords | On rank 0, the length of coordsArray. On other ranks, 0. |
Definition at line 2526 of file io.c.
| 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.
This function wraps ReadFieldData and VecToArrayOnRank0 into a single step. The gathered data is stored in scalarArray on rank 0, with its length in Nscalars.
| [in] | timeIndex | The time index used to construct file names. |
| [in] | fieldName | Name of the field to be read (e.g., "velocity"). |
| [in] | user | Pointer to the user context. |
| [out] | scalarArray | On rank 0, a newly allocated array holding the field data. |
| [out] | Nscalars | On rank 0, length of scalarArray. On other ranks, 0. |
Definition at line 2574 of file io.c.
|
static |
|
static |
|
static |
|
static |