The TELEMAC-MASCARET system  trunk
cvsp_check_f.f
Go to the documentation of this file.
1 ! *****************************
2  RECURSIVE FUNCTION cvsp_check_f
3 ! *****************************
4 !
5  &(j,k, sometext) result(ret)
6 !
7 !***********************************************************************
8 ! SISYPHE V7P2 16/05/2017
9 !***********************************************************************
10 !
11 !brief CHECKS IF SUM OF FRACTIONS = 1 FOR
12 !+ A SECTION IN THE VERTICAL SORTING PROFILE
13 !
14 !history UWE MERKEL
15 !+ 19/08/2011
16 !+ V6P2
17 !+
18 !
19 !history P. A. TASSI (EDF R&D, LNHE)
20 !+ 12/03/2013
21 !+ V6P3
22 !+ Cleaning, cosmetic
23 !
24 !history UWE MERKEL, R. KOPMANN (BAW)
25 !+ 19/08/2016 / 2017
26 !+ V6P3 / V7P2
27 !+ many changes!
28 !
29 !history R. KOPMANN (BAW)
30 !+ 25/02/2019
31 !+ V7P2
32 !+ inserting check PRO_F>1, removing 1/NSICLA
33 !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
34 !| J |<--| INDEX OF A POINT IN MESH
35 !| K |<--| INDEX OF A SECTION IN VERTICAL SORTING PROFILE
36 !| SOMETEXT |<--| DEBUGING TEXT FOR LOG-OUTPUT
37 !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
38 !
39  USE bief_def, ONLY : ncsize
40  USE bief
42  USE cvsp_outputfiles, ONLY: cp
43 !
45  IMPLICIT NONE
46 !
47 !+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
48 !
49  INTEGER, INTENT(IN) :: J
50  INTEGER, INTENT(IN) :: K
51  CHARACTER(LEN=10),INTENT(IN) :: SOMETEXT
52 !
53 !+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
54 !
55  DOUBLE PRECISION TEMP, AT, ERRTOCORR
56  INTEGER I, JG
57  LOGICAL RET
58 !-----------------------------------------------------------------------
59  at = dt*lt/percou
60  jg = j
61  IF (ncsize > 1) jg = mesh%KNOLG%I(j)
62  ret = .true.
63  temp = 0.d0
64 !-----------------------------------------------------------------------
65 !SUM UP AND SLIGHT CORRECTION
66 !-----------------------------------------------------------------------
67  DO i=1,nsicla
68  IF (pro_f(j,k,i).LT.0.d0) THEN
69  IF (pro_f(j,k,i).LE.-1.d-7.AND.cp) WRITE(lu,*)
70  & 'CVSP CF:PRO_F<0: WARN,J;K;F_I;%: ',
71  & sometext,jg,k,i,pro_f(j,k,i)
72  IF(pro_f(j,k,i).GE.-1.d-3) THEN
73  pro_f(j,k,i) = 0.d0
74  ELSE
75  CALL cvsp_p('./','PRO_F.lt'//sometext, j)
76  WRITE(lu,*) 'CVSP CF:PRO_F<0: ERR,LT,J;K;F_I;%: '
77  & ,sometext,lt,jg,k,i,pro_f(j,k,i)
78  CALL plante(1)
79  stop
80  ENDIF
81  ENDIF
82 !RK PRO_F > 1
83  IF (pro_f(j,k,i).GT.1.d0) THEN
84  IF ((1.d0-pro_f(j,k,i)).LE.-1.d-7.AND.cp) WRITE(lu,*)
85  & 'CVSP CF:PRO_F>1: WARN,J;K;F_I;%: ',
86  & sometext,jg,j,k,i,pro_f(j,k,i)
87 ! IF((1.D0-PRO_F(J,K,I)).GE.-1.D-3) THEN
88 ! This barrier is quite low, as it is a numerical problem in rm_fraction
89 ! if a fraction of value nearly 1 is removed than the "normalising procedure" is not very
90 ! precise as it is diveded by (1-reomoved fraction) which can be nearly zero...
91  IF((1.d0-pro_f(j,k,i)).GE.-1.d0) THEN
92  pro_f(j,k,i) = 1.d0
93  ELSE
94  CALL cvsp_p('./','PRO_F.gt'//sometext, j)
95  WRITE(lu,*) 'CVSP CF:PRO_F>1: ERR,LT,J;K;F_I;%: '
96  & ,sometext,lt,jg,k,i,pro_f(j,k,i),pro_max(j)
97  CALL plante(1)
98  stop
99  ENDIF
100  ENDIF
101  temp = temp + pro_f(j,k,i)
102  ENDDO
103 ! ALL FRACTION ZERO IS OK, IN CVSP_MAIN this section will be deleted
104  IF(temp.EQ.0.d0) THEN
105  temp = 1.d0
106  ENDIF
107 !-----------------------------------------------------------------------
108 ! CHECK AND CORRECT DEVIATIONS
109 !-----------------------------------------------------------------------
110  IF(abs(temp-1.d0).GT.0.d0) THEN
111  IF(abs(temp).LT.1.d-6) THEN
112 ! SEVERE ERROR, FOR DEBUGGING ONLY RESET to 1 / NSICLA
113  IF(cp) WRITE(lu,*) 'CVSP CF: |SUM_ERR|~0;LT;J;K;SUM:'
114  & ,sometext,lt,jg,k,temp
115  ret = .false.
116  IF(cp) WRITE(lu,*) 'CVSP --> NSICLA: ', nsicla
117  DO i=1,nsicla
118  IF(cp) WRITE(lu,*) 'CVSP --> ;LT;Pnt_J;Lay_K;F_I,%: '
119  & ,lt,jg,k,i,pro_f(j,k,i)
120  pro_f(j,k,i) = 0.d0
121  ENDDO
122  ELSEIF(abs(temp-1.d0).GT.1.d-6) THEN
123 !STRONG DIFFERENCES ARE CORRECTED BY NORMALIZING ALL FRACTIONS
124 !!!!!!!!!!! README!
125 !The following warning occured in 0.00025 of all cases
126 !In almost every case |SUM_ERR| < 2*1.D-5
127 !To remove this remaining errors would cost 2-3 times higher
128 !computational expense with no significant global effects
129 !So the following warning is just meant to remember you on truncation errors
130 !that still exist
131  IF(abs(temp-1.d0).GT.5.d-5) THEN
132  IF(cp) WRITE(lu,*) 'CVSP CF: |SUM_ERR|>1.-5 ;LT;J;K;SUM:'
133  & ,sometext,lt,jg,k,temp
134  ENDIF
135  ret = .false.
136  DO i=1,nsicla
137  IF(pro_f(j,k,i).GT.0.d0) THEN
138  pro_f(j,k,i) = pro_f(j,k,i) / temp
139  ENDIF
140  ENDDO
141  ELSE
142 ! SLIGHT DIFFERENCES TO 0 ARE CORRECTED BY CHANGING ONLY
143 ! THE FIRST FRACTION BIG ENOUGH
144  errtocorr = 1.d0-temp
145  DO i=1,nsicla
146  IF(pro_f(j,k,i)+errtocorr.GT.0.d0.AND.
147  & pro_f(j,k,i)+errtocorr.LE.1.d0 ) THEN
148  pro_f(j,k,i) = pro_f(j,k,i) + errtocorr
149  EXIT
150  ENDIF
151  ENDDO
152  ENDIF
153  ENDIF
154 !-----------------------------------------------------------------------
155 ! RECHECK
156 !-----------------------------------------------------------------------
157  IF(ret .EQV. .false.) THEN
158  ret = cvsp_check_f(j,k,'ReCheck ')
159  ENDIF
160 !
161 !-----------------------------------------------------------------------
162 !
163  RETURN
164  END FUNCTION cvsp_check_f
recursive logical function cvsp_check_f(J, K, SOMETEXT)
Definition: cvsp_check_f.f:7
double precision, dimension(:,:,:), allocatable, target pro_f
integer ncsize
Definition: bief_def.f:49
double precision, target dt
subroutine cvsp_p(PATH_PRE, FILE_PRE, JG)
Definition: cvsp_p.f:7
integer, dimension(:), allocatable pro_max
type(bief_mesh), target mesh
Definition: bief.f:3