Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 44 additions & 58 deletions src/ansys/fluent/core/services/datamodel_se.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,20 +708,22 @@ def __init__(
service: DatamodelService,
rules: str,
path: Path,
static_info,
parent_arg,
):
self.parent = parent
self.name = name

self.service = service
self.rules = rules
self.path = path
self.static_info = static_info
self.parent_arg = parent_arg

def __getattr__(self, attr):
return PyCommandArgumentsSubItem(
self, attr, self.service, self.rules, self.path, self.static_info
)
arg = self.parent_arg.info.parameters[attr]

mode = AccessorModes.get_mode(arg.type)
py_class = mode.value[1]
return py_class(self, attr, self.service, self.rules, self.path, arg)

def get_state(self) -> Any:
parent_state = self.parent.get_state()
Expand Down Expand Up @@ -774,51 +776,9 @@ def __getattr__(self, attr):

for arg in self.static_info.commands[self.command].commandinfo.args:
if arg.name == attr:
if arg.type in ["String", "ListString"]:
return PyTextualCommandArgumentsSubItem(
self,
attr,
self.service,
self.rules,
self.path,
self.static_info,
)
elif arg.type in ["Real", "Int", "ListReal"]:
return PyNumericalCommandArgumentsSubItem(
self,
attr,
self.service,
self.rules,
self.path,
self.static_info,
)
elif arg.type == "Dict":
return PyDictionaryCommandArgumentsSubItem(
self,
attr,
self.service,
self.rules,
self.path,
self.static_info,
)
elif arg.type in ["Bool", "Logical"]:
return PyParameterCommandArgumentsSubItem(
self,
attr,
self.service,
self.rules,
self.path,
self.static_info,
)
else:
return PyCommandArgumentsSubItem(
self,
attr,
self.service,
self.rules,
self.path,
self.static_info,
)
mode = AccessorModes.get_mode(arg.type)
py_class = mode.value[1]
return py_class(self, attr, self.service, self.rules, self.path, arg)


class PyTextualCommandArgumentsSubItem(PyCommandArgumentsSubItem, PyTextual):
Expand All @@ -829,10 +789,10 @@ def __init__(
service: DatamodelService,
rules: str,
path: Path,
static_info,
arg,
):
PyCommandArgumentsSubItem.__init__(
self, parent, attr, service, rules, path, static_info
self, parent, attr, service, rules, path, arg
)
PyTextual.__init__(self, service, rules, path)

Expand All @@ -845,10 +805,10 @@ def __init__(
service: DatamodelService,
rules: str,
path: Path,
static_info,
arg,
):
PyCommandArgumentsSubItem.__init__(
self, parent, attr, service, rules, path, static_info
self, parent, attr, service, rules, path, arg
)
PyNumerical.__init__(self, service, rules, path)

Expand All @@ -861,10 +821,10 @@ def __init__(
service: DatamodelService,
rules: str,
path: Path,
static_info,
arg,
):
PyCommandArgumentsSubItem.__init__(
self, parent, attr, service, rules, path, static_info
self, parent, attr, service, rules, path, arg
)
PyDictionary.__init__(self, service, rules, path)

Expand All @@ -877,14 +837,40 @@ def __init__(
service: DatamodelService,
rules: str,
path: Path,
static_info,
arg,
):
PyCommandArgumentsSubItem.__init__(
self, parent, attr, service, rules, path, static_info
self, parent, attr, service, rules, path, arg
)
PyParameter.__init__(self, service, rules, path)


class AccessorModes(Enum):
"""Provides the standard Fluent launch modes."""

# Tuple: Name, Solver object type, Meshing flag, Launcher options
TEXT = (["String", "ListString", "String List"], PyTextualCommandArgumentsSubItem)
NUMBER = (
["Real", "Int", "ListReal", "Real List", "Integer"],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@prmukherj are the tests failures there simply because we are waiting for the Fluent docker update?

Copy link
Collaborator Author

@prmukherj prmukherj Sep 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seanpearsonuk yes, the test failures are due to the pending update in the server side.

PyNumericalCommandArgumentsSubItem,
)
DICTIONARY = (["Dict"], PyDictionaryCommandArgumentsSubItem)
PARAMETER = (
["Bool", "Logical", "Logical List"],
PyParameterCommandArgumentsSubItem,
)
GENERIC = ([], PyCommandArgumentsSubItem)

@staticmethod
def get_mode(mode: str) -> "AccessorModes":
"""Returns the LaunchMode based on the mode in string format."""
for m in AccessorModes:
if mode in m.value[0]:
return m
else:
return AccessorModes.GENERIC


class PyMenuGeneric(PyMenu):
attrs = ("service", "rules", "path")

Expand Down
39 changes: 37 additions & 2 deletions tests/test_meshing_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,45 @@ def test_accessors_for_argument_sub_items(new_mesh_session):
w.InitializeWorkflow(WorkflowType="Watertight Geometry")

assert w.task("Import Geometry").CommandArguments.LengthUnit.default_value() == "mm"
assert w.task("Import Geometry").CommandArguments.LengthUnit.is_read_only()
assert w.task("Import Geometry").CommandArguments.MeshUnit.is_read_only()
assert w.task("Import Geometry").CommandArguments.LengthUnit.is_active()
assert w.task("Import Geometry").CommandArguments.FileName.is_read_only()
assert w.task("Import Geometry").CommandArguments.MeshUnit.is_read_only()
assert w.task(
"Import Geometry"
).CommandArguments.CadImportOptions.OneZonePer.is_read_only()
assert (
w.task(
"Import Geometry"
).CommandArguments.CadImportOptions.OneZonePer.default_value()
== "Body"
)

# Test particular to string type (allowed_values() only available in string types)
assert w.task(
"Import Geometry"
).CommandArguments.CadImportOptions.OneZonePer.allowed_values() == [
"Body",
"Face",
"Object",
]
assert (
w.task(
"Import Geometry"
).CommandArguments.CadImportOptions.FeatureAngle.default_value()
== 40.0
)

# Test particular to numerical type (min() only available in numerical types)
assert (
w.task("Import Geometry").CommandArguments.CadImportOptions.FeatureAngle.min()
== 0.0
)

# Test intended to fail in numerical type (allowed_values() only available in string types)
with pytest.raises(AttributeError):
assert w.task(
"Import Geometry"
).CommandArguments.CadImportOptions.FeatureAngle.allowed_values()


def test_dummy_journal_data_model_methods(new_mesh_session):
Expand Down