The introspection.py module#
Summary#
Split a Fluent path into its attribute components. |
|
Resolve a Fluent settings |
|
Try the Scheme |
|
Walk the settings tree and collect every named-object collection. |
|
Replicate the legacy targeted-context endpoint against a live solver. |
|
Fetch state for the requested paths, defaulting to the global set. |
Description#
Live introspection helpers shared by backends.
These mirror the behavior of the legacy
/fluent_get_targeted_context and /fluent_get_state endpoints from
aali-flowkit-python. Keeping the logic in one place keeps PyFluent and
any future in-process backend (such as Discovery or Prime) consistent.
All functions take a root (the Settings root of a connected solver)
and operate on caller-provided paths. There are no hardcoded collection lists.
Module detail#
- introspection.normalise_attr_path(path: str) list[str]#
Split a Fluent path into its attribute components.
Accepts both slash/dash format (
setup/boundary-conditions/velocity-inlet) and dot/underscore format (setup.boundary_conditions.velocity_inlet) plus indexed instances like...velocity_inlet[cold-in].Dash-to-underscore conversion is applied only to attribute name segments, never to text inside
[...](which is the instance key and may legitimately contain dashes).
- introspection.resolve_path(root: Any, path: str) Any#
Resolve a Fluent settings
pathagainstroot(== solver.settings).Supports indexed segments such as
...velocity_inlet[cold-in]for named-object instance access. RaisesAttributeError/KeyErrorif the path does not resolve.Dotted segments that are not exposed as Python attributes (such as a NamedObject key containing a dash, like
phase.phase-1.momentum) are transparently re-tried as__getitem__lookups. This lets callers write the same dotted form for attribute children and NamedObject keys, matching how the agent expresses query predicates.- Parameters:
- root
Any Root to supply to the function.
- path
str Fluent object path or file-system path to inspect.
- root
- Returns:
AnyResult produced by the function.
- introspection.discover_named_objects_via_scheme(solver: Any) dict[str, list[str]] | None#
Try the Scheme
api-get-named-object-namesAPI.Returns a
{path: [names]}mapping if successful, otherwiseNone(Caller falls back to a recursive walk.)Fluent’s
api-get-named-object-namesiterates every known named-object type and callsapi-get-object-nameson each. For inactive types (such assetup/solid-regionsandsetup/turbo-interfaceswhen those physics aren’t enabled), the inner Scheme printsError: api-get-object-names: Object is invalidto the Fluent transcript as a side-effect oferr-protect. The return value is still complete, but the transcript noise is visible to the user. The call is wrapped inwith-output-to-port (open-output-string)so those diagnostic prints land in a discarded string sink instead of the transcript. They fall back to the unwrapped form if the Scheme dialect does not support that pattern.
- introspection.discover_named_objects_via_walk(root: Any, *, max_depth: int = 4, max_entries: int = 200) dict[str, list[str]]#
Walk the settings tree and collect every named-object collection.
A node is considered a named-object collection if it exposes
get_object_names()(or has dictionary-likekeys()).Returns a mapping of slash-separated path → list of instance names.
- introspection.collect_targeted_context(root: Any, *, paths_to_check: Iterable[str], named_object_types: Iterable[str] = (), instance_state_fetch: Iterable[str] = ()) dict[str, Any]#
Replicate the legacy targeted-context endpoint against a live solver.
Returns a dictionary with the following keys (all optional. Missing entries simply don’t appear.
active_status: path → boolstate_values: path → state value (or")" child_names: path → list of child setting namesnamed_objects: type_path → list of instance namesallowed_values: property path → list of allowed valuesphase_property_map: phase_name → list of property categories
- Parameters:
- Returns:
- introspection.collect_global_state(root: Any, paths: Iterable[str] | None = None) dict[str, Any]#
Fetch state for the requested paths, defaulting to the global set.
Always probes
is_active()before callingget_state()so that inactive objects (such assetup/models/viscouswhile the model is not enabled) yield a structured{"inactive": True}marker rather than raising the PyFluentobject is inactiveRuntimeError. This matches the gating already done incollect_targeted_context()and theactive?semantics defined by the Fluent Settings API, where every setting may declare anactive?predicate.