chombo-discharge
Loading...
Searching...
No Matches
CD_DischargeIOImplem.H
Go to the documentation of this file.
1/* chombo-discharge
2 * Copyright © 2024 SINTEF Energy Research.
3 * Please refer to Copyright.txt and LICENSE in the chombo-discharge root directory.
4 */
5
12#ifndef CD_DischargeIOImplem_H
13#define CD_DischargeIOImplem_H
14
15// Std includes
16#ifdef CH_USE_HDF5
17#include <hdf5.h>
18#endif
19
20// Our includes
21#include <CD_DischargeIO.H>
22#include <CD_NamespaceHeader.H>
23
24template <size_t M, size_t N>
25void
30 const RealVect a_shift,
31 const Real a_time) noexcept
32{
33#ifdef CH_USE_HDF5
34 CH_TIME("DischargeIO::writeH5Part");
35
36 CH_assert(a_realVars.size() == 0 || a_realVars.size() == M);
37 CH_assert(a_vectVars.size() == 0 || a_vectVars.size() == N);
38
41
42 if (a_realVars.size() == M) {
44
45 for (int i = 0; i < M; i++) {
46 if (realVariables[i] == "") {
47 realVariables[i] = "real-" + std::to_string(i);
48 }
49 }
50 }
51 else {
52 for (int i = 0; i < M; i++) {
53 realVariables[i] = "real-" + std::to_string(i);
54 }
55 }
56
57 if (a_vectVars.size() == N) {
59
60 for (int i = 0; i < N; i++) {
61 if (vectVariables[i] == "") {
62 vectVariables[i] = "vect-" + std::to_string(i);
63 }
64 }
65 }
66 else {
67 for (int i = 0; i < N; i++) {
68 vectVariables[i] = "vect-" + std::to_string(i);
69 }
70 }
71
72 // Figure out the number of particles on each rank
73 const unsigned long long numParticlesLocal = a_particles.getNumberOfValidParticlesLocal();
74 const unsigned long long numParticlesGlobal = a_particles.getNumberOfValidParticlesGlobal();
75
77#ifdef CH_MPI
78 particlesPerRank.resize(numProc(), 0ULL);
79
82 for (int i = 0; i < numProc(); i++) {
83 displ[i] = i;
84 }
86 1,
89 &recv[0],
90 &displ[0],
93#else
94 particlesPerRank.resize(1);
96#endif
97
98 // Set up file access and create the file.
99 hid_t fileAccess = 0;
100#ifdef CH_MPI
103#endif
104
107
108 // Define the top group necessary for the H5Part file format
110
111 // Write the time attribute
115
116 H5Sclose(scal);
117 H5Aclose(attr);
118
119 // Define dataspace dimensions.
120 hsize_t dims[1];
122
123 hid_t fileSpaceID = H5Screate_simple(1, dims, nullptr);
124
125 // Memory space
126 hsize_t memDims[1];
129
130 // Set hyperslabs for file and memory
133
134 hsize_t memStart[1];
135 hsize_t memCount[1];
136
137 memStart[0] = 0;
138 fileStart[0] = 0;
139 for (int i = 0; i < procID(); i++) {
141 }
144
147
148 // Create the ID and positional data sets
152#if CH_SPACEDIM == 3
154#endif
155
156 // Write ID data set
161
162 for (int lvl = 0; lvl <= a_particles.getFinestLevel(); lvl++) {
163
164 const DisjointBoxLayout& dbl = a_particles.getGrids()[lvl];
165 const DataIterator& dit = dbl.dataIterator();
166
167 const int nbox = dit.size();
168
169 for (int mybox = 0; mybox < nbox; mybox++) {
170 const DataIndex& din = dit[mybox];
171
173
175 id.push_back(procID());
176 x.push_back(lit().position()[0] - a_shift[0]);
177 y.push_back(lit().position()[1] - a_shift[1]);
178#if CH_SPACEDIM == 3
179 z.push_back(lit().position()[2] - a_shift[2]);
180#endif
181 }
182 }
183 }
184
188#if CH_SPACEDIM == 3
190#endif
191
192 id.resize(0);
193 x.resize(0);
194 y.resize(0);
195 z.resize(0);
196
197 // Close the ID and positional data sets
201#if CH_SPACEDIM == 3
203#endif
204
205 // Write the M real-variables
206 for (int curVar = 0; curVar < M; curVar++) {
214
216
217 for (int lvl = 0; lvl <= a_particles.getFinestLevel(); lvl++) {
218
219 const DisjointBoxLayout& dbl = a_particles.getGrids()[lvl];
220 const DataIterator& dit = dbl.dataIterator();
221
222 const int nbox = dit.size();
223
224 for (int mybox = 0; mybox < nbox; mybox++) {
225 const DataIndex& din = dit[mybox];
226
228
230 ds.push_back(lit().getReals()[curVar]);
231 }
232 }
233 }
234
235 // Write and clsoe dataset
238 }
239
240 // Write the N vector variables
241 for (int curVar = 0; curVar < N; curVar++) {
242 for (int dir = 0; dir < SpaceDim; dir++) {
244 if (dir == 0) {
245 varName = vectVariables[curVar] + "-x";
246 }
247 else if (dir == 1) {
248 varName = vectVariables[curVar] + "-y";
249 }
250 else if (dir == 2) {
251 varName = vectVariables[curVar] + "-z";
252 }
253
255 varName.c_str(),
261
263
264 for (int lvl = 0; lvl <= a_particles.getFinestLevel(); lvl++) {
265
266 const DisjointBoxLayout& dbl = a_particles.getGrids()[lvl];
267 const DataIterator& dit = dbl.dataIterator();
268
269 const int nbox = dit.size();
270
271 for (int mybox = 0; mybox < nbox; mybox++) {
272 const DataIndex& din = dit[mybox];
273
275
277 const RealVect var = lit().getVects()[curVar];
278
279 ds.push_back(var[dir]);
280 }
281 }
282 }
283
284 // Write and close dataset
287 }
288 }
289
290 // Close top group and file
291 H5Gclose(grp);
293#endif
294}
295
296#include <CD_NamespaceFooter.H>
297
298#endif
Silly, but useful functions that override standard Chombo HDF5 IO.
Templated class for holding particles on an AMR hierarchy with particle remapping.
Definition CD_ParticleContainer.H:50
Base class for a tracer particle solver. This solver can advance particles in a pre-defined velocity ...
Definition CD_TracerParticleSolver.H:37
TracerParticleSolver()
Default constructor.
Definition CD_TracerParticleSolverImplem.H:25
void writeH5Part(const std::string a_filename, const ParticleContainer< GenericParticle< M, N > > &a_particles, const std::vector< std::string > a_realVars=std::vector< std::string >(), const std::vector< std::string > a_vectVars=std::vector< std::string >(), const RealVect a_shift=RealVect::Zero, const Real a_time=0.0) noexcept
A shameless copy of Chombo's writeEBHDF5 but including the lower-left corner of the physical domain a...
Definition CD_DischargeIOImplem.H:26