-
Notifications
You must be signed in to change notification settings - Fork 3
/
createAllNlElsetsInRegionParaNConftest.py
158 lines (121 loc) · 5.05 KB
/
createAllNlElsetsInRegionParaNConftest.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
#!/usr/bin/python
#USE THIS ONE - ayushi
#import datetime
#import multiprocessing
#from functools import partial
#from dictionary import thisdict
################################################################
################# start main Program ##########################
###############################################################
def createVolume():
###############################
###### USER INPUTS #########
###############################
import numpy as np
import datetime
import multiprocessing
from functools import partial
from dictionary import thisdict
import sys
from getElemInd import getElemInd
from multiprocessing_func import multiprocessing_func
import warnings
# 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=',')
with warnings.catch_warnings():
warnings.simplefilter('ignore')
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()
#if __name__=="__main__":
#main()