Skip to content

Commit 7462b0e

Browse files
Merge pull request #28 from yoctoyotta1024/add_pysdm
Add pysdm as git submodule
2 parents 92a1f5f + 9dd2689 commit 7462b0e

23 files changed

Lines changed: 3077 additions & 63 deletions

cleo_1dkid/cleo_deps/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ include(FetchContent)
2323
FetchContent_Declare(
2424
cleo
2525
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
26-
URL https://github.com/yoctoyotta1024/CLEO/archive/refs/tags/v0.63.0.zip
27-
GIT_TAG 5af4642cc6305d93577ad3e4c027890fbd52fded
26+
URL https://github.com/yoctoyotta1024/CLEO/archive/refs/tags/v0.64.0.zip
27+
GIT_TAG 4cf4985b741c098c12baa0c0261ae602a221c31a
2828
)
2929
FetchContent_MakeAvailable(cleo)
3030

31-
message(STATUS "CLEO version v0.63.0, installation in: ${CLEO_BINARY_DIR}")
31+
message(STATUS "CLEO version v0.64.0, installation in: ${CLEO_BINARY_DIR}")
3232

3333
# print default compiler flags
3434
message(STATUS "CLEO primary CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")

cleo_1dkid/libs/cleo_sdm/cleo_sdm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
-----
1717
File Description:
1818
class and functions for handing setup and running of CLEO via python bindings,
19-
functions adapted from CLEO v0.63.0 python_bindings example.
19+
functions adapted from CLEO v0.64.0 python_bindings example.
2020
NOTE: To use the wrapper, you must first export "CLEO_PYTHON_BINDINGS".
2121
E.g. if python bindings are built in $HOME/superdrops-in-action/build/, do:
2222
export CLEO_PYTHON_BINDINGS=$HOME/superdrops-in-action/build/_deps/cleo-build/cleo_python_bindings/

cleo_1dkid/libs/cleo_sdm/initconds/create_config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@
6262
type=float,
6363
help="alpha value for superdroplet initial conditions",
6464
)
65+
parser.add_argument(
66+
"--numconc",
67+
type=float,
68+
help="number concentration /cm^3 for superdroplet initial conditions",
69+
)
6570
args = parser.parse_args()
6671

6772
from cleopy import editconfigfile
@@ -74,6 +79,7 @@
7479
zarrbasedir = args.zarrbasedir
7580
nsupers_pergbx = args.nsupers_pergbx
7681
alpha = args.alpha
82+
numconc_perm3 = float(args.numconc) * 1e6 # [m^-3]
7783

7884
cnfg = yaml.safe_load(open(args.src_config_filename))
7985
initnsupers = int(cnfg["domain"]["ngbxs"]) * nsupers_pergbx
@@ -101,6 +107,8 @@
101107
"maxnsupers": int(maxnsupers),
102108
"initnsupers": int(initnsupers),
103109
"newnsupers": int(newnsupers),
110+
"numconc": int(numconc_perm3),
111+
"NUMCONC_a": int(numconc_perm3),
104112
}
105113

106114
print("--- create_config configuration arguments ---")

cleo_1dkid/libs/cleo_sdm/initconds/initial_pressure_profile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def get_initial_pressure_profile(
5252
is_approx_drhod_dz=False,
5353
)
5454
zfull = np.arange(z_min + z_delta / 2, z_max + z_delta / 2, z_delta)
55-
press_prof = settings.press(zfull)
55+
press_prof = settings.press0(zfull)
5656

5757
gbxbounds = rgrid.read_dimless_gbxboundaries_binary(grid_filename, isprint=False)
5858

cleo_1dkid/libs/test_case_1dkid/kid_dynamics.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def __init__(
7272
self.mpdata = MPDATA(
7373
nz=self.settings.nz,
7474
dt=self.settings.dt,
75-
qv_of_zZ_at_t0=lambda zZ: self.settings.qv(
75+
qv_of_zZ_at_t0=lambda zZ: self.settings.qv0(
7676
zZ * self.settings.dz + self.settings.z_min
7777
),
7878
g_factor_of_zZ=lambda zZ: self.settings.rhod(
@@ -87,13 +87,9 @@ def __init__(
8787
assert self.settings.z_min == z_min
8888
assert self.settings.z_max == z_max
8989
assert self.settings.dz == z_delta
90-
zfull = np.arange(z_min + z_delta / 2, z_max + z_delta / 2, z_delta)
90+
self.zfull = np.arange(z_min + z_delta / 2, z_max + z_delta / 2, z_delta)
9191
self.zhalf = np.arange(z_min, z_max + z_delta, z_delta)
92-
assert np.all((self.zhalf[1:] + self.zhalf[:-1]) / 2 == zfull)
93-
94-
self.rhod_prof = self.settings.rhod(zfull)
95-
self.temp_prof = self.settings.temp(zfull)
96-
self.press_prof = self.settings.press(zfull)
92+
assert np.all((self.zhalf[1:] + self.zhalf[:-1]) / 2 == self.zfull)
9793

9894
key = f"nr={self.mpdata.nr}, dz={self.settings.dz}, dt={self.settings.dt}, options={options}"
9995
print(f"Simulating {self.settings.nt} timesteps using {key}")
@@ -107,15 +103,15 @@ def set_thermo(self, time, thermo):
107103
Returns:
108104
Thermodynamics: Updated thermodynamic state.
109105
"""
110-
thermo.temp[:] = self.temp_prof
111-
thermo.rho[:] = self.rhod_prof
112-
thermo.press[:] = self.press_prof
113106
thermo.massmix_ratios["qvap"][:] = self.mpdata["qvap"].advectee.get()
114107
thermo.massmix_ratios["qcond"][:] = self.mpdata["qcond"].advectee.get()
115108
thermo.massmix_ratios["qice"][:] = self.mpdata["qice"].advectee.get()
116109
thermo.massmix_ratios["qrain"][:] = self.mpdata["qrain"].advectee.get()
117110
thermo.massmix_ratios["qsnow"][:] = self.mpdata["qsnow"].advectee.get()
118111
thermo.massmix_ratios["qgrau"][:] = self.mpdata["qgrau"].advectee.get()
112+
thermo.rhod[:] = self.settings.rhod(self.zfull)
113+
thermo.temp[:] = self.settings.temp(self.zfull)
114+
thermo.press[:] = self.settings.press(self.zfull, thermo.massmix_ratios["qvap"])
119115

120116
if thermo.wvel.size != 0:
121117
z_half_reps = np.repeat(

cleo_1dkid/libs/test_case_1dkid/settings.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ def __init__(
5656
self.z_max = z_max
5757
self.t_max = t_max
5858

59-
self.qv = interp1d(
59+
self.qv0 = interp1d(
6060
(0, 740, 3260), (0.015, 0.0138, 0.0024), fill_value="extrapolate"
6161
)
6262
self._th = interp1d(
6363
(0, 740, 3260), (297.9, 297.9, 312.66), fill_value="extrapolate"
6464
)
6565

66-
self.thd = lambda z: formulae.th_dry(self._th(z), self.qv(z))
66+
self.thd = lambda z, qv: formulae.th_dry(self._th(z), qv)
6767

6868
z_points = np.arange(0, self.z_max + self.dz / 2, self.dz / 2)
6969

@@ -104,7 +104,7 @@ def z2exner(z, return_rho=False, return_press=False, return_temp=False):
104104
return exner
105105

106106
self.temp = lambda z: z2exner(zpos(z), return_temp=True)
107-
self.press = lambda z: z2exner(zpos(z), return_press=True)
107+
self.press = lambda z, qv: z2exner(zpos(z), return_press=True)
108108
self.rhod = lambda z: z2exner(zpos(z), return_rho=True)
109109
if is_exner_novapour_uniformrho:
110110
rhod0 = 1.0 * np.ones_like(z_points) # [kg / m^3]
@@ -114,30 +114,31 @@ def z2exner(z, return_rho=False, return_press=False, return_temp=False):
114114
# note: not in the paper,
115115
# https://github.com/BShipway/KiD/tree/master/src/physconst.f90#L43
116116
def drhod_dz(z, rhod):
117-
T = formulae.temperature(rhod[0], self.thd(z))
118-
p = formulae.pressure(rhod[0], T, self.qv(z))
119-
drhod_dz = formulae.drho_dz(const.g, p, T, self.qv(z), const.lv)
117+
T = formulae.temperature(rhod[0], self.thd(z, self.qv0(z)))
118+
p = formulae.pressure(rhod[0], T, self.qv0(z))
119+
drhod_dz = formulae.drho_dz(const.g, p, T, self.qv0(z), const.lv)
120120
if not is_approx_drhod_dz: # to resolve issue #335
121-
qv = self.qv(z)
122-
dqv_dz = Derivative(self.qv)(z)
121+
qv = self.qv0(z)
122+
dqv_dz = Derivative(self.qv0)(z)
123123
drhod_dz = drhod_dz / (1 + qv) - rhod * dqv_dz / (1 + qv) ** 2
124124
return drhod_dz
125125

126-
rhod0 = formulae.rho_d(p_surf, self.qv(0), self._th(0))
126+
rhod0 = formulae.rho_d(p_surf, self.qv0(0), self._th(0))
127127
rhod_solution = solve_ivp(
128128
fun=drhod_dz,
129129
t_span=(0, self.z_max),
130130
y0=np.asarray((rhod0,)),
131131
t_eval=z_points,
132+
max_step=self.dz / 2,
132133
)
133134
assert rhod_solution.success
134135

135136
self.rhod = lambda z: interp1d(z_points, rhod_solution.y[0])(zpos(z))
136137
self.temp = lambda z: formulae.temperature(
137-
self.rhod(zpos(z)), self.thd(zpos(z))
138+
self.rhod(zpos(z)), self.thd(zpos(z), self.qv0(zpos(z)))
138139
)
139-
self.press = lambda z: formulae.pressure(
140-
self.rhod(zpos(z)), self.temp(zpos(z)), self.qv(zpos(z))
140+
self.press = lambda z, qv: formulae.pressure(
141+
self.rhod(zpos(z)), self.temp(zpos(z)), qv
141142
)
142143

143144
rhod_w_const = wmax_const * si.m / si.s * si.kg / si.m**3
@@ -147,6 +148,7 @@ def drhod_dz(z, rhod):
147148
)
148149

149150
self.nz_vec = arakawa_c.z_vector_coord((self.nz,))
151+
self.press0 = lambda z: self.press(z, self.qv0(zpos(z)))
150152

151153
@property
152154
def nz(self):

cleo_1dkid/libs/thermo/output_thermodynamics.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ class OutputThermodynamics:
9191
time (s).
9292
temp (OutputVariable):
9393
Temperature (K).
94-
rho (OutputVariable):
95-
Density of moist air (kg/m3).
94+
rhod (OutputVariable):
95+
Density of dry air (kg/m3).
9696
press (OutputVariable):
9797
Pressure (Pa).
9898
qvap (OutputVariable):
@@ -121,7 +121,7 @@ def __init__(self, shape, zhalf=None, xhalf=None, yhalf=None):
121121

122122
self.time = OutputVariable("time", "s", [shape[0]])
123123
self.temp = OutputVariable("temp", "K", shape)
124-
self.rho = OutputVariable("rho", "kg m-3", shape)
124+
self.rhod = OutputVariable("rhod", "kg m-3", shape)
125125
self.press = OutputVariable("press", "Pa", shape)
126126
self.qvap = OutputVariable("qvap", "kg/kg", shape)
127127
self.qcond = OutputVariable("qcond", "kg/kg", shape)
@@ -165,7 +165,7 @@ def output_thermodynamics(self, time: float, thermo: Thermodynamics):
165165
"""
166166
self.time.write(time)
167167
self.temp.write(thermo.temp)
168-
self.rho.write(thermo.rho)
168+
self.rhod.write(thermo.rhod)
169169
self.press.write(thermo.press)
170170
self.qvap.write(thermo.massmix_ratios["qvap"])
171171
self.qcond.write(thermo.massmix_ratios["qcond"])
@@ -212,7 +212,7 @@ def finalize(self):
212212
"""
213213
self.time.finalize()
214214
self.temp.finalize()
215-
self.rho.finalize()
215+
self.rhod.finalize()
216216
self.press.finalize()
217217
self.qvap.finalize()
218218
self.qcond.finalize()

cleo_1dkid/libs/thermo/thermodynamics.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class Thermodynamics:
3131
Parameters:
3232
temp (np.ndarray):
3333
Temperature (K).
34-
rho (np.ndarray):
35-
Density of moist air (kg/m3).
34+
rhod (np.ndarray):
35+
Density of dry air (kg/m3).
3636
press (np.ndarray):
3737
Pressure (Pa).
3838
qvap (np.ndarray):
@@ -51,8 +51,8 @@ class Thermodynamics:
5151
Attributes:
5252
temp (np.ndarray):
5353
Temperature (K).
54-
rho (np.ndarray):
55-
Density of moist air (kg/m3).
54+
rhod (np.ndarray):
55+
Density of dry air (kg/m3).
5656
press (np.ndarray):
5757
Pressure (Pa).
5858
massmix_ratios (dict):
@@ -71,7 +71,7 @@ class Thermodynamics:
7171
def __init__(
7272
self,
7373
temp: np.ndarray,
74-
rho: np.ndarray,
74+
rhod: np.ndarray,
7575
press: np.ndarray,
7676
qvap: np.ndarray,
7777
qcond: np.ndarray,
@@ -88,7 +88,7 @@ def __init__(
8888
Parameters:
8989
press (np.ndarray): Pressure (Pa).
9090
temp (np.ndarray): Temperature (K).
91-
rho (np.ndarray): Density of moist air (kg/m3)
91+
rhod (np.ndarray): Density of moist air (kg/m3)
9292
qvap (np.ndarray): Specific water vapor content (kg/kg)
9393
qcond (np.ndarray): Specific cloud water content (kg/kg)
9494
qice (np.ndarray): Specific cloud ice content (kg/kg)
@@ -100,7 +100,7 @@ def __init__(
100100
vvel (np.ndarray): meridional wind velocity, 'y', (m/s)
101101
"""
102102
self.temp = deepcopy(temp)
103-
self.rho = deepcopy(rho)
103+
self.rhod = deepcopy(rhod)
104104
self.press = deepcopy(press)
105105
self.massmix_ratios = {
106106
"qvap": deepcopy(qvap),
@@ -116,7 +116,7 @@ def __init__(
116116

117117
def print_state(self):
118118
print(self.temp)
119-
print(self.rho)
119+
print(self.rhod)
120120
print(self.press)
121121
print(self.massmix_ratios)
122122

cleo_1dkid/scripts/bash/inputfiles_cleo_1dkid.sh

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ isfigures=FALSE
2424
python=/work/bm1183/m300950/bin/envs/superdrops-in-action/bin/python
2525
path2initcondsscripts=${path2cleo1dkid}/libs/cleo_sdm/initconds
2626

27+
runtype=condevap_only
2728
nsupers_pergbxs=(256) # for superdroplet initial conditions
28-
alphas=(0 0.5 1.0) # for superdroplet initial conditions alpha sampling
29+
alphas=(0.5) # for superdroplet initial conditions alpha sampling
30+
numconc=150
2931

3032
### src_configs is list of absolute paths to source config files seperated by spaces
3133
### e.g. src_configs=("$HOME/config1" "$HOME/config2"), following lists are
32-
src_configs=("${path2cleo1dkid}/share/cleo_initial_conditions/1dkid/condevap_only/config.yaml"
33-
"${path2cleo1dkid}/share/cleo_initial_conditions/1dkid/fullscheme/config.yaml")
34+
src_configs=("${path2cleo1dkid}/share/cleo_initial_conditions/1dkid/${runtype}/config.yaml")
3435

3536
### IDs of ensemble members (diff superdrop initial conditions) for each src_configs to create
3637
if [[ "${start_id}" == "" || "${end_id}" == "" ]]
@@ -45,13 +46,11 @@ cleoconstants_filepath="${path2build}/_deps/cleo-src/libs/"
4546
grid_filename="${path2build}/share/dimlessGBxboundaries.dat"
4647

4748
### same files for all src_configs, different for run_ids
48-
initsupers_directory="${path2build}/share"
49+
initsupers_directory="${path2build}/share/share_${numconc}cm3"
4950

5051
### different for all src_configs and different for run_ids
51-
configs_directory=("${path2build}/tmp/condevap_only"
52-
"${path2build}/tmp/fullscheme")
53-
bin_directory=("${path2build}/bin/condevap_only"
54-
"${path2build}/bin/fullscheme")
52+
configs_directory=("${path2build}/tmp_${numconc}cm3/${runtype}")
53+
bin_directory=("${path2build}/bin_${numconc}cm3/${runtype}")
5554
### ---------------------------------------------------- ###
5655
### ---------------------------------------------------- ###
5756
### ---------------------------------------------------- ###
@@ -104,7 +103,7 @@ do
104103
initsupers_filename="${initsupers_directory}/dimlessSDsinit_${label}.dat"
105104
setup_filename="${bin_directory[i]}/setup_${label}.txt"
106105
zarrbasedir="${bin_directory[i]}/sol_${label}.zarr"
107-
echo "---- src ${i}, run number: ${m} ----"
106+
echo "---- src ${i}, run number: ${m}, numconc: ${numconc}cm^-3 ----"
108107
echo "---- nsupers ${nsupers_pergbxs[k]}, alpha ${alphas[l]} ----"
109108
echo "path to build directory: ${path2build}"
110109
echo "src config file: ${src_configfile}"
@@ -115,6 +114,7 @@ do
115114
echo "-- ${zarrbasedir}"
116115
echo "-- ${nsupers_pergbxs[k]}"
117116
echo "-- ${alphas[l]}"
117+
echo "-- ${numconc}"
118118

119119
echo "python create_config.py ${src_configfile} ${dest_configfile} [...]"
120120
${python} ${path2initcondsscripts}/create_config.py ${src_configfile} ${dest_configfile} \
@@ -124,7 +124,8 @@ do
124124
--setup_filename="${setup_filename}" \
125125
--zarrbasedir="${zarrbasedir}" \
126126
--nsupers_pergbx="${nsupers_pergbxs[k]}" \
127-
--alpha="${alphas[l]}"
127+
--alpha="${alphas[l]}" \
128+
--numconc="${numconc}"
128129
done
129130
done
130131
done

cleo_1dkid/scripts/bash/run_cleo_1dkid.sh

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
#SBATCH --nodes=1
55
#SBATCH --ntasks-per-node=1
66
#SBATCH --cpus-per-task=128
7-
#SBATCH --mem=20G
8-
#SBATCH --time=00:60:00
7+
#SBATCH --time=02:00:00
98
#SBATCH --mail-user=clara.bayley@mpimet.mpg.de
109
#SBATCH --mail-type=FAIL
1110
#SBATCH --account=bm1183
@@ -26,17 +25,16 @@ path2cleopythonbindings="${path2build}/_deps/cleo-build/cleo_python_bindings"
2625
python="/work/bm1183/m300950/bin/envs/superdrops-in-action/bin/python"
2726
pythonlibs="/work/bm1183/m300950/bin/envs/superdrops-in-action/lib/python3.13/site-packages"
2827

28+
runtype=condevap_only
2929
nsupers_pergbxs=(256) # for superdroplet initial conditions
30-
alphas=(0 0.5 1.0) # for superdroplet initial conditions alpha sampling
30+
alphas=(0.5) # for superdroplet initial conditions alpha sampling
31+
numconc=150
3132

3233
### loop over configs_directory for all different for run_ids
33-
configs_directory=("${path2build}/tmp/condevap_only"
34-
"${path2build}/tmp/fullscheme")
35-
run_labels=("condevap_only" "fullscheme")
36-
bin_directory=("${path2build}/bin/condevap_only"
37-
"${path2build}/bin/fullscheme") # Note! must match paths in config's 'outputdata'
38-
fig_directory=("${path2build}/bin/condevap_only"
39-
"${path2build}/bin/fullscheme")
34+
configs_directory=("${path2build}/tmp_${numconc}cm3/${runtype}")
35+
run_labels=("${runtype}")
36+
bin_directory=("${path2build}/bin_${numconc}cm3/${runtype}") # Note! must match paths in config's 'outputdata'
37+
fig_directory=("${path2build}/bin_${numconc}cm3/${runtype}")
4038

4139
### IDs of ensemble members (diff superdrop initial conditions) for each src_configs to create
4240
if [[ "${start_id}" == "" || "${end_id}" == "" ]]
@@ -93,7 +91,7 @@ do
9391
run_name="${run_labels[i]}_${label}"
9492
binpath="${bin_directory[i]}"
9593
figpath="${fig_directory[i]}"
96-
echo "---- src ${i}, run number: ${m} ----"
94+
echo "---- src ${i}, run number: ${m}, numconc: ${numconc}cm^-3 ----"
9795
echo "---- nsupers ${nsupers_pergbxs[k]}, alpha ${alphas[l]} ----"
9896
echo "--run_name=${run_name}"
9997
echo "--config_filename=${config_filename}"

0 commit comments

Comments
 (0)