Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/enable command args for datamodel se #735

Merged
merged 12 commits into from
Aug 22, 2022
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ jobs:
name: Smoke Tests
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest, ubuntu-latest]
python-version: ['3.7', '3.8', '3.9', '3.10']
Expand Down Expand Up @@ -234,6 +235,7 @@ jobs:
needs: test-import
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
image-tag: [v22.2.0, v23.1.0]

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/nightly-doc-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ jobs:
nightly_docs_build:
runs-on: [self-hosted, pyfluent]
strategy:
fail-fast: false
matrix:
image-tag: [v22.2.0, v23.1.0]

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
shutil.copy2(_README_FILE, _DOCS_FILE)

install_requires = [
"ansys-api-fluent~=0.2",
"ansys-api-fluent~=0.3",
"ansys-platform-instancemanagement~=1.0",
"grpcio>=1.30.0",
"numpy>=1.21.5",
Expand Down
3 changes: 2 additions & 1 deletion src/ansys/fluent/core/launcher/fluent_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def start_fluent_container(mounted_from: str, mounted_to: str, args: List[str])
license_server = os.environ["ANSYSLMD_LICENSE_FILE"]
port = _get_free_port()
container_sifile = mounted_to + "/" + Path(sifile).name
image_tag = os.getenv("FLUENT_IMAGE_TAG", "latest")

try:
subprocess.run(
Expand All @@ -56,7 +57,7 @@ def start_fluent_container(mounted_from: str, mounted_to: str, args: List[str])
f"REMOTING_PORTS={port}/portspan=2",
"-e",
"FLUENT_LAUNCHED_FROM_PYFLUENT=1",
"ghcr.io/pyansys/pyfluent",
f"ghcr.io/pyansys/pyfluent:{image_tag}",
"-gu",
f"-sifile={container_sifile}",
]
Expand Down
35 changes: 11 additions & 24 deletions src/ansys/fluent/core/services/datamodel_se.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Wrappers over StateEngine based datamodel gRPC service of Fluent."""

from enum import Enum
import itertools
from typing import Any, Dict, Iterator, List, Tuple
import warnings

import grpc

Expand Down Expand Up @@ -108,8 +108,6 @@ def execute_command(
) -> DataModelProtoModule.ExecuteCommandResponse:
return self.__stub.executeCommand(request, metadata=self.__metadata)

# pending the proto changes
"""
@catch_grpc_error
def create_command_arguments(
self, request: DataModelProtoModule.CreateCommandArgumentsRequest
Expand All @@ -121,7 +119,6 @@ def delete_command_arguments(
self, request: DataModelProtoModule.DeleteCommandArgumentsRequest
) -> DataModelProtoModule.DeleteCommandArgumentsResponse:
return self.__stub.deleteCommandArguments(request, metadata=self.__metadata)
"""

@catch_grpc_error
def get_specs(
Expand Down Expand Up @@ -362,16 +359,12 @@ def rename(self, new_name: str) -> None:
)

def create_command_arguments(self, command):
pass
# pending the proto changes
"""
request = DataModelProtoModule.CreateCommandArgumentsRequest()
request.rules = self.rules
request.path = _convert_path_to_se_path(self.path)
request.command = command
response = self.service.create_command_arguments(request)
return response.commandid
"""


class PyParameter(PyBasicStateContainer):
Expand Down Expand Up @@ -640,26 +633,24 @@ def help(self) -> None:
print(help_string)

def _create_command_arguments(self):
pass
# pending the proto changes
"""
request = DataModelProtoModule.CreateCommandArgumentsRequest()
request.rules = self.rules
request.path = _convert_path_to_se_path(self.path)
request.command = self.command
response = self.service.create_command_arguments(request)
return response.commandid
"""

def new(self):
# pending the proto changes
pass
"""
id = self._create_command_arguments()
return PyCommandArguments(
self.service, self.rules, self.command, self.path.copy(), id
)
"""
try:
id = self._create_command_arguments()
return PyCommandArguments(
self.service, self.rules, self.command, self.path.copy(), id
)
except RuntimeError:
warnings.warn(
"Create command arguments object is available from 23.1 onwards"
)
pass


class PyCommandArgumentsSubItem(PyCallableStateObject):
Expand Down Expand Up @@ -702,9 +693,6 @@ def __init__(
self.path.append((command, id))

def __del__(self):
# pending the proto changes
pass
"""
request = DataModelProtoModule.DeleteCommandArgumentsRequest()
request.rules = self.rules
request.path = _convert_path_to_se_path(self.path[:-1])
Expand All @@ -715,7 +703,6 @@ def __del__(self):
except ValueError:
# "Cannot invoke RPC on closed channel!"
pass
"""

def __getattr__(self, attr):
return PyCommandArgumentsSubItem(self, attr)
Expand Down
4 changes: 2 additions & 2 deletions src/ansys/fluent/core/services/datamodel_tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,12 @@ def get_static_info(self) -> Dict[str, Any]:
DataModelProtoModule.StaticInfo
static info
"""
if hasattr(DataModelProtoModule, "GetStaticInfoRequest"):
try:
request = DataModelProtoModule.GetStaticInfoRequest()
request.path = self._path
response = self._service.get_static_info(request)
prmukherj marked this conversation as resolved.
Show resolved Hide resolved
return MessageToDict(response.info, including_default_value_fields=True)
else:
except RuntimeError:
return _get_static_info_at_level(self)


Expand Down
6 changes: 6 additions & 0 deletions src/ansys/fluent/core/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ def exit(self) -> None:
"""Close the Fluent connection and exit Fluent."""
self.fluent_connection.exit()

def get_fluent_version(self):
"""Gets and returns the fluent version."""
return ".".join(
map(str, self.fluent_connection.scheme_eval.scheme_eval("(cx-version)"))
)

def __enter__(self):
"""Close the Fluent connection and exit Fluent."""
return self
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/fluent/core/solver/flobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ def get_cls(name, info, parent=None):
dct["__doc__"] = f"'{pname.strip('_')}' child."

include_child_named_objects = info.get("include_child_named_objects", False)
user_creatable = info.get("user_creatable", False)
user_creatable = info.get("user_creatable", True)

bases = (base,)
if include_child_named_objects:
Expand Down
148 changes: 77 additions & 71 deletions tests/test_cad_to_post_ftm.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,9 @@ def test_exhaust_system(new_fault_tolerant_workflow_session, exhaust_system_geom

###############################################################################
# Check the mesh in Meshing mode
meshing_session.tui.mesh.check_mesh()
# TODO: Remove the if condition after a stable version of 23.1 is available and update the commands as required.
if float(meshing_session.get_fluent_version()[:-2]) < 23.0:
meshing_session.tui.mesh.check_mesh()

###############################################################################
# Switch to Solution mode
Expand All @@ -451,74 +453,78 @@ def test_exhaust_system(new_fault_tolerant_workflow_session, exhaust_system_geom
###############################################################################
# Set the velocity and turbulence boundary conditions for the first inlet
# (inlet-1).
solver_session.tui.define.boundary_conditions.set.velocity_inlet(
"inlet-1", [], "vmag", "no", 1, "quit"
)
###############################################################################
# Apply the same conditions for the other velocity inlet boundaries (inlet_2,
# and inlet_3).
solver_session.tui.define.boundary_conditions.copy_bc(
"inlet-1", "inlet-2", "inlet-3", ()
)

###############################################################################
# Set the boundary conditions at the outlet (outlet-1).
solver_session.tui.define.boundary_conditions.set.pressure_outlet(
"outlet-1", [], "turb-intensity", 5, "quit"
)
solver_session.tui.solve.monitors.residual.plot("yes")

###############################################################################
# Initialize the flow field using the Initialization
solver_session.tui.solve.initialize.hyb_initialization()

###############################################################################
# Start the calculation by requesting 100 iterations
solver_session.tui.solve.set.number_of_iterations(100)
solver_session.tui.solve.iterate()

###############################################################################
# Assert the returned mass flow rate report definition value
solver_session.solution.report_definitions.flux["mass_flow_rate"] = {}
solver_session.solution.report_definitions.flux["mass_flow_rate"].zone_names = [
"inlet-1",
"inlet-2",
"inlet-3",
"outlet-1",
]

check_report_definition = partial(
check_report_definition_result,
report_definitions=solver_session.solution.report_definitions,
)

check_report_definition(
report_definition_name="mass_flow_rate",
expected_result=approx(-6.036667e-07, abs=1e-3),
)

###############################################################################
# Assert the returned velocity-magnitude report definition value on the outlet
# surface
solver_session.solution.report_definitions.surface["velocity_magnitude_outlet"] = {}
solver_session.solution.report_definitions.surface[
"velocity_magnitude_outlet"
].report_type = "surface-areaavg"
solver_session.solution.report_definitions.surface[
"velocity_magnitude_outlet"
].field = "velocity-magnitude"
solver_session.solution.report_definitions.surface[
"velocity_magnitude_outlet"
].surface_names = ["outlet-1"]

check_report_definition = partial(
check_report_definition_result,
report_definitions=solver_session.solution.report_definitions,
)

check_report_definition(
report_definition_name="velocity_magnitude_outlet",
expected_result=approx(3.7988207, rel=1e-3),
)
# TODO: Remove the if condition after a stable version of 23.1 is available and update the commands as required.
if float(meshing_session.get_fluent_version()[:-2]) < 23.0:
solver_session.tui.define.boundary_conditions.set.velocity_inlet(
"inlet-1", [], "vmag", "no", 1, "quit"
)
###############################################################################
# Apply the same conditions for the other velocity inlet boundaries (inlet_2,
# and inlet_3).
solver_session.tui.define.boundary_conditions.copy_bc(
"inlet-1", "inlet-2", "inlet-3", ()
)

###############################################################################
# Set the boundary conditions at the outlet (outlet-1).
solver_session.tui.define.boundary_conditions.set.pressure_outlet(
"outlet-1", [], "turb-intensity", 5, "quit"
)
solver_session.tui.solve.monitors.residual.plot("yes")

###############################################################################
# Initialize the flow field using the Initialization
solver_session.tui.solve.initialize.hyb_initialization()

###############################################################################
# Start the calculation by requesting 100 iterations
solver_session.tui.solve.set.number_of_iterations(100)
solver_session.tui.solve.iterate()

###############################################################################
# Assert the returned mass flow rate report definition value
solver_session.solution.report_definitions.flux["mass_flow_rate"] = {}
solver_session.solution.report_definitions.flux["mass_flow_rate"].zone_names = [
"inlet-1",
"inlet-2",
"inlet-3",
"outlet-1",
]

###############################################################################
check_report_definition = partial(
check_report_definition_result,
report_definitions=solver_session.solution.report_definitions,
)

check_report_definition(
report_definition_name="mass_flow_rate",
expected_result=approx(-6.036667e-07, abs=1e-3),
)

###############################################################################
# Assert the returned velocity-magnitude report definition value on the outlet
# surface
solver_session.solution.report_definitions.surface[
"velocity_magnitude_outlet"
] = {}
solver_session.solution.report_definitions.surface[
"velocity_magnitude_outlet"
].report_type = "surface-areaavg"
solver_session.solution.report_definitions.surface[
"velocity_magnitude_outlet"
].field = "velocity-magnitude"
solver_session.solution.report_definitions.surface[
"velocity_magnitude_outlet"
].surface_names = ["outlet-1"]

check_report_definition = partial(
check_report_definition_result,
report_definitions=solver_session.solution.report_definitions,
)

check_report_definition(
report_definition_name="velocity_magnitude_outlet",
expected_result=approx(3.7988207, rel=1e-3),
)

###############################################################################
Loading