5 import matplotlib.pyplot as plt
7 from math import log10, sqrt
12 def test_validation2DWaveSystemPStagSquares_DISK(bctype,scaling):
15 meshList=['diskWithSquares_1','diskWithSquares_2']#,'diskWithSquares_3','diskWithSquares_4','diskWithSquares_5'
16 mesh_path='../../../ressources/2DdiskWithSquares/'
17 meshType="Regular squares"
18 testColor="Red : Wall -> no stationary state reached, if BC changed to Neuman -> unstable scheme"
19 nbMeshes=len(meshList)
20 error_p_tab=[0]*nbMeshes
21 error_u_tab=[0]*nbMeshes
22 mesh_size_tab=[0]*nbMeshes
23 mesh_name='diskWithSquares'
24 diag_data_press=[0]*nbMeshes
25 diag_data_vel=[0]*nbMeshes
28 ndt_final=[0]*nbMeshes
31 curv_abs=np.linspace(0,sqrt(2),resolution+1)
32 cond_number=[0]*nbMeshes
37 # Storing of numerical errors, mesh sizes and diagonal values
38 for filename in meshList:
39 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,bctype)
40 assert max_vel[i]>0.76 and max_vel[i]<1.5
41 error_p_tab[i]=log10(error_p_tab[i])
42 error_u_tab[i]=log10(error_u_tab[i])
43 time_tab[i]=log10(time_tab[i])
48 # Plot of condition number
51 plt.plot(mesh_size_tab, cond_number, label='Condition number - no scaling')
53 plt.plot(mesh_size_tab, cond_number, label='Condition number - with scaling')
55 plt.xlabel('Number of cells')
56 plt.ylabel('Condition number')
57 plt.title('Condition number for the stationary Wave System \n with pseudo staggered scheme on 2D square meshes')
58 plt.savefig(mesh_name+"_2DWaveSystemCentered_"+"scaling"+str(scaling)+"_condition_number.png")
60 # Plot over diagonal line
61 for i in range(nbMeshes):
62 plt.plot(curv_abs, diag_data_press[i], label= str(mesh_size_tab[i]) + ' cells')
64 plt.xlabel('Position on diagonal line')
65 plt.ylabel('Pressure on diagonal line')
66 plt.title('Plot over diagonal line for stationary wave system \n with pseudo staggered scheme on 2D DISK with square meshes')
67 plt.savefig(mesh_name+'_Pressure_2DWaveSystemPStag_DISK_'+"PlotOverDiagonalLine.png")
71 for i in range(nbMeshes):
72 plt.plot(curv_abs, diag_data_vel[i], label= str(mesh_size_tab[i]) + ' cells')
74 plt.xlabel('Position on diagonal line')
75 plt.ylabel('Velocity on diagonal line')
76 plt.title('Plot over diagonal line for the stationary wave system \n with pseudo staggered scheme on 2D DISK with square meshes')
77 plt.savefig(mesh_name+"_Velocity_2DWaveSystemPStag_DISK_"+"PlotOverDiagonalLine.png")
80 # Plot of number of time steps
82 plt.plot(mesh_size_tab, ndt_final, label='Number of time step to reach stationary regime')
84 plt.xlabel('number of cells')
85 plt.ylabel('Max time steps for stationary regime')
86 plt.title('Number of times steps required for the stationary Wave System \n with pseudo staggered scheme on 2D DISK with square meshes')
87 plt.savefig(mesh_name+"_2DWaveSystemPStag_DISK_"+"TimeSteps.png")
89 # Plot of number of stationary time
91 plt.plot(mesh_size_tab, t_final, label='Time where stationary regime is reached')
93 plt.xlabel('number of cells')
94 plt.ylabel('Max time for stationary regime')
95 plt.title('Simulated time for the stationary Wave System \n with pseudo staggered scheme on 2D DISK with square meshes')
96 plt.savefig(mesh_name+"_2DWaveSystemPStag_DISK_"+"TimeFinal.png")
98 # Plot of number of maximal velocity norm
100 plt.plot(mesh_size_tab, max_vel, label='Maximum velocity norm')
102 plt.xlabel('number of cells')
103 plt.ylabel('Max velocity norm')
104 plt.title('Maximum velocity norm for the stationary Wave System \n with pseudo staggered scheme on 2D DISK with square meshes')
105 plt.savefig(mesh_name+"_2DWaveSystemPStag_DISK_"+"MaxVelNorm.png")
107 for i in range(nbMeshes):
108 mesh_size_tab[i]=0.5*log10(mesh_size_tab[i])
110 # Least square linear regression
111 # Find the best a,b such that f(x)=ax+b best approximates the convergence curve
112 # The vector X=(a,b) solves a symmetric linear system AX=B with A=(a1,a2\\a2,a3), B=(b1,b2)
113 a1=np.dot(mesh_size_tab,mesh_size_tab)
114 a2=np.sum(mesh_size_tab)
118 assert det!=0, 'test_validation2DWaveSystemPStag_DISK_squares() : Make sure you use distinct meshes and at least two meshes'
120 b1p=np.dot(error_p_tab,mesh_size_tab)
121 b2p=np.sum(error_p_tab)
122 ap=( a3*b1p-a2*b2p)/det
123 bp=(-a2*b1p+a1*b2p)/det
125 print( "FV pseudo staggered on 2D DISK with square meshes : scheme order for pressure is ", -ap)
127 b1u=np.dot(error_u_tab,mesh_size_tab)
128 b2u=np.sum(error_u_tab)
129 au=( a3*b1u-a2*b2u)/det
130 bu=(-a2*b1u+a1*b2u)/det
132 print( "FV pseudo staggered on 2D DISK with square meshes : scheme order for velocity is ", -au)
134 # Plot of convergence curves
136 plt.plot(mesh_size_tab, error_p_tab, label='|error on stationary pressure|')
138 plt.xlabel('1/2 log(number of cells)')
139 plt.ylabel('|error p|')
140 plt.title('Convergence of finite volumes for the stationary Wave System \n with pseudo staggered scheme on 2D DISK with square meshes')
141 plt.savefig(mesh_name+"_Pressure_2DWaveSystemPStag_DISK_"+"ConvergenceCurve.png")
144 plt.plot(mesh_size_tab, error_u_tab, label='log(|error on stationary velocity|)')
146 plt.xlabel('1/2 log(number of cells)')
147 plt.ylabel('log(|error u|)')
148 plt.title('Convergence of finite volumes for the stationary Wave System\n with pseudo staggered scheme on 2D DISK with square meshes')
149 plt.savefig(mesh_name+"_Velocity_2DWaveSystemPStag_DISK_"+"ConvergenceCurve.png")
151 # Plot of computational time
153 plt.plot(mesh_size_tab, time_tab, label='log(cpu time)')
155 plt.xlabel('1/2 log(number of cells)')
156 plt.ylabel('log(cpu time)')
157 plt.title('Computational time of finite volumes for the stationary Wave System \n with pseudo staggered scheme on 2D DISK with square meshes')
158 plt.savefig(mesh_name+"_2DWaveSystemPStag_DISK_ComputationalTimeSquares.png")
162 convergence_synthesis={}
164 convergence_synthesis["PDE_model"]="Wave system"
165 convergence_synthesis["PDE_is_stationary"]=False
166 convergence_synthesis["PDE_search_for_stationary_solution"]=True
167 convergence_synthesis["Numerical_method_name"]="PStag"
168 convergence_synthesis["Numerical_method_space_discretization"]="Finite volumes"
169 convergence_synthesis["Numerical_method_time_discretization"]="Implicit"
170 convergence_synthesis["Initial_data"]="Disk vortex (Constant pressure, divergence free velocity)"
171 convergence_synthesis["Boundary_conditions"]="Periodic"
172 convergence_synthesis["Numerical_parameter_cfl"]=cfl
173 convergence_synthesis["Space_dimension"]=2
174 convergence_synthesis["Mesh_dimension"]=2
175 convergence_synthesis["Mesh_names"]=meshList
176 convergence_synthesis["Mesh_type"]=meshType
177 convergence_synthesis["Mesh_path"]=mesh_path
178 convergence_synthesis["Mesh_description"]=mesh_name
179 convergence_synthesis["Mesh_sizes"]=mesh_size_tab
180 convergence_synthesis["Mesh_cell_type"]="Squares"
181 convergence_synthesis["Numerical_error_velocity"]=error_u_tab
182 convergence_synthesis["Numerical_error_pressure"]=error_p_tab
183 convergence_synthesis["Max_vel_norm"]=max_vel
184 convergence_synthesis["Final_time"]=t_final
185 convergence_synthesis["Final_time_step"]=ndt_final
186 convergence_synthesis["Scheme_order"]=min(-au,-ap)
187 convergence_synthesis["Scheme_order_vel"]=-au
188 convergence_synthesis["Scheme_order_press"]=-ap
189 convergence_synthesis["Scaling_preconditioner"]="None"
190 convergence_synthesis["Test_color"]=testColor
191 convergence_synthesis["Computational_time"]=end-start
193 with open('Convergence_WaveSystem_2DFV_PStag_DISK_'+mesh_name+'.json', 'w') as outfile:
194 json.dump(convergence_synthesis, outfile)
196 if __name__ == """__main__""":
197 if len(sys.argv) >2 :
199 scaling = int(sys.argv[2])
200 test_validation2DWaveSystemPStagSquares_DISK(bctype,scaling)
202 raise ValueError("test_validation2DWaveSystemPStagSquares_DISK.py expects a mesh file name and a scaling parameter")