Set Up, Solve, and Post-Process a Structural Study Using AIM

This example demonstrates a basic structural study using scripting in ANSYS AIM. After you extract the ScriptingGuideExamples.zip file, you will find the files for this example in the AIM_Structural_Study directory.

ANSYS AIM Script The script for this example follows.

1  	# encoding: utf-8
2  	SetScriptVersion(Version="16.0")
3  	Reset()
4  
5  	# Define working directory 
6  	workingDir = r"D:\ScriptingGuideExamples\AIM_Structural_Study\"
7  	CADFile = "gearcasing.agdb"
8  	projectName = "sce-4-mech.wbpj"
9  
10 	import os
11 	fullPath = os.path.join(workingDir, CADFile)
12 	savePath = os.path.join(workingDir, projectName)
13 
14 	with Transaction():
15 	    # Define Study system and access the container
16 	    system1 = GetSystem(Name="Study")
17 	    study1 = system1.GetContainer(ComponentName="Study")
18 
19 	    # Define the Tasks and Groups
20 	    importComponent1 = Study.CreateTask(Type="Import", System=system1)
21 	    meshingComponent1 = Study.CreateTask(Type="Meshing", System=system1)
22 
23 	    physicsDefinitionComponent1 = Study.CreateTask(Type="Physics Definition",System=system1)
24 	    solvePhysicsComponent1 = Study.CreateTask(Type="Solve Physics",System=system1)
25 	    # physicsDefinitionComponent1 and solvePhysicsComponent1 will be grouped together
26 
27 	    physicsSolutionGroup1 = Study.CreateGroup(Name="Physics Solution")
28 	    physicsSolutionGroup1.Add(Component=physicsDefinitionComponent1)
29 	    physicsSolutionGroup1.Add(Component=solvePhysicsComponent1)
30 	    
31 	    resultsEvaluationComponent1 = Study.CreateTask(Type="Results Evaluation", System=system1)
32 
33 	    # Define the Import 
34 	    import1 = importComponent1.GetTaskObject()
35 
36 	    # Define the Part Meshing properties
37 	    partMesh1 = meshingComponent1.GetTaskObject()
38 	    partMesh1.EngineeringIntent = "StructuralOrThermalOrElectricConduction"
39 	    partMesh1.GlobalMeshSizingAttributes.UseAdvancedSizeFunction = "Adaptive"
40 
41 	    # Define the Solution properties
42 	    physicsDefinition1 = physicsDefinitionComponent1.GetTaskObject()
43 	    physicsDefinition1.CalculationType = "Static"
44 
45 	    # Define PhysicsRegion, SolverSettings, Material
46 	    physicsRegion1 = study1.CreateEntity(Type="PhysicsRegion",AssociatedObject=physicsDefinition1)
47 	    physicsRegion1.PhysicsType = "Structural"
48 	    physicsRegion1.Location = "AllBodies()"
49 
50 	    solverSettings1 = study1.CreateEntity(Type="SolverSettings",AssociatedObject=physicsDefinition1)
51 
52 	    material1 = study1.CreateEntity(Type="Material", AssociatedObject=physicsDefinition1)
53 	    material1.ImportEngineeringData(Name="Structural Steel")
54 
55 	    materialAssignment1 = study1.CreateEntity(Type="MaterialAssignment",AssociatedObject=physicsDefinition1)
56 	    materialAssignment1.Material = material1
57 	    materialAssignment1.Location = [physicsRegion1]
58 
59 	    # Define upstream-downstream links between the tasks
60 	    AddSourceToComponentInSystem(SourceComponent=importComponent1, TargetComponent=meshingComponent1)
61 	    AddSourceToComponentInSystem(SourceComponent=meshingComponent1, TargetComponent=physicsDefinitionComponent1)
62 	    AddSourceToComponentInSystem(SourceComponent=physicsDefinitionComponent1, TargetComponent=solvePhysicsComponent1)
63 	    AddSourceToComponentInSystem(SourceComponent=solvePhysicsComponent1, TargetComponent=resultsEvaluationComponent1)
64 
65 	    # Add a Transcript tab
66 	    transcript1 = study1.CreateEntity(Type="Transcript", AssociatedObject=physicsDefinition1)
67 
68 	    # Define Results
69 	    results1 = resultsEvaluationComponent1.GetTaskObject()
70 
71 	with Transaction():
72 	    # Import the CAD 
73 	    Study.AddGeometryImportSourceOperation(ObjectReference=import1)
74 	    geometryImportSource1 = study1.GetGeometryImportSource(Name="GeometryImportSource 1")
75 	    geometryImportSource1.FilePath = fullPath
76 	    geometryImportSource1.GeometryPreferences.ImportNamedSelections = "True"
77 	    geometryImportSource1.GeometryPreferences.NamedSelectionKey = ""
78 	    
79 	    importComponent1.Update(AllDependencies=True)
80 
81 	# Refresh other cells
82 	meshingComponent1.Refresh()
83 	physicsDefinitionComponent1.Refresh()
84 	resultsEvaluationComponent1.Refresh()
85 
86 	# Define Boundary Conditions
87 	with Transaction():
88 	    support1 = study1.CreateEntity(Type="Support", AssociatedObject=physicsRegion1)
89 	    support1.Location = 'GetSelectionSet("@side1")'
90 	    
91 	with Transaction():
92 	    pressure1 = study1.CreateEntity(Type="Pressure", AssociatedObject=physicsRegion1)
93 	    pressure1.Location =  'GetSelectionSet("@side2")'
94 	    pressure1.Magnitude = "1.0E7 [Pa]"
95 	    # Define this as a input Parameter
96 	    parameter1 = Parameters.CreateParameter(Entity=pressure1, PropertyName="Magnitude", IsOutput=False)
97 	    parameter1.Expression = str(pressure1.Magnitude)
98 	    parameter1.DisplayText="Pressure1"
99 
100	# Add post-processing contours
101	with Transaction():
102	    contourResult1 = study1.CreateEntity(Type="ContourResult", AssociatedObject=results1)
103	    contourResult1.Variable = "Displacement.mag"
104	    contourResult1.Location = "AllBodies()"
105	    contourResult1.DisplayText = "Total Deformation"
106	    # Define this as a output Parameter
107	    parameter2 = Parameters.CreateParameter(Entity=contourResult1, PropertyName="Summary.Max", IsOutput=True, IsDirectOutput=True)
108	    parameter2.DisplayText="Maximum Deformation"
109
110	with Transaction():
111	    contourResult2 = study1.CreateEntity(Type="ContourResult", AssociatedObject=results1)
112	    contourResult2.Variable = "Stress.eqv"
113	    contourResult2.Location = "AllBodies()"
114	    contourResult2.DisplayText = "Eqv Stress"
115
116	with Transaction():
117	    vectorResult1 = study1.CreateEntity(Type="VectorResult", AssociatedObject=results1)
118	    vectorResult1.Variable = "Displacement"
119	    vectorResult1.Location = "AllBodies()"
120
121	# Generate the Mesh
122	meshingComponent1.Update(AllDependencies=True)
123
124	# Perform the Simulation
125	# Perform the Simulation
126	with Transaction():
127	    physicsDefinitionComponent1.Update(AllDependencies=True)
128	    solvePhysicsComponent1.Update(AllDependencies=True)
129	    
130	# Update the Results
131	resultsEvaluationComponent1.Update(AllDependencies=True)
132
133	# Save project to working directory
134	Save(FilePath=savePath, Overwrite=True)
135
136	# Exit from Workbench AIM
137

Discussion A description of each line follows.

Line 3

Reset() command starts a new session.

Line 6

The working directory is set, so that the script can load the geometry file from the specified location. When completing this example, this line will need to be modified to reflect your working location.

Line 10-12

The 'os' module used in this script provides capabilities for interacting with operating system services. Refer to the Python Standard Library documentation for details on all available modules.

Lines 14-69

This part defines a basic Static Structural analysis template. All the different tasks (e.g., geometry import, mesh generation, solution and results) are created and populated.

Lines 19-34

Different tasks (e.g., geometry import, mesh generation, solution, and results) are created.

Lines 36-39

Define some global properties for the mesh generation.

Lines 45-57

Define PhysicsRegion, SolverSettings, and Material for the solution.

Lines 59-63

Define links between the tasks, i.e., meshing task takes the geometry from the import task as input; solution task takes the mesh generated from the meshing task, etc.

Lines 65-66

Add a Transcript tab so that solver output information can be monitored.

Lines 71-84

The geometry file is imported (along all NamedSelections) and other tasks are refreshed as their upstream data is updated.

Lines 88-89

Define a fixed support boundary condition on "side1" Named Selection.

Lines 91-98

Define a 1.0E7 Pa pressure load "side2" Named Selection and make it an input parameter, named "Pressure1".

Lines 101-105

Create a displacement magnitude contours on all bodies.

Lines 107-108

Make the maximum displacement magnitude as a output parameter, named "Maximum Deformation".

Lines 110-119

Create more contour and vector results.

Line 122

Generate the mesh.

Line 126-128

Perform the simulation.

Line 131

Evaluate all of the results.

Line 133

Save the project files.


Release 18.2 - © ANSYS, Inc. All rights reserved.