SPEED
GET_CFL4CASES.f90
Go to the documentation of this file.
1! Copyright (C) 2012 The SPEED FOUNDATION
2! Author: Ilario Mazzieri
3!
4! This file is part of SPEED.
5!
6! SPEED is free software; you can redistribute it and/or modify it
7! under the terms of the GNU Affero General Public License as
8! published by the Free Software Foundation, either version 3 of the
9! License, or (at your option) any later version.
10!
11! SPEED is distributed in the hope that it will be useful, but
12! WITHOUT ANY WARRANTY; without even the implied warranty of
13! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14! Affero General Public License for more details.
15!
16! You should have received a copy of the GNU Affero General Public License
17! along with SPEED. If not, see <http://www.gnu.org/licenses/>.
18
38! 'not' deltat could be changed if is extremely small for the time integration
54
55 subroutine get_cfl4cases(time_step, nn_loc, loc_n_num, nm, tm, pm, sdeg, &
56 xx_loc, yy_loc, zz_loc, cs_nnz_loc, cs_loc, &
57 time_step_cfl, fmax, deltat_fixed, &
58 mpi_comm, mpi_np, mpi_id, &
59 ncase,vcase, tcase, zs_elev, zs_all, vs_tria, thick_tria, sub_tag_all, b_failCFL, &
60 damping_type, QS, QP)
61
63 use speed_par, only: label_testcase
64
65 implicit none
66
67 include 'SPEED.MPI'
68
69 character*3 :: deltat_fixed
70
71 integer*4 :: nm, im, nn_loc, cs_nnz_loc, mpi_comm, mpi_np, mpi_err, mpi_id
72 integer*4 :: ie, i, j, k, nn, mcode, smcode, sdeg_deltat_cfl, sdeg_npoints
73 integer*4 :: damping_type, ncase, icase
74 integer*4 :: nel_loc, ic1, ic2, n1, n2, istart, ifin
75
76 integer*4, dimension(1) :: pos, pos2
77 integer*4, dimension(nm) :: tm, sdeg
78 integer*4, dimension(nn_loc) :: loc_n_num
79 integer*4, dimension(nn_loc) :: sub_tag_all
80 integer*4, dimension(0:cs_nnz_loc) :: cs_loc
81 integer*4, dimension(ncase) :: tcase, vcase
82
83 real*8 :: time_step, time_step_cfl, fmax
84 real*8 :: length_min,length,vs_length_min,vs_length,length_vp_min,length_vp
85 real*8 :: percent_deltat
86 real*8 :: num_of_points,vs_npoints,vp_deltat_cfl
87 real*8 :: rho,lambda,mu,vs,vp
88 real*8 :: x1_length_vp_min,y1_length_vp_min,z1_length_vp_min
89 real*8 :: x2_length_vp_min,y2_length_vp_min,z2_length_vp_min
90
91 real*8, dimension(:), allocatable :: ct,ww
92 real*8, dimension(:), allocatable :: time_step_glo, vs_length_glo
93 real*8, dimension(nn_loc) :: xx_loc, yy_loc, zz_loc
94 real*8, dimension(nn_loc) :: zs_elev
95 real*8, dimension(nn_loc) :: zs_all
96 real*8, dimension(nn_loc) :: vs_tria, thick_tria
97
98
99 real*8, dimension(nm,4) :: pm
100 real*8, dimension(:,:), allocatable :: dd
101 real*8, dimension(nm) :: qs, qp
102
103 real*8, dimension(:,:,:), allocatable :: rho_el, lambda_el, mu_el, gamma_el
104
105 logical :: b_failCFL, b_CFL_failure = .false.
106
107 nel_loc = cs_loc(0) - 1
108
109 length_vp_min = 1.d30
110 vs_length_min = 1.d30
111 vs_npoints = 1.d30;
112
113
114 do ie = 1, nel_loc
115
116 im = cs_loc(cs_loc(ie -1) +0)
117 nn = sdeg(im) +1
118
119 allocate(rho_el(nn,nn,nn), lambda_el(nn,nn,nn),mu_el(nn,nn,nn),gamma_el(nn,nn,nn))
120
121 rho_el = pm(im,1)
122 lambda_el = pm(im,2)
123 mu_el = pm(im,3)
124 gamma_el = pm(im,4)
125
126 do icase = 1, ncase
127
128 if (vcase(icase) .eq. tm(im)) then
129 call make_eltensor_for_cases(tcase(icase), vcase(icase),&
130 nn, rho_el, lambda_el, mu_el, gamma_el,&
131 nn_loc, zs_elev, zs_all, vs_tria, thick_tria,&
132 cs_nnz_loc, cs_loc, ie,&
133 sub_tag_all, zz_loc, mpi_id, loc_n_num, &
134 damping_type, qs(im), qp(im), &
135 xx_loc, yy_loc,0,label_testcase)
136 endif
137 enddo
138
139
140 smcode=sdeg(im)
141 rho = 0.d0
142 lambda = 0.d0
143 mu = 0.d0
144
145 do i = 1, nn
146 do j = 1, nn
147 do k = 1, nn
148 rho = rho + rho_el(i,j,k)
149 lambda = lambda + lambda_el(i,j,k)
150 mu = mu + mu_el(i,j,k)
151 enddo
152 enddo
153 enddo
154
155 rho = rho/(nn**3)
156 lambda = lambda/(nn**3)
157 mu = mu/(nn**3)
158
159 vs = dsqrt(mu/rho)
160 vp = dsqrt((lambda+2*mu)/rho)
161
162 n1 = nn*nn*(1 -1) +nn*(1 -1) +1
163 n2 = nn*nn*(nn -1) +nn*(nn -1) +nn
164 istart = cs_loc(ie -1) +n1
165 ifin = cs_loc(ie -1) +n2
166
167
168 do ic1 = istart, ifin
169 do ic2 = ic1 + 1, ifin
170
171 if(cs_loc(ic1) .ne. 0 .and. cs_loc(ic2) .ne. 0) then
172
173 length=dsqrt((xx_loc(cs_loc(ic1))-xx_loc(cs_loc(ic2)))**2 + &
174 (yy_loc(cs_loc(ic1))-yy_loc(cs_loc(ic2)))**2 + &
175 (zz_loc(cs_loc(ic1))-zz_loc(cs_loc(ic2)))**2)
176
177 length_vp = length/vp
178
179 if (length_vp_min .gt. length_vp) then
180 length_vp_min = length_vp
181 x1_length_vp_min = xx_loc(cs_loc(ic1))
182 y1_length_vp_min = yy_loc(cs_loc(ic1))
183 z1_length_vp_min = zz_loc(cs_loc(ic1))
184 x2_length_vp_min = xx_loc(cs_loc(ic2))
185 y2_length_vp_min = yy_loc(cs_loc(ic2))
186 z2_length_vp_min = zz_loc(cs_loc(ic2))
187 vp_deltat_cfl = vp
188 sdeg_deltat_cfl = smcode
189 length_min = length
190 endif
191
192
193 vs_length = vs/length
194
195 if (vs_length_min.gt.vs_length) then
196 vs_length_min = vs_length
197 vs_npoints = vs
198 sdeg_npoints = smcode
199 endif
200
201 endif
202
203 enddo
204 enddo
205
206 deallocate(lambda_el, gamma_el, mu_el, rho_el)
207
208 enddo
209
210 nn = sdeg_deltat_cfl + 1
211
212 time_step_cfl = length_vp_min !/((nn-1)**2)
213
214
215 !write(*,*) mpi_id, 'id', vs_npoints
216 !call MPI_BARRIER(mpi_comm, mpi_err)
217
218
219 allocate(time_step_glo(mpi_np),vs_length_glo(mpi_np))
220
221 call mpi_barrier(mpi_comm, mpi_err)
222 call mpi_allgather(time_step_cfl, 1, speed_double, time_step_glo, 1, speed_double, mpi_comm, mpi_err)
223 call mpi_allgather(vs_length_min, 1, speed_double, vs_length_glo, 1, speed_double, mpi_comm, mpi_err)
224
225 pos = minloc(time_step_glo)
226 pos2 = minloc(vs_length_glo)
227
228 !write(*,*) mpi_id, 'id', pos2(1), vs_length_min, 'oooo',vs_length_glo
229 !call MPI_BARRIER(mpi_comm, mpi_err)
230
231 deallocate(time_step_glo, vs_length_glo)
232
233 if((mpi_id + 1) .eq. pos(1)) then
234
235 write(*,'(A)')' '
236 write(*,'(A)') '--------Stability for time advancing algorithm --------'
237 write(*,'(A,E12.4)') 'Mininum distance beteween grid nodes :', length_vp_min*vp_deltat_cfl
238 write(*,'(A,E12.4)') 'Vp for CFL condition :', vp_deltat_cfl
239 write(*,'(A,E12.4,E12.4,E12.4)')'Min. node 1 : ',x1_length_vp_min,y1_length_vp_min,z1_length_vp_min
240 write(*,'(A,E12.4,E12.4,E12.4)')'Min. node 2 : ',x2_length_vp_min,y2_length_vp_min,z2_length_vp_min
241 write(*,'(A)') '-------------------------------------------------------'
242
243 if (time_step.le.time_step_cfl) then
244 percent_deltat=time_step/time_step_cfl*100
245 if (percent_deltat.le.1) then
246 write(*,'(A,E12.4)')'WARNING!!! deltat CFL =',&
247 time_step_cfl
248 write(*,'(A,F6.2,A)')'You are using ',percent_deltat,&
249 '% of critical time step.'
250 write(*,'(A)')'This time step is excedingly lower the deltat CFL'
251 if (deltat_fixed.eq.'not') then
252 write(*,'(A)')'deltat chosen will be substituted with 10% of deltat CFL'
253 time_step=time_step_cfl*0.1
254 write(*,'(A,E12.4)')'deltat chosen :',time_step
255 endif
256 elseif (percent_deltat.le.25) then
257 write(*,'(A,E12.4)')'OK!!! deltat CFL =',&
258 time_step_cfl
259 write(*,'(A,F6.2,A)')'You are using ',percent_deltat,&
260 '% of critical time step.'
261 else
262 write(*,'(A,E12.4)')'WARNING!!! deltat CFL =',&
263 time_step_cfl
264 write(*,'(A,F6.2,A)')'You are using ',percent_deltat,&
265 '% of critical time step.'
266 write(*,'(A)')'This could be not enough for the correct working of ABC'
267 if (deltat_fixed.eq.'not') then
268 write(*,'(A)')'deltat chosen will be substituted with 20% of deltat CFL'
269 time_step=time_step_cfl*0.2
270 write(*,'(A,E12.4)')'deltat chosen :',time_step
271 endif
272 endif
273
274 elseif (time_step .gt. time_step_cfl) then
275 write(*,'(2X,A,E12.4)')'ERROR!!! deltat CFL = ',&
276 time_step_cfl,' < deltat = ',time_step
277 write(*,'(A)')'The time advancing scheme will be unstable!'
278 if (deltat_fixed.eq.'not') then
279 write(*,'(A)')'deltat chosen will be substituted with 20% of deltat CFL'
280 time_step=time_step_cfl*0.2
281 write(*,'(A,E12.4)')'deltat chosen :',time_step
282 else
283 b_cfl_failure = .true.
284 endif
285 endif
286
287 write(*,'(A)')'-------------------------------------------------------'
288 write(*,'(A)')' '
289
290 if (b_failcfl .and. b_cfl_failure) then
291 write(*,*) 'CFL does NOT hold, asked to quit. Program finished.'
292 call mpi_finalize(mpi_err)
293 call exit(exit_cfl)
294 endif
295
296 !Writing of the results for the maximum number of points per wave length
297
298 endif
299
300 call mpi_barrier(mpi_comm, mpi_err)
301
302 allocate(ct(nn),ww(nn),dd(nn,nn))
303 call make_lgl_nw(nn,ct,ww,dd)
304
305 num_of_points = vs_length_min*(ct(1)-ct(nn))/(ct(int(nn/2))-ct(int(nn/2)+1))/fmax
306
307 !write(*,*) mpi_id, 'id', fmax, 'ppppp', vs_length_min, num_of_points
308 !call MPI_BARRIER(mpi_comm, mpi_err)
309
310 if((mpi_id + 1) .eq. pos2(1)) then
311 write(*,'(A)')'-----------Number of points per wave length------------'
312 !write(*,'(A,E12.4)')'Max. el. length :',1/vs_length_min*vs_npoints !length
313 write(*,'(A,E12.4)')'Minum vs wrt max frequency :',vs_npoints
314 write(*,'(A,E12.4)')'Points per wavelength :',num_of_points
315 write(*,'(A)') ' '
316 endif
317
318 deallocate(ct,ww,dd)
319
320 call mpi_barrier(mpi_comm, mpi_err)
321
322 !stop
323 return
324
325 end subroutine get_cfl4cases
326
subroutine make_eltensor_for_cases(tcase, vcase, nn, rho_el, lambda_el, mu_el, gamma_el, nn_loc, zs_elev, zs_all, vs_nodes, thic
Assignes material properties node by node.
subroutine make_lgl_nw(nb_pnt, xq, wq, dd)
Makes Gauss-Legendre-Lobatto nodes, weigths and spectral derivatives.
SPEED exit codes.
Definition MODULES.f90:25
integer, parameter exit_cfl
Definition MODULES.f90:30
Contains SPEED PARAMETERS used in (SPEED, READ_INPUT_FILES, MAKE_PARTION_AND_MPI_FILES,...
Definition MODULES.f90:207
real *8, dimension(:), allocatable qs
Definition MODULES.f90:437
integer *4 label_testcase
Definition MODULES.f90:269
real *8, dimension(:), allocatable vs_tria
Definition MODULES.f90:408
real *8 fmax
Definition MODULES.f90:393
real *8, dimension(:), allocatable qp
Definition MODULES.f90:437
real *8, dimension(:), allocatable zs_elev
Definition MODULES.f90:408
real *8, dimension(:), allocatable zs_all
Definition MODULES.f90:408