The extension FluentDemo1 contains a target product wizard
for Fluent named Simple Analysis (Fluent Demo 1). This Fluent
wizard imports an MSH file, runs a simple analysis, generates results, and displays
the results in a custom panel in the user interface. This example can be used in
either of the following scenarios:
Within a Workbench project that contains a Fluent (with Fluent Meshing) system
In a Fluent standalone project with Meshing Mode selected
Note: The extension FluentDemo1 and sample input file are
included in the package ACT Wizards Templates, which you
can download from the ACT Resources page on the ANSYS Customer
Portal. For more information, see Extension Examples.
Definitions follow for codes blocks in the XML extension definition file FluentDemo1.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 main.py.
The <interface> block defines the
user interface for the wizard.
The attribute context is set to
Fluent because the extension
runs from ANSYS Fluent.
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 use as an icon.
The <uidefinition> block defines a
custom layout named ResultsView for the
Fluent wizard. It is made up of five custom components:
Title, Properties,
Report, Chart, and
. The
Properties, Report,
and Chart components are views, and the
component is a button.
The wizard Simple Analysis (Fluent Demo 1)
and its steps are defined in the
<wizard> block named
Simple Analysis (Fluent Demo 1).
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 the wizard runs from Fluent, whether a
stand-alone instance or an instance within Workbench,
context is set to
Fluent.
The attribute icon specifies
the filename of the image to display as the icon for the
wizard: wizard_icon. The file
wizard_icon.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 define the steps of
the wizard. This wizard has two steps:
Analysis and
Results. For each step:
The attributes name,
version, and
caption define the step name,
version, and display text for the step.
The attribute context specifies
the ANSYS product 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.
The attribute layout specifies
the custom layout to apply to the step. For the step
Results,
layout is set to
ResultsView@FluentDemo1. The
custom layout ResultsView is
defined in the
<uidefinition>
block.
Any <property> blocks
specify properties and property attributes to be used in
the step. For the step Analysis,
the property velocity is defined.
The attribute caption is set to
velocity. For the step
Results, the property
pressure is defined. The
attribute caption is set to
Pressure.
The <callbacks> blocks
specify callbacks to functions defined in the script
main.py. These are discussed in
more detail in Reviewing the Analysis.
The XML extension definition file FluentDemo1.xml follows.
<extension name="FluentDemo1" version="1"> <guid>A0A3E28C-E094-4B2D-8A91-A0B0884D1AE2</guid> <author>ANSYS Inc.</author> <description>This extension demonstrates how to create a wizard in Fluent (.msh file import).</description> <script src="main.py" /> <interface context="Fluent"> <images>images</images> </interface> <uidefinition> <layout name="ResultsView"> <component name="Title" topAttachment="" topOffset="10" leftAttachment="" leftOffset="10" rightAttachment="" rightOffset="10" bottomOffset="10" bottomAttachment="Properties" widthType="Percentage" width="100" heightType="FitToContent" height="200" componentType="startPageHeaderComponent" /> <component name="Properties" topAttachment="Title" leftAttachment="" leftOffset="10" rightAttachment="" rightOffset="10" bottomAttachment="Report" bottomOffset="10" widthType="Percentage" width="100" heightType="Percentage" height="20" componentType="propertiesComponent" /> <component name="Report" topAttachment="Properties" leftAttachment="" leftOffset="10" rightAttachment="" rightOffset="10" bottomAttachment="Chart" bottomOffset="10" widthType="Percentage" width="100" heightType="Percentage" height="40" componentType="helpContentComponent" /> <component name="Chart" topAttachment="Report" leftAttachment="" leftOffset="10" rightAttachment="" rightOffset="10" bottomAttachment="Submit" bottomOffset="10" widthType="Percentage" width="100" heightType="Percentage" height="40" componentType="chartComponent" /> <component name="Submit" topAttachment="Chart" leftAttachment="" leftOffset="10" rightAttachment="" rightOffset="10" bottomAttachment="" bottomOffset="10" widthType="Percentage" width="100" heightType="FitToContent" height="50" componentType="buttonsComponent" /> </layout> </uidefinition> <wizard name="Simple Analysis (Fluent Demo 1)" version="1" context="Fluent" icon="wizard_icon"> <description>Generate the mesh and solve the analysis.</description> <step name="Analysis" caption="Analysis" version="1"> <callbacks> <onrefresh>ImportMesh</onrefresh> <onupdate>CreateAnalysis</onupdate> </callbacks> <property name="velocity" caption="Velocity" control="float" default="3" /> </step> <step name="Results" caption="Results" version="1" layout="ResultsView@FluentDemo1"> <callbacks> <onrefresh>CreateReport</onrefresh> </callbacks> <property name="pressure" caption="Pressure Drop" control="text" readonly="true" /> </step> </wizard> </extension>
The IronPython script main.py follows. This script defines all functions executed by the callbacks in the XML extension definition file:
The function ImportMesh is invoked by the
callback <onrefresh> in the step
Analysis.
The function CreateAnalysis is invoked by the
callback <onupdate> in the step
Analysis.
The function CreateReport is invoked by the
callback <onrefresh> in the step
Results.
def ImportMesh(step):
tui = ExtAPI.Application.ScriptByName("TUI")
tui.SendCommand("""switch-to-meshing-mode""")
tui.SendCommand("""/file/read-mesh "{0}" """.format(System.IO.Path.Combine(
ExtAPI.Extension.InstallDir,"final.msh")))
tui.SendCommand("""switch-to-solution-mode yes yes""")
tui.SendCommand("""/display/mesh ok""")
tui.SendCommand("""/display/views/restore-view right""")
def CreateAnalysis(step):
tui = ExtAPI.Application.ScriptByName("TUI")
res = System.IO.Path.GetTempFileName()
img = System.IO.Path.GetTempFileName()+".jpg"
curve = System.IO.Path.GetTempFileName()
tui.SendCommand("""/define/boundary-conditions/velocity-inlet inlet no no yes yes no {0} no
0""".format(step.Properties["velocity"].Value), True)
tui.SendCommand("""/solve/initialize/hyb-initialization""", True)
tui.SendCommand("""/solve/iterate 50""", True)
tui.SendCommand("""/display/mesh ok""", True)
tui.SendCommand("""/display/views/restore-view right""", True)
tui.SendCommand("""/display/set/contours/filled-contours? yes""", True)
tui.SendCommand("""/display/set/contours/surfaces wall inlet outlet ()""", True)
tui.SendCommand("""/display/contour pressure 0 2""", True)
tui.SendCommand("""/display/save-picture "{0}" """.format(img), True)
tui.SendCommand("""/surface/rake-surface rake-5 0 0 0 0 0 1 50""", True)
tui.SendCommand("""/plot/plot-direction 0 0 1""", True)
tui.SendCommand("""/plot/plot yes "{0}" yes yes no no pressure yes 0 0 1 rake-5 ()""".format(curve),
True)
tui.SendCommand("""/report/surface-integrals/area-weighted-avg inlet () pressure yes "{0}"
""".format(res), True)
val = 0.
n = 0;
with System.IO.StreamReader(res) as reader:
while n!=5:
line = reader.ReadLine()
if line!=None:
n+=1
str = line.Substring(32)
val = System.Double.Parse(str, System.Globalization.CultureInfo.InvariantCulture)
x=[]
y=[]
n = 0;
with System.IO.StreamReader(curve) as reader:
while n!=5:
line = reader.ReadLine()
if line!=None:
n+=1
while not line.StartsWith(")"):
tab = line.Split("\t")
x.Add(System.Double.Parse(tab[0], System.Globalization.CultureInfo.InvariantCulture))
y.Add(System.Double.Parse(tab[1], System.Globalization.CultureInfo.InvariantCulture))
line = reader.ReadLine()
System.IO.File.Delete(res)
System.IO.File.Delete(curve)
step.NextStep.Properties["pressure"].Value = val
step.NextStep.Attributes["img"] = img
step.NextStep.Attributes["x"] = x
step.NextStep.Attributes["y"] = y
def CreateReport(step):
graph = step.UserInterface.GetComponent("Chart")
graph.Title("Static Pressure")
graph.ShowLegend(False)
graph.Plot(step.Attributes["x"], step.Attributes["y"], key="Static Pressure", color='g')
help = step.UserInterface.GetComponent("Report")
help.SetHtmlContent(ExtAPI.Extension.InstallDir,"""<center><img style="height:250px"
src="{0}"></center>""".format(step.Attributes["img"]))This section reviews the user interface and the processes performed in
each step of the wizard Simple Analysis (Fluent Demo
1).
The first step is Analysis, which imports the mesh
file and creates the analysis. It requires the user to specify a value for
the property Velocity.
In th this step:
The function ImportMesh is invoked by the
callback <onrefresh>. It imports the
file final.msh and displays the mesh in the
Mesh view.
The function CreateAnalysis is invoked by
the callback <onupdate> when the user
clicks the button. This function sets up
the analysis.
The property Velocity defined in
the <property> block is shown
in the GUI as a float field with a default value of
3. The user can enter
the desired value. In this example, a value of 5 is entered.
The additional actions to be performed as part of the analysis are defined.
Intermediate results are shown dynamically in the Scaled Residuals window as the analysis is performed.


The second step is Results, which creates a report of the results.
In this step:
The function CreateReport is invoked by the
callback <onrefresh>.
The <layout> block specifies the
custom layout to apply to the results. This is a child block within
the <uidefinition> block.
The wizard takes the results obtained and displays them:
The calculated value for the property
PressureDrop defined in the
<property> block is
displayed in the GUI as a ready-only field.
The static pressure results are shown in the Graph and Contours views.
