Skip to content

Commit 669b424

Browse files
committed
[Draft] MeshRecordComponent: Properties
Add `Mesh` properties as read-only properties to `MeshRecordComponent` as well. This simplifies read logic.
1 parent 14cf17a commit 669b424

File tree

7 files changed

+202
-14
lines changed

7 files changed

+202
-14
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Bug Fixes
3434
- ``flush()`` exceptions in ``~Series``/``~..IOHandler`` do not abort anymore #709
3535
- readme: python example syntax was broken and outdated #722
3636
- examples: fix ``"weighting"`` record attribute (ED-PIC) #728
37+
- ADIOS2: remove noisy warning for default options #733
3738

3839
Other
3940
"""""

include/openPMD/Mesh.hpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
#include "openPMD/backend/Attributable.hpp"
2424
#include "openPMD/backend/BaseRecord.hpp"
25+
#include "openPMD/backend/MeshGeometry.hpp"
26+
#include "openPMD/backend/MeshDataOrder.hpp"
2527
#include "openPMD/backend/MeshRecordComponent.hpp"
2628

2729
#include <array>
@@ -49,24 +51,14 @@ class Mesh : public BaseRecord< MeshRecordComponent >
4951
/** @brief Enumerated datatype for the geometry of the mesh.
5052
*
5153
* @note If the default values do not suit your application, you can set arbitrary
52-
* Geometry with MeshRecordComponent::setAttribute("geometry", VALUE).
54+
* Geometry with Mesh::setAttribute("geometry", VALUE).
5355
* Note that this might break openPMD compliance and tool support.
5456
*/
55-
enum class Geometry
56-
{
57-
cartesian,
58-
thetaMode,
59-
cylindrical,
60-
spherical
61-
}; //Geometry
57+
using Geometry = MeshGeometry;
6258

6359
/** @brief Enumerated datatype for the memory layout of N-dimensional data.
6460
*/
65-
enum class DataOrder : char
66-
{
67-
C = 'C',
68-
F = 'F'
69-
}; //DataOrder
61+
using DataOrder = MeshDataOrder;
7062

7163
/**
7264
* @return String representing the geometry of the mesh of the mesh record.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* Copyright 2017-2020 Axel Huebl, 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+
24+
namespace openPMD
25+
{
26+
/** @brief Enumerated datatype for the memory layout of N-dimensional data.
27+
*/
28+
enum class MeshDataOrder : char
29+
{
30+
C = 'C',
31+
F = 'F'
32+
};
33+
} // namespace openPMD
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* Copyright 2017-2020 Axel Huebl, 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+
24+
namespace openPMD
25+
{
26+
/** Enumerated datatype for the geometry of a mesh.
27+
*
28+
* Mesh geometries as defined in the openPMD base standard.
29+
*/
30+
enum class MeshGeometry
31+
{
32+
cartesian,
33+
thetaMode,
34+
cylindrical, // reserved
35+
spherical // reserved
36+
};
37+
} // namespace openPMD

include/openPMD/backend/MeshRecordComponent.hpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#pragma once
2222

2323
#include "openPMD/RecordComponent.hpp"
24+
#include "openPMD/backend/MeshGeometry.hpp"
25+
#include "openPMD/backend/MeshDataOrder.hpp"
2426

2527
#include <vector>
2628

@@ -76,6 +78,65 @@ class MeshRecordComponent : public RecordComponent
7678
*/
7779
template< typename T >
7880
MeshRecordComponent& makeConstant(T);
81+
82+
// below are read-only attributes from Mesh, duplicated for user read-convenience
83+
84+
/** @brief Enumerated datatype for the geometry of the mesh.
85+
*
86+
* @note If the default values do not suit your application, you can set arbitrary
87+
* Geometry with Mesh::setAttribute("geometry", VALUE).
88+
* Note that this might break openPMD compliance and tool support.
89+
*/
90+
using Geometry = MeshGeometry;
91+
92+
/** @brief Enumerated datatype for the memory layout of N-dimensional data.
93+
*/
94+
using DataOrder = MeshDataOrder;
95+
96+
/**
97+
* @return String representing the geometry of the mesh of the mesh record.
98+
*/
99+
Geometry geometry() const;
100+
101+
/**
102+
* @throw no_such_attribute_error If Mesh::geometry is not Mesh::Geometry::thetaMode.
103+
* @return String representing additional parameters for the geometry, separated by a @code ; @endcode.
104+
*/
105+
std::string geometryParameters() const;
106+
107+
/**
108+
* @return Memory layout of N-dimensional data.
109+
*/
110+
DataOrder dataOrder() const;
111+
112+
/**
113+
* @return Ordering of the labels for the Mesh::geometry of the mesh.
114+
*/
115+
std::vector< std::string > axisLabels() const;
116+
117+
/**
118+
* @tparam T Floating point type of user-selected precision (e.g. float, double).
119+
* @return vector of T representing the spacing of the grid points along each dimension (in the units of the simulation).
120+
*/
121+
template< typename T >
122+
std::vector< T > gridSpacing() const;
123+
124+
/**
125+
* @return Vector of (double) representing the start of the current domain of the simulation (position of the beginning of the first cell) in simulation units.
126+
*/
127+
std::vector< double > gridGlobalOffset() const;
128+
129+
/**
130+
* @return Unit-conversion factor to multiply each value in Mesh::gridSpacing and Mesh::gridGlobalOffset, in order to convert from simulation units to SI units.
131+
*/
132+
double gridUnitSI() const;
133+
134+
/**
135+
* @tparam T Floating point type of user-selected precision (e.g. float, double).
136+
* @return Offset between the time at which this record is defined and the Iteration::time attribute of the Series::basePath level.
137+
*/
138+
template< typename T >
139+
T timeOffset() const;
79140
};
80141

81142

@@ -91,4 +152,15 @@ MeshRecordComponent::makeConstant(T value)
91152
RecordComponent::makeConstant(value);
92153
return *this;
93154
}
155+
156+
template< typename T >
157+
inline std::vector< T >
158+
MeshRecordComponent::gridSpacing() const
159+
{ return m_writable->parent->attributable->readVectorFloatingpoint< T >("gridSpacing"); }
160+
161+
template< typename T >
162+
inline T
163+
MeshRecordComponent::timeOffset() const
164+
{ return m_writable->parent->attributable->readFloatingpoint< T >("timeOffset"); }
165+
94166
} // namespace openPMD

include/openPMD/backend/Writable.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class Writable final
6565
friend class Container;
6666
friend class Iteration;
6767
friend class Mesh;
68+
friend class MeshRecordComponent;
6869
friend class ParticleSpecies;
6970
friend class Series;
7071
friend class Record;

src/backend/MeshRecordComponent.cpp

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* and the GNU Lesser General Public License along with openPMD-api.
1919
* If not, see <http://www.gnu.org/licenses/>.
2020
*/
21+
#include "openPMD/backend/MeshDataOrder.hpp"
2122
#include "openPMD/backend/MeshRecordComponent.hpp"
2223

2324

@@ -54,6 +55,8 @@ MeshRecordComponent::read()
5455
else
5556
throw std::runtime_error( "Unexpected Attribute datatype for 'position'");
5657

58+
// auto xx = m_writable->parent->attributable->getAttribute("gridUnitSI").get< double >();
59+
5760
readBase();
5861
}
5962

@@ -77,4 +80,53 @@ MeshRecordComponent::setPosition(std::vector< double > pos);
7780
template
7881
MeshRecordComponent&
7982
MeshRecordComponent::setPosition(std::vector< long double > pos);
80-
} // openPMD
83+
84+
MeshGeometry
85+
MeshRecordComponent::geometry() const
86+
{
87+
auto const attributable = m_writable->parent->attributable;
88+
std::string ret = attributable->getAttribute("geometry").get< std::string >();
89+
if( "cartesian" == ret ) { return Geometry::cartesian; }
90+
else if( "thetaMode" == ret ) { return Geometry::thetaMode; }
91+
else if( "cylindrical" == ret ) { return Geometry::cylindrical; }
92+
else if( "spherical" == ret ) { return Geometry::spherical; }
93+
else { throw std::runtime_error("Unknown geometry " + ret); }
94+
}
95+
96+
std::string
97+
MeshRecordComponent::geometryParameters() const
98+
{
99+
auto const attributable = m_writable->parent->attributable;
100+
return attributable->getAttribute("geometryParameters").get< std::string >();
101+
}
102+
103+
MeshDataOrder
104+
MeshRecordComponent::dataOrder() const
105+
{
106+
auto const attributable = m_writable->parent->attributable;
107+
return MeshDataOrder(attributable->getAttribute("dataOrder").get< std::string >().c_str()[0]);
108+
}
109+
110+
std::vector< std::string >
111+
MeshRecordComponent::axisLabels() const
112+
{
113+
auto const attributable = m_writable->parent->attributable;
114+
return attributable->getAttribute("axisLabels").get< std::vector< std::string > >();
115+
}
116+
117+
118+
std::vector< double >
119+
MeshRecordComponent::gridGlobalOffset() const
120+
{
121+
auto const attributable = m_writable->parent->attributable;
122+
return attributable->getAttribute("gridGlobalOffset").get< std::vector< double> >();
123+
}
124+
125+
double
126+
MeshRecordComponent::gridUnitSI() const
127+
{
128+
auto const attributable = m_writable->parent->attributable;
129+
return attributable->getAttribute("gridUnitSI").get< double >();
130+
}
131+
132+
} // namespace openPMD

0 commit comments

Comments
 (0)