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

Last change on this file since 603 was 603, checked in by dubos, 7 years ago

devel : output theta and momentum fluxes

File size: 7.8 KB
RevLine 
[583]1MODULE diagflux_mod
2  USE icosa
[594]3  USE omp_para
[583]4  IMPLICIT NONE
5  SAVE
[594]6  PRIVATE
7
8  TYPE(t_field), POINTER, PUBLIC :: &
[593]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
[601]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
[583]14  LOGICAL :: diagflux_on
15  !$OMP THREADPRIVATE(diagflux_on)
16
[594]17  PUBLIC :: diagflux_on, init_diagflux, zero_qfluxt, qflux_centered_lonlat, flux_centered_lonlat, diagflux_energy
18
[583]19CONTAINS
20
21  SUBROUTINE init_diagflux
22    USE getin_mod
[593]23    INTEGER :: ll
[583]24    diagflux_on = .FALSE.
25    CALL getin("diagflux", diagflux_on)
[594]26    ll = MERGE(llm,1,diagflux_on)
[593]27    CALL allocate_field(f_masst,         field_t,type_real,ll,       name="masst")
[601]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")
[593]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")
[601]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")
[593]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
[583]44  END SUBROUTINE init_diagflux
45
[594]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
[583]49  SUBROUTINE zero_qfluxt
50    INTEGER :: ind
[592]51    REAL(rstd), POINTER :: buf2(:,:),buf3(:,:,:)
[583]52    DO ind=1,ndomain
53       IF (.NOT. assigned_domain(ind)) CYCLE
54       CALL swap_dimensions(ind)
[594]55       ZERO2(f_masst)
[603]56       ZERO2(f_ulont)
57       ZERO2(f_thetat)
[594]58       ZERO2(f_epot)
59       ZERO2(f_ekin)
60       ZERO2(f_enthalpy)
61       ZERO3(f_qmasst)
62       ZERO2(f_massfluxt)
[603]63       ZERO2(f_ulonfluxt)
64       ZERO2(f_thetafluxt)
[594]65       ZERO2(f_epotfluxt)
66       ZERO2(f_ekinfluxt)
67       ZERO2(f_enthalpyfluxt)
68       ZERO3(f_qfluxt)
[583]69    END DO
70  END SUBROUTINE zero_qfluxt
[585]71
[594]72!------------------------------------ Reconstruct fluxes at cell centers ---------------------------------------
73
74  SUBROUTINE qflux_centered_lonlat(scale, f_flux, f_flux_lon, f_flux_lat)
[587]75    REAL(rstd), INTENT(IN) :: scale
[594]76    TYPE(t_field),POINTER :: f_flux(:), f_flux_lon(:), f_flux_lat(:)
77    REAL(rstd), POINTER :: flux(:,:,:), flux_lon(:,:,:), flux_lat(:,:,:)
[585]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)
[587]84       flux_lon=f_flux_lon(ind)
85       flux_lat=f_flux_lat(ind)
[585]86       DO itrac=1,nqtot
[587]87          CALL compute_flux_centered_lonlat(scale, flux(:,:,itrac), flux_lon(:,:,itrac), flux_lat(:,:,itrac))
[585]88       END DO
89    END DO
[594]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
[585]106  END SUBROUTINE flux_centered_lonlat
[583]107 
[587]108  SUBROUTINE compute_flux_centered_lonlat(scale, flux, flux_lon, flux_lat)
109    USE wind_mod
110    REAL(rstd), INTENT(IN) :: scale
[585]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)
[587]114    CALL compute_flux_centered(scale, flux, flux_3d)
[585]115    CALL compute_wind_centered_lonlat_compound(flux_3d, flux_lon, flux_lat)
116  END SUBROUTINE compute_flux_centered_lonlat
117
[594]118!------------------------------------ Compute energy fluxes ---------------------------------------
119
[601]120  SUBROUTINE diagflux_energy(frac, f_phis,f_rhodz,f_theta_rhodz,f_u, f_geopot,f_theta,f_pk, f_hfluxt)
[594]121    REAL(rstd), INTENT(IN) :: frac
[601]122    TYPE(t_field),POINTER :: f_phis(:),f_rhodz(:),f_theta_rhodz(:),f_u(:), f_geopot(:), f_theta(:), f_pk(:), f_hfluxt(:)
[594]123    REAL(rstd), POINTER :: phis(:), rhodz(:,:), theta_rhodz(:,:,:), u(:,:), &
[601]124         geopot(:,:), theta(:,:,:), pk(:,:), hfluxt(:,:), &
125         ulont(:,:), thetat(:,:), epot(:,:), ekin(:,:), enthalpy(:,:), &
126         thetaflux(:,:), ulonflux(:,:), epotflux(:,:), ekinflux(:,:), enthalpyflux(:,:)
[594]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)
[601]138       theta = f_theta(ind) ! buffer
139       pk = f_pk(ind) ! buffer
140       ulont = f_ulont(ind)
141       thetat = f_thetat(ind)
[594]142       epot = f_epot(ind)
143       ekin = f_ekin(ind)
144       enthalpy = f_enthalpy(ind)
[601]145       ulonflux = f_ulonfluxt(ind)
146       thetaflux = f_thetafluxt(ind)
[594]147       epotflux = f_epotfluxt(ind)
148       ekinflux = f_ekinfluxt(ind)
149       enthalpyflux = f_enthalpyfluxt(ind)
[601]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)
[594]153    END DO
154  END SUBROUTINE diagflux_energy
155
[601]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)
[594]159    USE disvert_mod, ONLY : ptop
160    REAL(rstd), INTENT(IN) :: frac
[601]161    REAL(rstd), INTENT(IN) :: massflux(3*iim*jjm,llm), ue(3*iim*jjm,llm),&
[594]162                              phis(iim*jjm), rhodz(iim*jjm,llm), theta_rhodz(iim*jjm,llm,nqtot)
[601]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
[594]167    INTEGER :: ij, l, ij_omp_begin_ext, ij_omp_end_ext
168    Rd = kappa*cpp
[595]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
[603]171    CALL distrib_level(ij_begin_ext, ij_end_ext, ij_omp_begin_ext,ij_omp_end_ext)
[594]172#include "../kernels/energy_fluxes.k90"
173  END SUBROUTINE compute_diagflux_energy
174
[583]175END MODULE diagflux_mod
Note: See TracBrowser for help on using the repository browser.