]> SALOME platform Git repositories - tools/solverlab.git/blob
Salome HOME
de446e9c0c8d5a40ab51a4421c96007372ba9e65
[tools/solverlab.git] /
1 import cdmath
2 import WaveSystemUpwind
3 import matplotlib
4 matplotlib.use("Agg")
5 import matplotlib.pyplot as plt
6 import numpy as np
7 from math import log10, sqrt
8 import sys
9 import time, json
10
11
12 def test_validation3DWaveSystemUpwindTetrahedra(bctype,scaling):
13     start = time.time()
14     #### 3D tetrahedral mesh of a cartesian mesh
15     #meshList=[5,11,21,26]
16     meshList=['meshCubeTetrahedra_0','meshCubeTetrahedra_1','meshCubeTetrahedra_2','meshCubeTetrahedra_3','meshCubeTetrahedra_4']
17     mesh_path='../../../ressources/3DTetrahedra/'
18     meshType="Unstructured tetrahedra"
19     testColor="Green"
20     nbMeshes=len(meshList)
21     error_p_tab=[0]*nbMeshes
22     error_u_tab=[0]*nbMeshes
23     mesh_size_tab=[0]*nbMeshes
24     mesh_name='CubeWithTetrahedra'
25     diag_data_press=[0]*nbMeshes
26     diag_data_vel=[0]*nbMeshes
27     time_tab=[0]*nbMeshes
28     t_final=[0]*nbMeshes
29     ndt_final=[0]*nbMeshes
30     max_vel=[0]*nbMeshes
31     resolution=100
32     curv_abs=np.linspace(0,sqrt(3),resolution+1)
33
34     plt.close('all')
35     i=0
36     cfl=1./3
37     
38     # Storing of numerical errors, mesh sizes and diagonal values
39     for filename in meshList:
40     #for nx in meshList:
41         #my_mesh=cdmath.Mesh(0.,1.,nx,0.,1.,nx,0.,1.,nx,6)
42         #error_p_tab[i], error_u_tab[i], mesh_size_tab[i], t_final[i], ndt_final[i], max_vel[i], diag_data_press[i], diag_data_vel[i], time_tab[i] =WaveSystemUpwind.solve(my_mesh, mesh_name+str(my_mesh.getNumberOfCells()), resolution,scaling,meshType,testColor,cfl,bctype)
43         error_p_tab[i], error_u_tab[i], mesh_size_tab[i], t_final[i], ndt_final[i], max_vel[i], diag_data_press[i], diag_data_vel[i], time_tab[i] =WaveSystemUpwind.solve_file(mesh_path+filename, mesh_name, resolution,scaling,meshType,testColor,cfl,bctype)
44         assert max_vel[i]>1.7 and max_vel[i]<2
45         error_p_tab[i]=log10(error_p_tab[i])
46         error_u_tab[i]=log10(error_u_tab[i])
47         i=i+1
48     
49     end = time.time()
50
51     # Plot over diagonal line
52     for i in range(nbMeshes):
53         plt.plot(curv_abs, diag_data_press[i], label= str(mesh_size_tab[i]) + ' cells')
54     plt.legend()
55     plt.xlabel('Position on diagonal line')
56     plt.ylabel('Pressure on diagonal line')
57     plt.title('Plot over diagonal line for stationary wave system \n on 3D tetrahedral meshes')
58     plt.savefig(mesh_name+'_Pressure_3DWaveSystemUpwind_'+"PlotOverDiagonalLine.png")
59     plt.close()
60
61     plt.clf()
62     for i in range(nbMeshes):
63         plt.plot(curv_abs, diag_data_vel[i],   label= str(mesh_size_tab[i]) + ' cells')
64     plt.legend()
65     plt.xlabel('Position on diagonal line')
66     plt.ylabel('Velocity on diagonal line')
67     plt.title('Plot over diagonal line for the stationary wave system \n on 3D tetrahedral meshes')
68     plt.savefig(mesh_name+"_Velocity_3DWaveSystemUpwind_"+"PlotOverDiagonalLine.png")    
69     plt.close()
70
71     # Plot of number of time steps
72     plt.close()
73     plt.plot(mesh_size_tab, ndt_final, label='Number of time step to reach stationary regime')
74     plt.legend()
75     plt.xlabel('number of cells')
76     plt.ylabel('Max time steps for stationary regime')
77     plt.title('Number of times steps required \n for the stationary Wave System on 3D tetrahedral meshes')
78     plt.savefig(mesh_name+"_3DWaveSystemUpwind_"+"TimeSteps.png")
79     
80     # Plot of time where stationary regime is reached
81     plt.close()
82     plt.plot(mesh_size_tab, t_final, label='Time where stationary regime is reached')
83     plt.legend()
84     plt.xlabel('number of cells')
85     plt.ylabel('Max time for stationary regime')
86     plt.title('Simulated time  \n for the stationary Wave System on 3D tetrahedral meshes')
87     plt.savefig(mesh_name+"_3DWaveSystemUpwind_"+"TimeFinal.png")
88     
89     # Plot of maximal velocity norm
90     plt.close()
91     plt.plot(mesh_size_tab, max_vel, label='Maximum velocity norm')
92     plt.legend()
93     plt.xlabel('number of cells')
94     plt.ylabel('Max velocity norm')
95     plt.title('Maximum velocity norm  \n for the stationary Wave System on 3D tetrahedral meshes')
96     plt.savefig(mesh_name+"_3DWaveSystemUpwind_"+"MaxVelNorm.png")
97     
98        
99     for i in range(nbMeshes):
100         mesh_size_tab[i] = 0.5*log10(mesh_size_tab[i])
101
102     # Least square linear regression
103     # Find the best a,b such that f(x)=ax+b best approximates the convergence curve
104     # The vector X=(a,b) solves a symmetric linear system AX=B with A=(a1,a2\\a2,a3), B=(b1,b2)
105     a1=np.dot(mesh_size_tab,mesh_size_tab)
106     a2=np.sum(mesh_size_tab)
107     a3=nbMeshes
108     
109     det=a1*a3-a2*a2
110     assert det!=0, 'test_validation3DWaveSystemUpwindSquaresFV() : Make sure you use distinct meshes and at least two meshes'
111
112     b1p=np.dot(error_p_tab,mesh_size_tab)   
113     b2p=np.sum(error_p_tab)
114     ap=( a3*b1p-a2*b2p)/det
115     bp=(-a2*b1p+a1*b2p)/det
116     
117     print("FV on 3D tetrahedral meshes : scheme order for pressure is ", -ap)
118
119     b1u=np.dot(error_u_tab,mesh_size_tab)   
120     b2u=np.sum(error_u_tab)
121     au=( a3*b1u-a2*b2u)/det
122     bu=(-a2*b1u+a1*b2u)/det
123     
124     print("FV on 3D tetrahedral meshes : scheme order for velocity is ", -au)
125     
126     # Plot of convergence curves
127     plt.close()
128     plt.plot(mesh_size_tab, error_p_tab, label='|error on stationary pressure|')
129     plt.legend()
130     plt.xlabel('number of cells')
131     plt.ylabel('error p')
132     plt.title('Convergence of finite volumes for \n the stationary Wave System on 3D tetrahedral meshes')
133     plt.savefig(mesh_name+"_Pressure_3DWaveSystemUpwind_"+"ConvergenceCurve.png")
134     
135     plt.close()
136     plt.plot(mesh_size_tab, error_u_tab, label='|error on stationary velocity|')
137     plt.legend()
138     plt.xlabel('number of cells')
139     plt.ylabel('error p')
140     plt.title('Convergence of finite volumes for \n the stationary Wave System on 3D tetrahedral meshes')
141     plt.savefig(mesh_name+"_Velocity_3DWaveSystemUpwind_"+"ConvergenceCurve.png")
142     
143     # Plot of computational time
144     plt.close()
145     plt.plot(mesh_size_tab, time_tab, label='log(cpu time)')
146     plt.legend()
147     plt.xlabel('number of cells')
148     plt.ylabel('cpu time')
149     plt.title('Computational time of finite volumes \n for the stationary Wave System on 3D tetrahedral meshes')
150     plt.savefig(mesh_name+"_3DWaveSystemUpwind_"+"_scaling_"+str(scaling)+"_ComputationalTime.png")
151     
152     plt.close('all')
153     
154
155     convergence_synthesis={}
156
157     convergence_synthesis["PDE_model"]="Wave system"
158     convergence_synthesis["PDE_is_stationary"]=False
159     convergence_synthesis["PDE_search_for_stationary_solution"]=True
160     convergence_synthesis["Numerical_method_name"]="Upwind"
161     convergence_synthesis["Numerical_method_space_discretization"]="Finite volumes"
162     convergence_synthesis["Numerical_method_time_discretization"]="Implicit"
163     convergence_synthesis["Initial_data"]="Constant pressure, divergence free velocity"
164     convergence_synthesis["Boundary_conditions"]="Periodic"
165     convergence_synthesis["Numerical_parameter_cfl"]=cfl
166     convergence_synthesis["Space_dimension"]=3
167     convergence_synthesis["Mesh_dimension"]=3
168     convergence_synthesis["Mesh_names"]=meshList
169     convergence_synthesis["Mesh_type"]=meshType
170     #convergence_synthesis["Mesh_path"]=mesh_path
171     convergence_synthesis["Mesh_description"]=mesh_name
172     convergence_synthesis["Mesh_sizes"]=mesh_size_tab
173     convergence_synthesis["Mesh_cell_type"]="Tetrahedra"
174     convergence_synthesis["Numerical_error_velocity"]=error_u_tab
175     convergence_synthesis["Numerical_error_pressure"]=error_p_tab
176     convergence_synthesis["Max_vel_norm"]=max_vel
177     convergence_synthesis["Final_time"]=t_final  
178     convergence_synthesis["Final_time_step"]=ndt_final  
179     convergence_synthesis["Scheme_order"]=min(-au,-ap)
180     convergence_synthesis["Scheme_order_vel"]=-au
181     convergence_synthesis["Scheme_order_press"]=-ap
182     convergence_synthesis["Scaling_preconditioner"]="None"
183     convergence_synthesis["Test_color"]=testColor
184     convergence_synthesis["Computational_time"]=end-start
185
186     with open('Convergence_WaveSystem_3DFV_Upwind_'+mesh_name+"_scaling_"+str(scaling)+'.json', 'w') as outfile:  
187         json.dump(convergence_synthesis, outfile)
188
189 if __name__ == """__main__""":
190     if len(sys.argv) >2 :
191         bctype = sys.argv[1]
192         scaling = int(sys.argv[2])
193         test_validation3DWaveSystemUpwindTetrahedra(bctype,scaling)
194     else :
195         raise ValueError("test_validation3DWaveSystemUpwindTetrahedra.py expects a mesh file name and a scaling parameter")