PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
Loading...
Searching...
No Matches
vtk_io.h
Go to the documentation of this file.
1#ifndef VTK_IO_H
2#define VTK_IO_H
3
4#include "variables.h"
5#include "logging.h"
6#include "io.h"
7
8// --- Public Function Prototypes ---
9
10/**
11 * @brief Creates and writes a VTK file (either .vts or .vtp) from a populated metadata struct.
12 * @param[in] filename The output file name.
13 * @param[in] meta Pointer to a VTKMetaData structure containing all necessary fields.
14 * @param[in] comm The MPI communicator.
15 * @return 0 on success, non-zero on failure.
16 */
17PetscInt CreateVTKFileFromMetadata(const char *filename, const VTKMetaData *meta, MPI_Comm comm);
18
19/**
20 * @brief Creates a C array of coordinates corresponding to a subsampled (legacy-style) grid.
21 *
22 * This function gathers the full, distributed grid coordinates onto rank 0. On rank 0,
23 * it then allocates a new, smaller C array and copies only the coordinates for the
24 * nodes within the range [0..IM-2, 0..JM-2, 0..KM-2]. This produces a contiguous
25 * array of points for a grid of size (IM-1)x(JM-1)x(KM-1), matching the legacy output.
26 * The output arrays are only allocated and valid on rank 0.
27 *
28 * @param[in] user The UserCtx containing the grid information (DM, IM/JM/KM).
29 * @param[out] out_coords On rank 0, a pointer to the newly allocated C array for coordinate data. NULL on other ranks.
30 * @param[out] out_nx The number of points in the x-dimension for the new grid (IM-1).
31 * @param[out] out_ny The number of points in the y-dimension for the new grid (JM-1).
32 * @param[out] out_nz The number of points in the z-dimension for the new grid (KM-1).
33 * @param[out] out_npoints The total number of points in the new grid.
34 * @return PetscErrorCode
35 */
36PetscErrorCode PrepareOutputCoordinates(UserCtx* user, PetscScalar** out_coords, PetscInt* out_nx, PetscInt* out_ny, PetscInt* out_nz, PetscInt* out_npoints);
37
38/**
39 * @brief Creates a C array of field data corresponding to a subsampled (legacy-style) grid.
40 *
41 * This function gathers a full, distributed PETSc vector to rank 0. On rank 0,
42 * it then allocates a new, smaller C array and copies only the data components
43 * for nodes within the range [0..IM-2, 0..JM-2, 0..KM-2]. This produces a contiguous
44 * data array that perfectly matches the point ordering of the subsampled coordinates.
45 * The output array is only allocated and valid on rank 0.
46 *
47 * @param[in] user The UserCtx for grid information.
48 * @param[in] field_vec The full-sized PETSc vector containing the field data (e.g., user->P_nodal).
49 * @param[in] num_components The number of components for this field (1 for scalar, 3 for vector).
50 * @param[out] out_data On rank 0, a pointer to the newly allocated C array for the field data. NULL on other ranks.
51 * @return PetscErrorCode
52 */
53PetscErrorCode PrepareOutputEulerianFieldData(UserCtx* user, Vec field_vec, PetscInt num_components, PetscScalar** out_data);
54
55/**
56 * @brief Gathers, subsamples, and prepares all particle data for VTK output.
57 *
58 * This function is a COLLECTIVE operation. All ranks must enter it.
59 * The heavy lifting (memory allocation, subsampling) is performed only on rank 0.
60 *
61 * 1. Gathers the full coordinate and field data from the distributed DMSwarm to rank 0.
62 * 2. On rank 0, subsamples the data based on pps->particle_output_freq.
63 * 3. On rank 0, populates the VTKMetaData struct with the new, smaller, subsampled data arrays.
64 *
65 * @param[in] user The UserCtx containing the DMSwarm.
66 * @param[in] pps The PostProcessParams struct for configuration.
67 * @param[out] meta A pointer to the VTKMetaData struct to be populated (on rank 0).
68 * @param[out] p_n_total On rank 0, the total number of particles before subsampling.
69 * @return PetscErrorCode
70 */
71PetscErrorCode PrepareOutputParticleData(UserCtx* user, PostProcessParams* pps, VTKMetaData* meta, PetscInt* p_n_total);
72
73#endif // VTK_IO_H
74
Public interface for data input/output routines.
Logging utilities and macros for PETSc-based applications.
Main header file for a complex fluid dynamics solver.
Holds all configuration parameters for a post-processing run.
Definition variables.h:443
User-defined context containing data specific to a single computational grid level.
Definition variables.h:630
PetscErrorCode PrepareOutputEulerianFieldData(UserCtx *user, Vec field_vec, PetscInt num_components, PetscScalar **out_data)
Creates a C array of field data corresponding to a subsampled (legacy-style) grid.
Definition vtk_io.c:287
PetscErrorCode PrepareOutputCoordinates(UserCtx *user, PetscScalar **out_coords, PetscInt *out_nx, PetscInt *out_ny, PetscInt *out_nz, PetscInt *out_npoints)
Creates a C array of coordinates corresponding to a subsampled (legacy-style) grid.
Definition vtk_io.c:223
PetscInt CreateVTKFileFromMetadata(const char *filename, const VTKMetaData *meta, MPI_Comm comm)
Creates and writes a VTK file (either .vts or .vtp) from a populated metadata struct.
Definition vtk_io.c:128
PetscErrorCode PrepareOutputParticleData(UserCtx *user, PostProcessParams *pps, VTKMetaData *meta, PetscInt *p_n_total)
Gathers, subsamples, and prepares all particle data for VTK output.
Definition vtk_io.c:421