Skip to content

Commit

Permalink
freezing tests volume-to-mass refactor. closes #1262 (#1358)
Browse files Browse the repository at this point in the history
  • Loading branch information
slayoo authored Jul 7, 2024
1 parent f44d88b commit 9e153ee
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions tests/unit_tests/backends/test_freezing_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from PySDM import Builder, Formulae
from PySDM.dynamics import Freezing
from PySDM.environments import Box
from PySDM.physics import constants_defaults as const
from PySDM.physics import si
from PySDM.products import IceWaterContent

Expand Down Expand Up @@ -68,7 +67,7 @@ def test_freeze_singular(backend_class):
dt = 1 * si.s
dv = 1 * si.m**3
T_fz = 250 * si.K
vol = 1 * si.um**3
water_mass = 1 * si.mg
multiplicity = 1e10
steps = 1

Expand All @@ -81,7 +80,7 @@ def test_freeze_singular(backend_class):
attributes = {
"multiplicity": np.full(n_sd, multiplicity),
"freezing temperature": np.full(n_sd, T_fz),
"volume": np.full(n_sd, vol),
"water mass": np.full(n_sd, water_mass),
}
products = (IceWaterContent(name="qi"),)
particulator = builder.build(attributes=attributes, products=products)
Expand All @@ -92,9 +91,10 @@ def test_freeze_singular(backend_class):
particulator.run(steps=steps)

# assert
np.testing.assert_almost_equal(
np.asarray(particulator.products["qi"].get()),
[n_sd * multiplicity * vol * const.rho_w / dv],
np.testing.assert_approx_equal(
actual=np.asarray(particulator.products["qi"].get()),
desired=n_sd * multiplicity * water_mass / dv,
significant=7,
)

@staticmethod
Expand Down Expand Up @@ -123,7 +123,7 @@ def test_freeze_time_dependent(backend_class, double_precision, plot=False):
)

# dummy (but must-be-set) values
vol = (
initial_water_mass = (
44 # for sign flip (ice water has negative volumes), value does not matter
)
d_v = 666 # products use conc., dividing there, multiplying here, value does not matter
Expand Down Expand Up @@ -165,7 +165,7 @@ def low(t):
attributes = {
"multiplicity": np.full(n_sd, int(case["N"])),
"immersed surface area": np.full(n_sd, immersed_surface_area),
"volume": np.full(n_sd, vol),
"water mass": np.full(n_sd, initial_water_mass),
}
particulator = builder.build(attributes=attributes, products=products)
env["RH"] = 1.0001
Expand All @@ -178,7 +178,7 @@ def low(t):

ice_mass_per_volume = particulator.products["qi"].get()[cell_id]
ice_mass = ice_mass_per_volume * d_v
ice_number = ice_mass / (const.rho_w * vol)
ice_number = ice_mass / initial_water_mass
unfrozen_fraction = 1 - ice_number / number_of_real_droplets
output[key]["unfrozen_fraction"].append(unfrozen_fraction)

Expand Down

0 comments on commit 9e153ee

Please sign in to comment.