openPMD-api
Mesh.hpp
1 /* Copyright 2017-2021 Fabian Koller
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/backend/Attributable.hpp"
24 #include "openPMD/backend/BaseRecord.hpp"
25 #include "openPMD/backend/MeshRecordComponent.hpp"
26 
27 #include <array>
28 #include <ostream>
29 #include <string>
30 #include <type_traits>
31 #include <vector>
32 
33 namespace openPMD
34 {
40 class Mesh : public BaseRecord<MeshRecordComponent>
41 {
42  friend class Container<Mesh>;
43  friend class Iteration;
44 
45 public:
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;
86  Mesh &setGeometry(Geometry g);
95  Mesh &setGeometry(std::string geometry);
96 
103  std::string geometryParameters() const;
112  Mesh &setGeometryParameters(std::string const &geometryParameters);
113 
117  DataOrder dataOrder() const;
123  Mesh &setDataOrder(DataOrder dor);
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;
192  Mesh &setGridUnitSI(double gridUnitSI);
193 
201  Mesh &
202  setUnitDimension(std::map<UnitDimension, double> const &unitDimension);
203 
210  template <typename T>
211  T timeOffset() const;
223  template <
224  typename T,
225  typename = std::enable_if_t<std::is_floating_point<T>::value> >
226  Mesh &setTimeOffset(T timeOffset);
227 
228 private:
229  Mesh();
230 
231  void
232  flush_impl(std::string const &, internal::FlushParams const &) override;
233  void read() override;
234 }; // Mesh
235 
236 template <typename T>
237 inline std::vector<T> Mesh::gridSpacing() const
238 {
239  return readVectorFloatingpoint<T>("gridSpacing");
240 }
241 
242 template <typename T>
243 inline T Mesh::timeOffset() const
244 {
245  return readFloatingpoint<T>("timeOffset");
246 }
247 
248 std::ostream &operator<<(std::ostream &, openPMD::Mesh::Geometry const &);
249 
250 std::ostream &operator<<(std::ostream &, openPMD::Mesh::DataOrder const &);
251 
252 } // namespace openPMD
Geometry
Enumerated datatype for the geometry of the mesh.
Definition: Mesh.hpp:56
DataOrder
Enumerated datatype for the memory layout of N-dimensional data.
Definition: Mesh.hpp:67
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:152
std::string geometryParameters() const
Definition: Mesh.cpp:117
std::vector< double > gridGlobalOffset() const
Definition: Mesh.cpp:166
Logical compilation of data from one snapshot (e.g.
Definition: Iteration.hpp:126
Mesh & setGeometry(Geometry g)
Set the geometry of the mesh of the mesh record.
Definition: Mesh.cpp:76
Mesh & setDataOrder(DataOrder dor)
Set the memory layout of N-dimensional data.
Definition: Mesh.cpp:134
Mesh & setUnitDimension(std::map< UnitDimension, double > const &unitDimension)
Set the powers of the 7 base measures characterizing the record&#39;s unit in SI.
Definition: Mesh.cpp:188
Mesh & setGridUnitSI(double gridUnitSI)
Set the unit-conversion factor to multiply each value in Mesh::gridSpacing and Mesh::gridGlobalOffset...
Definition: Mesh.cpp:182
std::string geometryString() const
Definition: Mesh.cpp:71
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:171
DataOrder dataOrder() const
Definition: Mesh.cpp:128
T timeOffset() const
Definition: Mesh.hpp:243
Public definitions of openPMD-api.
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:201
double gridUnitSI() const
Definition: Mesh.cpp:177
std::array< double, 7 > unitDimension() const
Return the physical dimension (quantity) of a record.
Definition: BaseRecord.hpp:58
Parameters recursively passed through the openPMD hierarchy when flushing.
Definition: AbstractIOHandler.hpp:84
std::vector< std::string > axisLabels() const
Definition: Mesh.cpp:140
Mesh & setAxisLabels(std::vector< std::string > const &axisLabels)
Set the ordering of the labels for the Mesh::geometry of the mesh.
Definition: Mesh.cpp:145
Container for N-dimensional, homogeneous Records.
Definition: Mesh.hpp:40
Geometry geometry() const
Definition: Mesh.cpp:46
Map-like container that enforces openPMD requirements and handles IO.
Definition: Container.hpp:131
std::vector< T > gridSpacing() const
Definition: Mesh.hpp:237
Mesh & setGeometryParameters(std::string const &geometryParameters)
Set additional parameters for the geometry, separated by a.
Definition: Mesh.cpp:122