def initial_state(): rhod = arr_t([1.]) th = arr_t([300.]) rv = arr_t([0.02]) T = common.T(th[0], rhod[0]) p = arr_t([common.p(rhod[0], rv[0], T)]) return rhod, th, rv, p
def supersat_state(): rhod = arr_t([1. ]) th = arr_t([300.]) rv = arr_t([0.0091]) T = common.T(th[0], rhod[0]) p = arr_t([common.p(rhod[0], rv[0], T)]) return rhod, th, rv, p
def initial_state(): rhod = arr_t([1. ]) th = arr_t([300.]) rv = arr_t([0.02]) T = common.T(th[0], rhod[0]) p = arr_t([common.p(rhod[0], rv[0], T)]) return rhod, th, rv, p
def supersat_state(): rhod = arr_t([1.]) th = arr_t([300.]) rv = arr_t([0.0091]) T = common.T(th[0], rhod[0]) p = arr_t([common.p(rhod[0], rv[0], T)]) return rhod, th, rv, p
def initial_state(): # a little below saturation rhod = arr_t([1.1]) th = arr_t([305.]) rv = arr_t([0.0085]) T = common.T(th[0], rhod[0]) p = arr_t([common.p(rhod[0], rv[0], T)]) return rhod, th, rv, p
def initial_state(): # a little below saturation rhod = arr_t([1.1 ]) th = arr_t([305.]) rv = arr_t([0.0085]) T = common.T(th[0], rhod[0]) p = arr_t([common.p(rhod[0], rv[0], T)]) return rhod, th, rv, p
def __init__(self, outdir, dt): self.dt = dt self.outdir = outdir self.opts = blk_2m.opts_t() # TODO! # self.opts.dry_distros = [ # {"mean_rd":.04e-6 / 2, "sdev_rd":1.4, "N_stp":60e6, "chem_b":.55}, # {"mean_rd":.15e-6 / 2, "sdev_rd":1.6, "N_stp":40e6, "chem_b":.55} # ] self.rc = arr_t([0.]) self.nc = arr_t([0.]) self.rr = arr_t([0.]) self.nr = arr_t([0.])
def step(self, rhod, th_d, r_v, dot_th, dot_rv): dot_rc = arr_t([0.]) dot_nc = arr_t([0.]) dot_rr = arr_t([0.]) dot_nr = arr_t([0.]) blk_2m.rhs_cellwise(self.opts, dot_th, dot_rv, dot_rc, dot_nc, dot_rr, dot_nr, rhod, th_d, r_v, self.rc, self.nc, self.rr, self.nr, self.dt ); self.rc += dot_rc * self.dt self.nc += dot_nc * self.dt self.rr += dot_rr * self.dt self.nr += dot_nr * self.dt
def test_adj_cellwise_nwtrph(init_sup_sat, nwtrph_iters = nwtrph_iters_def): opts.nwtrph_iters = nwtrph_iters print "[nwtrph adj_cellwise]" rhod, th, rv, rc, rr, dt = initial_state(init_sup_sat) # define pressure consistent with adj_cellwise to compare results p = arr_t([common.p(rhod[0], rv[0], common.T(th[0], rhod[0]))]) #nwtrph requires th_std input th_std = arr_t([common.th_dry2std(th[0], rv[0])]) blk_1m.adj_cellwise_nwtrph(opts, p, th_std, rv, rc, dt) T = common.exner(p[0]) * th_std[0] ss = supersaturation(T, p[0], rv[0]) print "final supersaturation", ss, th_std[0], rv[0] return ss
def test_adj_cellwise_nwtrph(init_sup_sat, nwtrph_iters=nwtrph_iters_def): opts.nwtrph_iters = nwtrph_iters print("[nwtrph adj_cellwise]") rhod, th, rv, rc, rr, dt = initial_state(init_sup_sat) # define pressure consistent with adj_cellwise to compare results p = arr_t([common.p(rhod[0], rv[0], common.T(th[0], rhod[0]))]) #nwtrph requires th_std input th_std = arr_t([common.th_dry2std(th[0], rv[0])]) blk_1m.adj_cellwise_nwtrph(opts, p, th_std, rv, rc, dt) T = common.exner(p[0]) * th_std[0] ss = supersaturation(T, p[0], rv[0]) print("final supersaturation", ss, th_std[0], rv[0]) return ss
def test_adj_cellwise_constp(init_sup_sat, r_eps = r_eps_def): opts.r_eps = r_eps print "[constp adj_cellwise]" rhod, th, rv, rc, rr, dt = initial_state(init_sup_sat) # define pressure consistent with adj_cellwise to compare results p = arr_t([common.p(rhod[0], rv[0], common.T(th[0], rhod[0]))]) #constp requires th_std input th_std = arr_t([common.th_dry2std(th[0], rv[0])]) blk_1m.adj_cellwise_constp(opts, rhod, p, th_std, rv, rc, rr, dt) T = common.exner(p[0]) * th_std[0] ss = supersaturation(T, p[0], rv[0]) print "final supersaturation", ss, th_std[0], rv[0] return ss
def parcel(p_d, th_d, r_v, w, nt, outfreq, rhs): # perfect gas for for dry air def rhod_fun(p_d, th_d): def T(p_d, th_d): return th_d * pow(p_d / p_1000, R_d / c_pd) return p_d / R_d / T(p_d, th_d) # t=0 stuff rhod = rhod_fun(p_d, th_d) rhs.init(rhod, th_d, r_v) rhs.diag(rhod, th_d, r_v, 0) # placing a quick-look gnuplot file in the output directory import os, shutil shutil.copyfile(os.path.dirname(__file__) + '/quicklook.gpi', rhs.outdir + '/quicklook.gpi') # Euler-like integration for t in range(nt): #TODO: update process name :) # first, adjusting thr pressure using hydrostatic law p_d += rhs.dt * (-g * rhod * w) # computing rhs for th and rv dot_th = arr_t([0.]) dot_rv = arr_t([0.]) rhod = rhod_fun(p_d, th_d) rhs.step(rhod, th_d, r_v, dot_th, dot_rv) # applying the rhs th_d += rhs.dt * dot_th r_v += rhs.dt * dot_rv rhod = rhod_fun(p_d, th_d) # doing diagnostics / output if (t % outfreq == 0): rhs.diag(rhod, th_d, r_v, t * rhs.dt)
def initial_state(init_sup_sat): rhod = arr_t([1. ]) th = arr_t([300.]) if init_sup_sat: rv = arr_t([0.02]) else: rv = arr_t([0.002]) rc = arr_t([0.015]) rr = arr_t([0. ]) dt = 1 T = common.T(th[0], rhod[0]) p = common.p(rhod[0], rv[0], T) ss = supersaturation(T, p, rv[0]) print "initial supersaturation", ss return rhod, th, rv, rc, rr, dt
def initial_state(init_sup_sat): rhod = arr_t([1.]) th = arr_t([300.]) if init_sup_sat: rv = arr_t([0.02]) else: rv = arr_t([0.002]) rc = arr_t([0.015]) rr = arr_t([0.]) dt = 1 T = common.T(th[0], rhod[0]) p = common.p(rhod[0], rv[0], T) ss = supersaturation(T, p, rv[0]) print("initial supersaturation", ss) return rhod, th, rv, rc, rr, dt
def test(opts_init): opts_init.supstp_src = 50 opts_init.rng_seed = int(time()) opts_init.dt = 1 opts_init.nx = 2 opts_init.nz = 2 opts_init.dx = 1. opts_init.dz = 1. opts_init.x0 = 0. opts_init.z0 = 0. opts_init.x1 = opts_init.nx * opts_init.dx opts_init.z1 = opts_init.nz * opts_init.dz opts_init.src_z0 = 0 opts_init.src_z1 = opts_init.dz #create aerosol only in the lower cells opts_init.src_x0 = 0 opts_init.src_x1 = opts_init.dx * opts_init.nx opts_init.chem_switch = 0 opts_init.coal_switch = 0 opts_init.adve_switch = 0 opts_init.cond_switch = 0 opts_init.sedi_switch = 0 opts = lgrngn.opts_t() opts.adve = 0 opts.chem = 0 opts.sedi = 0 opts.coal = 0 opts.cond = 0 rhod = arr_t([[1., 1.], [1., 1.]]) th = arr_t([[300., 300.], [300., 300.]]) rv = arr_t([[.01, .01], [.01, .01]]) try: prtcls = lgrngn.factory(lgrngn.backend_t.OpenMP, opts_init) except: prtcls = lgrngn.factory(lgrngn.backend_t.serial, opts_init) prtcls.init(th, rv, rhod) # 100 steps during which number of droplets should be doubled in two calls to src opts.src = 1 for i in range(100): prtcls.step_sync(opts, th, rv, rhod) prtcls.step_async(opts) prtcls.diag_all() prtcls.diag_sd_conc() sd_conc = frombuffer(prtcls.outbuf()).copy() prtcls.diag_all() prtcls.diag_wet_mom(0) wet_mom0 = frombuffer(prtcls.outbuf()).copy() prtcls.diag_all() prtcls.diag_wet_mom(1) wet_mom1 = frombuffer(prtcls.outbuf()).copy() return sd_conc, wet_mom0, wet_mom1
opts.chem_gas = { lgrngn.chem_species_t.SO2 : 44, lgrngn.chem_species_t.O3 : 44, lgrngn.chem_species_t.H2O2 : 44 } print("chem_gas[SO2] = ", opts.chem_gas[lgrngn.chem_species_t.SO2]) print("chem_gas = ", opts.chem_gas) # --------- test runs ----------- # ---------- # 0D (parcel) print("0D") opts_init.sedi_switch = False rhod = arr_t([ 1.]) th = arr_t([300.]) rv = arr_t([ 0.01]) prtcls = lgrngn.factory(backend, opts_init) prtcls.init(th, rv, rhod) try: prtcls.init(th, rv, rhod) raise Exception("multiple init call not reported!") except: pass prtcls.step_sync(opts, th, rv, rhod) try: prtcls.step_sync(opts, th, rv, rhod) raise Exception("sync/async order mismatch not reported!") except:
from numpy import array as arr_t # ndarray dtype default to float64, while array's is int64! from libcloudphxx import blk_1m opts = blk_1m.opts_t() print "cond =", opts.cond print "cevp =", opts.cevp print "revp =", opts.revp print "conv =", opts.conv print "accr =", opts.accr print "sedi =", opts.sedi print "r_c0 =", opts.r_c0 print "r_eps =", opts.r_eps rhod = arr_t([1.]) p = arr_t([1.e5]) th = arr_t([300.]) rv = arr_t([0.]) rc = arr_t([0.01]) rr = arr_t([0.]) dt = 1 dz = 1 # sat adjustment with variable pressure th_old = th.copy() rv_old = rv.copy() rc_old = rc.copy() rr_old = rr.copy() blk_1m.adj_cellwise(opts, rhod, th, rv, rc, rr, dt) assert th != th_old # some water should have evaporated
from parcel import parcel from rhs_blk_2m import rhs_blk_2m from rhs_lgrngn import rhs_lgrngn from libcloudphxx.common import th_std2dry, th_dry2std from libcloudphxx.common import p_vs from libcloudphxx.common import eps, p_1000, R_d, c_pd from libcloudphxx.lgrngn import chem_species_t from numpy import array as arr_t from math import exp, log, sqrt, pi # initial parameters T = arr_t([282.2]) p = arr_t([95000.]) p_v = arr_t([0.95 * p_vs(T[0])]) p_d = p - p_v r_v = eps * p_v / p_d #th_d = arr_t([th_std2dry(300., r_v[0])]) th_d = T * pow(p_1000 / p_d[0], R_d / c_pd) w = 0.5 dt = .1 nt = int(600 / w / dt) # 600 metres # blk_2m-specific parameter # TODO: spectrum # lgrngn-specific parameters sd_conc = 44
def test(opts_init): opts_init.supstp_rlx = 2 opts_init.rng_seed = int(time()) opts_init.dt = 1 opts_init.nx = 2; opts_init.nz = 2; opts_init.dx=1.; opts_init.dz=1.; opts_init.x0=0.; opts_init.z0=0.; opts_init.x1=opts_init.nx * opts_init.dx; opts_init.z1=opts_init.nz * opts_init.dz; opts_init.aerosol_independent_of_rhod=1; opts_init.y0=0.; opts_init.y1=1.; opts_init.chem_switch = 0; opts_init.coal_switch = 0; opts_init.adve_switch = 0; opts_init.cond_switch = 0; opts_init.sedi_switch = 0; opts_init.rlx_switch = 1; opts = lgrngn.opts_t() opts.adve = 0; opts.chem = 0; opts.sedi = 0; opts.coal = 0; opts.cond = 0; rhod = arr_t([[ 1., 1. ],[ 1., 1. ]]) th = arr_t([[300., 300. ],[ 300., 300. ]]) rv = arr_t([[ .01, .01],[ .01, .01]]) try: prtcls = lgrngn.factory(lgrngn.backend_t.OpenMP, opts_init) except: prtcls = lgrngn.factory(lgrngn.backend_t.serial, opts_init) prtcls.init(th, rv, rhod) # 2 steps during which relaxation should be done once opts.rlx = 1 for i in range(2): prtcls.step_sync(opts,th,rv,rhod) prtcls.step_async(opts) prtcls.diag_all() prtcls.diag_sd_conc() sd_conc = frombuffer(prtcls.outbuf()).copy() prtcls.diag_all() prtcls.diag_wet_mom(0) wet_mom0 = frombuffer(prtcls.outbuf()).copy() prtcls.diag_all() prtcls.diag_wet_mom(1) wet_mom1 = frombuffer(prtcls.outbuf()).copy() return sd_conc, wet_mom0, wet_mom1
print "sedi =", opts.sedi print "RH_max =", opts.RH_max opts.dry_distros = [{ "mean_rd": .04e-6 / 2, "sdev_rd": 1.4, "N_stp": 60e6, "chem_b": .55 }, { "mean_rd": .15e-6 / 2, "sdev_rd": 1.6, "N_stp": 40e6, "chem_b": .55 }] rhod = arr_t([1.]) th = arr_t([300.]) rv = arr_t([0.]) rc = arr_t([0.01]) nc = arr_t([1e-3]) rr = arr_t([0.]) nr = arr_t([0.]) dt = 1 dot_th = arr_t([0.]) dot_rv = arr_t([0.]) dot_rc = arr_t([0.]) dot_nc = arr_t([0.]) dot_rr = arr_t([0.]) dot_nr = arr_t([0.])
print "sedi =", opts.sedi print "cond =", opts.cond print "coal =", opts.coal print "chem =", opts.chem print "RH_max =", opts.RH_max opts.chem_gas = { lgrngn.chem_species_t.SO2 : 44, lgrngn.chem_species_t.O3 : 44, lgrngn.chem_species_t.H2O2 : 44 } print "chem_gas[SO2] = ", opts.chem_gas[lgrngn.chem_species_t.SO2] print "chem_gas = ", opts.chem_gas # 0D (parcel) rhod = arr_t([ 1.]) th = arr_t([300.]) rv = arr_t([ 0.01]) prtcls = lgrngn.factory(backend, opts_init) prtcls.init(th, rv, rhod) prtcls.step_sync(opts, th, rv, rhod) rain = prtcls.step_async(opts) prtcls.diag_dry_rng(0.,1.) prtcls.diag_wet_rng(0.,1.) prtcls.diag_dry_mom(1) prtcls.diag_wet_mom(1) prtcls.diag_all() #prtcls.diag_chem(lgrngn.chem_species_t.OH) prtcls.diag_sd_conc() assert frombuffer(prtcls.outbuf()) == opts_init.sd_conc_mean # parcel set-up
opts_init.dry_distros = {kappa1:lognormal, kappa2:lognormal} opts_init.kernel = lgrngn.kernel_t.geometric opts_init.terminal_velocity = lgrngn.vt_t.beard76 opts_init.dt = 1 opts_init.sd_conc = 64 opts_init.n_sd_max = 512 opts_init.rng_seed = 396 opts_init.src_sd_conc = 64 opts_init.src_z1 = opts_init.dz backend = lgrngn.backend_t.serial opts = lgrngn.opts_t() # 0D rhod = arr_t([ 1.]) th = arr_t([300.]) rv = arr_t([ 0.01]) prtcls = lgrngn.factory(backend, opts_init) prtcls.init(th, rv, rhod) check_kappa_conc(prtcls, 2e-2) # 3D opts_init.ny = 2 opts_init.dy = 10 opts_init.y1 = opts_init.ny * opts_init.dy opts_init.nx = 2 opts_init.dx = 10
print "RH_max =", opts.RH_max opts.chem_gas = { lgrngn.chem_species_t.SO2: 44, lgrngn.chem_species_t.O3: 44, lgrngn.chem_species_t.H2O2: 44 } print "chem_gas[SO2] = ", opts.chem_gas[lgrngn.chem_species_t.SO2] print "chem_gas = ", opts.chem_gas # --------- test runs ----------- # ---------- # 0D (parcel) print "0D" rhod = arr_t([1.]) th = arr_t([300.]) rv = arr_t([0.01]) prtcls = lgrngn.factory(backend, opts_init) prtcls.init(th, rv, rhod) try: prtcls.init(th, rv, rhod) raise Exception("multiple init call not reported!") except: pass prtcls.step_sync(opts, th, rv, rhod) try: prtcls.step_sync(opts, th, rv, rhod) raise Exception("sync/async order mismatch not reported!") except:
opts_init.chem_switch = 0 opts_init.coal_switch = 0 opts_init.adve_switch = 0 opts_init.cond_switch = 0 opts_init.sedi_switch = 0 opts_init.src_switch = 1 opts = lgrngn.opts_t() opts.adve = 0 opts.chem = 0 opts.sedi = 0 opts.coal = 0 opts.cond = 0 rhod = arr_t([[1., 1.], [1., 1.]]) th = arr_t([[300., 300.], [300., 300.]]) rv = arr_t([[.01, .01], [.01, .01]]) try: prtcls = lgrngn.factory(lgrngn.backend_t.OpenMP, opts_init) except: prtcls = lgrngn.factory(lgrngn.backend_t.serial, opts_init) prtcls.init(th, rv, rhod) # 100 steps during which number of droplets should be doubled in two calls to src opts.src = 1 for i in range(100): prtcls.step_sync(opts, th, rv, rhod) prtcls.step_async(opts)
from numpy import array as arr_t # ndarray dtype default to float64, while array's is int64! from libcloudphxx import blk_1m opts = blk_1m.opts_t() print "cond =", opts.cond print "cevp =", opts.cevp print "revp =", opts.revp print "conv =", opts.conv print "accr =", opts.accr print "sedi =", opts.sedi print "r_c0 =", opts.r_c0 print "r_eps =", opts.r_eps rhod = arr_t([1. ]) p = arr_t([1.e5]) th = arr_t([300.]) rv = arr_t([0. ]) rc = arr_t([0.01]) rr = arr_t([0. ]) dt = 1 dz = 1 # sat adjustment with variable pressure th_old = th.copy() rv_old = rv.copy() rc_old = rc.copy() rr_old = rr.copy() blk_1m.adj_cellwise(opts, rhod, th, rv, rc, rr, dt) assert th != th_old # some water should have evaporated
opts_init.dt = 1 opts_init.sd_conc = 64 opts_init.n_sd_max = 512 opts_init.rng_seed = 396 opts_init.exact_sstp_cond = True # test would fail with per-cell sstp logic spinup = 20 backend = lgrngn.backend_t.serial opts = lgrngn.opts_t() opts.sedi=0 opts.coal=0 opts.cond=1 # 1D (periodic horizontal domain) rhod = arr_t([ 1., 1.]) C = arr_t([ 1., 1., 1.]) opts_init.nx = 2 opts_init.dx = 1 opts_init.x1 = opts_init.nx * opts_init.dx for sstp_cond in [1,2,5]: print 'sstp_cond = ' + str(sstp_cond) opts.adve=0 opts_init.sstp_cond = sstp_cond prtcls = lgrngn.factory(backend, opts_init) th = arr_t([300., 300.]) rv = arr_t([ .0025, .0095]) # first cell subsaturated, second cell supersaturated prtcls.init(th, rv, rhod, Cx=C)
opts = blk_2m.opts_t() print "acti =", opts.acti print "cond =", opts.cond print "acnv =", opts.acnv print "accr =", opts.accr print "sedi =", opts.sedi print "RH_max =", opts.RH_max opts.dry_distros = [ {"mean_rd":.04e-6 / 2, "sdev_rd":1.4, "N_stp":60e6, "chem_b":.55}, {"mean_rd":.15e-6 / 2, "sdev_rd":1.6, "N_stp":40e6, "chem_b":.55} ] rhod = arr_t([1. ]) th = arr_t([300.]) rv = arr_t([0. ]) rc = arr_t([0.01]) nc = arr_t([1e-3]) rr = arr_t([0. ]) nr = arr_t([0. ]) dt = 1 dot_th = arr_t([0.]) dot_rv = arr_t([0.]) dot_rc = arr_t([0.]) dot_nc = arr_t([0.]) dot_rr = arr_t([0.]) dot_nr = arr_t([0.])
prsr_lgr.add_argument('--kappa', type=float, required=True, help='aerosol hygroscopicity parameter [1]') prsr_lgr.add_argument('--n_tot', type=float, required=True, help='aerosol concentration @STP [m-3]') prsr_lgr.add_argument('--meanr', type=float, required=True, help='aerosol mean dry radius [m]') prsr_lgr.add_argument('--gstdv', type=float, required=True, help='aerosol geometric standard deviation [1]') prsr_lgr.add_argument('--chem_SO2', type=float, default=0, help='SO2 volume concentration [1]') prsr_lgr.add_argument('--chem_O3', type=float, default=0, help='O3 volume concentration [1]') prsr_lgr.add_argument('--chem_H2O2', type=float, default=0, help='H2O2 volume concentration [1]') ## blk_2m options prsr_b2m = sprsr.add_parser('blk_2m') #TODO... args = prsr.parse_args() # computing state variables p_v = arr_t([args.RH * p_vs(args.T)]) p_d = args.p - p_v r_v = eps * p_v / p_d th_d = args.T * pow(p_1000 / p_d, R_d / c_pd) class lognormal: def __init__(self, n_tot, meanr, gstdv): self.meanr = meanr self.stdev = gstdv self.n_tot = n_tot def __call__(self, lnr): return self.n_tot * exp( -pow((lnr - log(self.meanr)), 2) / 2 / pow(log(self.stdev),2) ) / log(self.stdev) / sqrt(2*pi);
opts_init.chem_switch = 0; opts_init.coal_switch = 0; opts_init.adve_switch = 0; opts_init.cond_switch = 0; opts_init.sedi_switch = 0; opts_init.src_switch = 1; opts = lgrngn.opts_t() opts.adve = 0; opts.chem = 0; opts.sedi = 0; opts.coal = 0; opts.cond = 0; rhod = arr_t([[ 1., 1. ],[ 1., 1. ]]) th = arr_t([[300., 300. ],[ 300., 300. ]]) rv = arr_t([[ .01, .01],[ .01, .01]]) try: prtcls = lgrngn.factory(lgrngn.backend_t.OpenMP, opts_init) except: prtcls = lgrngn.factory(lgrngn.backend_t.serial, opts_init) prtcls.init(th, rv, rhod) # 100 steps during which number of droplets should be doubled in two calls to src opts.src = 1 for i in range(100): prtcls.step_sync(opts,th,rv,rhod) prtcls.step_async(opts)
def initial_state(): rhod = arr_t([1.]) th = arr_t([300.]) rv = arr_t([0.009 - 0.00005]) return rhod, th, rv
opts_init.dt = 1 opts_init.sd_conc = 64 opts_init.n_sd_max = 512 opts_init.rng_seed = 396 opts_init.exact_sstp_cond = True # test would fail with per-cell sstp logic spinup = 20 backend = lgrngn.backend_t.serial opts = lgrngn.opts_t() opts.sedi = 0 opts.coal = 0 opts.cond = 1 # 1D (periodic horizontal domain) rhod = arr_t([1., 1.]) C = arr_t([1., 1., 1.]) opts_init.nx = 2 opts_init.dx = 1 opts_init.x1 = opts_init.nx * opts_init.dx for sstp_cond in [1, 2, 5]: print 'sstp_cond = ' + str(sstp_cond) opts.adve = 0 opts_init.sstp_cond = sstp_cond prtcls = lgrngn.factory(backend, opts_init) th = arr_t([300., 300.]) rv = arr_t([.0025, .0095]) # first cell subsaturated, second cell supersaturated prtcls.init(th, rv, rhod, C)
print "chem_dsl =", opts.chem_dsl print "chem_dcs =", opts.chem_dsc print "chem_rct =", opts.chem_rct print "RH_max =", opts.RH_max opts.chem_gas = { lgrngn.chem_species_t.SO2 : 44, lgrngn.chem_species_t.O3 : 44, lgrngn.chem_species_t.H2O2 : 44 } print "chem_gas[SO2] = ", opts.chem_gas[lgrngn.chem_species_t.SO2] print "chem_gas = ", opts.chem_gas # 0D (parcel) print "0D" rhod = arr_t([ 1.]) th = arr_t([300.]) rv = arr_t([ 0.01]) prtcls = lgrngn.factory(backend, opts_init) prtcls.init(th, rv, rhod) try: prtcls.init(th, rv, rhod) raise Exception("multiple init call not reported!") except: pass prtcls.step_sync(opts, th, rv, rhod) try: prtcls.step_sync(opts, th, rv, rhod) raise Exception("sync/async order mismatch not reported!") except:
from parcel import parcel from rhs_blk_2m import rhs_blk_2m from rhs_lgrngn import rhs_lgrngn from libcloudphxx.common import th_std2dry, th_dry2std from libcloudphxx.common import p_vs from libcloudphxx.common import eps, p_1000, R_d, c_pd from libcloudphxx.lgrngn import chem_species_t from numpy import array as arr_t from math import exp, log, sqrt, pi # initial parameters T = arr_t([282.2]) p = arr_t([95000.]) p_v = arr_t([0.95 * p_vs(T[0])]) p_d = p - p_v r_v = eps * p_v / p_d #th_d = arr_t([th_std2dry(300., r_v[0])]) th_d = T * pow(p_1000 / p_d[0], R_d / c_pd) w = 0.5 dt = .1 nt = int(600 / w / dt) # 600 metres # blk_2m-specific parameter # TODO: spectrum # lgrngn-specific parameters sd_conc = 44 def lognormal(lnr):