Skip to content

Commit d506f96

Browse files
author
Daniel Ruprecht
committed
added convergence plot script for scalar test problem to make sure order there is exactly equal to number of iterations K
1 parent 0c46aed commit d506f96

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

examples/fwsw/run_convergence.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
from __future__ import print_function
2+
3+
from pySDC import CollocationClasses as collclass
4+
5+
import numpy as np
6+
import matplotlib.pyplot as plt
7+
8+
from examples.fwsw.ProblemClass import swfw_scalar
9+
from pySDC.datatype_classes.complex_mesh import mesh, rhs_imex_mesh
10+
from pySDC.sweeper_classes.imex_1st_order import imex_1st_order
11+
import pySDC.PFASST_stepwise as mp
12+
from pySDC import Log
13+
14+
15+
16+
if __name__ == "__main__":
17+
18+
# set global logger (remove this if you do not want the output at all)
19+
logger = Log.setup_custom_logger('root')
20+
21+
num_procs = 1
22+
23+
# This comes as read-in for the level class
24+
lparams = {}
25+
lparams['restol'] = 1E-12
26+
27+
sparams = {}
28+
sparams['maxiter'] = 4
29+
30+
# This comes as read-in for the problem class
31+
pparams = {}
32+
pparams['lambda_s'] = np.array([0.1j], dtype='complex')
33+
pparams['lambda_f'] = np.array([1.0j], dtype='complex')
34+
pparams['u0'] = 1
35+
36+
# Fill description dictionary for easy hierarchy creation
37+
description = {}
38+
description['problem_class'] = swfw_scalar
39+
description['problem_params'] = pparams
40+
description['dtype_u'] = mesh
41+
description['dtype_f'] = rhs_imex_mesh
42+
description['collocation_class'] = collclass.CollGaussLegendre
43+
description['num_nodes'] = [3]
44+
description['do_LU'] = False
45+
description['sweeper_class'] = imex_1st_order
46+
description['level_params'] = lparams
47+
48+
# quickly generate block of steps
49+
MS = mp.generate_steps(num_procs,sparams,description)
50+
51+
Nsteps_v = np.array([1, 2, 4, 8, 10, 15, 20])
52+
Tend = 1.0
53+
t0 = 0
54+
55+
P = MS[0].levels[0].prob
56+
uinit = P.u_exact(t0)
57+
uex = P.u_exact(Tend)
58+
error = np.zeros(np.size(Nsteps_v))
59+
convline = np.zeros(np.size(Nsteps_v))
60+
61+
for j in range(0,np.size(Nsteps_v)):
62+
# setup parameters "in time"
63+
dt = Tend/float(Nsteps_v[j])
64+
65+
# call main function to get things done...
66+
uend,stats = mp.run_pfasst(MS,u0=uinit,t0=t0,dt=dt,Tend=Tend)
67+
error[j] = np.abs(uend.values - uex.values)
68+
convline[j] = error[j]*(float(Nsteps_v[j])/float(Nsteps_v[j]))**sparams['maxiter']
69+
70+
plt.figure()
71+
plt.loglog(Nsteps_v, error, 'bo', markersize=12)
72+
plt.loglog(Nsteps_v, convline, '-', color='k')
73+
plt.show()

0 commit comments

Comments
 (0)