forked from guoxiaoyu543/TallyConvert
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostprocess.py
119 lines (93 loc) · 4.32 KB
/
postprocess.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
# coding = gbk
# module name: postprocess
import re
import os
class Tecplot:
"""
this class will help handle the tecplot data file
data title, variablenames, variables ,solutionstime, xnode, ynode, znode are required
"""
def __init__(self, Title = 'tecplot.dat', VariableNameList = ['X','Y','Z'],\
VariableList = [], SolutionTime = 0.0,\
XNodes = 1, YNodes = 1, ZNodes = 1):
self.Title = Title
self.VariableNameList = VariableNameList
self.VariableList = VariableList
# VariableList is a two-dimentional list containing all the variables
self.SolutionTime = SolutionTime
self.XNodes = XNodes
self.YNodes = YNodes
self.ZNodes = ZNodes
def outputTecplotFile(self, TecplotFile):
TecplotFile.write('Title = \"%s\"\n'%self.Title)
TecplotFile.write('Variables = ')
for VariableName in self.VariableNameList[:-1]:
TecplotFile.write('\"%s\",'%VariableName)
TecplotFile.write('\"%s\"\n'%self.VariableNameList[-1])
TecplotFile.write('ZONE SOLUTIONTIME = %f I = %d J = %d K = %d F=POINT\n'%(self.SolutionTime,self.XNodes,self.YNodes,self.ZNodes))
for Variables in self.VariableList:
# Variables is a list containing the coordinates and
# corresponding temperature, power, ect. of every single point
for Variable in Variables:
TecplotFile.write('%s '%(str(Variable)))
TecplotFile.write('\n')
def getTimePoint(singleTallyFile):
TimePoint = 0.0
for line in singleTallyFile:
findTimePoint = re.findall('Total step time\(Day\): ([.\d]*)',line)
if findTimePoint != []:
TimePoint = float(findTimePoint[0])
singleTallyFile.seek(0)
return TimePoint
def getAveAndRe(singleTallyFile):
TallyFileContent = singleTallyFile.read()
TallyAve = re.findall('\s+\d+\s+([+-]*[.\d]+[Ee][+-]*[\d]+)',TallyFileContent)
TallyRe = re.findall('\s+\d+\s+[+-]*[.\d]+[Ee][+-]*[\d]+\s+([+-]*[.\d]+[Ee][+-]*[\d]+)',TallyFileContent)
return [TallyAve, TallyRe]
def normalize(TallyAve):
TallyFluxSum = 0
for j in range(0,len(TallyAve)):
TallyFluxSum += float(TallyAve[j])
TallyFlux = []
for j in range(0,len(TallyAve)):
TallyFlux.append(float(TallyAve[j])/TallyFluxSum)
for j in range(0,len(TallyAve)):
TallyAve[j] = '%.4E'%(TallyFlux[j])
def createTecplotFile(TallyAve, TecplotFileName, singleTallyFileName, Legend, TimePoint, Xnodes, Ynodes, Znodes):
MeshBurnup = []
for z in range(Znodes):
for y in range(Ynodes):
for x in range(Xnodes):
MeshBurnup.append([x+1, y+1, z+1, str(TallyAve[x+Xnodes*y+Xnodes*Ynodes*z])])
TecplotObject = Tecplot(TecplotFileName+singleTallyFileName[9:],['X','Y','Z',Legend],\
MeshBurnup, TimePoint, Xnodes,Ynodes,Znodes)
TecplotFile = open('%s%s.dat'%(TecplotFileName,singleTallyFileName[9:]),'w')
TecplotObject.outputTecplotFile(TecplotFile)
TecplotFile.close()
def createTable(i, TallyX, TypeName):
if i == 0:
TabularXFile = open(TypeName,'w')
for RowCount in range(0,len(TallyX)):
if RowCount == 0:
TabularXFile.write('%s'%(TallyX[RowCount]))
else:
TabularXFile.write('\n%s'%(TallyX[RowCount]))
TabularXFile.close()
if i > 0:
TabularXFile = open(TypeName,'r')
newTabularXFile = open('new%s'%(TypeName),'w')
TotalRow = 0
for line in TabularXFile:
TotalRow += 1
TabularXFile.seek(0)
RowCount = 0
for line in TabularXFile:
if RowCount != TotalRow - 1:
newTabularXFile.write('%s %s\n'%(line[:-1], TallyX[RowCount]))
if RowCount == TotalRow - 1:
newTabularXFile.write('%s %s'%(line, TallyX[RowCount]))
RowCount += 1
TabularXFile.close()
newTabularXFile.close()
os.remove(TypeName)
os.rename('new%s'%(TypeName),TypeName)