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 contact, 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_Contact_Example.agdb
Mechanical_RBD_Contact_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_Contact_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_Contact_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 connections = Model.Connections transient_rbd = Model.Analyses[0] analysis_settings = transient_rbd.Children[0] mesh = Model.Mesh 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] ns_fixed_surface = DataModel.GetObjectsByName("NS_fixed_surface")[0] # Section 3 - Define the Contact contact = connections.AddContactRegion() contact.SourceLocation = ns_torus_surface contact.TargetLocation = ns_cone_surface contact.ContactType = ContactType.Frictionless contact.PinballRegion = ContactPinballType.ProgramControlled contact.RestitutionFactor = 0.5 contact.RBDContactDetection = DSRBDContactDetection.kCDGeometryBased # Section 4 - Define the Fixed Joint fixed_joint = connections.AddJoint() fixed_joint.ConnectionType=JointScopingType.BodyToGround fixed_joint.Type = JointType.Fixed fixed_joint.MobileLocation = ns_fixed_surface # Section 5 - Define the Mesh mesh.PhysicsPreference = MeshPhysicsPreferenceType.Mechanical mesh.ElementOrder=ElementOrder.Quadratic mesh.ElementSize = Quantity("0.005 [m]") mesh.Resolution = 4 mesh.GenerateMesh() # Section 6 - Insert Standard Earth Gravity gravity = transient_rbd.AddEarthGravity() gravity.Direction=GravityOrientationType.NegativeZAxis # Section 7 - Define the Analysis Settings analysis_settings.SetStepEndTime( 1, Quantity("0.4 [s]")) analysis_settings.SetAutomaticTimeStepping(1,AutomaticTimeStepping.On) analysis_settings.SetInitialTimeStep(1,Quantity("0.0001 [s]")) analysis_settings.SetMinimumTimeStep(1,Quantity("0.0000001 [s]")) analysis_settings.SetMaximumTimeStep(1,Quantity("0.01 [s]")) # Section 8 - Define the Contact Results total_contact_force_reaction = solution.AddForceReaction() total_contact_force_reaction.LocationMethod=LocationDefinitionMethod.ContactRegion total_contact_force_reaction.ContactRegionSelection = contact total_contact_force_reaction.ContactForce=ContactForceType.Total tangent_contact_force_reaction = solution.AddForceReaction() tangent_contact_force_reaction.LocationMethod=LocationDefinitionMethod.ContactRegion tangent_contact_force_reaction.ContactRegionSelection = contact tangent_contact_force_reaction.ContactForce=ContactForceType.Tangent normal_contact_force_reaction = solution.AddForceReaction() normal_contact_force_reaction.LocationMethod=LocationDefinitionMethod.ContactRegion normal_contact_force_reaction.ContactRegionSelection = contact normal_contact_force_reaction.ContactForce=ContactForceType.Normal # Section 9 - Set up the Unit Systems ExtAPI.Application.ActiveUnitSystem = MechanicalUnitSystem.StandardMKS ExtAPI.Application.ActiveAngleUnit = AngleUnitType.Radian ExtAPI.Application.ActiveAngularVelocityUnit=AngularVelocityUnitType.RadianPerSecond # Section 10 - Solve the System and Define the Contact Results solution.Solve(True) total_contact_force_reaction_z = total_contact_force_reaction.ZAxis.Value total_contact_force_reaction_maximum_z = total_contact_force_reaction.MaximumZAxis.Value tangent_contact_force_reaction_maximum_total = total_contact_force_reaction.MaximumTotal.Value normal_contact_force_reaction_maximum_total = normal_contact_force_reaction.MaximumTotal.Value normal_contact_force_reaction_minimum_z = normal_contact_force_reaction.MinimumZAxis.Value # Section 11 - Insert and Evaluate the Energy Probe Results energy_probe = solution.AddEnergyProbe() solution.EvaluateAllResults() maximum_potential_energy = energy_probe.MaximumPotentialEnergy.Value maximum_kinetic_energy = energy_probe.MaximumKineticEnergy.Value maximum_total_energy = energy_probe.MaximumTotalEnergy.Value maximum_external_energy = energy_probe.MaximumExternalEnergy.Value
Summary
This example demonstrates how scripting in Mechanical can be used to automate your actions.