1 import FiniteVolumes2DPoissonStiffBC_DISK
2 import matplotlib.pyplot as plt
4 from math import log10, sqrt
7 convergence_synthesis=dict(FiniteVolumes2DPoissonStiffBC_DISK.test_desc)
9 def test_validation2DVF_StiffBC_hexagons():
11 #### 2D FV hexagon mesh of a disk
12 meshList=['diskWithHexagons_1','diskWithHexagons_2','diskWithHexagons_3','diskWithHexagons_4','diskWithHexagons_5']
13 meshType="Structured_hexagons"
15 nbMeshes=len(meshList)
16 error_tab=[0]*nbMeshes
17 mesh_size_tab=[0]*nbMeshes
18 mesh_path='../../../ressources/2DDiskWithHexagons/'
19 mesh_name='diskWithHexagons'
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_DISK.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 disk with hexagon 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 disk with hexagon 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_hexagons() : Make sure you use distinct meshes and at least two meshes'
75 print( "FV on 2D disk with hexagonal mesh : l2 scheme order is ", -a )
76 assert abs(a+1.12)<0.01
77 # Plot of convergence curves
79 plt.plot(mesh_size_tab, error_tab, label='log(|numerical-exact|)')
80 plt.plot(mesh_size_tab, a*np.array(mesh_size_tab)+b,label='least square slope : '+'%.3f' % a)
82 plt.xlabel('log(sqrt(number of nodes))')
83 plt.ylabel('log(error)')
84 plt.title('Convergence of finite volumes for Laplace operator \n on 2D disk with hexagon meshes')
85 plt.savefig(mesh_name+"_2DPoissonVF_StiffBC_ConvergenceCurve.png")
87 # Plot of computational time
89 plt.plot(mesh_size_tab, time_tab, label='log(cpu time)')
91 plt.xlabel('log(sqrt(number of nodes))')
92 plt.ylabel('log(cpu time)')
93 plt.title('Computational time of finite volumes for Laplace operator \n on 2D disk with hexagon meshes')
94 plt.savefig(mesh_name+"_2DPoissonVF_StiffBC_ComputationalTime.png")
98 convergence_synthesis["Mesh_names"]=meshList
99 convergence_synthesis["Mesh_type"]=meshType
100 convergence_synthesis["Mesh_path"]=mesh_path
101 convergence_synthesis["Mesh_description"]=mesh_name
102 convergence_synthesis["Mesh_sizes"]=[10**x for x in mesh_size_tab]
103 convergence_synthesis["Space_dimension"]=2
104 convergence_synthesis["Mesh_dimension"]=2
105 convergence_synthesis["Mesh_cell_type"]="Squares"
106 convergence_synthesis["Errors"]=[10**x for x in error_tab]
107 convergence_synthesis["Scheme_order"]=-a
108 convergence_synthesis["Test_color"]=testColor
109 convergence_synthesis["Computational_time"]=end-start
111 with open('Convergence_PoissonStiffBC_2DFV_'+mesh_name+'.json', 'w') as outfile:
112 json.dump(convergence_synthesis, outfile)
114 if __name__ == """__main__""":
115 test_validation2DVF_StiffBC_hexagons()