-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathansys_script.lgw
190 lines (144 loc) · 3.76 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
! 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
/input,menust,tmp,''
WPSTYLE,,,,,,,,0
! Disable "Solution is done" popup window.
KEYW,pr_sgui,1
! Define either 2 (2D analysis) or 3 (3D analysis).
dimensions = 2
! Define constants.
load = 500
*DO, angle, 0, 90, 5
*DO, length, 0.8, 3.2, 0.2
*DO, height, 0.4, 1.6, 0.2
*DO, position, 0.2, 1.0, 0.2
! Save parameters defined in this script so far so that they can be accessed after calling /CLEAR.
PARSAV, ALL
/NOPR
KEYW,PR_SET,1
KEYW,PR_STRUC,1
KEYW,PR_THERM,0
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
! Disable popups.
/UIS,MSGPOP,4
! Enter the model creation preprocessor.
/PREP7
! Create the model.
*IF,dimensions,EQ,2,THEN
! Create area if 2D.
BLC4,0,0,length,height,0
*ELSE
! Create volume if 3D.
BLC4,0,0,length,height,width
*ENDIF
! Define element type.
*IF,dimensions,EQ,2,THEN
ET,1,PLANE182
KEYOPT,1,1,0
KEYOPT,1,3,3
KEYOPT,1,6,0
! Define the element thickness.
R,1,1,
*ELSE
ET,1,SOLID185
KEYOPT,1,2,0
KEYOPT,1,3,0
KEYOPT,1,6,0
KEYOPT,1,8,0
*ENDIF
! Define material properties.
MPTEMP,,,,,,,,
MPTEMP,1,0
MPDATA,EX,1,,1e9
MPDATA,PRXY,1,,0.3
! Define the number of elements along each dimension and create the mesh.
*IF,dimensions,EQ,2,THEN
! X lines have line numbers: 1, 3.
LSEL,S,LINE,,1,3,2,0
LESIZE,ALL, , ,length/0.1-1, , , , ,1
! Y lines have line numbers: 2, 4.
LSEL,S,LINE,,2,4,2,0
LESIZE,ALL, , ,height/0.1-1, , , , ,1
! Create the mesh.
MSHAPE,0,2D
MSHKEY,0
AMESH,1
*ELSE
! X lines have line numbers: 2, 4, 5, 7.
LSEL,S,LINE,,2,4,2,0
LSEL,A,LINE,,5,7,2,0
LESIZE,ALL, , ,nodes_x-1, , , , ,1
! Y lines have line numbers: 1, 3, 6, 8.
LSEL,S,LINE,,1,3,2,0
LSEL,A,LINE,,6,8,2,0
LESIZE,ALL, , ,nodes_y-1, , , , ,1
! Z lines have line numbers: 9, 10, 11, 12.
LSEL,S,LINE,,9,12,1,0
LESIZE,ALL, , ,nodes_z-1, , , , ,1
! Create the mesh.
MSHAPE,0,3D
MSHKEY,1
VMESH,1
*ENDIF
! Specify the displacement boundary conditions and the X and Y components of the load.
*IF,dimensions,EQ,2,THEN
DL, 4, , ALL, 0
! Define trigonometric functions to use degrees.
*AFUN, DEG
! Calculate x- and y-components of the load.
load_x = COS(angle)*load
load_y = SIN(angle)*load
! Select the node closest to the desired load position.
mesh_size_x = length/(length/0.1-1)
mesh_size_y = height/(height/0.1-1)
tolerance_x = 0.9*(mesh_size_x/2)
tolerance_y = 0.9*(mesh_size_y/2)
NSEL, S, LOC, X, (position*length)-tolerance_x, (position*length)+tolerance_x
NSEL, R, LOC, Y, 0-tolerance_y, 0+tolerance_y
F, ALL, FX, load_x
F, ALL, FY, load_y
*ELSE
DA,5,ALL,0
ASEL,S,AREA,,6
NSLA,S,0
F,ALL,FX,load_x_3d/((nodes_y-2)*(nodes_z-2))
F,ALL,FY,load_y_3d/((nodes_y-2)*(nodes_z-2))
F,ALL,FZ,load_z_3d/((nodes_y-2)*(nodes_z-2))
*ENDIF
! Select all nodes again, which is required for solving.
ALLSEL
FINISH
! Solve.
/SOL
SOLVE
FINISH
! Enter the database results postprocessor.
/POST1
SET,FIRST
! Get nodal results as an array.
*VGET,stress,NODE,,S,EQV
! Get the node coordinates as arrays, used for sorting nodes.
*VGET,location_x,NODE,,LOC,X
*VGET,location_y,NODE,,LOC,Y
*VGET,location_z,NODE,,LOC,Z
! Write the results to a file.
filename = 'stress_%angle%_%length%_%height%_%position%'
*CFOPEN, filename, 'txt'
*VWRITE, stress(1), location_x(1), location_y(1), location_z(1)
(E10.4, ',', F6.3, ',', F6.3, ',', F6.3)
*CFCLOS
/CLEAR
# Restore parameters previously saved after calling /CLEAR.
PARRES
*ENDDO
*ENDDO
*ENDDO
*ENDDO