source: LMDZ6/trunk/libf/dyn3dmem/check_isotopes_loc.F @ 4125

Last change on this file since 4125 was 4125, checked in by dcugnet, 2 years ago

Fix in parallel mode

File size: 8.4 KB
Line 
1        subroutine check_isotopes(q,ijb,ije,err_msg)
2        USE infotrac, ONLY: nqtot, nqo, niso, ntraciso, nzone,
3     &                use_iso, ntraceurs_zone,
4     &                iqiso, indnum_fn_num, index_trac, tnat
5        USE parallel_lmdz
6        implicit none
7
8#include "dimensions.h"
9
10        ! inputs
11        integer ijb,ije ! peut être local et différent de ijb_u,ije_u, ex: dans qminimum
12        real q(ijb_u:ije_u,llm,nqtot)
13        character*(*) err_msg ! message d''erreur à afficher
14
15        ! locals
16        integer ixt,phase,k,i,iq,iiso,izone,ieau,iqeau
17        real xtractot,xiiso
18        real borne
19        real qmin
20        real errmax ! erreur maximale en absolu.
21        real errmaxrel ! erreur maximale en relatif autorisée
22        real deltaDmax,deltaDmin
23        real ridicule
24        parameter (borne=1e19)
25        parameter (errmax=1e-8)
26        parameter (errmaxrel=1e-3)
27        parameter (qmin=1e-11)
28        parameter (deltaDmax=1000.0,deltaDmin=-999.0)
29        parameter (ridicule=1e-12)
30        real deltaD
31
32        if (niso > 0) then
33
34!        write(*,*) 'check_isotopes 31: err_msg=',err_msg
35        ! verifier que rien n'est NaN
36        do ixt=1,ntraciso
37          do phase=1,nqo
38            iq=iqiso(ixt,phase)
39c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
40            do k=1,llm
41              DO i = ijb,ije
42                if ((q(i,k,iq).gt.-borne).and.
43     :            (q(i,k,iq).lt.borne)) then
44                else !if ((x(ixt,i,j).gt.-borne).and.
45                  write(*,*) 'erreur detectee par iso_verif_noNaN:'
46                  write(*,*) err_msg
47                  write(*,*) 'q,i,k,iq=',q(i,k,iq),i,k,iq
48                  write(*,*) 'borne=',borne
49                  call abort_gcm('check_isotopes_loc','plantage iso',0)
50                endif  !if ((x(ixt,i,j).gt.-borne).and.
51              enddo !DO i = ijb,ije
52            enddo !do k=1,llm
53c$OMP END DO NOWAIT
54          enddo !do phase=1,nqo
55        enddo !do ixt=1,ntraciso
56
57!        write(*,*) 'check_isotopes 52'
58        ! verifier que l'eau normale est OK
59        if (use_iso(1)) then
60          ixt=indnum_fn_num(1)
61          do phase=1,nqo
62            iq=iqiso(ixt,phase)
63c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
64            do k=1,llm
65            DO i = ijb,ije 
66              if ((abs(q(i,k,phase)-q(i,k,iq)).gt.errmax).and.
67     :          (abs((q(i,k,phase)-q(i,k,iq))/
68     :           max(max(abs(q(i,k,phase)),abs(q(i,k,iq))),1e-18))
69     :           .gt.errmaxrel)) then
70                  write(*,*) 'erreur detectee par iso_verif_egalite:'
71                  write(*,*) err_msg
72                  write(*,*) 'ixt,phase,ijb=',ixt,phase,ijb
73                  write(*,*) 'q,iq,i,k=',q(i,k,iq),iq,i,k
74                  write(*,*) 'q(i,k,phase)=',q(i,k,phase)
75                  call abort_gcm('check_isotopes_loc','plantage iso',0)
76              endif !if ((abs(q(i,k,phase)-q(i,k,iq)).gt.errmax).and.
77              ! bidouille pour éviter divergence:
78              q(i,k,iq)= q(i,k,phase)
79            enddo ! DO i = ijb,ije
80            enddo !do k=1,llm
81c$OMP END DO NOWAIT
82          enddo ! do phase=1,nqo
83        endif !if (use_iso(1)) then
84       
85!        write(*,*) 'check_isotopes 78'
86        ! verifier que HDO est raisonable
87        if (use_iso(2)) then
88          ixt=indnum_fn_num(2)
89          do phase=1,nqo
90            iq=iqiso(ixt,phase)
91c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
92            do k=1,llm
93            DO i = ijb,ije
94            if (q(i,k,iq).gt.qmin) then
95             deltaD=(q(i,k,iq)/q(i,k,phase)/tnat(2)-1)*1000
96             if ((deltaD.gt.deltaDmax).or.(deltaD.lt.deltaDmin)) then
97                  write(*,*) 'erreur detectee par iso_verif_aberrant:'
98                  write(*,*) err_msg
99                  write(*,*) 'ixt,phase=',ixt,phase
100                  write(*,*) 'q,iq,i,k,=',q(i,k,iq),iq,i,k
101                  write(*,*) 'q=',q(i,k,:)
102                  write(*,*) 'deltaD=',deltaD
103                  call abort_gcm('check_isotopes_loc','plantage iso',0)
104             endif !if ((deltaD.gt.deltaDmax).or.(deltaD.lt.deltaDmin)) then
105            endif !if (q(i,k,iq).gt.qmin) then
106            enddo !DO i = ijb,ije
107            enddo !do k=1,llm
108c$OMP END DO NOWAIT
109          enddo ! do phase=1,nqo
110        endif !if (use_iso(2)) then
111
112!        write(*,*) 'check_isotopes 103'
113        ! verifier que O18 est raisonable
114        if (use_iso(3)) then
115          ixt=indnum_fn_num(3)
116          do phase=1,nqo
117            iq=iqiso(ixt,phase)
118c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
119            do k=1,llm
120            DO i = ijb,ije
121            if (q(i,k,iq).gt.qmin) then
122             deltaD=(q(i,k,iq)/q(i,k,phase)/tnat(3)-1)*1000
123             if ((deltaD.gt.deltaDmax).or.(deltaD.lt.deltaDmin)) then
124                  write(*,*) 'erreur detectee iso_verif_aberrant O18:'
125                  write(*,*) err_msg
126                  write(*,*) 'ixt,phase=',ixt,phase
127                  write(*,*) 'q,iq,i,k,=',q(i,k,phase),iq,i,k
128                  write(*,*) 'xt=',q(i,k,:)
129                  write(*,*) 'deltaO18=',deltaD
130                  call abort_gcm('check_isotopes_loc','plantage iso',0)
131             endif !if ((deltaD.gt.deltaDmax).or.(deltaD.lt.deltaDmin)) then
132            endif !if (q(i,k,iq).gt.qmin) then
133            enddo !DO i = ijb,ije
134            enddo !do k=1,llm
135c$OMP END DO NOWAIT
136          enddo ! do phase=1,nqo
137        endif !if (use_iso(2)) then
138
139
140!        write(*,*) 'check_isotopes 129'
141        if (nzone > 0) then
142
143          if (use_iso(2).and.use_iso(1)) then
144            do izone=1,ntraceurs_zone
145             ixt=index_trac(izone,indnum_fn_num(2))
146             ieau=index_trac(izone,indnum_fn_num(1))
147             do phase=1,nqo
148               iq=iqiso(ixt,phase)
149               iqeau=iqiso(ieau,phase)
150c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
151               do k=1,llm
152                DO i = ijb,ije
153                if (q(i,k,iq).gt.qmin) then
154                 deltaD=(q(i,k,iq)/q(i,k,iqeau)/tnat(2)-1)*1000
155                 if ((deltaD.gt.deltaDmax).or.
156     &                   (deltaD.lt.deltaDmin)) then
157                  write(*,*) 'erreur dans iso_verif_aberrant trac:'
158                  write(*,*) err_msg
159                  write(*,*) 'izone,phase=',izone,phase
160                  write(*,*) 'ixt,ieau=',ixt,ieau
161                  write(*,*) 'q,iq,i,k,=',q(i,k,iq),iq,i,k
162                  write(*,*) 'deltaD=',deltaD                 
163                  call abort_gcm('check_isotopes_loc','plantage iso',0)
164                 endif !if ((deltaD.gt.deltaDmax).or.
165                endif !if (q(i,k,iq).gt.qmin) then
166                enddo !DO i = ijb,ije
167                enddo  ! do k=1,llm
168c$OMP END DO NOWAIT
169              enddo ! do phase=1,nqo   
170            enddo !do izone=1,ntraceurs_zone
171          endif !if (use_iso(2).and.use_iso(1)) then
172
173          do iiso=1,niso
174           do phase=1,nqo
175              iq=iqiso(iiso,phase)
176c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
177              do k=1,llm
178                DO i = ijb,ije
179                   xtractot=0.0
180                   xiiso=q(i,k,iq)
181                   do izone=1,ntraceurs_zone
182                      iq=iqiso(index_trac(izone,iiso),phase)
183                      xtractot=xtractot+ q(i,k,iq)
184                   enddo !do izone=1,ntraceurs_zone
185                   if ((abs(xtractot-xiiso).gt.errmax).and.
186     :                  (abs(xtractot-xiiso)/
187     :                  max(max(abs(xtractot),abs(xiiso)),1e-18)
188     :                  .gt.errmaxrel)) then
189                  write(*,*) 'erreur detectee par iso_verif_traceurs:'
190                  write(*,*) err_msg
191                  write(*,*) 'iiso,phase=',iiso,phase
192                  write(*,*) 'i,k,=',i,k
193                  write(*,*) 'q(i,k,:)=',q(i,k,:)
194                  call abort_gcm('check_isotopes_loc','plantage iso',0)
195                 endif !if ((abs(q(i,k,phase)-q(i,k,iq)).gt.errmax).and.
196                 
197                 ! bidouille pour éviter divergence:
198                 if (abs(xtractot).gt.ridicule) then
199                   do izone=1,ntraceurs_zone
200                     ixt=index_trac(izone,iiso)
201                     q(i,k,iq)=q(i,k,iq)/xtractot*xiiso
202                   enddo !do izone=1,ntraceurs_zone               
203                  endif !if ((abs(xtractot).gt.ridicule) then
204                enddo !DO i = ijb,ije
205              enddo !do k=1,llm
206c$OMP END DO NOWAIT
207           enddo !do phase=1,nqo
208          enddo !do iiso=1,niso
209
210        endif !if (nzone > 0)
211
212        endif ! if (niso > 0)
213!        write(*,*) 'check_isotopes 198'
214       
215        end
216
217
Note: See TracBrowser for help on using the repository browser.