1 import FiniteVolumes2DPoisson_SQUARE
2 import matplotlib.pyplot as plt
4 from math import log10,sqrt
7 convergence_synthesis=dict(FiniteVolumes2DPoisson_SQUARE.test_desc)
9 def test_validation2DVF_deformedQuadrangles():
11 ##### 2D FV deformed quadrangles mesh
12 meshList=['squareWithDeformedQuadrangles_1','squareWithDeformedQuadrangles_2','squareWithDeformedQuadrangles_3','squareWithDeformedQuadrangles_4','squareWithDeformedQuadrangles_5','squareWithDeformedQuadrangles_6','squareWithDeformedQuadrangles_7']
13 meshType="Deformed_quadrangles"
15 nbMeshes=len(meshList)
16 error_tab=[0]*nbMeshes
17 mesh_size_tab=[0]*nbMeshes
18 mesh_path='../../../ressources/2DDeformedQuadrangles/'
19 mesh_name='squareWithDeformedQuadrangles'
20 diag_data=[0]*nbMeshes
23 curv_abs=np.linspace(0,sqrt(2),resolution+1)
26 # Storing of numerical errors, mesh sizes and diagonal values
27 for filename in meshList:
28 error_tab[i], mesh_size_tab[i], diag_data[i], min_sol_num, max_sol_num, time_tab[i] =FiniteVolumes2DPoisson_SQUARE.solve_file(mesh_path+filename,resolution,meshType,testColor)
29 assert min_sol_num>-0.01
30 assert max_sol_num<1.2
31 plt.plot(curv_abs, diag_data[i], label= str(mesh_size_tab[i]) + ' cells')
32 error_tab[i]=log10(error_tab[i])
33 time_tab[i]=log10(time_tab[i])
34 mesh_size_tab[i] = 0.5*log10(mesh_size_tab[i])
39 # Plot over diagonal line
41 plt.xlabel('Position on diagonal line')
42 plt.ylabel('Value on diagonal line')
43 plt.title('Plot over diagonal line for finite volumes \n for Laplace operator on 2D deformed quadrangles meshes')
44 plt.savefig(mesh_name+"_2DPoissonVF_PlotOverDiagonalLine.png")
46 # Least square linear regression
47 # Find the best a,b such that f(x)=ax+b best approximates the convergence curve
48 # The vector X=(a,b) solves a symmetric linear system AX=B with A=(a1,a2\\a2,a3), B=(b1,b2)
49 a1=np.dot(mesh_size_tab,mesh_size_tab)
50 a2=np.sum(mesh_size_tab)
52 b1=np.dot(error_tab,mesh_size_tab)
56 assert det!=0, 'test_validation2DVF_deformedQuadrangles() : Make sure you use distinct meshes and at least two meshes'
60 print( "FV on 2D deformed quadrangles mesh : scheme order is ", -a )
63 # Plot of convergence curve
65 plt.plot(mesh_size_tab, error_tab, label='log(|numerical-exact|)')
66 plt.plot(mesh_size_tab, a*np.array(mesh_size_tab)+b,label='least square slope : '+'%.3f' % a)
68 plt.xlabel('log(sqrt(number of cells))')
69 plt.ylabel('log(error)')
70 plt.title('Convergence of finite volumes \n for Laplace operator on a 2D deformed quadrangles meshes')
71 plt.savefig(mesh_name+"_2DPoissonVF_ConvergenceCurve.png")
73 # Plot of computational time
75 plt.plot(mesh_size_tab, time_tab, label='log(cpu time)')
77 plt.xlabel('log(sqrt(number of cells))')
78 plt.ylabel('log(cpu time)')
79 plt.title('Computational time of finite volumes \n for Laplace operator on 2D meshes')
80 plt.savefig(mesh_name+"_2DpoissonVF_ComputationalTime.png")
84 convergence_synthesis["Mesh_names"]=meshList
85 convergence_synthesis["Mesh_type"]=meshType
86 convergence_synthesis["Mesh_path"]=mesh_path
87 convergence_synthesis["Mesh_description"]=mesh_name
88 convergence_synthesis["Mesh_sizes"]=[10**x for x in mesh_size_tab]
89 convergence_synthesis["Space_dimension"]=2
90 convergence_synthesis["Mesh_dimension"]=2
91 convergence_synthesis["Mesh_cell_type"]="Squares"
92 convergence_synthesis["Errors"]=[10**x for x in error_tab]
93 convergence_synthesis["Scheme_order"]=-a
94 convergence_synthesis["Test_color"]=testColor
95 convergence_synthesis["Computational_time"]=end-start
97 with open('Convergence_Poisson_2DVF_'+mesh_name+'.json', 'w') as outfile:
98 json.dump(convergence_synthesis, outfile)
101 os.system("jupyter-nbconvert --to notebook --execute Convergence_Poisson_FV5_SQUARE_deformedQuadrangles.ipynb")
102 os.system("jupyter-nbconvert --to html Convergence_Poisson_FV5_SQUARE_deformedQuadrangles.ipynb")
103 os.system("jupyter-nbconvert --to pdf Convergence_Poisson_FV5_SQUARE_deformedQuadrangles.ipynb")
105 if __name__ == """__main__""":
106 test_validation2DVF_deformedQuadrangles()