AIM Custom Template (Multiple-Step)

The extension PressureLossMultiple contains a product target wizard for AIM. This multi-step wizard has the same name as the extension. In AIM, wizards for simulations are called custom templates.

XML Extension Definition File

Definitions follow for codes blocks in the XML extension definition file PressureLossMultiple.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.

  • The attribute description specifies the text to display in the extension details accessed via the right-click About option in the Extension Manager when it is accessed from the ACT Start Page.

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 pressureLoss.py.

Wizard Interface Definition

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 use as an icon.

Wizard Definition

The custom template PressureLossMultiple and its steps are defined in the <wizard> block named PressureLossMultiple.

  • The attributes name and version specify the custom template name and version.

  • The attribute context specifies the ANSYS product in which the wizard is executed. Because the wizard runs from AIM, context is set to Study. In AIM, a study is the workspace in which you create and define one or more simulation processes.

  • The attribute icon specifies the filename for the image to display for the custom template on the start page or when adding a new simulation from the Study panel. This image must be stored in the images folder for the extension.

  • The attribute icon specifies the filename for the image to display for the custom template. 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 extension details accessed via the right-click About option in the Extension Manager when it is accessed from the ACT Start Page.

Step Definition

The <step> blocks define the steps of the custom template. This custom template has four steps: Step1, Step2, Step3, and Step4.

For each step:

  • The attributes name and version specify the step name and version 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 caption specifies the label to display for the step in AIM's data panel.

  • The attribute description specifies the text to display for the step in the user interface for the custom template.

  • The <property> blocks specify properties and property attributes for the step.

  • The <callbacks> block defines callbacks to functions defined in the IronPython script. For a custom template, only the callbacks <onupdate>, <onrefresh>, and <onreset> are supported.

    During the execution of the callback <onupdate> for a step, AIM displays a progress message, indicating that the step is being executed.

  • The <properties> block defines a property used in a step. A property definition can include a callback, as in Step3 of this example. A property definition can also include a child <help> block with the text message to display as the custom help for the property.

For more information about each step, see Breakdown of Steps.

Breakdown of Steps
Step1

Imports the geometry and creates the workflow in AIM.

  • The property geometryfile enables you to specify a geometry. You can either keep the geometry specified by the attribute default or browse to select a different one (control="fileopen"). For this example, a geometry file named TubeSelectionSet.agdb is selected.

  • The callback <onupdate> is invoked when the Next button is clicked. It executes the function importGeometry, which imports the selected geometry and then creates the workflow in AIM. Specifically, it creates the workflow from journal content included in the function.

  • The attribute HelpFile is set to Step1.html.

Step2

Refines the mesh for the geometry from low to high.

  • The property MeshResolution enables you to set the resolution for the mesh. This property has a default of 1 (default="1") and accepts only integer values (control= "integer").

  • The callback <onupdate> is invoked when the Next button is clicked. It executes the function refineMesh, which creates a mesh according to the specification.

  • The attribute HelpFile is set to step2.html.

Step3

Defines the loads applied on the geometry.

  • The properties Velocity and GaugePressure enable users to enter values (control=”float”).

  • The properties InletLocation and OutletLocation require users to define the inlet and outlet locations to which to apply the load (control=”scoping”).

  • When a value is entered for the outlet location, the callback <isvalid> is invoked. It executes the function isValid, which verifies that the inlet and outlet locations are not the same.

  • The callback <onupdate> invokes the function setup when the Next button is clicked. This function applies the loads to the selected locations and performs the calculations.

  • The attribute HelpFile is set to step3.html.

Step4

Exposes the maximum velocity and pressure loss results.

  • The properties MaximumVelocity and PressureLoss show the calculated values in read-only format (readonly="true").

  • The attribute HelpFile is set to step3.html.

  • When the Finish button is clicked, the custom template closes, returning the user to the analysis.

The file PressureLossMultiple.xml follows.

:<extension version="1" name="PressureLossMultiple" icon="images\loss.png">
  <guid shortid="AimMultiStepWizard">C3F86496-2F13-49E3-B7D0-353542207EAE</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="PressureLossMultiple" version="1" context="Study" 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="Study" HelpFile="help/Step1.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" HelpFile="help/Step2.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" HelpFile="help/Step3.html">
      <description>Specify the loads to applied on the geometry.</description>

      <callbacks>
        <onupdate>setup</onupdate>
      </callbacks>


         <property name="Velocity" caption="Velocity" control="float" unit="Velocity" default="0.1 [m s^-1]"/>
         <property name="InletLocation" caption="InletLocation" control="scoping" />

         <property name="GaugePressure" caption="Gauge Pressure" control="float" unit="Pressure" default="0 
[Pa]"/>
         <property name="OutletLocation" caption="OutletLocation" control="scoping" >
           <callbacks>
             <isvalid >isValid</isvalid>
           </callbacks>
         </property>
    </step>

     <step name="Step4" caption="Export the maximum velocity" version="1" HelpFile="help/Step4.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>

IronPython Script

The IronPython script pressureLoss.py follows. This script defines all functions executed by the callbacks in the XML extension definition file for the custom template.

meshingComponent1 = None
study1 = None
import1 = 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 isValid(step, property):
    if property.Value == step.Properties["InletLocation"].Value:
        ExtAPI.Log.WriteWarning("Inlet and Outlet locations must be different.")
        return False
    return True

def importGeometry(step):
    global  meshingComponent1, import1, 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()

    Study.ChangeModelSelectionContextTo(import1)

def refineMesh(step):
    global meshingComponent1, import1, study1, results1, vectorResult1, physicsDefinitionComponent1, 
singleValueResult1, 
resultsEvaluationComponent1, solvePhysicsComponent1, physicsRegion1
    meshing1 = meshingComponent1.GetTaskObject()
    meshing1.MeshResolution = step.Properties["MeshResolution"].Value

    Study.ChangeModelSelectionContextTo(import1)

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()

    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["InletLocation"].Value.LocationSet

        if inlet_location == None :
            ExtAPI.Log.WriteMessage("inlet selection set does not exist")

        inletBoundary1.Location = inlet_location
        inletBoundary1.Flow.Velocity.Magnitude = step.Properties["Velocity"].DisplayString

        outletBoundary1 = study1.CreateEntity( Type="OutletBoundary", Association=physicsRegion1)
        outlet_location = step.Properties["OutletLocation"].Value.LocationSet

        if outlet_location == None :
            ExtAPI.Log.WriteMessage("outlets selection set does not exist")

        outletBoundary1.Location = outlet_location
        outletBoundary1.Flow.Pressure.GaugeStaticPressure = step.Properties["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()

Defining Custom Help for the Multiple-Step Custom Template

For the custom template PressureLossMultiple, help files are defined for each of its four steps: Step1.html, Step2.html, Step3.html, and Step4.html. For an AIM wizard, filenames for custom help files do not have to be the same as the names for the steps. However, in this example, they are the same. The HTML files and the image files that they reference are placed in a folder within the extension. In this example, the folder is named help.

In the XML file, each <step> block references the custom help file for this step. For example, the Step1 definition begins as follows:

<step name="Step1" caption="Import the geometry" version="1" context="Study" HelpFile="help/Step1.html">

If you wanted to define custom help for a property, you would do so directly in the <properties> block in the XML file.


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