Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
3b6cfde
local para
seanpearsonuk Jul 15, 2022
d6244a8
PoC
seanpearsonuk Jul 15, 2022
124d88a
local para
seanpearsonuk Jul 18, 2022
450bf0b
cons fix
seanpearsonuk Jul 18, 2022
37796a7
refactor
seanpearsonuk Jul 18, 2022
8947b52
test
seanpearsonuk Jul 18, 2022
9f98958
refactor
seanpearsonuk Jul 18, 2022
36fcdc9
spread values into runtime study
seanpearsonuk Jul 19, 2022
5b4081c
spread values into runtime study
seanpearsonuk Jul 19, 2022
7894299
spread values into runtime study
seanpearsonuk Jul 19, 2022
e170ab2
in parallel = tricky
seanpearsonuk Jul 19, 2022
3182b21
fix for class attributes
seanpearsonuk Jul 19, 2022
477c853
sync fix
seanpearsonuk Jul 19, 2022
01cdf7a
fix by using base dp expicitly
seanpearsonuk Jul 19, 2022
9a24ce6
nice refactor
seanpearsonuk Jul 19, 2022
e9a9fda
nice refactor
seanpearsonuk Jul 19, 2022
8aea774
nice refactor
seanpearsonuk Jul 19, 2022
8422186
nice refactor
seanpearsonuk Jul 20, 2022
87b2b59
nice refactor
seanpearsonuk Jul 20, 2022
6c64fd3
nice refactor
seanpearsonuk Jul 20, 2022
2207ebd
nice refactor
seanpearsonuk Jul 20, 2022
9438b83
nice refactor
seanpearsonuk Jul 20, 2022
511f28f
nice refactor
seanpearsonuk Jul 20, 2022
586ac90
h5py
seanpearsonuk Jul 20, 2022
a61b4b1
h5py
seanpearsonuk Jul 20, 2022
1eaf4eb
h5py
seanpearsonuk Jul 20, 2022
c42b5b4
h5py
seanpearsonuk Jul 20, 2022
e8b1416
test simplified
seanpearsonuk Jul 21, 2022
182117f
refac
seanpearsonuk Jul 21, 2022
318e7df
refac
seanpearsonuk Jul 21, 2022
de815d8
refac
seanpearsonuk Jul 21, 2022
5bf4b12
refac
seanpearsonuk Jul 21, 2022
bead2a9
refac
seanpearsonuk Jul 21, 2022
19da42b
test simplified
seanpearsonuk Jul 21, 2022
52f649e
testing
seanpearsonuk Jul 21, 2022
abc5c2a
name fix
seanpearsonuk Jul 21, 2022
ed4641d
tidy ups
seanpearsonuk Jul 21, 2022
3060593
tidy ups
seanpearsonuk Jul 21, 2022
36109ca
tidy up
seanpearsonuk Jul 21, 2022
fb269c1
tidy ups
seanpearsonuk Jul 21, 2022
e28c1d2
tidy ups
seanpearsonuk Jul 21, 2022
ceeb494
tidy ups
seanpearsonuk Jul 21, 2022
d3535ea
tidy ups
seanpearsonuk Jul 21, 2022
a6e811a
extend case reader
seanpearsonuk Jul 21, 2022
8b10386
conditional import
seanpearsonuk Jul 21, 2022
dee0406
review comments
seanpearsonuk Jul 22, 2022
de063f1
undo test changes
seanpearsonuk Jul 22, 2022
bd9bc74
.h5 checks
seanpearsonuk Jul 22, 2022
b98102b
.h5 checks
seanpearsonuk Jul 22, 2022
2195fa0
redo test changes so that tests don't fail
seanpearsonuk Jul 22, 2022
6a2c082
case reader
seanpearsonuk Jul 22, 2022
3c66f9f
Update conf.py
seanpearsonuk Jul 23, 2022
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
2 changes: 1 addition & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
# Intersphinx mapping
intersphinx_mapping = {
"python": ("https://docs.python.org/dev", None),
"scipy": ("https://docs.scipy.org/doc/scipy/reference", None),
"scipy": ("https://docs.scipy.org/doc/scipy", None),
"numpy": ("https://numpy.org/devdocs", None),
"matplotlib": ("https://matplotlib.org/stable", None),
"pandas": ("https://pandas.pydata.org/pandas-docs/stable", None),
Expand Down
2 changes: 2 additions & 0 deletions examples/00-parametric/parametric_static_mixer_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@
session.solver.tui.define.boundary_conditions.set.velocity_inlet(
"inlet1", (), "vmag", "yes", "inlet1_vel", 1, "quit"
)

session.solver.tui.define.boundary_conditions.set.velocity_inlet(
"inlet1", (), "temperature", "yes", "inlet1_temp", 300, "quit"
)

session.solver.tui.define.boundary_conditions.set.velocity_inlet(
"inlet2", (), "vmag", "yes", "no", "inlet2_vel", 1, "quit"
)

session.solver.tui.define.boundary_conditions.set.velocity_inlet(
"inlet2", (), "temperature", "yes", "no", "inlet2_temp", 350, "quit"
)
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ packages = [
python = ">=3.7,<4.0"
importlib-metadata = {version = "^4.0", python = "<3.8"}
ansys-fluent-core = "~=0.10"
h5py = ">=3.7.0"

[tool.black]
line-length = 88
Expand Down
71 changes: 47 additions & 24 deletions src/ansys/fluent/parametric/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,33 +185,33 @@ class ParametricStudy:
Update a list of design points.
"""

_all_studies: Dict[int, "ParametricStudy"] = {}
current_study_name = None

def __init__(
self,
parametric_studies,
session=None,
name: Optional[str] = None,
design_points: Dict[str, DesignPoint] = None,
):
self._parametric_studies = parametric_studies
self.session = (
session if session is not None else (_shared_parametric_study_registry())
)
self.name = name
self.design_points = {}
if design_points is not None:
self.design_points = design_points
self.project_filepath = None
ParametricStudy._all_studies[id(self)] = self
self.session.register_study(self)

@classmethod
def get_all_studies(cls) -> Dict[str, "ParametricStudy"]:
def get_all_studies(self) -> Dict[str, "ParametricStudy"]:
"""Get all currently active studies.

Returns
-------
Dict[str, "ParametricStudy"]
currently active studies
"""
return {v.name: v for _, v in cls._all_studies.items()}
return {v.name: v for _, v in self.session._all_studies.items()}

def initialize(self) -> "ParametricStudy":
"""Initialize parametric study."""
Expand All @@ -235,7 +235,7 @@ def initialize(self) -> "ParametricStudy":
self._parametric_studies[self.name].design_points[BASE_DP_NAME],
)
self.design_points = {BASE_DP_NAME: base_design_point}
ParametricStudy.current_study_name = self.name
self.session.current_study_name = self.name
return self
else:
LOG.error("initialize is not available")
Expand All @@ -258,13 +258,13 @@ def rename(self, new_name: str) -> None:
@property
def is_current(self) -> bool:
"""Whether the parametric study is the current parametric study."""
return ParametricStudy.current_study_name == self.name
return self.session.current_study_name == self.name

def set_as_current(self) -> None:
"""Set the parametric study as the current parametric study."""
if not self.is_current:
self._parametric_studies.set_as_current(self.name)
ParametricStudy.current_study_name = self.name
self.session.current_study_name = self.name

def duplicate(self, copy_design_points: bool = True) -> "ParametricStudy":
"""Duplicate the current study.
Expand All @@ -283,9 +283,7 @@ def duplicate(self, copy_design_points: bool = True) -> "ParametricStudy":
self._parametric_studies.duplicate(copy_design_points=copy_design_points)
new_study_names = self._parametric_studies.get_object_names()
clone_name = set(new_study_names).difference(set(old_study_names)).pop()
current_study = ParametricStudy.get_all_studies()[
ParametricStudy.current_study_name
]
current_study = self.get_all_studies()[self.session.current_study_name]
if copy_design_points:
clone_design_points = {
k: DesignPoint(k, self._parametric_studies[clone_name].design_points[k])
Expand All @@ -298,9 +296,9 @@ def duplicate(self, copy_design_points: bool = True) -> "ParametricStudy":
)
clone_design_points = {BASE_DP_NAME: base_design_point}
clone = ParametricStudy(
self._parametric_studies, clone_name, clone_design_points
self._parametric_studies, self.session, clone_name, clone_design_points
)
ParametricStudy.current_study_name = clone.name
self.session.current_study_name = clone.name
return clone

def delete(self) -> None:
Expand All @@ -309,7 +307,7 @@ def delete(self) -> None:
LOG.error("Cannot delete the current study %s", self.name)
else:
del self._parametric_studies[self.name]
ParametricStudy._all_studies.pop(id(self))
self.session._all_studies.pop(id(self))
del self

def use_base_data(self) -> None:
Expand Down Expand Up @@ -508,11 +506,15 @@ def __init__(
parametric_project,
parametric_studies,
project_filepath: str,
session=None,
open_project: bool = True,
):
self._parametric_project = parametric_project
self._parametric_studies = parametric_studies
self.project_filepath = project_filepath
self.session = (
session if session is not None else (_shared_parametric_study_registry())
)
if open_project:
self.open(project_filepath=project_filepath)

Expand All @@ -534,7 +536,7 @@ def open(
)
self.project_filepath = project_filepath
for study_name in self._parametric_studies.get_object_names():
study = ParametricStudy(self._parametric_studies, study_name)
study = ParametricStudy(self._parametric_studies, self.session, study_name)
dps_settings = self._parametric_studies[study_name].design_points
for dp_name in dps_settings.get_object_names():
study.design_points[dp_name] = DesignPoint(
Expand Down Expand Up @@ -600,7 +602,16 @@ def __call__(self):
return pyfluent.launch_fluent(*self._args, **self._kwargs)


class ParametricSession:
class ParametricStudyRegistry:
def __init__(self):
self._all_studies: Dict[int, "ParametricStudy"] = {}
self.current_study_name = None

def register_study(self, study):
self._all_studies[id(study)] = study


class ParametricSession(ParametricStudyRegistry):
"""ParametricSession class which encapsulates studies and project.

Attributes
Expand Down Expand Up @@ -645,42 +656,45 @@ def __init__(
Whether to start streaming of Fluent transcript, by default
False.
"""
super().__init__()
self.studies = {}
self.project = None
self._session = launcher()
self.scheme_eval = self._session.scheme_eval.scheme_eval
self.scheme_eval(
"(set parametric-study-dependents-manager " "save-project-at-exit? #f)"
)
if start_transcript:
self.start_transcript()
if not start_transcript:
self.stop_transcript()
self._root = self._session.solver.root
if case_filepath is not None:
self._root.file.read(file_name=case_filepath, file_type="case")
study = ParametricStudy(self._root.parametric_studies).initialize()
study = ParametricStudy(self._root.parametric_studies, self).initialize()
self.studies[study.name] = study
self.project = ParametricProject(
parametric_project=self._root.file.parametric_project,
parametric_studies=self._root.parametric_studies,
project_filepath=str(study.project_filepath),
open_project=False,
session=self._session,
)
elif project_filepath is not None:
self.project = ParametricProject(
parametric_project=self._root.file.parametric_project,
parametric_studies=self._root.parametric_studies,
project_filepath=project_filepath,
session=self._session,
)
studies_settings = self._root.parametric_studies
for study_name in studies_settings.get_object_names():
study = ParametricStudy(studies_settings, study_name)
study = ParametricStudy(studies_settings, self, study_name)
dps_settings = studies_settings[study_name].design_points
for dp_name in dps_settings.get_object_names():
study.design_points[dp_name] = DesignPoint(
dp_name, dps_settings[dp_name]
)
self.studies[study_name] = study
ParametricStudy.current_study_name = self._root.current_parametric_study()
self.current_study_name = self._root.current_parametric_study()

def new_study(self) -> ParametricStudy:
"""Create new study.
Expand All @@ -690,7 +704,7 @@ def new_study(self) -> ParametricStudy:
ParametricStudy
New study.
"""
study = self.studies[ParametricStudy.current_study_name].duplicate()
study = self.studies[self.current_study_name].duplicate()
self.studies[study.name] = study
return study

Expand Down Expand Up @@ -741,4 +755,13 @@ def stop_transcript(self) -> None:
self._session.stop_transcript()


def _shared_parametric_study_registry():
if _shared_parametric_study_registry.instance is None:
_shared_parametric_study_registry.instance = ParametricStudyRegistry()
return _shared_parametric_study_registry.instance


_shared_parametric_study_registry.instance = None


from ansys.fluent.parametric.parameters import InputParameters, OutputParameters
Loading