2020 */
2121#pragma once
2222
23+ #include " openPMD/UnitDimension.hpp"
2324#include " openPMD/backend/Attributable.hpp"
2425#include " openPMD/backend/BaseRecord.hpp"
2526#include " openPMD/backend/MeshRecordComponent.hpp"
2627
27- #include < array>
2828#include < ostream>
2929#include < string>
3030#include < type_traits>
@@ -155,7 +155,7 @@ class Mesh : public BaseRecord<MeshRecordComponent>
155155 */
156156 template <
157157 typename T,
158- typename = std::enable_if_t <std::is_floating_point<T>::value> >
158+ typename = std::enable_if_t <std::is_floating_point<T>::value>>
159159 Mesh &setGridSpacing (std::vector<T> const &gridSpacing);
160160
161161 /* *
@@ -184,22 +184,119 @@ class Mesh : public BaseRecord<MeshRecordComponent>
184184 * Mesh::gridSpacing and Mesh::gridGlobalOffset, in order to convert from
185185 * simulation units to SI units.
186186 *
187+ * Valid for openPMD version 1.*.
188+ * In order to specify the gridUnitSI per dimension (openPMD 2.*),
189+ * use the vector overload or `setGridUnitSIPerDimension()`.
190+ *
187191 * @param gridUnitSI unit-conversion factor to multiply each value in
188192 * Mesh::gridSpacing and Mesh::gridGlobalOffset, in order to convert from
189193 * simulation units to SI units.
190194 * @return Reference to modified mesh.
191195 */
192196 Mesh &setGridUnitSI (double gridUnitSI);
193197
198+ /* * Alias for `setGridUnitSIPerDimension(std::vector<double>)`.
199+ *
200+ * Set the unit-conversion factors per axis to multiply each value in
201+ * Mesh::gridSpacing and Mesh::gridGlobalOffset, in order to convert from
202+ * simulation units to SI units.
203+ *
204+ * Valid for openPMD 2.*.
205+ * The legacy behavior (openPMD 1.*, a scalar gridUnitSI) is implemented
206+ * by `setGridUnitSI(double)`.
207+ *
208+ * @param gridUnitSI unit-conversion factor to multiply each value in
209+ * Mesh::gridSpacing and Mesh::gridGlobalOffset, in order to convert from
210+ * simulation units to SI units.
211+ *
212+ * @return Reference to modified mesh.
213+ */
214+ Mesh &setGridUnitSI (std::vector<double > const &gridUnitSI);
215+
216+ /* *
217+ * @return A vector of the gridUnitSI per grid axis in the order of
218+ * the axisLabels. If the gridUnitSI is defined as a scalar
219+ * (legacy openPMD), the dimensionality is determined and a vector of
220+ * `dimensionality` times the scalar vector is returned.
221+ */
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+
194240 /* * Set the powers of the 7 base measures characterizing the record's unit
195241 * in SI.
196242 *
197243 * @param unitDimension map containing pairs of (UnitDimension, double)
198244 * that represent the power of the particular base.
199245 * @return Reference to modified mesh.
200246 */
247+ Mesh &setUnitDimension (unit_representations::AsMap const &unitDimension);
248+
249+ /* * Set the powers of the 7 base measures characterizing the record's unit
250+ * in SI.
251+ *
252+ * @param unitDimension array containing seven doubles, each
253+ * representing the power of the particular base in order.
254+ * @return Reference to modified mesh.
255+ */
256+ Mesh &setUnitDimension (unit_representations::AsArray const &unitDimension);
257+
258+ /* *
259+ * @brief Set the unitDimension for each axis of the current grid.
260+ *
261+ * @param gridUnitDimension A vector of the unitDimensions for each
262+ * axis of the grid in the order of the axisLabels, in dict representation.
263+
264+ * Behavior note: This is an updating method, meaning that an SI unit that
265+ * has been defined before and is in the next call not explicitly set
266+ * in the `std::map<UnitDimension, double>` will keep its previous value.
267+ *
268+ * @return Reference to modified mesh.
269+ */
201270 Mesh &
202- setUnitDimension (std::map<UnitDimension, double > const &unitDimension);
271+ setGridUnitDimension (unit_representations::AsMaps const &gridUnitDimension);
272+
273+ /* *
274+ * @brief Set the unitDimension for each axis of the current grid.
275+ *
276+ * @param gridUnitDimension A vector of the unitDimensions for each
277+ * axis of the grid in the order of the axisLabels, in array representation.
278+
279+ * Behavior note: This is an updating method, meaning that an SI unit that
280+ * has been defined before and is in the next call not explicitly set
281+ * in the `std::map<UnitDimension, double>` will keep its previous value.
282+ *
283+ * @return Reference to modified mesh.
284+ */
285+ Mesh &setGridUnitDimension (
286+ unit_representations::AsArrays const &gridUnitDimension);
287+
288+ /* *
289+ * @brief Return the physical dimensions of the mesh axes.
290+
291+ * If the attribute is not defined, the axes are assumed to be spatial
292+ * and the return value will be according to this assumption.
293+ * If the attribute is defined, the dimensionality of the return value is
294+ * not checked against the dimensionality of the mesh.
295+ *
296+ * @return A vector of arrays, each array representing the SI unit of one
297+ * mesh axis.
298+ */
299+ unit_representations::AsArrays gridUnitDimension () const ;
203300
204301 /* *
205302 * @tparam T Floating point type of user-selected precision (e.g. float,
@@ -222,7 +319,7 @@ class Mesh : public BaseRecord<MeshRecordComponent>
222319 */
223320 template <
224321 typename T,
225- typename = std::enable_if_t <std::is_floating_point<T>::value> >
322+ typename = std::enable_if_t <std::is_floating_point<T>::value>>
226323 Mesh &setTimeOffset (T timeOffset);
227324
228325private:
0 commit comments