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 specify a Joint as Cylindrical, define mesh and boundary and result objects and solve the analysis.
This example begins in the Mechanical application. It requires you to download the following Ansys DesignModeler and python files.
Cylindrical_Joint_Example.agbd
Cylindrical_Joint_Example.py
These files are available here.
Procedure
Open Mechanical directly without importing a geometry or specifying an analysis type. This can be done through Start Menu.
From the Analysis drop-down menu of the Insert group on the Home tab, insert a system into the tree.
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 Cylindrical_Joint_Example.agbd.
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 Cylindrical_Joint_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 - Set up the Units System ExtAPI.Application.ActiveUnitSystem = MechanicalUnitSystem.StandardCGS # Scenario 2 - Set up the Tree Object Items GEOMETRY = Model.Geometry CONNECTION_GROUP = Model.Connections MESH = Model.Mesh TRANSIENT_STRUCTURAL = Model.Analyses[0] ANALYSIS_SETTINGS = TRANSIENT_STRUCTURAL.Children[1] TRANSIENT_STRUCTURAL_SOLUTION = TRANSIENT_STRUCTURAL.Solution # Scenario 3 - Set the Stiffness Behavior of bodies as Rigid PART1 = GEOMETRY.Children[0].Children[0] PART2 = GEOMETRY.Children[1].Children[0] PART1.StiffnessBehavior = StiffnessBehavior.Rigid PART2.StiffnessBehavior = StiffnessBehavior.Rigid # Scenario 4 - Define Named Selections NS_FACE_1 = DataModel.GetObjectsByName("NS_Face_1")[0] NS_FACE_2 = DataModel.GetObjectsByName("NS_Face_2")[0] NS_FACE_3 = DataModel.GetObjectsByName("NS_Face_3")[0] NS_FORCE_1 = DataModel.GetObjectsByName("NS_Force_1")[0] NS_FORCE_2 = DataModel.GetObjectsByName("NS_Force_2")[0] # Scenario 5 - Define Cylindrical Joint and Fixed Joint CONNECTION_GROUP.Activate() JOINT_CYLINDRICAL = CONNECTION_GROUP.AddJoint() JOINT_CYLINDRICAL.Name = "CYLINDRICAL_JOINT" JOINT_CYLINDRICAL.ConnectionType = JointScopingType.BodyToBody JOINT_CYLINDRICAL.Type = JointType.Cylindrical JOINT_CYLINDRICAL.ReferenceLocation = NS_FACE_3 JOINT_CYLINDRICAL.MobileLocation= NS_FACE_2 # User can set the value of Torsional Stiffness and Torsional Damping using below commands. JOINT_CYLINDRICAL.TorsionalStiffness = Quantity ("1e6 [dyne cm deg^-1]") JOINT_CYLINDRICAL.TorsionalDamping= Quantity ("1e6 [dyne cm s deg^-1]") CONNECTION_GROUP.Activate() JOINT_FIXED = CONNECTION_GROUP.AddJoint() JOINT_FIXED.Name = "FIXED_JOINT" JOINT_FIXED.ConnectionType = JointScopingType.BodyToGround JOINT_FIXED.Type = JointType.Fixed JOINT_FIXED.MobileLocation= NS_FACE_1 # Scenario 6 - Define Analysis Settings ANALYSIS_SETTINGS.Activate() ANALYSIS_SETTINGS.AutomaticTimeStepping = AutomaticTimeStepping.Off ANALYSIS_SETTINGS.TimeStep = Quantity("1e-2 [s]") # Scenario 7 - Insert Remote Force BC TRANSIENT_STRUCTURAL.Activate() REMOTE_FORCE_BC = TRANSIENT_STRUCTURAL.AddRemoteForce() REMOTE_FORCE_BC.Location = NS_FORCE_2 REMOTE_FORCE_BC.DefineBy = LoadDefineBy.Components REMOTE_FORCE_BC.YComponent.Output.DiscreteValues = [Quantity("1e11 [dyne]")] REMOTE_FORCE_BC.ZComponent.Output.DiscreteValues = [Quantity("1e11 [dyne]")] # Scenario 8 - Insert Results DIRECTIONAL_DEFORMATION = TRANSIENT_STRUCTURAL_SOLUTION.AddDirectionalDeformation() DIRECTIONAL_DEFORMATION.NormalOrientation = NormalOrientationType.ZAxis JOINT_PROBE_RELATIVE_DISPLACEMENT = TRANSIENT_STRUCTURAL_SOLUTION.AddJointProbe() JOINT_PROBE_RELATIVE_DISPLACEMENT.BoundaryConditionSelection = JOINT_CYLINDRICAL JOINT_PROBE_RELATIVE_DISPLACEMENT.ResultType = ProbeResultType.DeformationProbe JOINT_PROBE_RELATIVE_DISPLACEMENT.ResultSelection = ProbeDisplayFilter.ZAxis JOINT_PROBE_RELATIVE_VELOCITY = TRANSIENT_STRUCTURAL_SOLUTION.AddJointProbe() JOINT_PROBE_RELATIVE_VELOCITY.BoundaryConditionSelection = JOINT_CYLINDRICAL JOINT_PROBE_RELATIVE_VELOCITY.ResultType = ProbeResultType.VelocityProbe JOINT_PROBE_RELATIVE_VELOCITY.ResultSelection = ProbeDisplayFilter.ZAxis JOINT_PROBE_RELATIVE_ACCELERATION = TRANSIENT_STRUCTURAL_SOLUTION.AddJointProbe() JOINT_PROBE_RELATIVE_ACCELERATION.BoundaryConditionSelection = JOINT_CYLINDRICAL JOINT_PROBE_RELATIVE_ACCELERATION.ResultType = ProbeResultType.AccelerationProbe JOINT_PROBE_RELATIVE_ACCELERATION.ResultSelection = ProbeDisplayFilter.ZAxis JOINT_PROBE_RELATIVE_ROTATION = TRANSIENT_STRUCTURAL_SOLUTION.AddJointProbe() JOINT_PROBE_RELATIVE_ROTATION.BoundaryConditionSelection = JOINT_CYLINDRICAL JOINT_PROBE_RELATIVE_ROTATION.ResultType = ProbeResultType.RotationProbe JOINT_PROBE_RELATIVE_ROTATION.ResultSelection = ProbeDisplayFilter.ZAxis JOINT_PROBE_RELATIVE_ANGULAR_VELOCITY = TRANSIENT_STRUCTURAL_SOLUTION.AddJointProbe() JOINT_PROBE_RELATIVE_ANGULAR_VELOCITY.BoundaryConditionSelection = JOINT_CYLINDRICAL JOINT_PROBE_RELATIVE_ANGULAR_VELOCITY.ResultType = ProbeResultType.AngularVelocityProbe JOINT_PROBE_RELATIVE_ANGULAR_VELOCITY.ResultSelection = ProbeDisplayFilter.ZAxis JOINT_PROBE_RELATIVE_ANGULAR_ACCELERATION = TRANSIENT_STRUCTURAL_SOLUTION.AddJointProbe() JOINT_PROBE_RELATIVE_ANGULAR_ACCELERATION.BoundaryConditionSelection = JOINT_CYLINDRICAL JOINT_PROBE_RELATIVE_ANGULAR_ACCELERATION.ResultType = ProbeResultType.AngularAccelerationProbe JOINT_PROBE_RELATIVE_ANGULAR_ACCELERATION.ResultSelection = ProbeDisplayFilter.ZAxis JOINT_PROBE_TOTAL_FORCE = TRANSIENT_STRUCTURAL_SOLUTION.AddJointProbe() JOINT_PROBE_TOTAL_FORCE.BoundaryConditionSelection = JOINT_CYLINDRICAL JOINT_PROBE_TOTAL_FORCE.ResultType = ProbeResultType.ForceReaction JOINT_PROBE_TOTAL_FORCE.ResultSelection = ProbeDisplayFilter.YAxis JOINT_PROBE_TOTAL_MOMENT = TRANSIENT_STRUCTURAL_SOLUTION.AddJointProbe() JOINT_PROBE_TOTAL_MOMENT.BoundaryConditionSelection = JOINT_CYLINDRICAL JOINT_PROBE_TOTAL_MOMENT.ResultType = ProbeResultType.MomentReaction JOINT_PROBE_TOTAL_MOMENT.ResultSelection = ProbeDisplayFilter.YAxis # Scenario 9 - Solve and review the results TRANSIENT_STRUCTURAL_SOLUTION.Solve(True) JOINT_PROBE_RELATIVE_DISPLACEMENT_VAL = JOINT_PROBE_RELATIVE_DISPLACEMENT.ZAxis.Value JOINT_PROBE_RELATIVE_VELOCITY_VAL = JOINT_PROBE_RELATIVE_VELOCITY.ZAxis.Value JOINT_PROBE_RELATIVE_ACCELERATION_VAL = JOINT_PROBE_RELATIVE_ACCELERATION.ZAxis.Value JOINT_PROBE_RELATIVE_ROTATION_VAL = JOINT_PROBE_RELATIVE_ROTATION.ZAxis.Value JOINT_PROBE_RELATIVE_ANGULAR_VELOCITY_VAL = JOINT_PROBE_RELATIVE_ANGULAR_VELOCITY.ZAxis.Value JOINT_PROBE_RELATIVE_ANGULAR_ACCELERATION_VAL = JOINT_PROBE_RELATIVE_ANGULAR_ACCELERATION.ZAxis.Value JOINT_PROBE_TOTAL_FORCE_VAL = JOINT_PROBE_TOTAL_FORCE.YAxis.Value JOINT_PROBE_TOTAL_MOMENT_VAL = JOINT_PROBE_TOTAL_MOMENT.YAxis.Value
Summary
This example demonstrates how scripting in Mechanical can be used to automate your actions.