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 Writes one VTK file (.vts or .vtp) collectively from every rank's part of it.
12 * @details Rank 0 writes the XML header, each block's byte count and the footer; every rank
13 * writes its own points into each appended block through MPI-IO, so no rank holds
14 * more than its own part. The file is the same whatever the rank count. Block byte
15 * counts are UInt64 (`header_type="UInt64"`), so no block size limit applies.
16 * @param[in] filename The output file name.
17 * @param[in] meta This rank's part of the file (see VTKMetaData).
18 * @param[in] comm The communicator all of whose ranks call this.
19 * @return 0 on success, or a PETSc error.
20 */
21PetscErrorCode CreateVTKFileFromMetadata(const char *filename, const VTKMetaData *meta, MPI_Comm comm);
22
23/**
24 * @brief Copies this rank's part of the output grid's coordinates.
25 *
26 * The output grid is the nodes [0..IM-2, 0..JM-2, 0..KM-2], a grid of (IM-1)x(JM-1)x(KM-1)
27 * points. This rank's part is its owned nodes within it, i fastest.
28 *
29 * @param[in] user The UserCtx containing the grid information (DM, IM/JM/KM).
30 * @param[out] out_coords Newly allocated coordinates of this rank's points (x, y, z each).
31 * @param[out] out_nx The number of points in the x-dimension for the new grid (IM-1).
32 * @param[out] out_ny The number of points in the y-dimension for the new grid (JM-1).
33 * @param[out] out_nz The number of points in the z-dimension for the new grid (KM-1).
34 * @param[out] out_npoints The total number of points in the new grid.
35 * @param[out] local_start First output point of this rank's box on each axis.
36 * @param[out] local_size Points in this rank's box on each axis (zero for a rank holding only dummy nodes).
37 * @return PetscErrorCode
38 */
39PetscErrorCode PrepareOutputCoordinates(UserCtx* user, PetscScalar** out_coords, PetscInt* out_nx, PetscInt* out_ny, PetscInt* out_nz,
40 PetscInt* out_npoints, PetscInt local_start[3], PetscInt local_size[3]);
41
42/**
43 * @brief Copies this rank's part of a nodal field on the output grid.
44 *
45 * The points and their order are those of PrepareOutputCoordinates() on the same rank, with
46 * the field's components interleaved.
47 *
48 * @param[in] user The UserCtx for grid information.
49 * @param[in] field_vec The full-sized PETSc vector containing the field data (e.g., user->P_nodal).
50 * @param[in] num_components The number of components for this field (1 for scalar, 3 for vector).
51 * @param[out] out_data Newly allocated values of this rank's points.
52 * @return PetscErrorCode
53 */
54PetscErrorCode PrepareOutputEulerianFieldData(UserCtx* user, Vec field_vec, PetscInt num_components, PetscScalar** out_data);
55
56/**
57 * @brief Begins one structured VTK file: clears the metadata and builds its coordinates.
58 *
59 * Every Eulerian VTK file is assembled the same way — coordinates, then a set of
60 * point-data fields, then the write. This trio exists so the two producers share that
61 * shape instead of restating it, and so the buffers each producer allocates are
62 * released in one place rather than in neither.
63 *
64 * @param[in] user Block context supplying the grid.
65 * @param[out] meta Metadata to initialize.
66 * @return Zero on success, or a PETSc error.
67 */
68PetscErrorCode BeginStructuredVTKOutput(UserCtx *user, VTKMetaData *meta);
69
70/**
71 * @brief Adds one point-data field to a structured VTK file being assembled.
72 *
73 * Skips the field with a warning when the file is already at its field limit, so a
74 * long output list degrades rather than corrupting the metadata.
75 *
76 * @param[in] user Block context supplying the grid.
77 * @param[in,out] meta Metadata to append to.
78 * @param[in] name Field name as it will appear in the file.
79 * @param[in] field_vec Nodal vector holding the values.
80 * @param[in] components One for a scalar, three for a vector.
81 * @return Zero on success, or a PETSc error.
82 */
83PetscErrorCode AppendStructuredVTKField(UserCtx *user, VTKMetaData *meta, const char *name,
84 Vec field_vec, PetscInt components);
85
86/**
87 * @brief Writes an assembled structured VTK file and releases its buffers.
88 * @param[in,out] meta Metadata to write and then release.
89 * @param[in] filename Destination path.
90 * @return Zero on success, or a PETSc error.
91 */
92PetscErrorCode FinishStructuredVTKOutput(VTKMetaData *meta, const char *filename);
93
94/**
95 * @brief Prepares this rank's part of the subsampled particle VTK output.
96 *
97 * Collective: all ranks must enter it. Particles are numbered in rank order and every
98 * pps->particle_output_freq-th one is kept; each rank copies only its own kept particles
99 * (positions, the requested fields, connectivity and offsets), with no gather. With no
100 * particles, only `meta->fileType` is set and nothing is allocated.
101 *
102 * @param[in] user The UserCtx containing the DMSwarm.
103 * @param[in] pps The PostProcessParams struct for configuration.
104 * @param[out] meta Zeroed metadata to populate with this rank's part (see VTKMetaData).
105 * @param[out] p_n_total The total number of particles before subsampling, on every rank.
106 * @return PetscErrorCode
107 */
108PetscErrorCode PrepareOutputParticleData(UserCtx* user, PostProcessParams* pps, VTKMetaData* meta, PetscInt* p_n_total);
109
110#endif // VTK_IO_H
111
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:793
User-defined context containing data specific to a single computational grid level.
Definition variables.h:1157
One VTK file being assembled collectively.
Definition variables.h:871
PetscErrorCode CreateVTKFileFromMetadata(const char *filename, const VTKMetaData *meta, MPI_Comm comm)
Writes one VTK file (.vts or .vtp) collectively from every rank's part of it.
Definition vtk_io.c:172
PetscErrorCode PrepareOutputEulerianFieldData(UserCtx *user, Vec field_vec, PetscInt num_components, PetscScalar **out_data)
Copies this rank's part of a nodal field on the output grid.
Definition vtk_io.c:361
PetscErrorCode FinishStructuredVTKOutput(VTKMetaData *meta, const char *filename)
Writes an assembled structured VTK file and releases its buffers.
Definition vtk_io.c:336
PetscErrorCode BeginStructuredVTKOutput(UserCtx *user, VTKMetaData *meta)
Begins one structured VTK file: clears the metadata and builds its coordinates.
Definition vtk_io.c:285
PetscErrorCode PrepareOutputCoordinates(UserCtx *user, PetscScalar **out_coords, PetscInt *out_nx, PetscInt *out_ny, PetscInt *out_nz, PetscInt *out_npoints, PetscInt local_start[3], PetscInt local_size[3])
Copies this rank's part of the output grid's coordinates.
Definition vtk_io.c:260
PetscErrorCode AppendStructuredVTKField(UserCtx *user, VTKMetaData *meta, const char *name, Vec field_vec, PetscInt components)
Adds one point-data field to a structured VTK file being assembled.
Definition vtk_io.c:305
PetscErrorCode PrepareOutputParticleData(UserCtx *user, PostProcessParams *pps, VTKMetaData *meta, PetscInt *p_n_total)
Prepares this rank's part of the subsampled particle VTK output.
Definition vtk_io.c:384