Skip to content

Commit 4f618cb

Browse files
prmukherjpyansys-ci-botseanpearsonuk
authored
fix: Implement migration adapter check for textual settings parameters. (#4515)
This change updates the type-checking logic to correctly handle cases where a migration adapter is present. **Previous Behavior** When setting a textual attribute through PyFluent, type checking was performed before delegating to the underlying Settings API. If the provided value did not strictly match the expected type, PyFluent raised a TypeError, even in cases where a migration adapter existed to handle type conversion. For example: ```python >>> solver.settings.setup.models.discrete_phase.general_settings.unsteady_tracking.create_particles_at = False ``` Here, the property accepts a string value, but a migration adapter is available that correctly converts a boolean (False) into the appropriate string value. Previously, PyFluent would still raise a TypeError before this conversion could occur. **Current Behavior** If a migration adapter exists for a setting, PyFluent now bypasses type checking and directly forwards the input to the Settings API. This allows the migration adapter to handle type conversions or other logic as intended. Please refer to the test to see the detailed usage. The change aligns PyFluent behavior with the Fluent-side fix (ref. bug 1293534). --------- Co-authored-by: pyansys-ci-bot <[email protected]> Co-authored-by: Sean Pearson <[email protected]>
1 parent ec2c873 commit 4f618cb

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

doc/changelog.d/4515.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Implement migration adapter check for textual settings parameters.

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,9 +686,11 @@ def set_state(self, state: StateT | None = None, **kwargs):
686686
allowed_types = (str, VariableDescriptor)
687687

688688
if not isinstance(state, allowed_types):
689-
expected = " or ".join(t.__name__ for t in allowed_types)
689+
if self._has_migration_adapter:
690+
return self.base_set_state(state=state, **kwargs)
690691
raise TypeError(
691-
f"Expected state to be {expected}, got {type(state).__name__}."
692+
f"Expected state to be {' or '.join(t.__name__ for t in allowed_types)}, "
693+
f"got {type(state).__name__}."
692694
)
693695
return self.base_set_state(state=_to_field_name_str(state), **kwargs)
694696

tests/test_settings_api.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,3 +793,39 @@ def test_setting_string_constants(mixing_elbow_settings_session):
793793

794794
with pytest.raises(ValueError):
795795
viscous.k_epsilon_model = viscous.k_epsilon_model.EASM
796+
797+
798+
@pytest.mark.fluent_version(">=26.1")
799+
def test_migration_adapter_for_strings(mixing_elbow_settings_session):
800+
solver = mixing_elbow_settings_session
801+
solver.settings.setup.general.solver.time = "unsteady-2nd-order"
802+
solver.settings.setup.models.discrete_phase.general_settings.interaction.enabled = (
803+
True
804+
)
805+
806+
solver.settings.setup.models.discrete_phase.general_settings.unsteady_tracking.enabled = (
807+
True
808+
)
809+
solver.settings.setup.models.discrete_phase.general_settings.unsteady_tracking.option = (
810+
"particle-time-step"
811+
)
812+
solver.settings.setup.models.discrete_phase.general_settings.unsteady_tracking.dpm_time_step_size = (
813+
0.0002
814+
)
815+
816+
# Migration adapter is set on the 'create_particles_at' to accept boolean values as well besides string
817+
solver.settings.setup.models.discrete_phase.general_settings.unsteady_tracking.create_particles_at = (
818+
False
819+
)
820+
assert (
821+
solver.settings.setup.models.discrete_phase.general_settings.unsteady_tracking.create_particles_at()
822+
== "fluid-flow-time-step"
823+
)
824+
825+
solver.settings.setup.models.discrete_phase.general_settings.unsteady_tracking.create_particles_at = (
826+
True
827+
)
828+
assert (
829+
solver.settings.setup.models.discrete_phase.general_settings.unsteady_tracking.create_particles_at()
830+
== "particle-time-step"
831+
)

0 commit comments

Comments
 (0)