Skip to content

Commit

Permalink
fix: Empty locations list as input for reduction. (#3526)
Browse files Browse the repository at this point in the history
* fix: Empty locations list as input for reduction.

* Update __eq__ implementation in flobject.Base
  • Loading branch information
prmukherj authored Dec 20, 2024
1 parent f1c28f9 commit e586c61
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/ansys/fluent/core/services/reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ def _validate_str_location(self, loc: str):
raise ValueError(f"Invalid location input: '{loc}'")

def _get_location_string(self, locations, ctxt) -> List[str]:
if locations == []:
return []
for loc in locations:
if isinstance(loc, str):
self._validate_str_location(loc)
Expand Down
2 changes: 2 additions & 0 deletions src/ansys/fluent/core/solver/flobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,8 @@ def _while_executing_command(self):
return nullcontext()

def __eq__(self, other):
if not isinstance(other, self.__class__):
return False
return self.flproxy == other.flproxy and self.path == other.path


Expand Down
3 changes: 3 additions & 0 deletions src/ansys/fluent/core/solver/function/reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ def _validate_locn_list(locn_list, ctxt):


def _locns(locns, ctxt):
if locns == []:
# Raising 'RuntimeError' instead of 'ValueError' to address a limitation in the server-side implementation.
raise RuntimeError("No locations specified.")
locn_names_and_objs = _locn_names_and_objs(locns)
locn_list = []
for name, obj in locn_names_and_objs:
Expand Down
30 changes: 30 additions & 0 deletions tests/test_reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,3 +452,33 @@ def test_fix_for_invalid_location_inputs(static_mixer_case_session: Any):

with pytest.raises(ValueError):
assert solver.fields.reduction.area(locations=["inlet-1"])


@pytest.mark.fluent_version(">=25.2")
def test_fix_for_empty_location_inputs(static_mixer_case_session: Any):
solver = static_mixer_case_session
solver.solution.initialization.hybrid_initialize()

assert solver.fields.reduction.area(locations=["inlet1"])

with pytest.raises(RuntimeError):
assert reduction.area(locations=[], ctxt=solver)

with pytest.raises(RuntimeError):
assert reduction.area_average(
expression="AbsolutePressure", locations=[], ctxt=solver
)

with pytest.raises(RuntimeError):
assert reduction.centroid(locations=[], ctxt=solver)

with pytest.raises(RuntimeError):
assert solver.fields.reduction.area(locations=[])

with pytest.raises(RuntimeError):
assert solver.fields.reduction.area_average(
expression="AbsolutePressure", locations=[]
)

with pytest.raises(RuntimeError):
assert solver.fields.reduction.centroid(locations=[])

0 comments on commit e586c61

Please sign in to comment.