Skip to content

Commit

Permalink
add component to MPL value setter
Browse files Browse the repository at this point in the history
  • Loading branch information
joergbuchwald committed Nov 4, 2023
1 parent 084aea1 commit 05acc32
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion ogs6py/ogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,20 @@ def _get_phase_pointer(cls, root, phase):
raise RuntimeError
return phasepointer

@classmethod
def _get_component_pointer(cls, root, component):
components = root.findall("./components/component")
componentnames = root.findall("./components/component/name")
componentcounter = None
for i, componentname in enumerate(componentnames):
if componentname.text == component:
componentcounter = i
componentpointer = components[componentcounter]
if componentpointer is None:
print("Component not found")
raise RuntimeError
return componentpointer

@classmethod
def _set_type_value(cls, parameterpointer, value, parametertype, valuetag=None):
for paramproperty in parameterpointer:
Expand Down Expand Up @@ -445,7 +459,7 @@ def replace_parameter_value(self, name=None, value=None, valuetag="value"):
parameterpointer = self._get_parameter_pointer(root, name, parameterpath)
self._set_type_value(parameterpointer, value, None, valuetag=valuetag)

def replace_phase_property_value(self, mediumid=None, phase="AqueousLiquid", name=None, value=None,
def replace_phase_property_value(self, mediumid=None, phase="AqueousLiquid", component=None, name=None, value=None,
propertytype=None, valuetag="value"):
"""Replaces properties in medium phases
Expand All @@ -455,6 +469,7 @@ def replace_phase_property_value(self, mediumid=None, phase="AqueousLiquid", nam
id of the medium
phase : `str`
name of the phase
component : `str`
name : `str`
property name
value : `str`/any
Expand All @@ -468,6 +483,8 @@ def replace_phase_property_value(self, mediumid=None, phase="AqueousLiquid", nam
root = self._get_root()
mediumpointer = self._get_medium_pointer(root, mediumid)
phasepointer = self._get_phase_pointer(mediumpointer, phase)
if component is not None:
phasepointer = self._get_component_pointer(phasepointer, component)
xpathparameter = "./properties/property"
parameterpointer = self._get_parameter_pointer(phasepointer, name, xpathparameter)
self._set_type_value(parameterpointer, value, propertytype, valuetag=valuetag)
Expand Down

0 comments on commit 05acc32

Please sign in to comment.