Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
df68d26
Add get and create methods to objects
Gobot1234 Jan 27, 2026
61d4c66
Update src/ansys/fluent/core/solver/settings_builtin_bases.py
Gobot1234 Jan 28, 2026
f274df3
add a test case
Gobot1234 Jan 28, 2026
4e5c6be
check get on non creatable objects
Gobot1234 Jan 28, 2026
269c59e
chore: adding changelog file 4866.added.md [dependabot-skip]
pyansys-ci-bot Jan 28, 2026
c40e9ed
chore: adding changelog file 4866.added.md [dependabot-skip]
pyansys-ci-bot Jan 28, 2026
91882b2
Update src/ansys/fluent/core/solver/flobject.py
Gobot1234 Jan 28, 2026
9430310
fix tests + warning and fmt
Gobot1234 Jan 28, 2026
c38d797
generate the types for this
Gobot1234 Jan 28, 2026
9d6dacc
slightly fix up generation
Gobot1234 Jan 28, 2026
73cafbe
add all
Gobot1234 Jan 28, 2026
d42a24a
add some more tests
Gobot1234 Jan 28, 2026
779bb60
Apply suggestions from code review
Gobot1234 Jan 28, 2026
51664a4
Apply suggestions from code review
Gobot1234 Jan 29, 2026
c3c5aee
Merge branch 'main' into jhilton/create-and-find
Gobot1234 Feb 3, 2026
20ce7f9
add more tests and fix the data
Gobot1234 Feb 3, 2026
ae11446
Merge branch 'jhilton/create-and-find' of https://github.com/ansys/py…
Gobot1234 Feb 3, 2026
fedf799
touch of work still doesnt work
Gobot1234 Feb 13, 2026
fb48b06
add all as an alias for allowed_values
Gobot1234 Mar 16, 2026
a81582c
Merge branch 'main' into jhilton/create-and-find
Gobot1234 Apr 24, 2026
dae1864
Apply suggestions from code review
Gobot1234 May 5, 2026
644de8b
update docs
May 12, 2026
a173cd8
make stuff actually work
May 12, 2026
4be2437
remove unsupported tests
May 12, 2026
83f560d
chore: adding changelog file 4866.added.md [dependabot-skip]
pyansys-ci-bot May 12, 2026
61e1717
add some comments
Gobot1234 May 13, 2026
f22c11d
Update src/ansys/fluent/core/codegen/builtin_settingsgen.py
Gobot1234 May 13, 2026
2a8df61
Potential fix for pull request finding
Gobot1234 May 13, 2026
e48d985
remove warning as it's too noisy
May 14, 2026
4bf9cdf
more service fixes
May 14, 2026
f9724f6
chore: adding changelog file 4866.added.md [dependabot-skip]
pyansys-ci-bot May 14, 2026
a29e52c
add missing reciprocals
May 14, 2026
95558fe
remove kwarg setting source
May 14, 2026
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
10 changes: 6 additions & 4 deletions src/ansys/fluent/core/solver/flobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,7 @@ def to_python_keys(cls, value):
query_names = []
_child_aliases = {}

def _create_child_object(self, cname: str):
def _create_child_object(self, cname: str, **kwargs: Any):
ret = self._objects.get(cname)
if not ret:
cls = self.__class__.child_object_type
Expand All @@ -1399,6 +1399,7 @@ def _create_child_object(self, cname: str):
"rename",
types.MethodType(lambda obj, name: _rename(self, name, cname), ret),
)
ret.set_state(kwargs)
Comment thread
Gobot1234 marked this conversation as resolved.
Outdated
return ret

def _update_objects(self):
Expand Down Expand Up @@ -1451,7 +1452,7 @@ def get_object_names(self):
obj_names_list = obj_names if isinstance(obj_names, list) else list(obj_names)
return obj_names_list

def __getitem__(self, name: str) -> ChildTypeT:
def __getitem__(self, name: str, **kwargs: Any) -> ChildTypeT:
Comment thread
Gobot1234 marked this conversation as resolved.
Comment thread
Gobot1234 marked this conversation as resolved.
if name not in self.get_object_names():
if self.flproxy.has_wildcard(name):
child_cls = self.__class__.child_object_type
Expand All @@ -1473,7 +1474,7 @@ def __getitem__(self, name: str) -> ChildTypeT:

obj = self._objects.get(name)
if not obj:
obj = self._create_child_object(name)
obj = self._create_child_object(name, **kwargs)
Comment thread
Gobot1234 marked this conversation as resolved.
return obj

def get(self, name: str) -> ChildTypeT:
Expand Down Expand Up @@ -1843,7 +1844,8 @@ def execute_command(self, *args, **kwds):
and isinstance(self._parent, NamedObject)
and ret in self._parent
):
Comment thread
Gobot1234 marked this conversation as resolved.
return self._parent[ret]
nameless_kwargs = {k: v for k, v in kwds.items() if k != "name"}
return self._parent.__getitem__(ret, **nameless_kwargs)
Comment thread
Gobot1234 marked this conversation as resolved.
Outdated
return_t = getattr(self, "return_type", None)
if return_t:
base_t = _baseTypes.get(return_t)
Expand Down
69 changes: 51 additions & 18 deletions src/ansys/fluent/core/solver/settings_builtin_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@

"""Base classes for builtin setting classes."""

from typing import Protocol, runtime_checkable
from typing import Any, Protocol, runtime_checkable

from typing_extensions import Self

from ansys.fluent.core.solver.flobject import (
Comment on lines +27 to 30
InactiveObjectError,
Comment on lines +27 to 31
Expand Down Expand Up @@ -82,19 +84,19 @@ def _get_settings_obj(settings_root, builtin_settings_obj):
return obj


def _initialize_settings(instance, defaults: dict, settings_source=None, **kwargs):
active_session = _get_active_session()
instance.__dict__.update(defaults | kwargs)
if settings_source is not None:
instance.settings_source = settings_source
elif active_session:
instance.settings_source = active_session

class _SettingsInitializerMixin:
def __init__(self, defaults: dict, settings_source: SettingsBase | Solver | None = None, **kwargs: Any):
active_session = _get_active_session()
self.__dict__.update(defaults | kwargs)
if settings_source is not None:
self.settings_source = settings_source
elif active_session:
self.settings_source = active_session

class _SingletonSetting:
class _SingletonSetting(_SettingsInitializerMixin):
# Covers groups, named-object containers and commands.
def __init__(self, settings_source: SettingsBase | Solver | None = None, **kwargs):
_initialize_settings(self, {"settings_source": None}, settings_source, **kwargs)
super().__init__({"settings_source": None}, settings_source, **kwargs)

def __setattr__(self, name, value):
if name == "settings_source":
Expand All @@ -106,14 +108,25 @@ def __setattr__(self, name, value):
else:
super().__setattr__(name, value)

@classmethod
def get(cls, settings_source: SettingsBase | Solver | None = None, /, * name: str) -> Self:
Comment thread
Gobot1234 marked this conversation as resolved.
Outdated
"""Get and return the singleton instance of this object in Fluent.

Parameters
----------
settings_source
Something with a .settings attribute. If omitted the active session assumed from the :func:`using` context manager.
Comment thread
Gobot1234 marked this conversation as resolved.
Outdated
name
Name of the object to get, if applicable, can be a wildcard pattern.
Comment thread
Gobot1234 marked this conversation as resolved.
Outdated
"""
return cls(settings_source=settings_source, name=name)


class _NonCreatableNamedObjectSetting:
class _NonCreatableNamedObjectSetting(_SettingsInitializerMixin):
def __init__(
self, name: str, settings_source: SettingsBase | Solver | None = None, **kwargs
):
_initialize_settings(
self, {"settings_source": None, "name": name}, settings_source, **kwargs
)
super().__init__({"settings_source": None, "name": name}, settings_source, **kwargs)

def __setattr__(self, name, value):
if name == "settings_source":
Expand All @@ -127,7 +140,7 @@ def __setattr__(self, name, value):
super().__setattr__(name, value)


class _CreatableNamedObjectSetting:
class _CreatableNamedObjectSetting(_SettingsInitializerMixin):
def __init__(
self,
settings_source: SettingsBase | Solver | None = None,
Expand All @@ -137,8 +150,7 @@ def __init__(
):
if name and new_instance_name:
raise ValueError("Cannot specify both name and new_instance_name.")
_initialize_settings(
self,
super().__init__(
{
"settings_source": None,
"name": name,
Expand All @@ -148,6 +160,27 @@ def __init__(
**kwargs,
)

@classmethod
def create(cls, settings_source: SettingsBase | Solver | None = None, /, name: str | None = None, **kwargs: Any) -> Self:
"""Create and return an instance of this object in Fluent.

Parameters
----------
settings_source
Something with a .settings attribute. If omitted the active session assumed from the :func:`using` context manager.
Comment thread
Gobot1234 marked this conversation as resolved.
Outdated
name
Name of the new object to create. If omitted, a default name will be assigned by Fluent.
**kwargs
Additional attributes to set on the created object. This only works for direct value assignments, not for nested objects.
Comment thread
Gobot1234 marked this conversation as resolved.
"""
self = cls(
settings_source=settings_source,
new_instance_name=name,
)
self.set_state(kwargs)

return self

def __setattr__(self, name, value):
if name == "settings_source":
settings_root = _get_settings_root(value)
Expand Down
Loading