source: LMDZ6/trunk/libf/dyn3d/check_isotopes.F90 @ 5054

Last change on this file since 5054 was 4984, checked in by crisi, 5 months ago

plenty of files that I forgot to commit last time.

File size: 8.0 KB
Line 
1SUBROUTINE check_isotopes_seq(q, ip1jmp1, err_msg)
2   USE strings_mod, ONLY: maxlen, msg, strIdx, strStack, int2str, real2str
3   USE infotrac,    ONLY: nqtot, niso, nphas, isotope, isoCheck, iqIsoPha, isoSelect, &
4                          ntiso, iH2O, nzone, tracers, isoName,  itZonIso, getKey
5   IMPLICIT NONE
6   include "dimensions.h"
7   REAL,             INTENT(INOUT) :: q(ip1jmp1,llm,nqtot)
8   INTEGER,          INTENT(IN)    :: ip1jmp1
9   CHARACTER(LEN=*), INTENT(IN)    :: err_msg    !--- Error message to display
10   CHARACTER(LEN=maxlen) :: modname, msg1, nm(2)
11   INTEGER :: ixt, ipha, k, i, iq, iiso, izon, ieau, iqeau, iqpar
12   INTEGER, ALLOCATABLE ::   ix(:)
13   REAL,    ALLOCATABLE, SAVE :: tnat(:)
14   REAL    :: xtractot, xiiso, deltaD, q1, q2
15   REAL, PARAMETER :: borne     = 1e19,  &
16                      errmax    = 1e-8,  &       !--- Max. absolute error
17                      errmaxrel = 1e-3,  &       !--- Max. relative error
18                      qmin      = 1e-11, &
19                      deltaDmax =1000.0, &
20                      deltaDmin =-999.0, &
21                      ridicule  = 1e-12
22   INTEGER, SAVE :: iso_eau, iso_HDO, iso_O18, &
23                             iso_O17, iso_HTO
24   LOGICAL, SAVE :: first=.TRUE.
25   LOGICAL, PARAMETER :: tnat1=.TRUE.
26
27   modname='check_isotopes'
28   IF(.NOT.isoCheck)    RETURN                   !--- No need to check => finished
29   IF(isoSelect('H2O')) RETURN                   !--- No H2O isotopes group found
30   IF(niso == 0)        RETURN                   !--- No isotopes => finished
31   IF(first) THEN
32      iso_eau = strIdx(isoName,'H216O')
33      iso_HDO = strIdx(isoName,'HDO')
34      iso_O18 = strIdx(isoName,'H218O')
35      iso_O17 = strIdx(isoName,'H217O')
36      iso_HTO = strIdx(isoName,'HTO')
37      if (tnat1) then
38              tnat(:)=1.0
39      else
40         IF(getKey('tnat', tnat)) CALL abort_gcm(modname, 'missing isotopic parameter', 1)
41      endif
42      first = .FALSE.
43   END IF
44   CALL msg('31: err_msg='//TRIM(err_msg), modname)
45
46   !--- CHECK FOR NaNs (FOR ALL THE ISOTOPES, INCLUDING GEOGRAPHIC TAGGING TRACERS)
47   modname = 'check_isotopes:iso_verif_noNaN'
48   DO ixt = 1, ntiso
49      DO ipha = 1, nphas
50         iq = iqIsoPha(ixt,ipha)
51         DO k = 1, llm
52            DO i = 1, ip1jmp1
53               IF(ABS(q(i,k,iq)) < borne) CYCLE
54               WRITE(msg1,'(s,"(",i0,",",i0,",",i0,") = ",ES12.4)')TRIM(isoName(ixt)),i,k,iq,q(i,k,iq)
55               CALL msg(msg1, modname)
56               CALL abort_gcm(modname, 'Error with isotopes: '//TRIM(err_msg), 1)
57            END DO
58         END DO
59      END DO
60   END DO
61
62   !--- CHECK CONSERVATION (MAIN ISOTOPE AND PARENT CONCENTRATIONS MUST BE EQUAL)
63   modname = 'check_isotopes:iso_verif_egalite'
64   ixt = iso_eau
65   IF(ixt /= 0) THEN
66      DO ipha = 1, nphas
67         iq = iqIsoPha(ixt,ipha)
68         iqpar = tracers(iq)%iqParent
69         DO k = 1, llm
70            DO i = 1, ip1jmp1
71               q1 = q(i,k,iqpar)
72               q2 = q(i,k,iq)
73!--- IMPROVEMENT in case at least one isotope is not negligible compared to the main isotopic form.
74!    This would be probably required to sum from smallest to highest concentrations ; the corresponding
75!    indices vector can be computed once only (in the initializations stage), using mean concentrations.
76!              q2 = SUM(q(i,k,tracers(iqPar)%iqDesc), DIM=3)
77               IF(ABS(q1-q2) <= errmax .OR. ABS(q1-q2)/MAX(MAX(ABS(q1),ABS(q2)),1e-18) <= errmaxrel) THEN
78                  q(i,k,iq) = q1                 !--- Bidouille pour convergence
79!                 q(i,k,tracers(iqPar)%iqDesc) = q(i,k,tracers(iqPar)%iqDesc) * q1 / q2
80                  CYCLE
81               END IF
82               CALL msg('ixt, iq = '//TRIM(strStack(int2str([ixt,iq]))), modname)
83               msg1 = '('//TRIM(strStack(int2str([i,k])))//')'
84               CALL msg(TRIM(tracers(iqpar)%name)//TRIM(msg1)//' = '//TRIM(real2str(q1)), modname)
85               CALL msg(TRIM(tracers(iq   )%name)//TRIM(msg1)//' = '//TRIM(real2str(q2)), modname)
86               CALL abort_gcm(modname, 'Error with isotopes: '//TRIM(err_msg), 1)
87            END DO
88         END DO
89      END DO
90   END IF
91
92   !--- CHECK DELTA ANOMALIES
93   modname = 'check_isotopes:iso_verif_aberrant'
94   ix = [ iso_HDO  ,   iso_O18 ]
95   nm = ['deltaD  ', 'deltaO18']
96   DO iiso = 1, SIZE(ix)
97      ixt = ix(iiso)
98      IF(ixt  == 0) CYCLE
99      DO ipha = 1, nphas
100         iq = iqIsoPha(ixt,ipha)
101         iqpar = tracers(iq)%iqParent
102         DO k = 1, llm
103            DO i = 1, ip1jmp1
104               q1 = q(i,k,iqpar)
105               q2 = q(i,k,iq)
106!--- IMPROVEMENT in case at least one isotope is not negligible compared to the main isotopic form.
107!    This would be probably required to sum from smallest to highest concentrations ; the corresponding
108!    indices vector can be computed once only (in the initializations stage), using mean concentrations.
109!              q2 = SUM(q(i,k,tracers(iqPar)%iqDesc), DIM=3)
110               IF(q2 <= qmin) CYCLE
111               deltaD = (q2/q1/tnat(ixt)-1.)*1000.
112               IF(deltaD <= deltaDmax .AND. deltaD >= deltaDmin) CYCLE
113               CALL msg('ixt, iq = '//TRIM(strStack(int2str([ixt,iq]))), modname)
114               msg1 = '('//TRIM(strStack(int2str([i,k])))//')'
115               CALL msg(TRIM(tracers(iqpar)%name)//TRIM(msg1)//' = '//TRIM(real2str(q1)), modname)
116               CALL msg(TRIM(tracers(iq   )%name)//TRIM(msg1)//' = '//TRIM(real2str(q2)), modname)
117               CALL msg(TRIM(nm(iiso))//TRIM(real2str(deltaD)), modname)
118               CALL abort_gcm(modname, 'Error with isotopes: '//TRIM(err_msg), 1)
119            END DO
120         END DO
121      END DO
122   END DO
123
124   IF(nzone == 0) RETURN
125
126   !--- CHECK FOR TAGGING TRACERS DELTAD ANOMALIES
127   modname = 'check_isotopes:iso_verif_aberrant'
128   IF(iso_eau /= 0 .AND. iso_HDO /= 0) THEN
129      DO izon = 1, nzone
130         ixt  = itZonIso(izon, iso_HDO)
131         ieau = itZonIso(izon, iso_eau)
132         DO ipha = 1, nphas
133            iq    = iqIsoPha(ixt,  ipha)
134            iqeau = iqIsoPha(ieau, ipha)
135            DO k = 1, llm
136               DO i = 1, ip1jmp1
137                  q1 = q(i,k,iqeau)
138                  q2 = q(i,k,iq)
139                  IF(q2<=qmin) CYCLE
140                  deltaD = (q2/q1/tnat(iso_HDO)-1.)*1000.
141                  IF(deltaD <= deltaDmax .AND. deltaD >= deltaDmin) CYCLE
142                  CALL msg('izon, ipha = '//TRIM(strStack(int2str([izon, ipha]))), modname)
143                  CALL msg( 'ixt, ieau = '//TRIM(strStack(int2str([ ixt, ieau]))), modname)
144                  msg1 = '('//TRIM(strStack(int2str([i,k])))//')'
145                  CALL msg(TRIM(tracers(iqeau)%name)//TRIM(msg1)//' = '//TRIM(real2str(q1)), modname)
146                  CALL msg(TRIM(tracers(iq   )%name)//TRIM(msg1)//' = '//TRIM(real2str(q2)), modname)
147                  CALL msg('deltaD = '//TRIM(real2str(deltaD)), modname)
148                  CALL abort_gcm(modname, 'Error with isotopes: '//TRIM(err_msg), 1)
149               END DO
150            END DO
151         END DO
152      END DO
153   END IF
154
155   !--- CHECK FOR TAGGING TRACERS CONSERVATION (PARENT AND TAGGING TRACERS SUM OVER ALL REGIONS MUST BE EQUAL)
156   DO iiso = 1, niso
157      DO ipha = 1, nphas
158         iq = iqIsoPha(iiso, ipha)
159         DO k = 1, llm
160            DO i = 1, ip1jmp1
161               xiiso = q(i,k,iq)
162               xtractot = SUM(q(i, k, iqIsoPha(itZonIso(1:nzone,iiso), ipha)))
163               IF(ABS(xtractot-xiiso) > errmax .AND. ABS(xtractot-xiiso)/MAX(MAX(ABS(xtractot),ABS(xiiso)),1e-18) > errmaxrel) THEN
164                  CALL msg('Error in iso_verif_aberrant trac: '//TRIM(err_msg))
165                  CALL msg('iiso, ipha = '//TRIM(strStack(int2str([iiso, ipha]))), modname)
166                  CALL msg('q('//TRIM(strStack(int2str([i,k])))//',:) = '//TRIM(strStack(real2str(q(i,k,:)))), modname)
167                  CALL abort_gcm(modname, 'Error with isotopes: '//TRIM(err_msg), 1)
168               END IF
169               IF(ABS(xtractot) <= ridicule) CYCLE
170               DO izon = 1, nzone
171                  q(i,k,iq) = q(i,k,iq) / xtractot * xiiso !--- Bidouille pour convergence
172               END DO
173            END DO
174         END DO
175      END DO
176   END DO
177
178END SUBROUTINE check_isotopes_seq
179
Note: See TracBrowser for help on using the repository browser.