42 REAL*8,
ALLOCATABLE ::
q(:,:,:)
44 REAL*8,
ALLOCATABLE ::
q0(:,:,:)
46 REAL*8,
ALLOCATABLE ::
q_fv(:,:,:)
86 REAL*8,
ALLOCATABLE ::
q1max(:,:)
107 REAL*8,
ALLOCATABLE ::
qp(:,:,:)
148 REAL*8,
ALLOCATABLE ::
q_rk(:,:,:,:)
151 REAL*8,
ALLOCATABLE ::
qp_rk(:,:,:,:)
158 REAL*8,
ALLOCATABLE ::
nh(:,:,:,:)
161 REAL*8,
ALLOCATABLE ::
si_nh(:,:,:,:)
170 REAL*8,
ALLOCATABLE ::
nhj(:,:)
219 REAL*8 :: gamma , delta
223 ALLOCATE(
q( n_vars , comp_cells_x , comp_cells_y ) ,
q0( n_vars , &
224 comp_cells_x , comp_cells_y ) )
226 ALLOCATE(
qp( n_vars+2 , comp_cells_x , comp_cells_y ) )
228 q(1:n_vars,1:comp_cells_x,1:comp_cells_y) = 0.d0
229 qp(1:n_vars+2,1:comp_cells_x,1:comp_cells_y) = 0.d0
231 ALLOCATE(
q1max( comp_cells_x , comp_cells_y ) )
233 ALLOCATE(
q_fv( n_vars , comp_cells_x , comp_cells_y ) )
235 ALLOCATE(
q_interfacel( n_vars , comp_interfaces_x, comp_cells_y ) )
236 ALLOCATE(
q_interfacer( n_vars , comp_interfaces_x, comp_cells_y ) )
239 ALLOCATE(
h_interface_x( n_eqns , comp_interfaces_x, comp_cells_y ) )
242 ALLOCATE(
q_interfaceb( n_vars , comp_cells_x, comp_interfaces_y ) )
243 ALLOCATE(
q_interfacet( n_vars , comp_cells_x, comp_interfaces_y ) )
247 ALLOCATE(
qp_interfacel( n_vars+2 , comp_interfaces_x, comp_cells_y ) )
248 ALLOCATE(
qp_interfacer( n_vars+2 , comp_interfaces_x, comp_cells_y ) )
249 ALLOCATE(
qp_interfaceb( n_vars+2 , comp_cells_x, comp_interfaces_y ) )
250 ALLOCATE(
qp_interfacet( n_vars+2 , comp_cells_x, comp_interfaces_y ) )
253 ALLOCATE(
q_cellnw( n_vars , comp_cells_x , comp_cells_y ) )
254 ALLOCATE(
q_cellne( n_vars , comp_cells_x , comp_cells_y ) )
255 ALLOCATE(
q_cellsw( n_vars , comp_cells_x , comp_cells_y ) )
256 ALLOCATE(
q_cellse( n_vars , comp_cells_x , comp_cells_y ) )
258 ALLOCATE(
qp_cellnw( n_vars+2 , comp_cells_x , comp_cells_y ) )
259 ALLOCATE(
qp_cellne( n_vars+2 , comp_cells_x , comp_cells_y ) )
260 ALLOCATE(
qp_cellsw( n_vars+2 , comp_cells_x , comp_cells_y ) )
261 ALLOCATE(
qp_cellse( n_vars+2 , comp_cells_x , comp_cells_y ) )
268 ALLOCATE(
h_interface_y( n_eqns , comp_cells_x, comp_interfaces_y ) )
270 ALLOCATE(
solve_mask( comp_cells_x , comp_cells_y ) )
271 ALLOCATE(
solve_mask_x( comp_interfaces_x , comp_cells_y ) )
272 ALLOCATE(
solve_mask_y( comp_cells_x , comp_interfaces_y ) )
274 ALLOCATE(
source_xy( comp_cells_x , comp_cells_y ) )
280 ALLOCATE(
omega(n_rk) )
284 ALLOCATE(
mask22(n_eqns,n_eqns) )
285 ALLOCATE(
mask21(n_eqns,n_eqns) )
286 ALLOCATE(
mask11(n_eqns,n_eqns) )
287 ALLOCATE(
mask12(n_eqns,n_eqns) )
290 mask11(1:n_eqns,1:n_eqns) = .false.
291 mask12(1:n_eqns,1:n_eqns) = .false.
292 mask22(1:n_eqns,1:n_eqns) = .false.
293 mask21(1:n_eqns,1:n_eqns) = .false.
331 gamma = 1.d0 - 1.d0 / sqrt(2.d0)
332 delta = 1.d0 - 1.d0 / ( 2.d0 * gamma )
334 IF ( n_rk .EQ. 1 )
THEN 344 ELSEIF ( n_rk .EQ. 2 )
THEN 357 ELSEIF ( n_rk .EQ. 3 )
THEN 376 omega(1) = 1.0d0 / 3.0d0
377 omega(2) = 1.0d0 / 3.0d0
378 omega(3) = 1.0d0 / 3.0d0
380 ELSEIF ( n_rk .EQ. 4 )
THEN 408 ALLOCATE(
q_rk( n_vars , comp_cells_x , comp_cells_y , n_rk ) )
409 ALLOCATE(
qp_rk( n_vars+2 , comp_cells_x , comp_cells_y , n_rk ) )
410 ALLOCATE(
divflux( n_eqns , comp_cells_x , comp_cells_y , n_rk ) )
411 ALLOCATE(
nh( n_eqns , comp_cells_x , comp_cells_y , n_rk ) )
412 ALLOCATE(
si_nh( n_eqns , comp_cells_x , comp_cells_y , n_rk ) )
414 ALLOCATE(
expl_terms( n_eqns , comp_cells_x , comp_cells_y , n_rk ) )
417 ALLOCATE(
nhj(n_eqns,n_rk) )
418 ALLOCATE(
si_nhj(n_eqns,n_rk) )
422 ALLOCATE(
residual_term( n_vars , comp_cells_x , comp_cells_y ) )
424 comp_cells_xy = comp_cells_x * comp_cells_y
426 ALLOCATE(
j_cent( comp_cells_xy ) )
427 ALLOCATE(
k_cent( comp_cells_xy ) )
429 ALLOCATE(
j_stag_x( comp_interfaces_x * comp_cells_y ) )
430 ALLOCATE(
k_stag_x( comp_interfaces_x * comp_cells_y ) )
432 ALLOCATE(
j_stag_y( comp_cells_x * comp_interfaces_y ) )
433 ALLOCATE(
k_stag_y( comp_cells_x * comp_interfaces_y ) )
553 solve_mask(1:comp_cells_x,1:comp_cells_y) = .false.
559 solve_mask(comp_cells_x,1:comp_cells_y) = .true.
561 solve_mask(1:comp_cells_x,comp_cells_y) = .true.
563 IF ( radial_source_flag )
THEN 565 DO k = 1,comp_cells_y
567 DO j = 1,comp_cells_x
569 IF ( source_cell(j,k) .EQ. 2 )
THEN 584 solve_mask(2:comp_cells_x-1,2:comp_cells_y-1) = &
585 solve_mask(2:comp_cells_x-1,2:comp_cells_y-1) .OR. &
586 solve_mask(1:comp_cells_x-2,2:comp_cells_y-1) .OR. &
587 solve_mask(3:comp_cells_x,2:comp_cells_y-1) .OR. &
588 solve_mask(2:comp_cells_x-1,1:comp_cells_y-2) .OR. &
593 IF ( radial_source_flag )
THEN 595 DO k = 1,comp_cells_y
597 DO j = 1,comp_cells_x
599 IF ( source_cell(j,k) .EQ. 1 )
solve_mask(j,k) = .false.
607 solve_mask_x(1:comp_interfaces_x,1:comp_cells_y) = .false.
608 solve_mask_y(1:comp_cells_x,1:comp_interfaces_y) = .false.
613 DO k = 1,comp_cells_y
615 DO j = 1,comp_cells_x
639 DO k = 1,comp_cells_y
641 DO j = 1,comp_interfaces_x
661 DO k = 1,comp_interfaces_y
663 DO j = 1,comp_cells_x
708 REAL*8 :: dt_interface_x, dt_interface_y
715 INTEGER :: max_j,max_k
722 IF (
cfl .NE. -1.d0 )
THEN 729 CALL qc_to_qp(
q(1:n_vars,j,k) ,
qp(1:n_vars+2,j,k) )
759 IF ( max_a .GT. max_vel)
THEN 768 IF ( max_a .GT. 0.d0 )
THEN 770 dt_interface_x =
cfl *
dx / max_a
781 IF ( max_a .GT. max_vel)
THEN 790 IF ( max_a .GT. 0.d0 )
THEN 792 dt_interface_y =
cfl *
dy / max_a
801 dt_cfl = min( dt_interface_x , dt_interface_y )
837 REAL*8 :: q_si(n_vars)
838 REAL*8 :: q_guess(n_vars)
844 q0( 1:n_vars , 1:comp_cells_x , 1:comp_cells_y ) = &
845 q( 1:n_vars , 1:comp_cells_x , 1:comp_cells_y )
847 IF ( verbose_level .GE. 2 )
WRITE(*,*)
'solver, imex_RK_solver: beginning' 850 q_rk(1:n_vars,1:comp_cells_x,1:comp_cells_y,1:n_rk) = 0.d0
851 qp_rk(1:n_vars+2,1:comp_cells_x,1:comp_cells_y,1:n_rk) = 0.d0
853 divflux(1:n_eqns,1:comp_cells_x,1:comp_cells_y,1:n_rk) = 0.d0
855 nh(1:n_eqns,1:comp_cells_x,1:comp_cells_y,1:n_rk) = 0.d0
857 si_nh(1:n_eqns,1:comp_cells_x,1:comp_cells_y,1:n_rk) = 0.d0
859 expl_terms(1:n_eqns,1:comp_cells_x,1:comp_cells_y,1:n_rk) = 0.d0
861 runge_kutta:
DO i_rk = 1,n_rk
863 IF ( verbose_level .GE. 2 )
WRITE(*,*)
'solver, imex_RK_solver: i_RK',
i_rk 883 IF ( verbose_level .GE. 2 )
THEN 885 WRITE(*,*)
'solver, imex_RK_solver: j',j,k
890 IF (
i_rk .EQ. 1 )
THEN 893 q_guess(1:n_vars) =
q0( 1:n_vars , j , k)
906 nhj(1:n_eqns,1:n_rk) =
nh( 1:n_eqns , j , k , 1:n_rk )
909 si_nhj(1:n_eqns,1:n_rk) =
si_nh( 1:n_eqns , j , k , 1:n_rk )
916 q_fv( 1:n_vars , j , k ) =
q0( 1:n_vars , j , k ) &
922 IF ( verbose_level .GE. 2 )
THEN 924 WRITE(*,*)
'q_guess',q_guess
926 WRITE(*,*)
'q_guess: qp',
qp(1:n_vars+2,j,k)
930 adiag_pos:
IF (
a_diag .NE. 0.d0 )
THEN 932 pos_thick:
IF (
q_fv(1,j,k) .GT. 0.d0 )
THEN 936 CALL eval_nh_semi_impl_terms( grav_surf(j,k) , &
945 IF ( (
q_fv(2,j,k)**2 +
q_fv(3,j,k)**2 ) .EQ. 0.d0 )
THEN 950 ELSEIF ( ( q_si(2)*
q_fv(2,j,k) .LT. 0.d0 ) .OR. &
951 ( q_si(3)*
q_fv(3,j,k) .LT. 0.d0 ) )
THEN 960 q_si(2:3) = dsqrt( q_si(2)**2 + q_si(3)**2 ) * &
961 q_fv(2:3,j,k) / dsqrt(
q_fv(2,j,k)**2 &
968 si_nh(1:n_eqns,j,k,
i_rk) = ( q_si(1:n_vars) - &
974 q_guess(1:n_vars) = q_si(1:n_vars)
981 IF ( comp_cells_y .EQ. 1 )
THEN 987 IF ( comp_cells_x .EQ. 1 )
THEN 994 CALL eval_nonhyperbolic_terms( r_qj =q_guess , &
995 r_nh_term_impl =
nh(1:n_eqns,j,k,
i_rk) )
997 IF ( q_si(2)**2 + q_si(3)**2 .EQ. 0.d0 )
THEN 1001 ELSEIF ( ( q_guess(2)*q_si(2) .LE. 0.d0 ) .AND. &
1002 ( q_guess(3)*q_si(3) .LE. 0.d0 ) )
THEN 1011 q_guess(2:3) = dsqrt( q_guess(2)**2 + q_guess(3)**2 ) * &
1012 q_si(2:3) / dsqrt( q_si(2)**2 + q_si(3)**2 )
1019 q_guess(1:n_vars) =
q_fv( 1:n_vars , j , k )
1020 q_si(1:n_vars) =
q_fv( 1:n_vars , j , k )
1022 nh(1:n_eqns,j,k,
i_rk) = 0.d0
1031 IF (
a_diag .NE. 0.d0 )
THEN 1034 nh(1:n_vars,j,k,
i_rk) = ( q_guess(1:n_vars) - q_si(1:n_vars)) &
1040 q_rk( 1:n_vars , j , k ,
i_rk ) = q_guess
1042 IF ( verbose_level .GE. 2 )
THEN 1044 WRITE(*,*)
'imex_RK_solver: qc',q_guess
1045 CALL qc_to_qp( q_guess ,
qp(1:n_vars+2,j,k) )
1046 WRITE(*,*)
'imex_RK_solver: qp',
qp(1:n_vars+2,j,k)
1072 q_rk(1:n_vars,1:comp_cells_x,1:comp_cells_y,
i_rk) , &
1073 qp_rk(1:n_vars+2,1:comp_cells_x,1:comp_cells_y,
i_rk) , &
1074 divflux(1:n_eqns,1:comp_cells_x,1:comp_cells_y,
i_rk) )
1082 q_rk(1:n_vars,1:comp_cells_x,1:comp_cells_y,
i_rk) , &
1083 qp_rk(1:n_vars+2,1:comp_cells_x,1:comp_cells_y,
i_rk) , &
1100 matmul(
nh(1:n_eqns,j,k,1:n_rk) +
si_nh(1:n_eqns,j,k,1:n_rk) , &
1110 IF ( verbose_level .GE. 1 )
THEN 1112 WRITE(*,*)
'cell jk =',j,k
1113 WRITE(*,*)
'before imex_RK_solver: qc',
q0(1:n_vars,j,k)
1115 WRITE(*,*)
'before imex_RK_solver: qp',
qp(1:n_vars+2,j,k)
1123 q(1:n_vars,j,k) =
q_rk(1:n_vars,j,k,n_rk)
1132 negative_thickness_check:
IF (
q(1,j,k) .LT. 0.d0 )
THEN 1134 IF (
q(1,j,k) .GT. -1.d-7 )
THEN 1137 q(2:n_vars,j,k) = 0.d0
1141 WRITE(*,*)
'j,k,n_RK',j,k,n_rk
1143 WRITE(*,*)
'source_cell',source_cell(j,k)
1144 WRITE(*,*)
'source_cell left',source_cell(j-1,k)
1145 WRITE(*,*)
'source_cell right',source_cell(j+1,k)
1146 WRITE(*,*)
'source_cell top',source_cell(j,k+1)
1147 WRITE(*,*)
'source_cell bottom',source_cell(j,k-1)
1148 WRITE(*,*)
'before imex_RK_solver: qc',
q0(1:n_vars,j,k)
1150 WRITE(*,*)
'before imex_RK_solver: qp',
qp(1:n_vars+2,j,k)
1151 WRITE(*,*)
'h old',
q0(1,j,k)
1152 WRITE(*,*)
'h new',
q(1,j,k)
1153 WRITE(*,*)
'B_cent(j,k)',b_cent(j,k)
1154 WRITE(*,*)
'qp_interfaceR(1:n_vars+2,j,k)',
qp_interfacer(1:n_vars+2,j,k)
1155 WRITE(*,*)
'qp_interfaceL(1:n_vars+2,j+1,k)',
qp_interfacel(1:n_vars+2,j+1,k)
1156 WRITE(*,*)
'qp_interfaceT(1:n_vars+2,j,k)',
qp_interfacet(1:n_vars+2,j,k)
1157 WRITE(*,*)
'qp_interfaceB(1:n_vars+2,j,k+1)',
qp_interfaceb(1:n_vars+2,j,k)
1166 END IF negative_thickness_check
1168 IF ( sum(
q(5:4+n_solid,j,k)) .GT.
q(1,j,k) )
THEN 1170 IF ( sum(
q(5:4+n_solid,j,k))-
q(1,j,k) .LT. 1.d-10 )
THEN 1172 q(5:4+n_solid,j,k) =
q(5:4+n_solid,j,k) &
1173 / sum(
q(5:4+n_solid,j,k)) *
q(1,j,k)
1177 WRITE(*,*)
'j,k,n_RK',j,k,n_rk
1179 WRITE(*,*)
' B_cent(j,k)', b_cent(j,k)
1180 WRITE(*,*)
'before imex_RK_solver: qc',
q0(1:n_vars,j,k)
1182 WRITE(*,*)
'before imex_RK_solver: qp',
qp(1:n_vars+2,j,k)
1183 WRITE(*,*)
'after imex_RK_solver: qc',
q(1:n_vars,j,k)
1184 CALL qc_to_qp(
q(1:n_vars,j,k) ,
qp(1:n_vars+2,j,k))
1185 WRITE(*,*)
'after imex_RK_solver: qp',
qp(1:n_vars+2,j,k)
1190 IF ( verbose_level .GE. 1 )
THEN 1192 WRITE(*,*)
'h new',
q(1,j,k)
1227 SUBROUTINE solve_rk_step( qj, qj_old, a_tilde , a_dirk , a_diag )
1235 REAL*8,
INTENT(INOUT) :: qj(n_vars)
1236 REAL*8,
INTENT(IN) :: qj_old(n_vars)
1237 REAL*8,
INTENT(IN) :: a_tilde(n_rk)
1238 REAL*8,
INTENT(IN) :: a_dirk(n_rk)
1239 REAL*8,
INTENT(IN) :: a_diag
1241 REAL*8 :: qj_init(n_vars)
1243 REAL*8 :: qj_org(n_vars) , qj_rel(n_vars)
1245 REAL*8 :: left_matrix(n_eqns,n_vars)
1246 REAL*8 :: right_term(n_eqns)
1250 REAL*8 :: coeff_f(n_eqns)
1252 REAL*8 :: qj_rel_NR_old(n_vars)
1253 REAL*8 :: scal_f_old
1254 REAL*8 :: desc_dir(n_vars)
1255 REAL*8 :: grad_f(n_vars)
1258 INTEGER :: pivot(n_vars)
1260 REAL*8 :: left_matrix_small22(n_nh,n_nh)
1261 REAL*8 :: left_matrix_small21(n_eqns-n_nh,n_nh)
1262 REAL*8 :: left_matrix_small11(n_eqns-n_nh,n_vars-n_nh)
1263 REAL*8 :: left_matrix_small12(n_nh,n_vars-n_nh)
1265 REAL*8 :: desc_dir_small2(n_nh)
1266 INTEGER :: pivot_small2(n_nh)
1268 REAL*8 :: desc_dir_small1(n_vars-n_nh)
1275 REAL*8,
PARAMETER :: STPMX=100.d0
1279 REAL*8,
PARAMETER :: TOLF=1.d-10 , tolmin=1.d-6
1282 REAL*8 :: qpj(n_vars+2)
1284 REAL*8 :: desc_dir2(n_vars)
1286 REAL*8 :: desc_dir_temp(n_vars)
1292 coeff_f(1:n_eqns) = 1.d0
1294 grad_f(1:n_eqns) = 0.d0
1302 - matmul(
nhj,a_dirk) )
1304 CALL eval_f( qj , qj_old , a_tilde , a_dirk , a_diag , coeff_f , &
1305 right_term , scal_f )
1307 IF ( verbose_level .GE. 3 )
THEN 1309 WRITE(*,*)
'solve_rk_step: non-normalized right_term' 1310 WRITE(*,*) right_term
1311 WRITE(*,*)
'scal_f',scal_f
1317 IF ( abs(right_term(i)) .GE. 1.d0 ) coeff_f(i) = 1.d0 / right_term(i)
1321 right_term = coeff_f * right_term
1323 scal_f = 0.5d0 * dot_product( right_term , right_term )
1325 IF ( verbose_level .GE. 3 )
THEN 1326 WRITE(*,*)
'solve_rk_step: after normalization',scal_f
1337 qj_org = max( abs(qj_org) , 1.d-3 )
1341 qj_org(1:n_vars) = 1.d0
1345 qj_rel = qj / qj_org
1351 tolx = epsilon(qj_rel)
1353 IF ( verbose_level .GE. 2 )
WRITE(*,*)
'solve_rk_step: nl_iter',nl_iter
1355 CALL eval_f( qj , qj_old , a_tilde , a_dirk , a_diag , coeff_f , &
1356 right_term , scal_f )
1358 IF ( verbose_level .GE. 2 )
THEN 1360 WRITE(*,*)
'solve_rk_step: right_term',right_term
1364 IF ( verbose_level .GE. 2 )
THEN 1366 WRITE(*,*)
'before_lnsrch: scal_f',scal_f
1372 IF ( maxval( abs( right_term(:) ) ) < tolf )
THEN 1374 IF ( verbose_level .GE. 3 )
WRITE(*,*)
'1: check',check
1379 IF ( (
normalize_f ) .AND. ( scal_f < 1.d-6 ) )
THEN 1381 IF ( verbose_level .GE. 3 )
WRITE(*,*)
'check scal_f',check
1388 IF ( count( implicit_flag ) .EQ. n_eqns )
THEN 1392 desc_dir_temp = - right_term
1394 CALL dgesv(n_eqns,1, left_matrix , n_eqns, pivot, desc_dir_temp , &
1397 desc_dir = desc_dir_temp
1403 left_matrix_small11 = reshape(pack(left_matrix,
mask11), &
1404 [n_eqns-n_nh,n_eqns-n_nh])
1406 left_matrix_small12 = reshape(pack(left_matrix,
mask12), &
1409 left_matrix_small22 = reshape(pack(left_matrix,
mask22), &
1412 left_matrix_small21 = reshape(pack(left_matrix,
mask21), &
1415 desc_dir_small1 = pack( right_term, .NOT.implicit_flag )
1416 desc_dir_small2 = pack( right_term , implicit_flag )
1420 desc_dir_small1(i) = desc_dir_small1(i) / left_matrix_small11(i,i)
1424 desc_dir_small2 = desc_dir_small2 - &
1425 matmul( desc_dir_small1 , left_matrix_small21 )
1427 CALL dgesv(n_nh,1, left_matrix_small22 , n_nh , pivot_small2 , &
1428 desc_dir_small2 , n_nh, ok)
1430 desc_dir = unpack( - desc_dir_small2 , implicit_flag , 0.0d0 ) &
1431 + unpack( - desc_dir_small1 , .NOT.implicit_flag , 0.0d0 )
1444 IF ( verbose_level .GE. 3 )
WRITE(*,*)
'desc_dir',desc_dir
1446 qj_rel_nr_old = qj_rel
1452 stpmax = stpmx * max( sqrt( dot_product(qj_rel,qj_rel) ) , &
1453 dble(
SIZE(qj_rel) ) )
1455 grad_f = matmul( right_term , left_matrix )
1457 desc_dir2 = desc_dir
1459 CALL lnsrch( qj_rel_nr_old , qj_org , qj_old , scal_f_old , grad_f , &
1460 desc_dir , coeff_f , qj_rel , scal_f , right_term , stpmax , &
1465 qj_rel = qj_rel_nr_old + desc_dir
1467 qj = qj_rel * qj_org
1469 CALL eval_f( qj , qj_old , a_tilde , a_dirk , a_diag , coeff_f , &
1470 right_term , scal_f )
1474 IF ( verbose_level .GE. 2 )
WRITE(*,*)
'after_lnsrch: scal_f',scal_f
1476 qj = qj_rel * qj_org
1478 IF ( verbose_level .GE. 3 )
THEN 1487 IF ( maxval( abs( right_term(:) ) ) < tolf )
THEN 1489 IF ( verbose_level .GE. 3 )
WRITE(*,*)
'1: check',check
1497 check = ( maxval( abs(grad_f(:)) * max( abs( qj_rel(:) ),1.d0 ) / &
1498 max( scal_f , 0.5d0 *
SIZE(qj_rel) ) ) < tolmin )
1500 IF ( verbose_level .GE. 3 )
WRITE(*,*)
'2: check',check
1505 IF ( maxval( abs( qj_rel(:) - qj_rel_nr_old(:) ) / max( abs( qj_rel(:)) ,&
1506 1.d0 ) ) < tolx )
THEN 1508 IF ( verbose_level .GE. 3 )
WRITE(*,*)
'check',check
1513 END DO newton_raphson_loop
1541 SUBROUTINE lnsrch( qj_rel_NR_old , qj_org , qj_old , scal_f_old , grad_f , &
1542 desc_dir , coeff_f , qj_rel , scal_f , right_term , stpmax , check )
1547 REAL*8,
DIMENSION(:),
INTENT(IN) :: qj_rel_NR_old
1550 REAL*8,
DIMENSION(:),
INTENT(IN) :: qj_org
1553 REAL*8,
DIMENSION(:),
INTENT(IN) :: qj_old
1556 REAL*8,
DIMENSION(:),
INTENT(IN) :: grad_f
1559 REAL*8,
INTENT(IN) :: scal_f_old
1562 REAL*8,
DIMENSION(:),
INTENT(INOUT) :: desc_dir
1564 REAL*8,
INTENT(IN) :: stpmax
1567 REAL*8,
DIMENSION(:),
INTENT(IN) :: coeff_f
1570 REAL*8,
DIMENSION(:),
INTENT(OUT) :: qj_rel
1573 REAL*8,
INTENT(OUT) :: scal_f
1576 REAL*8,
INTENT(OUT) :: right_term(n_eqns)
1579 LOGICAL,
INTENT(OUT) :: check
1581 REAL*8,
PARAMETER :: TOLX=epsilon(qj_rel)
1583 INTEGER,
DIMENSION(1) :: ndum
1584 REAL*8 :: ALF , a,alam,alam2,alamin,b,disc
1586 REAL*8 :: desc_dir_abs
1587 REAL*8 :: rhs1 , rhs2 , slope, tmplam
1589 REAL*8 :: scal_f_min , alam_min
1591 REAL*8 :: qj(n_vars)
1595 IF (
size(grad_f) ==
size(desc_dir) .AND.
size(grad_f) ==
size(qj_rel) &
1596 .AND.
size(qj_rel) ==
size(qj_rel_nr_old) )
THEN 1602 WRITE(*,*)
'nrerror: an assert_eq failed with this tag:',
'lnsrch' 1603 stop
'program terminated by assert_eq4' 1609 desc_dir_abs = sqrt( dot_product(desc_dir,desc_dir) )
1611 IF ( desc_dir_abs > stpmax ) desc_dir(:) = desc_dir(:) * stpmax/desc_dir_abs
1613 slope = dot_product(grad_f,desc_dir)
1615 alamin = tolx / maxval( abs( desc_dir(:))/max( abs(qj_rel_nr_old(:)),1.d0 ) )
1617 IF ( alamin .EQ. 0.d0)
THEN 1619 qj_rel(:) = qj_rel_nr_old(:)
1627 scal_f_min = scal_f_old
1629 optimal_step_search:
DO 1631 IF ( verbose_level .GE. 4 )
THEN 1633 WRITE(*,*)
'alam',alam
1637 qj_rel = qj_rel_nr_old + alam * desc_dir
1639 qj = qj_rel * qj_org
1642 right_term , scal_f )
1644 IF ( verbose_level .GE. 4 )
THEN 1646 WRITE(*,*)
'lnsrch: effe_old,effe',scal_f_old,scal_f
1651 IF ( scal_f .LT. scal_f_min )
THEN 1658 IF ( scal_f .LE. 0.9 * scal_f_old )
THEN 1661 IF ( verbose_level .GE. 4 )
THEN 1663 WRITE(*,*)
'sufficient function decrease' 1667 EXIT optimal_step_search
1669 ELSE IF ( alam < alamin )
THEN 1672 IF ( verbose_level .GE. 4 )
THEN 1674 WRITE(*,*)
' convergence on Delta_x',alam,alamin
1678 qj_rel(:) = qj_rel_nr_old(:)
1682 EXIT optimal_step_search
1687 IF ( alam .EQ. 1.d0 )
THEN 1689 tmplam = - slope / ( 2.0d0 * ( scal_f - scal_f_old - slope ) )
1693 rhs1 = scal_f - scal_f_old - alam*slope
1694 rhs2 = scal_f2 - scal_f_old - alam2*slope
1696 a = ( rhs1/alam**2.d0 - rhs2/alam2**2.d0 ) / ( alam - alam2 )
1697 b = ( -alam2*rhs1/alam**2 + alam*rhs2/alam2**2 ) / ( alam - alam2 )
1699 IF ( a .EQ. 0.d0 )
THEN 1701 tmplam = - slope / ( 2.0d0 * b )
1705 disc = b*b - 3.0d0*a*slope
1707 IF ( disc .LT. 0.d0 )
THEN 1709 tmplam = 0.5d0 * alam
1711 ELSE IF ( b .LE. 0.d0 )
THEN 1713 tmplam = ( - b + sqrt(disc) ) / ( 3.d0 * a )
1717 tmplam = - slope / ( b + sqrt(disc) )
1723 IF ( tmplam .GT. 0.5d0*alam ) tmplam = 0.5d0 * alam
1731 alam = max( tmplam , 0.5d0*alam )
1733 END DO optimal_step_search
1757 SUBROUTINE eval_f( qj , qj_old , a_tilde , a_dirk , a_diag , coeff_f , f_nl , &
1764 REAL*8,
INTENT(IN) :: qj(n_vars)
1765 REAL*8,
INTENT(IN) :: qj_old(n_vars)
1766 REAL*8,
INTENT(IN) :: a_tilde(n_rk)
1767 REAL*8,
INTENT(IN) :: a_dirk(n_rk)
1768 REAL*8,
INTENT(IN) :: a_diag
1769 REAL*8,
INTENT(IN) :: coeff_f(n_eqns)
1770 REAL*8,
INTENT(OUT) :: f_nl(n_eqns)
1771 REAL*8,
INTENT(OUT) :: scal_f
1773 REAL*8 :: nh_term_impl(n_eqns)
1774 REAL*8 :: Rj(n_eqns)
1779 a_tilde(1:
i_rk-1) ) - matmul(
nhj(1:n_eqns,1:
i_rk-1) &
1781 - a_diag * ( nh_term_impl +
si_nhj(1:n_eqns,
i_rk) )
1783 f_nl = qj - qj_old +
dt * rj
1785 f_nl = coeff_f * f_nl
1787 scal_f = 0.5d0 * dot_product( f_nl , f_nl )
1809 SUBROUTINE eval_jacobian( qj_rel , qj_org , coeff_f, left_matrix)
1815 REAL*8,
INTENT(IN) :: qj_rel(n_vars)
1816 REAL*8,
INTENT(IN) :: qj_org(n_vars)
1817 REAL*8,
INTENT(IN) :: coeff_f(n_eqns)
1819 REAL*8,
INTENT(OUT) :: left_matrix(n_eqns,n_vars)
1821 REAL*8 :: Jacob_relax(n_eqns,n_vars)
1822 COMPLEX*16 :: nh_terms_cmplx_impl(n_eqns)
1823 COMPLEX*16 :: qj_cmplx(n_vars) , qj_rel_cmplx(n_vars)
1829 h = n_vars * epsilon(1.d0)
1833 left_matrix(1:n_eqns,1:n_vars) = 0.d0
1834 jacob_relax(1:n_eqns,1:n_vars) = 0.d0
1840 left_matrix(i,i) = coeff_f(i) * qj_org(i)
1842 IF ( implicit_flag(i) )
THEN 1844 qj_rel_cmplx(1:n_vars) = qj_rel(1:n_vars)
1845 qj_rel_cmplx(i) = dcmplx(qj_rel(i), h)
1847 qj_cmplx = qj_rel_cmplx * qj_org
1850 c_nh_term_impl = nh_terms_cmplx_impl )
1852 jacob_relax(1:n_eqns,i) = coeff_f(i) * &
1853 aimag(nh_terms_cmplx_impl) / h
1855 left_matrix(1:n_eqns,i) = left_matrix(1:n_eqns,i) -
dt *
a_diag &
1856 * jacob_relax(1:n_eqns,i)
1893 REAL*8,
INTENT(IN) :: dt
1895 REAL*8 :: erosion_term(n_solid)
1896 REAL*8 :: deposition_term(n_solid)
1897 REAL*8 :: eqns_term(n_eqns)
1898 REAL*8 :: deposit_term(n_solid)
1900 REAL*8 :: r_Ri , r_rho_m
1902 REAL*8 :: r_red_grav
1906 IF ( ( sum(erosion_coeff) .EQ. 0.d0 ) .AND. ( .NOT. settling_flag ) )
RETURN 1913 CALL qc_to_qp(
q(1:n_vars,j,k) ,
qp(1:n_vars+2,j,k) )
1915 CALL eval_erosion_dep_term(
qp(1:n_vars+2,j,k) , dt , &
1916 erosion_term(1:n_solid) , deposition_term(1:n_solid) )
1919 deposition_term(1:n_solid) = max(0.d0,min( deposition_term(1:n_solid), &
1920 q(5:4+n_solid,j,k) / ( rho_s(1:n_solid) * dt ) ))
1923 CALL eval_topo_term(
qp(1:n_vars+2,j,k) , deposition_term , &
1924 erosion_term , eqns_term , deposit_term )
1926 IF ( verbose_level .GE. 2 )
THEN 1928 WRITE(*,*)
'before update erosion/deposition: j,k,q(:,j,k),B(j,k)', &
1929 j,k,
q(:,j,k),b_cent(j,k)
1934 q(1:n_eqns,j,k) =
q(1:n_eqns,j,k) + dt * eqns_term(1:n_eqns)
1936 deposit(j,k,1:n_solid) =
deposit(j,k,1:n_solid)+dt*deposit_term(1:n_solid)
1941 b_cent(j,k) = b_cent(j,k) + dt * sum( deposit_term(1:n_solid) )
1946 IF (
q(1,j,k) .LT. 0.d0 )
THEN 1948 IF (
q(1,j,k) .GT. -1.d-10 )
THEN 1950 q(1:n_vars,j,k) = 0.d0
1954 WRITE(*,*)
'j,k',j,k
1956 WRITE(*,*)
'before erosion' 1957 WRITE(*,*)
'qp',
qp(1:n_eqns+2,j,k)
1958 WRITE(*,*)
'deposition_term',deposition_term
1959 WRITE(*,*)
'erosion_term',erosion_term
1960 CALL qc_to_qp(
q(1:n_vars,j,k) ,
qp(1:n_vars+2,j,k))
1961 WRITE(*,*)
'qp',
qp(1:n_eqns+2,j,k)
1968 CALL qc_to_qp(
q(1:n_vars,j,k) ,
qp(1:n_vars+2,j,k) )
1969 CALL mixt_var(
qp(1:n_vars+2,j,k),r_ri,r_rho_m,r_rho_c,r_red_grav)
1971 IF ( r_red_grav .LE. 0.d0 )
THEN 1973 q(1:n_vars,j,k) = 0.d0
2004 REAL*8,
INTENT(IN) :: qc_expl(n_vars,comp_cells_x,comp_cells_y)
2005 REAL*8,
INTENT(IN) :: qp_expl(n_vars+2,comp_cells_x,comp_cells_y)
2006 REAL*8,
INTENT(OUT) :: expl_terms(n_eqns,comp_cells_x,comp_cells_y)
2008 REAL*8 :: qcj(n_vars)
2009 REAL*8 :: qpj(n_vars+2)
2010 REAL*8 :: expl_forces_term(n_eqns)
2021 qcj(1:n_vars) = qc_expl(1:n_vars,j,k)
2022 qpj(1:n_vars+2) = qp_expl(1:n_vars+2,j,k)
2025 qpj(1:n_vars+2) , qcj(1:n_vars) , expl_forces_term )
2027 expl_terms(1:n_eqns,j,k) = expl_forces_term
2060 REAL*8,
INTENT(IN) :: q_expl(n_vars,comp_cells_x,comp_cells_y)
2061 REAL*8,
INTENT(IN) :: qp_expl(n_vars+2,comp_cells_x,comp_cells_y)
2062 REAL*8,
INTENT(OUT) :: divFlux(n_eqns,comp_cells_x,comp_cells_y)
2064 REAL*8 :: h_new , h_old
2068 INTEGER :: l , i, j, k
2116 divflux(i,j,k) = 0.d0
2118 IF ( comp_cells_x .GT. 1 )
THEN 2120 divflux(i,j,k) = divflux(i,j,k) + &
2125 IF ( comp_cells_y .GT. 1 )
THEN 2127 divflux(i,j,k) = divflux(i,j,k) + &
2134 h_old = q_expl(1,j,k)
2135 h_new = h_old -
dt * divflux(1,j,k)
2163 REAL*8 :: fluxL(n_eqns)
2164 REAL*8 :: fluxR(n_eqns)
2165 REAL*8 :: fluxB(n_eqns)
2166 REAL*8 :: fluxT(n_eqns)
2173 IF ( comp_cells_x .GT. 1 )
THEN 2216 IF ( comp_cells_y .GT. 1 )
THEN 2281 REAL*8 :: fluxL(n_eqns)
2282 REAL*8 :: fluxR(n_eqns)
2283 REAL*8 :: fluxB(n_eqns)
2284 REAL*8 :: fluxT(n_eqns)
2286 REAL*8 :: flux_avg_x(n_eqns)
2287 REAL*8 :: flux_avg_y(n_eqns)
2294 IF ( comp_cells_x .GT. 1 )
THEN 2309 fluxl , fluxr , flux_avg_x )
2311 eqns_loop:
DO i=1,n_eqns
2343 IF ( comp_cells_y .GT. 1 )
THEN 2409 SUBROUTINE average_kt( a1 , a2 , w1 , w2 , w_avg )
2413 REAL*8,
INTENT(IN) :: a1(:) , a2(:)
2414 REAL*8,
INTENT(IN) :: w1(:) , w2(:)
2415 REAL*8,
INTENT(OUT) :: w_avg(:)
2424 IF ( a1(i) .EQ. a2(i) )
THEN 2426 w_avg(i) = 0.5d0 * ( w1(i) + w2(i) )
2431 w_avg(i) = ( a2(i) * w1(i) - a1(i) * w2(i) ) / ( a2(i) - a1(i) )
2451 WRITE(*,*)
'method not yet implemented in 2-d case' 2465 WRITE(*,*)
'method not yet implemented in 2-d case' 2512 REAL*8,
INTENT(IN) :: q_expl(:,:,:)
2513 REAL*8,
INTENT(IN) :: qp_expl(:,:,:)
2515 REAL*8,
ALLOCATABLE :: qrec(:,:,:)
2516 REAL*8,
ALLOCATABLE :: qrecW(:)
2517 REAL*8,
ALLOCATABLE :: qrecE(:)
2518 REAL*8,
ALLOCATABLE :: qrecS(:)
2519 REAL*8,
ALLOCATABLE :: qrecN(:)
2521 REAL*8,
ALLOCATABLE :: source_bdry(:)
2522 REAL*8,
ALLOCATABLE :: qrec_prime_x(:)
2523 REAL*8,
ALLOCATABLE :: qrec_prime_y(:)
2525 REAL*8 :: qp2recW(3) , qp2recE(3)
2526 REAL*8 :: qp2recS(3) , qp2recN(3)
2528 REAL*8 :: qrec_stencil(3)
2529 REAL*8 :: x_stencil(3)
2530 REAL*8 :: y_stencil(3)
2536 ALLOCATE ( qrec(n_vars+2,comp_cells_x,comp_cells_y) )
2537 ALLOCATE ( qrecw(n_vars+2) )
2538 ALLOCATE ( qrece(n_vars+2) )
2539 ALLOCATE ( qrecs(n_vars+2) )
2540 ALLOCATE ( qrecn(n_vars+2) )
2542 ALLOCATE ( source_bdry(n_vars+2) )
2544 ALLOCATE ( qrec_prime_x(n_vars+2) )
2545 ALLOCATE ( qrec_prime_y(n_vars+2) )
2548 DO k = 1,comp_cells_y
2550 DO j = 1,comp_cells_x
2552 qrec(1:n_vars+2,j,k) = qp_expl(1:n_vars+2,j,k)
2554 IF ( sum(qrec(5:4+n_solid,j,k)) .GT. 1.d0 )
THEN 2556 WRITE(*,*)
'reconstruction: j,k',j,k
2557 WRITE(*,*)
'qrec(5:n_solid,j,k)',qrec(5:4+n_solid,j,k)
2558 WRITE(*,*)
'q(1:n_vars,j,k)',q_expl(1:n_vars,j,k)
2559 WRITE(*,*)
'B_cent(j,k)', b_cent(j,k)
2575 qrecw(1:n_vars+2) = qp_expl(1:n_vars+2,j,k)
2576 qrece(1:n_vars+2) = qp_expl(1:n_vars+2,j,k)
2577 qrecs(1:n_vars+2) = qp_expl(1:n_vars+2,j,k)
2578 qrecn(1:n_vars+2) = qp_expl(1:n_vars+2,j,k)
2580 vars_loop:
DO i=1,n_vars
2583 check_comp_cells_x:
IF ( comp_cells_x .GT. 1 )
THEN 2586 check_x_boundary:
IF (j.EQ.1)
THEN 2588 IF ( bcw(i)%flag .EQ. 0 )
THEN 2590 x_stencil(1) = x_stag(1)
2591 x_stencil(2:3) = x_comp(1:2)
2593 qrec_stencil(1) = bcw(i)%value
2594 qrec_stencil(2:3) = qrec(i,1:2,k)
2596 CALL limit( qrec_stencil , x_stencil , limiter(i) , &
2599 ELSEIF ( bcw(i)%flag .EQ. 1 )
THEN 2601 qrec_prime_x(i) = bcw(i)%value
2603 ELSEIF ( bcw(i)%flag .EQ. 2 )
THEN 2605 qrec_prime_x(i) = ( qrec(i,2,k) - qrec(i,1,k) ) / dx
2610 ELSEIF (j.EQ.comp_cells_x)
THEN 2612 IF ( bce(i)%flag .EQ. 0 )
THEN 2614 qrec_stencil(3) = bce(i)%value
2615 qrec_stencil(1:2)= qrec(i,comp_cells_x-1:comp_cells_x,k)
2617 x_stencil(3) = x_stag(comp_interfaces_x)
2618 x_stencil(1:2) = x_comp(comp_cells_x-1:comp_cells_x)
2620 CALL limit( qrec_stencil , x_stencil , limiter(i) , &
2623 ELSEIF ( bce(i)%flag .EQ. 1 )
THEN 2625 qrec_prime_x(i) = bce(i)%value
2627 ELSEIF ( bce(i)%flag .EQ. 2 )
THEN 2629 qrec_prime_x(i) = ( qrec(i,comp_cells_x,k) - &
2630 qrec(i,comp_cells_x-1,k) ) / dx
2637 x_stencil(1:3) = x_comp(j-1:j+1)
2638 qrec_stencil(1:3) = qrec(i,j-1:j+1,k)
2642 IF ( radial_source_flag .AND. ( source_cell(j,k).EQ.2 ) )
THEN 2644 IF ( sourcee(j,k) )
THEN 2647 sourcee_vect_y(j,k) , source_bdry )
2649 x_stencil(3) = x_stag(j+1)
2650 qrec_stencil(3) = source_bdry(i)
2652 ELSEIF ( sourcew(j,k) )
THEN 2655 sourcew_vect_y(j,k) , source_bdry )
2657 x_stencil(1) = x_stag(j)
2658 qrec_stencil(1) = source_bdry(i)
2664 CALL limit( qrec_stencil , x_stencil , limiter(i) , &
2667 ENDIF check_x_boundary
2672 END IF check_comp_cells_x
2675 check_comp_cells_y:
IF ( comp_cells_y .GT. 1 )
THEN 2678 check_y_boundary:
IF (k.EQ.1)
THEN 2680 IF ( bcs(i)%flag .EQ. 0 )
THEN 2682 qrec_stencil(1) = bcs(i)%value
2683 qrec_stencil(2:3) = qrec(i,j,1:2)
2685 y_stencil(1) = y_stag(1)
2686 y_stencil(2:3) = y_comp(1:2)
2688 CALL limit( qrec_stencil , y_stencil , limiter(i) , &
2691 ELSEIF ( bcs(i)%flag .EQ. 1 )
THEN 2693 qrec_prime_y(i) = bcs(i)%value
2695 ELSEIF ( bcs(i)%flag .EQ. 2 )
THEN 2697 qrec_prime_y(i) = ( qrec(i,j,2) - qrec(i,j,1) ) / dy
2702 ELSEIF ( k .EQ. comp_cells_y )
THEN 2704 IF ( bcn(i)%flag .EQ. 0 )
THEN 2706 qrec_stencil(3) = bcn(i)%value
2707 qrec_stencil(1:2)= qrec(i,j,comp_cells_y-1:comp_cells_y)
2709 y_stencil(3) = y_stag(comp_interfaces_y)
2710 y_stencil(1:2) = y_comp(comp_cells_y-1:comp_cells_y)
2712 CALL limit( qrec_stencil , y_stencil , limiter(i) , &
2715 ELSEIF ( bcn(i)%flag .EQ. 1 )
THEN 2717 qrec_prime_y(i) = bcn(i)%value
2719 ELSEIF ( bcn(i)%flag .EQ. 2 )
THEN 2721 qrec_prime_y(i) = ( qrec(i,j,comp_cells_y) - &
2722 qrec(i,j,comp_cells_y-1) ) / dy
2729 y_stencil(1:3) = y_comp(k-1:k+1)
2730 qrec_stencil = qrec(i,j,k-1:k+1)
2734 IF ( radial_source_flag .AND. ( source_cell(j,k).EQ.2 ) )
THEN 2736 IF ( sources(j,k) )
THEN 2739 sources_vect_y(j,k) , source_bdry )
2741 y_stencil(1) = y_stag(k)
2742 qrec_stencil(1) = source_bdry(i)
2744 ELSEIF ( sourcen(j,k) )
THEN 2747 sourcen_vect_y(j,k) , source_bdry )
2749 x_stencil(3) = y_stag(k+1)
2750 qrec_stencil(3) = source_bdry(i)
2756 CALL limit( qrec_stencil , y_stencil , limiter(i) , &
2759 ENDIF check_y_boundary
2764 ENDIF check_comp_cells_y
2768 add_vars_loop:
DO i=n_vars+1,n_vars+2
2772 check_comp_cells_x2:
IF ( comp_cells_x .GT. 1 )
THEN 2774 IF ( (j .GT. 1) .AND. (j .LT. comp_cells_x) )
THEN 2776 x_stencil(1:3) = x_comp(j-1:j+1)
2777 qrec_stencil(1:3) = qrec(i,j-1:j+1,k)
2781 IF ( radial_source_flag .AND. ( source_cell(j,k).EQ.2 ) )
THEN 2783 IF ( sourcee(j,k) )
THEN 2786 sourcee_vect_y(j,k) , source_bdry )
2788 x_stencil(3) = x_stag(j+1)
2789 qrec_stencil(3) = source_bdry(i)
2791 ELSEIF ( sourcew(j,k) )
THEN 2794 sourcew_vect_y(j,k) , source_bdry )
2796 x_stencil(1) = x_stag(j)
2797 qrec_stencil(1) = source_bdry(i)
2803 CALL limit( qrec_stencil , x_stencil , limiter(i) , &
2811 END IF check_comp_cells_x2
2814 check_comp_cells_y2:
IF ( comp_cells_y .GT. 1 )
THEN 2816 IF ( ( k .GT. 1 ) .AND. ( k .LT. comp_cells_y ) )
THEN 2818 y_stencil(1:3) = y_comp(k-1:k+1)
2819 qrec_stencil = qrec(i,j,k-1:k+1)
2823 IF ( radial_source_flag .AND. ( source_cell(j,k).EQ.2 ) )
THEN 2825 IF ( sources(j,k) )
THEN 2828 sources_vect_y(j,k) , source_bdry )
2830 y_stencil(1) = y_stag(k)
2831 qrec_stencil(1) = source_bdry(i)
2833 ELSEIF ( sourcen(j,k) )
THEN 2836 sourcen_vect_y(j,k) , source_bdry )
2838 x_stencil(3) = y_stag(k+1)
2839 qrec_stencil(3) = source_bdry(i)
2845 CALL limit( qrec_stencil , y_stencil , limiter(i) , &
2853 ENDIF check_comp_cells_y2
2858 IF ( comp_cells_x .GT. 1 )
THEN 2860 IF ( ( j .GT. 1 ) .AND. ( j .LT. comp_cells_x ) )
THEN 2862 IF ( q_expl(1,j,k) .EQ. 0.d0 )
THEN 2864 IF ( ( .NOT. radial_source_flag ) .OR. &
2865 ( ( radial_source_flag ) .AND. &
2866 ( source_cell(j,k) .EQ. 0 ) ) )
THEN 2894 IF ( bcw(i)%flag .EQ. 0 )
THEN 2896 qrecw(i) = bcw(i)%value
2902 DO i=n_vars+1,n_vars+2
2904 CALL qp_to_qp2( qrecw(1:n_vars) , b_cent(j,k) , qp2recw )
2905 qrecw(i) = qp2recw(i-n_vars+1)
2907 CALL qp_to_qp2( qrece(1:n_vars) , b_cent(j,k) , qp2rece )
2908 qrece(i) = qp2rece(i-n_vars+1)
2912 ELSEIF ( j.EQ.comp_cells_x )
THEN 2917 IF ( bce(i)%flag .EQ. 0 )
THEN 2919 qrece(i) = bce(i)%value
2925 DO i=n_vars+1,n_vars+2
2927 CALL qp_to_qp2( qrecw(1:n_vars) , b_cent(j,k) , qp2recw )
2928 qrecw(i) = qp2recw(i-n_vars+1)
2930 CALL qp_to_qp2( qrece(1:n_vars) , b_cent(j,k) , qp2rece )
2931 qrece(i) = qp2rece(i-n_vars+1)
2940 IF ( radial_source_flag .AND. ( source_cell(j,k).EQ.2 ) )
THEN 2942 IF ( sourcee(j,k) )
THEN 2945 sourcee_vect_y(j,k) , source_bdry )
2947 qrece(1:n_vars+2) = source_bdry(1:n_vars+2)
2949 ELSEIF ( sourcew(j,k) )
THEN 2952 sourcew_vect_y(j,k) , source_bdry )
2954 qrecw(1:n_vars+2) = source_bdry(1:n_vars+2)
2962 CALL qp_to_qc( qrecw,b_interfacer(j,k),
q_interfacer(:,j,k) )
2963 CALL qp_to_qc( qrece,b_interfacel(j+1,k),
q_interfacel(:,j+1,k) )
2977 ELSEIF ( j.EQ.comp_cells_x )
THEN 2985 IF ( radial_source_flag .AND. ( source_cell(j,k) .EQ. 2 ) )
THEN 2987 IF ( sourcee(j,k) )
THEN 2992 ELSEIF ( sourcew(j,k) )
THEN 3014 IF ( comp_cells_y .EQ. 1 )
THEN 3025 IF ( ( k .GT. 1 ) .AND. ( k .LT. comp_cells_y ) )
THEN 3027 IF ( q_expl(1,j,k) .EQ. 0.d0 )
THEN 3029 IF ( ( .NOT. radial_source_flag ) .OR. &
3030 ( ( radial_source_flag ) .AND. &
3031 ( source_cell(j,k) .EQ. 0 ) ) )
THEN 3055 IF ( k .EQ. 1 )
THEN 3060 IF ( bcs(i)%flag .EQ. 0 )
THEN 3062 qrecs(i) = bcs(i)%value
3068 DO i=n_vars+1,n_vars+2
3070 CALL qp_to_qp2( qrecs(1:n_vars) , b_cent(j,k) , qp2recs )
3071 qrecs(i) = qp2recs(i-n_vars+1)
3073 CALL qp_to_qp2( qrecn(1:n_vars) , b_cent(j,k) , qp2recn )
3074 qrecn(i) = qp2recn(i-n_vars+1)
3078 ELSEIF ( k .EQ. comp_cells_y )
THEN 3083 IF ( bcn(i)%flag .EQ. 0 )
THEN 3085 qrecn(i) = bcn(i)%value
3091 DO i=n_vars+1,n_vars+2
3093 CALL qp_to_qp2( qrecs(1:n_vars) , b_cent(j,k) , qp2recs )
3094 qrecs(i) = qp2recs(i-n_vars+1)
3096 CALL qp_to_qp2( qrecn(1:n_vars) , b_cent(j,k) , qp2recn )
3097 qrecn(i) = qp2recn(i-n_vars+1)
3103 IF ( radial_source_flag .AND. ( source_cell(j,k) .EQ. 2 ) )
THEN 3105 IF ( sources(j,k) )
THEN 3108 sources_vect_y(j,k) , source_bdry )
3110 qrecs(1:n_vars+2) = source_bdry(1:n_vars+2)
3112 ELSEIF ( sourcen(j,k) )
THEN 3115 sourcen_vect_y(j,k) , source_bdry )
3117 qrecn(1:n_vars+2) = source_bdry(1:n_vars+2)
3125 CALL qp_to_qc( qrecs, b_interfacet(j,k),
q_interfacet(:,j,k))
3126 CALL qp_to_qc( qrecn, b_interfaceb(j,k+1),
q_interfaceb(:,j,k+1))
3131 IF ( k .EQ. 1 )
THEN 3137 ELSEIF ( k .EQ. comp_cells_y )
THEN 3145 IF ( radial_source_flag .AND. ( source_cell(j,k) .EQ. 2 ) )
THEN 3147 IF ( sources(j,k) )
THEN 3152 ELSEIF ( sourcen(j,k) )
THEN 3168 DEALLOCATE ( qrecw )
3169 DEALLOCATE ( qrece )
3170 DEALLOCATE ( qrecs )
3171 DEALLOCATE ( qrecn )
3172 DEALLOCATE ( source_bdry )
3173 DEALLOCATE ( qrec_prime_x )
3174 DEALLOCATE ( qrec_prime_y )
3198 REAL*8 :: abslambdaL_min(n_vars) , abslambdaL_max(n_vars)
3199 REAL*8 :: abslambdaR_min(n_vars) , abslambdaR_max(n_vars)
3200 REAL*8 :: abslambdaB_min(n_vars) , abslambdaB_max(n_vars)
3201 REAL*8 :: abslambdaT_min(n_vars) , abslambdaT_max(n_vars)
3202 REAL*8 :: min_r(n_vars) , max_r(n_vars)
3206 IF ( comp_cells_x .GT. 1 )
THEN 3219 min_r = min(abslambdal_min , abslambdar_min , 0.0d0)
3220 max_r = max(abslambdal_max , abslambdar_max , 0.0d0)
3225 END DO x_interfaces_loop
3229 IF ( comp_cells_y .GT. 1 )
THEN 3242 min_r = min(abslambdab_min , abslambdat_min , 0.0d0)
3243 max_r = max(abslambdab_max , abslambdat_max , 0.0d0)
3248 END DO y_interfaces_loop
real *8, dimension(:,:), allocatable b_prime_x
Topography slope (x direction) at the centers of the control volumes.
real *8, dimension(:,:,:), allocatable q_cellne
Reconstructed value at the NE corner of cell.
real *8 max_dt
Largest time step allowed.
subroutine eval_speeds
Characteristic speeds.
real *8, dimension(:,:), allocatable b_interfacel
Reconstructed value at the left of the x-interface.
real *8, dimension(:), allocatable a_dirk
Explicit coeff. for the non-hyp. part for a single step of the R-K scheme.
real *8 dy
Control volumes size.
real *8, dimension(:,:,:), allocatable qp_cellnw
Reconstructed physical value at the NW corner of cell.
real *8, dimension(:,:), allocatable nhj
Local Intermediate non-hyperbolic terms of the Runge-Kutta scheme.
subroutine eval_explicit_terms(qc_expl, qp_expl, expl_terms)
Evaluate the explicit terms.
integer n_rk
Runge-Kutta order.
real *8, parameter tol_rel
real *8, dimension(:,:,:,:), allocatable q_rk
Intermediate solutions of the Runge-Kutta scheme.
integer, dimension(:), allocatable j_stag_y
real *8, dimension(:), allocatable x_comp
Location of the centers (x) of the control volume of the domain.
real *8, dimension(:,:,:), allocatable q0
Conservative variables.
real *8, dimension(:,:), allocatable b_cent
Topography at the centers of the control volumes.
subroutine reconstruction(q_expl, qp_expl)
Linear reconstruction.
integer comp_cells_x
Number of control volumes x in the comp. domain.
subroutine eval_flux_gforce
Numerical fluxes GFORCE.
subroutine eval_local_speeds_x(qpj, vel_min, vel_max)
Local Characteristic speeds x direction.
real *8, dimension(:,:), allocatable sourcen_vect_y
real *8, dimension(:,:), allocatable grav_surf
gravity vector wrt surface coordinates for each cell
real *8, dimension(:,:,:,:), allocatable divflux
Intermediate hyperbolic terms of the Runge-Kutta scheme.
real *8, dimension(:,:), allocatable sourcee_vect_x
real *8, dimension(:), allocatable y_comp
Location of the centers (y) of the control volume of the domain.
logical, dimension(:,:), allocatable mask11
real *8, dimension(:,:), allocatable source_xy
Array defining fraction of cells affected by source term.
subroutine mixt_var(qpj, r_Ri, r_rho_m, r_rho_c, r_red_grav)
Physical variables.
integer, dimension(:), allocatable k_cent
subroutine average_kt(a1, a2, w1, w2, w_avg)
averaged KT flux
real *8 dx
Control volumes size.
real *8, dimension(:,:,:,:), allocatable si_nh
Intermediate semi-implicit non-hyperbolic terms of the Runge-Kutta scheme.
real *8, dimension(:,:,:), allocatable q_cellse
Reconstructed value at the SE corner of cell.
real *8, dimension(:,:,:), allocatable qp_interfaceb
Reconstructed physical value at the bottom of the y-interface.
integer comp_cells_y
Number of control volumes y in the comp. domain.
real *8, dimension(:,:,:), allocatable a_interface_xneg
Local speeds at the left of the x-interface.
subroutine deallocate_solver_variables
Memory deallocation.
subroutine qp_to_qp2(qpj, Bj, qp2j)
Additional Physical variables.
logical, dimension(:,:), allocatable sourcee
real *8, dimension(:,:,:,:), allocatable expl_terms
Intermediate explicit terms of the Runge-Kutta scheme.
logical, dimension(:,:), allocatable sourcew
type(bc), dimension(:), allocatable bcw
bcW&flag defines the west boundary condition:
real *8, dimension(:,:,:,:), allocatable nh
Intermediate non-hyperbolic terms of the Runge-Kutta scheme.
real *8, dimension(:,:), allocatable sourcew_vect_y
real *8, dimension(:,:), allocatable b_interfacer
Reconstructed value at the right of the x-interface.
real *8 function minmod(a, b)
subroutine eval_nh_semi_impl_terms(grav3_surf, qcj, nh_semi_impl_term)
Non-Hyperbolic semi-implicit terms.
integer, dimension(:), allocatable k_stag_x
real *8, dimension(:,:,:), allocatable qp_interfacet
Reconstructed physical value at the top of the y-interface.
real *8, dimension(:,:), allocatable sourcew_vect_x
real *8, dimension(:,:,:), allocatable q_cellsw
Reconstructed value at the SW corner of cell.
real *8, dimension(:), allocatable a_tilde
Explicit coeff. for the hyperbolic part for a single step of the R-K scheme.
integer n_vars
Number of conservative variables.
real *8, dimension(:,:), allocatable b_interfaceb
Reconstructed value at the bottom of the y-interface.
real *8, dimension(:,:,:), allocatable a_interface_yneg
Local speeds at the bottom of the y-interface.
subroutine eval_flux_lxf
Numerical fluxes Lax-Friedrichs.
real *8, dimension(:,:,:), allocatable qp_cellne
Reconstructed physical value at the NE corner of cell.
integer comp_interfaces_y
Number of interfaces (comp_cells_y+1)
real *8 cfl
Courant-Friedrichs-Lewy parameter.
subroutine eval_expl_terms(Bprimej_x, Bprimej_y, source_xy, qpj, qcj, expl_term)
Explicit Forces term.
integer, parameter max_nl_iter
real *8, dimension(:,:,:), allocatable residual_term
Sum of all the terms of the equations except the transient term.
subroutine eval_fluxes(qcj, qpj, dir, flux)
Hyperbolic Fluxes.
subroutine update_erosion_deposition_cell(dt)
Evaluate the eroion/deposition terms.
logical normalize_q
Flag for the normalization of the array q in the implicit solution scheme.
logical, dimension(:,:), allocatable mask21
real *8, dimension(:,:,:), allocatable h_interface_x
Semidiscrete numerical interface fluxes.
real *8, dimension(:,:), allocatable a_dirk_ij
Butcher Tableau for the implicit part of the Runge-Kutta scheme.
logical, dimension(:,:), allocatable solve_mask_y
real *8, dimension(:,:,:), allocatable a_interface_ypos
Local speeds at the top of the y-interface.
logical, dimension(:), allocatable implicit_flag
flag used for size of implicit non linear-system
real *8, dimension(:,:,:), allocatable h_interface_y
Semidiscrete numerical interface fluxes.
subroutine limit(v, z, limiter, slope_lim)
Slope limiter.
real *8, dimension(:,:,:), allocatable qp_interfacer
Reconstructed physical value at the right of the x-interface.
real *8, dimension(:), allocatable erosion_coeff
erosion model coefficient (units: m-1 )
logical settling_flag
Flag to determine if sedimentation is active.
real *8, dimension(:,:,:), allocatable q_interfacel
Reconstructed value at the left of the x-interface.
subroutine solve_rk_step(qj, qj_old, a_tilde, a_dirk, a_diag)
Runge-Kutta single step integration.
subroutine eval_source_bdry(time, vect_x, vect_y, source_bdry)
Internal boundary source fluxes.
real *8, dimension(:,:), allocatable sourcee_vect_y
real *8, dimension(:,:), allocatable sources_vect_y
real *8, dimension(:), allocatable omega_tilde
Coefficients for the explicit part of the Runge-Kutta scheme.
subroutine eval_local_speeds_y(qpj, vel_min, vel_max)
Local Characteristic speeds y direction.
character(len=20) solver_scheme
Finite volume method: .
real *8, dimension(:,:), allocatable sourcen_vect_x
integer, dimension(:,:), allocatable source_cell
subroutine eval_erosion_dep_term(qpj, dt, erosion_term, deposition_term)
Erosion/Deposition term.
real *8, dimension(:), allocatable omega
Coefficients for the implicit part of the Runge-Kutta scheme.
real *8, dimension(:,:), allocatable expl_terms_j
Local Intermediate explicit terms of the Runge-Kutta scheme.
real *8, dimension(:,:,:), allocatable q_cellnw
Reconstructed value at the NW corner of cell.
subroutine check_solve
Masking of cells to solve.
real *8, dimension(:,:,:), allocatable qp_cellsw
Reconstructed physical value at the SW corner of cell.
real *8, dimension(:,:,:), allocatable qp_cellse
Reconstructed physical value at the SE corner of cell.
real *8, dimension(:,:,:), allocatable a_interface_xpos
Local speeds at the right of the x-interface.
integer, dimension(:), allocatable k_stag_y
logical, dimension(:,:), allocatable mask22
subroutine lnsrch(qj_rel_NR_old, qj_org, qj_old, scal_f_old, grad_f, desc_dir, coeff_f, qj_rel, scal_f, right_term, stpmax, check)
Search the descent stepsize.
subroutine eval_hyperbolic_terms(q_expl, qp_expl, divFlux)
Semidiscrete finite volume central scheme.
real *8, dimension(:,:), allocatable b_prime_y
Topography slope (y direction) at the centers of the control volumes.
subroutine timestep
Time-step computation.
real *8, dimension(:,:), allocatable si_nhj
Local Intermediate semi-impl non-hyperbolic terms of the Runge-Kutta scheme.
real *8, dimension(:,:,:), allocatable a_interface_x_max
Max local speeds at the x-interface.
integer solve_interfaces_x
subroutine qc_to_qp(qc, qp)
Conservative to physical variables.
real *8, dimension(:,:,:), allocatable q_interfaceb
Reconstructed value at the bottom of the y-interface.
integer, dimension(:), allocatable j_cent
real *8, dimension(:), allocatable x_stag
Location of the boundaries (x) of the control volumes of the domain.
real *8, dimension(:,:), allocatable sources_vect_x
real *8, dimension(:,:), allocatable a_tilde_ij
Butcher Tableau for the explicit part of the Runge-Kutta scheme.
integer solve_interfaces_y
real *8 a_diag
Implicit coeff. for the non-hyp. part for a single step of the R-K scheme.
logical opt_search_nl
Flag for the search of optimal step size in the implicit solution scheme.
real *8, dimension(:,:,:), allocatable q_fv
Solution of the finite-volume semidiscrete cheme.
logical normalize_f
Flag for the normalization of the array f in the implicit solution scheme.
integer, dimension(10) limiter
Limiter for the slope in the linear reconstruction: .
real *8, dimension(:,:,:,:), allocatable qp_rk
Intermediate physical solutions of the Runge-Kutta scheme.
type(bc), dimension(:), allocatable bcn
bcN&flag defines the north boundary condition:
real *8, dimension(:,:), allocatable b_interfacet
Reconstructed value at the top of the y-interface.
logical, dimension(:,:), allocatable sourcen
real *8 dx2
Half x Control volumes size.
integer n_eqns
Number of equations.
subroutine eval_jacobian(qj_rel, qj_org, coeff_f, left_matrix)
Evaluate the jacobian.
subroutine qp_to_qc(qp, B, qc)
Physical to conservative variables.
real *8, dimension(:,:,:), allocatable deposit
deposit for the different classes
real *8, parameter tol_abs
subroutine eval_nonhyperbolic_terms(c_qj, c_nh_term_impl, r_qj, r_nh_term_impl)
Non-Hyperbolic terms.
subroutine eval_flux_up
Upwind numerical fluxes.
real *8 reconstr_coeff
Slope coefficient in the linear reconstruction.
subroutine imex_rk_solver
Runge-Kutta integration.
type(bc), dimension(:), allocatable bcs
bcS&flag defines the south boundary condition:
logical, dimension(:,:), allocatable solve_mask
integer comp_interfaces_x
Number of interfaces (comp_cells_x+1)
real *8, dimension(:), allocatable y_stag
Location of the boundaries (x) of the control volumes of the domain.
type(bc), dimension(:), allocatable bce
bcE&flag defines the east boundary condition:
subroutine eval_f(qj, qj_old, a_tilde, a_dirk, a_diag, coeff_f, f_nl, scal_f)
Evaluate the nonlinear system.
logical, dimension(:,:), allocatable solve_mask_x
real *8, dimension(:,:), allocatable q1max
Maximum over time of thickness.
real *8, dimension(:,:,:), allocatable q_interfacer
Reconstructed value at the right of the x-interface.
logical radial_source_flag
integer, dimension(:), allocatable j_stag_x
real *8, dimension(:,:), allocatable divfluxj
Local Intermediate hyperbolic terms of the Runge-Kutta scheme.
subroutine eval_flux_kt
Semidiscrete numerical fluxes.
integer i_rk
loop counter for the RK iteration
subroutine allocate_solver_variables
Memory allocation.
real *8 dy2
Half y Control volumes size.
logical, dimension(:,:), allocatable mask12
real *8, dimension(:,:,:), allocatable a_interface_y_max
Max local speeds at the y-interface.
real *8, dimension(:,:,:), allocatable qp_interfacel
Reconstructed physical value at the left of the x-interface.
real *8, dimension(:,:,:), allocatable q_interfacet
Reconstructed value at the top of the y-interface.
integer n_solid
Number of solid classes.
real *8, dimension(:), allocatable rho_s
Density of sediments ( units: kg m-3 )
real *8, dimension(:,:,:), allocatable qp
Physical variables ( )
subroutine eval_topo_term(qpj, deposition_avg_term, erosion_avg_term, eqns_term, deposit_term)
Topography modification related term.
integer n_nh
Number of non-hyperbolic terms.
logical, dimension(:,:), allocatable sources
real *8, dimension(:,:,:), allocatable q
Conservative variables.