Transient Structural Analysis

In this example, using the support files, you will insert a Transient Structural analysis object into an undefined Mechanical session 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 CAD model and python files.

  • Transient_Structural_001.x_t

  • Transient_Structural_001.py

These files are available here.

Procedure

  1. Open Mechanical directly without importing a geometry or specifying an analysis type. This can be done through Start Menu.

  2. From the Analysis drop-down menu of the Insert group on the Home tab, insert a Transient Structural system into the tree.

  3. Select the Geometry object and select the Attach Geometry option from the Geometry group on the Geometry Context tab. Navigate to the proper folder location and select Transient_Structural_001.x_t.

     

  4. Select the Automation tab and select the Scripting option to open the Mechanical Scripting pane.

  5. Select the Open Script option ( ) from the Editor toolbar. Navigate to the proper folder location and select Transient_Structural_001.py.

  6. Select the Run Script option ( ) from the Editor toolbar.

Scripts Illustrated

In this example, the python file automatically performs the following actions:

# Section 1 - Set up the Tree Object Items.
#Section 2 - Set Units.
#Section 3 - Select Frictionless Contact
#Section 4 -  Create Named Selection
#Section 5 - Create Mesh Refinement
#Section 6 - Analysis Settings 
#Section 7 - Define Boundary Conditions and Loads
#Section 8 - Insert Results
#Section 9 - Solve and Evaluate Results

# Section 1 - Set up the Tree Object Items.

CONT_REG = DataModel.Project.Model.Connections.Children[0]
MSH = DataModel.Project.Model.Mesh
TRANS_STRUC1 = DataModel.AnalysisByName("Transient")
ANA_SETTING1 = TRANS_STRUC1.AnalysisSettings
SOLN= TRANS_STRUC1.Solution 

#Section 2 - Set Units

ExtAPI.Application.ActiveUnitSystem = MechanicalUnitSystem.StandardMKS
ExtAPI.Application.ActiveAngleUnit = AngleUnitType.Radian

#Section 3 - Select Frictionless Contact 

CONT1 = CONT_REG.Children[0]
CONT1.ContactType = ContactType.Frictionless
CONT1.InterfaceTreatment =ContactInitialEffect.AdjustToTouch

#Section 4 -  Create Named Selection

NS1 = DataModel.Project.Model.AddNamedSelection()
NS1.ScopingMethod=GeometryDefineByType.Worksheet
NS1.Name = "MSH_ref_1"
GEN_CRT1 = NS1.GenerationCriteria
CRT1 = Ansys.ACT.Automation.Mechanical.NamedSelectionCriterion()
CRT1.Active=True
CRT1.Action=SelectionActionType.Add
CRT1.EntityType=SelectionType.GeoFace
CRT1.Criterion=SelectionCriterionType.Size
CRT1.Operator=SelectionOperatorType.Equal
CRT1.Value=Quantity('9397.9 [mm mm]')
GEN_CRT1.Add(CRT1)
NS1.Activate()
NS1.Generate()

NS1.Duplicate()
NS2= DataModel.Project.Model.NamedSelections.Children[1]
NS2.Name = "MSH_ref_2"
GEN_CRT2 = NS2.GenerationCriteria
CRT1 = Ansys.ACT.Automation.Mechanical.NamedSelectionCriterion()
CRT1.Active=True
GEN_CRT2[0].Value=Quantity('62653 [mm^2]')
NS2.Activate()
NS2.Generate()

NS1.Duplicate()
NS3= DataModel.Project.Model.NamedSelections.Children[2]
NS3.Name = "cmpsnonlysupp"
GEN_CRT3 = NS3.GenerationCriteria
CRT1 = Ansys.ACT.Automation.Mechanical.NamedSelectionCriterion()
CRT1.Active=True
GEN_CRT3[0].Value=Quantity('22555 [mm^2]')
NS3.Activate()
NS3.Generate()

NS1.Duplicate()
NS4= DataModel.Project.Model.NamedSelections.Children[3]
NS4.Name = "frctlsupp"
GEN_CRT4 = NS4.GenerationCriteria
CRT1 = Ansys.ACT.Automation.Mechanical.NamedSelectionCriterion()
CRT1.Active=True
GEN_CRT4[0].Value=Quantity('32558 [mm^2]')
CRT2 = Ansys.ACT.Automation.Mechanical.NamedSelectionCriterion()
CRT2.Active=True
CRT2.Action=SelectionActionType.Add
CRT2.EntityType=SelectionType.GeoFace
CRT2.Criterion=SelectionCriterionType.Size
CRT2.Operator=SelectionOperatorType.Equal
CRT2.Value=Quantity('60155 [mm mm]')
GEN_CRT4.Add(CRT2)
CRT3 = Ansys.ACT.Automation.Mechanical.NamedSelectionCriterion()
CRT3.Active=True
CRT3.Action=SelectionActionType.Add
CRT3.EntityType=SelectionType.GeoFace
CRT3.Criterion=SelectionCriterionType.Size
CRT3.Operator=SelectionOperatorType.Equal
CRT3.Value=Quantity('7764.6 [mm mm]')
GEN_CRT4.Add(CRT3)
NS4.Activate()
NS4.Generate()

NS1.Duplicate()
NS5= DataModel.Project.Model.NamedSelections.Children[4]
NS5.Name = "DISP1"
GEN_CRT5 = NS5.GenerationCriteria
CRT1 = Ansys.ACT.Automation.Mechanical.NamedSelectionCriterion()
CRT1.Active=True
GEN_CRT5[0].Value=Quantity('7764.6 [mm^2]')
NS5.Activate()
NS5.Generate()

# Section 5 - Create Mesh Refinement

MSH.ElementSize =Quantity("10 [mm]")
REFINEMENT1 = MSH.AddRefinement()
SEL=ExtAPI.SelectionManager.AddSelection(NS1)
SEL1=ExtAPI.SelectionManager.CurrentSelection
CLRSEL = ExtAPI.SelectionManager.ClearSelection()
REFINEMENT1.Location = SEL1
REFINEMENT1.NumberOfRefinements = 1

#Section 6 - Analysis Settings 

ANA_SETTING1.Activate()
ANA_SETTING1.NumberOfSteps=2
ANA_SETTING1.CurrentStepNumber=1
ANA_SETTING1.StepEndTime=Quantity("1 [sec]")
ANA_SETTING1.InitialTimeStep=Quantity("0.5 [sec]")
ANA_SETTING1.MinimumTimeStep=Quantity("0.5 [sec]")
ANA_SETTING1.MaximumTimeStep=Quantity("0.5 [sec]")
ANA_SETTING1.CurrentStepNumber=2
ANA_SETTING1.StepEndTime=Quantity("2 [sec]")
ANA_SETTING1.InitialTimeStep=Quantity("0.5 [sec]")
ANA_SETTING1.MinimumTimeStep=Quantity("0.5 [sec]")
ANA_SETTING1.MaximumTimeStep=Quantity("0.5 [sec]")

ANA_SETTING1.NewtonRaphsonOption=NewtonRaphsonType.ProgramControlled
ANA_SETTING1.ForceConvergence=ConvergenceToleranceType.On

# Section 7 - Define Boundary Conditions and Loads

COMP_SUP = TRANS_STRUC1.AddCompressionOnlySupport()
COMP_SUP.Location = NS3

BEARING_LD = TRANS_STRUC1.AddBearingLoad()
BEARING_LD.Location = NS2
BEARING_LD.DefineBy = LoadDefineBy.Components
BEARING_LD.XComponent.Inputs[0].DiscreteValues = [Quantity("0 [sec]"), Quantity("1 [sec]"), Quantity("2 [sec]")]
BEARING_LD.XComponent.Output.DiscreteValues = [Quantity("1e5 [N]"), Quantity("2e5 [N]"), Quantity("3e5 [N]")]

FRIC_SUP = TRANS_STRUC1.AddFrictionlessSupport()
FRIC_SUP.Location = NS4

DISP1 = TRANS_STRUC1.AddDisplacement()
DISP1.Location = NS5
DISP1.DefineBy = LoadDefineBy.Components
DISP1.YComponent.Inputs[0].DiscreteValues = [Quantity("0 [sec]"), Quantity("1 [sec]"), Quantity("2 [sec]")]
DISP1.YComponent.Output.DiscreteValues = [Quantity("0.0 [m]"), Quantity("0.0 [m]"), Quantity("0.0 [m]")]

#Section 8 - Insert Results

FRC_REAC_PROBE = TRANS_STRUC1.Solution.AddForceReaction()
FRC_REAC_PROBE.BoundaryConditionSelection = COMP_SUP

EQV_STRS_1 = TRANS_STRUC1.Solution.AddEquivalentStress()

STRS_TOOL_1 = TRANS_STRUC1.Solution.AddStressTool()
STRS_SAF_FCTR_1 = STRS_TOOL_1.AddSafetyFactor()
STRS_TOOL_1.StressLimitType = SafetyLimitType.UltimatePerMaterial

#Section 9 - Solve and Evaluate Results

TRANS_STRUC1.Solution.Solve(True)

EQV_STRS_MAX_1 = EQV_STRS_1.MaximumOfMaximumOverTime.Value
EQV_STRS_MIN_1 = EQV_STRS_1.MinimumOfMinimumOverTime.Value
FRC_REAC_PROBE_VAL = FRC_REAC_PROBE.XAxis.Value
STRS_SAF_FCTR_1_VAL = STRS_SAF_FCTR_1.Minimum.Value

Summary

This example demonstrates how scripting in Mechanical can be used to automate your actions.