4from datetime
import datetime
5from matplotlib
import pyplot
as plt
6from matrixReader
import populateRHS
8os.system(
'export PYTHONPATH=../../../../python/')
10meshes = (3, 9, 81, 243)
13current_date_time = datetime.now()
15formatted_date_time = current_date_time.strftime(
"%Y-%m-%d_%H-%M-%S")
17folder_name = f
"convergence-test-{formatted_date_time}"
19input(f
"This will run a convergence test for meshes {meshes}. The output will be saved in {folder_name}/. Press Enter to continue...")
21os.system(f
"mkdir {folder_name}")
24 meshsize = 1.1 * 1.0/mesh
25 os.system(
"python3 dg.py -m release --meshsize " + str(meshsize))
26 os.system(
"./peano4petsc")
28 mesh_folder_name = f
"{folder_name}/{mesh}"
29 os.system(f
"mkdir {mesh_folder_name}")
30 os.system(f
"mv mat.xml {mesh_folder_name}/")
31 os.system(f
"mv rhs.xml {mesh_folder_name}/")
32 os.system(f
"mv sol.xml {mesh_folder_name}/")
33 os.system(f
"mv exactSol.txt {mesh_folder_name}/")
35 os.system(f
"git clean -xdf -e {folder_name}")
43 cell_ndof = mesh ** 2 * 4
44 mesh_folder_name = f
"{folder_name}/{mesh}"
45 sol = populateRHS(f
"{mesh_folder_name}/sol.xml")[:cell_ndof]
46 exact_sol = np.loadtxt(f
"{mesh_folder_name}/exactSol.txt")
47 assert(len(sol) == len(exact_sol))
49 error = np.max(np.abs(sol - exact_sol))
52 print(f
"for mesh {mesh}, error = {error}")
69plt.title(
r"Interiror penatly method for 2D Poisson equation: " +
'\n' +
r"$-\Delta u = f(x,y), \quad f(x,y) = 8 \pi^2 \, \sin(2\pi x) \, \sin(2\pi y), \quad u |_{\partial \Omega} = 0$")
72ax.set_xlabel(
"Grid spacing $h$")
73ax.set_ylabel(
r"Max error: $||u-u_{\mathrm{exact}}||_\inf$")
76 [2.0e-3, 2.0e-3 * 10**2.0],
80 label=
r"$\propto h^{-2.0}$",
83plt.legend(loc=
"lower right")
84plt.savefig(f
"{folder_name}/error.png", bbox_inches=
"tight")
85print(f
"Error plot saved in {folder_name}/error.png")