133 WRITE(*,*)
'init_grid: dx = ',
dx 134 WRITE(*,*)
'init_grid: dy = ',
dy 164 IF (
wp .EQ.
sp )
THEN 166 eps_sing=min(min(
dx ** 4.0_wp,
dy ** 4.0_wp ),1.0e-6_wp)
170 eps_sing=min(min(
dx ** 4.0_wp,
dy ** 4.0_wp ),1.0e-10_wp)
174 IF ( verbose_level .GE. 1 )
WRITE(*,*)
'eps_sing = ',
eps_sing 260 REAL(wp) :: total_source
281 total_source = 0.0_wp
393 REAL(wp),
INTENT(IN),
DIMENSION(:) :: x1, f1
394 REAL(wp),
INTENT(IN) :: x2
395 REAL(wp),
INTENT(OUT) :: f2
397 REAL(wp) :: grad , rel_pos
407 search:
DO n = 1, n1x-1
409 rel_pos = ( x2 - x1(n) ) / ( x1(n+1) - x1(n) )
411 IF ( ( rel_pos .GE. 0.0_wp ) .AND. ( rel_pos .LE. 1.0_wp ) )
THEN 413 grad = ( f1(n+1)-f1(n) ) / ( x1(n+1)-x1(n) )
414 f2 = f1(n) + ( x2-x1(n) ) * grad
418 ELSEIF ( rel_pos .LT. 0.0_wp )
THEN 451 REAL(wp),
INTENT(IN),
DIMENSION(:,:) :: x1, y1, f1
452 REAL(wp),
INTENT(IN) :: x2, y2
453 REAL(wp),
INTENT(OUT) :: f2
456 REAL(wp) :: alfa_x , alfa_y
458 IF (
size(x1,1) .GT. 1 )
THEN 460 ix = floor( ( x2 - x1(1,1) ) / ( x1(2,1) - x1(1,1) ) ) + 1
461 ix = min( ix ,
SIZE(x1,1)-1 )
462 alfa_x = ( x1(ix+1,1) - x2 ) / ( x1(ix+1,1) - x1(ix,1) )
471 IF (
size(x1,2) .GT. 1 )
THEN 473 iy = floor( ( y2 - y1(1,1) ) / ( y1(1,2) - y1(1,1) ) ) + 1
474 iy = min( iy ,
SIZE(x1,2)-1 )
475 alfa_y = ( y1(1,iy+1) - y2 ) / ( y1(1,iy+1) - y1(1,iy) )
484 IF (
size(x1,1) .EQ. 1 )
THEN 486 f2 = alfa_y * f1(ix,iy) + ( 1.0_wp - alfa_y ) * f1(ix,iy+1)
488 ELSEIF (
size(x1,2) .EQ. 1 )
THEN 490 f2 = alfa_x * f1(ix,iy) + ( 1.0_wp - alfa_x ) * f1(ix+1,iy)
494 f2 = alfa_x * ( alfa_y * f1(ix,iy) + ( 1.0_wp - alfa_y ) * f1(ix,iy+1) ) &
495 + ( 1.0_wp - alfa_x ) * ( alfa_y * f1(ix+1,iy) + ( 1.0_wp - alfa_y )&
520 REAL(wp),
INTENT(IN),
DIMENSION(:) :: x1, y1
521 REAL(wp),
INTENT(IN),
DIMENSION(:,:) :: f1
522 REAL(wp),
INTENT(IN) :: x2, y2
523 REAL(wp),
INTENT(OUT) :: f2
526 REAL(wp) :: alfa_x , alfa_y
528 IF (
size(x1) .GT. 1 )
THEN 530 ix = floor( ( x2 - x1(1) ) / ( x1(2) - x1(1) ) ) + 1
531 ix = max(0,min( ix ,
SIZE(x1)-1 ))
532 alfa_x = ( x1(ix+1) - x2 ) / ( x1(ix+1) - x1(ix) )
541 IF (
size(y1) .GT. 1 )
THEN 543 iy = floor( ( y2 - y1(1) ) / ( y1(2) - y1(1) ) ) + 1
544 iy = max(1,min( iy ,
SIZE(y1)-1 ))
545 alfa_y = ( y1(iy+1) - y2 ) / ( y1(iy+1) - y1(iy) )
554 IF ( ( alfa_x .LT. 0.0_wp ) .OR. ( alfa_x .GT. 1.0_wp ) &
555 .OR. ( alfa_y .LT. 0.0_wp ) .OR. ( alfa_y .GT. 1.0_wp ) )
THEN 563 IF (
size(x1) .EQ. 1 )
THEN 565 f2 = alfa_y * f1(ix,iy) + ( 1.0_wp - alfa_y ) * f1(ix,iy+1)
567 ELSEIF (
size(y1) .EQ. 1 )
THEN 569 f2 = alfa_x * f1(ix,iy) + ( 1.0_wp - alfa_x ) * f1(ix+1,iy)
573 f2 = alfa_x * ( alfa_y * f1(ix,iy) + ( 1.0_wp - alfa_y ) * f1(ix,iy+1) ) &
574 + ( 1.0_wp - alfa_x ) * ( alfa_y * f1(ix+1,iy) + ( 1.0_wp - alfa_y )&
600 REAL(wp),
INTENT(IN),
DIMENSION(:,:) :: x1, y1, f1
601 REAL(wp),
INTENT(IN) :: x2, y2
602 REAL(wp),
INTENT(OUT) :: f_x , f_y
605 REAL(wp) :: alfa_x , alfa_y
606 REAL(wp) :: f_x1 , f_x2 , f_y1 , f_y2
609 IF (
size(x1,1) .GT. 1 )
THEN 611 ix = floor( ( x2 - x1(1,1) ) / ( x1(2,1) - x1(1,1) ) ) + 1
612 ix = min( ix ,
SIZE(x1,1)-1 )
613 alfa_x = ( x1(ix+1,1) - x2 ) / ( x1(ix+1,1) - x1(ix,1) )
622 IF (
size(x1,2) .GT. 1 )
THEN 624 iy = floor( ( y2 - y1(1,1) ) / ( y1(1,2) - y1(1,1) ) ) + 1
625 iy = min( iy ,
SIZE(x1,2)-1 )
626 alfa_y = ( y1(1,iy+1) - y2 ) / ( y1(1,iy+1) - y1(1,iy) )
638 IF (
size(x1,1) .GT. 1 )
THEN 640 f_x1 = ( f1(ix+1,iy) - f1(ix,iy) ) / ( x1(2,1) - x1(1,1) )
642 IF (
size(x1,2) .GT. 1 )
THEN 644 f_x2 = ( f1(ix+1,iy+1) - f1(ix,iy+1) ) / ( x1(2,1) - x1(1,1) )
650 f_x = alfa_y * f_x1 + ( 1.0_wp - alfa_y ) * f_x2
655 IF (
size(x1,2) .GT. 1 )
THEN 657 f_y1 = ( f1(ix,iy+1) - f1(ix,iy) ) / ( y1(1,2) - y1(1,1) )
659 IF (
size(x1,1) .GT. 1 )
THEN 661 f_y2 = ( f1(ix+1,iy+1) - f1(ix+1,iy) ) / ( y1(1,2) - y1(1,1) )
667 f_y = alfa_x * f_y1 + ( 1.0_wp - alfa_x ) * f_y2
691 SUBROUTINE regrid_scalar(xin, yin, fin, xl, xr , yl, yr, fout)
694 REAL(wp),
INTENT(IN),
DIMENSION(:) :: xin, yin
695 REAL(wp),
INTENT(IN),
DIMENSION(:,:) :: fin
696 REAL(wp),
INTENT(IN) :: xl, xr , yl , yr
697 REAL(wp),
INTENT(OUT) :: fout
700 INTEGER :: ix1 , ix2 , iy1 , iy2
701 REAL(wp) :: alfa_x , alfa_y
702 REAL(wp) :: dXin , dYin
709 dxin = xin(2) - xin(1)
710 dyin = yin(2) - yin(1)
712 ix1 = max(1,ceiling( ( xl - xin(1) ) / dxin ))
713 ix2 = min(nxin,ceiling( ( xr -xin(1) ) / dxin )+1)
715 iy1 = max(1,ceiling( ( yl - yin(1) ) / dyin ))
716 iy2 = min(nyin,ceiling( ( yr - yin(1) ) / dyin ) + 1)
722 alfa_x = ( min(xr,xin(ix+1)) - max(xl,xin(ix)) ) / ( xr - xl )
726 alfa_y = ( min(yr,yin(iy+1)) - max(yl,yin(iy)) ) / ( yr - yl )
728 fout = fout + alfa_x * alfa_y * fin(ix,iy)
755 SUBROUTINE limit( v , z , limiter , slope_lim )
761 REAL(wp),
INTENT(IN) :: v(3)
762 REAL(wp),
INTENT(IN) :: z(3)
763 INTEGER,
INTENT(IN) :: limiter
765 REAL(wp),
INTENT(OUT) :: slope_lim
767 REAL(wp) :: a , b , c
769 REAL(wp) :: sigma1 , sigma2
771 a = ( v(3) - v(2) ) / ( z(3) - z(2) )
772 b = ( v(2) - v(1) ) / ( z(2) - z(1) )
773 c = ( v(3) - v(1) ) / ( z(3) - z(1) )
775 SELECT CASE (limiter)
789 sigma1 =
minmod( a , 2.0_wp*b )
790 sigma2 =
minmod( 2.0_wp*a , b )
791 slope_lim =
maxmod( sigma1 , sigma2 )
823 REAL(wp) FUNCTION minmod(a,b)
827 REAL(wp) :: a , b , sa , sb
829 IF ( a*b .EQ. 0.0_wp )
THEN 838 minmod = 0.5_wp * ( sa+sb ) * min( abs(a) , abs(b) )
844 REAL(wp) function maxmod(a,b)
848 REAL(wp) :: a , b , sa , sb
850 IF ( a*b .EQ. 0.0_wp )
THEN 859 maxmod = 0.5_wp * ( sa+sb ) * max( abs(a) , abs(b) )
871 REAL(wp),
ALLOCATABLE :: x_subgrid(:) , y_subgrid(:)
875 INTEGER,
ALLOCATABLE :: check_subgrid(:)
877 INTEGER n_points , n_points2
879 REAL(wp) :: source_area
880 REAL(wp) :: delta_x , delta_y
892 n_points2 = n_points**2
894 ALLOCATE( x_subgrid(n_points2) )
895 ALLOCATE( y_subgrid(n_points2) )
896 ALLOCATE( check_subgrid(n_points2) )
903 x_subgrid(h:n_points2:n_points) = dble(h)
904 y_subgrid((h-1)*n_points+1:h*n_points) = dble(h)
908 x_subgrid = ( 2.0_wp * x_subgrid - 1.0_wp ) / ( 2.0_wp * dble(n_points) )
909 y_subgrid = ( 2.0_wp * y_subgrid - 1.0_wp ) / ( 2.0_wp * dble(n_points) )
911 x_subgrid = ( x_subgrid - 0.5_wp ) *
dx 912 y_subgrid = ( y_subgrid - 0.5_wp ) *
dy 936 cell_fract(j,k) =
REAL(sum(check_subgrid))/n_points2
940 r_rel = min( 1.0_wp , sqrt( delta_x**2 + delta_y**2 ) /
r_source )
942 dx_rel(j,k) = delta_x / sqrt( delta_x**2 + delta_y**2 ) * r_rel *
dr_dz 943 dy_rel(j,k) = delta_y / sqrt( delta_x**2 + delta_y**2 ) * r_rel *
dr_dz 953 IF ( verbose_level .GE. 0 )
THEN 955 WRITE(*,*)
'Source area =',source_area,
' Error =',abs( 1.0_wp - &
960 DEALLOCATE( x_subgrid )
961 DEALLOCATE( y_subgrid )
962 DEALLOCATE( check_subgrid )
real(wp), dimension(:,:), allocatable sourcew_vect_x
real(wp), dimension(:,:), allocatable sourcew_vect_y
real(wp), dimension(:,:), allocatable sources_vect_x
integer comp_cells_x
Number of control volumes x in the comp. domain.
real(wp) dy2
Half y Control volumes size.
integer n_topography_profile_y
integer comp_cells_y
Number of control volumes y in the comp. domain.
logical, dimension(:,:), allocatable sourcee
logical, dimension(:,:), allocatable sourcew
real(wp) x0
Left of the physical domain.
real(wp), dimension(:,:), allocatable cell_fract
real(wp), dimension(:,:), allocatable sourcee_vect_x
subroutine regrid_scalar(xin, yin, fin, xl, xr, yl, yr, fout)
Scalar regrid (2D)
integer n_topography_profile_x
real(wp) yn
Top of the physical domain.
real(wp) function minmod(a, b)
integer comp_interfaces_y
Number of interfaces (comp_cells_y+1)
real(wp), dimension(:,:), allocatable dist_sourcee
real(wp), dimension(:), allocatable x_comp
Location of the centers (x) of the control volume of the domain.
real(wp) function maxmod(a, b)
real(wp), dimension(:,:), allocatable dist_sources
real(wp), dimension(:,:), allocatable sourcee_vect_y
subroutine init_grid
Finite volume grid initialization.
subroutine limit(v, z, limiter, slope_lim)
Slope limiter.
real(wp), dimension(:), allocatable x_stag
Location of the boundaries (x) of the control volumes of the domain.
subroutine interp_2d_slope(x1, y1, f1, x2, y2, f_x, f_y)
Scalar interpolation (2D)
real(wp), dimension(:,:), allocatable dist_sourcen
real(wp) dx2
Half x Control volumes size.
integer, dimension(:,:), allocatable source_cell
subroutine deallocate_grid
real(wp), dimension(:), allocatable y_stag
Location of the boundaries (x) of the control volumes of the domain.
subroutine compute_cell_fract
real(wp), dimension(:,:), allocatable dx_rel
subroutine interp_2d_scalarb(x1, y1, f1, x2, y2, f2)
Scalar interpolation (2D)
real(wp) dx
Control volumes size.
subroutine interp_2d_scalar(x1, y1, f1, x2, y2, f2)
Scalar interpolation (2D)
real(wp), dimension(:,:), allocatable upwind_dist
real(wp), dimension(:,:), allocatable sources_vect_y
integer, parameter wp
working precision
real(wp), dimension(:,:), allocatable sourcen_vect_y
real(wp), dimension(:,:), allocatable crosswind_dist
real(wp), dimension(:,:), allocatable grid_output
Solution in ascii grid format (ESRI)
logical, dimension(:,:), allocatable sourcen
integer comp_interfaces_x
Number of interfaces (comp_cells_x+1)
real(wp) y0
Bottom of the physical domain.
real(wp) xn
Right of the physical domain.
real(wp), dimension(:,:), allocatable dist_sourcew
real(wp) theta
Van Leer limiter parameter.
subroutine interp_1d_scalar(x1, f1, x2, f2)
Scalar interpolation.
real(wp) eps_sing
parameter for desingularization
real(wp), dimension(:), allocatable y_comp
Location of the centers (y) of the control volume of the domain.
real(wp), dimension(:,:), allocatable sourcen_vect_x
logical, dimension(:,:), allocatable sources
real(wp) dy
Control volumes size.
real(wp), dimension(:,:), allocatable dy_rel