source: codes/icosagcm/trunk/src/hevi_scheme.f90 @ 378

Last change on this file since 378 was 371, checked in by dubos, 8 years ago

Bugfix : NH slow tendencies for W,Phi were ignored

File size: 4.7 KB
Line 
1MODULE hevi_scheme_mod
2  USE prec
3  USE domain_mod
4  USE field_mod
5  USE euler_scheme_mod
6  USE caldyn_kernels_base_mod, ONLY : DEC
7  IMPLICIT NONE
8  PRIVATE
9
10  REAL(rstd), SAVE :: wj(3), bjl(3,3), cjl(3,3), taujj(3)
11  REAL(rstd), PARAMETER, DIMENSION(3) :: zero = (/0.,0.,0./)
12
13  PUBLIC :: set_coefs_ark23, set_coefs_ark33, hevi_scheme
14
15CONTAINS
16
17  SUBROUTINE set_coefs_ark23(dt)
18    ! ARK2 scheme by Giraldo, Kelly, Constantinescu 2013
19    ! See Weller et al., 2013 - ARK2 scheme Fig. 2
20    REAL(rstd) :: dt
21    REAL(rstd), PARAMETER :: delta=.5/SQRT(2.), gamma=1.-2.*delta
22!    REAL(rstd), PARAMETER :: alpha=(3.+SQRT(8.))/6. ! original value in GKC2013
23    REAL(rstd), PARAMETER :: alpha=0.7
24    REAL(rstd), PARAMETER, DIMENSION(3) :: wj = (/delta,delta,gamma/)
25    CALL set_coefs_hevi(dt, &
26         (/ zero, (/2.*gamma,0.,0./), (/1-alpha,alpha,0./), wj /), &
27         (/ zero, (/gamma,gamma,0./), wj, wj /) )
28  END SUBROUTINE set_coefs_ark23
29
30  SUBROUTINE set_coefs_ark33(dt)
31    ! Fully-explicit RK3 scheme disguised as ARK
32    REAL(rstd) :: dt
33    CALL set_coefs_rk(dt, (/ zero, (/.5,0.,0./), (/-1.,2.,0./), (/1./6.,2./3.,1./6./) /) )
34  END SUBROUTINE set_coefs_ark33
35   
36  SUBROUTINE set_coefs_rk(dt, ajl)
37    REAL(rstd) :: dt, ajl(3,4)
38    CALL set_coefs_hevi(dt,ajl,ajl)
39  END SUBROUTINE set_coefs_rk
40
41  SUBROUTINE set_coefs_hevi(dt, ajl_slow, ajl_fast)
42    REAL(rstd) :: dt, ajl_slow(3,4), ajl_fast(3,4) ! fast/slow Butcher tableaus
43    INTEGER :: j
44    DO j=1,3
45       bjl(:,j) = dt*(ajl_slow(:,j+1)-ajl_slow(:,j))
46       cjl(:,j) = dt*(ajl_fast(:,j+1)-ajl_fast(:,j))
47       taujj(j) = dt*ajl_fast(j,j)
48    END DO
49    wj=dt*ajl_slow(:,4)
50  END SUBROUTINE set_coefs_hevi
51
52  SUBROUTINE HEVI_scheme(it, fluxt_zero)
53    USE time_mod
54    USE disvert_mod
55    USE caldyn_hevi_mod
56    LOGICAL :: fluxt_zero(ndomain) ! set to .TRUE. to start accumulating fluxes in time
57    INTEGER :: it,j,l, ind
58    REAL(rstd),POINTER :: hflux(:,:),wflux(:,:),hfluxt(:,:),wfluxt(:,:)
59
60    IF(DEC) CALL legacy_to_DEC(f_ps, f_u)
61    DO j=1,nb_stage
62       CALL caldyn_hevi((j==1) .AND. (MOD(it,itau_out)==0), taujj(j), &
63            f_phis, f_ps,f_mass,f_theta_rhodz,f_u,f_q, &
64            f_W, f_geopot, f_hflux, f_wflux, &
65            f_dps_slow(:,j), f_dmass_slow(:,j), f_dtheta_rhodz_slow(:,j), &
66            f_du_slow(:,j), f_du_fast(:,j), &
67            f_dPhi_slow(:,j), f_dPhi_fast(:,j), &
68            f_dW_slow(:,j), f_dW_fast(:,j) )
69       ! accumulate mass fluxes for transport scheme
70       DO ind=1,ndomain
71          IF (.NOT. assigned_domain(ind)) CYCLE
72          CALL swap_dimensions(ind)
73          hflux=f_hflux(ind);     hfluxt=f_hfluxt(ind)
74          wflux=f_wflux(ind);     wfluxt=f_wfluxt(ind)
75          CALL accumulate_fluxes(hflux,wflux, hfluxt,wfluxt, wj(j), fluxt_zero(ind))
76       END DO
77       ! update model state
78       DO l=1,j
79          IF(caldyn_eta==eta_mass) THEN
80             CALL update_2D(bjl(l,j), f_ps, f_dps_slow(:,l))
81          ELSE
82             CALL update(bjl(l,j), f_mass, f_dmass_slow(:,l))
83          END IF
84          CALL update(bjl(l,j), f_theta_rhodz, f_dtheta_rhodz_slow(:,l))
85          CALL update(bjl(l,j), f_u, f_du_slow(:,l))
86          CALL update(cjl(l,j), f_u, f_du_fast(:,l))
87          IF(.NOT. hydrostatic) THEN
88             CALL update(bjl(l,j), f_W, f_dW_slow(:,l))
89             CALL update(cjl(l,j), f_W, f_dW_fast(:,l))
90             CALL update(bjl(l,j), f_geopot, f_dPhi_slow(:,l))
91             CALL update(cjl(l,j), f_geopot, f_dPhi_fast(:,l))
92          END IF
93       END DO
94    END DO
95    IF(DEC) CALL DEC_to_legacy(f_ps, f_u)
96  END SUBROUTINE HEVI_scheme
97 
98  SUBROUTINE update(w, f_y, f_dy)
99    USE dimensions
100    REAL(rstd) :: w
101    TYPE(t_field) :: f_y(:), f_dy(:)
102    REAL(rstd), POINTER :: y(:,:), dy(:,:)
103    INTEGER :: ind
104    IF(w /= 0.) THEN
105       DO ind=1,ndomain
106          IF (.NOT. assigned_domain(ind)) CYCLE
107          CALL swap_dimensions(ind)
108          dy=f_dy(ind); y=f_y(ind)
109          CALL compute_update(w,y,dy)
110       ENDDO
111    END IF
112  END SUBROUTINE update
113   
114  SUBROUTINE compute_update(w, y, dy)
115    USE omp_para
116    USE disvert_mod
117    REAL(rstd) :: w
118    REAL(rstd) :: y(:,:), dy(:,:)
119    INTENT(INOUT) :: y
120    INTENT(IN) :: dy
121    INTEGER :: l
122    DO l=ll_begin,ll_end
123       y(:,l)=y(:,l)+w*dy(:,l)
124    ENDDO
125  END SUBROUTINE compute_update
126 
127  SUBROUTINE update_2D(w, f_y, f_dy)
128    REAL(rstd) :: w
129    TYPE(t_field) :: f_y(:), f_dy(:)
130    REAL(rstd), POINTER :: y(:), dy(:)
131    INTEGER :: ind
132    DO ind=1,ndomain
133       IF (.NOT. assigned_domain(ind)) CYCLE
134       dy=f_dy(ind); y=f_y(ind)
135       CALL compute_update_2D(w,y,dy)
136    ENDDO
137  END SUBROUTINE update_2D
138   
139  SUBROUTINE compute_update_2D(w, y, dy)
140    REAL(rstd) :: w, y(:), dy(:)
141    INTENT(INOUT) :: y
142    INTENT(IN) :: dy
143    y(:)=y(:)+w*dy(:)
144  END SUBROUTINE compute_update_2D
145 
146END MODULE hevi_scheme_mod
Note: See TracBrowser for help on using the repository browser.