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