OGS
anonymous_namespace{ogs_mpl.cpp} Namespace Reference

Functions

std::optional< MathLib::Point3dpythonToSpatialPositionCoords (py::object const &coordinates)
py::object spatialPositionCoordsToPython (SpatialPosition const &pos)
void bindSpatialPosition (py::module_ &m)
void bindVariableArray (py::module_ &m)
void bindVariableEnum (py::module_ &m)
void bindProperty (py::module_ &m)
void bindConstant (py::module_ &m)
void bindLinear (py::module_ &m)

Function Documentation

◆ bindConstant()

void anonymous_namespace{ogs_mpl.cpp}::bindConstant ( py::module_ & m)

Definition at line 238 of file ogs_mpl.cpp.

238 :
239 variable_array: Current time step values.
240 pos: Spatial position.
241 t: Current time.
242 dt: Time step size.
243 )pbdoc")
244
245 .def(

Referenced by PYBIND11_MODULE().

◆ bindLinear()

void anonymous_namespace{ogs_mpl.cpp}::bindLinear ( py::module_ & m)

Definition at line 247 of file ogs_mpl.cpp.

249 { return p.value(va, vap, pos, t, dt); },
250 py::arg("variable_array"),
251 py::arg("variable_array_prev"),
252 py::arg("pos"),
253 py::arg("t"),
254 py::arg("dt"),
255 R"pbdoc(
256 Evaluate the property value with previous time step data.
257
258 Parameters:
259 variable_array: Current time step values.
260 variable_array_prev: Previous time step values.
261 pos: Spatial position.
262 t: Current time.
263 dt: Time step size.
264 )pbdoc")
265
266 .def(
267 "dValue",
268 [](const Property& p, const VariableArray& va,
269 const VariableArray& vap, Variable var,

References MaterialPropertyLib::Property::value().

Referenced by PYBIND11_MODULE().

◆ bindProperty()

void anonymous_namespace{ogs_mpl.cpp}::bindProperty ( py::module_ & m)

Definition at line 185 of file ogs_mpl.cpp.

190{
191 py::enum_<Variable>(m, "Variable")
192 .value("capillary_pressure", Variable::capillary_pressure)
193 .value("concentration", Variable::concentration)
194 .value("deformation_gradient", Variable::deformation_gradient)
195 .value("density", Variable::density)
196 .value("effective_pore_pressure", Variable::effective_pore_pressure)
197 .value("enthalpy", Variable::enthalpy)
198 .value("enthalpy_of_evaporation", Variable::enthalpy_of_evaporation)
199 .value("equivalent_plastic_strain", Variable::equivalent_plastic_strain)
200 .value("fracture_aperture", Variable::fracture_aperture)
201 .value("grain_compressibility", Variable::grain_compressibility)
202 .value("liquid_phase_pressure", Variable::liquid_phase_pressure)
203 .value("liquid_saturation", Variable::liquid_saturation)
204 .value("mechanical_strain", Variable::mechanical_strain)
205 .value("molar_mass", Variable::molar_mass)
206 .value("molar_mass_derivative", Variable::molar_mass_derivative)
207 .value("molar_fraction", Variable::molar_fraction)
208 .value("gas_phase_pressure", Variable::gas_phase_pressure)
209 .value("porosity", Variable::porosity)
210 .value("solid_grain_pressure", Variable::solid_grain_pressure)
211 .value("stress", Variable::stress)
212 .value("temperature", Variable::temperature)
213 .value("total_strain", Variable::total_strain)
214 .value("total_stress", Variable::total_stress)
215 .value("transport_porosity", Variable::transport_porosity)
216 .value("vapour_pressure", Variable::vapour_pressure)
217 .value("volumetric_strain", Variable::volumetric_strain)
218 .export_values();
219}
220
221void bindProperty(py::module_& m)
222{
223 py::class_<Property>(m, "Property", R"pbdoc(
224 Base class for material properties.
225 )pbdoc")
226 .def(
227 "value",
228 [](const Property& p, const VariableArray& va,
229 const SpatialPosition& pos, double t, double dt)
230 { return p.value(va, pos, t, dt); },
231 py::arg("variable_array"),
232 py::arg("pos"),
233 py::arg("t"),
234 py::arg("dt"),
235 R"pbdoc(
236 Evaluate the property value.
virtual PropertyDataType value() const
void bindProperty(py::module_ &m)
Definition ogs_mpl.cpp:185

References MaterialPropertyLib::VariableArray::vapour_pressure, and MaterialPropertyLib::VariableArray::volumetric_strain.

Referenced by PYBIND11_MODULE().

◆ bindSpatialPosition()

void anonymous_namespace{ogs_mpl.cpp}::bindSpatialPosition ( py::module_ & m)

Definition at line 53 of file ogs_mpl.cpp.

54{
55 py::class_<SpatialPosition>(m, "SpatialPosition",
56 R"pbdoc(
57 Describes a spatial position within a mesh or domain.
58
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.
62
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
68
69 The class is used as a parameter to property evaluations in the OGS material properties library.
70)pbdoc")
71 .def(py::init(
72 [](std::optional<std::size_t> node_id,
73 std::optional<std::size_t>
74 element_id,
75 py::object const& coordinates)
76 {
77 return SpatialPosition(
78 node_id, element_id,
80 }),
81 py::arg("node_id") = std::nullopt,
82 py::arg("element_id") = std::nullopt,
83 py::arg("coords") = py::none(),
84 R"pbdoc(
85 SpatialPosition(node_id=None, element_id=None, coords=None)
86
87 Parameters:
88 node_id (int, optional): Node ID
89 element_id (int, optional): Element ID
90 coords (array-like of 3 floats, optional): Coordinates
91 )pbdoc")
92
93 .def_property(
94 "node_id",
95 [](SpatialPosition const& pos) { return pos.getNodeID(); },
96 [](SpatialPosition& pos, std::size_t const id)
97 { pos.setNodeID(id); },
98 R"pbdoc(
99 Node ID of the spatial position.
100
101 This property can be read and set from Python. Setting to None is not supported.
102 )pbdoc")
103
104 .def_property(
105 "element_id",
106 [](SpatialPosition const& pos) { return pos.getElementID(); },
107 [](SpatialPosition& pos, std::size_t const id)
108 { pos.setElementID(id); },
109 R"pbdoc(
110 Element ID of the spatial position.
111
std::optional< std::size_t > getNodeID() const
void setNodeID(std::size_t node_id)
std::optional< std::size_t > getElementID() const
void setElementID(std::size_t element_id)
std::optional< MathLib::Point3d > pythonToSpatialPositionCoords(py::object const &coordinates)
Definition ogs_mpl.cpp:29

References ParameterLib::SpatialPosition::getElementID(), ParameterLib::SpatialPosition::getNodeID(), pythonToSpatialPositionCoords(), ParameterLib::SpatialPosition::setElementID(), and ParameterLib::SpatialPosition::setNodeID().

Referenced by PYBIND11_MODULE().

◆ bindVariableArray()

void anonymous_namespace{ogs_mpl.cpp}::bindVariableArray ( py::module_ & m)

Definition at line 113 of file ogs_mpl.cpp.

119 {
120 pos.setCoordinates(
121 pythonToSpatialPositionCoords(coordinates).value());
122 },
123 R"pbdoc(
124 Coordinates of the spatial position as a 3-element array.
125
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.
128 )pbdoc")
129
130 .def(
131 "__repr__",
132 [](SpatialPosition const& pos)
133 {
134 auto const node_id =
135 pos.getNodeID() ? std::to_string(*pos.getNodeID()) : "None";
136 auto const element_id =
137 pos.getElementID() ? std::to_string(*pos.getElementID())
138 : "None";
139 auto const coords = spatialPositionCoordsToPython(pos);
140
141 return "<SpatialPosition(" + node_id + ", " + element_id +
142 ", " + py::str(coords).cast<std::string>() + ")>";
143 },
144 R"pbdoc(
145 Return string representation of the SpatialPosition.
146 )pbdoc");
147}
148
149void bindVariableArray(py::module_& m)
150{
151 py::class_<VariableArray>(m, "VariableArray")
void bindVariableArray(py::module_ &m)
Definition ogs_mpl.cpp:113
py::object spatialPositionCoordsToPython(SpatialPosition const &pos)
Definition ogs_mpl.cpp:43

References pythonToSpatialPositionCoords(), ParameterLib::SpatialPosition::setCoordinates(), and spatialPositionCoordsToPython().

Referenced by PYBIND11_MODULE().

◆ bindVariableEnum()

◆ pythonToSpatialPositionCoords()

std::optional< MathLib::Point3d > anonymous_namespace{ogs_mpl.cpp}::pythonToSpatialPositionCoords ( py::object const & coordinates)

Definition at line 29 of file ogs_mpl.cpp.

31{
32 if (coordinates.is_none())
33 {
34 return std::nullopt;
35 }
36 return std::make_optional<MathLib::Point3d>(
37 py::cast<std::array<double, 3>>(coordinates));
38}

Referenced by bindSpatialPosition(), and bindVariableArray().

◆ spatialPositionCoordsToPython()

py::object anonymous_namespace{ogs_mpl.cpp}::spatialPositionCoordsToPython ( SpatialPosition const & pos)

Definition at line 43 of file ogs_mpl.cpp.

44{
45 auto const& opt_coords = pos.getCoordinates();
46 if (opt_coords)
47 {
48 return py::array_t<double>(3, opt_coords->data());
49 }
50 return py::none();
51}

References ParameterLib::SpatialPosition::getCoordinates().

Referenced by bindVariableArray().