Skip to content

Commit

Permalink
fix: Fix set_state issue with inactive children (#3311)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkundu1 authored Sep 23, 2024
1 parent 78f9b04 commit a213d62
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/ansys/fluent/core/solver/flobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,8 @@ def get_state(self) -> StateT:
"""Get the state of the object."""
return self.to_python_keys(self.flproxy.get_var(self.path))

# Following is not a classmethod, as parent (required to support ".." in alias-path)
# is available only at the instance level.
def _unalias(self, cls, value):
"""Unalias the given value."""
if isinstance(value, collections.abc.Mapping):
Expand All @@ -730,15 +732,23 @@ def _unalias(self, cls, value):
outer_obj = outer_obj.parent
comps = comps[1:]
for comp in comps:
outer_obj = getattr(outer_obj, comp)
try:
outer_obj = getattr(outer_obj, comp)
except InactiveObjectError:
outer_obj = super(
SettingsBase, outer_obj
).__getattribute__(comp)
outer_set_states.append((outer_obj, v))
else:
ret_alias = ret
aliased_cls = cls
obj = self
for i, comp in enumerate(comps):
aliased_cls = aliased_cls._child_classes[comp]
obj = getattr(obj, comp)
try:
obj = getattr(obj, comp)
except InactiveObjectError:
obj = super(SettingsBase, obj).__getattribute__(comp)
if i == len(comps) - 1:
ret_alias[comp], o_set_states = obj._unalias(
aliased_cls, v
Expand All @@ -749,7 +759,10 @@ def _unalias(self, cls, value):
else:
if issubclass(cls, Group):
ccls = cls._child_classes[k]
cobj = getattr(self, k)
try:
cobj = getattr(self, k)
except InactiveObjectError:
cobj = super(SettingsBase, self).__getattribute__(k)
ret[k], o_set_states = cobj._unalias(ccls, v)
outer_set_states.extend(o_set_states)
else:
Expand Down
18 changes: 18 additions & 0 deletions tests/test_settings_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,24 @@ def test_generated_code_special_cases(new_solver_session):
@pytest.mark.fluent_version(">=25.1")
def test_child_alias_with_parent_path(mixing_elbow_settings_session):
solver = mixing_elbow_settings_session

# Following set_state should not throw InactiveObjectError
solver.settings.setup.materials.fluid["air"] = {
"density": {"option": "ideal-gas"},
"specific_heat": {"value": 1006.43, "option": "constant"},
"thermal_conductivity": {"value": 0.0242, "option": "constant"},
"molecular_weight": {"value": 28.966, "option": "constant"},
}
assert solver.settings.setup.materials.fluid["air"].density.option() == "ideal-gas"
assert solver.settings.setup.materials.fluid["air"].specific_heat.value() == 1006.43
assert (
solver.settings.setup.materials.fluid["air"].thermal_conductivity.value()
== 0.0242
)
assert (
solver.settings.setup.materials.fluid["air"].molecular_weight.value() == 28.966
)

solver.settings.solution.initialization.hybrid_initialize()
assert (
solver.settings.setup.models.discrete_phase.numerics.node_based_averaging.kernel._child_aliases
Expand Down

0 comments on commit a213d62

Please sign in to comment.