SW_VAR_DENS_MODEL  0.9
Dept-averagedgas-particlemodel
geometry_2d.f90
Go to the documentation of this file.
1 !*********************************************************************
3 !
6 !*********************************************************************
7 MODULE geometry_2d
8 
9  USE parameters_2d, ONLY : verbose_level
10 
11  IMPLICIT NONE
12 
14  REAL*8, ALLOCATABLE :: x_comp(:)
15 
17  REAL*8, ALLOCATABLE :: x_stag(:)
18 
20  REAL*8, ALLOCATABLE :: y_comp(:)
21 
23  REAL*8, ALLOCATABLE :: y_stag(:)
24 
26  REAL*8, ALLOCATABLE :: b_ver(:,:)
27 
29  REAL*8, ALLOCATABLE :: b_interfacel(:,:)
30 
32  REAL*8, ALLOCATABLE :: b_interfacer(:,:)
33 
35  REAL*8, ALLOCATABLE :: b_interfaceb(:,:)
36 
38  REAL*8, ALLOCATABLE :: b_interfacet(:,:)
39 
41  REAL*8, ALLOCATABLE :: b_cent(:,:)
42 
44  REAL*8, ALLOCATABLE :: b_prime_x(:,:)
45 
47  REAL*8, ALLOCATABLE :: b_prime_y(:,:)
48 
50  REAL*8, ALLOCATABLE :: grid_output(:,:)
51 
53  REAL*8, ALLOCATABLE :: grav_surf(:,:)
54 
56  REAL*8, ALLOCATABLE :: curv_xy(:,:)
57 
59  REAL*8, ALLOCATABLE :: deposit(:,:,:)
60 
61  REAL*8, ALLOCATABLE :: topography_profile(:,:,:)
62 
63  INTEGER, ALLOCATABLE :: source_cell(:,:)
64  LOGICAL, ALLOCATABLE :: sourcee(:,:)
65  LOGICAL, ALLOCATABLE :: sourcew(:,:)
66  LOGICAL, ALLOCATABLE :: sources(:,:)
67  LOGICAL, ALLOCATABLE :: sourcen(:,:)
68 
69  REAL*8, ALLOCATABLE :: dist_sourcee(:,:)
70  REAL*8, ALLOCATABLE :: dist_sourcew(:,:)
71  REAL*8, ALLOCATABLE :: dist_sources(:,:)
72  REAL*8, ALLOCATABLE :: dist_sourcen(:,:)
73 
74  REAL*8, ALLOCATABLE :: sourcee_vect_x(:,:)
75  REAL*8, ALLOCATABLE :: sourcee_vect_y(:,:)
76 
77  REAL*8, ALLOCATABLE :: sourcew_vect_x(:,:)
78  REAL*8, ALLOCATABLE :: sourcew_vect_y(:,:)
79 
80  REAL*8, ALLOCATABLE :: sources_vect_x(:,:)
81  REAL*8, ALLOCATABLE :: sources_vect_y(:,:)
82 
83  REAL*8, ALLOCATABLE :: sourcen_vect_x(:,:)
84  REAL*8, ALLOCATABLE :: sourcen_vect_y(:,:)
85 
86  REAL*8 :: pi_g
87 
89 
90  REAL*8 :: dx
91  REAL*8 :: x0
92  REAL*8 :: xn
93  REAL*8 :: dy
94  REAL*8 :: y0
95  REAL*8 :: yn
96  REAL*8 :: dx2
97  REAL*8 :: dy2
98  INTEGER :: comp_cells_x
99  INTEGER :: comp_interfaces_x
100  INTEGER :: comp_cells_y
101  INTEGER :: comp_interfaces_y
102  REAL*8 :: cell_size
103  INTEGER :: comp_cells_xy
104 
105 CONTAINS
106 
107  !*********************************************************************
109  !
112  !*********************************************************************
113 
114  SUBROUTINE init_grid
116  USE parameters_2d, ONLY: eps_sing
117 
118  IMPLICIT none
119 
120  INTEGER j,k
121 
124 
125  ALLOCATE( x_comp(comp_cells_x) )
126  ALLOCATE( x_stag(comp_interfaces_x) )
127  ALLOCATE( y_comp(comp_cells_y) )
128  ALLOCATE( y_stag(comp_interfaces_y) )
129 
131 
132  ! cell where are equations are solved
134 
135 
136  ALLOCATE( sourcee(comp_cells_x,comp_cells_y) )
137  ALLOCATE( sourcew(comp_cells_x,comp_cells_y) )
138  ALLOCATE( sourcen(comp_cells_x,comp_cells_y) )
139  ALLOCATE( sources(comp_cells_x,comp_cells_y) )
140 
145 
154 
155  ALLOCATE( b_ver( comp_interfaces_x , comp_interfaces_y ) )
156 
157  ALLOCATE( b_cent(comp_cells_x,comp_cells_y) )
158  ALLOCATE( b_prime_x(comp_cells_x,comp_cells_y) )
159  ALLOCATE( b_prime_y(comp_cells_x,comp_cells_y) )
160 
165 
167 
168  ALLOCATE( grav_surf(comp_cells_x,comp_cells_y) )
169 
170  IF ( comp_cells_x .GT. 1 ) THEN
171 
172  dx = cell_size
173 
174  ELSE
175 
176  dx = 1.d0
177 
178  END IF
179 
180 
181  IF ( comp_cells_y .GT. 1 ) THEN
182 
183  dy = cell_size
184 
185  ELSE
186 
187  dy = 1.d0
188 
189  END IF
190 
191  xn = x0 + comp_cells_x * dx
192  yn = y0 + comp_cells_y * dy
193 
194  dx2 = dx / 2.d0
195  dy2 = dy / 2.d0
196 
197  ! eps_sing = MIN( dx ** 4.D0,dy ** 4.D0 )
198  eps_sing=min(min( dx ** 4.d0,dy ** 4.d0 ),1.d-10)
199 
200  IF ( verbose_level .GE. 1 ) WRITE(*,*) 'eps_sing = ',eps_sing
201 
202  DO j=1,comp_interfaces_x
203 
204  x_stag(j) = x0 + (j-1) * dx
205 
206  END DO
207 
208  DO k=1,comp_interfaces_y
209 
210  y_stag(k) = y0 + (k-1) * dy
211 
212  END DO
213 
214  DO j=1,comp_cells_x
215 
216  x_comp(j) = 0.5d0 * ( x_stag(j) + x_stag(j+1) )
217 
218  END DO
219 
220  DO k=1,comp_cells_y
221 
222  y_comp(k) = 0.5d0 * ( y_stag(k) + y_stag(k+1) )
223 
224  END DO
225 
226 
227  DO k=1,comp_interfaces_y
228 
229  DO j=1,comp_interfaces_x
230 
231  CALL interp_2d_scalar( topography_profile(1,:,:) , &
232  topography_profile(2,:,:), topography_profile(3,:,:) , &
233  x_stag(j), y_stag(k) , b_ver(j,k) )
234 
235  END DO
236 
237  END DO
238 
239 !!$ DO j=1,comp_cells_x
240 !!$
241 !!$ DO k=1,comp_cells_y
242 !!$
243 !!$ B_interfaceR(j,k) = 0.5D0 * ( B_ver(j,k+1) + B_ver(j,k) )
244 !!$ B_interfaceL(j+1,k) = 0.5D0 * ( B_ver(j+1,k+1) + B_ver(j+1,k) )
245 !!$
246 !!$ B_interfaceT(j,k) = 0.5D0 * ( B_ver(j+1,k) + B_ver(j,k) )
247 !!$ B_interfaceB(j,k+1) = 0.5D0 * ( B_ver(j+1,k+1) + B_ver(j,k+1) )
248 !!$
249 !!$ B_cent(j,k) = 0.25D0 * ( B_ver(j,k) + B_ver(j+1,k) + B_ver(j,k+1) &
250 !!$ + B_ver(j+1,k+1) )
251 !!$
252 !!$ ! Second factor in RHS 1st Eq. 3.16 K&P
253 !!$ B_prime_x(j,k) = ( B_interfaceL(j+1,k) - B_interfaceR(j,k) ) / &
254 !!$ ( x_stag(j+1) - x_stag(j) )
255 !!$
256 !!$ ! Second factor in RHS 2nd Eq. 3.16 K&P
257 !!$ B_prime_y(j,k) = ( B_interfaceB(j,k+1) - B_interfaceT(j,k) ) / &
258 !!$ ( y_stag(k+1) - y_stag(k) )
259 !!$
260 !!$ END DO
261 !!$
262 !!$ ENDDO
263 
264  DO k=1,comp_cells_y
265 
266  DO j=1,comp_cells_x
267 
268  CALL interp_2d_scalar( topography_profile(1,:,:) , &
269  topography_profile(2,:,:), topography_profile(3,:,:) , &
270  x_comp(j), y_comp(k) , b_cent(j,k) )
271 
272  CALL interp_2d_slope( topography_profile(1,:,:) , &
273  topography_profile(2,:,:), topography_profile(3,:,:) , &
274  x_comp(j), y_comp(k) , b_prime_x(j,k) , b_prime_y(j,k) )
275 
276  b_interfacer(j,k) = b_cent(j,k) - dx2 * b_prime_x(j,k)
277  b_interfacel(j+1,k) = b_cent(j,k) + dx2 * b_prime_x(j,k)
278 
279  b_interfacet(j,k) = b_cent(j,k) - dx2 * b_prime_y(j,k)
280  b_interfaceb(j,k+1) = b_cent(j,k) + dx2 * b_prime_y(j,k)
281 
282  END DO
283 
284  ENDDO
285 
286  ! this coefficient is used when the the scalar dot between the normal to the
287  ! topography and gravity is computed
288  DO j = 1,comp_cells_x
289 
290  DO k=1,comp_cells_y
291 
292  grav_surf(j,k) = - ( 1.d0/ dsqrt( 1.d0 + b_prime_x(j,k)**2 &
293  + b_prime_y(j,k)**2) )
294 
295  ENDDO
296 
297  ENDDO
298 
299  pi_g = 4.d0 * datan(1.d0)
300 
301  RETURN
302 
303  END SUBROUTINE init_grid
304 
305 
306  SUBROUTINE init_source
308  USE parameters_2d, ONLY : x_source , y_source , r_source
309 
310  IMPLICIT NONE
311 
312  INTEGER :: j,k
313 
314  REAL*8 :: total_source
315 
316  WRITE(*,*) 'r_source',r_source
317  WRITE(*,*) 'dx,dy',dx,dy
318 
319  ! cell where are equations are solved
321 
322  sourcee(1:comp_cells_x,1:comp_cells_y) = .false.
323  sourcew(1:comp_cells_x,1:comp_cells_y) = .false.
324  sourcen(1:comp_cells_x,1:comp_cells_y) = .false.
325  sources(1:comp_cells_x,1:comp_cells_y) = .false.
326 
331 
332  total_source = 0.d0
333 
334  DO k = 2,comp_cells_y-1
335 
336  DO j = 2,comp_cells_x-1
337 
338  IF ( ( x_comp(j) - x_source )**2 + ( y_comp(k) - y_source )**2 .LE. &
339  r_source**2 ) THEN
340 
341  ! cells where equations are not solved
342  source_cell(j,k) = 1
343 
344  ! check on west cell
345  IF ( ( x_comp(j-1) - x_source )**2 + ( y_comp(k) - y_source )**2 &
346  .GE. r_source**2 ) THEN
347 
348  ! cells where radial source boundary condition are applied
349  source_cell(j-1,k) = 2
350  sourcee(j-1,k) = .true.
351  dist_sourcee(j-1,k) = dsqrt( ( x_stag(j) - x_source )**2 &
352  + ( y_comp(k) - y_source )**2 )
353 
354  sourcee_vect_x(j-1,k) = ( x_stag(j) - x_source ) * r_source &
355  / dist_sourcee(j-1,k)**2
356 
357  sourcee_vect_y(j-1,k) = ( y_comp(k) - y_source ) * r_source &
358  / dist_sourcee(j-1,k)**2
359 
360  total_source = total_source + dx * dabs( sourcee_vect_x(j-1,k) )
361 
362  ELSEIF ( ( x_comp(j+1) - x_source )**2 + ( y_comp(k)-y_source )**2 &
363  .GE. r_source**2 ) THEN
364  ! check on east cell
365 
366  ! cells where radial source boundary condition are applied
367  source_cell(j+1,k) = 2
368  sourcew(j+1,k) = .true.
369  dist_sourcew(j+1,k) = dsqrt( ( x_stag(j+1) - x_source )**2 &
370  + ( y_comp(k) - y_source )**2 )
371 
372  sourcew_vect_x(j+1,k) = ( x_stag(j+1) - x_source ) * r_source &
373  / dist_sourcew(j+1,k)**2
374 
375  sourcew_vect_y(j+1,k) = ( y_comp(k) - y_source ) * r_source &
376  / dist_sourcew(j+1,k)**2
377 
378  total_source = total_source + dx * dabs( sourcew_vect_x(j+1,k) )
379 
380  END IF
381 
382  ! check on south cell
383  IF ( ( x_comp(j) - x_source )**2 + ( y_comp(k-1) - y_source )**2 &
384  .GE. r_source**2 ) THEN
385 
386  ! cells where radial source boundary condition are applied
387  source_cell(j,k-1) = 2
388  sourcen(j,k-1) = .true.
389  dist_sourcen(j,k-1) = dsqrt( ( x_comp(j) - x_source )**2 &
390  + ( y_stag(k) - y_source )**2 )
391 
392  sourcen_vect_x(j,k-1) = ( x_comp(j) - x_source ) * r_source &
393  / dist_sourcen(j,k-1)**2
394 
395  sourcen_vect_y(j,k-1) = ( y_stag(k) - y_source ) * r_source &
396  / dist_sourcen(j,k-1)**2
397 
398  total_source = total_source + dy * dabs( sourcen_vect_y(j,k-1) )
399 
400  ELSEIF ( ( x_comp(j)-x_source )**2 + ( y_comp(k+1) - y_source )**2 &
401  .GE. r_source**2 ) THEN
402 
403  ! cells where radial source boundary condition are applied
404  source_cell(j,k+1) = 2
405  sources(j,k+1) = .true.
406  dist_sources(j,k+1) = dsqrt( ( x_comp(j) - x_source )**2 &
407  + ( y_stag(k+1) - y_source )**2 )
408 
409  sources_vect_x(j,k+1) = ( x_comp(j) - x_source ) * r_source &
410  / dist_sources(j,k+1)**2
411 
412  sources_vect_y(j,k+1) = ( y_stag(k+1) - y_source ) * r_source &
413  / dist_sources(j,k+1)**2
414 
415  total_source = total_source + dy * dabs( sources_vect_y(j,k+1) )
416 
417  END IF
418 
419  END IF
420 
421  END DO
422 
423  END DO
424 
425  RETURN
426 
427  END SUBROUTINE init_source
428 
429  !---------------------------------------------------------------------------
431  !
439  !---------------------------------------------------------------------------
440 
441  SUBROUTINE interp_1d_scalar(x1, f1, x2, f2)
442  IMPLICIT NONE
443 
444  REAL*8, INTENT(IN), DIMENSION(:) :: x1, f1
445  REAL*8, INTENT(IN) :: x2
446  REAL*8, INTENT(OUT) :: f2
447  INTEGER :: n, n1x, t
448  REAL*8 :: grad , rel_pos
449 
450  n1x = SIZE(x1)
451 
452  !
453  ! ... locate the grid points near the topographic points
454  ! ... and interpolate linearly the profile
455  !
456  t = 1
457 
458  search:DO n = 1, n1x-1
459 
460  rel_pos = ( x2 - x1(n) ) / ( x1(n+1) - x1(n) )
461 
462  IF ( ( rel_pos .GE. 0.d0 ) .AND. ( rel_pos .LE. 1.d0 ) ) THEN
463 
464  grad = ( f1(n+1)-f1(n) ) / ( x1(n+1)-x1(n) )
465  f2 = f1(n) + ( x2-x1(n) ) * grad
466 
467  EXIT search
468 
469  ELSEIF ( rel_pos .LT. 0.d0 ) THEN
470 
471  f2 = f1(n)
472 
473  ELSE
474 
475  f2 = f1(n+1)
476 
477  END IF
478 
479  END DO search
480 
481  RETURN
482 
483  END SUBROUTINE interp_1d_scalar
484 
485 
486  !---------------------------------------------------------------------------
488  !
498  !---------------------------------------------------------------------------
499 
500  SUBROUTINE interp_2d_scalar(x1, y1, f1, x2, y2, f2)
501  IMPLICIT NONE
502 
503  REAL*8, INTENT(IN), DIMENSION(:,:) :: x1, y1, f1
504  REAL*8, INTENT(IN) :: x2, y2
505  REAL*8, INTENT(OUT) :: f2
506 
507  INTEGER :: ix , iy
508  REAL*8 :: alfa_x , alfa_y
509 
510  IF ( size(x1,1) .GT. 1 ) THEN
511 
512  ix = floor( ( x2 - x1(1,1) ) / ( x1(2,1) - x1(1,1) ) ) + 1
513  ix = min( ix , SIZE(x1,1)-1 )
514  alfa_x = ( x1(ix+1,1) - x2 ) / ( x1(ix+1,1) - x1(ix,1) )
515 
516  ELSE
517 
518  ix = 1
519  alfa_x = 0.d0
520 
521  END IF
522 
523  IF ( size(x1,2) .GT. 1 ) THEN
524 
525  iy = floor( ( y2 - y1(1,1) ) / ( y1(1,2) - y1(1,1) ) ) + 1
526  iy = min( iy , SIZE(x1,2)-1 )
527  alfa_y = ( y1(1,iy+1) - y2 ) / ( y1(1,iy+1) - y1(1,iy) )
528 
529  ELSE
530 
531  iy = 1
532  alfa_y = 0.d0
533 
534  END IF
535 
536  IF ( size(x1,1) .EQ. 1 ) THEN
537 
538  f2 = alfa_y * f1(ix,iy) + ( 1.d0 - alfa_y ) * f1(ix,iy+1)
539 
540  ELSEIF ( size(x1,2) .EQ. 1 ) THEN
541 
542  f2 = alfa_x * f1(ix,iy) + ( 1.d0 - alfa_x ) * f1(ix+1,iy)
543 
544  ELSE
545 
546  f2 = alfa_x * ( alfa_y * f1(ix,iy) + ( 1.d0 - alfa_y ) * f1(ix,iy+1) ) &
547  + ( 1.d0 - alfa_x ) * ( alfa_y * f1(ix+1,iy) + ( 1.d0 - alfa_y ) &
548  * f1(ix+1,iy+1) )
549 
550  END IF
551 
552  END SUBROUTINE interp_2d_scalar
553 
554  !---------------------------------------------------------------------------
556  !
567  !---------------------------------------------------------------------------
568 
569  SUBROUTINE interp_2d_scalarb(x1, y1, f1, x2, y2, f2)
570  IMPLICIT NONE
571 
572  REAL*8, INTENT(IN), DIMENSION(:) :: x1, y1
573  REAL*8, INTENT(IN), DIMENSION(:,:) :: f1
574  REAL*8, INTENT(IN) :: x2, y2
575  REAL*8, INTENT(OUT) :: f2
576 
577  INTEGER :: ix , iy
578  REAL*8 :: alfa_x , alfa_y
579 
580  IF ( size(x1) .GT. 1 ) THEN
581 
582  ix = floor( ( x2 - x1(1) ) / ( x1(2) - x1(1) ) ) + 1
583  ix = max(0,min( ix , SIZE(x1)-1 ))
584  alfa_x = ( x1(ix+1) - x2 ) / ( x1(ix+1) - x1(ix) )
585 
586  ELSE
587 
588  ix = 1
589  alfa_x = 0.d0
590 
591  END IF
592 
593  IF ( size(y1) .GT. 1 ) THEN
594 
595  iy = floor( ( y2 - y1(1) ) / ( y1(2) - y1(1) ) ) + 1
596  iy = max(1,min( iy , SIZE(y1)-1 ))
597  alfa_y = ( y1(iy+1) - y2 ) / ( y1(iy+1) - y1(iy) )
598 
599  ELSE
600 
601  iy = 1
602  alfa_y = 0.d0
603 
604  END IF
605 
606  IF ( ( alfa_x .LT. 0.d0 ) .OR. ( alfa_x .GT. 1.d0 ) &
607  .OR. ( alfa_y .LT. 0.d0 ) .OR. ( alfa_y .GT. 1.d0 ) ) THEN
608 
609  f2 = 0.d0
610  RETURN
611 
612  END IF
613 
614 
615  IF ( size(x1) .EQ. 1 ) THEN
616 
617  f2 = alfa_y * f1(ix,iy) + ( 1.d0 - alfa_y ) * f1(ix,iy+1)
618 
619  ELSEIF ( size(y1) .EQ. 1 ) THEN
620 
621  f2 = alfa_x * f1(ix,iy) + ( 1.d0 - alfa_x ) * f1(ix+1,iy)
622 
623  ELSE
624 
625  f2 = alfa_x * ( alfa_y * f1(ix,iy) + ( 1.d0 - alfa_y ) * f1(ix,iy+1) ) &
626  + ( 1.d0 - alfa_x ) * ( alfa_y * f1(ix+1,iy) + ( 1.d0 - alfa_y ) &
627  * f1(ix+1,iy+1) )
628 
629  END IF
630 
631  RETURN
632 
633  END SUBROUTINE interp_2d_scalarb
634 
635 
636  !---------------------------------------------------------------------------
638  !
648  !---------------------------------------------------------------------------
649 
650  SUBROUTINE interp_2d_slope(x1, y1, f1, x2, y2, f_x, f_y)
651  IMPLICIT NONE
652 
653  REAL*8, INTENT(IN), DIMENSION(:,:) :: x1, y1, f1
654  REAL*8, INTENT(IN) :: x2, y2
655  REAL*8, INTENT(OUT) :: f_x , f_y
656 
657  INTEGER :: ix , iy
658  REAL*8 :: alfa_x , alfa_y
659  REAL*8 :: f_x1 , f_x2 , f_y1 , f_y2
660 
661 
662  IF ( size(x1,1) .GT. 1 ) THEN
663 
664  ix = floor( ( x2 - x1(1,1) ) / ( x1(2,1) - x1(1,1) ) ) + 1
665  ix = min( ix , SIZE(x1,1)-1 )
666  alfa_x = ( x1(ix+1,1) - x2 ) / ( x1(ix+1,1) - x1(ix,1) )
667 
668  ELSE
669 
670  ix = 1
671  alfa_x = 1.d0
672 
673  END IF
674 
675  IF ( size(x1,2) .GT. 1 ) THEN
676 
677  iy = floor( ( y2 - y1(1,1) ) / ( y1(1,2) - y1(1,1) ) ) + 1
678  iy = min( iy , SIZE(x1,2)-1 )
679  alfa_y = ( y1(1,iy+1) - y2 ) / ( y1(1,iy+1) - y1(1,iy) )
680 
681  ELSE
682 
683  iy = 1
684  alfa_y = 1.d0
685 
686  END IF
687 
688  f_x1 = 0.d0
689  f_x2 = 0.d0
690 
691  IF ( size(x1,1) .GT. 1 ) THEN
692 
693  f_x1 = ( f1(ix+1,iy) - f1(ix,iy) ) / ( x1(2,1) - x1(1,1) )
694 
695  IF ( size(x1,2) .GT. 1 ) THEN
696 
697  f_x2 = ( f1(ix+1,iy+1) - f1(ix,iy+1) ) / ( x1(2,1) - x1(1,1) )
698 
699  END IF
700 
701  END IF
702 
703  f_x = alfa_y * f_x1 + ( 1.d0 - alfa_y ) * f_x2
704 
705  f_y1 = 0.d0
706  f_y2 = 0.d0
707 
708  IF ( size(x1,2) .GT. 1 ) THEN
709 
710  f_y1 = ( f1(ix,iy+1) - f1(ix,iy) ) / ( y1(1,2) - y1(1,1) )
711 
712  IF ( size(x1,1) .GT. 1 ) THEN
713 
714  f_y2 = ( f1(ix+1,iy+1) - f1(ix+1,iy) ) / ( y1(1,2) - y1(1,1) )
715 
716  END IF
717 
718  END IF
719 
720  f_y = alfa_x * f_y1 + ( 1.d0 - alfa_x ) * f_y2
721 
722 
723  RETURN
724 
725  END SUBROUTINE interp_2d_slope
726 
727 
728  !******************************************************************************
730  !
736  !******************************************************************************
737 
738  SUBROUTINE topography_reconstruction
740  IMPLICIT NONE
741 
742  REAL*8 :: B_stencil(3)
743  REAL*8 :: x_stencil(3)
744  REAL*8 :: y_stencil(3)
745 
746  INTEGER :: limiterB
747 
748  INTEGER :: j,k
749 
750 
751  ! centered approximation for the topography slope
752  limiterb = 5
753 
754  y_loop:DO k = 1,comp_cells_y
755 
756  x_loop:DO j = 1,comp_cells_x
757 
758  ! x direction
759  check_comp_cells_x:IF ( comp_cells_x .GT. 1 ) THEN
760 
761  check_x_boundary:IF (j.EQ.1) THEN
762 
763  ! west boundary
764 
765  x_stencil(1) = 2.d0 * x_comp(1) - x_comp(2)
766  x_stencil(2:3) = x_comp(1:2)
767 
768  b_stencil(1) = 2.d0 * b_cent(1,k) - b_cent(2,k)
769  b_stencil(2:3) = b_cent(1:2,k)
770 
771  CALL limit( b_stencil , x_stencil , limiterb , b_prime_x(j,k) )
772 
773  ELSEIF (j.EQ.comp_cells_x) THEN
774 
775  !east boundary
776 
777  x_stencil(3) = 2.d0 * x_comp(comp_cells_x) - x_comp(comp_cells_x-1)
778  x_stencil(1:2) = x_comp(comp_cells_x-1:comp_cells_x)
779 
780  b_stencil(3) = 2.d0 * b_cent(comp_cells_x,k) - b_cent(comp_cells_x-1,k)
781  b_stencil(1:2) = b_cent(comp_cells_x-1:comp_cells_x,k)
782 
783  CALL limit( b_stencil , x_stencil , limiterb , b_prime_x(j,k) )
784 
785  ELSE
786 
787  ! Internal x interfaces
788  x_stencil(1:3) = x_comp(j-1:j+1)
789  b_stencil = b_cent(j-1:j+1,k)
790 
791  CALL limit( b_stencil , x_stencil , limiterb , b_prime_x(j,k) )
792 
793  ENDIF check_x_boundary
794 
795  ELSE
796 
797  b_prime_x(j,k) = 0.d0
798 
799  END IF check_comp_cells_x
800 
801  ! y-direction
802  check_comp_cells_y:IF ( comp_cells_y .GT. 1 ) THEN
803 
804  check_y_boundary:IF (k.EQ.1) THEN
805 
806  ! South boundary
807  y_stencil(1) = 2.d0 * y_comp(1) - y_comp(2)
808  y_stencil(2:3) = y_comp(1:2)
809 
810  b_stencil(1) = 2.d0 * b_cent(j,1) - b_cent(j,2)
811  b_stencil(2:3) = b_cent(j,1:2)
812 
813  CALL limit( b_stencil , y_stencil , limiterb , b_prime_y(j,k) )
814 
815  ELSEIF ( k .EQ. comp_cells_y ) THEN
816 
817  ! North boundary
818  y_stencil(3) = 2.d0 * y_comp(comp_cells_y) - y_comp(comp_cells_y-1)
819  y_stencil(1:2) = y_comp(comp_cells_y-1:comp_cells_y)
820 
821  b_stencil(3) = 2.d0 * b_cent(j,comp_cells_y) - b_cent(j,comp_cells_y-1)
822  b_stencil(1:2) = b_cent(j,comp_cells_y-1:comp_cells_y)
823 
824  CALL limit( b_stencil , y_stencil , limiterb , b_prime_y(j,k) )
825 
826  ELSE
827 
828  ! Internal y interfaces
829  y_stencil(1:3) = y_comp(k-1:k+1)
830  b_stencil = b_cent(j,k-1:k+1)
831 
832  CALL limit( b_stencil , y_stencil , limiterb , b_prime_y(j,k) )
833 
834  ENDIF check_y_boundary
835 
836  ELSE
837 
838  b_prime_y(j,k) = 0.d0
839 
840  ENDIF check_comp_cells_y
841 
842  END DO x_loop
843 
844  END DO y_loop
845 
846  DO j = 1,comp_cells_x
847 
848  DO k = 1,comp_cells_y
849 
850  b_interfacer(j,k) = b_cent(j,k) - dx2 * b_prime_x(j,k)
851  b_interfacel(j+1,k) = b_cent(j,k) + dx2 * b_prime_x(j,k)
852 
853  b_interfacet(j,k) = b_cent(j,k) - dx2 * b_prime_y(j,k)
854  b_interfaceb(j,k+1) = b_cent(j,k) + dx2 * b_prime_y(j,k)
855 
856  END DO
857 
858  END DO
859 
860  RETURN
861 
862  END SUBROUTINE topography_reconstruction
863 
864  !---------------------------------------------------------------------------
866  !
879  !---------------------------------------------------------------------------
880 
881  SUBROUTINE regrid_scalar(xin, yin, fin, xl, xr , yl, yr, fout)
882  IMPLICIT NONE
883 
884  REAL*8, INTENT(IN), DIMENSION(:) :: xin, yin
885  REAL*8, INTENT(IN), DIMENSION(:,:) :: fin
886  REAL*8, INTENT(IN) :: xl, xr , yl , yr
887  REAL*8, INTENT(OUT) :: fout
888 
889  INTEGER :: ix , iy
890  INTEGER :: ix1 , ix2 , iy1 , iy2
891  REAL*8 :: alfa_x , alfa_y
892  REAL*8 :: dXin , dYin
893 
894  INTEGER nXin,nYin
895 
896  nxin = size(xin)-1
897  nyin = size(yin)-1
898 
899  dxin = xin(2) - xin(1)
900  dyin = yin(2) - yin(1)
901 
902  ix1 = max(1,ceiling( ( xl - xin(1) ) / dxin ))
903  ix2 = min(nxin,ceiling( ( xr -xin(1) ) / dxin )+1)
904 
905  iy1 = max(1,ceiling( ( yl - yin(1) ) / dyin ))
906  iy2 = min(nyin,ceiling( ( yr - yin(1) ) / dyin ) + 1)
907 
908  fout = 0.d0
909 
910  DO ix=ix1,ix2-1
911 
912  alfa_x = ( min(xr,xin(ix+1)) - max(xl,xin(ix)) ) / ( xr - xl )
913 
914  DO iy=iy1,iy2-1
915 
916  alfa_y = ( min(yr,yin(iy+1)) - max(yl,yin(iy)) ) / ( yr - yl )
917 
918  fout = fout + alfa_x * alfa_y * fin(ix,iy)
919 
920  END DO
921 
922  END DO
923 
924  END SUBROUTINE regrid_scalar
925 
926  !******************************************************************************
928  !
943  !******************************************************************************
944 
945  SUBROUTINE limit( v , z , limiter , slope_lim )
947  USE parameters_2d, ONLY : theta
948 
949  IMPLICIT none
950 
951  REAL*8, INTENT(IN) :: v(3)
952  REAL*8, INTENT(IN) :: z(3)
953  INTEGER, INTENT(IN) :: limiter
954 
955  REAL*8, INTENT(OUT) :: slope_lim
956 
957  REAL*8 :: a , b , c
958 
959  REAL*8 :: sigma1 , sigma2
960 
961  a = ( v(3) - v(2) ) / ( z(3) - z(2) )
962  b = ( v(2) - v(1) ) / ( z(2) - z(1) )
963  c = ( v(3) - v(1) ) / ( z(3) - z(1) )
964 
965  SELECT CASE (limiter)
966 
967  CASE ( 0 )
968 
969  slope_lim = 0.d0
970 
971  CASE ( 1 )
972 
973  ! minmod
974  slope_lim = minmod(a,b)
975 
976  CASE ( 2 )
977 
978  ! superbee
979  sigma1 = minmod( a , 2.d0*b )
980  sigma2 = minmod( 2.d0*a , b )
981  slope_lim = maxmod( sigma1 , sigma2 )
982 
983  CASE ( 3 )
984 
985  ! generalized minmod
986  slope_lim = minmod( c , theta * minmod( a , b ) )
987 
988  CASE ( 4 )
989 
990  ! monotonized central-difference (MC, LeVeque p.112)
991  slope_lim = minmod( c , 2.0 * minmod( a , b ) )
992 
993  CASE ( 5 )
994 
995  ! centered
996  slope_lim = c
997 
998  CASE (6)
999 
1000  ! backward
1001  slope_lim = a
1002 
1003  CASE (7)
1004 
1005  !forward
1006  slope_lim = b
1007 
1008  END SELECT
1009 
1010  END SUBROUTINE limit
1011 
1012 
1013  REAL*8 FUNCTION minmod(a,b)
1015  IMPLICIT none
1016 
1017  REAL*8 :: a , b , sa , sb
1018 
1019  IF ( a*b .EQ. 0.d0 ) THEN
1020 
1021  minmod = 0.d0
1022 
1023  ELSE
1024 
1025  sa = a / abs(a)
1026  sb = b / abs(b)
1027 
1028  minmod = 0.5d0 * ( sa+sb ) * min( abs(a) , abs(b) )
1029 
1030  END IF
1031 
1032  END FUNCTION minmod
1033 
1034  REAL*8 function maxmod(a,b)
1036  IMPLICIT none
1037 
1038  REAL*8 :: a , b , sa , sb
1039 
1040  IF ( a*b .EQ. 0.d0 ) THEN
1041 
1042  maxmod = 0.d0
1043 
1044  ELSE
1045 
1046  sa = a / abs(a)
1047  sb = b / abs(b)
1048 
1049  maxmod = 0.5d0 * ( sa+sb ) * max( abs(a) , abs(b) )
1050 
1051  END IF
1052 
1053  END function maxmod
1054 
1055  SUBROUTINE compute_cell_fract(xs,ys,rs,cell_fract)
1057  IMPLICIT NONE
1058 
1059  REAL*8, INTENT(IN) :: xs,ys,rs
1060 
1061  REAL*8, INTENT(OUT) :: cell_fract(comp_cells_x,comp_cells_y)
1062 
1063  REAL*8, ALLOCATABLE :: x_subgrid(:) , y_subgrid(:)
1064 
1065  INTEGER, ALLOCATABLE :: check_subgrid(:)
1066 
1067  INTEGER n_points , n_points2
1068 
1069  REAL*8 :: source_area
1070 
1071  INTEGER :: h ,j, k
1072 
1073  n_points = 200
1074  n_points2 = n_points**2
1075 
1076  ALLOCATE( x_subgrid(n_points2) )
1077  ALLOCATE( y_subgrid(n_points2) )
1078  ALLOCATE( check_subgrid(n_points2) )
1079 
1080  x_subgrid = 0.d0
1081  y_subgrid = 0.d0
1082 
1083  DO h = 1,n_points
1084 
1085  x_subgrid(h:n_points2:n_points) = dble(h)
1086  y_subgrid((h-1)*n_points+1:h*n_points) = dble(h)
1087 
1088  END DO
1089 
1090  x_subgrid = ( 2.d0 * x_subgrid - 1.d0 ) / ( 2.d0 * dble(n_points) )
1091  y_subgrid = ( 2.d0 * y_subgrid - 1.d0 ) / ( 2.d0 * dble(n_points) )
1092 
1093  x_subgrid = ( x_subgrid - 0.5d0 ) * dx
1094  y_subgrid = ( y_subgrid - 0.5d0 ) * dy
1095 
1096  DO j=1,comp_cells_x
1097 
1098  DO k=1,comp_cells_y
1099 
1100  IF ( ( x_stag(j+1) .LT. ( xs - rs ) ) .OR. &
1101  ( x_stag(j) .GT. ( xs + rs ) ) .OR. &
1102  ( y_stag(k+1) .LT. ( ys - rs ) ) .OR. &
1103  ( y_stag(k) .GT. ( ys + rs ) ) ) THEN
1104 
1105  cell_fract(j,k) = 0.d0
1106 
1107  ELSE
1108 
1109  check_subgrid = 0
1110 
1111  WHERE ( ( x_comp(j) + x_subgrid - xs )**2 &
1112  + ( y_comp(k) + y_subgrid - ys )**2 < rs**2 )
1113 
1114  check_subgrid = 1
1115 
1116  END WHERE
1117 
1118  cell_fract(j,k) = REAL(sum(check_subgrid))/n_points2
1119 
1120  END IF
1121 
1122  ENDDO
1123 
1124  ENDDO
1125 
1126  source_area = dx*dy*sum(cell_fract)
1127 
1128  WRITE(*,*) 'Source area =',source_area,' Error =',abs( 1.d0 - &
1129  dx*dy*sum(cell_fract) / ( 4.d0*atan(1.d0)*rs**2 ) )
1130 
1131  DEALLOCATE( x_subgrid )
1132  DEALLOCATE( y_subgrid )
1133  DEALLOCATE( check_subgrid )
1134 
1135  RETURN
1136 
1137  END SUBROUTINE compute_cell_fract
1138 
1139 
1140 END MODULE geometry_2d
real *8, dimension(:,:), allocatable b_prime_x
Topography slope (x direction) at the centers of the control volumes.
Definition: geometry_2d.f90:44
real *8, dimension(:,:), allocatable b_interfacel
Reconstructed value at the left of the x-interface.
Definition: geometry_2d.f90:29
real *8 dy
Control volumes size.
Definition: geometry_2d.f90:93
real *8, dimension(:), allocatable x_comp
Location of the centers (x) of the control volume of the domain.
Definition: geometry_2d.f90:14
real *8 y0
Bottom of the physical domain.
Definition: geometry_2d.f90:94
subroutine topography_reconstruction
Linear reconstruction.
real *8, dimension(:,:), allocatable b_cent
Topography at the centers of the control volumes.
Definition: geometry_2d.f90:41
integer comp_cells_x
Number of control volumes x in the comp. domain.
Definition: geometry_2d.f90:98
real *8, dimension(:,:), allocatable sourcen_vect_y
Definition: geometry_2d.f90:84
real *8, dimension(:,:), allocatable grav_surf
gravity vector wrt surface coordinates for each cell
Definition: geometry_2d.f90:53
real *8, dimension(:,:), allocatable sourcee_vect_x
Definition: geometry_2d.f90:74
real *8, dimension(:), allocatable y_comp
Location of the centers (y) of the control volume of the domain.
Definition: geometry_2d.f90:20
integer n_topography_profile_y
Definition: geometry_2d.f90:88
Parameters.
real *8 dx
Control volumes size.
Definition: geometry_2d.f90:90
integer comp_cells_y
Number of control volumes y in the comp. domain.
logical, dimension(:,:), allocatable sourcee
Definition: geometry_2d.f90:64
logical, dimension(:,:), allocatable sourcew
Definition: geometry_2d.f90:65
real *8, dimension(:,:), allocatable curv_xy
curvature wrt mixed directions for each cell
Definition: geometry_2d.f90:56
real *8, dimension(:,:), allocatable sourcew_vect_y
Definition: geometry_2d.f90:78
real *8, dimension(:,:), allocatable b_interfacer
Reconstructed value at the right of the x-interface.
Definition: geometry_2d.f90:32
real *8 function minmod(a, b)
subroutine regrid_scalar(xin, yin, fin, xl, xr, yl, yr, fout)
Scalar regrid (2D)
integer n_topography_profile_x
Definition: geometry_2d.f90:88
real *8, dimension(:,:), allocatable sourcew_vect_x
Definition: geometry_2d.f90:77
real *8, dimension(:,:), allocatable b_interfaceb
Reconstructed value at the bottom of the y-interface.
Definition: geometry_2d.f90:35
integer comp_interfaces_y
Number of interfaces (comp_cells_y+1)
real *8 xn
Right of the physical domain.
Definition: geometry_2d.f90:92
integer comp_cells_xy
subroutine init_grid
Finite volume grid initialization.
real *8, dimension(:,:), allocatable dist_sources
Definition: geometry_2d.f90:71
real *8, dimension(:,:), allocatable dist_sourcee
Definition: geometry_2d.f90:69
subroutine limit(v, z, limiter, slope_lim)
Slope limiter.
real *8 yn
Top of the physical domain.
Definition: geometry_2d.f90:95
real *8 x0
Left of the physical domain.
Definition: geometry_2d.f90:91
real *8, dimension(:,:), allocatable sourcee_vect_y
Definition: geometry_2d.f90:75
real *8, dimension(:,:), allocatable sources_vect_y
Definition: geometry_2d.f90:81
subroutine interp_2d_slope(x1, y1, f1, x2, y2, f_x, f_y)
Scalar interpolation (2D)
real *8, dimension(:,:), allocatable b_ver
Topography at the vertices of the control volumes.
Definition: geometry_2d.f90:26
real *8, dimension(:,:), allocatable grid_output
Solution in ascii grid format (ESRI)
Definition: geometry_2d.f90:50
real *8, dimension(:,:), allocatable sourcen_vect_x
Definition: geometry_2d.f90:83
integer, dimension(:,:), allocatable source_cell
Definition: geometry_2d.f90:63
real *8, dimension(:,:), allocatable dist_sourcew
Definition: geometry_2d.f90:70
subroutine init_source
Grid module.
Definition: geometry_2d.f90:7
real *8 cell_size
real *8 theta
Van Leer limiter parameter.
integer verbose_level
real *8, dimension(:,:,:), allocatable topography_profile
Definition: geometry_2d.f90:61
real *8, dimension(:,:), allocatable b_prime_y
Topography slope (y direction) at the centers of the control volumes.
Definition: geometry_2d.f90:47
subroutine compute_cell_fract(xs, ys, rs, cell_fract)
real *8, dimension(:), allocatable x_stag
Location of the boundaries (x) of the control volumes of the domain.
Definition: geometry_2d.f90:17
real *8, dimension(:,:), allocatable sources_vect_x
Definition: geometry_2d.f90:80
subroutine interp_2d_scalarb(x1, y1, f1, x2, y2, f2)
Scalar interpolation (2D)
subroutine interp_2d_scalar(x1, y1, f1, x2, y2, f2)
Scalar interpolation (2D)
real *8, dimension(:,:), allocatable b_interfacet
Reconstructed value at the top of the y-interface.
Definition: geometry_2d.f90:38
logical, dimension(:,:), allocatable sourcen
Definition: geometry_2d.f90:67
real *8 dx2
Half x Control volumes size.
Definition: geometry_2d.f90:96
real *8, dimension(:,:,:), allocatable deposit
deposit for the different classes
Definition: geometry_2d.f90:59
real *8, dimension(:,:), allocatable dist_sourcen
Definition: geometry_2d.f90:72
integer comp_interfaces_x
Number of interfaces (comp_cells_x+1)
Definition: geometry_2d.f90:99
real *8 eps_sing
parameter for desingularization
real *8, dimension(:), allocatable y_stag
Location of the boundaries (x) of the control volumes of the domain.
Definition: geometry_2d.f90:23
subroutine interp_1d_scalar(x1, f1, x2, f2)
Scalar interpolation.
real *8 pi_g
Definition: geometry_2d.f90:86
real *8 dy2
Half y Control volumes size.
Definition: geometry_2d.f90:97
real *8 function maxmod(a, b)
logical, dimension(:,:), allocatable sources
Definition: geometry_2d.f90:66