Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
16687bf
Added option for group class
prmukherj Nov 9, 2022
8731634
Updated corrected path resolusion.
prmukherj Nov 9, 2022
333d60b
Apply check with fnmatch to support wild_card entries
prmukherj Nov 9, 2022
fa1addf
removed check identifier ==
prmukherj Nov 9, 2022
b4c6624
Added test cases.
prmukherj Nov 9, 2022
1233959
Added docstring
prmukherj Nov 9, 2022
bb878e4
Minor style modifications
prmukherj Nov 10, 2022
179a554
Preventive check added.
prmukherj Nov 25, 2022
a62d5a4
Apply check for ListObjects as well
prmukherj Nov 25, 2022
789d518
revert test.
prmukherj Nov 25, 2022
25cc53c
Merge branch 'main' into feat/find_child_in_flobject
prmukherj Nov 25, 2022
320f902
Merge branch 'main' of https://github.com/pyansys/pyfluent into feat/…
prmukherj Nov 25, 2022
ffdcbd2
Merge branch 'feat/find_child_in_flobject' of https://github.com/pyan…
prmukherj Nov 25, 2022
8138859
Added the test.
prmukherj Nov 25, 2022
92a8347
Comment test for debugging
prmukherj Nov 27, 2022
c41f3f7
Corrected test.
prmukherj Nov 27, 2022
b47ad9a
find_child -> find_children
prmukherj Nov 30, 2022
4f315da
Merge branch 'main' into feat/find_child_in_flobject
prmukherj Nov 30, 2022
4089033
Put find_children() as an independent method in flobject
prmukherj Dec 1, 2022
53340ab
fixed an error
prmukherj Dec 1, 2022
b64f6a0
Updated test
prmukherj Dec 1, 2022
b118b70
Merge branch 'main' into feat/find_child_in_flobject
prmukherj Dec 9, 2022
4dea3c1
Merge branch 'main' into feat/find_child_in_flobject
prmukherj Dec 19, 2022
67e2f96
Merge branch 'main' into feat/find_child_in_flobject
prmukherj Apr 17, 2023
c072584
Merge branch 'main' into feat/find_child_in_flobject
prmukherj Apr 18, 2023
57a2c87
Merge branch 'main' into feat/find_child_in_flobject
prmukherj Apr 19, 2023
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
39 changes: 39 additions & 0 deletions src/ansys/fluent/core/solver/flobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
r.boundary_conditions.velocity_inlet['inlet'].vmag.constant = 20
"""
import collections
import fnmatch
import hashlib
import importlib
import keyword
Expand Down Expand Up @@ -1214,3 +1215,41 @@ def get_root(flproxy, version: str = "") -> Group:
root.set_flproxy(flproxy)
root._setattr("_static_info", obj_info)
return root


def find_children(obj, identifier="*"):
"""Returns path of all the child objects matching an identifier.

Parameters
----------
obj: Object
Object whose children need to be queried.
identifier: str
Identifier to find specific children.

Returns
-------
List
"""
list_of_children = []
_list_children(obj.__class__, identifier, [], list_of_children)
return list_of_children


def _list_children(cls, identifier, path, list_of_children):
if issubclass(cls, (NamedObject, ListObject)):
if hasattr(cls.child_object_type, "child_names"):
_get_child_path(cls.child_object_type, path, identifier, list_of_children)
if issubclass(cls, Group):
_get_child_path(cls, path, identifier, list_of_children)


def _get_child_path(cls, path, identifier, list_of_children):
for name in cls.child_names:
path.append(name)
if fnmatch.fnmatch(name, identifier):
path_to_append = "/".join(path)
if path_to_append not in list_of_children:
list_of_children.append(path_to_append)
_list_children(getattr(cls, name), identifier, path, list_of_children)
path.pop()
65 changes: 65 additions & 0 deletions tests/test_flobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
# import codegen.settingsgen
from collections.abc import MutableMapping
import io
import os
import weakref

import pytest
from util.solver_workflow import new_solver_session_no_transcript # noqa: F401

from ansys.fluent.core.examples import download_file
from ansys.fluent.core.solver import flobject
from ansys.fluent.core.solver.flobject import find_children

os.environ["PYFLUENT_FLUENT_ROOT"] = r"C:\ANSYSDev\ANSYSDev\vNNN\fluent"


class Setting:
Expand Down Expand Up @@ -727,6 +731,67 @@ def test_accessor_methods_on_settings_object_types(load_static_mixer_case):


@pytest.mark.dev
@pytest.mark.fluent_231
def test_find_children_from_settings_root():
from ansys.fluent.core.solver.settings_231.setup import setup

assert len(find_children(setup())) == 18514
assert len(find_children(setup(), "gen*")) == 9
assert find_children(setup(), "general*") == [
"general",
"models/discrete_phase/general_settings",
"models/virtual_blade_model/disk/general",
]
assert find_children(setup(), "general") == [
"general",
"models/virtual_blade_model/disk/general",
]
assert find_children(setup(), "*gen") == [
"boundary_conditions/exhaust_fan/phase/p_backflow_spec_gen",
"boundary_conditions/exhaust_fan/p_backflow_spec_gen",
"boundary_conditions/outlet_vent/phase/p_backflow_spec_gen",
"boundary_conditions/outlet_vent/p_backflow_spec_gen",
"boundary_conditions/pressure_outlet/phase/p_backflow_spec_gen",
"boundary_conditions/pressure_outlet/p_backflow_spec_gen",
]


@pytest.mark.dev
@pytest.mark.fluent_231
def test_find_children_from_fluent_solver_session(load_static_mixer_case):
setup_children = find_children(load_static_mixer_case.setup)

assert len(setup_children) == 18514

viscous = load_static_mixer_case.setup.models.viscous
assert find_children(viscous, "prod*") == [
"options/production_kato_launder",
"turbulence_expert/production_limiter",
]

assert find_children(
load_static_mixer_case.setup.boundary_conditions.pressure_outlet, "*_dir_*"
) == [
"phase/geom_dir_spec",
"phase/geom_dir_x",
"phase/geom_dir_y",
"phase/geom_dir_z",
"geom_dir_spec",
"geom_dir_x",
"geom_dir_y",
"geom_dir_z",
]

assert find_children(
load_static_mixer_case.setup.materials.fluid["air"].density.piecewise_polynomial
) == [
"minimum",
"maximum",
"number_of_coefficients",
"coefficients",
]


@pytest.mark.fluent_232
def test_settings_matching_names(new_solver_session_no_transcript) -> None:
solver = new_solver_session_no_transcript
Expand Down