-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimulationData.py
More file actions
executable file
·49 lines (41 loc) · 1.69 KB
/
simulationData.py
File metadata and controls
executable file
·49 lines (41 loc) · 1.69 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
#!/usr/bin/python3
import numpy as np
import time
class simulationData:
def __init__(self, options, gridLevels, cycle, name):
# data common to all simulations
self.nu = float(options.nu)
tokens = options.xSpan.split()
self.xc = np.linspace(float(tokens[0]), float(tokens[1]), int(tokens[2]))
tokens = options.ySpan.split()
self.yc = np.linspace(float(tokens[0]), float(tokens[1]), int(tokens[2]))
self.timeSteps = int(options.timeSteps)
self.cornerTemp = float(options.cornerTemp)
self.iteration = np.zeros((self.timeSteps + 1))
self.iteration = range(0, self.timeSteps + 1)
self.residualThreshold = float(options.threshold)
# data different for each simulation
self.startingTime = time.time()
self.timeToThreshold = -1.0
self.gridLevels = gridLevels
self.cycleType = cycle
self.residuals = np.zeros((self.timeSteps + 1))
self.times = np.zeros((self.timeSteps + 1))
self.name = name
def LogResidual(self, nn, l2, linf):
self.residuals[nn] = l2
nresid = l2 / self.residuals[0]
dt = time.time() - self.startingTime
self.times[nn] = dt
print("{0:5d} {1:21.4e} {2:16.4e} {3:15.4e}".format(nn, nresid, linf, dt))
if nresid <= self.residualThreshold and self.timeToThreshold < 0.0:
self.timeToThreshold = time.time() - self.startingTime
def NormResids(self):
return self.residuals / self.residuals[0]
def PrintTimeToThreshold(self):
if self.timeToThreshold > 0:
print(self.name, "reached threshold in",
"{0:6.4e} s; final residual of {1:6.4e}".format(
self.timeToThreshold, self.residuals[-1] / self.residuals[0]))
else:
print(self.name, "did not reach threshold")