]> SALOME platform Git repositories - tools/solverlab.git/blob
Salome HOME
de6b39b56de50838fe0a8dd5795e0d5cd95b4f43
[tools/solverlab.git] /
1 import FiniteVolumes2DPoisson_SQUARE
2 import matplotlib.pyplot as plt
3 import numpy as np
4 from math import log10,sqrt
5 import time, json
6
7 convergence_synthesis=dict(FiniteVolumes2DPoisson_SQUARE.test_desc)
8
9 def test_validation2DVF_deformedQuadrangles():
10     start = time.time()
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"
14     testColor="Green"
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
21     time_tab=[0]*nbMeshes
22     resolution=100
23     curv_abs=np.linspace(0,sqrt(2),resolution+1)
24     plt.close('all')
25     i=0
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])
35         i=i+1
36         
37     end = time.time()
38
39     # Plot over diagonal line
40     plt.legend()
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")
45
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)
51     a3=nbMeshes
52     b1=np.dot(error_tab,mesh_size_tab)   
53     b2=np.sum(error_tab)
54     
55     det=a1*a3-a2*a2
56     assert det!=0, 'test_validation2DVF_deformedQuadrangles() : Make sure you use distinct meshes and at least two meshes'
57     a=( a3*b1-a2*b2)/det
58     b=(-a2*b1+a1*b2)/det
59     
60     print( "FV on 2D deformed quadrangles mesh : scheme order is ", -a )
61     assert abs(a+1.1)<0.1
62     
63     # Plot of convergence curve
64     plt.close()
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)
67     plt.legend()
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")
72
73     # Plot of computational time
74     plt.close()
75     plt.plot(mesh_size_tab, time_tab, label='log(cpu time)')
76     plt.legend()
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")
81     
82     plt.close('all')
83
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
96
97     with open('Convergence_Poisson_2DVF_'+mesh_name+'.json', 'w') as outfile:  
98         json.dump(convergence_synthesis, outfile)
99
100     import os
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")
104
105 if __name__ == """__main__""":
106     test_validation2DVF_deformedQuadrangles()