Skip to content

Commit

Permalink
Python documentation, C++ documentation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Nov 4, 2024
1 parent 6ae9e1c commit 44decb6
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 8 deletions.
8 changes: 4 additions & 4 deletions include/openPMD/Mesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ class Mesh : public BaseRecord<MeshRecordComponent>

/** Alias for `setGridUnitSIPerDimension(std::vector<double>)`.
*
* Set the unit-conversion factor per dimension to multiply each value in
* Set the unit-conversion factors per axis to multiply each value in
* Mesh::gridSpacing and Mesh::gridGlobalOffset, in order to convert from
* simulation units to SI units.
*
Expand All @@ -214,14 +214,14 @@ class Mesh : public BaseRecord<MeshRecordComponent>
Mesh &setGridUnitSI(std::vector<double> gridUnitSI);

/**
* @return A vector of the gridUnitSI per grid dimension as defined
* by the axisLabels. If the gridUnitSI is defined as a scalar
* @return A vector of the gridUnitSI per grid axis in the order of
* the axisLabels. If the gridUnitSI is defined as a scalar
* (legacy openPMD), the dimensionality is determined and a vector of
* `dimensionality` times the scalar vector is returned.
*/
std::vector<double> gridUnitSIPerDimension() const;

/* Set the unit-conversion factor per dimension to multiply each value in
/* Set the unit-conversion factors per axis to multiply each value in
* Mesh::gridSpacing and Mesh::gridGlobalOffset, in order to convert from
* simulation units to SI units.
*
Expand Down
26 changes: 24 additions & 2 deletions include/openPMD/binding/python/UnitDimension.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace openPMD
{
namespace python
{
constexpr auto doc_unit_dimension = R"docstr(
constexpr auto doc_unit_dimension = &R"docstr(
Return the physical dimension (quantity) of a record
Annotating the physical dimension of a record allows us to read data
Expand All @@ -40,7 +40,29 @@ See https://en.wikipedia.org/wiki/International_System_of_Quantities#Base_quanti
See https://github.com/openPMD/openPMD-standard/blob/1.1.0/STANDARD.md#required-for-each-record
Returns the powers of the 7 base measures in the order specified above.
)docstr";
)docstr"[1];

constexpr auto doc_mesh_unit_dimension = &R"docstr(
Return the physical dimension (quantity) of the record axes
Annotating the physical dimension of the record axes allows us to read data
sets with arbitrary names and understand their purpose simply by
dimensional analysis. The dimensional base quantities in openPMD are
in order: length (L), mass (M), time (T), electric current (I),
thermodynamic temperature (theta), amount of substance (N),
luminous intensity (J) after the international system of quantities
(ISQ).
This attribute may be left out, the axes will then be interpreted as spatial.
See https://en.wikipedia.org/wiki/Dimensional_analysis
See https://en.wikipedia.org/wiki/International_System_of_Quantities#Base_quantities
See https://github.com/openPMD/openPMD-standard/blob/1.1.0/STANDARD.md#required-for-each-record
Returns the powers of the 7 base measures in the order specified above, listed
for each axis in the order of the axisLabels.
This attribute has been introduced as part of openPMD 2.0.0 in:
Ref.: https://github.com/openPMD/openPMD-standard/pull/193
)docstr"[1];

} // namespace python
} // namespace openPMD
33 changes: 31 additions & 2 deletions src/binding/python/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ void init_Mesh(py::module &m)
.def_property(
"grid_unit_dimension",
&Mesh::gridUnitDimension,
&Mesh::setGridUnitDimension)
&Mesh::setGridUnitDimension,
python::doc_mesh_unit_dimension)

.def_property(
"geometry",
Expand Down Expand Up @@ -105,6 +106,13 @@ void init_Mesh(py::module &m)
&Mesh::setGridGlobalOffset)
.def_property(
"grid_unit_SI",
/*
* Using pybind11's support for std::variant in order to implement a
* polymorphic type for this property. Will be a scalar double in
* openPMD 1.*, a list of double in openPMD 2.*.
* Unlike in the C++ API, this means that no new API calls
* such as gridUnitSIPerDimension() must be added.
*/
[](Mesh &self) {
using return_t = std::variant<double, std::vector<double>>;
if (self.openPMDStandard() < OpenpmdStandard::v_2_0_0)
Expand All @@ -123,7 +131,28 @@ void init_Mesh(py::module &m)
static_cast<decltype(arg_resolved)>(arg_resolved));
},
arg);
})
},
&R"(
For openPMD versions 1.*:
Set the unit-conversion factor to multiply each value in
Mesh.grid_spacing and Mesh.grid_global_offset, in order to convert from
simulation units to SI units.
The type is a scalar floating point.
For openPMD versions 2.*:
Set the unit-conversion **factors per axis** in the order of the axisLabels
to multiply each value in Mesh.grid_spacing and Mesh.grid_global_offset,
in order to convert from simulation units to SI units.
The type is a list of floating points.
When writing a scalar value to an openPMD 2.* file, a warning will be printed
(for enabling a more comfortable migration to openPMD 2.*).
When writing a list value to an openPMD 1.* file, an error will be thrown,
since most openPMD 1.*-based readers will not be able to interpret this
properly.
Ref.: https://github.com/openPMD/openPMD-standard/pull/193)"[1])
.def_property(
"time_offset",
&Mesh::timeOffset<double>,
Expand Down

0 comments on commit 44decb6

Please sign in to comment.