summaryrefslogtreecommitdiff
path: root/test.py
blob: bcfa0c24d7f3fd3e3b84f5d05b37d7f7bcefac12 (plain)
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
import mg2d
import numpy as np

import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt

N = 4097
h = 1.0 / N
x = np.linspace(0, 1, N)
z = np.linspace(0, 1, N)
X, Z = np.meshgrid(x, z, indexing = 'xy')

rhs = - 8.0 * np.pi * np.pi * np.cos(X * 2 * np.pi) * np.cos(Z  * 2 * np.pi)

#rhs[0]     = np.cos(2 * np.pi * x)
#rhs[:, 0]  = np.cos(2 * np.pi * x)
#
#rhs[-1]    = np.cos(2 * np.pi * x)
#rhs[:, -1] = np.cos(2 * np.pi * x)

coeffs = [np.zeros_like(X) for i in xrange(mg2d.MG2D_DIFF_COEFF_NB)]
coeffs[mg2d.MG2D_DIFF_COEFF_XX][:] = 1
coeffs[mg2d.MG2D_DIFF_COEFF_ZZ][:] = 1

solver = mg2d.MG2DSolver(N, N, h, h, 6)
solution, res_norm = solver.solve(coeffs, rhs);

exact_solution = np.cos(2 * np.pi * X) * np.cos(2 * np.pi * Z)

print 'maxdiff ', np.max(np.abs(exact_solution - solution))

fig    = plt.figure(figsize = (8, 8))
axes   = fig.add_subplot(111)

axes.grid()
#axes.set_yscale('log')
for i in xrange(5):
    idx = int(i * N / 5.0)
    axes.plot(x, solution[idx], label = 'z = %g' % z[idx])
    axes.plot(x, exact_solution[idx], '--', label = 'z = %g' % z[idx])
axes.legend()
#axes.plot(res_norm)

fig.savefig('out.png')