-
Notifications
You must be signed in to change notification settings - Fork 24
/
postProc.py
130 lines (100 loc) · 4.26 KB
/
postProc.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
import numpy as np
import json
import matplotlib.pyplot as plt
import sys
import os
# load HTR modules
sys.path.insert(0, os.path.expandvars("$HTR_DIR/scripts/modules"))
import HTRrestart
###############################################################################
## Read Exact Solution ##
###############################################################################
def readExact():
# Open file
f = open('exact.txt', 'r')
x = []
u = []
p = []
rho = []
e = []
# Loop over lines and extract variables of interest
for line in f:
line = line.strip()
columns = line.split()
x.append( float(columns[0]))
rho.append(float(columns[1]))
u.append( float(columns[2]))
p.append( float(columns[3]))
f.close()
x = [(xp+1)*0.5 for xp in x]
e = [xp/xr/0.4 for xp, xr in zip(p,rho)]
return x, u, p, rho, e
###############################################################################
# Read Exact Solution #
###############################################################################
xExact, uExact, pExact, rhoExact, eExact = readExact()
def L2(err,dx):
tot = sum(map(sum, err**2*dx[:,:,0]*dx[:,:,1]*dx[:,:,2]))
vol = sum(map(sum, dx[:,:,0]*dx[:,:,1]*dx[:,:,2]))
return np.sqrt(tot/vol)
def process(case, i):
dir_name = os.path.join(os.environ['HTR_DIR'], 'testcases/LaxProblem')
soleil_input_file = os.path.join(dir_name, str(case)+'.json')
##############################################################################
# Read Prometeo Input File #
##############################################################################
with open(soleil_input_file) as f:
data = json.load(f)
xNum = data["Grid"]["xNum"]
xWidth = data["Grid"]["GridInput"]["width"][0]
nstep = data["Integrator"]["maxIter"]
##############################################################################
# Read Prometeo Output Data #
##############################################################################
restart = HTRrestart.HTRrestart(data)
restart.attach(sampleDir=os.path.join(dir_name, str(case)+'/sample0'), step=nstep)
# Get the data
x = restart.load('centerCoordinates')[0,0,:][:,0]
u = restart.load('velocity' )[0,0,:][:,0]
p = restart.load('pressure' )[0,0,:]
T = restart.load('temperature' )[0,0,:]
rho = restart.load('rho' )[0,0,:]
e = T/0.4
##############################################################################
# Plot #
##############################################################################
plt.figure(1+i*4)
plt.plot(xExact, uExact, '-k', label='Reference solution')
plt.plot( x, u, '-ob', label='HTR solver', markersize=4.5)
plt.xlabel(r'$x$', fontsize = 20)
plt.ylabel(r'$u$', fontsize = 20)
plt.legend()
plt.savefig('Velocity_'+str(case)+'.eps', bbox_inches='tight')
plt.figure(2+i*4)
plt.plot(xExact, pExact, '-k', label='Reference solution')
plt.plot( x, p, '-ob', label='HTR solver', markersize=4.5)
plt.xlabel(r'$x$', fontsize = 20)
plt.ylabel(r'$P$', fontsize = 20)
plt.legend()
plt.savefig('Pressure_'+str(case)+'.eps', bbox_inches='tight')
plt.figure(3+i*4)
plt.plot(xExact, rhoExact, '-k', label='Reference solution')
plt.plot( x, rho, '-ob', label='HTR solver', markersize=4.5)
plt.xlabel(r'$x$' , fontsize = 20)
plt.ylabel(r'$\rho$', fontsize = 20)
plt.legend()
plt.savefig('Density_'+str(case)+'.eps', bbox_inches='tight')
plt.figure(4+i*4)
plt.plot(xExact, eExact, '-k', label='Reference solution')
plt.plot( x, e, '-ob', label='HTR solver', markersize=4.5)
plt.xlabel(r'$x$', fontsize = 20)
plt.ylabel(r'$e$', fontsize = 20)
plt.legend()
plt.savefig('InternalEnergy_'+str(case)+'.eps', bbox_inches='tight')
return x, u, p, rho, e
plt.rcParams.update({'font.size': 16})
#cases = (100, 100)
#for i, case in enumerate(cases):
# x, u, p, r, e = process(case, i)
x, u, p, r, e = process(100, 0)
plt.show()