In this example, using the support files, you will insert a Steady-State Thermal 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.
Mechanical_Steady_State_Thermal_Example_001.agdb
Mechanical_Steady_State_Thermal_Example_001.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_Steady_State_Thermal_Example_001.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_Steady_State_Thermal_Example_001.py.
Select the Run Script option (
) from the Editor toolbar.
Scripts Illustrated
In this example, the python file automatically performs the following actions:
# Scenario1 - Set up Unit System: Set up the Unit Systems to Metric (mm, kg, N, s, mV, mA), ExtAPI.Application.ActiveUnitSystem = MechanicalUnitSystem.StandardNMM # Scenario 2 - Set up the Tree Object Items: Define the parts, connections, mesh, Steady-State Thermal system, the analysis settings, and the solution navigating through the tree items. PART1 = [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == 'Part 1'][0] PART2 = [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == 'Part 2'][0] PART3 = [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == 'Part 3'][0] MESH = Model.Mesh STEADY_STATE_THERMAL = DataModel.AnalysisByName("Steady-State Thermal") ANSLYSIS_SETTINGS = STEADY_STATE_THERMAL.AnalysisSettings SOLUTION = STEADY_STATE_THERMAL.Solution # Scenario 3 - Define Named Selections: Define the Named selections that will be used to define the Mesh Controls, the loads and the results. NS_CONVECTION_FACE = DataModel.GetObjectsByName("NS_convection_face")[0] NS_HG = DataModel.GetObjectsByName("NS_heat_generation")[0] NS_RESULTS = DataModel.GetObjectsByName("NS_results")[0] NS_ALL_BODIES = DataModel.GetObjectsByName("NS_all_bodies")[0] # Scenario 4 - Define Mesh Settings: Set the mesh resolution to 3. Define mesh control with sweep method, mesh algorithm set to Axisymmetric, mesh in centre is wedge and 24 number of sweep divisions. MESH.Resolution = 3 MESH_METHOD = MESH.AddAutomaticMethod() MESH_METHOD.Location = NS_ALL_BODIES MESH_METHOD.Method = MethodType.Sweep MESH_METHOD.Algorithm = MeshMethodAlgorithm.Axisymmetric MESH_METHOD.MeshInCenter = 0 MESH_METHOD.SweepNumberDivisions = 24 MESH.GenerateMesh() # Scenario 5 - Define Analysis Settings: Set the auto time stepping to on. Set the initial, minimum and maximum sub-steps. ANSLYSIS_SETTINGS.SetAutomaticTimeStepping(1, AutomaticTimeStepping.On) ANSLYSIS_SETTINGS.DefineBy = TimeStepDefineByType.Substeps ANSLYSIS_SETTINGS.InitialSubsteps = 20 ANSLYSIS_SETTINGS.MinimumSubsteps= 15 ANSLYSIS_SETTINGS.MaximumSubsteps = 50 # Scenario 6 - Insert Thermal loads: Insert and define Convection and Internal Heat Generation loads CONVECTION = STEADY_STATE_THERMAL.AddConvection() CONVECTION.Location = NS_CONVECTION_FACE CONVECTION.FilmCoefficient.Output.DiscreteValues=[Quantity('3.2e-4[W mm^-1 mm^-1 C^-1]'), Quantity('1.04e-4[W mm^-1 mm^-1 C^-1]')] CONVECTION.AmbientTemperature.Output.DiscreteValues=[Quantity('50 [C]'), Quantity('200 [C]')] INTERNAL_HEAT_GENERATION = STEADY_STATE_THERMAL.AddInternalHeatGeneration() INTERNAL_HEAT_GENERATION.Location = NS_ALL_BODIES INTERNAL_HEAT_GENERATION.Magnitude.Output.SetDiscreteValue(0, Quantity(0.001592, "W mm^-1 mm^-1 mm^-1")) # Scenario 7 - Insert Results: Insert a Temperature, Total Heat Flux and Reaction Probe results. TEMPERATURE01 = SOLUTION.AddTemperature() TEMPERATURE01.Location = NS_CONVECTION_FACE TOTAL_HEAT_FLUX01 = SOLUTION.AddTotalHeatFlux() TOTAL_HEAT_FLUX01.Location = NS_CONVECTION_FACE TEMPERATURE02 = SOLUTION.AddTemperature() TEMPERATURE02.Location = NS_RESULTS TOTAL_HEAT_FLUX02 = SOLUTION.AddTotalHeatFlux() TOTAL_HEAT_FLUX02.Location = NS_RESULTS REACTION_PROBE = SOLUTION.AddReactionProbe() REACTION_PROBE.BoundaryConditionSelection = CONVECTION # Scenario 8 - Solve and Define the Results: Solve the system and set the results variables. Note the Scripting window returns the value of any of the variables stored. SOLUTION.Solve(True) TEMPERATURE01_MAX = TEMPERATURE01.Maximum.Value TEMPERATURE02_MAX = TEMPERATURE02.Maximum.Value TOTAL_HEAT_FLUX01_MAX = TOTAL_HEAT_FLUX01.Maximum.Value TOTAL_HEAT_FLUX02_MAX = TOTAL_HEAT_FLUX02.Maximum.Value REACTION_PROBE = REACTION_PROBE.Heat.Value
Summary
This example demonstrates how scripting in Mechanical can be used to automate your actions.