Repository navigation
Expand file tree
/
Copy pathplotTime.py
More file actions
executable file
·88 lines (68 loc) · 1.77 KB
/
Copy pathplotTime.py
File metadata and controls
executable file
·88 lines (68 loc) · 1.77 KB
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
#!/usr/bin/env python3
import numpy as np
import matplotlib.pyplot as plt
import sys
import time
import warnings
warnings.filterwarnings('ignore') # turn off annoying warnings for mpl
''' Plots residuals from OpenFOAM stdout '''
def getTime():
try:
def skipHeader(fname):
f = open(fname, 'r')
line = next(f)
while ('Starting time loop' not in line):
line = next(f)
return f
fname = 'log'
var = ['deltaT'] # store variable names
# get variable names
# f = skipHeader(fname)
# for line in f:
# if (line.startswith('Time = 1')):
# line = next(f)
# while ('ExecutionTime' not in line):
# for i in range(len(line)):
# string = 'Solving for '
# if (line[i:i+len(string)] == string):
# var.append(line[i+len(string):].split(',')[0])
# line = next(f)
# break
# f.close()
num = len(var)
fig = plt.figure(figsize=(8,6))
# plt.ion()
run = 1
while(run == 1):
val = [] # store values
t = [] # store time
f = skipHeader(fname)
for line in f:
if ('deltaT = ' in line):
for j in range(len(line)):
string = 'deltaT = '
if (line[j:j+len(string)] == string):
val.append(line[j+len(string):].split(',')[0])
elif (line.startswith('Time = ')):
l = line.split()
t.append(float(l[2]))
if (line == 'End\n'):
run = 0
# print(str(t[-1]) + '\t' + str(val[-1].strip()) + '\r', end='', flush=True)
# time.sleep(1)
plt.semilogy(t, val)
plt.xlabel('t')
plt.ylabel(r'$\Delta$t')
plt.title(str(t[-1]))
f.close()
plt.legend(loc='best', frameon=False)
if (run == 1):
plt.pause(1)
fig.clear()
if (run == 0):
plt.show()
# exit nicely on ctrl-c
except KeyboardInterrupt:
sys.exit()
if __name__ == '__main__':
getTime()