source: LMDZ6/branches/LMDZ-tracers/libf/phylmd/infotrac_phy.F90 @ 3891

Last change on this file since 3891 was 3891, checked in by dcugnet, 3 years ago
  • Bugs corrections:
    • sequential gcm fixed
    • parallel gcm compilation fixed ; to be tested
  • Some generic operations moved from infotrac to readTracFile
  • Fixed algebrical reduction routine, used in the isotopes parameters file.
  • Additional component "comp" in the tracers descriptor derived type "tra",

specifying the model component name(s) (cf. tracers sections) it belongs.

  • isotopes class selection tool fixed.
File size: 16.2 KB
Line 
1MODULE infotrac_phy
2
3  USE       strings_mod, ONLY: msg, fmsg, test, strIdx, int2str
4
5  USE readTracFiles_mod, ONLY: getKey_init, getKey, indexUpdate, delPhase
6
7  USE trac_types_mod,    ONLY: tra, iso, kys
8
9  IMPLICIT NONE
10
11  PRIVATE
12
13  !=== FOR TRACERS:
14  PUBLIC :: tra,   tracers,  type_trac                     !--- Derived type, full database, tracers type keyword
15  PUBLIC :: nqtot,   nbtr,   nqo                           !--- Main dimensions
16  PUBLIC :: init_infotrac_phy                              !--- Initialization
17  PUBLIC :: itr_indice                                     !--- Indexes of the tracers passed to phytrac
18  PUBLIC :: niadv                                          !--- Indexes of true tracers (<=nqtot, such that iadv(idx)>0)
19  PUBLIC :: pbl_flg, conv_flg, solsym
20
21  !=== FOR ISOTOPES: General
22  !--- General
23  PUBLIC :: iso, isotopes, nbIso                           !--- Derived type, full isotopes families database + nb of families
24  PUBLIC :: isoSelect , ixIso                              !--- Isotopes family selection tool + selected family index
25  !=== FOR ISOTOPES: Specific to H2O isotopes
26  PUBLIC :: iH2O, tnat, alpha_ideal                        !--- H2O isotopes index, natural abundance, fractionning coeff.
27  !=== FOR ISOTOPES: Depending on selected isotopes family
28  PUBLIC :: isotope, isoKeys                               !--- Selected isotopes database + associated keys (cf. getKey)
29  PUBLIC :: isoName, isoZone, isoPhas                      !--- Isotopes and tagging zones names, phases
30  PUBLIC :: niso, nzon, npha, nitr                         !---  " " numbers + isotopes & tagging tracers number
31  PUBLIC :: iZonIso, iTraPha                               !--- 2D index tables to get "iq" index
32  PUBLIC :: isoCheck                                       !--- Run isotopes checking routines
33
34  !=== FOR BOTH TRACERS AND ISOTOPES
35  PUBLIC :: getKey                                         !--- Get a key from "tracers" or "isotope"
36
37  !=== FOR STRATOSPHERIC AEROSOLS
38#ifdef CPP_StratAer
39  PUBLIC :: nbtr_bin, nbtr_sulgas, id_OCS_strat, id_H2SO4_strat, id_SO2_strat, id_BIN01_strat, id_TEST_strat
40#endif
41
42  INTERFACE isoSelect; MODULE PROCEDURE isoSelectByIndex, isoSelectByName; END INTERFACE isoSelect
43
44!=== CONVENTIONS FOR TRACERS NUMBERS:
45!  |--------------------+----------------------+-----------------+---------------+----------------------------|
46!  | water in different |    water tagging     |  water isotopes | other tracers | additional tracers moments |
47!  | phases: H2O-[gls]  |      isotopes        |                 |               |  for higher order schemes  |
48!  |--------------------+----------------------+-----------------+---------------+----------------------------|
49!  |                    |                      |                 |               |                            |
50!  |<--     nqo      -->|<-- nqo*niso* nzon -->|<-- nqo*niso  -->|<--  nbtr   -->|<--        (nmom)        -->|         
51!  |                    |                                        |                                            |
52!  |                    |<-- nqo*niso*(nzon+1)  =   nqo*nitr  -->|<--    nqtottr = nbtr + nmom             -->|
53!  |                                                                             = nqtot - nqo*(nitr+1)       |
54!  |                                                                                                          |
55!  |<--                        nqtrue  =  nbtr + nqo*(nitr+1)                 -->|                            |
56!  |                                                                                                          |
57!  |<--                        nqtot   =  nqtrue + nmom                                                    -->|
58!  |                                                                                                          |
59!  |----------------------------------------------------------------------------------------------------------|
60! NOTES FOR THIS TABLE:
61!  * The used "niso", "nzon" and "nitr" are the H2O components of "isotopes(ip)"  (isotopes(ip)%prnt == 'H2O'),
62!    since water is so far the sole tracers family removed from the main tracers table.
63!  * For water, "nqo" is equal to the more general field "isotopes(ip)%npha".
64!  * "niso", "nzon", "nitr", "npha" are defined for other isotopic tracers families, if any.
65!
66!=== TRACERS DESCRIPTOR: DERIVED TYPE EMBEDDING MOST OF THE USEFUL QUANTITIES (LENGTH: nqtot)
67!    Each entry is accessible using "%" sign.
68!  |------------+-------------------------------------------------+-------------+------------------------+
69!  |  entry     | Meaning                                         | Former name | Possible values        |
70!  |------------+-------------------------------------------------+-------------+------------------------+
71!  | name       | Name (short)                                    | tname       |                        |
72!  | nam1       | Name of the 1st generation ancestor             | /           |                        |
73!  | prnt       | Name of the parent                              | /           |                        |
74!  | lnam       | Long name (with adv. scheme suffix) for outputs | ttext       |                        |
75!  | type       | Type (so far: tracer or tag)                    | /           | tracer,tag             |
76!  | phas       | Phases list ("g"as / "l"iquid / "s"olid)        | /           | [g][l][s]              |
77!  | comp       | Name(s) of the merged/cumulated section(s)      | /           | coma-separated names   |
78!  | iadv       | Advection scheme number                         | iadv        | 1-20,30 exc. 3-9,15,19 |
79!  | igen       | Generation (>=1)                                | /           |                        |
80!  | itr        | Index in "tr_seri" (0: absent from physics)     | cf. niadv   | 1:nqtottr              |
81!  | iprnt      | Index of the parent tracer                      | iqpere      | 1:nqtot                |
82!  | idesc      | Indexes of the childs (all generations)         | iqfils      | 1:nqtot                |
83!  | ndesc      | Number of the descendants (all generations)     | nqdesc      | 1:nqtot                |
84!  | nchld      | Number of childs (first generation only)        | nqfils      | 1:nqtot                |
85!  | keys       | key/val pairs accessible with "getKey" routine  | /           |                        |
86!  | iso_num    | Isotope name  index in iso(igr)%name(:)         | iso_indnum  | 1:niso                 |
87!  | iso_zon    | Isotope zone  index in iso(igr)%zone(:)         | zone_num    | 1:nzon                 |
88!  | iso_pha    | Isotope phase index in iso(igr)%phas            | phase_num   | 1:npha                 |
89!  +------------+-------------------------------------------------+-------------+------------------------+
90!
91!=== ISOTOPES DESCRIPTOR: DERIVED TYPE EMBEDDING MOST OF THE USEFUL QUANTITIES (LENGTH: NUMBER OF ISOTOPES FAMILIES USED)
92!    Each entry is accessible using "%" sign.
93!  |------------+-------------------------------------------------+-------------+-----------------------+
94!  |  entry     | Meaning                                         | Former name | Possible values       |
95!  |------------+-------------------------------------------------+-------------+-----------------------+
96!  | prnt       | Parent tracer (isotopes family name)            |             |                       |
97!  | trac, nitr | Isotopes & tagging tracers + number of elements |             |                       |
98!  | zone, nzon | Geographic tagging zones   + number of elements |             |                       |
99!  | phas, npha | Phases list                + number of elements |             | [g][l][s], 1:3        |
100!  | niso       | Number of isotopes, excluding tagging tracers   |             |                       |
101!  | iTraPha    | Index in "xt" = f(iname(niso+1:nitr),iphas)     | iqiso       | 1:niso                |
102!  | iZonIso    | Index in "xt" = f(izone, iname(1:niso))         | index_trac  | 1:nzon                |
103!  |------------+-------------------------------------------------+-------------+-----------------------+
104
105  !=== DIMENSIONS OF THE TRACERS TABLES AND OTHER SCALAR VARIABLES
106  INTEGER,            SAVE :: nqtot, &                     !--- Tracers nb in dynamics (incl. higher moments & water)
107                              nbtr,  &                     !--- Tracers nb in physics  (excl. higher moments & water)
108                              nqo,   &                     !--- Number of water phases
109                              nbIso                        !--- Number of available isotopes family
110  CHARACTER(LEN=256), SAVE :: type_trac                    !--- Keyword for tracers type
111!$OMP THREADPRIVATE(nqtot, nbtr, nqo, nbIso, type_trac)
112
113  !=== DERIVED TYPES EMBEDDING MOST INFORMATIONS ABOUT TRACERS AND ISOTOPES FAMILIES
114  TYPE(tra), TARGET,  SAVE, ALLOCATABLE ::  tracers(:)     !=== TRACERS DESCRIPTORS VECTOR
115  TYPE(iso), TARGET,  SAVE, ALLOCATABLE :: isotopes(:)     !=== ISOTOPES PARAMETERS VECTOR
116!$OMP THREADPRIVATE(tracers, isotopes)
117
118  !=== ALIASES FOR CURRENTLY SELECTED ISOTOPES FAMILY OF VARIABLES EMBEDDED IN THE VECTOR "isotopes"
119  TYPE(iso),          SAVE, POINTER     :: isotope         !--- CURRENTLY SELECTED ISOTOPES FAMILY DESCRIPTOR
120  INTEGER,            SAVE              :: ixIso, iH2O     !--- Index of the selected isotopes family and H2O family
121  LOGICAL,            SAVE              :: isoCheck        !--- Flag to trigger the checking routines
122  TYPE(kys),          SAVE, POINTER     :: isoKeys(:)      !--- ONE SET OF KEYS FOR EACH ISOTOPE (LISTED IN isoName)
123  CHARACTER(LEN=256), SAVE, POINTER     :: isoName(:),   & !--- ISOTOPES NAMES FOR THE CURRENTLY SELECTED FAMILY
124                                           isoZone(:),   & !--- TAGGING ZONES  FOR THE CURRENTLY SELECTED FAMILY
125                                           isoPhas         !--- USED PHASES    FOR THE CURRENTLY SELECTED FAMILY
126  INTEGER,            SAVE              :: niso, nzon,   & !--- NUMBER OF ISOTOPES, TAGGING ZONES AND PHASES
127                                           npha, nitr      !--- NUMBER OF PHASES AND ISOTOPES + ISOTOPIC TAGGING TRACERS
128  INTEGER,            SAVE, POINTER     :: iZonIso(:,:)    !--- INDEX IN "isoTrac" AS f(tagging zone, isotope)
129  INTEGER,            SAVE, POINTER     :: iTraPha(:,:)    !--- INDEX IN "isoTrac" AS f(isotopic tracer, phase)
130!$OMP THREADPRIVATE(isotope, ixIso,iH2O, isoCheck, isoKeys, isoName,isoZone,isoPhas, niso,nzon,npha,nitr, iZonIso,iTraPha)
131
132  !=== VARIABLES EMBEDDED IN "tracers", BUT DUPLICATED, AS THEY ARE RATHER FREQUENTLY USED + VARIABLES FOR INCA
133  REAL,               SAVE, ALLOCATABLE ::     tnat(:),  & !--- Natural relative abundance of water isotope        (niso)
134                                        alpha_ideal(:)     !--- Ideal fractionning coefficient (for initial state) (niso)
135  INTEGER,            SAVE, ALLOCATABLE :: conv_flg(:),  & !--- Convection     activation ; needed for INCA        (nbtr)
136                                            pbl_flg(:),  & !--- Boundary layer activation ; needed for INCA        (nbtr)
137                                         itr_indice(:),  & !--- Indexes of the tracers passed to phytrac        (nqtottr)
138                                              niadv(:)     !--- Indexes of true tracers  (<=nqtot, such that iadv(idx)>0)
139  CHARACTER(LEN=8),   SAVE, ALLOCATABLE ::   solsym(:)     !--- Names from INCA                                    (nbtr)
140!OMP THREADPRIVATE(tnat, alpha_ideal, conv_flg, pbl_flg, itr_indice, niadv, solsym)
141
142#ifdef CPP_StratAer
143  !=== SPECIFIC TO STRATOSPHERIC AEROSOLS (CK/OB)
144  INTEGER, SAVE :: nbtr_bin, nbtr_sulgas, id_OCS_strat, id_H2SO4_strat, id_SO2_strat, id_BIN01_strat, id_TEST_strat
145!OMP THREADPRIVATE(nbtr_bin, nbtr_sulgas, id_OCS_strat, id_H2SO4_strat, id_SO2_strat, id_BIN01_strat, id_TEST_strat)
146#endif
147
148CONTAINS
149
150SUBROUTINE init_infotrac_phy(tracers_, isotopes_, type_trac_, solsym_, nbtr_, niadv_, pbl_flg_, conv_flg_)
151  ! transfer information on tracers from dynamics to physics
152  USE print_control_mod, ONLY: prt_level, lunout
153  IMPLICIT NONE
154  TYPE(tra),        INTENT(IN) ::  tracers_(:)
155  TYPE(iso),        INTENT(IN) :: isotopes_(:)
156  CHARACTER(LEN=*), INTENT(IN) :: type_trac_, solsym_(:)
157  INTEGER,          INTENT(IN) :: nbtr_, niadv_(:), pbl_flg_(:), conv_flg_(:)
158
159  CHARACTER(LEN=256) :: modname="init_infotrac_phy"
160  LOGICAL :: lerr
161
162  tracers   = tracers_
163  isotopes  = isotopes_
164  type_trac = type_trac_
165  solsym    = solsym_
166  nqtot     = SIZE(tracers_)
167  nqo       = COUNT(delPhase(tracers%name)=='H2O' .AND. tracers%igen==1)
168  nbtr      = nbtr_
169  niadv     = niadv_
170  nbIso     = SIZE(isotopes_)
171  pbl_flg  = pbl_flg_
172  conv_flg = conv_flg_
173
174  CALL msg('nqtot = '//TRIM(int2str(nqtot)))
175  CALL msg('nbtr  = '//TRIM(int2str(nbtr)))
176  CALL msg('nqo   = '//TRIM(int2str(nqo)))
177
178  !=== Specific to water
179  CALL getKey_init(tracers, isotopes)
180  IF(.NOT.isoSelect('H2O')) THEN
181    iH2O = ixIso
182    lerr = getKey('tnat' ,tnat,        isoName(1:isotope%niso))
183    lerr = getKey('alpha',alpha_ideal, isoName(1:isotope%niso))
184  END IF
185  itr_indice = PACK(tracers(:)%itr, MASK = tracers(:)%itr/=0)
186  !? CDC isoInit => A VOIR !!
187
188#ifdef CPP_StratAer
189  IF (type_trac == 'coag') THEN
190    nbtr_bin=0
191    nbtr_sulgas=0
192    DO iq = 1, nqtrue
193      IF(tracers(iq)%name(1:3)=='BIN') nbtr_bin    = nbtr_bin   +1
194      IF(tracers(iq)%name(1:3)=='GAS') nbtr_sulgas = nbtr_sulgas+1
195      SELECT CASE(tracers(iq)%name)
196        CASE('BIN01');    id_BIN01_strat = iq - nqo; CALL msg('id_BIN01_strat=', id_BIN01_strat)
197        CASE('GASOCS');   id_OCS_strat   = iq - nqo; CALL msg('id_OCS_strat  =', id_OCS_strat)
198        CASE('GASSO2');   id_SO2_strat   = iq - nqo; CALL msg('id_SO2_strat  =', id_SO2_strat)
199        CASE('GASH2SO4'); id_H2SO4_strat = iq - nqo; CALL msg('id_H2SO4_strat=', id_H2SO4_strat)
200        CASE('GASTEST');  id_TEST_strat  = iq - nqo; CALL msg('id_TEST_strat =', id_TEST_strat)
201      END SELECT
202    END DO
203    CALL msg('nbtr_bin      =',nbtr_bin)
204    CALL msg('nbtr_sulgas   =',nbtr_sulgas)
205  END IF
206#endif
207
208END SUBROUTINE init_infotrac_phy
209
210
211!==============================================================================================================================
212!=== THE ROUTINE isoSelect IS USED TO SWITCH FROM AN ISOTOPE FAMILY TO ANOTHER: ISOTOPES DEPENDENT PARAMETERS ARE UPDATED
213!     Singe generic "isoSelect" routine, using the predefined parent index (fast version) or its name (first call).
214!==============================================================================================================================
215LOGICAL FUNCTION isoSelectByName(iName, lVerbose) RESULT(lerr)
216  IMPLICIT NONE
217  CHARACTER(LEN=*),  INTENT(IN)  :: iName
218  LOGICAL, OPTIONAL, INTENT(IN) :: lVerbose
219  INTEGER :: iIso
220  LOGICAL :: lV
221  lV = .FALSE.; IF(PRESENT(lVerbose)) lV = lVerbose
222  iIso = strIdx(isotopes(:)%prnt, iName)
223  lerr = iIso == 0
224  CALL msg(lerr .AND. lV, 'no isotope family named "'//TRIM(iName)//'"')
225  IF(lerr) RETURN
226  lerr = isoSelectByIndex(iIso)
227END FUNCTION isoSelectByName
228!==============================================================================================================================
229LOGICAL FUNCTION isoSelectByIndex(iIso, lVerbose) RESULT(lerr)
230  IMPLICIT NONE
231  INTEGER,           INTENT(IN) :: iIso
232  LOGICAL, OPTIONAL, INTENT(IN) :: lVerbose
233  LOGICAL :: lv
234  lv = .FALSE.; IF(PRESENT(lVerbose)) lv = lVerbose
235  lerr = .FALSE.
236  IF(iIso == ixIso) RETURN                                      !--- Nothing to do if the index is already OK
237  lerr = iIso<=0 .OR. iIso>nbIso
238  CALL msg(lerr .AND. lV, 'Inconsistent isotopes family index '//TRIM(int2str(iIso))//': should be > 0 and <= ' &
239                                                               //TRIM(int2str(nbIso))//'"')
240  IF(lerr) RETURN
241  ixIso = iIso                                                  !--- Update currently selected family index
242  isotope => isotopes(ixIso)                                    !--- Select corresponding component
243  isoKeys => isotope%keys;    niso     = isotope%niso
244  isoName => isotope%trac;    nitr     = isotope%nitr
245  isoZone => isotope%zone;    nzon     = isotope%nzon
246  isoPhas => isotope%phas;    npha     = isotope%npha
247  iZonIso => isotope%iZonIso; isoCheck = isotope%check
248  iTraPha => isotope%iTraPha
249END FUNCTION isoSelectByIndex
250!==============================================================================================================================
251
252END MODULE infotrac_phy
Note: See TracBrowser for help on using the repository browser.