2 import matplotlib.pyplot as plt
4 from math import log10, sqrt
8 def test_validation2DWaveSystemPStagCheckerboard(scaling):
10 #### 2D checkerboard mesh
11 meshList=['checkerboard_5x5','checkerboard_9x9','checkerboard_17x17','checkerboard_33x33']#,'checkerboard_65x65'
12 meshType="Regular checkerboard"
14 nbMeshes=len(meshList)
15 error_p_tab=[0]*nbMeshes
16 error_u_tab=[0]*nbMeshes
17 mesh_size_tab=[0]*nbMeshes
18 mesh_path='../../../ressources/2DCheckerboard/'
19 mesh_name='squareWithCheckerboard'
20 diag_data_press=[0]*nbMeshes
21 diag_data_vel=[0]*nbMeshes
24 ndt_final=[0]*nbMeshes
27 curv_abs=np.linspace(0,sqrt(2),resolution+1)
28 cond_number=[0]*nbMeshes
33 # Storing of numerical errors, mesh sizes and diagonal values
34 for filename in meshList:
35 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], cond_number[i] =WaveSystemPStag.solve_file(mesh_path+filename, mesh_name, resolution,scaling,meshType,testColor,cfl,"Periodic")
36 assert max_vel[i]>0.2 and max_vel[i]<1.3
37 error_p_tab[i]=log10(error_p_tab[i])
38 error_u_tab[i]=log10(error_u_tab[i])
39 time_tab[i]=log10(time_tab[i])
44 # Plot over diagonal line
45 for i in range(nbMeshes):
47 plt.plot(curv_abs, diag_data_press[i], label= str(mesh_size_tab[i]) + ' cells - no scaling')
49 plt.plot(curv_abs, diag_data_press[i], label= str(mesh_size_tab[i]) + ' cells - with scaling')
51 plt.xlabel('Position on diagonal line')
52 plt.ylabel('Pressure on diagonal line')
53 plt.title('Plot over diagonal line for stationary wave system \n with pseudo staggered scheme on 2D checkerboard meshes')
54 plt.savefig(mesh_name+'_Pressure_2DWaveSystemPStag_'+"scaling"+str(scaling)+"_PlotOverDiagonalLine.png")
58 for i in range(nbMeshes):
60 plt.plot(curv_abs, diag_data_vel[i], label= str(mesh_size_tab[i]) + ' cells - no scaling')
62 plt.plot(curv_abs, diag_data_vel[i], label= str(mesh_size_tab[i]) + ' cells - with scaling')
64 plt.xlabel('Position on diagonal line')
65 plt.ylabel('Velocity on diagonal line')
66 plt.title('Plot over diagonal line for the stationary wave system \n with pseudo staggered scheme on 2D checkerboard meshes')
67 plt.savefig(mesh_name+"_Velocity_2DWaveSystemPStag_"+"scaling"+str(scaling)+"_PlotOverDiagonalLine.png")
70 # Plot of number of time steps
73 plt.plot(mesh_size_tab, ndt_final, label='Number of time step to reach stationary regime - no scaling')
75 plt.plot(mesh_size_tab, ndt_final, label='Number of time step to reach stationary regime - with scaling')
77 plt.xlabel('Number of cells')
78 plt.ylabel('Max time steps for stationary regime')
79 plt.title('Number of times steps required for the stationary Wave System \n with pseudo staggered scheme on 2D checkerboard meshes')
80 plt.savefig(mesh_name+"_2DWaveSystemPStag_"+"scaling"+str(scaling)+"_TimeSteps.png")
82 # Plot of number of stationary time
85 plt.plot(mesh_size_tab, t_final, label='Time where stationary regime is reached - no scaling')
87 plt.plot(mesh_size_tab, t_final, label='Time where stationary regime is reached - with scaling')
89 plt.xlabel('Number of cells')
90 plt.ylabel('Max time for stationary regime')
91 plt.title('Simulated time for the stationary Wave System \n with pseudo staggered scheme on 2D checkerboard meshes')
92 plt.savefig(mesh_name+"_2DWaveSystemPStag_"+"scaling"+str(scaling)+"TimeFinal.png")
94 # Plot of number of maximal velocity norm
97 plt.plot(mesh_size_tab, max_vel, label='Maximum velocity norm - no scaling')
99 plt.plot(mesh_size_tab, max_vel, label='Maximum velocity norm - with scaling')
101 plt.xlabel('Number of cells')
102 plt.ylabel('Max velocity norm')
103 plt.title('Maximum velocity norm for the stationary Wave System \n with pseudo staggered scheme on 2D checkerboard meshes')
104 plt.savefig(mesh_name+"_2DWaveSystemCPStag_"+"scaling"+str(scaling)+"_MaxVelNorm.png")
106 # Plot of condition number
109 plt.plot(mesh_size_tab, cond_number, label='Condition number - no scaling')
111 plt.plot(mesh_size_tab, cond_number, label='Condition number - with scaling')
113 plt.xlabel('Number of cells')
114 plt.ylabel('Condition number')
115 plt.title('Condition number for the stationary Wave System \n with pseudo staggered scheme on 2D square meshes')
116 plt.savefig(mesh_name+"_2DWaveSystemPStag_"+"scaling"+str(scaling)+"_condition_number.png")
118 for i in range(nbMeshes):
119 mesh_size_tab[i]=0.5*log10(mesh_size_tab[i])
121 # Least square linear regression
122 # Find the best a,b such that f(x)=ax+b best approximates the convergence curve
123 # The vector X=(a,b) solves a symmetric linear system AX=B with A=(a1,a2\\a2,a3), B=(b1,b2)
124 a1=np.dot(mesh_size_tab,mesh_size_tab)
125 a2=np.sum(mesh_size_tab)
129 assert det!=0, 'test_validation2DWaveSystemPStagCheckerboardFV() : Make sure you use distinct meshes and at least two meshes'
131 b1p=np.dot(error_p_tab,mesh_size_tab)
132 b2p=np.sum(error_p_tab)
133 ap=( a3*b1p-a2*b2p)/det
134 bp=(-a2*b1p+a1*b2p)/det
137 print("FV pseudo staggered on 2D checkerboard meshes : scheme order for pressure without scaling is ", -ap)
139 print("FV pseudo staggered on 2D checkerboard meshes : scheme order for pressure with scaling is ", -ap)
141 b1u=np.dot(error_u_tab,mesh_size_tab)
142 b2u=np.sum(error_u_tab)
143 au=( a3*b1u-a2*b2u)/det
144 bu=(-a2*b1u+a1*b2u)/det
147 print("FV pseudo staggered on 2D checkerboard meshes : scheme order for velocity without scaling is ", -au)
149 print("FV pseudo staggered on 2D checkerboard meshes : scheme order for velocity with scaling is ", -au)
151 # Plot of convergence curves
154 plt.plot(mesh_size_tab, error_p_tab, label='|error on stationary pressure| - no scaling')
156 plt.plot(mesh_size_tab, error_p_tab, label='|error on stationary pressure| - with scaling')
158 plt.xlabel('1/2 log(Number of cells)')
159 plt.ylabel('log(Error p)')
160 plt.title('Convergence of finite volumes for the stationary Wave System \n with pseudo staggered scheme on 2D checkerboard meshes')
161 plt.savefig(mesh_name+"_Pressure_2DWaveSystemPStag_"+"scaling"+str(scaling)+"_ConvergenceCurve.png")
165 plt.plot(mesh_size_tab, error_u_tab, label='log(|error on stationary velocity|) - no scaling')
167 plt.plot(mesh_size_tab, error_u_tab, label='log(|error on stationary velocity|) - with scaling')
169 plt.xlabel('1/2 log(Number of cells)')
170 plt.ylabel('log(Error u)')
171 plt.title('Convergence of finite volumes for the stationary Wave System \n with pseudo staggered scheme on 2D checkerboard meshes')
172 plt.savefig(mesh_name+"_Velocity_2DWaveSystemPStag_"+"scaling"+str(scaling)+"_ConvergenceCurve.png")
174 # Plot of computational time
177 plt.plot(mesh_size_tab, time_tab, label='log(cpu time) - no scaling')
179 plt.plot(mesh_size_tab, time_tab, label='log(cpu time) - with scaling')
181 plt.xlabel('1/2 log(Number of cells)')
182 plt.ylabel('log(cpu time)')
183 plt.title('Computational time of finite volumes for the stationary Wave System \n with pseudo staggered scheme on 2D checkerboard meshes')
184 plt.savefig(mesh_name+"_2DWaveSystemPStag_"+"scaling"+str(scaling)+"_ComputationalTime.png")
188 convergence_synthesis={}
190 convergence_synthesis["PDE_model"]="Wave system"
191 convergence_synthesis["PDE_is_stationary"]=False
192 convergence_synthesis["PDE_search_for_stationary_solution"]=True
193 convergence_synthesis["Numerical_method_name"]="PStag"
194 convergence_synthesis["Numerical_method_space_discretization"]="Finite volumes"
195 convergence_synthesis["Numerical_method_time_discretization"]="Implicit"
196 convergence_synthesis["Initial_data"]="Constant pressure, divergence free velocity"
197 convergence_synthesis["Boundary_conditions"]="Periodic"
198 convergence_synthesis["Numerical_parameter_cfl"]=cfl
199 convergence_synthesis["Space_dimension"]=2
200 convergence_synthesis["Mesh_dimension"]=2
201 convergence_synthesis["Mesh_names"]=meshList
202 convergence_synthesis["Mesh_type"]=meshType
203 convergence_synthesis["Mesh_path"]=mesh_path
204 convergence_synthesis["Mesh_description"]=mesh_name
205 convergence_synthesis["Mesh_sizes"]=mesh_size_tab
206 convergence_synthesis["Mesh_cell_type"]="Squares"
207 convergence_synthesis["Numerical_error_velocity"]=error_u_tab
208 convergence_synthesis["Numerical_error_pressure"]=error_p_tab
209 convergence_synthesis["Max_vel_norm"]=max_vel
210 convergence_synthesis["Final_time"]=t_final
211 convergence_synthesis["Final_time_step"]=ndt_final
212 convergence_synthesis["Scheme_order"]=min(-au,-ap)
213 convergence_synthesis["Scheme_order_vel"]=-au
214 convergence_synthesis["Scheme_order_press"]=-ap
215 convergence_synthesis["Scaling_preconditioner"]="None"
216 convergence_synthesis["Test_color"]=testColor
217 convergence_synthesis["Computational_time"]=end-start
219 with open('Convergence_WaveSystem_2DFV_PStag_'+mesh_name+'.json', 'w') as outfile:
220 json.dump(convergence_synthesis, outfile)
222 if __name__ == """__main__""":
223 if len(sys.argv) >1 :
224 scaling = int(sys.argv[1])
225 test_validation2DWaveSystemPStagCheckerboard(scaling)
227 test_validation2DWaveSystemPStagCheckerboard(2)