Overview
Ansys Fluent is powerful computational fluid dynamics software, and PyFluent is a Python library of remotable APIs for interacting with Ansys Fluent. PyFluent provides an interface for automating, customizing, and streamlining CFD workflows using the flexibility and power of Python. This blog post offers an overview of the Settings APIs and objects available in PyFluent to help you understand how to effectively utilize them to develop PyFluent workflows.Settings APIs and objects
You use the Settings APIs and objects to set up simulation workflows in a Pythonic way. The let you configure various aspects of the simulation, such as the solver settings, materials, boundary conditions, physical models, solution settings, and results postprocessing settings. The Settings APIs and objects are categorized into different groups based on their functionality. The following figure shows the Ansys Fluent Outline View and categorization.
child_names and command_names attributes on these objects.
child_names: An object property for retrieving the list of the names of the child’s objects.command_names: An object property for getting the list of the commands (methods) available for a given object.
Examples
1. Access the Settings APIs and objects
Thesolver is a top-level object. Here is how you access the solver.settings object and its child names:
solver object. Now access the solver’s settings object and its child:
solver.settings object. These child names correspond to specific categories or sections in the Fluent GUI, such as setup, solution, and results, letting you map the API output directly to the GUI structure for easier navigation and configuration.
The solver has the file object as child. This is how you access its child’s names:
file object. It has additional child objects, which you use to configure the file settings in Fluent for specific purposes. This code shows how to configure export settings:
export.settings object, which you can further use to configure the export settings in Fluent.
The file object also has a command_names property, which lists the available commands (methods) on the file object.
file object, which you can use to perform various file operations in Fluent, such as reading and writing case and data files, executing macros, and managing settings.
To read the case and data files, you use the read_case_data command, passing a file name as an argument:
help(solver.settings.file.read_mesh). In addition to information about the command, the help provides argument and usage information.
argument_names property.
read_case_data command, which you can use to read the case and data files in Fluent.
However, the discussed properties list all child names and command names (methods) available on the object, which can be overwhelming. To get only active child names and command names, use the get_active_child_names() and get_active_command_names() methods on the Settings objects, respectively.
There are many other methods and properties available on the Settings objects, such as get_state(), set_state(), print_state(), allowed_values(), min(), and max(). You can use them to get or set the state of the object, print the current state of the object, get the allowed values for a given command, and get the minimum and maximum values for a given object.
e.g.,
setup object and its child names, further access the models object and its child names, and enable the energy model.
setup object contains models as one of its child objects. Here is how you access the models object and view the name of its children:
models object, which can be used to configure various physical models in Fluent. The energy model can be accessed as follows:
energy model object, which you can use to configure the energy model in Fluent.
Print the current settings of the energy model object using the print_state() method:
enabled object is currently set to False, indicating that the energy model is disabled. To enable the energy model, the enabled object should be set to True (a Boolean value).
To enable the energy model, set the enabled object to True:
enabled object of the energy model to True, enabling the energy model in Fluent.
To verify that the energy model is enabled, print the current state of the energy model object again:
- Access the Settings APIs and objects in PyFluent.
- Use these APIs and objects to configure the simulation setup.
- Understand the hierarchy of the objects and APIs available in PyFluent with respect to the Ansys Fluent user interface.