By using ACT extensions in AIM, you have the ability to create a complete CFD system encapsulating existing boundary conditions. This section discusses the customization of AIM to expose a fluids system with access to all available boundary conditions.
You can have one load per boundary condition and have access to all fluid boundary conditions (such as inlet, outlet, wall, and so on). The boundary conditions appear as scoping properties. In some instances, you can also add an inlet velocity and an outlet pressure to standard boundary conditions.
Fluids extensions developed in AIM are very similar in construction to other extensions developed in AIM or Workbench. As with other extensions, each AFD extension developed in AIM has an XML extension definition file and an IronPython script.
The XML file has a block for defining buttons and toolbars and a block containing callbacks and properties for defining the load.
The script defines the functions invoked by the events and callbacks in the XML file to implement the behavior of the extension.
This section describes a theoretical extension named AFDLoad. This example is for demonstration purposes only.
The XML extension definition file AFDLoad.xml follows. This extension is used to create a CFD system with full access to available boundary conditions.
<extension version="1" name="AFDLoad">
<script src="main.py" />
<interface context="Study">
<images>images</images>
</interface>
<simdata context="Study">
<load name="InOut" version="1" caption="InOut" icon="support" issupport="true" color="#0000FF">
<callbacks>
<getsolvecommands>getcmds</getsolvecommands>
</callbacks>
<property name="Inlet" caption="Inlet" control="scoping" />
<property name="Outlet" caption="Outlet" control="scoping" />
<property name="InletVelocity" caption="Inlet Velocity" control="float" unit="Velocity"
default="1 [m s^-1]"/>
<property name="OutletPressure" caption="Outlet Pressure" control="float" unit="Pressure"
default="0 [Pa]"/>
</load>
</simdata>
</extension>This XML file has the standard ACT construction, with the
<extension> block defining the attributes
version and name, and the
<script> block specifying the IronPython script
main.py. The <interface>
block sets the attribute context to
Study to indicate that the extension is for AIM.
As in the AIM preprocessing example, the
<simdata> block encapsulates the definition of
the load. The attribute context is set to
Study, and the attributes in the
<load> block provide the name, version,
caption, icon, support status, and color that apply to the load that contains
the boundary condition. In this example, both the load name and caption are
InOut. As before, the
<callbacks> block encapsulates the function
<getsolvecommands>, which creates the boundary
conditions for the load.
In the callbacks definition, the load properties to use for the boundary
conditions are defined: Inlet,
Outlet, Inlet Velocity,
Velocity, Outlet Pressure, and
Pressure. The attributes
control,unit, and
default function as described in previous examples.
These properties are displayed in the specific ACT object created when the user
provides the necessary values to complete the load definition.
The IronPython script main.py for the extension AFDLoad follows.
Note: In future releases, the IronPython commands used to define fluid dynamics features might be modified to ensure consistency with AIM journaling and scripting functionality. For information on whether a given command has been modified or deprecated, refer to the ANSYS ACT API Reference Guide.
import clr
clr.AddReference("Ansys.Study.Proxies.Customization")
from Ansys.Study.Proxies.Customization.Analysis import AFDObject
def getcmds(load,stream):
velocity = load.Properties["InletVelocity"]
pressure = load.Properties["OutletPressure"]
faces = []
faces += load.Properties["Inlet"].Value.Ids
faces += load.Properties["Outlet"].Value.Ids
geo = load.Analysis.GeoData
wallFaces = []
for part in geo.Assemblies[0].Parts:
for body in part.Bodies:
for face in body.Faces:
if not faces.Contains(face.Id) and not wallFaces.Contains(face.Id):
wallFaces.Add(face.Id)
boundary = AFDObject.CreateBoundary()
boundary.SetProperty("BoundaryType","Inlet")
boundary.SetProperty("Location",load.Properties["Inlet"].Value.Ids)
boundary.SetProperty("Flow.Option","Velocity")
boundary.SetProperty("Flow.Velocity.Magnitude",velocity.Value.ToString()+' ['+velocity.UnitString+']')
boundary.Send(stream)
boundary = AFDObject.CreateBoundary()
boundary.SetProperty("BoundaryType","Outlet")
boundary.SetProperty("Location",load.Properties["Outlet"].Value.Ids)
boundary.SetProperty("Flow.Option","Pressure")
boundary.SetProperty("Flow.Pressure.GaugeStaticPressure",pressure.Value.ToString()+'
['+pressure.UnitString+']')
boundary.Send(stream)
boundary = AFDObject.CreateBoundary()
boundary.SetProperty("BoundaryType","Wall")
boundary.SetProperty("Location",wallFaces)
boundary.Send(stream) The function getcmds is defined in the script
main.py. This function writes commands to the solver
input file. The required input arguments are load and
stream, where load is the load
object and stream is the solver input file. In the XML
file, the callback <getsolvecommands> references
the function getcmds. When called, this function creates
the boundaries for AFDObject, defines boundary
properties, and specifies the faces to which to apply the boundary. Within this
function:
The method CreateBoundary() is applied to
AFDObject to create a boundary.
(AFDObject was imported by the command
import at the top of the
script.)
boundary = AFDObject.CreateBoundary()
In the section faces, you can specify:
The faces to use in the inlet and
outlet properties.
The faces belonging to the wall (which
are all faces not already used for the
inlet and
outlet properties).
With boundary.SetProperty, you specify the
boundary type, such as inlet, outlet, wall, and so on. It can also be
applied to the boundary object to add a property. As part of the
argument, you must specify both the type of property to add and the
value to assign.
For example, the following code segment specifies the creation of an inlet boundary.
boundary.SetProperty("BoundaryType","Inlet")With boundary.SetProperty, you can also specify
the location (faces, bodies, and so on) to which the boundary applies.
To do so, you can use the scoping properties previously defined in the
extension. The property location expects a list
of identifiers.
boundary.SetProperty("Location",load.Properties["Inlet"].Value.Ids)To the property just added, you can add an option representing a velocity (for an inlet) or a pressure (for an outlet).
boundary.SetProperty("Flow.Option","Velocity")To the option just added, you can add a float value and specify a unit. The float value can come from a property defined in the XML file.
boundary.SetProperty("Flow.Velocity.Magnitude",velocity.Value.ToString()+' ['+velocity.UnitString+']')Finally, you write the command generated by creation of the boundary.
boundary.Send(stream)
The following figure shows that the load InOut that you
created in ACT is now available as a fluids boundary condition in AIM. This load
includes all of the properties defined in the extension.
The following figure shows the status of the load once all of the properties are defined.