Rigid Dynamics: Variable Load Specification

In this example, using the support files, you will insert a Rigid Dynamics analysis object into an undefined Mechanical session and execute a sequence of python journal commands that defines an analysis, with a focus on the VariableLoad Extension, and solves the analysis.

This example begins in the Mechanical application. It requires you to download the following Ansys DesignModeler and python files.

  • Mechanical_RBD_Variable_Load_Example.agdb

  • Mechanical_RBD_Variable_Load_Example.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 Rigid Dynamics 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 Mechanical_RBD_Variable_Load_Example.agdb.

     

  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 Mechanical_RBD_Variable_Load_Example.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

connections = Model.Connections
transient_rbd = Model.Analyses[0]
analysis_settings = transient_rbd.Children[0]
solution = transient_rbd.Solution

# Section 2 - Define the Named Selections

ns_torus_surface = DataModel.GetObjectsByName("NS_torus_surface")[0]
ns_cone_surface = DataModel.GetObjectsByName("NS_cone_surface")[0]

# Section 3 - Define the Torus Translational Joint

torus_translational_joint = connections.AddJoint()
torus_translational_joint.ConnectionType=JointScopingType.BodyToGround
torus_translational_joint.Type = JointType.Translational
torus_translational_joint.MobileLocation = ns_torus_surface

# Section 4 - Define the Cone Translational Joint

cone_translational_joint = connections.AddJoint()
cone_translational_joint.ConnectionType=JointScopingType.BodyToGround
cone_translational_joint.Type = JointType.Translational
cone_translational_joint.MobileLocation = ns_cone_surface

# Section 5 - Define the Spring connecting the Torus and the Cone

cone_torus_spring = connections.AddSpring()
cone_torus_spring.LongitudinalStiffness=Quantity("10 [N m-1]")
cone_torus_spring.Scope = SpringScopingType.BodyToBody
cone_torus_spring.ReferenceScopeLocation = ns_cone_surface
cone_torus_spring.MobileScopeLocation = ns_torus_surface

# Section 6 - Insert a Rigid Dynamics Measures Folder

rigid_dynamics_measures = ExtAPI.DataModel.CreateObject('MeasuresFolder','VariableLoad')

body_measures_attributes = ExtAPI.DataModel.GetUserObjects('VariableLoad')[1].Attributes["measurements"]
joint_measures_attributes = ExtAPI.DataModel.GetUserObjects('VariableLoad')[2].Attributes["measurements"]
derived_measures_attributes = ExtAPI.DataModel.GetUserObjects('VariableLoad')[3].Attributes["measurements"]

# Section 7 - Insert the Joint and the Derived Measures

joint_measures_attributes.append({'selection': torus_translational_joint.Name, 'variable': 'Translation', 'name': 'TorusTranslation', 'selectionId': int(torus_translational_joint.ObjectId)})
derived_measures_attributes.append({'selection': 'X', 'basemeasure': 'TorusTranslation', 'name': 'TorusTranslationX', 'basemeasuretype': 'Joint', 'type': 'Component', 'value': 0})

# Section 8 - Insert a Measure Varying Joint Load to the Torus Translational Joint in X direction

measure_varying_joint_load_torus = transient_rbd.CreateLoadObject('MeasureJointLoad','VariableLoad') 

measure_varying_joint_load_torus.Properties["JointSelection"].Value = str(torus_translational_joint.ObjectId) 
measure_varying_joint_load_torus.Properties["JointDof"].Value = 'X'    

# Section 9 - Define the Measure Output Type as a Table

measure_varying_joint_load_torus.Properties["OutputType"].Value = 'Table' 
torus_table = measure_varying_joint_load_torus.Properties["OutputType"].Properties["Table"]  
measure_value = torus_table.Properties["MeasureValue"] 
magnitude = torus_table.Properties["Magnitude"]  

torus_table.AddRow()
measure_value.Value = -0.1  
magnitude.Value = 10
torus_table.SaveActiveRow()
torus_table.AddRow()
measure_value.Value = 0.1
magnitude.Value = -10
torus_table.SaveActiveRow()

# Section 10 - Define the Measures Selection

measure_selection = measure_varying_joint_load_torus.Properties["MeasurementSelections"]    
measure_selection.UpdateStateFreq = UpdateStateFreqEnum.UpdateEachTime
measure = measure_selection.Properties["MeasurementSelection"]   
measure_selection.AddRow()
measure.Value = 'TorusTranslationX' 
measure_selection.SaveActiveRow()
measure_varying_joint_load_torus.NotifyChange() 

# Section 11 - Insert Standard Earth Gravity
 
gravity = transient_rbd.AddEarthGravity() 

# Section 12 - Insert Total Deformation result and Solve 

total_deformation = solution.AddTotalDeformation()
solution.Solve(True)

Summary

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