Skip to content

Commit

Permalink
fix: dict set-state with alias (#2630)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkundu1 authored Mar 28, 2024
1 parent 02e32af commit 51fc833
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 24 deletions.
5 changes: 3 additions & 2 deletions src/ansys/fluent/core/solver/flobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,10 +661,11 @@ def _unalias(cls, value):
)
ret_alias = ret
comps = alias.split("/")
aliased_cls = cls
for i, comp in enumerate(comps):
cls = cls._child_classes[comp]
aliased_cls = aliased_cls._child_classes[comp]
if i == len(comps) - 1:
ret_alias[comp] = cls._unalias(v)
ret_alias[comp] = aliased_cls._unalias(v)
else:
ret_alias[comp] = {}
ret_alias = ret_alias[comp]
Expand Down
67 changes: 45 additions & 22 deletions tests/test_settings_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ def test_api_upgrade(new_solver_session, capsys):
"<solver_session>.file.read_case" in capsys.readouterr().out


@pytest.mark.skip
@pytest.mark.fluent_version(">=24.2")
def test_deprecated_settings(new_solver_session):
solver = new_solver_session
Expand Down Expand Up @@ -189,56 +188,76 @@ def test_deprecated_settings(new_solver_session):
)
assert (
len(
solver.setup.boundary_conditions.wall["wall-inlet"].thermal.t._child_aliases
solver.setup.boundary_conditions.wall[
"wall-inlet"
].thermal.temperature._child_aliases
)
> 0
)
assert (
solver.setup.boundary_conditions.wall["wall-inlet"].thermal.t._child_aliases[
"constant"
]
solver.setup.boundary_conditions.wall[
"wall-inlet"
].thermal.temperature._child_aliases["constant"]
== "value"
)
with pytest.warns(DeprecatedSettingWarning):
solver.setup.boundary_conditions.wall["wall-inlet"].thermal.t.constant = 400
solver.setup.boundary_conditions.wall[
"wall-inlet"
].thermal.temperature.constant = 400

assert solver.setup.boundary_conditions.wall["wall-inlet"].thermal.t.value() == 400
assert (
solver.setup.boundary_conditions.wall["wall-inlet"].thermal.temperature.value()
== 400
)
assert (
len(
solver.setup.boundary_conditions.wall["wall-inlet"].thermal.t._child_aliases
solver.setup.boundary_conditions.wall[
"wall-inlet"
].thermal.temperature._child_aliases
)
> 0
)
assert isinstance(
solver.setup.boundary_conditions.wall["wall-inlet"].thermal.t._child_alias_objs[
"constant"
],
solver.setup.boundary_conditions.wall[
"wall-inlet"
].thermal.temperature._child_alias_objs["constant"],
_Alias,
)
solver.setup.boundary_conditions.wall["wall-inlet"].thermal._setattr(
"_child_aliases", {"temp": "t"}
)
with pytest.warns(DeprecatedSettingWarning):
solver.setup.boundary_conditions.wall["wall-inlet"].thermal.temp.value = 410
solver.setup.boundary_conditions.wall["wall-inlet"].thermal.t.value = 410

assert solver.setup.boundary_conditions.wall["wall-inlet"].thermal.t.value() == 410
assert (
solver.setup.boundary_conditions.wall["wall-inlet"].thermal.temperature.value()
== 410
)

solver.setup.boundary_conditions._setattr("_child_aliases", {"w": "wall"})
with pytest.warns(DeprecatedSettingWarning):
solver.setup.boundary_conditions.w["wall-inlet"].thermal.t.value = 420
solver.setup.boundary_conditions.w["wall-inlet"].thermal.temperature.value = 420

assert solver.setup.boundary_conditions.wall["wall-inlet"].thermal.t.value() == 420
assert (
solver.setup.boundary_conditions.wall["wall-inlet"].thermal.temperature.value()
== 420
)

solver.setup._setattr("_child_aliases", {"bc": "boundary_conditions"})
with pytest.warns(DeprecatedSettingWarning):
solver.setup.bc.wall["wall-inlet"].thermal.t.value = 430
solver.setup.bc.wall["wall-inlet"].thermal.temperature.value = 430

assert solver.setup.boundary_conditions.wall["wall-inlet"].thermal.t.value() == 430
assert (
solver.setup.boundary_conditions.wall["wall-inlet"].thermal.temperature.value()
== 430
)

with pytest.warns(DeprecatedSettingWarning):
solver.setup.boundary_conditions.wall["wall-inlet"].thermal.t.constant = 400
solver.setup.boundary_conditions.wall[
"wall-inlet"
].thermal.temperature.constant = 400

assert solver.setup.boundary_conditions.wall["wall-inlet"].thermal.t.value() == 400
assert (
solver.setup.boundary_conditions.wall["wall-inlet"].thermal.temperature.value()
== 400
)

solver.results._setattr("_child_aliases", {"gr": "graphics"})
with pytest.warns(DeprecatedSettingWarning):
Expand Down Expand Up @@ -270,6 +289,10 @@ def test_deprecated_settings(new_solver_session):

solver.setup.cell_zone_conditions.fluid["elbow-fluid"] = {"material": "air"}

solver.setup.boundary_conditions.wall["wall-inlet"] = {
"thermal": {"q_dot": {"value": 2000000000}, "wall_thickness": {"value": 0.002}}
}


@pytest.mark.fluent_version(">=24.2")
def test_command_return_type(new_solver_session):
Expand Down

0 comments on commit 51fc833

Please sign in to comment.