Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
085cddc
Add the option to remove a dynamic from builder
Oct 14, 2022
a98709f
Merge branch 'main' of github.com:atmos-cloud-sim-uj/PySDM
slayoo Oct 23, 2022
c42cec1
Merge branch 'main' of github.com:atmos-cloud-sim-uj/PySDM
slayoo Oct 23, 2022
21dff10
Merge branch 'main' of github.com:atmos-cloud-sim-uj/PySDM
slayoo Oct 23, 2022
1a6d335
Merge branch 'main' of github.com:atmos-cloud-sim-uj/PySDM
slayoo Oct 24, 2022
c854c33
Merge branch 'main' of github.com:atmos-cloud-sim-uj/PySDM
slayoo Oct 26, 2022
a1739de
Merge branch 'main' of github.com:atmos-cloud-sim-uj/PySDM
slayoo Oct 28, 2022
493901c
Merge branch 'main' of https://github.com/atmos-cloud-sim-uj/PySDM
Oct 31, 2022
08d1c17
Merge branch 'main' of github.com:atmos-cloud-sim-uj/PySDM
slayoo Nov 1, 2022
3757896
Merge branch 'main' of github.com:atmos-cloud-sim-uj/PySDM
slayoo Nov 2, 2022
36e69a1
Merge branch 'main' of github.com:atmos-cloud-sim-uj/PySDM
slayoo Nov 4, 2022
a983200
Merge branch 'main' of github.com:atmos-cloud-sim-uj/PySDM
slayoo Nov 4, 2022
0ea6b78
Merge branch 'main' of github.com:atmos-cloud-sim-uj/PySDM
slayoo Nov 4, 2022
5973b25
Merge branch 'main' of https://github.com/atmos-cloud-sim-uj/PySDM
Nov 8, 2022
264497d
Merge branch 'main' of github.com:atmos-cloud-sim-uj/PySDM
slayoo Dec 8, 2022
fded80b
Merge branch 'main' of github.com:atmos-cloud-sim-uj/PySDM
slayoo Dec 16, 2022
6e74287
Merge branch 'main' of github.com:atmos-cloud-sim-uj/PySDM
slayoo Jan 14, 2023
9ddb0d9
Merge branch 'main' of github.com:atmos-cloud-sim-uj/PySDM
slayoo Feb 6, 2023
94aad02
Merge branch 'main' of https://github.com/atmos-cloud-sim-uj/PySDM
Feb 8, 2023
81eb1d4
Revisions to JOSS v2 paper
Feb 9, 2023
75a33cf
updated references in JOSS v2 paper
slayoo Feb 9, 2023
4bbb108
grant number, mention of PyPartMC, remove melting, OB contribs, break…
slayoo Feb 9, 2023
aa2e76a
fix PyPartMC_AMS ref
slayoo Feb 9, 2023
1c3abff
Merge branch 'main' of github.com:atmos-cloud-sim-uj/PySDM
slayoo Feb 9, 2023
5eee349
make math usable within Formulae (test to be added)
slayoo Feb 9, 2023
4db1add
Merge branch 'slayoo-patch-37' of https://github.com/atmos-cloud-sim-…
Feb 9, 2023
bedaf6f
make math available in cpp2python
slayoo Feb 9, 2023
0875848
Update collisions_methods.py
abulenok Feb 10, 2023
6ea71e4
Merge branch 'abulenok-patch-1' of https://github.com/open-atmos/PySD…
Feb 10, 2023
8f179e4
Merge branch 'slayoo-patch-37' of https://github.com/open-atmos/PySDM…
Feb 10, 2023
f4372bc
Switch from tanh to erf in gaussian CDF
Feb 10, 2023
8c1611f
Rename breakup subfunctions in CPU backend
Feb 10, 2023
48ba0d3
reassign attributes[a,j] in case of new_nj == 0 (breakup1)
Feb 10, 2023
0341a07
Remove redundant checks, add logic comments, clean up breakup CPU bac…
Feb 10, 2023
d9fc399
Add Ben's Scripps affiliation
Feb 10, 2023
208bc45
Merge branch 'main' of https://github.com/open-atmos/PySDM into ej/br…
Feb 13, 2023
9989efe
Linting
Feb 13, 2023
7195765
Merge branch 'main' of github.com:atmos-cloud-sim-uj/PySDM
slayoo Feb 14, 2023
f902547
Merge branch 'ej/breakup_issues' of github.com:edejong-caltech/PySDM …
slayoo Feb 14, 2023
6f622e7
removing spurious bib entry
slayoo Feb 14, 2023
5937fe7
rename codecov workflow to highlight that it uses nojit
slayoo Feb 14, 2023
969bcb3
Merge branch 'main' of https://github.com/open-atmos/PySDM into ej/br…
Feb 14, 2023
fa9e5da
Revisions to JOSS v2 paper
Feb 9, 2023
fd0f63a
make math usable within Formulae (test to be added)
slayoo Feb 9, 2023
3ef73af
make math available in cpp2python
slayoo Feb 9, 2023
71a7d4d
Switch from tanh to erf in gaussian CDF
Feb 10, 2023
bf98184
Rename breakup subfunctions in CPU backend
Feb 10, 2023
f631f4a
reassign attributes[a,j] in case of new_nj == 0 (breakup1)
Feb 10, 2023
97b8ac7
Remove redundant checks, add logic comments, clean up breakup CPU bac…
Feb 10, 2023
a152424
Linting
Feb 13, 2023
49fb978
removing spurious bib entry
slayoo Feb 14, 2023
7925a9e
rename codecov workflow to highlight that it uses nojit
slayoo Feb 14, 2023
74e9ad8
Merge branch 'main' of https://github.com/open-atmos/PySDM into ej/br…
Feb 19, 2023
3b0ec3b
Merge branch 'ej/breakup_issues' of https://github.com/edejong-caltec…
Feb 19, 2023
e0c43cd
Remove old docstring
Feb 19, 2023
7ceb588
WIP on LL82 fragmenttion fucntion
Feb 21, 2023
07c90b0
include math pkg name replacement in formula c_inline
slayoo Feb 21, 2023
cb56394
sorting out CUDA problem with log(int)
slayoo Feb 21, 2023
2067f36
make Straub formulae CUDA-compatible
slayoo Feb 21, 2023
db98cd1
pre-commit cleanup
slayoo Feb 21, 2023
2bc2ce4
fix erf support in FakeThrust
slayoo Feb 21, 2023
febbb30
WIP on LL82 fragmentation function
Feb 22, 2023
33c96f8
Attempt at CDF sampling for ll82
Feb 22, 2023
d8fffc0
WIP on testing ll82
Feb 27, 2023
2bc8874
Merge branch 'main' of https://github.com/open-atmos/PySDM
Feb 27, 2023
46cc1d8
Merge branch 'ej/breakup_issues' of https://github.com/edejong-caltec…
Feb 27, 2023
dd20975
WIP to satisfy numba's needs
Feb 28, 2023
6ae2a9c
Some fixes to LL82
Mar 1, 2023
60dd8ea
Testing & debugging
Mar 2, 2023
58b7723
Adding limiting cases to LL82
Mar 3, 2023
0f6afc9
Update fragmentation unit tests
Mar 3, 2023
9866cec
Implement LL82 coalescence efficiency
Mar 3, 2023
db532e9
Final fixes on LL82 efficiency
Mar 7, 2023
9358a10
Merge branch 'main' of https://github.com/open-atmos/PySDM into ej/ll82
Mar 7, 2023
1a8dee7
Merge branch 'main' of https://github.com/open-atmos/PySDM
Mar 7, 2023
9f69935
Merge branch 'ej/ll82' of https://github.com/edejong-caltech/PySDM in…
Mar 7, 2023
1763590
Fixes to MP distribution
Mar 7, 2023
645862e
remove MP separate file
Mar 8, 2023
bace062
Fixing issues with LL82
Mar 8, 2023
583538d
Add'l limiters in LL82
Mar 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
pre-commit autoupdate
pre-commit run --all-files

codecov:
nojit_and_codecov:
runs-on: ubuntu-latest
env:
NUMBA_DISABLE_JIT: 1
Expand Down Expand Up @@ -106,7 +106,7 @@ jobs:
prop_path: 'creators'

build:
needs: [pylint, pdoc, codecov, precommit, zenodo_json]
needs: [pylint, pdoc, nojit_and_codecov, precommit, zenodo_json]
strategy:
matrix:
platform: [ubuntu-latest, macos-12, windows-latest]
Expand Down
237 changes: 215 additions & 22 deletions PySDM/backends/impl_numba/methods/collisions_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def coalesce( # pylint: disable=too-many-arguments


@numba.njit(**{**conf.JIT_FLAGS, **{"parallel": False}})
def breakup_fun0(
def breakup0_compute_mult_transfer(
gamma, j, k, multiplicity, volume, nfi, fragment_size_i, max_multiplicity
): # pylint: disable=too-many-arguments
overflow_flag = False
Expand All @@ -78,7 +78,7 @@ def breakup_fun0(
overflow_flag = True
break

# check for new_n > 0
# check for new_n >= 0
if take_from_j_test > multiplicity[j]:
break

Expand All @@ -89,7 +89,7 @@ def breakup_fun0(


@numba.njit(**{**conf.JIT_FLAGS, **{"parallel": False}})
def breakup_fun1(
def breakup1_update_mult_attributes(
j, k, attributes, multiplicity, take_from_j, new_mult_k
): # pylint: disable=too-many-arguments
for a in range(len(attributes)):
Expand All @@ -100,20 +100,23 @@ def breakup_fun1(
if multiplicity[j] == take_from_j:
nj = new_mult_k / 2
nk = nj
else:
for a in range(len(attributes)):
attributes[a, j] = attributes[a, k]
else: # take_from_j < multiplicity[j]
nj = multiplicity[j] - take_from_j
nk = new_mult_k
return nj, nk


@numba.njit(**{**conf.JIT_FLAGS, **{"parallel": False}})
def breakup_fun2(
j, k, nj, nk, attributes, multiplicity, take_from_j
def breakup2_round_mults_to_ints(
j,
k,
nj,
nk,
attributes,
multiplicity,
): # pylint: disable=too-many-arguments
if multiplicity[j] <= take_from_j:
for a in range(len(attributes)):
attributes[a, j] = attributes[a, k]

multiplicity[j] = max(round(nj), 1)
multiplicity[k] = max(round(nk), 1)
factor_j = nj / multiplicity[j]
Expand All @@ -139,8 +142,8 @@ def break_up( # pylint: disable=too-many-arguments,c,too-many-locals
breakup_rate_deficit,
warn_overflows,
volume,
):
take_from_j, new_mult_k, gamma_j_k, overflow_flag = breakup_fun0(
): # breakup0 guarantees take_from_j <= multiplicity[j]
take_from_j, new_mult_k, gamma_j_k, overflow_flag = breakup0_compute_mult_transfer(
gamma[i],
j,
k,
Expand All @@ -152,17 +155,16 @@ def break_up( # pylint: disable=too-many-arguments,c,too-many-locals
)
gamma_deficit = gamma[i] - gamma_j_k

nj, nk = breakup_fun1(j, k, attributes, multiplicity, take_from_j, new_mult_k)

if multiplicity[j] <= take_from_j and round(nj) == 0:
atomic_add(breakup_rate_deficit, cid, gamma[i] * multiplicity[k])
return
# breakup1 also handles new_n[j] == 0 case via splitting
nj, nk = breakup1_update_mult_attributes(
j, k, attributes, multiplicity, take_from_j, new_mult_k
)

atomic_add(breakup_rate, cid, gamma_j_k * multiplicity[k])
atomic_add(breakup_rate_deficit, cid, gamma_deficit * multiplicity[k])

breakup_fun2(j, k, nj, nk, attributes, multiplicity, take_from_j)

# breakup2 also guarantees that no multiplicities are set to 0
breakup2_round_mults_to_ints(j, k, nj, nk, attributes, multiplicity)
if overflow_flag and warn_overflows:
warn("overflow", __file__)

Expand Down Expand Up @@ -201,7 +203,12 @@ def break_up_while(
else:
if multiplicity[k] > multiplicity[j]:
j, k = k, j
take_from_j, new_mult_k, gamma_j_k, overflow_flag = breakup_fun0(
(
take_from_j,
new_mult_k,
gamma_j_k,
overflow_flag,
) = breakup0_compute_mult_transfer(
gamma_deficit,
j,
k,
Expand All @@ -212,15 +219,17 @@ def break_up_while(
max_multiplicity,
)

nj, nk = breakup_fun1(j, k, attributes, multiplicity, take_from_j, new_mult_k)
nj, nk = breakup1_update_mult_attributes(
j, k, attributes, multiplicity, take_from_j, new_mult_k
)

if multiplicity[j] <= take_from_j and round(nj) == 0:
atomic_add(breakup_rate_deficit, cid, gamma[i] * multiplicity[k])
return

atomic_add(breakup_rate, cid, gamma_j_k * multiplicity[k])
gamma_deficit -= gamma_j_k
breakup_fun2(j, k, nj, nk, attributes, multiplicity, take_from_j)
breakup2_round_mults_to_ints(j, k, nj, nk, attributes, multiplicity)

atomic_add(breakup_rate_deficit, cid, gamma_deficit * multiplicity[k])

Expand Down Expand Up @@ -251,6 +260,30 @@ def straub_Nr( # pylint: disable=too-many-arguments,unused-argument
Nrt[i] = Nr1[i] + Nr2[i] + Nr3[i] + Nr4[i]


@numba.njit(**{**conf.JIT_FLAGS, **{"parallel": False}})
def ll82_Nr( # pylint: disable=too-many-arguments,unused-argument
i,
Rf,
Rs,
Rd,
CKE,
W,
W2,
): # pylint: disable=too-many-branches`
if CKE[i] >= 0.893e-6:
Rf[i] = 1.11e-4 * CKE[i] ** (-0.654)
else:
Rf[i] = 1.0
if W[i] >= 0.86:
Rs[i] = 0.685 * (1 - np.exp(-1.63 * (W2[i] - 0.86)))
else:
Rs[i] = 0.0
if (Rs[i] + Rf[i]) > 1.0:
Rd[i] = 0.0
else:
Rd[i] = 1.0 - Rs[i] - Rf[i]


class CollisionsMethods(BackendMethods):
def __init__(self):
BackendMethods.__init__(self)
Expand Down Expand Up @@ -321,6 +354,14 @@ def __collision_coalescence_breakup_body(

self.__collision_coalescence_breakup_body = __collision_coalescence_breakup_body

@numba.njit(**{**conf.JIT_FLAGS, "fastmath": self.formulae.fastmath})
def __ll82_coalescence_check_body(*, Ec, ds, dl):
for i in numba.prange(len(Ec)): # pylint: disable=not-an-iterable
if dl[i] < 0.4e-3:
Ec[i] = 1.0

self.__ll82_coalescence_check_body = __ll82_coalescence_check_body

if self.formulae.fragmentation_function.__name__ == "Straub2010Nf":
straub_p1 = self.formulae.fragmentation_function.p1
straub_p2 = self.formulae.fragmentation_function.p2
Expand Down Expand Up @@ -356,6 +397,101 @@ def __straub_fragmentation_body(
)

self.__straub_fragmentation_body = __straub_fragmentation_body
elif self.formulae.fragmentation_function.__name__ == "LowList1982Nf":
ll82_params_f1 = self.formulae.fragmentation_function.params_f1
ll82_params_f2 = self.formulae.fragmentation_function.params_f2
ll82_params_f3 = self.formulae.fragmentation_function.params_f3
ll82_params_s1 = self.formulae.fragmentation_function.params_s1
ll82_params_s2 = self.formulae.fragmentation_function.params_s2
ll82_params_d1 = self.formulae.fragmentation_function.params_d1
ll82_params_d2 = self.formulae.fragmentation_function.params_d2
ll82_erfinv = self.formulae.fragmentation_function.erfinv

@numba.njit(**{**conf.JIT_FLAGS, "fastmath": self.formulae.fastmath})
def __ll82_fragmentation_body(
*, CKE, W, W2, St, ds, dl, dcoal, frag_size, rand, Rf, Rs, Rd, tol
):
for i in numba.prange( # pylint: disable=not-an-iterable
len(frag_size)
):
if dl[i] <= 0.4e-3:
frag_size[i] = dcoal[i] ** 3 * 3.1415 / 6
elif ds[i] == 0.0 or dl[i] == 0.0:
frag_size[i] = 1e-18
else:
ll82_Nr(i, Rf, Rs, Rd, CKE, W, W2)
if rand[i] <= Rf[i]: # filament breakup
(H1, mu1, sigma1) = ll82_params_f1(dl[i], dcoal[i])
(H2, mu2, sigma2) = ll82_params_f2(ds[i])
(H3, mu3, sigma3) = ll82_params_f3(ds[i], dl[i])
H1 = H1 * mu1
H2 = H2 * mu2
H3 = H3 * np.exp(mu3)
Hsum = H1 + H2 + H3
rand[i] = rand[i] / Rf[i]
if rand[i] <= H1 / Hsum:
X = max(rand[i] * Hsum / H1, tol)
frag_size[i] = mu1 + np.sqrt(2) * sigma1 * ll82_erfinv(
2 * X - 1
)
elif rand[i] <= (H1 + H2) / Hsum:
X = (rand[i] * Hsum - H1) / H2
frag_size[i] = mu2 + np.sqrt(2) * sigma2 * ll82_erfinv(
2 * X - 1
)
else:
X = min((rand[i] * Hsum - H1 - H2) / H3, 1.0 - tol)
lnarg = mu3 + np.sqrt(2) * sigma3 * ll82_erfinv(
2 * X - 1
)
frag_size[i] = np.exp(lnarg)

elif rand[i] <= Rf[i] + Rs[i]: # sheet breakup
(H1, mu1, sigma1) = ll82_params_s1(dl[i], ds[i], dcoal[i])
(H2, mu2, sigma2) = ll82_params_s2(dl[i], ds[i], St[i])
H1 = H1 * mu1
H2 = H2 * np.exp(mu2)
Hsum = H1 + H2
rand[i] = (rand[i] - Rf[i]) / (Rs[i])
if rand[i] <= H1 / Hsum:
X = max(rand[i] * Hsum / H1, tol)
frag_size[i] = mu1 + np.sqrt(2) * sigma1 * ll82_erfinv(
2 * X - 1
)
else:
X = min((rand[i] * Hsum - H1) / H2, 1.0 - tol)
lnarg = mu2 + np.sqrt(2) * sigma2 * ll82_erfinv(
2 * X - 1
)
frag_size[i] = np.exp(lnarg)

else: # disk breakup
(H1, mu1, sigma1) = ll82_params_d1(
W[i], dl[i], dcoal[i], CKE[i]
)
(H2, mu2, sigma2) = ll82_params_d2(ds[i], dl[i], CKE[i])
H1 = H1 * mu1
Hsum = H1 + H2
rand[i] = (rand[i] - Rf[i] - Rs[i]) / Rd[i]
if rand[i] <= H1 / Hsum:
X = max(rand[i] * Hsum / H1, tol)
frag_size[i] = mu1 + np.sqrt(2) * sigma1 * ll82_erfinv(
2 * X - 1
)
else:
X = min((rand[i] * Hsum - H1) / H2, 1 - tol)
lnarg = mu2 + np.sqrt(2) * sigma2 * ll82_erfinv(
2 * X - 1
)
frag_size[i] = np.exp(lnarg)

frag_size[i] = (
frag_size[i] * 0.01
) # diameter in cm; convert to m
frag_size[i] = frag_size[i] ** 3 * 3.1415 / 6
# print(np.sum(Rf), np.sum(Rs), np.sum(Rd))

self.__ll82_fragmentation_body = __ll82_fragmentation_body
elif self.formulae.fragmentation_function.__name__ == "Gaussian":
gaussian_frag_size = self.formulae.fragmentation_function.frag_size

Expand Down Expand Up @@ -573,7 +709,10 @@ def collision_coalescence_breakup(
# pylint: disable=too-many-arguments
def __fragmentation_limiters(n_fragment, frag_size, v_max, vmin, nfmax, x_plus_y):
for i in numba.prange(len(frag_size)): # pylint: disable=not-an-iterable
if np.isnan(frag_size[i]):
frag_size[i] = x_plus_y[i]
frag_size[i] = min(frag_size[i], v_max[i])
frag_size[i] = min(frag_size[i], x_plus_y[i])
frag_size[i] = max(frag_size[i], vmin)
if nfmax is not None:
if x_plus_y[i] / frag_size[i] > nfmax:
Expand Down Expand Up @@ -750,6 +889,60 @@ def straub_fragmentation(
nfmax=nfmax,
)

def ll82_fragmentation(
# pylint: disable=too-many-arguments,too-many-locals
self,
*,
n_fragment,
CKE,
W,
W2,
St,
ds,
dl,
dcoal,
frag_size,
v_max,
x_plus_y,
rand,
vmin,
nfmax,
Rf,
Rs,
Rd,
tol=1e-8,
):
self.__ll82_fragmentation_body(
CKE=CKE.data,
W=W.data,
W2=W2.data,
St=St.data,
ds=ds.data,
dl=dl.data,
dcoal=dcoal.data,
frag_size=frag_size.data,
rand=rand.data,
Rf=Rf.data,
Rs=Rs.data,
Rd=Rd.data,
tol=tol,
)
self.__fragmentation_limiters(
n_fragment=n_fragment.data,
frag_size=frag_size.data,
v_max=v_max.data,
x_plus_y=x_plus_y.data,
vmin=vmin,
nfmax=nfmax,
)

def ll82_coalescence_check(self, *, Ec, ds, dl):
self.__ll82_coalescence_check_body(
Ec=Ec.data,
ds=ds.data,
dl=dl.data,
)

@staticmethod
@numba.njit(**conf.JIT_FLAGS)
# pylint: disable=too-many-arguments,too-many-locals
Expand Down
1 change: 1 addition & 0 deletions PySDM/backends/impl_thrust_rtc/test_helpers/cpp2python.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ def to_numba(name, args, iter_var, body):
result = (
f"""
def make(self):
from math import erf
import numpy as np
from numpy import floor, ceil, exp, log, power, sqrt
import numba
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
from .exponential import ExponFrag
from .feingold1988 import Feingold1988Frag
from .gaussian import Gaussian
from .lowlist82 import LowList1982Nf
from .slams import SLAMS
from .straub2010 import Straub2010Nf
Loading