Skip to content

Commit

Permalink
added hexagonal version of snowfall, restructured yaml file
Browse files Browse the repository at this point in the history
  • Loading branch information
akosira committed Jun 11, 2024
1 parent 03e1425 commit f4977c0
Show file tree
Hide file tree
Showing 20 changed files with 570 additions and 144 deletions.
12 changes: 3 additions & 9 deletions examples/snowfall_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,15 @@
from ethz_snow.operatingConditions import OperatingConditions

# define the heat transfer parameters dictionary
d = {"int": 10, "ext": 100, "s0": 50, "s_sigma_rel": 0}
d = {"int": 20, "ext": 0, "s0": 50, "s_sigma_rel": 0}

# define the cooling rate profile and holding steps
c = {"rate": 0.5 / 60, "start": 20, "end": -50}
h = []

# create an instance of the operating conditions class
op = OperatingConditions(t_tot=4 * 3600, cooling=c, holding=h)
op = OperatingConditions(t_tot=3 * 3600, cooling=c, holding=h)

# run a single simulation
S = Snowfall(
k=d, opcond=op, seed_v=0
) # seed_v is used to seed the rng for vial-dependent nuc parameters (See Snowflake docs)
S = Snowfall(k=d, opcond=op, N_vials=(5, 5, 5))
S.run()

print(S.nucleationTimes())
print(S.nucleationTemperatures())
print(S.solidificationTimes())
10 changes: 3 additions & 7 deletions examples/snowflake_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@
from ethz_snow.operatingConditions import OperatingConditions

# define the heat transfer parameters dictionary
d = {"int": 10, "ext": 100, "s0": 50, "s_sigma_rel": 0}
d = {"int": 20, "ext": 0, "s0": 50, "s_sigma_rel": 0}

# define the cooling rate profile and holding steps
c = {"rate": 0.5 / 60, "start": 20, "end": -50}
h = []

# create an instance of the operating conditions class
op = OperatingConditions(t_tot=4 * 3600, cooling=c, holding=h)
op = OperatingConditions(t_tot=3 * 3600, cooling=c)

# run a single simulation
S = Snowflake(k=d, opcond=op)
S = Snowflake(k=d, opcond=op, N_vials=(5, 5, 1))
S.run()

print(S.nucleationTimes())
print(S.nucleationTemperatures())
print(S.solidificationTimes())
34 changes: 4 additions & 30 deletions examples/snowing_example.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,17 @@
# import modules: Snowing and OperatingConditions
# import modules
from ethz_snow.snowing import Snowing
from ethz_snow.operatingConditions import OperatingConditions

# define the heat transfer parameters dictionary
d = {"int": 0, "ext": 0, "s0": 50, "s_sigma_rel": 0}
d = {"int": 20, "ext": 0, "s0": 50, "s_sigma_rel": 0}

# define the cooling rate profile and holding steps
c = {"rate": 0.5 / 60, "start": 20, "end": -50}
h = []

# create an instance of the operating conditions class
op = OperatingConditions(t_tot=4 * 3600, cooling=c, holding=h)

op = OperatingConditions(t_tot=3 * 3600, cooling=c, holding=h)

# run a single spatial simulation
S_1 = Snowing(k=d, opcond=op, Nrep=1)
S_1.run()

# show results
S_1.results

# plot evolutions of temperature and ice mass fraction
S_1.plot_evolution(what="temperature")
S_1.plot_evolution(what="ice_mass_fraction")

# get individual arrays
time = S_1.time
shelf = S_1.shelfTemp
temp = S_1.temp
ice = S_1.iceMassFraction


# multiple simulations are run if Nrep > 1
S = Snowing(k=d, opcond=op, Nrep=50)
S = Snowing(k=d, opcond=op)
S.run()
S.results

# plot
S.plot_cdf(what="T_nuc")
S.plot_cdf(what="t_nuc")
S.plot_cdf(what="t_sol")
S.plot_cdf(what="t_fr")
14 changes: 10 additions & 4 deletions src/ethz_snow/config/snowConfig_default.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# model dimensionality/temperature resolution within vial (homogeneous, spatial_1D, spatial_2D)
dimensionality: homogeneous
# additional parameters for the shelf-scale model (Snowfall and Snowflake modules)
snowfall_parameters:
# arrangment of vials (only for homogeneous dimensionality model)
vial_arrangement: square

# freezing configuration to be simulated (shelf, VISF, jacket)
configuration: shelf
# additional parameters for the spatial model (Snowing module)
snowing_parameters:
# model dimensionality/temperature resolution within vial (homogeneous, spatial_1D, spatial_2D)
dimensionality: spatial_1D
# freezing configuration to be simulated (shelf, VISF, jacket)
configuration: shelf

# all vial-related parameters
vial:
Expand Down
62 changes: 38 additions & 24 deletions src/ethz_snow/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,12 @@ def calculateDerived(fpath: Optional[str] = None) -> dict:
height = float(config["vial"]["geometry"]["height"])
diameter = float(config["vial"]["geometry"]["diameter"])

dimensionality = str(config["dimensionality"])
configuration = str(config["configuration"])
# snowing parameters
dimensionality = str(config["snowing_parameters"]["dimensionality"])
configuration = str(config["snowing_parameters"]["configuration"])

# snowfall parameters
vial_arrangement = str(config["snowfall_parameters"]["vial_arrangement"])

# check configuration
if configuration not in {"shelf", "VISF", "jacket"}:
Expand All @@ -158,6 +162,15 @@ def calculateDerived(fpath: Optional[str] = None) -> dict:
)
)

# check vial arrangement
if vial_arrangement not in {"hexagonal", "square"}:
raise NotImplementedError(
(
f'Vial arrangment "{vial_arrangement}" '
+ 'not correctly specified, use "hexagonal" or "square".'
)
)

# check model dimensionality
if dimensionality not in {"homogeneous", "spatial_1D", "spatial_2D"}:
raise NotImplementedError(
Expand Down Expand Up @@ -209,6 +222,15 @@ def calculateDerived(fpath: Optional[str] = None) -> dict:
)
)

# # vial arrangement is only considered in the homogeneous model
# if dimensionality in {"homogeneous", "spatial_1D", "spatial_2D"}:
# print(
# (
# f'WARNING: Vial arrangement "{vial_arrangement}" '
# + "is relevant only for Snowfall and Snowflake simulations."
# )
# )

# volume
V = A * height

Expand Down Expand Up @@ -255,11 +277,9 @@ def calculateDerived(fpath: Optional[str] = None) -> dict:
mass_solute = mass * solid_fraction
mass_water = mass * (1 - solid_fraction)

# freezing configuration
configuration = str(config["configuration"])

constVars = [
"dimensionality",
"vial_arrangement",
"T_eq",
"T_eq_l",
"a",
Expand Down Expand Up @@ -291,13 +311,10 @@ def calculateDerived(fpath: Optional[str] = None) -> dict:
]

# check that spatial model is chosen for VISF
if config["configuration"] == "VISF":
if config["dimensionality"] == "homogeneous":
if configuration == "VISF":
if dimensionality == "homogeneous":
raise NotImplementedError(
(
f'For simulating "{config["configuration"]}" '
+ "a spatial model is required."
)
(f'For simulating "{configuration}" ' + "a spatial model is required.")
)

# set up additional parameters for VISF
Expand All @@ -320,13 +337,10 @@ def calculateDerived(fpath: Optional[str] = None) -> dict:
)

# check that spatial model is chosen for jacket
elif config["configuration"] == "jacket":
if config["dimensionality"] != "spatial_2D":
elif configuration == "jacket":
if dimensionality != "spatial_2D":
raise NotImplementedError(
(
f'For simulating "{config["configuration"]}" '
+ "a 2D model is required."
)
(f'For simulating "{configuration}" ' + "a 2D model is required.")
)

# set up additional parameters for jacket-ramped freezing
Expand All @@ -336,13 +350,13 @@ def calculateDerived(fpath: Optional[str] = None) -> dict:
constVars.extend(["lambda_air", "air_gap"])

# warn that cylindrical gemoetry instead of cubic geometry is used for spatial model
if config["dimensionality"] != "homogeneous":
print(
(
f'WARNING: For simulating a "{config["dimensionality"]}" '
+ "model a cylindrical geometry is required. Shape is automatically rewritten to cylinder."
)
)
if dimensionality != "homogeneous":
# print(
# (
# f'WARNING: For simulating a "{dimensionality}" '
# + "model a cylindrical geometry is required. Shape is automatically rewritten to cylinder."
# )
# )

# this is not a lumped capacitance model
# effective heat conductivity (for non-homog. vial temps)
Expand Down
Loading

0 comments on commit f4977c0

Please sign in to comment.