4#include <pybind11/eigen.h>
5#include <pybind11/pybind11.h>
6#include <pybind11/stl.h>
8#include <range/v3/range/conversion.hpp>
9#include <range/v3/view/transform.hpp>
19namespace py = pybind11;
30 py::object
const& coordinates)
32 if (coordinates.is_none())
36 return std::make_optional<MathLib::Point3d>(
37 py::cast<std::array<double, 3>>(coordinates));
48 return py::array_t<double>(3, opt_coords->data());
55 py::class_<SpatialPosition>(m,
"SpatialPosition",
57 Describes a spatial position within a mesh or domain.
59 A SpatialPosition may refer to a node (via node ID), an element (via element ID),
60 or a physical point in space (via coordinates). It is typically used when evaluating
61 material properties that depend on the spatial context within a simulation.
63 The position may be partially specified. For example:
64 - Only coordinates for geometric evaluation
65 - Only node ID for nodal properties
66 - Only element ID for element-wise values
67 - Or any combination of the above
69 The class is used as a parameter to property evaluations in the OGS material properties library.
72 [](std::optional<std::size_t> node_id,
73 std::optional<std::size_t>
75 py::object const& coordinates)
81 py::arg(
"node_id") = std::nullopt,
82 py::arg(
"element_id") = std::nullopt,
83 py::arg(
"coords") = py::none(),
85 SpatialPosition(node_id=None, element_id=None, coords=None)
88 node_id (int, optional): Node ID
89 element_id (int, optional): Element ID
90 coords (array-like of 3 floats, optional): Coordinates
99 Node ID of the spatial position.
101 This property can be read and set from Python. Setting to None is not supported.
110 Element ID of the spatial position.
112 This property can be read and set from Python. Setting to None is not supported.
124 Coordinates of the spatial position as a 3-element array.
126 This property can be read and set from Python. Use a 3-element list, tuple,
127 or NumPy array. Setting to None is not supported.
136 auto const element_id =
141 return "<SpatialPosition(" + node_id +
", " + element_id +
142 ", " + py::str(coords).cast<std::string>() +
")>";
145 Return string representation of the SpatialPosition.
151 py::class_<VariableArray>(m,
"VariableArray")
155 .def_readwrite(
"deformation_gradient",
158 .def_readwrite(
"effective_pore_pressure",
161 .def_readwrite(
"enthalpy_of_evaporation",
163 .def_readwrite(
"equivalent_plastic_strain",
166 .def_readwrite(
"grain_compressibility",
168 .def_readwrite(
"liquid_phase_pressure",
173 .def_readwrite(
"molar_mass_derivative",
178 .def_readwrite(
"solid_grain_pressure",
191 py::enum_<Variable>(m,
"Variable")
223 py::class_<Property>(m,
"Property", R
"pbdoc(
224 Base class for material properties.
230 {
return p.
value(va, pos, t, dt); },
231 py::arg(
"variable_array"),
236 Evaluate the property value.
239 variable_array: Current time step values.
240 pos: Spatial position.
249 double dt) {
return p.
value(va, vap, pos, t, dt); },
250 py::arg(
"variable_array"),
251 py::arg(
"variable_array_prev"),
256 Evaluate the property value with previous time step data.
259 variable_array: Current time step values.
260 variable_array_prev: Previous time step values.
261 pos: Spatial position.
271 {
return p.
dValue(va, vap, var, pos, t, dt); },
272 py::arg(
"variable_array"),
273 py::arg(
"variable_array_prev"),
279 Evaluate the derivative of the property with respect to a variable,
280 using previous time step data.
283 variable_array: Current time step values.
284 variable_array_prev: Previous time step values.
285 variable: Variable to differentiate with respect to.
286 pos: Spatial position.
295 {
return p.
dValue(va, var, pos, t, dt); },
296 py::arg(
"variable_array"),
302 Evaluate the derivative of the property with respect to a variable.
305 variable_array: Current time step values.
306 variable: Variable to differentiate with respect to.
307 pos: Spatial position.
315 py::class_<Constant, Property>(m,
"Constant", R
"pbdoc(
316 Constant property with a fixed value.
318 .def(py::init<std::string, PropertyDataType>(),
322 Construct a Constant property.
325 name: Name of the property.
326 value: Constant value.
332 py::class_<Linear, Property>(m,
"Linear", R
"pbdoc(
333 Linearly interpolated property dependent on independent variables.
342 {
return std::make_from_tuple<IndependentVariable>(iv); };
344 auto independent_variables =
345 ivs | ranges::views::transform(makeIV) |
346 ranges::to<std::vector>();
347 return std::make_unique<Linear>(
name, reference_value,
348 independent_variables);
351 py::arg(
"reference_value"),
352 py::arg(
"independent_variables"),
354 Construct a Linear property.
357 name: Name of the property.
358 reference_value: Base property value.
359 independent_variables: List of tuples (variable, reference condition, slope), each defining a linear dependency on a variable.
372 m.attr(
"__name__") =
"ogs.mpl";
373 m.doc() =
"pybind11 ogs MPL bindings";
virtual PropertyDataType value() const
virtual PropertyDataType dValue(VariableArray const &variable_array, VariableArray const &variable_array_prev, Variable const variable, ParameterLib::SpatialPosition const &pos, double const t, double const dt) const
KelvinVector mechanical_strain
DeformationGradient deformation_gradient
KelvinVector total_stress
double solid_grain_pressure
double transport_porosity
double grain_compressibility
double molar_mass_derivative
KelvinVector total_strain
double gas_phase_pressure
double effective_pore_pressure
double equivalent_plastic_strain
double capillary_pressure
double enthalpy_of_evaporation
double liquid_phase_pressure
std::optional< std::size_t > getNodeID() const
void setNodeID(std::size_t node_id)
std::optional< std::size_t > getElementID() const
void setCoordinates(MathLib::Point3d const &coordinates)
void setElementID(std::size_t element_id)
std::optional< MathLib::Point3d > const getCoordinates() const
void initOGSLogger(std::string const &log_level)
std::variant< std::monostate, double, Eigen::Vector< double, 4 >, Eigen::Vector< double, 5 >, Eigen::Vector< double, 6 >, Eigen::Vector< double, 9 > > VariableType
@ enthalpy_of_evaporation
@ equivalent_plastic_strain
@ effective_pore_pressure
std::variant< double, Eigen::Matrix< double, 2, 1 >, Eigen::Matrix< double, 3, 1 >, Eigen::Matrix< double, 2, 2 >, Eigen::Matrix< double, 3, 3 >, Eigen::Matrix< double, 4, 1 >, Eigen::Matrix< double, 6, 1 >, Eigen::MatrixXd > PropertyDataType
void bindSpatialPosition(py::module_ &m)
void bindConstant(py::module_ &m)
void bindLinear(py::module_ &m)
void bindVariableArray(py::module_ &m)
void bindVariableEnum(py::module_ &m)
std::optional< MathLib::Point3d > pythonToSpatialPositionCoords(py::object const &coordinates)
py::object spatialPositionCoordsToPython(SpatialPosition const &pos)
void bindProperty(py::module_ &m)