1 import FiniteVolumes2DPoissonStiffBC_SQUARE
2 import matplotlib.pyplot as plt
4 from math import log10, sqrt
7 convergence_synthesis=dict(FiniteVolumes2DPoissonStiffBC_SQUARE.test_desc)
9 def test_validation2DVF_StiffBC_equilateralTriangles():
11 #### 2D FV equilateral triangle mesh of a square
12 meshList=['squareWithEquilateralTriangles5','squareWithEquilateralTriangles20','squareWithEquilateralTriangles50','squareWithEquilateralTriangles100','squareWithEquilateralTriangles200']
13 meshType="Regular_triangles"
15 nbMeshes=len(meshList)
16 error_tab=[0]*nbMeshes
17 mesh_size_tab=[0]*nbMeshes
18 mesh_path='../../../ressources/2DEquilateralTriangles/'
19 mesh_name='squareWithEquilateralTriangles'
20 diag_data=[0]*nbMeshes
25 curv_abs=np.linspace(0,sqrt(2),resolution+1)
28 # Storing of numerical errors, mesh sizes and diagonal values
29 for filename in meshList:
30 error_tab[i], mesh_size_tab[i], diag_data[i], min_tab[i], max_tab[i], time_tab[i] =FiniteVolumes2DPoissonStiffBC_SQUARE.solve_file(mesh_path+filename, resolution, mesh_name, testColor)
31 assert min_tab[i]>-1.6
33 plt.plot(curv_abs, diag_data[i], label= str(mesh_size_tab[i]) + ' nodes')
34 error_tab[i]=log10(error_tab[i])
35 time_tab[i]=log10(time_tab[i])
40 # Plot over diagonal line
42 plt.xlabel('Position on diagonal line')
43 plt.ylabel('Value on diagonal line')
44 plt.title('Plot over diagonal line for finite volumes for Laplace operator \n on 2D square with equilateral triangle meshes')
45 plt.savefig(mesh_name+"_2DPoissonVF_StiffBC_PlotOverDiagonalLine.png")
48 # Plot of min and max curves
50 plt.plot(mesh_size_tab, min_tab, label='Minimum value')
51 plt.plot(mesh_size_tab, max_tab, label='Maximum value')
53 plt.xlabel('Number of nodes')
55 plt.title('Min/Max of Finite volumes for Laplace operator \n on 2D square with equilateral triangle meshes')
56 plt.savefig(mesh_name+"_2DPoissonVF_StiffBC_MinMax.png")
58 for i in range(nbMeshes):
59 mesh_size_tab[i] = 0.5*log10(mesh_size_tab[i])
61 # Least square linear regression
62 # Find the best a,b such that f(x)=ax+b best approximates the convergence curve
63 # The vector X=(a,b) solves a symmetric linear system AX=B with A=(a1,a2\\a2,a3), B=(b1,b2)
64 a1=np.dot(mesh_size_tab,mesh_size_tab)
65 a2=np.sum(mesh_size_tab)
67 b1=np.dot(error_tab,mesh_size_tab)
71 assert det!=0, 'test_validation2DVF_StiffBC_equilateralTriangles() : Make sure you use distinct meshes and at least two meshes'
75 print( "FV on 2D square with equilateral triangle mesh : l2 scheme order is ", -a )
76 assert abs(a+1.01)<0.01
78 # Plot of convergence curves
80 plt.plot(mesh_size_tab, error_tab, label='log(|numerical-exact|)')
81 plt.plot(mesh_size_tab, a*np.array(mesh_size_tab)+b,label='least square slope : '+'%.3f' % a)
83 plt.xlabel('log(sqrt(number of nodes))')
84 plt.ylabel('log(error)')
85 plt.title('Convergence of finite volumes for Laplace operator \n on 2D square with equilateral triangle meshes')
86 plt.savefig(mesh_name+"_2DPoissonVF_StiffBC_ConvergenceCurve.png")
88 # Plot of computational time
90 plt.plot(mesh_size_tab, time_tab, label='log(cpu time)')
92 plt.xlabel('log(sqrt(number of nodes))')
93 plt.ylabel('log(cpu time)')
94 plt.title('Computational time of finite volumes for Laplace operator \n on 2D square with equilateral triangle meshes')
95 plt.savefig(mesh_name+"_2DPoissonVF_StiffBC_ComputationalTime.png")
99 convergence_synthesis["Mesh_names"]=meshList
100 convergence_synthesis["Mesh_type"]=meshType
101 convergence_synthesis["Mesh_path"]=mesh_path
102 convergence_synthesis["Mesh_description"]=mesh_name
103 convergence_synthesis["Mesh_sizes"]=[10**x for x in mesh_size_tab]
104 convergence_synthesis["Space_dimension"]=2
105 convergence_synthesis["Mesh_dimension"]=2
106 convergence_synthesis["Mesh_cell_type"]="Squares"
107 convergence_synthesis["Errors"]=[10**x for x in error_tab]
108 convergence_synthesis["Scheme_order"]=-a
109 convergence_synthesis["Test_color"]=testColor
110 convergence_synthesis["Computational_time"]=end-start
112 with open('Convergence_PoissonStiffBC_2DFV_'+mesh_name+'.json', 'w') as outfile:
113 json.dump(convergence_synthesis, outfile)
115 if __name__ == """__main__""":
116 test_validation2DVF_StiffBC_equilateralTriangles()