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 Topology Optimization - Density Based method.
This example begins in the Mechanical application. It requires you to download the following Ansys DesignModeler and python files.
Topology_Optimization_Example_001.agdb
Topology_Optimization_Example_001.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 Topology_Optimization_Example_001.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 Topology_Optimization_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:
#Scenario 1 Store all main tree objects 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 variables Body_1 = [i for i in NAMED_SELECTIONS.GetChildren[Ansys.ACT.Automation.Mechanical.NamedSelection](True) if i.Name == 'Body_1'][0] Body_2 = [i for i in NAMED_SELECTIONS.GetChildren[Ansys.ACT.Automation.Mechanical.NamedSelection](True) if i.Name == 'Body_2'][0] Body_3 = [i for i in NAMED_SELECTIONS.GetChildren[Ansys.ACT.Automation.Mechanical.NamedSelection](True) if i.Name == 'Body_3'][0] Body_4 = [i for i in NAMED_SELECTIONS.GetChildren[Ansys.ACT.Automation.Mechanical.NamedSelection](True) if i.Name == 'Body_4'][0] Optimization_Region_1 = [i for i in NAMED_SELECTIONS.GetChildren[Ansys.ACT.Automation.Mechanical.NamedSelection](True) if i.Name == 'Optimization_Region_1'][0] Optimization_Region_2 = [i for i in NAMED_SELECTIONS.GetChildren[Ansys.ACT.Automation.Mechanical.NamedSelection](True) if i.Name == 'Optimization_Region_2'][0] Force_Face = [i for i in NAMED_SELECTIONS.GetChildren[Ansys.ACT.Automation.Mechanical.NamedSelection](True) if i.Name == 'Force_Face'][0] Fixed_Face_1 = [i for i in NAMED_SELECTIONS.GetChildren[Ansys.ACT.Automation.Mechanical.NamedSelection](True) if i.Name == 'Fixed_Face_1'][0] Fixed_Face_2 = [i for i in NAMED_SELECTIONS.GetChildren[Ansys.ACT.Automation.Mechanical.NamedSelection](True) if i.Name == 'Fixed_Face_2'][0] Exclusion_1 = [i for i in NAMED_SELECTIONS.GetChildren[Ansys.ACT.Automation.Mechanical.NamedSelection](True) if i.Name == 'Exclusion_1'][0] Exclusion_2 = [i for i in NAMED_SELECTIONS.GetChildren[Ansys.ACT.Automation.Mechanical.NamedSelection](True) if i.Name == 'Exclusion_2'][0] #Scenario 4 Add mesh method MESH.ElementSize = Quantity('0.005 [m]') MESH_METHOD1 = MESH.AddAutomaticMethod() MESH_METHOD1.Location = Body_1 MESH_METHOD1.Method =MethodType.Sweep MESH_METHOD1.Algorithm = MeshMethodAlgorithm.Axisymmetric #Scenario 5 Add local coordinate systems COORDINATE_SYSTEM1 = COORDINATE_SYSTEMS.AddCoordinateSystem() COORDINATE_SYSTEM1.OriginLocation = Body_2 COORDINATE_SYSTEM2 = COORDINATE_SYSTEMS.AddCoordinateSystem() COORDINATE_SYSTEM2.OriginLocation = Body_4 #Scenario 6 Setup Static Structural analysis STATIC_STRUCTURAL = Model.Analyses[0] FIXED_SUPPORT1 = STATIC_STRUCTURAL.AddFixedSupport() FIXED_SUPPORT1.Location = Fixed_Face_1 FIXED_SUPPORT2 = STATIC_STRUCTURAL.AddFixedSupport() FIXED_SUPPORT2.Location = Fixed_Face_2 FORCE1 = STATIC_STRUCTURAL.AddForce() FORCE1.Location = Force_Face FORCE1.DefineBy = LoadDefineBy.Components FORCE1.YComponent.Output.DiscreteValues = [Quantity("5000 [N]")] FORCE1.ZComponent.Output.DiscreteValues = [Quantity("1000 [N]")] SOLUTION1 = STATIC_STRUCTURAL.Solution TOTAL_DEFORMATION = SOLUTION1.AddTotalDeformation() EQUIVALENT_STRESS = SOLUTION1.AddEquivalentStress() #Scenario 7 Setup Topology Optimization analysis TOPOLOGY_OPTIMIZATION = Model.Analyses[1] OPTIMIZATION_REGION1 = TOPOLOGY_OPTIMIZATION.Children[1] OPTIMIZATION_REGION1.DesignRegionLocation = Optimization_Region_1 OPTIMIZATION_REGION1.BoundaryCondition = BoundaryConditionType.AllLoadsAndSupports OPTIMIZATION_REGION1.OptimizationType = OptimizationType.TopologyDensity # Insert Exclusion Region 1 EXCLUSION_REGION1 = OPTIMIZATION_REGION1.AddExclusionRegion() EXCLUSION_REGION1.ExclusionRegionLocation = Exclusion_1 # Insert Optimization Region 2 OPTIMIZATION_REGION2 = TOPOLOGY_OPTIMIZATION.AddOptimizationRegion() OPTIMIZATION_REGION2.DesignRegionLocation = Optimization_Region_2 OPTIMIZATION_REGION2.BoundaryCondition = BoundaryConditionType.AllLoadsAndSupports OPTIMIZATION_REGION2.OptimizationType = OptimizationType.TopologyDensity # Insert Exclusion Region 2 EXCLUSION_REGION2 = OPTIMIZATION_REGION2.AddExclusionRegion() EXCLUSION_REGION2.ExclusionRegionLocation = Exclusion_2 # Mass Constraint RESPONSE_CONSTRAINT1 = TOPOLOGY_OPTIMIZATION.Children[4] RESPONSE_CONSTRAINT1.Location = OPTIMIZATION_REGION1 RESPONSE_CONSTRAINT1.PercentageToRetain = 40 # Insert Volume Constraint RESPONSE_CONSTRAINT2 = TOPOLOGY_OPTIMIZATION.AddVolumeConstraint() RESPONSE_CONSTRAINT2.Location = OPTIMIZATION_REGION2 RESPONSE_CONSTRAINT2.DefineBy = ResponseConstraintDefineBy.Range RESPONSE_CONSTRAINT2.PercentageToRetainMin = 40 RESPONSE_CONSTRAINT2.PercentageToRetainMax = 50 # Insert Member Size Constraint MANUFACTURING_CONSTRAINT1 = TOPOLOGY_OPTIMIZATION.AddMemberSizeManufacturingConstraint() MANUFACTURING_CONSTRAINT1.Location = OPTIMIZATION_REGION1 MANUFACTURING_CONSTRAINT1.Minimum = ManuMemberSizeControlledType.Manual MANUFACTURING_CONSTRAINT1.MinSize = Quantity('0.0125 [m]') # Insert Symmetry Constraints MANUFACTURING_CONSTRAINT2 = TOPOLOGY_OPTIMIZATION.AddSymmetryManufacturingConstraint() MANUFACTURING_CONSTRAINT2.Location = Body_2 MANUFACTURING_CONSTRAINT2.CoordinateSystem = COORDINATE_SYSTEM1 MANUFACTURING_CONSTRAINT2.Axis = CoordinateSystemAxisType.PositiveYAxis MANUFACTURING_CONSTRAINT3 = TOPOLOGY_OPTIMIZATION.AddSymmetryManufacturingConstraint() MANUFACTURING_CONSTRAINT3.Location = Body_2 MANUFACTURING_CONSTRAINT3.CoordinateSystem = COORDINATE_SYSTEM1 MANUFACTURING_CONSTRAINT3.Axis = CoordinateSystemAxisType.PositiveZAxis MANUFACTURING_CONSTRAINT4 = TOPOLOGY_OPTIMIZATION.AddSymmetryManufacturingConstraint() MANUFACTURING_CONSTRAINT4.Location = Body_3 MANUFACTURING_CONSTRAINT4.CoordinateSystem = GLOBAL_COORDINATE_SYSTEM MANUFACTURING_CONSTRAINT4.Axis = CoordinateSystemAxisType.PositiveZAxis MANUFACTURING_CONSTRAINT5 = TOPOLOGY_OPTIMIZATION.AddSymmetryManufacturingConstraint() MANUFACTURING_CONSTRAINT5.Location = Body_3 MANUFACTURING_CONSTRAINT5.CoordinateSystem = GLOBAL_COORDINATE_SYSTEM MANUFACTURING_CONSTRAINT5.Axis = CoordinateSystemAxisType.PositiveYAxis MANUFACTURING_CONSTRAINT6 = TOPOLOGY_OPTIMIZATION.AddSymmetryManufacturingConstraint() MANUFACTURING_CONSTRAINT6.Location = Body_4 MANUFACTURING_CONSTRAINT6.CoordinateSystem = COORDINATE_SYSTEM2 MANUFACTURING_CONSTRAINT6.Axis = CoordinateSystemAxisType.PositiveXAxis MANUFACTURING_CONSTRAINT7 = TOPOLOGY_OPTIMIZATION.AddSymmetryManufacturingConstraint() MANUFACTURING_CONSTRAINT7.Location = Body_4 MANUFACTURING_CONSTRAINT7.CoordinateSystem = COORDINATE_SYSTEM2 MANUFACTURING_CONSTRAINT7.Axis = CoordinateSystemAxisType.PositiveZAxis # Insert Cyclic Constraints MANUFACTURING_CONSTRAINT8 = TOPOLOGY_OPTIMIZATION.AddCyclicManufacturingConstraint() MANUFACTURING_CONSTRAINT8.Location = OPTIMIZATION_REGION1 MANUFACTURING_CONSTRAINT8.NumberofSectors = 4 MANUFACTURING_CONSTRAINT8.CoordinateSystem = GLOBAL_COORDINATE_SYSTEM MANUFACTURING_CONSTRAINT8.Axis = CoordinateSystemAxisType.PositiveZAxis # Get Tracker and Result SOLUTION2 = TOPOLOGY_OPTIMIZATION.Solution SOLUTION_INFORMATION2 = SOLUTION2.SolutionInformation TOPOLOGY_DENSITY_TRACKER1 = SOLUTION_INFORMATION2.Children[0] TOPOLOGY_DENSITY_TRACKER1.ScopingMethod = GeometryDefineByType.AllOptimizationRegions TOPOLOGY_DENSITY1 = SOLUTION2.Children[1] TOPOLOGY_DENSITY1.ScopingMethod = GeometryDefineByType.AllOptimizationRegions # Insert Smoothing SMOOTHING1 = TOPOLOGY_DENSITY1.AddSmoothing() #Scenario 8 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.