source: codes/icosagcm/devel/src/diagnostics/diagflux.F90 @ 612

Last change on this file since 612 was 612, checked in by dubos, 6 years ago

devel : rename directory kernels as kernels_hex

File size: 7.8 KB
Line 
1MODULE diagflux_mod
2  USE icosa
3  USE omp_para
4  IMPLICIT NONE
5  SAVE
6  PRIVATE
7
8  TYPE(t_field), POINTER, PUBLIC :: &
9       f_masst(:), f_qmasst(:), & ! time-averaged mass, tracer mass,
10       f_massfluxt(:), f_qfluxt(:), & ! time-integrated mass flux and tracer flux
11       f_qfluxt_lon(:), f_qfluxt_lat(:), & ! scalar flux reconstructed at cell centers
12       f_ulont(:), f_thetat(:), f_epot(:), f_ekin(:), f_enthalpy(:), & ! time-averaged potential E, kinetic E and enthalpy
13       f_ulonfluxt(:), f_thetafluxt(:), f_epotfluxt(:), f_ekinfluxt(:), f_enthalpyfluxt(:) ! time averaged 'fluxes' of epot, ekin and enthalpy
14  LOGICAL :: diagflux_on
15  !$OMP THREADPRIVATE(diagflux_on)
16
17  PUBLIC :: diagflux_on, init_diagflux, zero_qfluxt, qflux_centered_lonlat, flux_centered_lonlat, diagflux_energy
18
19CONTAINS
20
21  SUBROUTINE init_diagflux
22    USE getin_mod
23    INTEGER :: ll
24    diagflux_on = .FALSE.
25    CALL getin("diagflux", diagflux_on)
26    ll = MERGE(llm,1,diagflux_on)
27    CALL allocate_field(f_masst,         field_t,type_real,ll,       name="masst")
28    CALL allocate_field(f_ulont,         field_t,type_real,ll,       name="ulont")
29    CALL allocate_field(f_thetat,        field_t,type_real,ll,       name="thetat")
30    CALL allocate_field(f_epot,          field_t,type_real,ll,       name="epot")
31    CALL allocate_field(f_ekin,          field_t,type_real,ll,       name="ekin")
32    CALL allocate_field(f_enthalpy,      field_t,type_real,ll,       name="enthalpy")
33    CALL allocate_field(f_qmasst,        field_t,type_real,ll,nqtot, name="qmasst")
34    CALL allocate_field(f_massfluxt,     field_u,type_real,ll,       name="massfluxt")
35    CALL allocate_field(f_ulonfluxt,     field_u,type_real,ll,       name="ulonfluxt")
36    CALL allocate_field(f_thetafluxt,    field_u,type_real,ll,       name="thetafluxt")
37    CALL allocate_field(f_epotfluxt,     field_u,type_real,ll,       name="epotfluxt")
38    CALL allocate_field(f_ekinfluxt,     field_u,type_real,ll,       name="ekinfluxt")
39    CALL allocate_field(f_enthalpyfluxt, field_u,type_real,ll,       name="enthalpyfluxt")
40    CALL allocate_field(f_qfluxt,        field_u,type_real,ll,nqtot, name="qfluxt")
41    CALL allocate_field(f_qfluxt_lon,    field_t,type_real,ll,nqtot, name="qfluxt_lon")
42    CALL allocate_field(f_qfluxt_lat,    field_t,type_real,ll,nqtot, name="qfluxt_lat")
43    IF(diagflux_on) CALL zero_qfluxt
44  END SUBROUTINE init_diagflux
45
46#define ZERO2(field) buf2=field(ind) ; buf2(:,ll_begin:ll_end)=0.
47#define ZERO3(field) buf3=field(ind) ; buf3(:,ll_begin:ll_end,:)=0.
48
49  SUBROUTINE zero_qfluxt
50    INTEGER :: ind
51    REAL(rstd), POINTER :: buf2(:,:),buf3(:,:,:)
52    DO ind=1,ndomain
53       IF (.NOT. assigned_domain(ind)) CYCLE
54       CALL swap_dimensions(ind)
55       ZERO2(f_masst)
56       ZERO2(f_ulont)
57       ZERO2(f_thetat)
58       ZERO2(f_epot)
59       ZERO2(f_ekin)
60       ZERO2(f_enthalpy)
61       ZERO3(f_qmasst)
62       ZERO2(f_massfluxt)
63       ZERO2(f_ulonfluxt)
64       ZERO2(f_thetafluxt)
65       ZERO2(f_epotfluxt)
66       ZERO2(f_ekinfluxt)
67       ZERO2(f_enthalpyfluxt)
68       ZERO3(f_qfluxt)
69    END DO
70  END SUBROUTINE zero_qfluxt
71
72!------------------------------------ Reconstruct fluxes at cell centers ---------------------------------------
73
74  SUBROUTINE qflux_centered_lonlat(scale, f_flux, f_flux_lon, f_flux_lat)
75    REAL(rstd), INTENT(IN) :: scale
76    TYPE(t_field),POINTER :: f_flux(:), f_flux_lon(:), f_flux_lat(:)
77    REAL(rstd), POINTER :: flux(:,:,:), flux_lon(:,:,:), flux_lat(:,:,:)
78    INTEGER :: ind, itrac
79    DO ind=1,ndomain
80       IF (.NOT. assigned_domain(ind)) CYCLE
81       CALL swap_dimensions(ind)
82       CALL swap_geometry(ind)
83       flux=f_flux(ind)
84       flux_lon=f_flux_lon(ind)
85       flux_lat=f_flux_lat(ind)
86       DO itrac=1,nqtot
87          CALL compute_flux_centered_lonlat(scale, flux(:,:,itrac), flux_lon(:,:,itrac), flux_lat(:,:,itrac))
88       END DO
89    END DO
90  END SUBROUTINE qflux_centered_lonlat
91 
92  SUBROUTINE flux_centered_lonlat(scale, f_flux, f_flux_lon, f_flux_lat)
93    REAL(rstd), INTENT(IN) :: scale
94    TYPE(t_field),POINTER :: f_flux(:), f_flux_lon(:), f_flux_lat(:)
95    REAL(rstd), POINTER :: flux(:,:), flux_lon(:,:), flux_lat(:,:)
96    INTEGER :: ind
97    DO ind=1,ndomain
98       IF (.NOT. assigned_domain(ind)) CYCLE
99       CALL swap_dimensions(ind)
100       CALL swap_geometry(ind)
101       flux=f_flux(ind)
102       flux_lon=f_flux_lon(ind)
103       flux_lat=f_flux_lat(ind)
104       CALL compute_flux_centered_lonlat(scale, flux, flux_lon, flux_lat)
105    END DO
106  END SUBROUTINE flux_centered_lonlat
107 
108  SUBROUTINE compute_flux_centered_lonlat(scale, flux, flux_lon, flux_lat)
109    USE wind_mod
110    REAL(rstd), INTENT(IN) :: scale
111    REAL(rstd), INTENT(IN) :: flux(3*iim*jjm,llm)
112    REAL(rstd), INTENT(OUT) :: flux_lon(iim*jjm,llm), flux_lat(iim*jjm,llm)
113    REAL(rstd) :: flux_3d(iim*jjm,llm,3)
114    CALL compute_flux_centered(scale, flux, flux_3d)
115    CALL compute_wind_centered_lonlat_compound(flux_3d, flux_lon, flux_lat)
116  END SUBROUTINE compute_flux_centered_lonlat
117
118!------------------------------------ Compute energy fluxes ---------------------------------------
119
120  SUBROUTINE diagflux_energy(frac, f_phis,f_rhodz,f_theta_rhodz,f_u, f_geopot,f_theta,f_pk, f_hfluxt)
121    REAL(rstd), INTENT(IN) :: frac
122    TYPE(t_field),POINTER :: f_phis(:),f_rhodz(:),f_theta_rhodz(:),f_u(:), f_geopot(:), f_theta(:), f_pk(:), f_hfluxt(:)
123    REAL(rstd), POINTER :: phis(:), rhodz(:,:), theta_rhodz(:,:,:), u(:,:), &
124         geopot(:,:), theta(:,:,:), pk(:,:), hfluxt(:,:), &
125         ulont(:,:), thetat(:,:), epot(:,:), ekin(:,:), enthalpy(:,:), &
126         thetaflux(:,:), ulonflux(:,:), epotflux(:,:), ekinflux(:,:), enthalpyflux(:,:)
127    INTEGER :: ind
128    DO ind=1,ndomain
129       IF (.NOT. assigned_domain(ind)) CYCLE
130       CALL swap_dimensions(ind)
131       CALL swap_geometry(ind)
132       hfluxt = f_hfluxt(ind)
133       phis = f_phis(ind)
134       rhodz = f_rhodz(ind)
135       theta_rhodz = f_theta_rhodz(ind)
136       u = f_u(ind)
137       geopot = f_geopot(ind)
138       theta = f_theta(ind) ! buffer
139       pk = f_pk(ind) ! buffer
140       ulont = f_ulont(ind)
141       thetat = f_thetat(ind)
142       epot = f_epot(ind)
143       ekin = f_ekin(ind)
144       enthalpy = f_enthalpy(ind)
145       ulonflux = f_ulonfluxt(ind)
146       thetaflux = f_thetafluxt(ind)
147       epotflux = f_epotfluxt(ind)
148       ekinflux = f_ekinfluxt(ind)
149       enthalpyflux = f_enthalpyfluxt(ind)
150       CALL compute_diagflux_energy(frac,hfluxt, phis,rhodz,theta_rhodz,u, geopot,theta,pk, &
151            ulont, thetat, epot, ekin, enthalpy, &
152            ulonflux, thetaflux, epotflux, ekinflux, enthalpyflux)
153    END DO
154  END SUBROUTINE diagflux_energy
155
156  SUBROUTINE compute_diagflux_energy(frac, massflux, phis,rhodz,theta_rhodz,ue, geopot,theta,pk, &
157       ulon, thetat, epot, ekin, enthalpy, &
158       ulon_flux, thetat_flux, epot_flux, ekin_flux, enthalpy_flux)
159    USE disvert_mod, ONLY : ptop
160    REAL(rstd), INTENT(IN) :: frac
161    REAL(rstd), INTENT(IN) :: massflux(3*iim*jjm,llm), ue(3*iim*jjm,llm),&
162                              phis(iim*jjm), rhodz(iim*jjm,llm), theta_rhodz(iim*jjm,llm,nqtot)
163    REAL(rstd), INTENT(INOUT) :: geopot(iim*jjm,llm+1), theta(iim*jjm,llm), pk(iim*jjm,llm) ! theta,pk = buffers
164    REAL(rstd), INTENT(INOUT), DIMENSION(iim*jjm, llm)   ::  ulon, thetat, epot, ekin, enthalpy
165    REAL(rstd), INTENT(INOUT), DIMENSION(3*iim*jjm, llm) ::  ulon_flux, thetat_flux, epot_flux, ekin_flux, enthalpy_flux   
166    REAL(rstd) :: energy, p_ik, theta_ik, temp_ik, gv, Rd, cx,cy,cz, ux,uy,uz, ue_le,ulon_i
167    INTEGER :: ij, l, ij_omp_begin_ext, ij_omp_end_ext
168    Rd = kappa*cpp
169    ! even if loops are of the _ext variant, we still need halo exchanges before reconstructing fluxes at cell centers
170    ! => loop over interior region
171    CALL distrib_level(ij_begin_ext, ij_end_ext, ij_omp_begin_ext,ij_omp_end_ext)
172#include "../kernels_hex/energy_fluxes.k90"
173  END SUBROUTINE compute_diagflux_energy
174
175END MODULE diagflux_mod
Note: See TracBrowser for help on using the repository browser.