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

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

References MaterialPropertyLib::Property::value().

Referenced by PYBIND11_MODULE().

◆ bindLinear()

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

Definition at line 257 of file ogs_mpl.cpp.

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

References MaterialPropertyLib::Property::dValue().

Referenced by PYBIND11_MODULE().

◆ bindProperty()

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

Definition at line 191 of file ogs_mpl.cpp.

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

Referenced by PYBIND11_MODULE().

◆ bindSpatialPosition()

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

Definition at line 59 of file ogs_mpl.cpp.

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

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

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

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

Referenced by PYBIND11_MODULE().

◆ bindVariableEnum()

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

Definition at line 159 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 35 of file ogs_mpl.cpp.

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

Referenced by bindSpatialPosition(), and bindVariableArray().

◆ spatialPositionCoordsToPython()

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

Definition at line 49 of file ogs_mpl.cpp.

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

References ParameterLib::SpatialPosition::getCoordinates().