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 245 of file ogs_mpl.cpp.

245 : Spatial position.
246 t: Current time.
247 dt: Time step size.
248 )pbdoc")
249
250 .def(
251 "value",
252 [](const Property& p, const VariableArray& va,
253 const VariableArray& vap, const SpatialPosition& pos, double t,
254 double dt) { return p.value(va, vap, pos, t, dt); },

Referenced by PYBIND11_MODULE().

◆ bindLinear()

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

Definition at line 256 of file ogs_mpl.cpp.

263 :
264 variable_array: Current time step values.
265 variable_array_prev: Previous time step values.
266 pos: Spatial position.
267 t: Current time.
268 dt: Time step size.
269 )pbdoc")
270
271 .def(
272 "dValue",
273 [](const Property& p, const VariableArray& va,
274 const VariableArray& vap, Variable var,
275 const SpatialPosition& pos, double t, double dt)
276 { return p.dValue(va, vap, var, pos, t, dt); },
277 py::arg("variable_array"),
278 py::arg("variable_array_prev"),
279 py::arg("variable"),
280 py::arg("pos"),

Referenced by PYBIND11_MODULE().

◆ bindProperty()

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

Definition at line 190 of file ogs_mpl.cpp.

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

Referenced by PYBIND11_MODULE().

◆ bindSpatialPosition()

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

Definition at line 58 of file ogs_mpl.cpp.

59{
60 py::class_<SpatialPosition>(m, "SpatialPosition",
61 R"pbdoc(
62 Describes a spatial position within a mesh or domain.
63
64 A SpatialPosition may refer to a node (via node ID), an element (via element ID),
65 or a physical point in space (via coordinates). It is typically used when evaluating
66 material properties that depend on the spatial context within a simulation.
67
68 The position may be partially specified. For example:
69 - Only coordinates for geometric evaluation
70 - Only node ID for nodal properties
71 - Only element ID for element-wise values
72 - Or any combination of the above
73
74 The class is used as a parameter to property evaluations in the OGS material properties library.
75)pbdoc")
76 .def(py::init(
77 [](std::optional<std::size_t> node_id,
78 std::optional<std::size_t>
79 element_id,
80 py::object const& coordinates)
81 {
82 return SpatialPosition(
83 node_id, element_id,
85 }),
86 py::arg("node_id") = std::nullopt,
87 py::arg("element_id") = std::nullopt,
88 py::arg("coords") = py::none(),
89 R"pbdoc(
90 SpatialPosition(node_id=None, element_id=None, coords=None)
91
92 Parameters:
93 node_id (int, optional): Node ID
94 element_id (int, optional): Element ID
95 coords (array-like of 3 floats, optional): Coordinates
96 )pbdoc")
97
98 .def_property(
99 "node_id",
100 [](SpatialPosition const& pos) { return pos.getNodeID(); },
101 [](SpatialPosition& pos, std::size_t const id)
102 { pos.setNodeID(id); },
103 R"pbdoc(
104 Node ID of the spatial position.
105
106 This property can be read and set from Python. Setting to None is not supported.
107 )pbdoc")
108
109 .def_property(
110 "element_id",
111 [](SpatialPosition const& pos) { return pos.getElementID(); },
112 [](SpatialPosition& pos, std::size_t const id)
113 { pos.setElementID(id); },
114 R"pbdoc(
115 Element ID of the spatial position.
116
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:34

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 118 of file ogs_mpl.cpp.

124 {
125 pos.setCoordinates(
126 pythonToSpatialPositionCoords(coordinates).value());
127 },
128 R"pbdoc(
129 Coordinates of the spatial position as a 3-element array.
130
131 This property can be read and set from Python. Use a 3-element list, tuple,
132 or NumPy array. Setting to None is not supported.
133 )pbdoc")
134
135 .def(
136 "__repr__",
137 [](SpatialPosition const& pos)
138 {
139 auto const node_id =
140 pos.getNodeID() ? std::to_string(*pos.getNodeID()) : "None";
141 auto const element_id =
142 pos.getElementID() ? std::to_string(*pos.getElementID())
143 : "None";
144 auto const coords = spatialPositionCoordsToPython(pos);
145
146 return "<SpatialPosition(" + node_id + ", " + element_id +
147 ", " + py::str(coords).cast<std::string>() + ")>";
148 },
149 R"pbdoc(
150 Return string representation of the SpatialPosition.
151 )pbdoc");
152}
153
154void bindVariableArray(py::module_& m)
155{
156 py::class_<VariableArray>(m, "VariableArray")
void bindVariableArray(py::module_ &m)
Definition ogs_mpl.cpp:118
py::object spatialPositionCoordsToPython(SpatialPosition const &pos)
Definition ogs_mpl.cpp:48

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

Referenced by PYBIND11_MODULE().

◆ bindVariableEnum()

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

Definition at line 158 of file ogs_mpl.cpp.

Referenced by PYBIND11_MODULE().

◆ pythonToSpatialPositionCoords()

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

Definition at line 34 of file ogs_mpl.cpp.

36{
37 if (coordinates.is_none())
38 {
39 return std::nullopt;
40 }
41 return std::make_optional<MathLib::Point3d>(
42 py::cast<std::array<double, 3>>(coordinates));
43}

Referenced by bindSpatialPosition(), and bindVariableArray().

◆ spatialPositionCoordsToPython()

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

Definition at line 48 of file ogs_mpl.cpp.

49{
50 auto const& opt_coords = pos.getCoordinates();
51 if (opt_coords)
52 {
53 return py::array_t<double>(3, opt_coords->data());
54 }
55 return py::none();
56}

References ParameterLib::SpatialPosition::getCoordinates().