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