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 
34 namespace openPMD
35 {
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;
95  Mesh& setGeometry(std::string geometry);
96 
101  std::string geometryParameters() const;
108  Mesh& setGeometryParameters(std::string const& geometryParameters);
109 
113  DataOrder dataOrder() const;
120 
124  std::vector< std::string > axisLabels() const;
131  Mesh& setAxisLabels(std::vector< std::string > const & axisLabels);
132 
137  template< typename T >
138  std::vector< T > gridSpacing() const;
146  template< typename T,
147  typename = std::enable_if_t<std::is_floating_point< T >::value> >
148  Mesh& setGridSpacing(std::vector< T > const & gridSpacing);
149 
153  std::vector< double > gridGlobalOffset() const;
160  Mesh& setGridGlobalOffset(std::vector< double > const & gridGlobalOffset);
161 
165  double gridUnitSI() const;
171  Mesh& setGridUnitSI(double gridUnitSI);
172 
178  Mesh& setUnitDimension(std::map< UnitDimension, double > const& unitDimension);
179 
184  template< typename T >
185  T timeOffset() const;
193  template< typename T,
194  typename = std::enable_if_t<std::is_floating_point< T >::value> >
196 
197 private:
198  Mesh();
199 
200  void flush_impl(std::string const&) override;
201  void read() override;
202 }; // Mesh
203 
204 template< typename T >
205 inline std::vector< T >
207 { return readVectorFloatingpoint< T >("gridSpacing"); }
208 
209 template< typename T >
210 inline T
212 { return readFloatingpoint< T >("timeOffset"); }
213 
214 std::ostream&
215 operator<<(std::ostream&, openPMD::Mesh::Geometry const&);
216 
217 std::ostream&
218 operator<<(std::ostream&, openPMD::Mesh::DataOrder const&);
219 
220 } // openPMD
openPMD::Mesh::setTimeOffset
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:206
openPMD::Mesh::geometryParameters
std::string geometryParameters() const
Definition: Mesh.cpp:105
openPMD::BaseRecord
Definition: BaseRecord.hpp:36
openPMD::Mesh::gridUnitSI
double gridUnitSI() const
Definition: Mesh.cpp:179
openPMD::Mesh::timeOffset
T timeOffset() const
Definition: Mesh.hpp:211
openPMD::Mesh::geometryString
std::string geometryString() const
Definition: Mesh.cpp:56
openPMD::Mesh::dataOrder
DataOrder dataOrder() const
Definition: Mesh.cpp:118
openPMD::Mesh::setGridSpacing
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:147
openPMD::Mesh
Container for N-dimensional, homogeneous Records.
Definition: Mesh.hpp:40
openPMD::Mesh::Geometry
Geometry
Enumerated datatype for the geometry of the mesh.
Definition: Mesh.hpp:56
openPMD::UnitDimension::T
@ T
time
openPMD::BaseRecord< MeshRecordComponent >::unitDimension
std::array< double, 7 > unitDimension() const
Return the physical dimension (quantity) of a record.
Definition: BaseRecord.hpp:247
openPMD::Mesh::gridGlobalOffset
std::vector< double > gridGlobalOffset() const
Definition: Mesh.cpp:166
openPMD::Iteration
Logical compilation of data from one snapshot (e.g.
Definition: Iteration.hpp:39
openPMD
Public definitions of openPMD-api.
Definition: Date.cpp:29
openPMD::Mesh::setAxisLabels
Mesh & setAxisLabels(std::vector< std::string > const &axisLabels)
Set the ordering of the labels for the Mesh::geometry of the mesh.
Definition: Mesh.cpp:139
openPMD::Mesh::axisLabels
std::vector< std::string > axisLabels() const
Definition: Mesh.cpp:133
openPMD::Mesh::gridSpacing
std::vector< T > gridSpacing() const
Definition: Mesh.hpp:206
openPMD::Container
Map-like container that enforces openPMD requirements and handles IO.
Definition: Container.hpp:106
openPMD::Mesh::geometry
Geometry geometry() const
Definition: Mesh.cpp:46
openPMD::Mesh::setGridGlobalOffset
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:172
openPMD::Mesh::DataOrder
DataOrder
Enumerated datatype for the memory layout of N-dimensional data.
Definition: Mesh.hpp:67
openPMD::Mesh::setDataOrder
Mesh & setDataOrder(DataOrder dor)
Set the memory layout of N-dimensional data.
Definition: Mesh.cpp:124
openPMD::Mesh::setGeometry
Mesh & setGeometry(Geometry g)
Set the geometry of the mesh of the mesh record.
Definition: Mesh.cpp:62
openPMD::Mesh::setUnitDimension
Mesh & setUnitDimension(std::map< UnitDimension, double > const &unitDimension)
Set the powers of the 7 base measures characterizing the record's unit in SI.
Definition: Mesh.cpp:192
openPMD::Mesh::setGridUnitSI
Mesh & setGridUnitSI(double gridUnitSI)
Set the unit-conversion factor to multiply each value in Mesh::gridSpacing and Mesh::gridGlobalOffset...
Definition: Mesh.cpp:185
openPMD::Mesh::setGeometryParameters
Mesh & setGeometryParameters(std::string const &geometryParameters)
Set additional parameters for the geometry, separated by a.
Definition: Mesh.cpp:111