Skip to content

Commit ec6596a

Browse files
authored
Merge pull request #731 from slayoo/MAC
mass and heat accommodation coefficients alterable from within constants. closes #730
2 parents 533499d + 246a627 commit ec6596a

File tree

7 files changed

+67
-18
lines changed

7 files changed

+67
-18
lines changed

PySDM/backends/impl_numba/methods/condensation_methods.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ def calculate_ml_old(volume, multiplicity, cell_idx):
201201
@staticmethod
202202
def make_calculate_ml_new(
203203
jit_flags, dx_dt, volume_of_x, x, phys_r_dr_dt, phys_RH_eq, phys_sigma, radius,
204-
phys_lambdaK, phys_lambdaD, phys_DK, within_tolerance, max_iters, RH_rtol, const
204+
phys_lambdaK, phys_lambdaD, phys_dk_D, phys_dk_K, within_tolerance, max_iters, RH_rtol,
205+
const
205206
):
206207
@numba.njit(**jit_flags)
207208
def minfun(x_new, x_old, timestep, kappa, f_org, rd3, temperature, RH, lv, pvs, D, K):
@@ -238,8 +239,8 @@ def calculate_ml_new(
238239
sgm = phys_sigma(T, v[drop], vdry[drop], f_org[drop])
239240
RH_eq = phys_RH_eq(r_old, T, kappa[drop], rd3, sgm)
240241
if not within_tolerance(np.abs(RH - RH_eq), RH, RH_rtol):
241-
Dr = phys_DK(DTp, r_old, lambdaD)
242-
Kr = phys_DK(const.K0, r_old, lambdaK)
242+
Dr = phys_dk_D(DTp, r_old, lambdaD)
243+
Kr = phys_dk_K(const.K0, r_old, lambdaK)
243244
args = (x_old, timestep, kappa[drop], f_org[drop], rd3, T, RH, lv, pvs, Dr, Kr)
244245
r_dr_dt_old = phys_r_dr_dt(RH_eq, T, RH, lv, pvs, Dr, Kr)
245246
dx_old = timestep * dx_dt(x_old, r_dr_dt_old)
@@ -326,7 +327,8 @@ def make_condensation_solver(self,
326327
phys_dthd_dt=self.formulae.state_variable_triplet.dthd_dt,
327328
phys_lambdaK=self.formulae.diffusion_kinetics.lambdaK,
328329
phys_lambdaD=self.formulae.diffusion_kinetics.lambdaD,
329-
phys_DK=self.formulae.diffusion_kinetics.DK,
330+
phys_dk_D=self.formulae.diffusion_kinetics.D,
331+
phys_dk_K=self.formulae.diffusion_kinetics.K,
330332
phys_D=self.formulae.diffusion_thermics.D,
331333
within_tolerance=self.formulae.trivia.within_tolerance,
332334
dx_dt=self.formulae.condensation_coordinate.dx_dt,
@@ -346,16 +348,17 @@ def make_condensation_solver(self,
346348
@lru_cache()
347349
def make_condensation_solver_impl(
348350
fastmath, phys_pvs_C, phys_lv, phys_r_dr_dt, phys_RH_eq, phys_sigma, radius,
349-
phys_T, phys_p, phys_pv, phys_dthd_dt, phys_lambdaK, phys_lambdaD, phys_DK, phys_D,
350-
within_tolerance, dx_dt, volume, x, timestep, dt_range, adaptive,
351+
phys_T, phys_p, phys_pv, phys_dthd_dt, phys_lambdaK, phys_lambdaD, phys_dk_D, phys_dk_K,
352+
phys_D, within_tolerance, dx_dt, volume, x, timestep, dt_range, adaptive,
351353
fuse, multiplier, RH_rtol, max_iters, const
352354
):
353355
jit_flags = {**conf.JIT_FLAGS, **{'parallel': False, 'cache': False, 'fastmath': fastmath}}
354356

355357
calculate_ml_old = CondensationMethods.make_calculate_ml_old(jit_flags, const)
356358
calculate_ml_new = CondensationMethods.make_calculate_ml_new(
357359
jit_flags, dx_dt, volume, x, phys_r_dr_dt, phys_RH_eq, phys_sigma, radius,
358-
phys_lambdaK, phys_lambdaD, phys_DK, within_tolerance, max_iters, RH_rtol, const
360+
phys_lambdaK, phys_lambdaD, phys_dk_D, phys_dk_K, within_tolerance, max_iters, RH_rtol,
361+
const
359362
)
360363
step_impl = CondensationMethods.make_step_impl(
361364
jit_flags, phys_pvs_C, phys_lv, calculate_ml_old, calculate_ml_new,

PySDM/backends/impl_numba/test_helpers/bdf.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ def _make_solve(formulae):
7575
phys_dthd_dt = formulae.state_variable_triplet.dthd_dt
7676
phys_lambdaD = formulae.diffusion_kinetics.lambdaD
7777
phys_lambdaK = formulae.diffusion_kinetics.lambdaK
78-
phys_DK = formulae.diffusion_kinetics.DK
78+
phys_diff_kin_D = formulae.diffusion_kinetics.D
79+
phys_diff_kin_K = formulae.diffusion_kinetics.K
7980
phys_D = formulae.diffusion_thermics.D
8081

8182
@numba.njit(**{**JIT_FLAGS, **{'parallel': False}})
@@ -91,8 +92,8 @@ def _impl(dy_dt, x, T, p, n, RH, kappa, f_org, dry_volume, thd,
9192
for i, x_i in enumerate(x):
9293
v = volume(x_i)
9394
r = phys_radius(v)
94-
Dr = phys_DK(DTp, r, lambdaD)
95-
Kr = phys_DK(K0, r, lambdaK)
95+
Dr = phys_diff_kin_D(DTp, r, lambdaD)
96+
Kr = phys_diff_kin_K(K0, r, lambdaK)
9697
sgm = sigma(T, v, dry_volume[i], f_org[i])
9798
dy_dt[idx_x + i] = dx_dt(
9899
x_i,

PySDM/backends/impl_thrust_rtc/methods/condensation_methods.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ def args(arg):
109109
if ( ! {phys.trivia.within_tolerance.c_inline(
110110
return_type='bool', error_estimate="abs(_RH - RH_eq)", value="_RH", rtol="RH_rtol"
111111
)}) {{
112-
Dr = {phys.diffusion_kinetics.DK.c_inline(
113-
DK="_DTp", r="r_old", lmbd="_lambdaD"
112+
Dr = {phys.diffusion_kinetics.D.c_inline(
113+
D="_DTp", r="r_old", lmbd="_lambdaD"
114114
)};
115-
Kr = {phys.diffusion_kinetics.DK.c_inline(
116-
DK="const.K0", r="r_old", lmbd="_lambdaK"
115+
Kr = {phys.diffusion_kinetics.K.c_inline(
116+
K="const.K0", r="r_old", lmbd="_lambdaK"
117117
)};
118118
r_dr_dt_old = {phys.drop_growth.r_dr_dt.c_inline(
119119
RH_eq="RH_eq", T="_T", RH="_RH", lv="_lv", pvs="_pvs", D="Dr", K="Kr"

PySDM/physics/constants_defaults.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424

2525
K0 = 2.4e-2 * si.joules / si.metres / si.seconds / si.kelvins
2626

27+
# mass and heat accommodation coefficients
28+
MAC = 1.
29+
HAC = 1.
30+
2731
p1000 = 1000 * si.hectopascals
2832
c_pd = 1005 * si.joule / si.kilogram / si.kelvin
2933
c_pv = 1850 * si.joule / si.kilogram / si.kelvin

PySDM/physics/diffusion_kinetics/fuchs_sutugin.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,13 @@ def lambdaK(const, T, p):
1818
return (4. / 5) * const.K0 * T / p / np.sqrt(2 * const.Rd * T)
1919

2020
@staticmethod
21-
def DK(_, DK, r, lmbd):
22-
return DK * (1 + lmbd/r) / (1 + 1.71 * lmbd/r + 1.33 * lmbd/r * lmbd/r)
21+
def D(const, D, r, lmbd):
22+
return D * (1 + lmbd/r) / (
23+
1 + (4./3/const.MAC + 0.377) * lmbd/r + (4./3/const.MAC) * lmbd/r * lmbd/r
24+
)
25+
26+
@staticmethod
27+
def K(const, K, r, lmbd):
28+
return K * (1 + lmbd/r) / (
29+
1 + (4./3/const.HAC + 0.377) * lmbd/r + (4./3/const.HAC) * lmbd/r * lmbd/r
30+
)

PySDM/physics/diffusion_kinetics/neglect.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,9 @@ def lambdaK(_, T, p): # pylint: disable=unused-argument
1616
return -1
1717

1818
@staticmethod
19-
def DK(_, DK, r, lmbd): # pylint: disable=unused-argument
20-
return DK
19+
def D(_, D, r, lmbd): # pylint: disable=unused-argument
20+
return D
21+
22+
@staticmethod
23+
def K(_, K, r, lmbd): # pylint: disable=unused-argument
24+
return K
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring
2+
import pytest
3+
import numpy as np
4+
from PySDM import Formulae
5+
6+
@pytest.mark.parametrize("constants", (
7+
{"MAC": 1., "HAC": 1.},
8+
{"MAC": 1., "HAC": .1},
9+
{"MAC": .1, "HAC": 1.},
10+
{"MAC": .1, "HAC": .1},
11+
))
12+
def test_accomodation_coefficients(constants):
13+
# arrange
14+
formulae = Formulae(constants=constants)
15+
D = 1
16+
K = 2
17+
r = 3
18+
lmbd = 4
19+
20+
# act
21+
D_dk = formulae.diffusion_kinetics.D(D, r, lmbd)
22+
K_dk = formulae.diffusion_kinetics.K(K, r, lmbd)
23+
24+
# assert
25+
Kn = lmbd / r
26+
xx_D = 4 / 3 / constants['MAC']
27+
np.testing.assert_almost_equal(D_dk, D * (1 + Kn) / (1 + (xx_D + .377) * Kn + xx_D * Kn**2))
28+
xx_K = 4 / 3 / constants['HAC']
29+
np.testing.assert_almost_equal(K_dk, K * (1 + Kn) / (1 + (xx_K + .377) * Kn + xx_K * Kn**2))

0 commit comments

Comments
 (0)