Skip to content

Commit 7e4ca94

Browse files
committed
python plot scripts to demo case: dt, iters, cp, kappa
1 parent 806b14a commit 7e4ca94

File tree

4 files changed

+128
-0
lines changed

4 files changed

+128
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import numpy as np
2+
from io import StringIO
3+
import matplotlib.pyplot as plt
4+
5+
# get data
6+
f = open('cpTable')
7+
bes = f.read()
8+
f.close()
9+
pod = bes.replace("("," ").replace(")", " ")
10+
tabela = np.loadtxt(StringIO(pod), usecols=(0,2))
11+
temp = np.add(tabela[:,0], -273.15)
12+
cp = tabela[:,1]
13+
14+
# plot
15+
fig, ax = plt.subplots()
16+
ax.plot(temp, cp)
17+
ax.set(xlabel='T (degC)', ylabel='c_p (J/kgK)',
18+
title='Specific heat at constant pressure')
19+
ax.grid()
20+
21+
plt.show()
22+
# fig.savefig("cp.png")
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import numpy as np
2+
from io import StringIO
3+
import matplotlib.pyplot as plt
4+
5+
# get data
6+
f = open('kappaTable')
7+
bes = f.read()
8+
f.close()
9+
pod = bes.replace("("," ").replace(")", " ")
10+
tabela = np.loadtxt(StringIO(pod), usecols=(0, 2, 4, 6))
11+
temp = np.add(tabela[:,0], -273.15)
12+
kappa1 = tabela[:,1]
13+
kappa2 = tabela[:,2]
14+
kappa3 = tabela[:,3]
15+
16+
# plot
17+
fig, ax = plt.subplots()
18+
19+
ax.set(xlabel='T (degC)'
20+
,ylabel='kappa (W/mK)'
21+
,title='Thermal conductivity')
22+
ax.grid()
23+
24+
ax.plot(temp, kappa1, 'k', label='20 MPa')
25+
ax.plot(temp, kappa2, 'k--', label='80 MPa')
26+
ax.plot(temp, kappa3, 'k:', label='120 MPa')
27+
28+
legend = ax.legend(loc='upper right', shadow=True, fontsize='x-large')
29+
30+
plt.show()
31+
# fig.savefig("kappa.png")

tutorials/demo/fill_pack/plot_dt.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import numpy as np
2+
from io import StringIO
3+
import matplotlib.pyplot as plt
4+
import re
5+
import sys
6+
'''
7+
example usage:
8+
python plot_dt.py log.openInjMoldSim
9+
'''
10+
# get data
11+
cas = ''
12+
dcas = ''
13+
with open(str(sys.argv[1])) as origin_file:
14+
data = origin_file.read()
15+
for match in re.findall(r'(?m)^Time\s=.*', data):
16+
cas = cas + match.split('=')[1] + '\n'
17+
for match in re.findall(r'(?m)^deltaT\s=.*', data):
18+
dcas = dcas + match.split('=')[1] + '\n'
19+
20+
cas = np.loadtxt(StringIO(cas))
21+
dcas = np.loadtxt(StringIO(dcas))
22+
23+
# plot
24+
fig, ax = plt.subplots()
25+
26+
ax.set(xlabel='t [s]'
27+
,ylabel='dt [s]'
28+
,title='Casovni korak')
29+
ax.grid()
30+
31+
ax.semilogy(cas, dcas, 'k', label='dt')
32+
33+
# legend = ax.legend(loc='upper right', shadow=True, fontsize='x-large')
34+
35+
plt.show()
36+
# fig.savefig("dt.png")
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import numpy as np
2+
from io import StringIO
3+
import matplotlib.pyplot as plt
4+
import re
5+
import sys
6+
'''
7+
example usage:
8+
python plot_iters.py log.openInjMoldSim
9+
'''
10+
# get data
11+
cas = ''
12+
iters = ''
13+
with open(str(sys.argv[1])) as origin_file:
14+
data = origin_file.read()
15+
for match in re.findall(r'(?m)^Time\s=.*', data):
16+
cas = cas + match.split('=')[1] + '\n'
17+
for match in re.findall(r'(?m)^PIMPLE:.*in.*iterations', data):
18+
iters = iters + match.split(' ')[-2] + '\n'
19+
20+
cas = np.loadtxt(StringIO(cas))
21+
iters = np.loadtxt(StringIO(iters))
22+
23+
if cas.size == iters.size+1:
24+
cas = cas[1:]
25+
26+
# plot
27+
fig, ax = plt.subplots()
28+
29+
ax.set(xlabel='t [s]'
30+
,ylabel='iters [1]'
31+
,title='Pimple iterations')
32+
ax.grid()
33+
34+
ax.plot(cas, iters, 'k', label='iters')
35+
36+
# legend = ax.legend(loc='upper right', shadow=True, fontsize='x-large')
37+
38+
plt.show()
39+
# fig.savefig("iters.png")

0 commit comments

Comments
 (0)