openPMD-api
 
Loading...
Searching...
No Matches
Mesh.hpp
1/* Copyright 2017-2025 Fabian Koller, Axel Huebl, Franz Poeschel
2 *
3 * This file is part of openPMD-api.
4 *
5 * openPMD-api is free software: you can redistribute it and/or modify
6 * it under the terms of of either the GNU General Public License or
7 * the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * openPMD-api is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License and the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * and the GNU Lesser General Public License along with openPMD-api.
19 * If not, see <http://www.gnu.org/licenses/>.
20 */
21#pragma once
22
23#include "openPMD/UnitDimension.hpp"
24#include "openPMD/backend/Attributable.hpp"
25#include "openPMD/backend/BaseRecord.hpp"
26#include "openPMD/backend/MeshRecordComponent.hpp"
27
28#include <ostream>
29#include <string>
30#include <type_traits>
31#include <vector>
32
33namespace openPMD
34{
40class Mesh : public BaseRecord<MeshRecordComponent>
41{
42 friend class Container<Mesh>;
43 friend class Iteration;
44
45public:
46 Mesh(Mesh const &) = default;
47 Mesh &operator=(Mesh const &) = default;
48 ~Mesh() override = default;
49
56 enum class Geometry
57 {
58 cartesian,
59 thetaMode,
60 cylindrical,
61 spherical,
62 other
63 }; // Geometry
64
67 enum class DataOrder : char
68 {
69 C = 'C',
70 F = 'F'
71 }; // DataOrder
72
76 Geometry geometry() const;
80 std::string geometryString() const;
95 Mesh &setGeometry(std::string geometry);
96
103 std::string geometryParameters() const;
112 Mesh &setGeometryParameters(std::string const &geometryParameters);
113
117 DataOrder dataOrder() const;
124
128 std::vector<std::string> axisLabels() const;
136 Mesh &setAxisLabels(std::vector<std::string> const &axisLabels);
137
144 template <typename T>
145 std::vector<T> gridSpacing() const;
156 template <
157 typename T,
158 typename = std::enable_if_t<std::is_floating_point<T>::value>>
159 Mesh &setGridSpacing(std::vector<T> const &gridSpacing);
160
166 std::vector<double> gridGlobalOffset() const;
175 Mesh &setGridGlobalOffset(std::vector<double> const &gridGlobalOffset);
176
182 double gridUnitSI() const;
197
214 Mesh &setGridUnitSI(std::vector<double> const &gridUnitSI);
215
222 std::vector<double> gridUnitSIPerDimension() const;
223
224 /* Set the unit-conversion factors per axis to multiply each value in
225 * Mesh::gridSpacing and Mesh::gridGlobalOffset, in order to convert from
226 * simulation units to SI units.
227 *
228 * Valid for openPMD 2.*.
229 * The legacy behavior (openPMD 1.*, a scalar gridUnitSI) is implemented
230 * by `setGridUnitSI(double)`.
231 *
232 * @param gridUnitSI unit-conversion factor to multiply each value in
233 * Mesh::gridSpacing and Mesh::gridGlobalOffset, in order to convert from
234 * simulation units to SI units.
235 *
236 * @return Reference to modified mesh.
237 */
238 Mesh &setGridUnitSIPerDimension(std::vector<double> const &gridUnitSI);
239
247 Mesh &setUnitDimension(unit_representations::AsMap const &unitDimension);
248
256 Mesh &setUnitDimension(unit_representations::AsArray const &unitDimension);
257
270 Mesh &
271 setGridUnitDimension(unit_representations::AsMaps const &gridUnitDimension);
272
286 unit_representations::AsArrays const &gridUnitDimension);
287
299 unit_representations::AsArrays gridUnitDimension() const;
300
307 template <typename T>
308 T timeOffset() const;
320 template <
321 typename T,
322 typename = std::enable_if_t<std::is_floating_point<T>::value>>
324
325private:
326 Mesh();
327
328 void
329 flush_impl(std::string const &, internal::FlushParams const &) override;
330 void read();
331}; // Mesh
332
333template <typename T>
334inline std::vector<T> Mesh::gridSpacing() const
335{
336 return readVectorFloatingpoint<T>("gridSpacing");
337}
338
339template <typename T>
340inline T Mesh::timeOffset() const
341{
342 return readFloatingpoint<T>("timeOffset");
343}
344
345std::ostream &operator<<(std::ostream &, openPMD::Mesh::Geometry const &);
346
347std::ostream &operator<<(std::ostream &, openPMD::Mesh::DataOrder const &);
348
349} // namespace openPMD
std::vector< T > readVectorFloatingpoint(std::string const &key) const
Retrieve a vector of values of a floating point Attributes of user-defined precision with ensured typ...
Definition Attributable.hpp:669
T readFloatingpoint(std::string const &key) const
Retrieve the value of a floating point Attribute of user-defined precision with ensured type-safety.
Definition Attributable.hpp:658
unit_representations::AsArray unitDimension() const
Map-like container that enforces openPMD requirements and handles IO.
Definition Container.hpp:104
Container for N-dimensional, homogeneous Records.
Definition Mesh.hpp:41
std::string geometryString() const
Definition Mesh.cpp:75
Geometry geometry() const
Definition Mesh.cpp:50
Mesh & setAxisLabels(std::vector< std::string > const &axisLabels)
Set the ordering of the labels for the Mesh::geometry of the mesh.
Definition Mesh.cpp:149
std::vector< std::string > axisLabels() const
Definition Mesh.cpp:144
std::vector< double > gridUnitSIPerDimension() const
Definition Mesh.cpp:229
T timeOffset() const
Definition Mesh.hpp:340
unit_representations::AsArrays gridUnitDimension() const
Return the physical dimensions of the mesh axes.
Definition Mesh.cpp:316
std::vector< T > gridSpacing() const
Definition Mesh.hpp:334
DataOrder dataOrder() const
Definition Mesh.cpp:132
Mesh & setGridUnitSI(double gridUnitSI)
Set the unit-conversion factor to multiply each value in Mesh::gridSpacing and Mesh::gridGlobalOffset...
Definition Mesh.cpp:186
Mesh & setGridSpacing(std::vector< T > const &gridSpacing)
Set the spacing of the grid points along each dimension (in the units of the simulation).
Definition Mesh.cpp:156
std::string geometryParameters() const
Definition Mesh.cpp:121
Mesh & setTimeOffset(T timeOffset)
Set the offset between the time at which this record is defined and the Iteration::time attribute of ...
Definition Mesh.cpp:351
Mesh & setDataOrder(DataOrder dor)
Set the memory layout of N-dimensional data.
Definition Mesh.cpp:138
Mesh & setGeometry(Geometry g)
Set the geometry of the mesh of the mesh record.
Definition Mesh.cpp:80
std::vector< double > gridGlobalOffset() const
Definition Mesh.cpp:170
Mesh & setGridGlobalOffset(std::vector< double > const &gridGlobalOffset)
Set the start of the current domain of the simulation (position of the beginning of the first cell) i...
Definition Mesh.cpp:175
double gridUnitSI() const
Definition Mesh.cpp:181
Mesh & setUnitDimension(unit_representations::AsMap const &unitDimension)
Set the powers of the 7 base measures characterizing the record's unit in SI.
Definition Mesh.cpp:268
Geometry
Enumerated datatype for the geometry of the mesh.
Definition Mesh.hpp:57
Mesh & setGridUnitDimension(unit_representations::AsMaps const &gridUnitDimension)
Set the unitDimension for each axis of the current grid.
Definition Mesh.cpp:286
Mesh & setGeometryParameters(std::string const &geometryParameters)
Set additional parameters for the geometry, separated by a.
Definition Mesh.cpp:126
DataOrder
Enumerated datatype for the memory layout of N-dimensional data.
Definition Mesh.hpp:68
Public definitions of openPMD-api.
Definition Date.cpp:29
@ T
time
Definition UnitDimension.hpp:41
Parameters recursively passed through the openPMD hierarchy when flushing.
Definition AbstractIOHandler.hpp:106