Fluent Wizard (CAS Input File)

The extension FluentDemo2 contains a target product wizard for Fluent named Simple Analysis (Fluent Demo 2). This Fluent wizard imports a CAS file, runs a simple analysis, generates results, and displays the results in a customized panel in the user interface. This example can be used in either of the following scenarios:


Note:  The extension FluentDemo2 and sample input file are included in the package ACT Wizards Templates. You can download this package from the ACT Resources page on the ANSYS Customer Portal. For more information, see Extension Examples.


XML Extension Definition File

Definitions follow for codes blocks in the XML extension definition file FluentDemo2.xml.

Extension Definition

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.

Guid Definition

The <guid> block specifies a unique identifier for the extension.

Script Definition

The <script> block specifies the IronPython script that is referenced by the extension. This extension references main.py.

Wizard Interface Definition

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.

Custom Layout Definition

The <uidefinition> block defines a custom layout called ResultsView for the Fluent wizard. It is made up of five custom components: Title, Properties, Report, Chart, and Submit. The Properties, Report, and Chart components are views, and the Submit component is a button.

Wizard Definition

The wizard Simple Analysis (Fluent Demo 2) and its steps are defined in the <wizard> block named Simple Analysis (Fluent Demo 2).

  • 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 be used as the icon for the wizard: wizard_icon. The file wizard_icon.png is stored in the images folder defined in the <images> block of the interface definition.

  • 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.

Step Definition

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@FluentDemo2. 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 For more information, see Reviewing the Analysis.

The XML extension definition file FluentDemo2.xml follows.

<extension name="FluentDemo2" version="1">
    <guid>49B358FB-EAFB-4678-BBBD-82E949B46F70</guid>
	<author>ANSYS Inc.</author>
	<description>This extension demonstrates how to create a wizard in Fluent (.cas 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 2)" 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>ImportModel</onrefresh>
				<onupdate>CreateAnalysis</onupdate>
			</callbacks>
		
			<property name="velocity" caption="Velocity" control="float" default="3" />
		</step>
		
		<step name="Results" caption="Results" version="1" layout="ResultsView@FluentDemo2">
			<callbacks>
				<onrefresh>CreateReport</onrefresh>
			</callbacks>
			
			<property name="pressure" caption="Pressure Drop" control="text" readonly="true" />
		</step>
	
	</wizard>
	
</extension>
IronPython Script

The IronPython script main.py follows. This script defines all functions executed by the callbacks in the XML extension definition file:

  • The function ImportModel 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 ImportModel(step):
    tui = ExtAPI.Application.ScriptByName("TUI")
    
    tui.SendCommand("""/file/read-case "{0}" """.format(System.IO.Path.Combine(
ExtAPI.Extension.InstallDir,"final.cas")))
    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"]))
Reviewing the Analysis

This section reviews the wizard interface and the processes performed in each step of the wizard Simple Analysis (Fluent Demo 2).

Reviewing the Analysis Step

The first step is Analysis, which imports the CAS file and creates the analysis. It requires the user to specify a value for the property Velocity.

In this step:

  • The function ImportModel is invoked by the callback <onrefresh>. It imports the file final.cas and displays the model in the Mesh view.

  • The function CreateAnalysis is invoked by the callback <onupdate> when the user clicks the step’s Next 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 2 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.

Reviewing the Results Step

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 attribute <layout> specifies the custom layout to apply to the results. Custom layouts are defined in 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.


Release 18.2 - © ANSYS, Inc. All rights reserved.