Skip to content

Commit

Permalink
Fix issue with passing case_file_name argument to launch_fluent()
Browse files Browse the repository at this point in the history
… throwing `TypeError` (#2312)

* Replaced read_case() with read() and used keyword arguments

* Read case lightweight as per PR 2268

* Add launcher tests for case/data file name arguments

* Add assertion tests for data validity, add lightweight setup test

* Replaced read_case() with read() and used keyword arguments

* Read case lightweight as per PR 2268

* Add launcher tests for case/data file name arguments

* Add assertion tests for data validity, add lightweight setup test

* Add version marker for >=23.2 since settings-only not supported on earlier versions

* Add standalone marker so that launcher tests don't run in container

* Made case_name parameter backwards-compatible with 22R2, skip mesh test for 22R2

---------

Co-authored-by: Jess Sia (External) <[email protected]>
  • Loading branch information
ansjsia and Jess Sia (External) authored Dec 15, 2023
1 parent b53f904 commit ce0351d
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/ansys/fluent/core/launcher/standalone_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,18 @@ def __call__(self):
if self.case_file_name:
if self.meshing_mode:
session.tui.file.read_case(self.case_file_name)
elif self.lightweight_mode:
session.read_case_lightweight(self.case_file_name)
else:
session.read_case(self.case_file_name, self.lightweight_mode)
session.file.read(
file_type="case",
file_name=self.case_file_name,
)
if self.case_data_file_name:
if not self.meshing_mode:
session.file.read(
file_type="case-data", file_name=self.case_data_file_name
file_type="case-data",
file_name=self.case_data_file_name,
)
else:
raise RuntimeError(
Expand Down
65 changes: 65 additions & 0 deletions tests/test_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from beartype.roar import BeartypeCallHintParamViolation
import pytest
from util.fixture_fluent import download_input_file

import ansys.fluent.core as pyfluent
from ansys.fluent.core.exceptions import DisallowedValuesError, InvalidArgument
Expand Down Expand Up @@ -75,6 +76,70 @@ def test_container_launcher():
assert session.health_check_service.is_serving


@pytest.mark.standalone
def test_case_load():
# Test that launch_fluent() works with a case file as an argument
_, cas_path = download_input_file(
"pyfluent/mixing_elbow",
"mixing_elbow.cas.h5",
)
session = pyfluent.launch_fluent(case_file_name=cas_path)

# Case loaded
assert session.setup.boundary_conditions.is_active()
# Mesh available because not lightweight
fluent_version = float(session.get_fluent_version()[:-2])
if not fluent_version < 23.1:
assert session.mesh.quality.is_active()
# Data not loaded
assert not session.field_data.is_data_valid()

session.exit()


@pytest.mark.standalone
@pytest.mark.fluent_version(">=23.2")
def test_case_lightweight_setup():
# Test that launch_fluent() correctly performs lightweight setup
_, cas_path = download_input_file(
"pyfluent/mixing_elbow",
"mixing_elbow.cas.h5",
)
session = pyfluent.launch_fluent(
case_file_name=cas_path,
lightweight_mode=True,
)

# Case loaded
assert session.setup.boundary_conditions.is_active()
# Mesh not available because lightweight
assert not session.mesh.quality.is_active()
# Data not loaded
assert not session.field_data.is_data_valid()


@pytest.mark.standalone
def test_case_data_load():
# Test that launch_fluent() works with a case+data file as an argument
_, cas_dat_path = download_input_file(
"pyfluent/mixing_elbow",
"mixing_elbow.cas.h5",
"mixing_elbow.dat.h5",
)
session = pyfluent.launch_fluent(case_data_file_name=cas_dat_path)

# Case loaded
assert session.setup.boundary_conditions.is_active()
# Mesh available because not lightweight
fluent_version = float(session.get_fluent_version()[:-2])
if not fluent_version < 23.1:
assert session.mesh.quality.is_active()
# Data loaded
assert session.field_data.is_data_valid()

session.exit()


def test_gpu_launch_arg(monkeypatch):
# The launch process is terminated intentionally to verify whether the fluent launch string
# (which is available in the error message) is generated correctly.
Expand Down

0 comments on commit ce0351d

Please sign in to comment.