source: codes/icosagcm/devel/src/dynamics/caldyn_hevi.f90 @ 853

Last change on this file since 853 was 853, checked in by jisesh, 5 years ago

devel: separate module for compute_caldyn_solver and removed Rd duplication in it

File size: 6.9 KB
Line 
1MODULE caldyn_hevi_mod
2  USE icosa
3  USE transfert_mod
4  USE caldyn_vars_mod
5  USE caldyn_kernels_hevi_mod
6  USE caldyn_kernels_base_mod
7  USE compute_theta_mod, ONLY : compute_theta
8  USE compute_caldyn_kv_mod, ONLY : compute_caldyn_kv
9  USE compute_caldyn_Coriolis_mod, ONLY : compute_caldyn_Coriolis
10  USE compute_caldyn_slow_hydro_mod, ONLY : compute_caldyn_slow_hydro
11  USE compute_caldyn_slow_NH_mod, ONLY : compute_caldyn_slow_NH
12  USE compute_caldyn_solver_mod, ONLY : compute_caldyn_solver
13  IMPLICIT NONE
14  PRIVATE
15  PUBLIC caldyn_hevi
16
17CONTAINS
18 
19  SUBROUTINE caldyn_hevi(write_out,tau, f_phis, f_ps, f_mass, f_theta_rhodz, f_u, f_q, &
20       f_W, f_geopot, f_hflux, f_wflux, f_dps, f_dmass, f_dtheta_rhodz, &
21       f_du_slow, f_du_fast, f_dPhi_slow, f_dPhi_fast, f_dW_slow, f_dW_fast) 
22    USE icosa
23    USE observable_mod
24    USE disvert_mod, ONLY : caldyn_eta, eta_mass
25    USE vorticity_mod
26    USE kinetic_mod
27    USE theta2theta_rhodz_mod
28    USE wind_mod
29    USE mpipara
30    USE trace
31    USE omp_para
32    USE output_field_mod
33    USE checksum_mod
34    USE compute_mod, ONLY : compute_pvort_only
35    IMPLICIT NONE
36    LOGICAL,INTENT(IN)    :: write_out
37    REAL(rstd), INTENT(IN) :: tau
38    TYPE(t_field),POINTER :: f_phis(:)
39    TYPE(t_field),POINTER :: f_ps(:)
40    TYPE(t_field),POINTER :: f_mass(:)
41    TYPE(t_field),POINTER :: f_theta_rhodz(:)
42    TYPE(t_field),POINTER :: f_u(:)
43    TYPE(t_field),POINTER :: f_q(:)
44    TYPE(t_field),POINTER :: f_W(:)
45    TYPE(t_field),POINTER :: f_geopot(:)
46    TYPE(t_field),POINTER :: f_hflux(:), f_wflux(:)
47    TYPE(t_field) :: f_dps(:)
48    TYPE(t_field) :: f_dmass(:)
49    TYPE(t_field) :: f_dtheta_rhodz(:)
50    TYPE(t_field) :: f_du_slow(:)
51    TYPE(t_field) :: f_du_fast(:)
52    TYPE(t_field) :: f_dW_slow(:)
53    TYPE(t_field) :: f_dW_fast(:)
54    TYPE(t_field) :: f_dPhi_slow(:)
55    TYPE(t_field) :: f_dPhi_fast(:)
56   
57    REAL(rstd),POINTER :: ps(:), dps(:), phis(:)
58    REAL(rstd),POINTER :: mass(:,:), theta_rhodz(:,:,:), dtheta_rhodz(:,:,:)
59    REAL(rstd),POINTER :: du(:,:), dW(:,:), dPhi(:,:), hflux(:,:), wflux(:,:)
60    REAL(rstd),POINTER :: u(:,:), w(:,:), qu(:,:), qv(:,:), Kv(:,:), hv(:,:)
61
62! temporary shared variable
63    REAL(rstd),POINTER  :: theta(:,:,:) 
64    REAL(rstd),POINTER  :: pk(:,:)
65    REAL(rstd),POINTER  :: geopot(:,:)
66    REAL(rstd),POINTER  :: convm(:,:) 
67    REAL(rstd),POINTER  :: wwuu(:,:)
68    REAL(rstd),POINTER  :: F_el(:,:), gradPhi2(:,:), w_il(:,:) , W_etadot(:,:), pres(:,:), m_il(:,:)
69    INTEGER :: ind
70    LOGICAL,SAVE :: first=.TRUE.
71!$OMP THREADPRIVATE(first)
72   
73    IF (first) THEN
74      first=.FALSE.
75      IF(caldyn_eta==eta_mass) THEN
76         CALL init_message(f_ps,req_i1,req_ps)
77      ELSE
78         CALL init_message(f_mass,req_i1,req_mass)
79      END IF
80      CALL init_message(f_theta_rhodz,req_i1,req_theta_rhodz)
81      CALL init_message(f_u,req_e1_vect,req_u)
82      CALL init_message(f_qu,req_e1_scal,req_qu)
83      IF(caldyn_kinetic==kinetic_consistent) CALL init_message(f_Kv,req_z1_scal,req_Kv)
84      IF(.NOT.hydrostatic) THEN
85         CALL init_message(f_geopot,req_i1,req_geopot)
86         CALL init_message(f_w,req_i1,req_w)
87      END IF
88    ENDIF
89   
90    CALL trace_start("caldyn")
91   
92    IF(caldyn_eta==eta_mass) THEN
93       CALL send_message(f_ps,req_ps) ! COM00
94       CALL wait_message(req_ps) ! COM00
95    ELSE
96       CALL send_message(f_mass,req_mass) ! COM00
97       CALL wait_message(req_mass) ! COM00
98    END IF
99    CALL send_message(f_theta_rhodz,req_theta_rhodz) ! COM01
100    CALL wait_message(req_theta_rhodz) ! COM01 Moved from caldyn_pvort
101
102    IF(.NOT.hydrostatic) THEN
103       CALL send_message(f_geopot,req_geopot) ! COM03
104       CALL wait_message(req_geopot) ! COM03
105       CALL send_message(f_w,req_w) ! COM04
106       CALL wait_message(req_w) ! COM04
107    END IF
108   
109    DO ind=1,ndomain
110       IF (.NOT. assigned_domain(ind)) CYCLE
111       CALL swap_dimensions(ind)
112       CALL swap_geometry(ind)
113       ps=f_ps(ind)
114       theta_rhodz=f_theta_rhodz(ind)
115       mass=f_mass(ind)
116       theta = f_theta(ind)
117       CALL compute_theta(ps,theta_rhodz, mass,theta)
118       pk = f_pk(ind)
119       geopot = f_geopot(ind)
120       du=f_du_fast(ind)
121       IF(hydrostatic) THEN
122          du(:,:)=0.
123          CALL compute_geopot(mass,theta, ps,pk,geopot)
124       ELSE
125          phis = f_phis(ind)
126          W = f_W(ind)
127          dW = f_dW_fast(ind)
128          dPhi = f_dPhi_fast(ind)
129          ! reuse buffers
130          m_il = f_wil(ind)
131          pres = f_gradPhi2(ind)
132          CALL compute_caldyn_solver(tau,phis, mass,theta,pk,geopot,W, m_il,pres, dPhi,dW,du) ! computes d(Phi,W,du)_fast and updates Phi,W
133       END IF
134       u=f_u(ind)
135       CALL compute_caldyn_fast(tau,u,mass,theta,pk,geopot,du) ! computes du_fast and updates u
136    ENDDO
137   
138    CALL send_message(f_u,req_u) ! COM02
139    CALL wait_message(req_u)   ! COM02
140   
141    DO ind=1,ndomain
142       IF (.NOT. assigned_domain(ind)) CYCLE
143       CALL swap_dimensions(ind)
144       CALL swap_geometry(ind)
145       u=f_u(ind)
146       mass=f_mass(ind)
147       qu=f_qu(ind)
148       qv=f_qv(ind)
149       hv=f_hv(ind)
150       CALL compute_pvort_only(u,mass,qu,qv,hv)
151       IF(caldyn_kinetic==kinetic_consistent) THEN
152          Kv=f_Kv(ind)
153          CALL compute_caldyn_Kv(u,Kv)
154       END IF
155    ENDDO
156   
157    CALL send_message(f_qu,req_qu) ! COM03
158    CALL wait_message(req_qu) ! COM03
159
160    IF(caldyn_kinetic==kinetic_consistent) THEN
161       CALL transfert_request(f_hv,req_z1_scal)
162       CALL send_message(f_Kv,req_Kv)
163       CALL wait_message(req_Kv)
164    END IF
165
166    DO ind=1,ndomain
167       IF (.NOT. assigned_domain(ind)) CYCLE
168       CALL swap_dimensions(ind)
169       CALL swap_geometry(ind)
170       u=f_u(ind)
171       mass=f_mass(ind)
172       theta = f_theta(ind)
173       qu=f_qu(ind)
174       hflux=f_hflux(ind)
175       convm = f_dmass(ind)
176       dtheta_rhodz=f_dtheta_rhodz(ind)
177       du=f_du_slow(ind)
178
179       IF(hydrostatic) THEN
180          hv=f_hv(ind)
181          Kv=f_Kv(ind)
182          CALL compute_caldyn_slow_hydro(u,mass,hv, hflux,Kv,du, .TRUE.)
183       ELSE
184          W = f_W(ind)
185          dW = f_dW_slow(ind)
186          geopot = f_geopot(ind)
187          dPhi = f_dPhi_slow(ind)
188          F_el = f_Fel(ind)
189          gradPhi2 = f_gradPhi2(ind)
190          w_il = f_wil(ind)
191          CALL compute_caldyn_slow_NH(u,mass,geopot,W, F_el,gradPhi2,w_il, hflux,du,dPhi,dW)
192       END IF
193       CALL compute_caldyn_Coriolis(hflux,theta,qu, convm,dtheta_rhodz,du)
194       IF(caldyn_eta==eta_mass) THEN
195          wflux=f_wflux(ind)
196          wwuu=f_wwuu(ind)
197          dps=f_dps(ind)
198          CALL compute_caldyn_vert(u,theta,mass,convm, wflux,wwuu, dps, dtheta_rhodz, du)
199          IF(.NOT.hydrostatic) THEN
200             W_etadot=f_Wetadot(ind)
201             CALL compute_caldyn_vert_NH(mass,geopot,W,wflux, W_etadot, du,dPhi,dW)
202          END IF
203       END IF
204    ENDDO
205   
206!$OMP BARRIER
207    !    CALL check_mass_conservation(f_ps,f_dps)
208    CALL trace_end("caldyn_hevi")
209!!$OMP BARRIER
210   
211  END SUBROUTINE caldyn_hevi
212
213END MODULE caldyn_hevi_mod
Note: See TracBrowser for help on using the repository browser.