-
Notifications
You must be signed in to change notification settings - Fork 46
homogeneous nucleation of liquid droplets & expansion chamber example #1492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
claresinger
wants to merge
64
commits into
open-atmos:main
Choose a base branch
from
claresinger:expansion_chamber
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 28 commits
Commits
Show all changes
64 commits
Select commit
Hold shift + click to select a range
ca90206
add example of lifting parcel for time t_lift and then holding it to …
f716859
do dp sweep to plot Tmin vs dp under a few conditions of S0 and C0 to…
f41866b
Merge remote-tracking branch 'oa/main' into expansion_chamber
82aca13
Merge remote-tracking branch 'oa/main' into expansion_chamber
58f5e14
add some placeholders for S&P classic nucleation theory homogeneous n…
5f4dc31
add formulae for critical size of nucleated droplets
5d1be16
doc eq origin
d0b56aa
pylint
c98eaab
add unit tests for formulae relative to tables 11.1 and 11.4 in S&P. …
099e7ca
add bibliography entries. I'm not sure I did this correctly.
b141f02
Merge remote-tracking branch 'oa/main' into expansion_chamber
37053f8
swtich url for S&P from 3rd to 2nd ed. (linked full text available on…
slayoo ca940e8
accommodate S&P url in doc-generating script
slayoo 70e0548
address pylint hints
slayoo a501b8f
addressing devops_tests hints - header cells in the notebook
slayoo e09bdc4
whitespace removal
slayoo 5c3df34
remove null
4135c22
better variable names
3b607ca
use Gaussian aerosol mode, not LogNormal
f6f26bb
change import order
slayoo e59f1af
Merge remote-tracking branch 'oa/main' into expansion_chamber
33e2e3a
add expansion_chamber environment. todo check the thermodynamics here…
b584cfd
Merge remote-tracking branch 'oa/main' into expansion_chamber
03bffe7
refactor ExpansionChamber env and use it in Erinin_et_al_2025 example
slayoo ce6e454
forgotten __init__ move
slayoo 220b13e
Merge branch 'main' into expansion_chamber
slayoo b91a94c
replace assumed temperature profile with adiabatic temperature condit…
a7f4950
add new physics formulae for adiabatic exponent
4ffd684
introduce homogeneous nucleation dynamic with some common code with s…
slayoo cd3375b
raname seeding -> spawning in backend tests
slayoo f9d99ce
raname injecting -> spawning in backend tests
slayoo 8bc50bb
comment on zero multiplicity -> MC sampling?
slayoo e5abcb3
work in progress towards getting nucleation dynamic enabled in the ex…
slayoo fedd946
add back boltzmann constant
fe4bfb9
fix errors in dynamic to get to error with 'No available null SDs to …
59a0fa4
wip add nan SDs. getting error about index out of bounds.
3bb377b
make attribute saving logic compatible with variable state-vector size
slayoo c4f2ec8
introduce SuperParticleSpawningDynamic.check_extensive_attribute_keys…
slayoo 763d853
make multiplicity a Storage as well (currently stops on: "Python int …
slayoo 1dc09c9
make example run with nucleation by shortening timestep to avoid over…
d53312a
simplified units handling, enabled condensation adaptivity
slayoo c11118c
resolve merge conflict
slayoo 0ee157d
fix bib issues
slayoo ee6cca2
fix multiplicity product. print out fractional change in total partic…
decce8e
Merge remote-tracking branch 'oa/main' into expansion_chamber
deb27c4
qv to vapour_mixing_ratio spelled out
60cb166
fixing tests, addressing pylint hints
slayoo 8989e38
reinstantiate changes from #1509
slayoo 84759aa
addressing pylint hints
slayoo fe370f8
setup chamber smoke tests execution on CI
slayoo 2b811bd
address pylint hints
slayoo 2bd28ba
fix badge URLs
slayoo 2896faa
add TODO labels (pointing to the PR!_
slayoo dc1217e
pylint hints, notebook header
slayoo ab4412d
pylint hints
slayoo 43c4828
missing bib entry
slayoo 897fb3e
simplify notebook code; skip nucleation if RH<1
slayoo 1e7631e
address pylint hints
slayoo 7d180ad
address pylint hints again
slayoo 649caba
fix MockParticulator
slayoo 89d1086
extensions in homogeneous liquid nucleation unit tests
slayoo 12b55dd
less crazy test values for T and S
slayoo 7150f84
unit test for homogeneous nucleation dynamic using constant rate
slayoo ed24039
Merge remote-tracking branch 'oa/main' into expansion_chamber
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
""" | ||
Zero-dimensional expansion chamber framework | ||
""" | ||
|
||
from typing import Optional, List | ||
|
||
from PySDM.environments.impl.moist_lagrangian import MoistLagrangian | ||
from PySDM.impl.mesh import Mesh | ||
from PySDM.environments.impl import register_environment | ||
|
||
|
||
@register_environment() | ||
class ExpansionChamber(MoistLagrangian): | ||
def __init__( | ||
self, | ||
*, | ||
dt, | ||
volume: float, | ||
initial_pressure: float, | ||
initial_temperature: float, | ||
initial_relative_humidity: float, | ||
delta_pressure: float, | ||
delta_time: float, | ||
variables: Optional[List[str]] = None, | ||
mixed_phase=False, | ||
): | ||
variables = (variables or []) + ["rhod"] | ||
|
||
super().__init__(dt, Mesh.mesh_0d(), variables, mixed_phase=mixed_phase) | ||
|
||
self.dv = volume | ||
self.initial_pressure = initial_pressure | ||
self.initial_temperature = initial_temperature | ||
self.initial_relative_humidity = initial_relative_humidity | ||
self.delta_time = delta_time | ||
self.dp_dt = delta_pressure / delta_time | ||
|
||
def register(self, builder): | ||
self.mesh.dv = self.dv | ||
|
||
super().register(builder) | ||
|
||
formulae = self.particulator.formulae | ||
pv0 = ( | ||
self.initial_relative_humidity | ||
* formulae.saturation_vapour_pressure.pvs_water(self.initial_temperature) | ||
) | ||
th_std = formulae.trivia.th_std( | ||
p=self.initial_pressure, T=self.initial_temperature | ||
) | ||
initial_water_vapour_mixing_ratio = ( | ||
formulae.constants.eps * pv0 / (self.initial_pressure - pv0) | ||
) | ||
|
||
self["rhod"][:] = formulae.state_variable_triplet.rho_d( | ||
p=self.initial_pressure, | ||
water_vapour_mixing_ratio=initial_water_vapour_mixing_ratio, | ||
theta_std=th_std, | ||
) | ||
self["thd"][:] = formulae.state_variable_triplet.th_dry( | ||
th_std, initial_water_vapour_mixing_ratio | ||
) | ||
self["water_vapour_mixing_ratio"][:] = initial_water_vapour_mixing_ratio | ||
|
||
self.post_register() | ||
|
||
def advance_moist_vars(self): | ||
"""compute new values of dry density and thd, and write them to self._tmp and self["thd"] | ||
assuming water-vapour mixing ratio is not altered by the expansion""" | ||
dt = self.particulator.dt | ||
t_new = (self.particulator.n_steps + 1) * dt | ||
if t_new > self.delta_time: | ||
return | ||
|
||
formulae = self.particulator.formulae | ||
p_new = self["p"][0] + self.dp_dt * dt | ||
qv = self["water_vapour_mixing_ratio"][0] | ||
gg = ( | ||
1 - formulae.adiabatic_exponent.gamma(qv) | ||
) / formulae.adiabatic_exponent.gamma(qv) | ||
T_new = self.initial_temperature * (self.initial_pressure / p_new) ** gg | ||
wvmr_new = self._tmp["water_vapour_mixing_ratio"][ | ||
0 | ||
] # TODO #1492 - should _tmp or self[] be used? | ||
pv_new = wvmr_new * p_new / (wvmr_new + formulae.constants.eps) | ||
pd_new = p_new - pv_new | ||
|
||
self._tmp["rhod"][:] = pd_new / T_new / formulae.constants.Rd | ||
self["thd"][:] = formulae.trivia.th_std(p=pd_new, T=T_new) | ||
|
||
def sync_moist_vars(self): | ||
for var in self.variables: | ||
self._tmp[var][:] = self[var][:] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
""" | ||
Zero-dimensional (Lagrangian) moist environment commons | ||
""" | ||
|
||
from PySDM.environments.impl.moist import Moist | ||
|
||
|
||
class MoistLagrangian(Moist): | ||
"""base class for moist Lagrangian environments (parcel, chamber, ...)""" | ||
|
||
def get_thd(self): | ||
return self["thd"] | ||
|
||
def get_water_vapour_mixing_ratio(self): | ||
return self["water_vapour_mixing_ratio"] | ||
|
||
def sync(self): | ||
self.sync_moist_vars() | ||
self.advance_moist_vars() | ||
super().sync() | ||
|
||
def post_register(self): | ||
self.sync_moist_vars() | ||
super().sync() | ||
self.notify() | ||
|
||
def sync_moist_vars(self): | ||
raise NotImplementedError() | ||
|
||
def advance_moist_vars(self): | ||
raise NotImplementedError() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
""" | ||
Alternative formulations of adiabatic exponent | ||
""" | ||
|
||
from .dry import Dry | ||
from .moist_leading_terms import MoistLeadingTerms |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
""" | ||
adiabatic exponent, dry air | ||
""" | ||
|
||
|
||
class Dry: | ||
def __init__(self, _): | ||
pass | ||
|
||
# pylint: disable=too-many-arguments | ||
@staticmethod | ||
def gamma(const, qv): | ||
return 1 + const.Rd / const.c_vd |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
""" | ||
adiabatic exponent, moist air, expanding to first order in qv, assuming qt=qv | ||
""" | ||
|
||
|
||
class MoistLeadingTerms: | ||
def __init__(self, _): | ||
pass | ||
|
||
# pylint: disable=too-many-arguments | ||
@staticmethod | ||
def gamma(const, qv): | ||
claresinger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return ( | ||
1 | ||
+ const.Rd / const.c_vd | ||
+ (const.Rv * qv) / (const.c_vd * (1 - qv)) | ||
- (const.Rd * qv * const.c_vv) / (const.c_vd**2 * (1 - qv)) | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
""" | ||
homogeneous liquid droplet nucleation rate formulations | ||
""" | ||
|
||
from PySDM.impl.null_physics_class import Null | ||
from .cnt import CNT | ||
from .constant import Constant |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
""" | ||
classical nucleation theory (CNT) | ||
formulae from [Seinfeld and Pandis](https://archive.org/details/0237-pdf-atmospheric-chemistry-and-physics-2nd-ed-j.-seinfeld-s.-pandis-wiley-2006-ww) | ||
Eq (11.47) and (11.52) | ||
""" # pylint: disable=line-too-long | ||
|
||
import numpy as np | ||
|
||
|
||
class CNT: | ||
def __init__(self, _): | ||
return | ||
|
||
@staticmethod | ||
def j_liq_homo(const, T, S, e_s): | ||
mass_per_moleculue = const.Mv / const.N_A | ||
volume_per_molecule = mass_per_moleculue / const.rho_w | ||
N1 = (S * e_s) / (mass_per_moleculue * const.Rv * T) # molecules per m3 | ||
return ( | ||
((2 * const.sgm_w) / (np.pi * mass_per_moleculue)) ** (1 / 2) | ||
* (volume_per_molecule * N1**2 / S) | ||
* np.exp( | ||
(-16 * np.pi * volume_per_molecule**2 * const.sgm_w**3) | ||
/ (3 * const.k_B**3 * T**3 * np.log(S) ** 2) | ||
) | ||
) | ||
|
||
@staticmethod | ||
def r_liq_homo(const, T, S): | ||
mass_per_moleculue = const.Mv / const.N_A | ||
volume_per_molecule = mass_per_moleculue / const.rho_w | ||
return (2 * const.sgm_w * volume_per_molecule) / (const.k_B * T * np.log(S)) |
19 changes: 19 additions & 0 deletions
19
PySDM/physics/homogeneous_liquid_nucleation_rate/constant.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
""" | ||
constant rate formulation (for tests) | ||
""" | ||
|
||
import numpy as np | ||
|
||
|
||
class Constant: | ||
def __init__(self, const): | ||
assert np.isfinite(const.J_LIQ_HOMO) | ||
assert np.isfinite(const.R_LIQ_HOMO) | ||
|
||
@staticmethod | ||
def j_liq_homo(const, T, S, e_s): # pylint: disable=unused-argument | ||
return const.J_LIQ_HOMO | ||
|
||
@staticmethod | ||
def r_liq_homo(const, T, S): # pylint: disable=unused-argument | ||
return const.R_LIQ_HOMO |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.