-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Builtin settings objects from Setup section of Fluent's outline…
… tree (#3127) feat: Initial implementation of settings objects
- Loading branch information
Showing
7 changed files
with
626 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
"""Generate builtin setting classes.""" | ||
|
||
from ansys.fluent.core import CODEGEN_OUTDIR, FluentVersion | ||
from ansys.fluent.core.solver.settings_builtin_data import DATA | ||
|
||
_PY_FILE = CODEGEN_OUTDIR / "solver" / "settings_builtin.py" | ||
_PYI_FILE = CODEGEN_OUTDIR / "solver" / "settings_builtin.pyi" | ||
|
||
|
||
def generate(): | ||
"""Generate builtin setting classes.""" | ||
CODEGEN_OUTDIR.mkdir(exist_ok=True) | ||
with open(_PY_FILE, "w") as f: | ||
f.write('"""Solver settings."""\n\n') | ||
f.write( | ||
"from ansys.fluent.core.solver.settings_builtin_bases import _SingletonSetting, _NamedObjectSetting\n\n\n" | ||
) | ||
f.write("__all__ = [\n") | ||
for name, _ in DATA.items(): | ||
f.write(f' "{name}",\n') | ||
f.write("]\n\n") | ||
for name, v in DATA.items(): | ||
kind, path = v | ||
f.write(f"class {name}(_{kind}Setting):\n") | ||
f.write(f' """{name} setting."""\n\n') | ||
|
||
with open(_PYI_FILE, "w") as f: | ||
for version in FluentVersion: | ||
f.write( | ||
f"from ansys.fluent.core.generated.solver.settings_{version.number} import root as settings_root_{version.number}\n" | ||
) | ||
f.write("\n\n") | ||
for name, v in DATA.items(): | ||
kind, path = v | ||
f.write(f"class {name}(\n") | ||
if isinstance(path, str): | ||
path = {v: path for v in FluentVersion} | ||
for v, p in path.items(): | ||
if kind == "NamedObject": | ||
p = f"{p}.child_object_type" | ||
f.write(f" type(settings_root_{v.number}.{p}),\n") | ||
f.write("): ...\n\n") | ||
|
||
|
||
if __name__ == "__main__": | ||
generate() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"""Base classes for builtin setting classes.""" | ||
|
||
from ansys.fluent.core.session_solver import Solver | ||
from ansys.fluent.core.solver.settings_builtin_data import DATA | ||
|
||
|
||
class _SingletonSetting: | ||
def __new__(cls, solver: Solver): | ||
obj = solver.settings | ||
path = DATA[cls.__name__][1] | ||
if isinstance(path, dict): | ||
version = solver.get_fluent_version() | ||
path = path.get(version) | ||
if path is None: | ||
raise RuntimeError( | ||
f"{cls.__name__} is not supported in Fluent version {version}." | ||
) | ||
for comp in path.split("."): | ||
obj = getattr(obj, comp) | ||
return obj | ||
|
||
|
||
class _NamedObjectSetting(_SingletonSetting): | ||
def __new__(cls, solver: Solver, name: str): | ||
obj = super().__new__(cls, solver) | ||
return obj[name] |
Oops, something went wrong.