In this example, using the support files, you perform a Structural Optimization analysis in Mechanical using a sequence of python journal commands that will define and solve the analysis. This analysis uses the Shape Optimization method.
This example begins in the Mechanical application. It requires you to download the following Ansys DesignModeler and python files.
Structural_Optimization_Shape_Optimization.agdb
Structural_Optimization_Shape_Optimization.py
These files are available here.
Procedure
The following procedure assumes you understand how to add a system in Workbench and make changes to system cells and properties as well as saving the support files to a known location.
Add a Static Structural analysis to the Project Schematic. Drag and drop a Structural Optimization system onto the static system as shown.
Right-click the Geometry cell of the static system and select > and select the Structural_Optimization_Shape_Optimization.agdb file.
Right-click the Model cell and select . This action launches the Mechanical application.
In Mechanical, 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 Structural_Optimization_Shape_Optimization.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 Store all main tree nodes as variables GEOMETRY = Model.Geometry MESH = Model.Mesh NAMED_SELECTIONS = Model.NamedSelections CONNECTIONS = Model.Connections COORDINATE_SYSTEMS = Model.CoordinateSystems GLOBAL_COORDINATE_SYSTEM = COORDINATE_SYSTEMS.Children[0] #Scenario 2 Select Unit System ExtAPI.Application.ActiveUnitSystem = MechanicalUnitSystem.StandardMKS #Scenario 3 Store Named selections as variable Body = [i for i in NAMED_SELECTIONS.GetChildren[Ansys.ACT.Automation.Mechanical.NamedSelection](True) if i.Name == 'Body'][0] Fixed_Support = [i for i in NAMED_SELECTIONS.GetChildren[Ansys.ACT.Automation.Mechanical.NamedSelection](True) if i.Name == 'Fixed_Support'][0] Force = [i for i in NAMED_SELECTIONS.GetChildren[Ansys.ACT.Automation.Mechanical.NamedSelection](True) if i.Name == 'Force'][0] Exclusion = [i for i in NAMED_SELECTIONS.GetChildren[Ansys.ACT.Automation.Mechanical.NamedSelection](True) if i.Name == 'Exclusion'][0] #Scenario 4 Add mesh method MESH.ElementSize = Quantity('0.005 [m]') MESH.UseAdaptiveSizing = False MESH_METHOD1 = MESH.AddAutomaticMethod() MESH_METHOD1.Location = Body MESH_METHOD1.Method =MethodType.AllTriAllTet MESH.GenerateMesh() #Scenario 5 Setup Static Structural analysis STATIC_STRUCTURAL = Model.Analyses[0] FIXED_SUPPORT1 = STATIC_STRUCTURAL.AddFixedSupport() FIXED_SUPPORT1.Location = Fixed_Support FORCE1 = STATIC_STRUCTURAL.AddForce() FORCE1.Location = Force FORCE1.DefineBy = LoadDefineBy.Components FORCE1.ZComponent.Output.DiscreteValues = [Quantity("25000 [N]")] SOLUTION1 = STATIC_STRUCTURAL.Solution TOTAL_DEFORMATION = SOLUTION1.AddTotalDeformation() EQUIVALENT_STRESS = SOLUTION1.AddEquivalentStress() #Scenario 6 Setup Topology Opimization analysis TOPOLOGY_OPTIMIZATION = Model.Analyses[1] OPTIMIZATION_REGION1 = TOPOLOGY_OPTIMIZATION.Children[1] OPTIMIZATION_REGION1.ExclusionRegionLocation = Exclusion OPTIMIZATION_REGION1.OptimizationType = OptimizationType.Shape OPTIMIZATION_REGION1.ShapeMoveLimitControl = TopoPropertyControlType.ProgramControlled OPTIMIZATION_REGION1.MaxCumulatedDisplacementControl = TopoPropertyControlType.ProgramControlled OPTIMIZATION_REGION1.MeshDeformationToleranceControl = TopoPropertyControlType.ProgramControlled # Objective - Minimize Volume OBJECTIVE = TOPOLOGY_OPTIMIZATION.GetChildren(DataModelObjectCategory.Objective, True) OBJECTIVE[0].Activate() OBJECTIVE[0].Worksheet.SetObjectiveType(0,ObjectiveType.MinimizeVolume) # Mass Constraint RESPONSE_CONSTRAINT1 = TOPOLOGY_OPTIMIZATION.Children[3] RESPONSE_CONSTRAINT1.Suppressed = True # Insert Compliance Constraint RESPONSE_CONSTRAINT2 = TOPOLOGY_OPTIMIZATION.AddComplianceConstraint() RESPONSE_CONSTRAINT2.ComplianceLimit.Output.DiscreteValues=[Quantity ("0.27 [J]")] # Get Tracker and Result SOLUTION2 = TOPOLOGY_OPTIMIZATION.Solution SOLUTION_INFORMATION2 = SOLUTION2.SolutionInformation TOPOLOGY_DENSITY_TRACKER1 = SOLUTION_INFORMATION2.Children[0] TOPOLOGY_DENSITY1 = SOLUTION2.Children[1] #Scenario 7 Solve and Review Results SOLUTION2.Solve(True) TOPO_DENS1_OV = TOPOLOGY_DENSITY1.OriginalVolume.Value TOPO_DENS1_FV = TOPOLOGY_DENSITY1.FinalVolume.Value TOPO_DENS1_PVO = TOPOLOGY_DENSITY1.PercentVolumeOfOriginal TOPO_DENS1_OM = TOPOLOGY_DENSITY1.OriginalMass.Value TOPO_DENS1_FM = TOPOLOGY_DENSITY1.FinalMass.Value TOPO_DENS1_PMO = TOPOLOGY_DENSITY1.PercentMassOfOriginal
Summary
This example demonstrates how scripting in Mechanical can be used to automate your actions.