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 Lattice Optimization method.
This example begins in the Mechanical application. It requires you to download the following Ansys DesignModeler and python files.
Structural_Optimization_Lattice.agdb
Structural_Optimization_Lattice.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_Lattice.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_Lattice.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] Pressure = [i for i in NAMED_SELECTIONS.GetChildren[Ansys.ACT.Automation.Mechanical.NamedSelection](True) if i.Name == 'Pressure'][0] Internal_Faces = [i for i in NAMED_SELECTIONS.GetChildren[Ansys.ACT.Automation.Mechanical.NamedSelection](True) if i.Name == 'Internal_Faces'][0] Top_Face = [i for i in NAMED_SELECTIONS.GetChildren[Ansys.ACT.Automation.Mechanical.NamedSelection](True) if i.Name == 'Top_Face'][0] #Scenario 4 Add mesh method FACE_SIZING = MESH.AddSizing() FACE_SIZING.Location = Top_Face FACE_SIZING.ElementSize = Quantity('0.01524 [m]') MESH_METHOD1 = MESH.AddAutomaticMethod() MESH_METHOD1.Location = Body MESH_METHOD1.Method =MethodType.MultiZone MESH.GenerateMesh() COORDINATE_SYSTEM1 = COORDINATE_SYSTEMS.AddCoordinateSystem() COORDINATE_SYSTEM1.OriginLocation = Internal_Faces #Scenario 5 Setup Static Structural analysis STATIC_STRUCTURAL = Model.Analyses[0] FIXED_SUPPORT1 = STATIC_STRUCTURAL.AddFixedSupport() FIXED_SUPPORT1.Location = Fixed_Support PRESSURE1 = STATIC_STRUCTURAL.AddPressure() PRESSURE1.Location = Pressure PRESSURE1.Magnitude.Output.DiscreteValues = [Quantity("50 [Pa]")] 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.BoundaryCondition = BoundaryConditionType.AllLoadsAndSupports OPTIMIZATION_REGION1.OptimizationType = OptimizationType.Lattice OPTIMIZATION_REGION1.LatticeType = LatticeType.Cubic OPTIMIZATION_REGION1.LatticeMinDensity = 0.3 OPTIMIZATION_REGION1.LatticeMaxDensity = 0.8 OPTIMIZATION_REGION1.LatticeSize = Quantity("0.06 [m]") # Mass Constraint RESPONSE_CONSTRAINT1 = TOPOLOGY_OPTIMIZATION.Children[3] RESPONSE_CONSTRAINT1.DefineBy = ResponseConstraintDefineBy.Range RESPONSE_CONSTRAINT1.PercentageToRetainMin = 30 RESPONSE_CONSTRAINT1.PercentageToRetainMax = 35 # Insert Symmetry Constraint MANUFACTURING_CONSTRAINT1 = TOPOLOGY_OPTIMIZATION.AddSymmetryManufacturingConstraint() MANUFACTURING_CONSTRAINT1.Location = Body MANUFACTURING_CONSTRAINT1.CoordinateSystem = COORDINATE_SYSTEM1 MANUFACTURING_CONSTRAINT1.Axis = CoordinateSystemAxisType.PositiveZAxis # Insert Global von-Mises Stress Constraint RESPONSE_CONSTRAINT2 = TOPOLOGY_OPTIMIZATION.AddGlobalVonMisesStressConstraint() RESPONSE_CONSTRAINT2.Maximum.Output.DiscreteValues=[Quantity ("150 [Pa]")] # Insert Moment of Inertia Constraint RESPONSE_CONSTRAINT3 = TOPOLOGY_OPTIMIZATION.AddMomentOfInertiaConstraint() RESPONSE_CONSTRAINT3.PercentageToRetainMin = 40 RESPONSE_CONSTRAINT3.PercentageToRetainMax = 50 # Get Tracker and Result SOLUTION2 = TOPOLOGY_OPTIMIZATION.Solution SOLUTION_INFORMATION2 = SOLUTION2.SolutionInformation LATTICE_DENSITY_TRACKER1 = SOLUTION_INFORMATION2.Children[0] LATTICE_DENSITY1 = SOLUTION2.Children[1] #Scenario 7 Solve and Review Results SOLUTION2.Solve(True) LATTICE_DENS1_OV = LATTICE_DENSITY1.OriginalVolume.Value LATTICE_DENS1_FV = LATTICE_DENSITY1.FinalVolume.Value LATTICE_DENS1_PVO = LATTICE_DENSITY1.PercentVolumeOfOriginal LATTICE_DENS1_OM = LATTICE_DENSITY1.OriginalMass.Value LATTICE_DENS1_FM = LATTICE_DENSITY1.FinalMass.Value LATTICE_DENS1_PMO = LATTICE_DENSITY1.PercentMassOfOriginal
Summary
This example demonstrates how scripting in Mechanical can be used to automate your actions.