In this example, using the support files, you will create a Static Structural analysis, execute a sequence of python journal commands that will setup and solve a Contact Debonding analysis.
This example begins in the Mechanical application. It requires you to download the following Ansys DesignModeler and python files.
Contact_Debonding_Example.agdb
Contact_Debonding_Example.py
Contact_Debonding_Example_Mat1.xml
Contact_Debonding_Example_Mat2.xml
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 Contact_Debonding_Example_Mat1.xml. Repeat this for Contact_Debonding_Example_Mat2.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.
Set the Analysis Type property to under the Advanced Geometry Options category.
Right-click the Geometry cell and select > and then navigate to the proper folder location and select Contact_Debonding_Example.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 Contact_Debonding_Example.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 GEOMETRY = Model.Geometry PART = [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == 'Part 2'][0] MAT_GRP = MODEL.Materials MAT_BODY = [i for i in MAT_GRP.GetChildren[Ansys.ACT.Automation.Mechanical.Material](True) if i.Name == 'Interface Body Material'][0] MAT_CZM = [i for i in MAT_GRP.GetChildren[Ansys.ACT.Automation.Mechanical.Material](True) if i.Name == 'CZM Crack Material'][0] CONNECTIONS_GRP = ExtAPI.DataModel.Project.Model.Connections CONTACTS = [i for i in CONNECTIONS_GRP.GetChildren[Ansys.ACT.Automation.Mechanical.Connections.ConnectionGroup](True) if i.Name == 'Contacts'][0] CONTACT_REGION = [i for i in CONTACTS.GetChildren[Ansys.ACT.Automation.Mechanical.Connections.ContactRegion](True) if i.Name == 'Contact Region'][0] MESH = Model.Mesh NAMED_SELECTIONS = ExtAPI.DataModel.Project.Model.NamedSelections NS_EDGE_HIGH = [i for i in NAMED_SELECTIONS.GetChildren[Ansys.ACT.Automation.Mechanical.NamedSelection](True) if i.Name == 'High_Edge'][0] NS_EDGE_LOW = [i for i in NAMED_SELECTIONS.GetChildren[Ansys.ACT.Automation.Mechanical.NamedSelection](True) if i.Name == 'Low_Edge'][0] NS_EDGES_SHORT = [i for i in NAMED_SELECTIONS.GetChildren[Ansys.ACT.Automation.Mechanical.NamedSelection](True) if i.Name == 'Short_Edges'][0] NS_EDGES_LONG = [i for i in NAMED_SELECTIONS.GetChildren[Ansys.ACT.Automation.Mechanical.NamedSelection](True) if i.Name == 'Long_Edges'][0] NS_EDGES_FIXED = [i for i in NAMED_SELECTIONS.GetChildren[Ansys.ACT.Automation.Mechanical.NamedSelection](True) if i.Name == 'Fixed_Edges'][0] NS_VERTEX_DISP1 = [i for i in NAMED_SELECTIONS.GetChildren[Ansys.ACT.Automation.Mechanical.NamedSelection](True) if i.Name == 'Disp1_Vertex'][0] NS_VERTEX_DISP2 = [i for i in NAMED_SELECTIONS.GetChildren[Ansys.ACT.Automation.Mechanical.NamedSelection](True) if i.Name == 'Disp2_Vertex'][0] NS_FACES_BOTH = [i for i in NAMED_SELECTIONS.GetChildren[Ansys.ACT.Automation.Mechanical.NamedSelection](True) if i.Name == 'Both_Faces'][0] STATIC_STRUCTURAL = ExtAPI.DataModel.AnalysisByName("Static Structural") ANALYSIS_SETTINGS = STATIC_STRUCTURAL.AnalysisSettings SOLUTION= STATIC_STRUCTURAL.Solution # Scenario 2 Set Display Unit ExtAPI.Application.ActiveUnitSystem = MechanicalUnitSystem.StandardNMM # Scenario 3 Set 2D Behavior GEOMETRY.Activate() GEOMETRY.Model2DBehavior=Model2DBehavior.PlaneStrain # Scenario 4 Assign Material PART.Activate() PART.Material = MAT_BODY.Name # Scenario 5 Define Contact Region CONTACT_REGION.Activate() CONTACT_REGION.SourceLocation = NS_EDGE_HIGH CONTACT_REGION.TargetLocation= NS_EDGE_LOW CONTACT_REGION.ContactType=ContactType.Bonded CONTACT_REGION.ContactFormulation=ContactFormulation.PurePenalty # Scenario 6 Define Mesh controls and generate mesh MESH.Activate() MESH.ElementOrder=ElementOrder.Quadratic MESH.UseAdaptiveSizing=False MESH.ElementSize = Quantity('0.75 [mm]') SIZING_MESH = MESH.AddSizing() SIZING_MESH.Location = NS_EDGES_SHORT SIZING_MESH.ElementSize = Quantity('0.75 [mm]') SIZING_MESH.Behavior=SizingBehavior.Hard SIZING_MESH2 = MESH.AddSizing() SIZING_MESH2.Location = NS_EDGES_LONG SIZING_MESH2.ElementSize = Quantity('0.5 [mm]') SIZING_MESH2.Behavior=SizingBehavior.Hard FACE_MESHING = MESH.AddFaceMeshing() FACE_MESHING.Location = NS_FACES_BOTH FACE_MESHING.Method=FaceMeshingMethod.Quadrilaterals MESH.Activate() MESH.GenerateMesh() # Scenario 7 Add Contact Debonding object MODEL.Activate() FRACTURE = MODEL.AddFracture() CONTACT_DEBONDING = FRACTURE.AddContactDebonding() CONTACT_DEBONDING.Material= MAT_CZM.Name CONTACT_DEBONDING.ContactRegion=CONTACT_REGION # Scenario 8 Define Analysis Settings ANALYSIS_SETTINGS.Activate() ANALYSIS_SETTINGS.AutomaticTimeStepping=AutomaticTimeStepping.On ANALYSIS_SETTINGS.DefineBy=TimeStepDefineByType.Substeps ANALYSIS_SETTINGS.MaximumSubsteps=100 ANALYSIS_SETTINGS.InitialSubsteps=100 ANALYSIS_SETTINGS.MinimumSubsteps=100 ANALYSIS_SETTINGS.LargeDeflection=True # Scenario 9 Define boundary conditions STATIC_STRUCTURAL.Activate() FIXED_SUPPORT = STATIC_STRUCTURAL.AddFixedSupport() FIXED_SUPPORT.Location = NS_EDGES_FIXED STATIC_STRUCTURAL.Activate() DISPLACEMENT = STATIC_STRUCTURAL.AddDisplacement() DISPLACEMENT.Location = NS_VERTEX_DISP1 DISPLACEMENT.DefineBy = LoadDefineBy.Components DISPLACEMENT.YComponent.Output.DiscreteValues=[Quantity('10 [mm]')] STATIC_STRUCTURAL.Activate() DISPLACEMENT2 = STATIC_STRUCTURAL.AddDisplacement() DISPLACEMENT2.Location = NS_VERTEX_DISP2 DISPLACEMENT2.DefineBy = LoadDefineBy.Components DISPLACEMENT2.YComponent.Output.DiscreteValues=[Quantity('-10 [mm]')] # Scenario 10 Add results SOLUTION.Activate() DIRECTIONAL_DEFORMATION = SOLUTION.AddDirectionalDeformation() DIRECTIONAL_DEFORMATION.NormalOrientation=NormalOrientationType.YAxis FORCE_REACTION = SOLUTION.AddForceReaction() FORCE_REACTION.BoundaryConditionSelection = DISPLACEMENT # Scenario 11 Solve and review results STATIC_STRUCTURAL.Activate() STATIC_STRUCTURAL.Solve(True) DIRECTIONAL_DEFORMATION.Activate() MIN_DIRECTIONAL_DEFORMATION = DIRECTIONAL_DEFORMATION.Minimum.Value MAX_DIRECTIONAL_DEFORMATION = DIRECTIONAL_DEFORMATION.Maximum.Value FORCE_REACTION.Activate() Y_AXIS_FORCE_REACTION = FORCE_REACTION.YAxis.Value MOT_Y_AXIS_FORCE_REACTION = FORCE_REACTION.MaximumYAxis.Value
Summary
This example demonstrates how scripting in Mechanical can be used to automate your actions.