1 import WaveSystemUpwind
2 import matplotlib.pyplot as plt
4 from math import log10, sqrt
8 def test_validation2DWaveSystemUpwindBrickWall(bctype,scaling):
10 #### 2D brick wall mesh
11 meshList=['squareWithBrickWall_1','squareWithBrickWall_2','squareWithBrickWall_3','squareWithBrickWall_4']
12 meshType="Regular brick wall"
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/2DBrickWall/'
19 mesh_name='squareWithBrickWall'
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)
32 # Storing of numerical errors, mesh sizes and diagonal values
33 for filename in meshList:
34 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)
35 assert max_vel[i]>0.002 and max_vel[i]<1
36 error_p_tab[i]=log10(error_p_tab[i])
37 error_u_tab[i]=log10(error_u_tab[i])
38 time_tab[i]=log10(time_tab[i])
43 # Plot over diagonal line
44 for i in range(nbMeshes):
45 plt.plot(curv_abs, diag_data_press[i], label= str(mesh_size_tab[i]) + ' cells')
47 plt.xlabel('Position on diagonal line')
48 plt.ylabel('Pressure on diagonal line')
49 plt.title('Plot over diagonal line for stationary wave system \n with upwind scheme on 2D brick'+"PlotOverDiagonalLine.png")
53 for i in range(nbMeshes):
54 plt.plot(curv_abs, diag_data_vel[i], label= str(mesh_size_tab[i]) + ' cells')
56 plt.xlabel('Position on diagonal line')
57 plt.ylabel('Velocity on diagonal line')
58 plt.title('Plot over diagonal line for the stationary wave system \n with upwind scheme on 2D brick wall meshes')
59 plt.savefig(mesh_name+"_Velocity_2DWaveSystemUpwind_"+"PlotOverDiagonalLine.png")
62 # Plot of number of time steps
64 plt.plot(mesh_size_tab, ndt_final, label='Number of time step to reach stationary regime')
66 plt.xlabel('Number of cells')
67 plt.ylabel('Max time steps for stationary regime')
68 plt.title('Number of times steps required for the stationary Wave System \n with upwind scheme on 2D brick wall meshes')
69 plt.savefig(mesh_name+"_2DWaveSystemUpwind_"+"TimeSteps.png")
71 # Plot of number of stationary time
73 plt.plot(mesh_size_tab, t_final, label='Time where stationary regime is reached')
75 plt.xlabel('Number of cells')
76 plt.ylabel('Max time for stationary regime')
77 plt.title('Simulated time for the stationary Wave System \n with upwind scheme on 2D brick wall meshes')
78 plt.savefig(mesh_name+"_2DWaveSystemUpwind_"+"TimeFinal.png")
80 # Plot of number of maximal velocity norm
82 plt.plot(mesh_size_tab, max_vel, label='Maximum velocity norm')
84 plt.xlabel('Number of cells')
85 plt.ylabel('Max velocity norm')
86 plt.title('Maximum velocity norm for the stationary Wave System \n with upwind scheme on 2D brick wall meshes')
87 plt.savefig(mesh_name+"_2DWaveSystemUpwind_"+"MaxVelNorm.png")
89 for i in range(nbMeshes):
90 mesh_size_tab[i]=0.5*log10(mesh_size_tab[i])
92 # Least square linear regression
93 # Find the best a,b such that f(x)=ax+b best approximates the convergence curve
94 # The vector X=(a,b) solves a symmetric linear system AX=B with A=(a1,a2\\a2,a3), B=(b1,b2)
95 a1=np.dot(mesh_size_tab,mesh_size_tab)
96 a2=np.sum(mesh_size_tab)
100 assert det!=0, 'test_validation2DWaveSystemUpwindBrickWallFV() : Make sure you use distinct meshes and at least two meshes'
102 b1p=np.dot(error_p_tab,mesh_size_tab)
103 b2p=np.sum(error_p_tab)
104 ap=( a3*b1p-a2*b2p)/det
105 bp=(-a2*b1p+a1*b2p)/det
107 print("FV upwind on 2D brick wall meshes : scheme order for pressure is ", -ap)
109 b1u=np.dot(error_u_tab,mesh_size_tab)
110 b2u=np.sum(error_u_tab)
111 au=( a3*b1u-a2*b2u)/det
112 bu=(-a2*b1u+a1*b2u)/det
114 print("FV upwind on 2D brick wall meshes : scheme order for velocity is ", -au)
116 # Plot of convergence curves
118 plt.plot(mesh_size_tab, error_p_tab, label='|error on stationary pressure|')
120 plt.xlabel('1/2 log(number of cells)')
121 plt.ylabel('log(error p)')
122 plt.title('Convergence of finite volumes for the stationary Wave System \n with upwind scheme on 2D brick wall meshes')
123 plt.savefig(mesh_name+"_Pressure_2DWaveSystemUpwind_"+"ConvergenceCurve.png")
126 plt.plot(mesh_size_tab, error_u_tab, label='|error on stationary velocity|')
128 plt.xlabel('1/2 log(number of cells)')
129 plt.ylabel('log(error u)')
130 plt.title('Convergence of finite volumes for the stationary Wave System \n with upwind scheme on 2D brick wall meshes')
131 plt.savefig(mesh_name+"_Velocity_2DWaveSystemUpwind_"+"ConvergenceCurve.png")
133 # Plot of computational time
135 plt.plot(mesh_size_tab, time_tab, label='log(cpu time)')
137 plt.xlabel('1/2 log(number of cells)')
138 plt.ylabel('log(cpu time)')
139 plt.title('Computational time of finite volumes for the stationary Wave System \n with upwind scheme on 2D brick wall meshes')
140 plt.savefig(mesh_name+"_2DWaveSystemUpwind_ComputationalTime.png")
144 convergence_synthesis={}
146 convergence_synthesis["PDE_model"]="Wave system"
147 convergence_synthesis["PDE_is_stationary"]=False
148 convergence_synthesis["PDE_search_for_stationary_solution"]=True
149 convergence_synthesis["Numerical_method_name"]="Upwind"
150 convergence_synthesis["Numerical_method_space_discretization"]="Finite volumes"
151 convergence_synthesis["Numerical_method_time_discretization"]="Implicit"
152 convergence_synthesis["Initial_data"]="Constant pressure, divergence free velocity"
153 convergence_synthesis["Boundary_conditions"]="Periodic"
154 convergence_synthesis["Numerical_parameter_cfl"]=cfl
155 convergence_synthesis["Space_dimension"]=2
156 convergence_synthesis["Mesh_dimension"]=2
157 convergence_synthesis["Mesh_names"]=meshList
158 convergence_synthesis["Mesh_type"]=meshType
159 convergence_synthesis["Mesh_path"]=mesh_path
160 convergence_synthesis["Mesh_description"]=mesh_name
161 convergence_synthesis["Mesh_sizes"]=mesh_size_tab
162 convergence_synthesis["Mesh_cell_type"]="Squares"
163 convergence_synthesis["Numerical_error_velocity"]=error_u_tab
164 convergence_synthesis["Numerical_error_pressure"]=error_p_tab
165 convergence_synthesis["Max_vel_norm"]=max_vel
166 convergence_synthesis["Final_time"]=t_final
167 convergence_synthesis["Final_time_step"]=ndt_final
168 convergence_synthesis["Scheme_order"]=min(-au,-ap)
169 convergence_synthesis["Scheme_order_vel"]=-au
170 convergence_synthesis["Scheme_order_press"]=-ap
171 convergence_synthesis["Scaling_preconditioner"]="None"
172 convergence_synthesis["Test_color"]=testColor
173 convergence_synthesis["Computational_time"]=end-start
175 with open('Convergence_WaveSystem_2DFV_Upwind_'+mesh_name+'.json', 'w') as outfile:
176 json.dump(convergence_synthesis, outfile)
178 if __name__ == """__main__""":
179 if len(sys.argv) >2 :
181 scaling = int(sys.argv[2])
182 test_validation2DWaveSystemUpwindBrickWall(bctype,scaling)
184 raise ValueError("test_validation2DWaveSystemUpwindBrickWall.py expects a mesh file name and a scaling parameter")