PHYEX 0.9.5
PHYsique EXternalisée
Loading...
Searching...
No Matches
mode_lima_init_ccn_activation_spectrum.F90
Go to the documentation of this file.
1!MNH_LIC Copyright 2007-2026 CNRS, Meteo-France and Universite Paul Sabatier
2!MNH_LIC This is part of the Meso-NH software governed by the CeCILL-C licence
3!MNH_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt
4!MNH_LIC for details. version 1.
5!-------------------------------------------------------------------------------
7 IMPLICIT NONE
8
9 PRIVATE
10
12
13 ! NM, NN, XS and XNCCN are declared at MODULE scope (instead of being local to the
14 ! subroutine below) as a workaround for nvfortran bug 6927287 (impacts NVHPC at least up to 26.9):
15 ! a contained procedure with host association (DISTANCE) passed as an EXTERNAL argument
16 ! (to LMDIF1) reads its host link from an uninitialised register at -O0/-O1 and crashes.
17 ! No crash at -O2 and more because the compiler inlines the contained procedure.
18 ! Keeping the data out of the host scope removes the host association.
19 INTEGER(KIND=4), PARAMETER :: NM = 1000 ! Number of points (S,Nccn) used to fit the spectra
20 INTEGER(KIND=4), PARAMETER :: NN = 3 ! Number of parameters to adjust
21 REAL, DIMENSION(NM) :: XS ! saturation ratio (S=1.01 for a 1% supersaturation)
22 REAL, DIMENSION(NM) :: XNCCN ! fraction of the aerosols larger than ZDCRIT (ie activable)
23
24CONTAINS
25! #############################################################
26 SUBROUTINE lima_init_ccn_activation_spectrum (CST, HTYPE_CCN,PD,PSIGMA,PLIMIT_FACTOR,PK,PMU,PBETA,PKAPPA)
27! #############################################################
28
29!!
30!!
31!! PURPOSE
32!! -------
33!!
34!! Compute mu, k and beta parameters of the activation spectrum based on CCN
35!! characteristics (type and PSD)
36!!
37!!
38!! AUTHOR
39!! ------
40!! J.-P. Pinty * Laboratoire d'Aerologie*
41!! S. Berthet * Laboratoire d'Aerologie*
42!! B. Vié * Laboratoire d'Aerologie*
43!!
44!! MODIFICATIONS
45!! -------------
46!! Original ??/??/13
47!!
48!-------------------------------------------------------------------------------
49!
50!* 0. DECLARATIONS
51! ------------
52!
53USE modi_gamma_inc, ONLY: gamma_inc
54USE modi_hypgeo, ONLY: hypgeo
55
56USE modd_cst, ONLY:cst_t
57USE yomhook, ONLY:lhook, dr_hook, jphook
59USE modi_minpack, ONLY: lmdif1
60!
61IMPLICIT NONE
62!
63!* 0.1 Declarations of dummy arguments :
64!
65TYPE(cst_t), INTENT(IN) :: cst
66CHARACTER(LEN=*), INTENT(IN) :: htype_ccn ! Aerosol type
67REAL, INTENT(IN) :: pd ! Aerosol PSD modal diameter
68REAL, INTENT(IN) :: psigma ! Aerosol PSD width
69REAL, INTENT(OUT) :: plimit_factor ! C/Naer
70REAL, INTENT(OUT) :: pk ! k
71REAL, INTENT(OUT) :: pmu ! mu
72REAL, INTENT(OUT) :: pbeta ! beta
73REAL, INTENT(OUT) :: pkappa ! kappa
74!
75!* 0.2 Declarations of local variables :
76!
77REAL(kind=mnhreal64), DIMENSION(NN) :: zparams ! Parameters to adjust by the LM algorithm (k, mu, beta)
78REAL(kind=mnhreal64), DIMENSION(NM) :: zfvec ! Array to store the distance between theoretical and fitted spectra
79INTEGER :: iflag !
80INTEGER(KIND=4) :: iinfo !
81REAL(kind=mnhreal64) :: ztol = 1.e-16 ! Fit precision required
82!
83INTEGER :: ii, ij ! Loop indices
84!
85REAL :: zw !
86REAL :: zddry = 0.1e-6 ! Dry diameter for which to compute Scrit
87REAL(kind=mnhreal64) :: zscrit ! Scrit for dry diameter ZDDRY
88REAL(kind=mnhreal64) :: zmin = 0.1e-6_mnhreal64 ! minimum diameter for root search (m)
89REAL(kind=mnhreal64) :: zmax = 10.e-6_mnhreal64 ! maximum diameter for root search (m)
90REAL :: zprec = 1.e-8 ! precision wanted for root (m)
91!
92REAL, DIMENSION(NM) :: zdcrit ! critical diameters (m) for the chosen S values
93REAL, DIMENSION(1) :: zt ! temperature
94!
95REAL(kind=jphook) :: zhook_handle
96!
97!-------------------------------------------------------------------------------
98!
99!* 1. Select kappa value based on HTYPE_CCN
100! ---------------------------------
101!
102! Kappa values are from Petters and Kreidenweis (2007), table 1.
103!
104IF (lhook) CALL dr_hook('LIMA_INIT_CCN_ACTIVATION_SPECTRUM', 0, zhook_handle)
105SELECT CASE (htype_ccn)
106CASE('NH42SO4','C') ! Ammonium sulfate
107 pkappa = 0.61
108CASE('NH4NO3') ! Ammonium nitrate
109 pkappa = 0.67
110CASE('NACL','M') ! Sea Salt
111 pkappa = 1.28
112CASE('H2SO4') ! Sulfuric acid
113 pkappa = 0.90
114CASE('NANO3') ! Sodium nitrate
115 pkappa = 0.88
116CASE('NAHSO4') ! Sodium bisulfate
117 pkappa = 0.91
118CASE('NA2SO4') ! Sodium sulfate
119 pkappa = 0.80
120CASE('NH43HSO42') ! Letovicite (rare ammonium sulfate mineral)
121 pkappa = 0.65
122CASE('SOA') ! Secondary organic aerosol (alpha-pinene, beta-pinene)
123 pkappa = 0.1
124CASE DEFAULT
125 pkappa = 1.
126END SELECT
127!
128!ZT = (/ 270., 271., 272., 273., 274., 275., 276., 277., 278., 279., 280., 281., 282., 283., 284., 285., 286., 287., 288., 289. /)
129zt = (/ 280. /)
130
131!
132! Initialize supersaturation values (in %)
133!
134DO ii=1, SIZE(xs)
135 xs(ii)=exp( log(10.**(-3.)) + real(ii) / real(SIZE(xs)) * (log(10.**2.)-log(10.**(-3.))) )
136END DO
137
138DO ij=1, SIZE(zt)
139!
140!* 2. Compute Nccn(s) for several supersaturation values
141! --------------------------------------------------
142!
143! Get the value of Scrit at Ddry=0.1 micron
144!
145 zddry = pd
146 zmin = pd
147 zmax = pd*10.
148 zprec = pd/100.
149 zw = 4 * 0.072 * cst%XMV / cst%XAVOGADRO / cst%XBOLTZ / zt(ij) / cst%XRHOLW
150 zscrit = zriddr(zmin,zmax,zprec,zddry,pkappa,zt(ij)) ! wet diameter at Scrit
151 zscrit = (zscrit**3-zddry**3) * exp(zw/zscrit) / (zscrit**3-(1-pkappa)*zddry**3) ! Saturation ratio at Scrit
152 zscrit = (zscrit - 1.) * 100. ! Scrit (in %)
153!
154! Get the ZDCRIT values for ZS using the approx.
155! ln(100*(Sw))~Dcrit^(-3/2) where Sw is in % (Sw=1 for a 1% supersaturation)
156!
157 zw = zddry * zscrit**0.66 ! "a" factor in Ddry_crit = a*S**-0.66
158 zdcrit(:) = zw * xs(:)**(-0.66) ! Ddry_crit for each value of S
159!
160! Compute Nccn(S) as the incomplete integral of n(D) from 0 to Ddry_crit(S)
161!
162 DO ii=1, SIZE(xs)
163 xnccn(ii) = 1- ( 0.5 + sign(0.5,zdcrit(ii)-pd) * gamma_inc(0.5,(log(zdcrit(ii)/pd)/sqrt(2.)/log(psigma))**2) )
164 END DO
165!
166!-------------------------------------------------------------------------------
167!
168!* 3. Compute C, k, mu, beta, using the Levenberg-Marquardt algorithm
169! ---------------------------------------------------------------
170!
171 zparams(1:3) = (/ 1._mnhreal64, 1._mnhreal64, 1000._mnhreal64 /)
172 iflag = 1
173 CALL lmdif1 ( distance, nm, nn, zparams, zfvec, ztol, iinfo )
174!
175 plimit_factor = gamma(zparams(2))*zparams(3)**(zparams(1)/2)/gamma(1+zparams(1)/2)/gamma(zparams(2)-zparams(1)/2)
176 pk = zparams(1)
177 pmu = zparams(2)
178 pbeta = zparams(3)
179!
180END DO ! loop on temperatures
181!
182!-------------------------------------------------------------------------------
183!
184!* 6. Functions used to compute Scrit at Ddry=0.1 micron
185! --------------------------------------------------
186!
187IF (lhook) CALL dr_hook('LIMA_INIT_CCN_ACTIVATION_SPECTRUM', 1, zhook_handle)
188CONTAINS
189!
190!------------------------------------------------------------------------------
191!
192 FUNCTION zriddr(PX1,PX2,PXACC,PDDRY,PKAPPA,PT) RESULT(PZRIDDR)
193USE yomhook, ONLY:lhook, dr_hook, jphook
194!
195!
196!!**** *ZRIDDR* - iterative algorithm to find root of a function
197!!
198!!
199!! PURPOSE
200!! -------
201!! The purpose of this function is to find the root of a given function
202!! the arguments are the brackets bounds (the interval where to find the root)
203!! the accuracy needed and the input parameters of the given function.
204!! Using Ridders' method, return the root of a function known to lie between
205!! PX1 and PX2. The root, returned as PZRIDDR, will be refined to an approximate
206!! accuracy PXACC.
207!!
208!!** METHOD
209!! ------
210!! Ridders' method
211!!
212!! EXTERNAL
213!! --------
214!! FUNCSMAX
215!!
216!! IMPLICIT ARGUMENTS
217!! ------------------
218!!
219!! REFERENCE
220!! ---------
221!! NUMERICAL RECIPES IN FORTRAN 77: THE ART OF SCIENTIFIC COMPUTING
222!! (ISBN 0-521-43064-X)
223!! Copyright (C) 1986-1992 by Cambridge University Press.
224!! Programs Copyright (C) 1986-1992 by Numerical Recipes Software.
225!!
226!! AUTHOR
227!! ------
228!! Frederick Chosson *CERFACS*
229!!
230!! MODIFICATIONS
231!! -------------
232!! Original 12/07/07
233!! S.BERTHET 2008 vectorization
234!------------------------------------------------------------------------------
235!
236!* 0. DECLARATIONS
237!
238!
239IMPLICIT NONE
240!
241!* 0.1 declarations of arguments and result
242!
243REAL(kind=mnhreal64), INTENT(INOUT) :: px1, px2
244REAL, INTENT(INOUT) :: pxacc
245REAL, INTENT(IN) :: pddry, pkappa, pt
246REAL(kind=mnhreal64) :: pzriddr
247!
248!* 0.2 declarations of local variables
249!
250!
251INTEGER, PARAMETER :: imaxit=60
252REAL(kind=mnhreal64) :: zfh,zfl, zfm,zfnew
253REAL(kind=mnhreal64) :: zs,zxh,zxl,zxm,zxnew
254INTEGER :: ij
255REAL(kind=jphook) :: zhook_handle
256!
257IF (lhook) CALL dr_hook('ZRIDDR', 0, zhook_handle)
258pzriddr= 999999._mnhreal64
259zfl = dsdd(px1,pddry,pkappa,pt)
260zfh = dsdd(px2,pddry,pkappa,pt)
261!
262100 IF ((zfl > 0.0 .AND. zfh < 0.0) .OR. (zfl < 0.0 .AND. zfh > 0.0)) then
263 zxl = px1
264 zxh = px2
265 DO ij=1,imaxit
266 zxm = 0.5_mnhreal64*(zxl+zxh)
267 zfm = dsdd(zxm,pddry,pkappa,pt)
268 zs = sqrt(zfm**2-zfl*zfh)
269 IF (zs == 0.0) then
270 GO TO 101
271 ENDIF
272 zxnew = zxm+(zxm-zxl)*(sign(1.0_mnhreal64,zfl-zfh)*zfm/zs)
273 IF (abs(zxnew - pzriddr) <= pxacc) then
274 GO TO 101
275 ENDIF
276 pzriddr = zxnew
277 zfnew = dsdd(pzriddr,pddry,pkappa,pt)
278 IF (zfnew == 0.0) then
279 GO TO 101
280 ENDIF
281 IF (sign(zfm,zfnew) /= zfm) then
282 zxl =zxm
283 zfl=zfm
284 zxh =pzriddr
285 zfh=zfnew
286 ELSE IF (sign(zfl,zfnew) /= zfl) then
287 zxh =pzriddr
288 zfh=zfnew
289 ELSE IF (sign(zfh,zfnew) /= zfh) then
290 zxl =pzriddr
291 zfl=zfnew
292 ELSE IF (px2 .LT. 0.05) then
293 px2 = px2 + 1.0e-2_mnhreal64
294! PRINT*, 'PX2 ALWAYS too small, we put a greater one : PX2 =',PX2
295 zfh = dsdd(px2,pddry,pkappa,pt)
296 GO TO 100
297 stop
298 END IF
299 IF (abs(zxh-zxl) <= pxacc) then
300 GO TO 101
301 ENDIF
302 END DO
303 stop
304 ELSE IF (zfl == 0.0) then
305 pzriddr=px1
306 ELSE IF (zfh == 0.0) then
307 pzriddr=px2
308 ELSE IF (px2 .LT. 0.05) then
309 px2 = px2 + 1.0e-2
310! PRINT*, 'PX2 too small, we put a greater one : PX2 =',PX2
311 zfh = dsdd(px2,pddry,pkappa,pt)
312 GO TO 100
313 ELSE
314 pzriddr=0.0_mnhreal64
315 GO TO 101
316 END IF
317!
318101 IF (lhook) CALL dr_hook('ZRIDDR', 1, zhook_handle)
319END FUNCTION zriddr
320!
321!------------------------------------------------------------------------------
322!
323 FUNCTION dsdd(PD,PDDRY,PKAPPA, PT) RESULT(ZDS)
324!!
325!! PURPOSE
326!! -------
327!! Derivative of S(D) from Petters and Kreidenweis 2007 (eq. 6) to get Dcrit and Scrit
328!!
329!!** METHOD
330!! ------
331!! This function is called by zriddr
332!!
333!! EXTERNAL
334!! --------
335!!
336!! IMPLICIT ARGUMENTS
337!! ------------------
338!!
339!! REFERENCE
340!! ---------
341!! Petters and Kreidenweis, 2007: "A single parameter representation of hygroscopic
342!! growth and cloud condensation nucleus activity",
343!! ACP, 7, 1961-1971
344!!
345!! AUTHOR
346!! ------
347!! Benoit Vie *CNRM*
348!!
349!! MODIFICATIONS
350!! -------------
351!! Original 13/11/17
352!!
353!------------------------------------------------------------------------------
354!
355!* 0. DECLARATIONS
356!
357USE yomhook, ONLY:lhook, dr_hook, jphook
358USE modd_precision, ONLY: mnhreal64
359!
360 IMPLICIT NONE
361!
362!* 0.1 declarations of arguments and result
363!
364 REAL(kind=mnhreal64), INTENT(IN) :: pd ! supersaturation is already in no units
365 REAL, INTENT(IN) :: pddry ! supersaturation is already in no units
366 REAL, INTENT(IN) :: pkappa ! supersaturation is already in no units
367 REAL, INTENT(IN) :: pt ! supersaturation is already in no units
368!
369 REAL(kind=mnhreal64) :: zds ! result
370!
371!* 0.2 declarations of local variables
372!
373 REAL(kind=jphook) :: zhook_handle
374 REAL :: za ! factor inside the exponential
375 REAL(kind=mnhreal64) :: z
376!
377 IF (lhook) CALL dr_hook('DSDD', 0, zhook_handle)
378 za = 4 * 0.072 * cst%XMV / cst%XAVOGADRO / cst%XBOLTZ / pt / cst%XRHOLW
379 z = (pd**3-pddry**3) * (pd**3-(1._mnhreal64-pkappa)*pddry**3) * za - 3._mnhreal64 * pkappa * dble(pd)**4 * dble(pddry)**3
380 z = z * exp(za/pd) / (pd**3-(1-pkappa)*pddry**3)**2
381 zds = z
382!
383IF (lhook) CALL dr_hook('DSDD', 1, zhook_handle)
384END FUNCTION dsdd
385!
386!-------------------------------------------------------------------------------
387!
388!* 7. Functions used to fit the CCN activation spectra with C s**k F()
389! ----------------------------------------------------------------
390!
391 SUBROUTINE distance(KM,KN,PX,PFVEC,IFLAG)
392USE yomhook, ONLY:lhook, dr_hook, jphook
393!!
394!! PURPOSE
395!! -------
396!! Derivative of S(D) from Petters and Kreidenweis 2007 (eq. 6) to get Dcrit and Scrit
397!!
398!!** METHOD
399!! ------
400!! This function is called by zriddr
401!!
402!! EXTERNAL
403!! --------
404!!
405!! IMPLICIT ARGUMENTS
406!! ------------------
407!!
408!! REFERENCE
409!! ---------
410!! Petters and Kreidenweis, 2007: "A single parameter representation of hygroscopic
411!! growth and cloud condensation nucleus activity",
412!! ACP, 7, 1961-1971
413!!
414!! AUTHOR
415!! ------
416!! Benoit Vie *CNRM*
417!!
418!! MODIFICATIONS
419!! -------------
420!! Original 13/11/17
421!!
422!------------------------------------------------------------------------------
423!
424!* 0. DECLARATIONS
425!
426!* 0.1 declarations of arguments and result
427!
428 !DISTANCE must use KIND 8 reals and KIND 4 integers to be used by LMDIF1
429 INTEGER(KIND=4), INTENT(IN) :: km
430 INTEGER(KIND=4), INTENT(IN) :: kn
431 REAL(kind=mnhreal64), INTENT(IN) :: px(kn)
432 REAL(kind=mnhreal64), INTENT(OUT) :: pfvec(km)
433 INTEGER(KIND=4), INTENT(INOUT) :: iflag
434!
435!* 0.2 declarations of local variables
436!
437 INTEGER ii
438 REAL(kind=mnhreal64) zc
439 REAL(kind=mnhreal64) zw
440 REAL(kind=jphook) :: zhook_handle
441!
442 ! print *, "X = ", X
443 IF (lhook) CALL dr_hook('DISTANCE', 0, zhook_handle)
444 IF ( any(px .LT.0.) .OR. px(1).GT.2*px(2)) THEN
445 pfvec(:) = 999999._mnhreal64
446 ELSE
447 zc=gamma(px(2))*px(3)**(px(1)/2)/gamma(1+px(1)/2)/gamma(px(2)-px(1)/2)
448 DO ii=1, km
449 ! ZS in "no units", ie ZS=0.01 for a 1% suersaturation
450 ! ZW= C * (ZS(I)/100)**X(1) * HYPGEO(X(2),X(1)/2,X(1)/2+1,X(3),ZS(I)/100)
451 zw= real(zc * (xs(ii))**px(1) * hypgeo(real(px(2)),real(px(1)/2),real(px(1)/2+1),real(px(3)),real(xs(ii))))
452!!$ IF (X(3)*(ZS(I)/100)**2 .LT. 0.98) THEN
453!!$ CALL HYPSER(X(2),X(1)/2,X(1)/2+1,-X(3)*(ZS(I)/100)**2,ZW2)
454!!$ print *, "args= ", X(2), X(1)/2, X(1)/2+1, -X(3)*(ZS(I)/100)**2, " hypser = ", ZW2
455!!$ CALL HYPSER(27.288,0.82/2,0.82/2+1,-38726*(0.5/100)**2,ZW2)
456!!$ print *, "args= ", 27.288, 0.82/2, 0.82/2+1, -38726*(0.5/100)**2, " hypser = ", ZW2
457!!$ END IF
458 ! print *, I, ZS(I), C, ZW, ZNCCN(I)
459 IF ( zw.GT.0. .AND. xnccn(ii).GT.0.) THEN
460 pfvec(ii) = log(zw) - log(xnccn(ii))
461 ELSE
462 pfvec(ii) = 0._mnhreal64
463 END IF
464 !FVEC(I) = LOG(MAX(ZW,1.E-24)) - LOG(MAX(ZNCCN(I),1.E-24))
465 !FVEC(I) = ZW - ZNCCN(I)
466 END DO
467 END IF
468! print *, "distance : ", SUM(FVEC*FVEC)
469!
470 IF (lhook) CALL dr_hook('DISTANCE', 1, zhook_handle)
471 END SUBROUTINE distance
472!
473!------------------------------------------------------------------------------
elemental real function gamma(px)
Definition gamma.h:14
real function gamma_inc(pa, px)
Definition gamma_inc.F90:6
real(kind=mnhreal64) function zriddr(px1, px2, pxacc, pddry, pkappa, pt)
type(cst_t), target, save cst
Definition modd_cst.F90:137
integer, parameter mnhreal64
subroutine, public lima_init_ccn_activation_spectrum(cst, htype_ccn, pd, psigma, plimit_factor, pk, pmu, pbeta, pkappa)