API Structure and Hierarchy Overview
The Autodesk® CFD Scripting language uses elements that are common to many programming languages. The language is based on a series of classes. Each class has its own properties and methods. Python is conceptually similar to C++, but has certain unique syntactic and formatting elements.
This topic discusses some of the concepts of Python that are essential for using the Autodesk® CFD API.
A general resource is the Python Programming Language Official Web site: http://python.org/.
Modules
The top-level API structure relates directly to the Autodesk® CFD workflow. Functionality is divided into four distinct modules:
DC
- Decision Center
- Use DC for all Decision Center functionality including summary planes and summary points
DSE
- Design Study Environment
- Use DSE to interact with the user interface.
- Examples include showing a message in the Output bar and saving an image.
Results
- Use Results to access results visualization functionality.
- Examples include cut planes and wall results.
Setup
- Setup contains classes for interacting with the simulation hierarchy (DesignStudy, Design, Scenario, and Part).
- Use these to get these items from the current session.
- Perform many of the tasks available in the design study bar (create, clone, add).
To access functionality within a module, you must call it at the beginning of the script. It is good practice to initialize all modules to ensure that all necessary functionality is available. To do this, include the following lines at the beginning of your scripts:
from CFD import Setup
from CFD import Results
from CFD import DSE
from CFD import DC
API Hierarchy
Each module contains a series of classes. Each class contains methods.
- A class is a pre-defined data type that is a “building block” for a Autodesk® CFD analysis.
- Every class contains properties, which describe certain aspects of the class.
- Classes also contain functions. These are class operations that either change an object’s internal state or provide information about the state.
- An object is a specific instance of a class.
Class Structure
The API class structure has a specific hierarchy. Object is the top-level class, and has several classes below it. The Container and SummaryObject classes have child classes of their own. The complete class structure is shown:
To call a specific static function, use the following structure:
Module.class.function
For example, to define a variable called study as the current design study, use this command:
study = Setup.DesignStudy.Create()
This calls the Create function, which is in the DesignStudy class, which is in the Setup module.
Inheritance
Classes in the API contain member functions that enable specific functionality. Sub-classes contain unique member functions, and also inherit the member functions of the parent class.
This concept is called inheritance. It is an important concept of the API.
For example, the SummaryPart class contains its members, plus the members in the SummaryObject class, and those in the Object class:
To see all of the members accessible from a class, click List of all members on the API Programming Reference page that describes the class. Here is the list for the SummaryPart class:
Function Types
The two primary types of functions owned by most classes are Static Public Member Functions and Public Member Functions.
Static Public Member Functions
Static public member functions can be used if a particular instance of the class does not currently exist. Many static public member functions are used for creating entities.
For example, in the DesignStudy class, Create is a static member function used for creating or getting the current design study. The command to get the design study object is:
Setup.DesignStudy.Create()
Public Member Functions
Public member functions perform actions on or to an actual object that already exists.
For example, in the DesignStudy class, Save is a public member function that acts on a design study that already exists. (It is not possible to save a design study that does not exist.)
Related Topics