The extension PressureLoss contains a project wizard with
the same name that is run from the AIM Project tab. This example calculates the
maximum velocity and pressure loss for a CFD system with one inlet and three
outlets.
The XML syntax used to define a project wizard run in AIM is the same as that used to define a project wizard run in Workbench.
No <uidefinition>
block is defined for an AIM wizard (custom template). The layout for AIM
is predefined.
Definitions follow for codes blocks in the XML extension definition file PressureLoss.xml.
The <extension> block is the top-most
level in the hierarchy.
The attributes name and
version specify the extension
name and version.
The attribute icon specifies
the image file to display as the icon for the extension.
You specify the location of the
images folder for all images
used by the extension in the
<interface> block.
The <guid> block specifies a unique
identifier for the extension.
The <script> block specifies the
IronPython script that is referenced by the extension. This
extension references pressureLoss.py.
The <interface> block defines the
user interface for the wizard.
The attribute context is set to
Project because the extension is
executed on the AIM Project tab.
The attribute images specifies the
images folder for all images that
the extension is to use. You use the attribute
icon for the extension, wizard,
step, and so on to specify an image file in this folder to
display as the icon.
The wizard PressureLoss and its steps are
defined in the <wizard> block named
PressureLoss.
The attributes name and
version specify the wizard name
and version.
The attribute context specifies the
ANSYS product in which the wizard is executed. Because this
wizard runs from the AIM Project tab,
context is set to
Project.
The attribute icon specifies the
filename of the image to display as the icon for the wizard:
images\loss.png. The file
loss.png is stored in the
images folder specified for the
attribute images in the
<interface> block.
The attribute description specifies
the text to display in the About window
for the extension when it is accessed from the
Extension Manager and in the
About window for the wizard when it
is accessed from the Wizards
page.
The <step> blocks are used to define
the steps of the wizard. There are four steps:
Step1, Step2,
Step3, and
Step4.
For each step:
The attributes name,
version, and
caption specify the name,
version, and display text for the step.
The attribute context specifies the
context in which the specific step is executed. You only
need to set the context for the step if it differs from the
context for the wizard.
The attribute HelpFile specifies
the HTML file to display as the custom help for the step. In
this example, the help provided for each step indicates
where each property is displayed in the
Study panel.
The <callbacks> blocks
specify callbacks to functions defined in the IronPython
script.
For step Step1, the
callback <onupdate>
executes the function
importGeometry. This step
creates the CFD workflow, importing and then
generating the specified geometry when the
Next button is
clicked.
For step Step2, the
callback <onupdate>
executes the function
refineMesh. This step
allows the user to specify the mesh resolution and
then refines the mesh accordingly when the
Next button is
clicked.
For step Step3, the
callback <onrefresh>
executes the function
initLocations. The callback
<onupdate> executes
the function setup. This step
enables the user to specify the loads applied to the
inlet and outlet, selecting a location and
specifying a load (Velocity
for the Inlet and
Gauge Pressure for the
Outlet).
The callback
<isvalid> on the
property OutletLocation
executes the action isValid,
validating the value selected for the outlet
location.
For step Step4, no callbacks are
required. This step takes the value calculated for the
property CalculatedMaximum and
populates it to the Calculated maximum
field of the Velocity object.
Any <propertygroup> blocks
specify groupings of properties within the step. Any
<property> blocks specify
properties and property attributes.
The XML extension definition file PressureLoss.xml follows.
<extension version="1" name="PressureLoss" icon="images\loss.png">
<guid shortid="PressureLoss">74182c0a-16ea-4169-8a55-00bad98afb6c</guid>
<author>ANSYS Inc.</author>
<description>Demonstration of a pressure loss in AIM.</description>
<script src="pressureLoss.py" />
<interface context="Project">
<images>images</images>
</interface>
<wizard name="PressureLoss" version="1" context="Project" icon="loss">
<description>This wizard is for demonstration of ACT wizard capability in AIM.</description>
<step name="Step1" caption="Import the geometry" version="1" context="Project" HelpFile="help/geometry.html">
<description>Import the geometry file and create the workflow.</description>
<callbacks>
<onupdate>importGeometry</onupdate>
</callbacks>
<property name="geometryfile" caption="geometry file" control="fileopen"
default="E:\Geometry\TubeSelectionSet.agdb"/>
</step>
<step name="Step2" caption="Refine the mesh" version="1" context="Project" HelpFile="help/mesh.html">
<description>Refine the mesh from Low to High.</description>
<callbacks>
<onupdate>refineMesh</onupdate>
</callbacks>
<property name="MeshResolution" caption="mesh resolution" control="integer" default="1"/>
</step>
<step name="Step3" caption="Define the loads" version="1" context="Project" HelpFile="help/loads.html">
<description>Specify the loads to applied on the geometry.</description>
<callbacks>
<onrefresh>initLocations</onrefresh>
<onupdate>setup</onupdate>
</callbacks>
<propertygroup name="Inlet" caption="Inlet">
<property name="Velocity" caption="Velocity" control="float" unit="Velocity" default="0.1 [m s^-1]"/>
<property name="InletLocation" caption="InletLocation" control="select" />
</propertygroup>
<propertygroup name="Outlet" caption="Outlet">
<property name="GaugePressure" caption="Gauge Pressure" control="float" unit="Pressure"
default="0 [Pa]"/>
<property name="OutletLocation" caption="OutletLocation" control="select" >
<callbacks>
<isvalid >isValid</isvalid>
</callbacks>
</property>
</propertygroup>
</step>
<step name="Step4" caption="Export the maximum velocity" version="1" context="Project"
HelpFile="help/result.html">
<description>Here we are just exposing the value of the maximum velocity and the pressure
loss.</description>
<property name="MaximumVelocity" caption="Maximum Velocity" control="float" unit="Velocity"
readonly = "True"/>
<property name="PressureLoss" caption="Pressure Loss" control="float" unit="Pressure" readonly = "True"/>
</step>
</wizard>
</extension>The IronPython script pressureLoss.py follows. This script defines all functions executed by the callbacks in the XML extension definition file. Each step defined in the XML file can include multiple actions.
meshingComponent1 = None
study1 = None
physicsDefinitionComponent1 = None
resultsEvaluationComponent1 = None
solvePhysicsComponent1 = None
physicsRegion1 = None
vectorResult1 = None
singleValueResult1 = None
results1 = None
materialAssignment1 = None
currentStep = None
clr.AddReference("Ans.UI")
def getSelectionSetsForProject():
context = __scriptingEngine__.CommandContext
project = context.Project
containers = project.GetContainers()
dataEntity = "SelectionSet"
for container in containers:
if container.Name == "Study":
try:
lockObject = context.ContainerReadLock(container)
dataReferences = project.GetDataReferencesByType(container, dataEntity)
finally:
lockObject.Dispose()
break
return dataReferences
def initLocations(step):
list = getSelectionSetsForProject()
propIn = step.Properties["Inlet/InletLocation"]
propIn.Options.Clear()
propOut = step.Properties["Outlet/OutletLocation"]
propOut.Options.Clear()
for sel in list:
ExtAPI.Log.WriteMessage("OPTION: "+sel.DisplayText)
propIn.Options.Add(sel.DisplayText)
propOut.Options.Add(sel.DisplayText)
comp = step.UserInterface.GetComponent("Properties")
comp.UpdateData()
comp.Refresh()
def isValid(step, property):
if property.Value == step.Properties["Inlet/InletLocation"].Value:
ExtAPI.Log.WriteWarning("Inlet and Outlet locations must be different.")
return False
return True
def importGeometry(step):
global meshingComponent1, study1, results1, vectorResult1, singleValueResult1, physicsDefinitionComponent1,
resultsEvaluationComponent1, solvePhysicsComponent1, physicsRegion1, materialAssignment1
with Transaction():
system1 = GetSystem(Name="Study")
physicsDefinitionComponent1 = Study.CreateTask( Type="Physics Definition", System=system1)
study1 = system1.GetContainer(ComponentName="Study")
physicsDefinition1 = physicsDefinitionComponent1.GetTaskObject()
physicsRegion1 = study1.CreateEntity( Type="PhysicsRegion", Association=physicsDefinition1)
solverSettings1 = study1.CreateEntity( Type="SolverSettings", Association=physicsDefinition1)
solvePhysicsComponent1 = Study.CreateTask( Type="Solve Physics", System=system1,
Input=physicsDefinitionComponent1)
solvePhysicsComponent1.Refresh()
resultsEvaluationComponent1 = Study.CreateTask( Type="Results Evaluation", System=system1,
Input=solvePhysicsComponent1)
resultsEvaluationComponent1.Refresh()
physicsDefinition1.CalculationType = "Static"
physicsRegion1.PhysicsType = "Fluid"
physicsRegion1.Location = "AllBodies()"
materialAssignment1 = study1.CreateEntity( Type="MaterialAssignment", Association=physicsDefinition1)
material1 = study1.CreateEntity( Type="Material", Association=physicsDefinition1)
material1.ImportEngineeringData(Name="Air")
materialAssignment1.Material = material1
materialAssignment1.Location = [physicsRegion1]
results1 = resultsEvaluationComponent1.GetTaskObject()
vectorResult1 = study1.CreateEntity( Type="VectorResult", Association=results1)
vectorResult1.Variable = "Velocity"
vectorResult1.DisplayText = "Velocity"
transcript1 = study1.CreateEntity( Type="Transcript", Association=physicsDefinition1)
transcript1.DisplayText = "Fluid Flow Output 1"
physicsSolutionGroup1 = Study.CreateGroup(Name="Physics Solution")
physicsSolutionGroup1.Add(Component=physicsDefinitionComponent1)
physicsSolutionGroup1.Add(Component=solvePhysicsComponent1)
meshingComponent1 = Study.CreateTask( Type="Meshing", System=system1, Output=physicsDefinitionComponent1)
physicsDefinitionComponent1.Refresh()
solvePhysicsComponent1.Refresh()
resultsEvaluationComponent1.Refresh()
importComponent1 = Study.CreateTask( Type="Import", System=system1, Output=meshingComponent1)
meshingComponent1.Refresh()
physicsDefinitionComponent1.Refresh()
solvePhysicsComponent1.Refresh()
resultsEvaluationComponent1.Refresh()
import1 = importComponent1.GetTaskObject()
geometryImportSource1 = import1.AddGeometryImportSourceOperation()
geometryImportSource1.FilePath = step.Properties["geometryfile"].Value
importComponent1.Update(AllDependencies=True)
meshingComponent1.Refresh()
physicsDefinitionComponent1.Refresh()
solvePhysicsComponent1.Refresh()
resultsEvaluationComponent1.Refresh()
def refineMesh(step):
global meshingComponent1, study1, results1, vectorResult1, physicsDefinitionComponent1,
singleValueResult1, resultsEvaluationComponent1, solvePhysicsComponent1, physicsRegion1
meshing1 = meshingComponent1.GetTaskObject()
meshing1.MeshResolution = step.Properties["MeshResolution"].Value
def setup(step):
global meshingComponent1, study1, results1, vectorResult1, physicsDefinitionComponent1, singleValueResult1,
resultsEvaluationComponent1, solvePhysicsComponent1, physicsRegion1
with Transaction():
meshing1 = meshingComponent1.GetTaskObject()
meshControlLocalInflation1 = study1.CreateEntity( Type="MeshControlLocalInflation", Association=meshing1)
meshing1.EngineeringIntent = "FluidFlow"
AddSourceToComponentInSystem( SourceComponent=physicsDefinitionComponent1,
TargetComponent=resultsEvaluationComponent1)
resultsEvaluationComponent1.Refresh()
#meshControlLocalInflation1.Location = ["FACE8", "FACE2", "FACE6"]
Study.Delete(Items=[meshControlLocalInflation1])
with Transaction():
meshingComponent1.Update(AllDependencies=True)
physicsDefinitionComponent1.Refresh()
solvePhysicsComponent1.Refresh()
resultsEvaluationComponent1.Refresh()
with Transaction():
inletBoundary1 = study1.CreateEntity( Type="InletBoundary", Association=physicsRegion1)
inlet_location = step.Properties["Inlet/InletLocation"].Value
ExtAPI.Log.WriteMessage("my inlet location property value is : " + inlet_location)
inlet_selection_set = None
selection_sets = getSelectionSetsForProject()
for selection_set in selection_sets:
if selection_set.DisplayText == inlet_location:
inlet_selection_set = selection_set
if inlet_selection_set == None :
ExtAPI.Log.WriteMessage("inlet selection set does not exist")
inletBoundary1.Location = [inlet_selection_set]
inletBoundary1.Flow.Velocity.Magnitude = step.Properties["Inlet/Velocity"].DisplayString
outletBoundary1 = study1.CreateEntity( Type="OutletBoundary", Association=physicsRegion1)
outlet_location = step.Properties["Outlet/OutletLocation"].Value
outlet_selection_set = None
selection_sets = getSelectionSetsForProject()
for selection_set in selection_sets:
if selection_set.DisplayText == outlet_location:
outlet_selection_set = selection_set
if outlet_selection_set == None :
ExtAPI.Log.WriteMessage("outlets selection set does not exist")
outletBoundary1.Location = [outlet_selection_set]
outletBoundary1.Flow.Pressure.GaugeStaticPressure = step.Properties["Outlet/GaugePressure"].DisplayString
wallBoundary1 = study1.CreateEntity( Type="WallBoundary", Association=physicsRegion1)
# Creation of the pressure loss expression.
singleValueResult1 = study1.CreateEntity( Type="SingleValueResult", Association=results1)
singleValueResult1.Method = "UserDefinedExpressionMethod"
singleValueResult1.Expression = "Average(Pressure, GetBoundary('@Inlet 1'), Weight='Area') -
Average(Pressure, GetBoundary('@Outlet 1'), Weight='Area')"
with Transaction():
physicsDefinitionComponent1.Update(AllDependencies=True)
solvePhysicsComponent1.Update(AllDependencies=True)
resultsEvaluationComponent1.Refresh()
resultsEvaluationComponent1.Refresh()
resultsEvaluationComponent1.Update(AllDependencies=True)
vectorResult1.Legend.Coloring = "Banded"
vectorResult1.Legend.NumberOfColors = "10"
vectorResult1.Distribution = "Mesh"
vectorResult1.Evaluate()
maximum_velocity = vectorResult1.Summary.Max
step.NextStep.Properties["MaximumVelocity"].Value = maximum_velocity.ToString()
step.NextStep.Properties["PressureLoss"].Value = singleValueResult1.Value.ToString()
def solve(step):
global meshingComponent1, study1, results1, vectorResult1, physicsDefinitionComponent1, singleValueResult1,
resultsEvaluationComponent1, solvePhysicsComponent1, physicsRegion1
with Transaction():
physicsDefinitionComponent1.Update(AllDependencies=True)
solvePhysicsComponent1.Update(AllDependencies=True)
resultsEvaluationComponent1.Refresh()
resultsEvaluationComponent1.Refresh()
resultsEvaluationComponent1.Update(AllDependencies=True)
vectorResult1.Legend.Coloring = "Banded"
vectorResult1.Legend.NumberOfColors = "10"
vectorResult1.Distribution = "Mesh"
vectorResult1.Evaluate()
maximum_velocity = vectorResult1.Summary.Max
step.NextStep.Properties["MaximumVelocity"].Value = maximum_velocity.ToString()
step.NextStep.Properties["PressureLoss"].Value = singleValueResult1.Value.ToString()When the wizard has completed, the final page shows the calculated Maximum Velocity. The Help panel indicates where the result is shown in the AIM study.
Clicking the button returns the user to the ACT Start Page.
The user can then open the Results task to view the final results obtained by the wizard-driven simulation.
On the Study panel, the user can see that the wizard created the workflow in AIM and then automatically executed the steps.