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 flexible part definition, 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_Flexible_Part_Example.agdb
Mechanical_RBD_Flexible_Part_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 Mechanical_RBD_Flexible_Part_Example.agdb.
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 Mechanical_RBD_Flexible_Part_Example.py.
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 geometry = Model.Geometry 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_face1 = DataModel.GetObjectsByName("NS_FACE1")[0] ns_face2 = DataModel.GetObjectsByName("NS_FACE2")[0] ns_cms1 = DataModel.GetObjectsByName("NS_CMS1")[0] # Section 3 - Define the Flexible Cms1 Part and Suppress Solid cms1 = geometry.Children[0].Children[0] solid = geometry.Children[1].Children[0] cms1.StiffnessBehavior = StiffnessBehavior.Flexible solid.Suppressed = True # Section 4 - Set up the General Revolute Joint general_revolute_joint = connections.AddJoint() general_revolute_joint.ConnectionType=JointScopingType.BodyToGround general_revolute_joint.Type = JointType.General general_revolute_joint.MobileLocation = ns_face1 general_revolute_joint.Rotations = JointRotationDOFType.FreeX # Section 5 - Set up the General Joint with 6 DOF general_all_free = connections.AddJoint() general_all_free.ConnectionType=JointScopingType.BodyToGround general_all_free.Type = JointType.General general_all_free.TranslationX=FixedOrFree.Free general_all_free.TranslationY=FixedOrFree.Free general_all_free.TranslationZ=FixedOrFree.Free general_all_free.Rotations=JointRotationDOFType.FreeAll general_all_free.MobileLocation = ns_face2 # Section 6 - Generate Condensed Geometries condensed_geometry = Model.AddCondensedGeometry() condensed_part = condensed_geometry.AddCondensedPart() condensed_part.GeometrySelection = ns_cms1 condensed_part.NumberOfModes = 10 condensed_part.DetectCondensedPartInterface() condensed_part.GenerateCondensedParts() # Section 7 - Define the Analysis Settings analysis_settings.SetStepEndTime( 1, Quantity("0.5 [s]")) analysis_settings.SetAutomaticTimeStepping( 1, AutomaticTimeStepping.On) analysis_settings.SetInitialTimeStep( 1, Quantity("1e-4[s]")) analysis_settings.SetMinimumTimeStep( 1, Quantity("1e-7[s]")) analysis_settings.SetMaximumTimeStep( 1, Quantity("1e-3[s]")) analysis_settings.SetStoreResultAt( 1,TimePointsOptions.EquallySpacedPoints) analysis_settings.SetStoreResultAtValue( 1,200) # Section 8 - Insert Standard Earth Gravity gravity = transient_rbd.AddEarthGravity() gravity.Direction=GravityOrientationType.PositiveYAxis # Section 9 - Define the Expansion Settings expansion_settings = solution.Children[1] expansion_settings.Activate() expansion_settings_state = expansion_settings.GetExpansionState( condensed_part) expansion_settings_state.Stress = True expansion_settings_state.Displacement = True expansion_settings.SetExpansionState( condensed_part, expansion_settings_state) # Section 10 - Insert the Condensed Part Results total_deformation = solution.AddTotalDeformation() joint_probe_deformation = solution.AddJointProbe() joint_probe_deformation.BoundaryConditionSelection = general_all_free joint_probe_deformation.ResultType = ProbeResultType.DeformationProbe equivalent_stress = solution.AddEquivalentStress() middle_principal_strain = solution.AddMiddlePrincipalElasticStrain() # Section 11 - Set up the Unit Systems ExtAPI.Application.ActiveUnitSystem = MechanicalUnitSystem.StandardMKS ExtAPI.Application.ActiveAngleUnit = AngleUnitType.Radian ExtAPI.Application.ActiveAngularVelocityUnit=AngularVelocityUnitType.RadianPerSecond # Section 12 - Solve the System and Define the Condensed Part Results solution.Solve(True) total_deformation_maximum = total_deformation.Maximum.Value equivalent_stress_maximum = equivalent_stress.Maximum.Value middle_principal_stress_maximum = middle_principal_strain.Maximum.Value
Summary
This example demonstrates how scripting in Mechanical can be used to automate your actions.