-
Notifications
You must be signed in to change notification settings - Fork 3
/
nonlocalFIP.py
88 lines (58 loc) · 2.27 KB
/
nonlocalFIP.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
#USE THIS ONE - ayushi
def nonlocalFIP():
import datetime
import numpy as np
import sys
from dictionary import thisdict
resultsFileName = thisdict["resultsFileName"]
dataPath = './data/'
resultsPath = './results/'
deckName = thisdict["deckName"]
print('nonlocal post processing ' + resultsFileName)
isNonConf = thisdict["isNonConf"]
if isNonConf == True:
outputfilename1=resultsPath+resultsFileName+'-nonlocalFIP_NC.txt'
else:
outputfilename1=resultsPath+resultsFileName+'-nonlocalFIP_C.txt'
## open txt file to write to
try:
out1 = open(outputfilename1,'w')
except:
out1 = open('.' + outputfilename1,'w')
elsetsFile = deckName +'-ElsetsMat.inp'
elsetsMat = np.loadtxt(elsetsFile,delimiter=',',dtype=int)
numVols = len(elsetsMat[:,0])
#numVols = len(elsetsMat)
fipFile = dataPath + resultsFileName
try:
localFipMat = np.loadtxt(fipFile,delimiter=',')
except:
localFipMat = np.loadtxt('.'+fipFile,delimiter=',')
numSteps = len(localFipMat[0,:])-1
numElem = len(localFipMat[:,0])
nonlocalFipMat = np.zeros((numVols,numSteps))
for s in range(numSteps):
print('start step ' + str(s+1))
for f in range(numVols):
elset = elsetsMat[f,:]
elset = elset[np.nonzero(elset)]
# assumes all element in volume are roughly the same size
numElemVol = len(elset)
sumVal = 0
for e in elset:
elemInd = np.where(localFipMat[:,0] == e)
for gp in elemInd:
sumVal += localFipMat[gp,s+1]
aveVal = sumVal/numElemVol
nonlocalFipMat[f,s] = aveVal
# write data
for f in range(numVols):
for s in range(numSteps):
if s == numSteps-1:
out1.write(str(nonlocalFipMat[f,s]))
else:
out1.write(str(nonlocalFipMat[f,s]) + ', ')
out1.write('\n')
print("max fip in last step" + str(max(nonlocalFipMat[:,-1])))
# close input and output files
out1.close()