-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_cfl.py
64 lines (51 loc) · 1.54 KB
/
test_cfl.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
from firedrake import *
set_log_level(ERROR)
import numpy as np
from benchmarker import solver_CG, _build_space
## defining method to analyze
space = "spectral"
cell_type = "quad"
error_threshold = 1e-1
if cell_type == "quad":
quadrilateral = True
elif cell_type == "tria":
quadrilateral = False
else:
raise ValueError("Cell type not supported")
## building reference solution
p = 4
timestep = 0.0005
mesh = UnitSquareMesh(50, 50, quadrilateral = quadrilateral)
ref = solver_CG(mesh, el=cell_type, space=space, deg=p, T=0.50, dt=timestep)
V_fine = _build_space(mesh,cell_type, space,p)
## checking dt as f(p) in mesh
degrees = np.array([1,2,3,4])
ns = np.array([40, 50, 60, 70, 100])
dts = np.zeros((len(ns),len(degrees)))
print(dts)
ref_dt = 0.00005
i = 0
for n in ns:
mesh = UnitSquareMesh(n, n, quadrilateral = quadrilateral)
### building reference solution
ref = solver_CG(mesh, el=cell_type, space=space, deg=p, T=0.50, dt=ref_dt)
j = 0
for degree in degrees:
dt = 0.0005
for two_pot in [-1,0,1,2,3,4]:
error = 1e-10 # value to enter while loop
while error < error_threshold:
incr = dt/(2**two_pot)
dt += incr
try:
sol = solver_CG(mesh, el=cell_type, space=space, deg=degree, T=0.50, dt=dt)
error = errornorm(ref, sol)
except:
error = 1e10
dt-= incr
dts[i,j] = dt
j+=1
i+=1
print(dts)
def find_fp(ns, degrees,dts):
xs = 1./ns