summaryrefslogtreecommitdiff
path: root/test.py
diff options
context:
space:
mode:
Diffstat (limited to 'test.py')
-rw-r--r--test.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/test.py b/test.py
new file mode 100644
index 0000000..bcfa0c2
--- /dev/null
+++ b/test.py
@@ -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')