Skip to content

Commit cb21518

Browse files
fix: set-state via call (#4567)
## Context There was an issue in the previous PR that implemented parameter set-state via `__call__` as the value was not sent to Fluent in the expected format. ## Change Summary Only the first argument value is sent to Fluent while setting parameter state via `__call__`. ## Rationale To send the set-state value to Fluent in the correct format ## Impact New unittest has been added, the example script `exhaust_system_settings_api.py` will pass. --------- Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent 41f5223 commit cb21518

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

doc/changelog.d/4567.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Set-state via call

src/ansys/fluent/core/solver/flobject.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,13 @@ def to_python_keys(cls, value: StateT) -> StateT:
822822
def __call__(self, *args, **kwargs):
823823
"""Get or set the state of the object."""
824824
if kwargs:
825-
self.set_state(kwargs)
825+
# Send value of the first key only
826+
if len(kwargs) > 1:
827+
warnings.warn(
828+
f"Only the first keyword argument is used when setting state at {self.python_path}.",
829+
PyFluentUserWarning,
830+
)
831+
self.set_state(next(iter(kwargs.values())))
826832
elif args:
827833
self.set_state(args)
828834
else:
@@ -1070,6 +1076,14 @@ def __init__(self, name: str | None = None, parent=None):
10701076
cls = self.__class__._child_classes[query]
10711077
self._setattr(query, _create_child(cls, None, self))
10721078

1079+
def __call__(self, *args, **kwargs):
1080+
if kwargs:
1081+
self.set_state(kwargs)
1082+
elif args:
1083+
self.set_state(args)
1084+
else:
1085+
return self.get_state()
1086+
10731087
@classmethod
10741088
def to_scheme_keys(cls, value, root_cls, path: list[str]):
10751089
"""Convert value to have keys with scheme names.

tests/test_settings_api.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,3 +841,8 @@ def test_migration_adapter_for_strings(mixing_elbow_settings_session):
841841
solver.settings.setup.models.discrete_phase.general_settings.unsteady_tracking.create_particles_at()
842842
== "particle-time-step"
843843
)
844+
845+
846+
def test_set_state_via_call(mixing_elbow_settings_session):
847+
solver = mixing_elbow_settings_session
848+
solver.settings.results.graphics.views.camera.position(xyz=[1.70, 1.14, 0.29])

0 commit comments

Comments
 (0)