diff options
author | Anton Khirnov <anton@khirnov.net> | 2018-12-28 10:20:54 +0100 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2019-05-17 09:42:27 +0200 |
commit | 36371cfd9ea2b81bfb967b7238a158d554f500e5 (patch) | |
tree | 06f488180b46d5619e864e6b498a5a2ab5e8a7fe /test.py | |
parent | 99cd43b5c824309961a0dae2782704b73b02e881 (diff) |
WIP files.brill_wip
Diffstat (limited to 'test.py')
-rw-r--r-- | test.py | 45 |
1 files changed, 45 insertions, 0 deletions
@@ -0,0 +1,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') |