In this example, using the support files, you will insert a Coupled Field Static 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 Ansys DesignModeler and python files.
Coupled_Field_Static_Example.agdb
Coupled_Field_Static_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 Coupled_Field_Static_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 Coupled_Field_Static_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 Tree Object Items GEOMETRY = Model.Geometry COORDINATE_SYSTEM = Model.CoordinateSystems CONNECTIONS = Model.Connections MESH = Model.Mesh COUPLED_FIELD_STATIC = ExtAPI.DataModel.AnalysisByName("Coupled Field Static") ANALYSIS_SETTINGS = COUPLED_FIELD_STATIC.AnalysisSettings SOLUTION = COUPLED_FIELD_STATIC.Solution # Scenario 2 Set up the Unit Systems ExtAPI.Application.ActiveUnitSystem = MechanicalUnitSystem.StandardNMM # Scenario 3 Define Geometry Details ROD_PART = GEOMETRY.Children[0].Children[0] RIGID_PART = GEOMETRY.Children[1].Children[0] RIGID_PART.StiffnessBehavior=StiffnessBehavior.Rigid # Scenario 4 Define Named Selections NS_FIXED_ROD = [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == 'Fixed_Rod'][0] NS_FIXED_RIGID = [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == 'Fixed_Rigid'][0] NS_RIGID_EDGES1 = [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == 'Rigid_Edges1'][0] NS_RIGID_EDGES2 = [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == 'Rigid_Edges2'][0] NS_RIGID_FACE = [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == 'Rigid_Face'][0] NS_ROD_EDGES1 = [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == 'Rod_Edges1'][0] NS_ROD_EDGES2 = [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == 'Rod_Edges2'][0] NS_ROD_FACE = [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == 'Rod_Face'][0] NS_ROD_BODY = [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == 'Rod_Body'][0] NS_RIGID_BODY = [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == 'Rigid_Body'][0] NS_BOTH_BODIES = [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == 'Both_Bodies'][0] # Scenario 5 Insert Local Coordinate System LCS = COORDINATE_SYSTEM.AddCoordinateSystem() LCS.OriginLocation = NS_ROD_BODY LCS.CreateConstructionSurface() CONST_GEOM = ExtAPI.DataModel.Project.Model.ConstructionGeometry CONST_SURF = CONST_GEOM.Children[0] # Scenario 6 Define Contact CONTACTS = CONNECTIONS.Children[0] CONTACTS_REGION = CONTACTS.Children[0] CONTACTS_REGION.ContactType=ContactType.Frictional CONTACTS_REGION.FrictionCoefficient=0.3 CONTACTS_REGION.TimeStepControls=ContactTimeStepControls.PredictForImpact CONTACTS_REGION.NormalStiffnessValueType=ElementControlsNormalStiffnessType.AbsoluteValue CONTACTS_REGION.NormalStiffnessValue=Quantity('1e10[N mm^-1 mm^-1 mm^-1]') # Scenario 7 Define Mesh Settings MESH.ElementSize = Quantity('25 [mm]') MESH.ElementOrder = ElementOrder.Quadratic MESH_METHOD = MESH.AddAutomaticMethod() MESH_METHOD.Location = NS_ROD_BODY MESH_METHOD.Method = MethodType.HexDominant MESH.GenerateMesh() # Scenario 8 Define Physics Region PHY_REG01 = COUPLED_FIELD_STATIC.Children[2] PHY_REG01.Location = NS_ROD_BODY PHY_REG01.ThermalStrain = ThermalStrainType.Strong PHY_REG02 = COUPLED_FIELD_STATIC.AddPhysicsRegion() PHY_REG02.Structural = True # Scenario 9 Define Analysis Settings INITIAL_PHYSICS_OPTION = COUPLED_FIELD_STATIC.Children[0] ANALYSIS_SETTINGS.NumberOfSteps = 1 ANALYSIS_SETTINGS.StepEndTime = Quantity('1 [sec]') ANALYSIS_SETTINGS.AutomaticTimeStepping = AutomaticTimeStepping.Off ANALYSIS_SETTINGS.NumberOfSubSteps = 10 # Scenario 10 Insert Load and Boundary Conditions FIXED_SUPPORT = COUPLED_FIELD_STATIC.AddFixedSupport() FIXED_SUPPORT.Location = NS_FIXED_ROD REMOTE_DISPLACEMENT = COUPLED_FIELD_STATIC.AddRemoteDisplacement() REMOTE_DISPLACEMENT.Location = NS_FIXED_RIGID REMOTE_DISPLACEMENT.XComponent.Output.DiscreteValues = [Quantity("0 [mm]")] REMOTE_DISPLACEMENT.YComponent.Output.DiscreteValues = [Quantity("0 [mm]")] REMOTE_DISPLACEMENT.ZComponent.Output.DiscreteValues = [Quantity("0 [mm]")] REMOTE_DISPLACEMENT.RotationX.Output.DiscreteValues = [Quantity("0 [deg]")] REMOTE_DISPLACEMENT.RotationY.Output.DiscreteValues = [Quantity("0 [deg]")] REMOTE_DISPLACEMENT.RotationZ.Output.DiscreteValues = [Quantity("0 [deg]")] TEMPERATURE = COUPLED_FIELD_STATIC.AddTemperature() TEMPERATURE.Location = NS_ROD_BODY TEMPERATURE.Magnitude.Output.DiscreteValues = [Quantity('122 [C]')] # Scenario 11 Insert Results DIRECTIONAL_DEFORMATION = SOLUTION.AddDirectionalDeformation() DIRECTIONAL_DEFORMATION.Location = NS_ROD_BODY DIRECTIONAL_DEFORMATION.NormalOrientation = NormalOrientationType.ZAxis NORMAL_STRESS = SOLUTION.AddNormalStress() NORMAL_STRESS.Location = CONST_SURF NORMAL_STRESS.NormalOrientation = NormalOrientationType.ZAxis THERMAL_STRAIN = SOLUTION.AddThermalStrain() THERMAL_STRAIN.NormalOrientation=NormalOrientationType.ZAxis THERMAL_STRAIN.Location = NS_ROD_BODY # Scenario 12 Solve and review the Result SOLUTION.Solve(True) MAXIMUM_DIRECTIONAL_DEFORMATION = DIRECTIONAL_DEFORMATION.Maximum.Value MINIMUM_DIRECTIONAL_DEFORMATION = DIRECTIONAL_DEFORMATION.Minimum.Value MAXIMUM_NORMAL_STRESS = NORMAL_STRESS.Maximum.Value MAXIMUM_THERMAL_STRAIN = THERMAL_STRAIN.Maximum.Value
Summary
This example demonstrates how scripting in Mechanical can be used to automate your actions.