Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
35 changes: 35 additions & 0 deletions compare_dry_density.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# %%
import numpy as np
import matplotlib.pyplot as plt

# %%
from PyMPDATA_examples.Shipway_and_Hill_2012 import si, settings

# %%
RHOD_VERTVELO = 3*si.m/si.s * si.kg/si.m**3
T_MAX = 15*si.minutes
P0 = 1000*si.hPa
Z_MAX = 3200*si.m
nr = 32
dt = 1.25*si.s
dz = 25*si.m
R_MIN = 1 * si.um
R_MAX = 20.2 * si.um
apprx_drhod_dz = False

settings_true = settings.Settings(
rhod_w_const=RHOD_VERTVELO, nr=nr, dt=dt, dz=dz, t_max=T_MAX,
r_min=R_MIN, r_max=R_MAX, p0=P0, z_max=Z_MAX, apprx_drhod_dz=apprx_drhod_dz
)
settings_false = settings.Settings(
rhod_w_const=RHOD_VERTVELO, nr=nr, dt=dt, dz=dz, t_max=T_MAX,
r_min=R_MIN, r_max=R_MAX, p0=P0, z_max=Z_MAX, apprx_drhod_dz=apprx_drhod_dz, use_max_step=False,
)
# %%
z = z_points = np.linspace(0.0, 2 * settings_true.nz + 1)
plt.plot(settings_false.rhod(z) - settings_true.rhod(z), z)
plt.legend()
plt.ylabel("z / m")
plt.xlabel("difference in dry density compared to using max_step / kg/m$^{-3}$")
plt.show()
# %%
6 changes: 6 additions & 0 deletions examples/PyMPDATA_examples/Shipway_and_Hill_2012/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(
ksi_1: float = default_ksi_1.to_base_units().magnitude,
z_max: float = 3000 * si.metres,
apprx_drhod_dz: bool = True,
use_max_step: bool = True,
):
self.dt = dt
self.dz = dz
Expand Down Expand Up @@ -58,11 +59,16 @@ def drhod_dz(z, rhod):
return drhod_dz

z_points = np.arange(0, self.z_max + self.dz / 2, self.dz / 2)
if use_max_step:
max_step=self.dz/2
else:
max_step = np.inf # (same as default in solve_ivp docs)
rhod_solution = solve_ivp(
fun=drhod_dz,
t_span=(0, self.z_max),
y0=np.asarray((self.rhod0,)),
t_eval=z_points,
max_step=max_step,
)
assert rhod_solution.success

Expand Down
Loading