Skip to content

Commit 1e80a35

Browse files
committed
draft logic for backend isotope_fractionation routine; placeholder file for timescale attributes
1 parent 678e3e5 commit 1e80a35

File tree

3 files changed

+71
-4
lines changed

3 files changed

+71
-4
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# TODO: register one class per isotope,
2+
# and in each class call the relevant physics formula for a given isotope
3+
4+
# TODO: code analogous to that in the delta.py file here

PySDM/backends/impl_numba/methods/isotope_methods.py

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,54 @@ def body(output, ratio, reference_ratio):
2424
def isotopic_delta(self, output, ratio, reference_ratio):
2525
self._isotopic_delta_body(output.data, ratio.data, reference_ratio)
2626

27-
def isotopic_fractionation(self):
28-
pass
27+
@cached_property
28+
def _isotopic_fractionation_body(self):
29+
@numba.njit(**self.default_jit_flags)
30+
def body(
31+
*,
32+
multiplicity,
33+
signed_timescale,
34+
moles,
35+
dt,
36+
ambient_isotope_mixing_ratio,
37+
cell_id,
38+
cell_volume,
39+
dry_air_density,
40+
molar_mass,
41+
):
42+
for sd_id in numba.prange(multiplicity.shape[0]):
43+
dn = dt / signed_timescale[sd_id] * moles[sd_id]
44+
moles[sd_id] += dn
45+
mass_of_dry_air = (
46+
dry_air_density[cell_id[sd_id]] * cell_volume[cell_id[sd_id]]
47+
)
48+
ambient_isotope_mixing_ratio[cell_id[sd_id]] -= (
49+
dn * multiplicity[sd_id] * molar_mass / mass_of_dry_air
50+
)
51+
52+
return body
53+
54+
def isotopic_fractionation(
55+
self,
56+
*,
57+
isotope,
58+
multiplicity,
59+
signed_timescale,
60+
moles,
61+
dt,
62+
ambient_isotope_mixing_ratio,
63+
cell_id,
64+
cell_volume,
65+
dry_air_density,
66+
):
67+
self._isotopic_fractionation_body(
68+
multiplicity=multiplicity.data,
69+
signed_timescale=signed_timescale.data,
70+
moles=moles.data,
71+
dt=dt,
72+
ambient_isotope_mixing_ratio=ambient_isotope_mixing_ratio.data,
73+
cell_id=cell_id.data,
74+
cell_volume=cell_volume.data,
75+
dry_air_density=dry_air_density.data,
76+
molar_mass=getattr(self.formulae.constants, f"M_{isotope}"),
77+
)

PySDM/particulator.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,9 +439,23 @@ def calculate_displacement(
439439
n_substeps=n_substeps,
440440
)
441441

442-
def isotopic_fractionation(self, heavy_isotopes: tuple):
443-
self.backend.isotopic_fractionation()
442+
def isotopic_fractionation(
443+
self, heavy_isotopes: tuple, ambient_isotope_mixing_ratios
444+
):
444445
for isotope in heavy_isotopes:
446+
self.backend.isotopic_fractionation(
447+
isotope=isotope,
448+
multiplicity=self.attributes["multiplicity"],
449+
signed_timescale=self.attributes[f"isotope_timescale_{isotope}"],
450+
moles=self.attributes[f"moles_{isotope}"],
451+
dt=self.dt,
452+
dry_air_density=self.environment[f"dry_air_density"],
453+
cell_volume=self.environment.mesh.dv,
454+
cell_id=self.attributes["cell id"],
455+
ambient_isotope_mixing_ratio=self.environment[
456+
f"mixing_ratio_{isotope}"
457+
],
458+
)
445459
self.attributes.mark_updated(f"moles_{isotope}")
446460

447461
def seeding(

0 commit comments

Comments
 (0)