-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathansys_script.lgw
230 lines (195 loc) · 5.88 KB
/
ansys_script.lgw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
! Run simulations in a for loop.
! Perform a thermal simulation followed by a structural simulation in each loop.
! When performing multiplication operations in this script using the * operator, there should not be spaces on either side of *. For example, use `1*2` instead of `1 * 2`.
/CLEAR
/BATCH
! Disable "Solution is done" popup window.
KEYW,pr_sgui,1
! Disable popups.
/UIS,MSGPOP,4
! Set lengths to mm.
/UNITS, USER, LENFACTOR, 1/1000
! Geometric constants.
height = 20
thickness_z = 1
! Mesh settings.
mesh_divisions_horizontal = 32-1
mesh_divisions_vertical = 8-1
! Material property constants.
thermal_conductivity = 400
specific_heat = 300
mass_density = 10
elastic_modulus = 100e9
poissons_ratio = 0.3
! Simulation settings.
initial_temperature = 22+273.15
temperature_left = 100+273.15
convection_bulk_temperature = 22+273.15
coefficient_thermal_expansion = 16e-9
duration = 100
steps = 10
! For loop over each simulation parameter, with parameters defined as: start, end, increment.
*DO, thickness, 5, 10, 1
*DO, taper_ratio, 0.1, 1.0, 0.1
*DO, convection_coefficient, 10, 100, 10
*DO, temperature_left, 30+273.15, 100+273.15, 10
! Save parameters defined in this script so far so that they can be accessed after calling /CLEAR.
PARSAV, ALL
! Convert parameters to strings to use for output file names.
thickness_string = CHRVAL(thickness)
thickness_string = STRFILL('00', thickness_string, 3-STRLENG(thickness_string))
taper_ratio_string = CHRVAL(taper_ratio)
convection_coefficient_string = CHRVAL(convection_coefficient)
convection_coefficient_string = STRFILL('000', convection_coefficient_string, 4-STRLENG(convection_coefficient_string))
temperature_left_string = CHRVAL(temperature_left)
/NOPR
KEYW,PR_SET,1
KEYW,PR_STRUC,0
KEYW,PR_THERM,1
KEYW,PR_FLUID,0
KEYW,PR_ELMAG,0
KEYW,MAGNOD,0
KEYW,MAGEDG,0
KEYW,MAGHFE,0
KEYW,MAGELC,0
KEYW,PR_MULTI,0
/GO
! Enter the model creation preprocessor.
/PREP7
! Create the four points of the geometry.
spacing = thickness*(1-taper_ratio)/2
K, 1, 0, 0, 0
K, 2, height, 0 + spacing, 0
K, 3, height, thickness - spacing, 0
K, 4, 0, thickness, 0
! Create the four lines that form the boundary of the geometry.
L, 1, 2
L, 2, 3
L, 3, 4
L, 4, 1
! Create the area using the four lines.
AL, 1, 2, 3, 4
! Define element type.
ET, 1, PLANE55
! Specify plane thickness behavior.
KEYOPT, 1, 3, 3
! Define the thickness.
R, 1, thickness_z
! Define material properties.
MPTEMP,,,,,,,,
MPTEMP,1,0
MPDATA,KXX,1,,thermal_conductivity
MPTEMP,,,,,,,,
MPTEMP,1,0
MPDATA,C,1,,specific_heat
MPTEMP,,,,,,,,
MPTEMP,1,0
MPDATA,ALPX,1,,coefficient_thermal_expansion
MPTEMP,,,,,,,,
MPTEMP,1,0
MPDATA,DENS,1,,mass_density
MPTEMP,,,,,,,,
MPTEMP,1,0
MPDATA,EX,1,,elastic_modulus
MPTEMP,,,,,,,,
MPTEMP,1,0
MPDATA,PRXY,1,,poissons_ratio
! Define the number of elements along each dimension and create the mesh.
! Horizontal lines have line numbers 1, 3.
LSEL, S, LINE, , 1, 3, 2, 0
LESIZE, ALL, , , mesh_divisions_horizontal, , , , , 1
! Vertical lines have line numbers 2, 4.
LSEL, S, LINE, , 2, 4, 2, 0
LESIZE, ALL, , , mesh_divisions_vertical, , , , , 1
! Create the mesh.
MSHAPE, 0, 2D
MSHKEY, 0
AMESH, 1
! Specify the initial temperature on all nodes.
ALLSEL, ALL, NODE
IC, ALL, TEMP, initial_temperature
! Specify the temperature boundary condition on the left edge.
DL, 4, , TEMP, temperature_left
! Specify a convection boundary condition.
LSEL, S, , , 1, 3, 1, 0
SFL, ALL, CONV, convection_coefficient, , convection_bulk_temperature
! Specify a reference temperature used for thermal strain calculations.
TREF, initial_temperature
! Specify the displacement boundary conditions.
DL, 4, ALL, UX, 0
DL, 4, ALL, UY, 0
DL, 4, ALL, UZ, 0
! Select all nodes again, which is required for solving.
ALLSEL
FINISH
! Enter the solution processor.
/SOL
! Define a transient analysis.
ANTYPE, TRANS
! Specify stepped loading instead of ramped loading (default).
KBC, 1
! Turn auto-time-stepping off.
AUTOTS, OFF
! Specify the end time of the current load step.
TIME, duration
! Specify the number of substeps. Alternatively, specify the time step using DELTIM.
NSUBST, steps, steps, steps
! Write results for every time step, instead of only the last one (default).
OUTRES, ALL, ALL
! Start the simulation.
SOLVE
FINISH
! Enter the database results postprocessor.
/POST1
! Loop over the data for each time step.
*DO, t, 1, steps, 1
! Specify the time step to read.
SET, 1, t
! Get nodal temperatures.
*VGET, temperature, NODE, , TEMP
! Get nodal thermal gradients.
*VGET, thermal_gradient, NODE, , TG, SUM
! Get nodal coordinates.
*VGET, location_x, NODE, , LOC, X
*VGET, location_y, NODE, , LOC, Y
! Create the file name.
t_string = CHRVAL(t)
t_string = STRFILL('00', t_string, 3-STRLENG(t_string))
filename = 'thermal_%thickness_string%_%taper_ratio_string%_%convection_coefficient_string%_%temperature_left_string%_%t_string%'
! Save the results to a file.
*CFOPEN, filename, 'txt'
*VWRITE, temperature(1), thermal_gradient(1), location_x(1), location_y(1)
(E9.4, ',', E9.4, ',', F7.4, ',', F7.4)
*CFCLOS
*ENDDO
! Switch to structural analysis.
/PREP7
ETCHG, TTS
! Read temperature data from the thermal simulation. The file extension rth must be specified, which represents the results of a thermal simulation.
LDREAD, TEMP, LAST, , , , , rth
! Start the simulation.
/SOL
SOLVE
FINISH
! Enter the database results postprocessor.
/POST1
SET, LAST
! Get nodal von Mises stresses.
*VGET, stress, NODE, , S, EQV
! Get nodal coordinates.
*VGET, location_x, NODE, , LOC, X
*VGET, location_y, NODE, , LOC, Y
! Create the file name.
filename = 'structural_%thickness_string%_%taper_ratio_string%_%convection_coefficient_string%_%temperature_left_string%'
! Save the results to a file.
*CFOPEN, filename, 'txt'
*VWRITE, stress(1), location_x(1), location_y(1)
(E9.4, ',', F7.4, ',', F7.4)
*CFCLOS
/CLEAR
# Restore parameters previously saved after calling /CLEAR.
PARRES
*ENDDO
*ENDDO
*ENDDO
*ENDDO