In this example, using the support files, you will perform a Static Structural analysis using Symmetric Symmetry and execute a sequence of python journal commands that will define and solve the analysis.
This example begins in the Mechanical application. It requires you to download the following files.
Symmetric_Symmetry.agdb
Symmetric_Symmetry.xml
Symmetric_Symmetry.py
These files are available here.
Procedure
Open Workbench and insert a Static Structural system into the Project Schematic.
Double-click the Engineering Data cell to open the workspace.
Select Symmetric_Symmetry.xml.
> , navigate to the proper folder location and selectReturn to the Project tab.
Right-click the Geometry cell and select .
Enable the Named Selections check box under the Basic Geometry Options category.
Right-click the Geometry cell and select > and then navigate to the proper folder location and select Symmetric_Symmetry.agdb.
Open Mechanical: right-click the Model cell and select .
Select the Automation tab and select the Scripting option to open the Mechanical Scripting pane.
Select the Open Script option (
) from the Editor toolbar. Navigate to the proper folder location and select Symmetric_Symmetry.py.
Select the Run Script option (
) from the Editor toolbar.
Scripts Illustrated
In this example, the python file automatically performs the following actions:
#Scenario 1: Store main Tree Object items MODEL = Model GEOM = MODEL.Geometry COORDINATE_SYSTEMS = Model.CoordinateSystems MESH = Model.Mesh PARTS = GEOM.GetChildren(DataModelObjectCategory.Part,False) for part in PARTS: bodies = part.GetChildren(DataModelObjectCategory.Body, False) for body in bodies: if body.Name == "Part 1": PART1 = body STAT_STRUC = DataModel.Project.Model.Analyses[0] ANALYSIS_SETTINGS = STAT_STRUC.AnalysisSettings STAT_STRUC_SOLUTION = STAT_STRUC.Solution #Scenario 2: Set Display Unit System ExtAPI.Application.ActiveUnitSystem = MechanicalUnitSystem.StandardMKS #Scenario 3: Insert Worksheet based Named Selections for applying Symmetric Symmetry and to setup Static Structural analysis # Create Named Selection for applying Symmetric Symmetry FIRSTNS = DataModel.Project.Model.AddNamedSelection() FIRSTNS.ScopingMethod=GeometryDefineByType.Worksheet FIRSTNS.Name = "SELECTION2" GEN_CRT1 = FIRSTNS.GenerationCriteria CRT1 = Ansys.ACT.Automation.Mechanical.NamedSelectionCriterion() CRT1.Active=True CRT1.Action=SelectionActionType.Add CRT1.EntityType=SelectionType.GeoFace CRT1.Criterion=SelectionCriterionType.LocationY CRT1.Operator=SelectionOperatorType.Equal CRT1.Value=Quantity('0 [m]') GEN_CRT1.Add(CRT1) FIRSTNS.Activate() FIRSTNS.Generate() # Create Named Selection for applying Fixed Support NAMED_SELCTIONS = DataModel.Project.Model.NamedSelections FIRSTNS.Duplicate() SECONDNS=NAMED_SELCTIONS.Children[1] SECONDNS.Name = "SELECTION3" GEN_CRT2 = SECONDNS.GenerationCriteria CRT1 = Ansys.ACT.Automation.Mechanical.NamedSelectionCriterion() CRT1.Active=True GEN_CRT2[0].Criterion=SelectionCriterionType.LocationX GEN_CRT2[0].Value=Quantity('-7.5 [m]') SECONDNS.Activate() SECONDNS.Generate() # Create Named Selection for applying Pressure SECONDNS.Duplicate() THIRDNS=NAMED_SELCTIONS.Children[2] THIRDNS.Name = "SELECTION4" GEN_CRT3 = THIRDNS.GenerationCriteria CRT1 = Ansys.ACT.Automation.Mechanical.NamedSelectionCriterion() CRT1.Active=True GEN_CRT3[0].Value=Quantity('7.5 [m]') THIRDNS.Activate() THIRDNS.Generate() #Scenario 4: Assign proper material to body") PART1.Activate() PART1.Assignment="T5" #Scenario 5: Insert Coordinate System for applying Symmetric Symmetry COORDINATE_SYSTEM = COORDINATE_SYSTEMS.AddCoordinateSystem() COORDINATE_SYSTEM.OriginZ = Quantity("0.1 [m]") COORDINATE_SYSTEM.AddTransformation(TransformationType.Offset,CoordinateSystemAxisType.PositiveZAxis) COORDINATE_SYSTEM.SetTransformationValue(1,0.4) COORDINATE_SYSTEM.AddTransformation(TransformationType.Rotation,CoordinateSystemAxisType.PositiveXAxis) COORDINATE_SYSTEM.SetTransformationValue(2,90) #Scenario 6: Insert Symmetric Symmetry using local Coordinate System SYMMETRY=MODEL.AddSymmetry() # Insert Symmetric Symmetry using Pre-selection SELECTION=ExtAPI.SelectionManager.AddSelection(FIRSTNS) SELECTION2=ExtAPI.SelectionManager.CurrentSelection SYMMETRY_REGION=SYMMETRY.AddSymmetryRegion() SYMMETRY_REGION.Type=SymmetryRegionType.Symmetric SYMMETRY_REGION.CoordinateSystem=COORDINATE_SYSTEM SYMMETRY_REGION.SymmetryNormal=SymmetryNormalType.ZAxis # Clear Selection for inserting new objects with default scoping CLRSEL = ExtAPI.SelectionManager.ClearSelection() #Scenario 7: Define global mesh size and generate mesh MESH.Activate() MESH.ElementSize = Quantity('0.5 [m]') MESH.GenerateMesh() #Scenario 8: Define load and boundary conditions in Static Structural analysis # Add Fixed Support FIX_SUPPORT = STAT_STRUC.AddFixedSupport() FIX_SUPPORT.Location = SECONDNS # Add Pressure PRESSURE = STAT_STRUC.AddPressure() PRESSURE.Location = THIRDNS PRESSURE.AppliedBy=LoadAppliedBy.SurfaceEffect PRESSURE.Magnitude.Output.SetDiscreteValue(0,Quantity("-100 [Pa]")) #Scenario 9: Add results in Static Structural analysis STAT_STRUC_SOLUTION.Activate() TOTAL_DEFORMATION = STAT_STRUC_SOLUTION.AddTotalDeformation() NORMAL_STRESS = STAT_STRUC_SOLUTION.AddNormalStress() #Scenario 10: Solve and review Results STAT_STRUC_SOLUTION.Activate() STAT_STRUC.Solve(True) #Total Deformation Result TOTAL_DEF_MIN = TOTAL_DEFORMATION.Minimum.Value TOTAL_DEF_MAX = TOTAL_DEFORMATION.Maximum.Value #Normal Stress Result NORMAL_STRESS_MIN = NORMAL_STRESS.Minimum.Value NORMAL_STRESS_MAX = NORMAL_STRESS.Maximum.Value
Summary
This example demonstrates how scripting in Mechanical can be used to automate your actions.