In this example, using the support files, you will perform a Thermal Stress analysis using Cyclic Symmetry or Pre-Meshed Cyclic Region 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.
Cyclic_Symmetry.agdb
Cyclic_Symmetry.py
These files are available here.
Procedure
Open Workbench and insert a Transient Thermal system into the Project Schematic.
Drag and drop an Static Structural system onto the Solution cell of the thermal analysis so that the systems are linked as shown.
Right-click the Geometry cell of the thermal system and select .
Enable the Named Selections check box under the Basic Geometry Options category.
Right-click the Geometry cell of the thermal system and select > and then navigate to the proper folder location and select Cyclic_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 Cyclic_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 = body if body.Name == "SurfaceBody": SHELL_BODY = body TRANS_THERM = DataModel.Project.Model.Analyses[0] ANALYSIS_SETTINGS1 = TRANS_THERM.AnalysisSettings TRANS_THERM_SOLUTION = TRANS_THERM.Solution STAT_STRUC = DataModel.Project.Model.Analyses[1] ANALYSIS_SETTINGS2 = STAT_STRUC.AnalysisSettings STAT_STRUC_SOLUTION = STAT_STRUC.Solution #Scenario 2: Set Display Unit System ExtAPI.Application.ActiveUnitSystem = MechanicalUnitSystem.StandardNMM #Scenario 3: Set isometric view and zoom to fit cam = Graphics.Camera cam.SetSpecificViewOrientation(ViewOrientationType.Iso) cam.SetFit() #Scenario 4: Store Named Selections for applying Symmetry and to setup Thermal Stress 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=='Low_Face'): LOW_FACE = NAMED_SELECTIONS.Children[i] if(ns=='High_Face'): HIGH_FACE = NAMED_SELECTIONS.Children[i] if(ns=='Pressure_Face'): LOAD_FACE = NAMED_SELECTIONS.Children[i] if(ns=='Fixed_Face'): FIXED_FACE = 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=='Edges1'): EDGES1 = NAMED_SELECTIONS.Children[i] if(ns=='Edges2'): EDGES2 = NAMED_SELECTIONS.Children[i] if(ns=='Edges3'): EDGES3 = NAMED_SELECTIONS.Children[i] if(ns=='Low_Edge'): LOW_EDGE = NAMED_SELECTIONS.Children[i] if(ns=='High_Edge'): HIGH_EDGE = NAMED_SELECTIONS.Children[i] if(ns=='Shell_Face'): SHELL_FACE = NAMED_SELECTIONS.Children[i] if(ns=='Solid_Body'): SOLID_BODY = NAMED_SELECTIONS.Children[i] if(ns=='Shell_Body'): SHELL_BODY = NAMED_SELECTIONS.Children[i] #Scenario 5: Insert Coordinate System for applying Cyclic Symmetry COORDINATE_SYSTEM = COORDINATE_SYSTEMS.AddCoordinateSystem() COORDINATE_SYSTEM.OriginX = Quantity("0 [mm]") COORDINATE_SYSTEM.OriginY = Quantity("0 [mm]") COORDINATE_SYSTEM.OriginZ = Quantity("0 [mm]") COORDINATE_SYSTEM.PrimaryAxis=CoordinateSystemAxisType.PositiveZAxis COORDINATE_SYSTEM.CoordinateSystemType=CoordinateSystemTypeEnum.Cylindrical #Scenario 6: Insert Cyclic Symmetry using local Coordinate System SYMMETRY=MODEL.AddSymmetry() # Insert Cyclic Symmetry scoped to Solid faces SYMMETRY_REGION1=SYMMETRY.AddCyclicRegion() SYMMETRY_REGION1.CoordinateSystem=COORDINATE_SYSTEM # Select Low and High Boundary with proper Coordinate System SYMMETRY_REGION1.LowBoundaryLocation=LOW_FACE SYMMETRY_REGION1.HighBoundaryLocation=HIGH_FACE #Scenario 7: Define mesh controls and generate mesh MESH.Activate() # Error Limits Standard Mechanical MESH.ShapeChecking=False FACE_MESHING = MESH.AddFaceMeshing() FACE_MESHING.Location = SHELL_FACE FACE_MESHING.Suppressed=True MESH_SIZE01 = MESH.AddSizing() MESH_SIZE01.Location = EDGES1 MESH_SIZE01.Type = SizingType.NumberOfDivisions MESH_SIZE01.NumberOfDivisions = 9 MESH_SIZE01.Behavior=SizingBehavior.Hard MESH_SIZE01.Suppressed=True MATCH_CONTROL01=MESH.AddMatchControl() MATCH_CONTROL01.LowGeometrySelection=LOW_FACE MATCH_CONTROL01.HighGeometrySelection=HIGH_FACE MATCH_CONTROL01.HighCoordinateSystem=COORDINATE_SYSTEM MATCH_CONTROL01.Suppressed=True MATCH_CONTROL02=MESH.AddMatchControl() MATCH_CONTROL02.LowGeometrySelection=LOW_EDGE MATCH_CONTROL02.HighGeometrySelection=HIGH_EDGE MATCH_CONTROL02.HighCoordinateSystem=COORDINATE_SYSTEM MATCH_CONTROL02.Suppressed=True MESH.GenerateMesh() #Scenario 8: Setup Transient Thermal analysis ANALYSIS_SETTINGS1.SetStepEndTime(1, Quantity("10 [sec]")) TEMPERATURE01 = TRANS_THERM.AddTemperature() TEMPERATURE01.Location = FIXED_FACE TEMPERATURE01.Magnitude.Output.DiscreteValues=[Quantity('5[C]')] TEMPERATURE02 = TRANS_THERM.AddTemperature() TEMPERATURE02.Location = SHELL_FACE TEMPERATURE02.Magnitude.Output.DiscreteValues=[Quantity('30[C]')] #Scenario 9: Define load and boundary conditions in Thermal Stress analysis STAT_STRUC.Activate() TOT_CHILD_STAT_STRUC = STAT_STRUC.Children.Count for i in range(0, TOT_CHILD_STAT_STRUC, 1): ns = STAT_STRUC.Children[i].Name if(ns=='Imported Load (A6) '): IMPORTED_LOAD_GRP = STAT_STRUC.Children[i] IMPORTED_BODY_TEMP01=IMPORTED_LOAD_GRP.Children[0] IMPORTED_BODY_TEMP01.Location=SOLID_BODY IMPORTED_BODY_TEMP02=IMPORTED_LOAD_GRP.AddImportedBodyTemperature() IMPORTED_BODY_TEMP02.Location=SHELL_BODY # Add Fixed Support FIXED_SUPPORT = STAT_STRUC.AddFixedSupport() FIXED_SUPPORT.Location = FIXED_FACE # Add Pressure PRESSURE = STAT_STRUC.AddPressure() PRESSURE.Location = LOAD_FACE PRESSURE.AppliedBy=LoadAppliedBy.SurfaceEffect PRESSURE.DefineBy=LoadDefineBy.Components PRESSURE.XComponent.Output.DiscreteValues = [Quantity("2 [MPa]")] #Scenario 10: Add results in Transient Thermal analysis TRANS_THERM_SOLUTION.Activate() TEMPERATURE01_RST = TRANS_THERM_SOLUTION.AddTemperature() #Scenario 11: Add results in Thermal Stress analysis STAT_STRUC_SOLUTION.Activate() # Insert Deformation results TOTAL_DEFORMATION = STAT_STRUC_SOLUTION.AddTotalDeformation() # Insert Equivalent Stress result EQUIVALENT_STRESS = STAT_STRUC_SOLUTION.AddEquivalentStress() #Scenario 12: Solve and review Results using Cyclic Symmetry TRANS_THERM_SOLUTION.Activate() TRANS_THERM_SOLUTION.Solve(True) #Temperature Result TEMPERATURE_RST_MIN = TEMPERATURE01_RST.Minimum.Value TEMPERATURE_RST_MAX = TEMPERATURE01_RST.Maximum.Value STAT_STRUC_SOLUTION.Activate() STAT_STRUC_SOLUTION.Solve(True) #Deformation Result TOTAL_DEF_MIN = TOTAL_DEFORMATION.Minimum.Value TOTAL_DEF_MAX = TOTAL_DEFORMATION.Maximum.Value #Equivalent Stress Result EQV_STRESS_MIN = EQUIVALENT_STRESS.Minimum.Value EQV_STRESS_MAX = EQUIVALENT_STRESS.Maximum.Value #Scenario 13: Suppress Cyclic Symmetry and insert Pre-Meshed Cyclic Region using local Coordinate System SYMMETRY_REGION1.Suppressed=True SYMMETRY_REGION2=SYMMETRY.AddPreMeshedCyclicRegion() SYMMETRY_REGION2.CoordinateSystem=COORDINATE_SYSTEM # Select Low and High Boundary with proper Coordinate System SYMMETRY_REGION2.LowBoundaryLocation=LOW_FACE SYMMETRY_REGION2.HighBoundaryLocation=HIGH_FACE SYMMETRY_REGION2.NumberOfSectors=4 #Scenario 14: Activate few mesh controls to get mapping mesh and generate mesh MESH.Activate() #Activate few mesh controls to get mapped meshed on low and high faces FACE_MESHING.Suppressed=False MESH_SIZE01.Suppressed=False MATCH_CONTROL01.Suppressed=False MATCH_CONTROL02.Suppressed=False MESH.GenerateMesh() #Scenario 15: Solve and review Results using Pre-Meshed Cyclic Region TRANS_THERM_SOLUTION.Activate() TRANS_THERM_SOLUTION.Solve(True) #Temperature Result TEMPERATURE2_RST_MIN = TEMPERATURE01_RST.Minimum.Value TEMPERATURE2_RST_MAX = TEMPERATURE01_RST.Maximum.Value STAT_STRUC_SOLUTION.Activate() STAT_STRUC_SOLUTION.Solve(True) #Deformation Result TOTAL_DEF2_MIN = TOTAL_DEFORMATION.Minimum.Value TOTAL_DEF2_MAX = TOTAL_DEFORMATION.Maximum.Value #Equivalent Stress Result EQV_STRESS2_MIN = EQUIVALENT_STRESS.Minimum.Value EQV_STRESS2_MAX = EQUIVALENT_STRESS.Maximum.Value
Summary
This example demonstrates how scripting in Mechanical can be used to automate your actions.