|
| 1 | +import sys |
| 2 | +sys.path.insert(0, "../../bindings/python/") |
| 3 | + |
| 4 | +from numpy import array as arr_t # ndarray dtype default to float64, while array's is int64! |
| 5 | +from numpy import arange |
| 6 | +from numpy import frombuffer |
| 7 | +from math import exp, log, sqrt, pi |
| 8 | + |
| 9 | +from libcloudphxx import lgrngn |
| 10 | +from libcloudphxx import common |
| 11 | + |
| 12 | +def lognormal(lnr): |
| 13 | + mean_r = .04e-6 / 2 |
| 14 | + stdev = 1.4 |
| 15 | + n_tot = 60e6 |
| 16 | + return n_tot * exp( |
| 17 | + -pow((lnr - log(mean_r)), 2) / 2 / pow(log(stdev),2) |
| 18 | + ) / log(stdev) / sqrt(2*pi); |
| 19 | + |
| 20 | +opts = lgrngn.opts_t() |
| 21 | + |
| 22 | +opts_init = lgrngn.opts_init_t() |
| 23 | +opts_init.dry_distros = {.61:lognormal, 1.28:lognormal} |
| 24 | +opts_init.coal_switch = False |
| 25 | +opts_init.sedi_switch = False |
| 26 | +opts_init.RH_max = 0.999 # to comply with the assert(RH<1) at init |
| 27 | +opts_init.dt = 0.1 |
| 28 | +opts_init.sd_conc = int(1e2) |
| 29 | +opts_init.n_sd_max = opts_init.sd_conc |
| 30 | +opts_init.diag_incloud_time = True |
| 31 | + |
| 32 | +backend = lgrngn.backend_t.serial |
| 33 | + |
| 34 | +opts.adve = False |
| 35 | +opts.sedi = False |
| 36 | +opts.cond = True |
| 37 | +opts.coal = False |
| 38 | +opts.chem = False |
| 39 | + |
| 40 | +def supersaturation(prtcls): |
| 41 | + prtcls.diag_RH() |
| 42 | + return (frombuffer(prtcls.outbuf())[0] - 1) * 100 |
| 43 | + |
| 44 | +def temperature(prtcls): |
| 45 | + prtcls.diag_temperature() |
| 46 | + return frombuffer(prtcls.outbuf())[0] |
| 47 | + |
| 48 | +def pressure(prtcls): |
| 49 | + prtcls.diag_pressure() |
| 50 | + return frombuffer(prtcls.outbuf())[0] |
| 51 | + |
| 52 | +def diag_incloud_time(prtcls): |
| 53 | + prtcls.diag_incloud_time_mom(1) |
| 54 | + m1 = frombuffer(prtcls.outbuf())[0] |
| 55 | + prtcls.diag_incloud_time_mom(0) |
| 56 | + m0 = frombuffer(prtcls.outbuf())[0] |
| 57 | + return m1/m0 |
| 58 | + |
| 59 | +def initial_state(): |
| 60 | + rhod = arr_t([1. ]) |
| 61 | + th = arr_t([300.]) |
| 62 | + rv = arr_t([0.009 - 0.00005]) |
| 63 | + return rhod, th, rv |
| 64 | + |
| 65 | +rhod, th, rv = initial_state() |
| 66 | + |
| 67 | +prtcls = lgrngn.factory(backend, opts_init) |
| 68 | +prtcls.init(th, rv, rhod) |
| 69 | + |
| 70 | +#ss = supersaturation(prtcls) |
| 71 | +#print "initial supersaturation", ss |
| 72 | + |
| 73 | +# first step without condesnation just to see diag output |
| 74 | +opts.cond = True |
| 75 | +for step in arange(400): |
| 76 | + rv[0] += 0.00001 * opts_init.dt |
| 77 | + prtcls.sync_in(th, rv, rhod) |
| 78 | + |
| 79 | +# ss_post_add = supersaturation(prtcls) |
| 80 | +# print "supersaturation after increaseing rv", ss_post_add |
| 81 | + |
| 82 | + prtcls.step_cond(opts, th, rv) |
| 83 | + prtcls.step_async(opts) |
| 84 | + |
| 85 | +# ss_post_cond = supersaturation(prtcls) |
| 86 | +# print "supersaturation after condensation", ss_post_cond |
| 87 | + |
| 88 | +prtcls.diag_all() |
| 89 | +all_mean_incloud_time = diag_incloud_time(prtcls) |
| 90 | +print "all: mean incloud time:", all_mean_incloud_time |
| 91 | +prtcls.diag_dry_rng(0, 0.02e-6) |
| 92 | +rdlt2_mean_incloud_time = diag_incloud_time(prtcls) |
| 93 | +print "rd < 2um: mean incloud time:", rdlt2_mean_incloud_time |
| 94 | +prtcls.diag_dry_rng(0.02e-6, 1) |
| 95 | +rdgt2_mean_incloud_time = diag_incloud_time(prtcls) |
| 96 | +print "rd > 2um: mean incloud time:", rdgt2_mean_incloud_time |
| 97 | +prtcls.diag_dry_rng(0.02e-6, 1) |
| 98 | +prtcls.diag_kappa_rng_cons(1, 10) |
| 99 | +rdgt2_kpagt1_mean_incloud_time = diag_incloud_time(prtcls) |
| 100 | +print "rd > 2um and kappa > 1: mean incloud time:", rdgt2_kpagt1_mean_incloud_time |
| 101 | +prtcls.diag_dry_rng(0.02e-6, 1) |
| 102 | +prtcls.diag_kappa_rng_cons(0, 1) |
| 103 | +rdgt2_kpalt1_mean_incloud_time = diag_incloud_time(prtcls) |
| 104 | +print "rd > 2um and kappa < 1: mean incloud time:", rdgt2_kpalt1_mean_incloud_time |
| 105 | + |
| 106 | +assert(rdlt2_mean_incloud_time < all_mean_incloud_time) |
| 107 | +assert(all_mean_incloud_time < rdgt2_mean_incloud_time) |
| 108 | +assert(rdgt2_mean_incloud_time < rdgt2_kpagt1_mean_incloud_time) |
| 109 | +assert(rdgt2_kpalt1_mean_incloud_time < rdgt2_mean_incloud_time) |
| 110 | + |
0 commit comments