In this example, using the support files, you will perform a Static Structural analysis using Linear Periodic 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 Ansys DesignModeler and python files.
Linear_Periodic_Symmetry.agdb
Linear_Periodic_Symmetry.py
These files are available here.
Procedure
Open Workbench and insert a Static Structural system into the Project Schematic.
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 Linear_Periodic_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 Linear_Periodic_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 NAMED_SELECTIONS = Model.NamedSelections PARTS = GEOM.GetChildren(DataModelObjectCategory.Part,False) for part in PARTS: bodies = part.GetChildren(DataModelObjectCategory.Body, False) for body in bodies: if body.Name == "Solid": SOLID = 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.StandardCGS #Scenario 3: Store Named Selections for applying Symmetry and to setup Static Structural analysis tot_child_NS_GRP = NAMED_SELECTIONS.Children.Count for i in range(0, tot_child_NS_GRP, 1): ns = NAMED_SELECTIONS.Children[i].Name if(ns=='Left_Face'): LOW_FACE = NAMED_SELECTIONS.Children[i] if(ns=='Right_Face'): HIGH_FACE = NAMED_SELECTIONS.Children[i] if(ns=='Base_Face'): LOAD = NAMED_SELECTIONS.Children[i] if(ns=='Top_Face'): FIXED = NAMED_SELECTIONS.Children[i] if(ns=='Front_Face'): FRONT_FACE = NAMED_SELECTIONS.Children[i] if(ns=='Back_Face'): BACK_FACE = NAMED_SELECTIONS.Children[i] if(ns=='Curved_Edges'): CURVED_EDGES = NAMED_SELECTIONS.Children[i] if(ns=='Straight_Edges'): STRAIGHT_EDGES = NAMED_SELECTIONS.Children[i] if(ns=='Short_Edges'): SHORT_EDGES = NAMED_SELECTIONS.Children[i] if(ns=='Mapping_Faces'): MAPPING_FACES = NAMED_SELECTIONS.Children[i] if(ns=='Vertex1'): VERETX1 = NAMED_SELECTIONS.Children[i] if(ns=='Vertex2'): VERETX2 = NAMED_SELECTIONS.Children[i] if(ns=='Vertex3'): VERETX3 = NAMED_SELECTIONS.Children[i] if(ns=='Vertex4'): VERETX4 = NAMED_SELECTIONS.Children[i] if(ns=='Vertex5'): VERETX5 = NAMED_SELECTIONS.Children[i] if(ns=='Vertex6'): VERETX6 = NAMED_SELECTIONS.Children[i] if(ns=='Vertex7'): VERETX7 = NAMED_SELECTIONS.Children[i] if(ns=='Vertex8'): VERETX8 = NAMED_SELECTIONS.Children[i] #Scenario 4: Insert Coordinate System for applying Linear Periodic Symmetry COORDINATE_SYSTEM = COORDINATE_SYSTEMS.AddCoordinateSystem() COORDINATE_SYSTEM.OriginX = Quantity("8 [cm]") COORDINATE_SYSTEM.OriginY = Quantity("4 [cm]") COORDINATE_SYSTEM.OriginZ = Quantity("0 [cm]") COORDINATE_SYSTEM.AddTransformation(TransformationType.Rotation,CoordinateSystemAxisType.PositiveYAxis) COORDINATE_SYSTEM.SetTransformationValue(1,90) #Scenario 5: Insert Linear Periodic Symmetry using local Coordinate System SYMMETRY=MODEL.AddSymmetry() # Insert Linear Periodic Symmetry SYMMETRY_REGION=SYMMETRY.AddLinearPeriodicRegion() SYMMETRY_REGION.Behavior=SymmetryBehavior.Free SYMMETRY_REGION.CoordinateSystem=COORDINATE_SYSTEM SYMMETRY_REGION.LinearShift=Quantity("8 [cm]") SYMMETRY_REGION.PeriodicityDirection=PeriodicityDirectionType.ZAxis # Select Low and High Boundary with proper Coordinate System SYMMETRY_REGION.LowBoundaryLocation=HIGH_FACE SYMMETRY_REGION.HighBoundaryLocation=LOW_FACE SYMMETRY_REGION.FlipHighLow() #Scenario 6: Define mesh controls and generate mesh MESH.Activate() MESH.ElementOrder=ElementOrder.Quadratic # Error Limits Standard Mechanical MESH.ShapeChecking=False MESH_SIZE01 = MESH.AddSizing() MESH_SIZE01.Location = CURVED_EDGES MESH_SIZE01.Type = SizingType.NumberOfDivisions MESH_SIZE01.NumberOfDivisions = 10 MESH_SIZE01.Behavior=SizingBehavior.Hard MESH_SIZE02 = MESH_SIZE01.Duplicate() MESH_SIZE02.Location = STRAIGHT_EDGES MESH_SIZE02.NumberOfDivisions = 10 MESH_SIZE03 = MESH_SIZE02.Duplicate() MESH_SIZE03.Location = SHORT_EDGES MESH_SIZE03.NumberOfDivisions = 3 FACE_MESHING = MESH.AddFaceMeshing() FACE_MESHING.Location = MAPPING_FACES MESH.GenerateMesh() #Scenario 7: Define load and boundary conditions in Static Structural analysis # Add Fixed Support FIXED_SUPPORT = STAT_STRUC.AddFixedSupport() FIXED_SUPPORT.Location = FIXED # Add Pressure PRESSURE = STAT_STRUC.AddPressure() PRESSURE.Location = LOAD PRESSURE.AppliedBy=LoadAppliedBy.SurfaceEffect PRESSURE.DefineBy=LoadDefineBy.Components PRESSURE.XComponent.Output.DiscreteValues = [Quantity("1e9 [dyne cm^-1 cm^-1]")] #Scenario 8: Add results in Static Structural analysis STAT_STRUC_SOLUTION.Activate() # Insert Deformation results TOTAL_DEFORMATION1 = STAT_STRUC_SOLUTION.AddTotalDeformation() TOTAL_DEFORMATION2 = STAT_STRUC_SOLUTION.AddTotalDeformation() TOTAL_DEFORMATION2.Location=VERETX3 TOTAL_DEFORMATION3 = STAT_STRUC_SOLUTION.AddTotalDeformation() TOTAL_DEFORMATION3.Location=VERETX7 TOTAL_DEFORMATION4 = STAT_STRUC_SOLUTION.AddTotalDeformation() TOTAL_DEFORMATION4.Location=VERETX4 TOTAL_DEFORMATION5 = STAT_STRUC_SOLUTION.AddTotalDeformation() TOTAL_DEFORMATION5.Location=VERETX8 DIRECTIONAL_DEFORMATION = STAT_STRUC_SOLUTION.AddDirectionalDeformation() # Insert Equivalent Stress result EQUIVALENT_STRESS = STAT_STRUC_SOLUTION.AddEquivalentStress() #Insert Force Reaction Probe scoped to Fixed Support FORCE_REACTION_PROBE = STAT_STRUC.Solution.AddForceReaction() FORCE_REACTION_PROBE.LocationMethod =LocationDefinitionMethod.BoundaryCondition FORCE_REACTION_PROBE.BoundaryConditionSelection = FIXED_SUPPORT #Scenario 9: Solve and review Results STAT_STRUC_SOLUTION.Activate() STAT_STRUC.Solve(True) #Deformation Result TOTAL_DEF1_MIN = TOTAL_DEFORMATION1.Minimum.Value TOTAL_DEF1_MAX = TOTAL_DEFORMATION1.Maximum.Value TOTAL_DEF2_MIN = TOTAL_DEFORMATION2.Minimum.Value TOTAL_DEF2_MAX = TOTAL_DEFORMATION2.Maximum.Value TOTAL_DEF3_MIN = TOTAL_DEFORMATION3.Minimum.Value TOTAL_DEF3_MAX = TOTAL_DEFORMATION3.Maximum.Value TOTAL_DEF4_MIN = TOTAL_DEFORMATION4.Minimum.Value TOTAL_DEF4_MAX = TOTAL_DEFORMATION4.Maximum.Value TOTAL_DEF5_MIN = TOTAL_DEFORMATION5.Minimum.Value TOTAL_DEF5_MAX = TOTAL_DEFORMATION5.Maximum.Value #Equivalent Stress Result EQV_STRESS_MIN = EQUIVALENT_STRESS.Minimum.Value EQV_STRESS_MAX = EQUIVALENT_STRESS.Maximum.Value FRC_REAC_PROBE_MAX_Y=FORCE_REACTION_PROBE.MaximumXAxis.Value FRC_REAC_PROBE_TOTAL=FORCE_REACTION_PROBE.MaximumTotal.Value
Summary
This example demonstrates how scripting in Mechanical can be used to automate your actions.