forked from bguest/ansys-macros
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NPRES2.mac
241 lines (215 loc) · 6.72 KB
/
NPRES2.mac
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
231
232
233
234
235
236
237
238
239
240
!&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
!NPRES2.MAC
!DESCRIPTION: This macro creates a traction
! distribution on A solid meshed either with SOLID92
! elements or SOLID186 elements.
!PRECONDITIONS:
! Required Inputs:
! -PressureSpaceFunction
! ARGUMENTS:
! ARG1 = Area to apply force to or <0 for ALL
! ELSE, User prompted to select Areas
! ARG2 = Number of Node of surface element
! IE: 3 -> Tri, 4 -> Quad, 6 -> Quadradic Tri
! 8 -> Quadradic Quad
! ARG3 = LOADCASE of PressureSpaceFunction.mac
! Other:
! -Surface mesh is uniform, IE not a mix of quads
! and tri elements
!NOTES: WILL NOT WORK WITH SHELL ELEMENTS (USE NPRES)
!&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
CM,temp_VOLU,VOLU
CM,temp_AREA,AREA
CM,temp_LINE,LINE
CM,temp_KP,KP
CM,temp_NODE,NODE
CM,temp_ELEM,ELEM
!GET NUMBER OF NODES per surface element
*IF,ARG2,EQ,0,THEN !PROMPT USER
*ASK,ans,Enter Number of Nodes Per Surface Element,0
*IF,ans,EQ,0,THEN
*GO,:END
*ELSE
ARG2=ans
*ENDIF
*ENDIF
!Create Temp Shell Properties
/PREP7
MatNum = 999
*IF,ARG2,EQ,6,OR,ARG2,EQ,8,THEN
!8-Node Structural Shell
ET,MatNum,SHELL93
R,MatNum,0.01,0.001,0.01,0.01, !0.1 = Thickness
*ELSEIF,arg2,eq,3,or,arg2,eq,4,THEN
ET,MatNum,SHELL181
SECTYPE,MatNum,SHELL
SECDATA,0.001
*ENDIF
!------------Material Definition: WIMPY----------------
MP,EX,MatNum,10
MP,PRXY,MatNum,0.33
MP,DENS,MatNum,0 !NO DENSITY
!======================================================
!SELECT AREAS, MESH
!------------------------------------------------------
!---------SELECT AREAS
*IF,ARG1,EQ,0,THEN
*MSG,UI
SELECT AREA TO APPLY LOAD
ASEL,r,p
*ELSEIF,ARG1,GT,0,THEN
ASEL,S,,,ARG1
*ENDIF !ELSE MESH ALL SELECTED AREAS
!---------MESH
TYPE,999
MAT,999
REAL,999
AMESH,ALL
!---------SELECT ELEMENTS AND NODES
ESEL,S,TYPE,,999
NSLE
!MAKE COMPONENTS
CM,NPRES_NODE,NODE
CM,NPRES_ELEM,ELEM
*GET,HighElem,ELEM,0,NUM,MAX !GET NUMBER OF HIGHEST SELECTED ELEMENT
*GET,LowElem,ELEM,0,NUM,MIN !GET NUMBER OF LOWEST SELECTED ELEMENT
*GET,NumElem,ELEM,0,COUNT !GET NUMBER OF ACTIVE Elements
*GET,HighNode,NODE,0,NUM,MAX !GET NUMBER OF HIGHEST SELECTED NODE
*GET,LowNode,NODE,0,NUM,MIN !GET NUMBER OF LOWEST SELECTED NODE
*GET,NumNode,NODE,0,COUNT !GET NUMBER OF ACTIVE Nodes
!-------Get Element Numbers
Select = $ *DIM,Select,ARRAY,HighElem
!Create Array for the selection status of Elements
*VGET,Select,ELEM,,ESEL !Get Selection Status of Elements
Elems = $ *DIM,Elems,ARRAY,NumElem !Create Array for Element Numbers
Loop=HighElem-LowElem+1 !SET Loop to Highest Element-Lowest Element+1
CurElem=HighElem
CurResult=NumElem !SET CurResult to Number of Elements
*DOWHILE,Loop !For active Elements
*IF,Select(CurElem),EQ,1,THEN !If the Element is selected
Elems(CurResult)=CurElem !Store Element Number in Elems
CurResult=CurResult-1
*ENDIF
CurElem=CurElem-1
Loop=Loop-1
*ENDDO
!-------GET AREAS
EAreas = $ *DIM,EAreas,ARRAY,NumElem !Create Array for Element areas
Loop=NumElem
*DOWHILE,Loop !FOR EACH Element
CurElem=Elems(Loop) !GET Current Element
*GET,EArea,ELEM,CurElem,AREA !GET AREA OF SELECTED ELEMENT
EAreas(Loop)=EArea !Store Area in EAreas ARRAY
Loop=Loop-1
*ENDDO
!-------GET ELEMENT LOCATIONS
Loc = $ *DIM,Loc,ARRAY,NumElem,3 !CREATE Array for Element Locations
Loop=NumElem
*DOWHILE,Loop !FOR EACH ELEMENT
CurElem=Elems(Loop) !GET Current Element
*GET,TempLoc,ELEM,CurElem,CENT,X !GET X Coordinate
Loc(Loop,1)=TempLoc !STORE x coordinate
*GET,TempLoc,ELEM,CurElem,CENT,Y !GET Y Coordinate
Loc(Loop,2)=TempLoc !STORE Y Coordinate
*GET,TempLoc,ELEM,CurElem,CENT,Z !GET Z Coordinate
Loc(Loop,3)=TempLoc
Loop=Loop-1
*ENDDO
!-------DERIVE ELEMENT LOADS
EPres = $ *DIM,EPres,ARRAY,NumELem,3 !Create Array For Element Loads
Loop=NumElem
*DOWHILE,Loop
A=EAreas(Loop)
X=Loc(Loop,1)
Y=Loc(Loop,2)
Z=Loc(Loop,3)
!-------------------------Fx,Fy,Fz=FUNCTION(X,Y,Z)-------------------
PressureSpaceFunction,ARG3
!-------------------------------------------------------
EPres(Loop,1)=Px*A
EPres(Loop,2)=Py*A
EPres(Loop,3)=Pz*A
Loop=Loop-1
*ENDDO
!--DERIVE LOADS FOR SHELL 93 ELEMENTS-----------------
NPres = $ *DIM,NPres,ARRAY,HighNode,3 !For Nodal Pressures
Loop=NumElem
*DOWHILE,Loop
CurElem=Elems(Loop)
! Quad 4 -----------------------
*if,arg2,eq,4,then
*do,i,1,4
*GET,N,ELEM,CurElem,NODE,i
*do,j,1,3
NPres(N,j) = NPres(N,j) + EPres(Loop,j)/4
*enddo
*enddo
!IF Tri 6 -----------------------------
*elseif,ARG2,EQ,6,THEN
*GET,N,ELEM,CurElem,NODE,5
NPres(N,1)=NPres(N,1)+EPres(Loop,1)/3
NPres(N,2)=NPres(N,2)+EPres(Loop,2)/3
NPres(N,3)=NPres(N,3)+EPres(Loop,3)/3
*GET,N,ELEM,CurElem,NODE,6
NPres(N,1)=NPres(N,1)+EPres(Loop,1)/3
NPres(N,2)=NPres(N,2)+EPres(Loop,2)/3
NPres(N,3)=NPres(N,3)+EPres(Loop,3)/3
*GET,N,ELEM,CurElem,NODE,8
NPres(N,1)=NPres(N,1)+EPres(Loop,1)/3
NPres(N,2)=NPres(N,2)+EPres(Loop,2)/3
NPres(N,3)=NPres(N,3)+EPres(Loop,3)/3
!IF QUAD 8 ----------------------------
*ELSEIF,ARG2,EQ,8,THEN
!FOR Corner nodes (See Fig 3.9-5 p58 of Finite Element Modeling for Stress Analysis by Robert D.Cook
*DO,i,1,4
*GET,N,ELEM,CurElem,NODE,i
*DO,j,1,3 !For Each Direction (1=X,2=Y,3=J)
NPres(N,j)=NPres(N,j)-EPres(Loop,j)/12
*ENDDO
*ENDDO
!For Midside Nodes
*DO,i,5,8
*GET,N,ELEM,CurElem,NODE,i
*DO,j,1,3 !For Each Direction (1=X,2=Y,3=J)
NPres(N,j)=NPres(N,j)+EPres(Loop,j)/3
*ENDDO
*ENDDO
*ENDIF !-------------------------------
Loop=Loop-1
*ENDDO
!--GET Selected Node Numbers--
NSelect = $ *DIM,NSelect,ARRAY,HighNode !Create Array for the selection status of Nodes
*VGET,NSelect,NODE,,NSEL !Get Selection Status of Nodes
Nodes = $ *DIM,Nodes,ARRAY,NumNode !Create Array for Element Nodes
Loop=HighNode-LowNode+1 !SET Loop to Highest Node-Lowest Node+1
CurNode=HighNode
CurResult=NumNode !SET CurResult to Number of Nodes
*DOWHILE,Loop !For active Nodes
*IF,NSelect(CurNode),EQ,1,THEN !If the Node is selected
Nodes(CurResult)=CurNode !Store Node Number in Node
CurResult=CurResult-1
*ENDIF
CurNode=CurNode-1
Loop=Loop-1
*ENDDO
!---APPLY FORCES
!/SOLU
Loop=NumNode
*DOWHILE,Loop
CurNode=Nodes(Loop) !Set Curretn Node
F,CurNode,FX,NPres(CurNode,1) !Apply Nodal Force in X-Direction
F,CurNode,FY,NPres(CurNode,2) !Apply Nodal Force in Y-Direction
F,CurNode,FZ,NPres(CurNode,3) !Apply Nodal Force in Z-Direction
Loop=Loop-1
*ENDDO
asel,s,type,,999
aclear,all
!--RESUME TEMPORARY COMPONENTS
CMSEL,S,temp_VOLU
CMSEL,S,temp_AREA
CMSEL,S,temp_LINE
CMSEL,S,temp_KP
CMSEL,S,temp_NODE
CMSEL,A,NPRES_NODE
!=========THE--END========THE--END========THE--END=====
!ITS THE END OF THE MACRO AS WE KNOW IT AND I FEEL FINE