Skip to content

Commit 2e6c6e8

Browse files
committed
bugfix...
1 parent 73ec94e commit 2e6c6e8

File tree

3 files changed

+42
-17
lines changed

3 files changed

+42
-17
lines changed

pySDC/implementations/problem_classes/HeatEquation_1D_FD_periodic.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,9 @@ def u_exact(self, t):
125125

126126
if self.params.freq >= 0:
127127
xvalues = np.array([i * self.dx for i in range(self.params.nvars)])
128+
rho = (2.0 - 2.0 * np.cos(np.pi * self.params.freq * self.dx)) / self.dx ** 2
128129
me.values = np.sin(np.pi * self.params.freq * xvalues) * \
129-
np.exp(-t * self.params.nu * (np.pi * self.params.freq) ** 2)
130+
np.exp(-t * self.params.nu * rho)
130131
else:
131132
np.random.seed(1)
132133
me.values = np.random.rand(self.params.nvars)

pySDC/playgrounds/order_test/heat1d.py

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,48 +28,49 @@ def main():
2828

2929
# This comes as read-in for the problem class
3030
problem_params = dict()
31-
problem_params['nu'] = 1.0
31+
problem_params['nu'] = 0.01
3232
problem_params['freq'] = 2
33-
problem_params['nvars'] = [2 ** 14 - 1]#, 2 ** 13]
33+
problem_params['nvars'] = [2 ** 7]#, 2 ** 6]
3434

3535
# This comes as read-in for the sweeper class
3636
sweeper_params = dict()
3737
sweeper_params['collocation_class'] = CollGaussRadau_Right
3838
sweeper_params['num_nodes'] = 3
3939
sweeper_params['QI'] = 'IE'
40-
sweeper_params['spread'] = False
40+
sweeper_params['spread'] = True
4141
sweeper_params['do_coll_update'] = False
4242

4343
# initialize space transfer parameters
4444
space_transfer_params = dict()
4545
space_transfer_params['rorder'] = 2
4646
space_transfer_params['iorder'] = 2
47-
space_transfer_params['periodic'] = False
47+
space_transfer_params['periodic'] = True
4848

4949
# initialize controller parameters
5050
controller_params = dict()
51-
controller_params['logger_level'] = 30
51+
controller_params['logger_level'] = 20
52+
controller_params['predict'] = False
5253

5354
# Fill description dictionary for easy hierarchy creation
5455
description = dict()
55-
description['problem_class'] = heat1d_forced
56+
description['problem_class'] = heat1d_periodic
5657
description['dtype_u'] = mesh
57-
description['dtype_f'] = rhs_imex_mesh
58-
description['sweeper_class'] = imex_1st_order
58+
description['dtype_f'] = mesh#rhs_imex_mesh
59+
description['sweeper_class'] = generic_implicit#imex_1st_order
5960
description['sweeper_params'] = sweeper_params
6061
description['step_params'] = step_params
6162
description['level_params'] = level_params
6263
description['problem_params'] = problem_params
63-
# description['space_transfer_class'] = mesh_to_mesh # pass spatial transfer class
64-
# description['space_transfer_params'] = space_transfer_params # pass paramters for spatial transfer
64+
description['space_transfer_class'] = mesh_to_mesh # pass spatial transfer class
65+
description['space_transfer_params'] = space_transfer_params # pass paramters for spatial transfer
6566

6667

6768
# setup parameters "in time"
68-
t0 = 0
69-
Tend = 2.0
69+
t0 = 0.0
70+
Tend = 1.0
7071

71-
dt_list = [Tend / 2 ** i for i in range(0, 4)]
72-
niter_list = [100]#[1, 2, 3, 4]
72+
dt_list = [Tend / 2 ** i for i in range(3, 6)]
73+
niter_list = [2]#[1, 2, 3, 4]
7374

7475
for niter in niter_list:
7576

@@ -81,6 +82,8 @@ def main():
8182
description['step_params']['maxiter'] = niter
8283
description['level_params']['dt'] = dt
8384

85+
Tend = t0 + dt
86+
8487
# instantiate the controller
8588
controller = allinclusive_multigrid_nonMPI(num_procs=1, controller_params=controller_params,
8689
description=description)
@@ -93,6 +96,8 @@ def main():
9396
uend, stats = controller.run(u0=uinit, t0=t0, Tend=Tend)
9497

9598
# compute exact solution and compare
99+
# uex = compute_collocation_solution(controller)
100+
# print(abs(uex - P.u_exact(Tend)))
96101
uex = P.u_exact(Tend)
97102
err_new = abs(uex - uend)
98103

@@ -126,5 +131,25 @@ def main():
126131
# print(out)
127132
print()
128133

134+
135+
def compute_collocation_solution(controller):
136+
137+
Q = controller.MS[0].levels[0].sweep.coll.Qmat[1:, 1:]
138+
A = controller.MS[0].levels[0].prob.A.todense()
139+
dt = controller.MS[0].levels[0].dt
140+
141+
N = controller.MS[0].levels[0].prob.init
142+
M = controller.MS[0].levels[0].sweep.coll.num_nodes
143+
144+
u0 = np.kron(np.ones(M), controller.MS[0].levels[0].u[0].values)
145+
146+
C = np.eye(M * N) - dt * np.kron(Q, A)
147+
148+
tmp = np.linalg.solve(C, u0)
149+
print(np.linalg.norm(C.dot(tmp) - u0, np.inf))
150+
uex = controller.MS[0].levels[0].prob.dtype_u(N)
151+
uex.values[:] = tmp[(M-1) * N:]
152+
return uex
153+
129154
if __name__ == "__main__":
130155
main()

pySDC/tests/test_2d_fd_accuracy.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,9 @@ def run_accuracy_check(nvars_list,problem_params):
5959
# create a mesh instance and fill it with the Laplacian of the sine wave
6060
u_lap = prob.dtype_u(init=prob.init)
6161
u_lap.values = -2*(np.pi * prob.params.freq) ** 2 * prob.params.nu * np.kron(np.sin(np.pi * prob.params.freq * xvalues), np.sin(np.pi * prob.params.freq * xvalues))
62-
u_lap.values = u_lap.values.flatten()
6362

6463
# compare analytic and computed solution using the eval_f routine of the problem class
65-
err = abs(prob.eval_f(u,0) - u_lap)
64+
err = abs(prob.eval_f(u, 0) - u_lap)
6665

6766
# get id for this nvars and put error into dictionary
6867
id = ID(nvars=nvars)

0 commit comments

Comments
 (0)