-
Notifications
You must be signed in to change notification settings - Fork 3
/
createAllNlElsetsInRegionParaNConf.py
194 lines (146 loc) · 5.89 KB
/
createAllNlElsetsInRegionParaNConf.py
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
#!/usr/bin/python
#DONT USE THIS ONE -ayushi chandel
#import numpy as np
#import datetime
#import multiprocessing
#from functools import partial
#from dictionary import thisdict
def getElemInd(f, numElements, elemCent, dr):
import numpy as np
import datetime
import multiprocessing
from functools import partial
from dictionary import thisdict
# f is the counter for the nonlocal volume
elemInd = np.empty((numElements,2))
elemInd[:] = np.nan
counter = 0
x0 = elemCent[f,1]
y0 = elemCent[f,2]
z0 = elemCent[f,3]
for e in range(numElements):
xP = elemCent[e,1]
yP = elemCent[e,2]
zP = elemCent[e,3]
x1 = abs(xP - x0);
y1 = abs(yP - y0);
z1 = abs(zP - z0);
r = np.sqrt(x1**2. + y1**2. +z1**2.);
if r <= dr:
elemInd[counter,0] = elemCent[e,0]
elemInd[counter,1] = r
counter = counter + 1
elemInd = elemInd[~np.isnan(elemInd)]
#elemInd = elemInd.astype(np.int64)
return elemInd
def multiprocessing_func(fip, ijk, total, numElements,elemCent, dr):
print (str(fip+1) + '/' + str(total))
elemInd = getElemInd(fip, numElements, elemCent, dr)
return elemInd
################################################################
################# start main Program ##########################
###############################################################
def createAllNlElsetsInREgionParaConf():
###############################
###### USER INPUTS #########
###############################
import numpy as np
import datetime
import multiprocessing
from functools import partial
from dictionary import thisdict
# input deck name without .inp (i.e., the output of this script)
deckName = thisdict["deckName"]
# element Set name
elsetName = thisdict["elsetName"]
#length of edge of square nl volume
dx = thisdict["dx"]
# radius of equivelent volume
dr = ((3./4.)*dx**3./np.pi)**(1./3.)
#number of processors
numProc = thisdict["numProc"]
###############################
###### LOAD FILES #########
###############################
#abaqus output files
elsetFile = deckName + '-Elsets.inp'
fileOutput = open(elsetFile ,'w')
elsetMatFile = deckName + '-ElsetsMat.inp'
fileOutput2 = open(elsetMatFile ,'w')
elsetCentRFile = deckName + '-ElsetsCentR.inp'
fileOutput3 = open(elsetCentRFile ,'w')
# node file name (from getElsetNode getElsetNodesElems.py, getNlNodesElems.py)
nodeFile = 'nlNodes.inp'
# element file name
elementFile = 'nlElements.inp'
# elset file name
elsetFile = 'nlElsets.inp'
# centroids of elems from getElemCent.py
elemCentFile = deckName +'-ElemCent.inp'
## Open input files
nodes = np.loadtxt(nodeFile,delimiter=',')
elements = np.loadtxt(elementFile,delimiter=',',dtype=int)
elemCent = np.loadtxt(elemCentFile,delimiter=',')
matrixElset = np.loadtxt(elsetFile,dtype=int)
matrixElsetInd = matrixElset-1
# assumes element numbers start at 1 with no breaks
if matrixElsetInd:
elements = elements[matrixElsetInd,:]
numNodes = nodes.shape[0]
print ('Number of Nodes: ' + str(numNodes))
numElements = elements.shape[0]
nodesPerElem = elements.shape[1] - 1
print ('Number of Elements: ' + str(numElements))
print ('Number of Nodes per Elements: ' + str(nodesPerElem))
fipCount = 1
print ('start fip count : ' + str(datetime.datetime.now()))
#####################################################################
###################### find elements in irregular mesh ##############
#####################################################################
total = numElements
#total = 1000
pool = multiprocessing.Pool(processes = numProc)
elemIndArray = pool.map(partial(multiprocessing_func,ijk=range(total), total=total, numElements=numElements, elemCent=elemCent, dr=dr), range(total))
sizeElemInd = 0
for fipCount in range(total):
elemIndTemp = elemIndArray[fipCount]
elemInd = elemIndTemp[0:-1:2]
elemCentR = elemIndTemp[1:len(elemIndTemp):2]
#print elemInd
#print elemCentR
if len(elemInd) > sizeElemInd:
sizeElemInd = len(elemInd)
#print 'start writing elements to file : ' + str(datetime.datetime.now())
fileOutput.write('\n' + '*Elset, elset=' + elsetName + str(fipCount+1) + '\n')
for i in range(len(elemInd)):
fileOutput.write(str(int(elemInd[i])) + ', ')
if i != 0 and i % 15 == 0:
fileOutput.write('\n')
#print 'end writing elements to file : ' + str(datetime.datetime.now())
#if len(elemInd) < 20:
# print elemInd
elsetMat = np.zeros((total,sizeElemInd))
elsetCentRMat = np.zeros((total,sizeElemInd))
elsetCentRMat[:] = np.nan
for fipCount in range(total):
elemIndTemp = elemIndArray[fipCount]
elemInd = elemIndTemp[0:-1:2]
elemCentR = elemIndTemp[1:len(elemIndTemp):2]
for i in range(len(elemInd)):
#print len(elemInd)
elsetMat[fipCount,i] = int(elemInd[i])
elsetCentRMat[fipCount,i] = elemCentR[i]
for fipCount in range(total):
for i in range(sizeElemInd):
if i == (sizeElemInd - 1 ):
fileOutput2.write(str(int(elsetMat[fipCount,i])))
fileOutput3.write(str((elsetCentRMat[fipCount,i])))
else:
fileOutput2.write(str(int(elsetMat[fipCount,i])) + ', ')
fileOutput3.write(str((elsetCentRMat[fipCount,i])) + ', ')
fileOutput2.write('\n')
fileOutput3.write('\n')
print ('end fip count : ' + str(datetime.datetime.now()))
fileOutput.close()
fileOutput2.close()
fileOutput3.close()