Skip to content

Commit cfd117b

Browse files
docs: use variable catalog (#4025)
Add PyFluent docs showing how to use `VariableCatalog` objects with its interfaces. --------- Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent d32f397 commit cfd117b

File tree

4 files changed

+81
-0
lines changed

4 files changed

+81
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use variable catalog
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
.. _user_guide_variables:
2+
3+
===============================
4+
Working with physical variables
5+
===============================
6+
7+
PyFluent integrates with the PyAnsys-units library, which provides a shared catalog of variable objects based on physical quantities like temperature, pressure, and velocity. These variable objects, or VariableDescriptors, can be used throughout PyFluent to reference fields and quantities in a clear, consistent, and reliable way.
8+
9+
Instead of relying on raw strings like ``"temperature"`` or ``"SV_T"``, which may vary between Fluent interfaces or be hard to interpret, you can use named descriptors from the catalog such as ``VariableCatalog``.``TEMPERATURE``). This improves code readability, reduces the chance of errors, and makes it easier to work across different APIs.
10+
11+
The same catalog is designed to work not just with PyFluent, but also with other PyAnsys libraries, offering a unified and expressive way to interact with physical quantities across products.
12+
13+
Overview
14+
--------
15+
16+
The key benefits of using the ``VariableCatalog`` include:
17+
18+
- Code that is portable across Ansys products and more resistant to typos
19+
- Simplified refactoring when field names change in Fluent or across versions
20+
- Integrated dimensional consistency (via ``ansys-units``)
21+
- Autocompletion and discoverability of supported quantities
22+
23+
Accessing field data
24+
---------------------
25+
26+
Here’s how to use ``VariableCatalog`` to read and reduce field data using unit-aware quantity references:
27+
28+
.. code-block:: python
29+
30+
from ansys.fluent.core import launch_fluent, examples
31+
from ansys.units.variable_descriptor import VariableCatalog
32+
33+
solver = launch_fluent()
34+
case_path = examples.download_file("mixing_elbow.cas.h5", "pyfluent/mixing_elbow")
35+
solver.file.read(file_type="case", file_name=case_path)
36+
37+
solver.settings.solution.initialization.hybrid_initialize()
38+
39+
temperature = VariableCatalog.TEMPERATURE
40+
locations = ["hot-inlet"]
41+
42+
# Access scalar field data
43+
temp_data = solver.fields.field_data.get_scalar_field_data(
44+
field_name=temperature, surfaces=locations
45+
)
46+
print(temp_data[locations[0]][0]) # value at hot-inlet
47+
48+
# Compute minimum of a physical quantity
49+
temp_min = solver.fields.reduction.minimum(expression=temperature, locations=locations)
50+
print(temp_min)
51+
52+
# Access solution variable data
53+
sol_data = solver.fields.solution_variable_data.get_data(
54+
solution_variable_name=temperature, zone_names=locations
55+
)
56+
print(sol_data[locations[0]][0])
57+
58+
Using variables with report definitions
59+
---------------------------------------
60+
61+
You can also use physical quantities in report definitions to improve clarity and maintainability:
62+
63+
.. code-block:: python
64+
65+
surface_report = solver.settings.solution.report_definitions.surface["avg_temp"]
66+
surface_report.report_type = "surface-areaavg"
67+
surface_report.field = temperature # Note: using VariableCatalog, not a string
68+
surface_report.surface_names = locations
69+
70+
result = solver.solution.report_definitions.compute(report_defs=["avg_temp"])
71+
print(result[0]["avg_temp"][0])
72+
73+
Notes
74+
-----
75+
76+
- All quantities used via ``VariableCatalog`` map to their correct Fluent field identifiers internally.
77+
- These objects can be validated against their expected dimensional types.
78+
- ``VariableCatalog`` is part of ``ansys-units``, which is automatically installed with PyFluent.

doc/source/user_guide/user_guide_contents.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ User guide
1616
monitors
1717
transfer_data
1818
units
19+
physical_variables
1920
file_transfer
2021
offline/offline_contents
2122
convert_journal

doc/styles/config/vocabularies/ANSYS/accept.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,4 @@ venv
8282
create_workflow
8383
load_workflow
8484
codegen
85+
discoverability

0 commit comments

Comments
 (0)