diff --git a/CMakeLists.txt b/CMakeLists.txt index c81cd7dc7..271f7fbbc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,8 +19,14 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CXX_EXTENSIONS ON) # install Kokkos for project -message(STATUS "Using Kokkos installation from: ${CMAKE_SOURCE_DIR}/extern/kokkos") -add_subdirectory(${CMAKE_SOURCE_DIR}/extern/kokkos) +set(kokkospath ${CMAKE_SOURCE_DIR}/extern/kokkos) +message(STATUS "Using Kokkos installation from: ${kokkospath}") +add_subdirectory(${kokkospath}) + +# install yaml-cpp for project +set(yamlcpppath ${CMAKE_SOURCE_DIR}/extern/yaml-cpp) +message(STATUS "Using yaml-cpp installation from: ${yamlcpppath}") +add_subdirectory(${yamlcpppath}) # print default compiler flags message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}") diff --git a/docs/source/index.rst b/docs/source/index.rst index 9ecd6ebc3..57bfc8caa 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -31,6 +31,7 @@ Time to get involved! Start by :doc:`installing CLEO` and ex intro/intro usage/requirements + usage/extern usage/installation usage/examples usage/quickstart diff --git a/docs/source/pySD/pySD.rst b/docs/source/pySD/pySD.rst index f60d2df05..d7d061563 100644 --- a/docs/source/pySD/pySD.rst +++ b/docs/source/pySD/pySD.rst @@ -22,6 +22,7 @@ input files and processing the Zarr output from CLEO. thermobinary_src/thermobinary_src sdmout_src/sdmout_src cxx2py + readconfigfile editconfigfile readbinary writebinary diff --git a/docs/source/pySD/readconfigfile.rst b/docs/source/pySD/readconfigfile.rst new file mode 100644 index 000000000..0aa37f592 --- /dev/null +++ b/docs/source/pySD/readconfigfile.rst @@ -0,0 +1,5 @@ +READCONFIGFILE +============== + +.. automodule:: pySD.readconfigfile + :members: diff --git a/docs/source/usage/extern.rst b/docs/source/usage/extern.rst new file mode 100644 index 000000000..57e6ae21a --- /dev/null +++ b/docs/source/usage/extern.rst @@ -0,0 +1,31 @@ +External Libraries +================== + +CLEO depends upon Kokkos and may depend upon some additional external libraries such as YAC and +``yaml-cpp`` depending on your setup. These are automatically built using CMAKE and compiled if +required. + +.. note:: + The installation of YAC for CLEO is currently in development and may require some manual installation. + +Kokkos +------ +All builds of CLEO require Kokkos in order to implement thread parallelism. You can read more about +how we use Kokkos on :doc:`our page about Kokkos<../intro/kokkos>`. + +YAC +--- +YAC is required if CLEO couples to dynamics using YAC and/or uses MPI domain decompoisiton. You can +find more information about it from `its documentation: `_. + +TODO(all): Detail how to install YAC for CLEO. + +yaml-cpp +-------- +CLEO's ``initialise`` library depends on the ```yaml-cpp``` package to read and write YAML files. You +can find more information about it from `its repository: `_. + +CVODE +----- +CLEO's ``coupldyn_cvode`` library requires the SUNDIALS CVODE package. You can find more information +about it from `its webpage: `_. diff --git a/docs/source/usage/requirements.rst b/docs/source/usage/requirements.rst index 9967c3257..62a771588 100644 --- a/docs/source/usage/requirements.rst +++ b/docs/source/usage/requirements.rst @@ -63,9 +63,14 @@ You can install Python packages to an existing Conda (or Mamba) environment via: YAC --- -To use YAC some additional MPI, NetCDF and yaml libraries are required alongside the gcc compiler. +.. note:: + The installation of YAC for CLEO is currently in development and may require some manual installation. -You can load them on Levante via: +YAC is one of the :doc:`external libraries` which CLEO may require in order to +couple to dynamics and/or have MPI domain decomposition. + +YAC requires some additional MPI, NetCDF and yaml libraries alongside the gcc compiler. You can +load them on Levante via: .. code-block:: console diff --git a/examples/adiabaticparcel/as2017.py b/examples/adiabaticparcel/as2017.py index 98b456743..711f072b2 100644 --- a/examples/adiabaticparcel/as2017.py +++ b/examples/adiabaticparcel/as2017.py @@ -8,7 +8,7 @@ Author: Clara Bayley (CB) Additional Contributors: ----- -Last Modified: Friday 12th April 2024 +Last Modified: Thursday 18th April 2024 Modified By: CB ----- License: BSD 3-Clause "New" or "Revised" License @@ -80,30 +80,28 @@ # parameters to edit in model configuration and plotting params1 = { - "W_AVG": 1, - "T_HALF": 150, + "W_avg": 1, + "TAU_half": 150, "T_END": 300, "COUPLTSTEP": 1, "OBSTSTEP": 2, - "lwdth": 2, } params2 = { - "W_AVG": 0.5, - "T_HALF": 300, + "W_avg": 0.5, + "TAU_half": 300, "T_END": 600, "COUPLTSTEP": 1, "OBSTSTEP": 2, - "lwdth": 1, } params3 = { - "W_AVG": 0.002, - "T_HALF": 75000, + "W_avg": 0.002, + "TAU_half": 75000, "T_END": 150000, "COUPLTSTEP": 3, "OBSTSTEP": 750, - "lwdth": 0.5, } paramslist = [params1, params2, params3] +lwdths = [2, 1, 0.5] def displacement(time, w_avg, thalf): '''displacement z given velocity, w, is sinusoidal @@ -163,16 +161,16 @@ def displacement(time, w_avg, thalf): plt.close() fig, axs = plt.subplots(nrows=3, ncols=1, figsize=(5, 16)) - for params in paramslist: + for params, lwdth in zip(paramslist, lwdths): ### edit relevant setup file parameters params["zarrbasedir"] = binpath+"as2017_sol"+str(runnum)+".zarr" - params["setuptxt"] = binpath+"as2017_setup.txt" + params["setup_filename"] = binpath+"as2017_setup.txt" editconfigfile.edit_config_params(configfile, params) ### delete any existing dataset os.system("rm -rf "+params["zarrbasedir"]) - os.system("rm "+params["setuptxt"]) + os.system("rm "+params["setup_filename"]) ### run model os.chdir(path2build) @@ -197,18 +195,18 @@ def displacement(time, w_avg, thalf): supersat = thermo.supersaturation() time = pyzarr.get_time(dataset).secs sddata = pyzarr.get_supers(dataset, consts) - zprof = displacement(time, config["W_AVG"], config["T_HALF"]) + zprof = displacement(time, config["W_avg"], config["TAU_half"]) attrs = ["radius", "xi", "msol"] sd0 = sdtracing.attributes_for1superdroplet(sddata, 0, attrs) numconc = np.sum(sddata["xi"][0])/gbxs["domainvol"]/1e6 # [/cm^3] ### plot results - wlab = " = {:.1f}".format(config["W_AVG"]*100)+"cm s$^{-1}$" + wlab = " = {:.1f}".format(config["W_avg"]*100)+"cm s$^{-1}$" axs = as2017fig.condensation_validation_subplots(axs, time, sd0["radius"], supersat[:, 0, 0, 0], zprof, - lwdth=params["lwdth"], + lwdth=lwdth, lab=wlab) runnum += 1 diff --git a/examples/adiabaticparcel/as2017.sh b/examples/adiabaticparcel/as2017.sh index b54ab813a..91a6d8cd9 100755 --- a/examples/adiabaticparcel/as2017.sh +++ b/examples/adiabaticparcel/as2017.sh @@ -23,7 +23,7 @@ path2build=${HOME}/CLEO/build_adia0D/ executables="adia0D" pythonscript=${path2CLEO}/examples/adiabaticparcel/as2017.py -configfile=${path2CLEO}/examples/adiabaticparcel/src/config/as2017_config.txt +configfile=${path2CLEO}/examples/adiabaticparcel/src/config/as2017_config.yaml script_args="${configfile}" ### ---------------------------------------------------- ### ### ---------------------------------------------------- ### diff --git a/examples/adiabaticparcel/cuspbifurc.py b/examples/adiabaticparcel/cuspbifurc.py index b56d6ad96..1367718bc 100644 --- a/examples/adiabaticparcel/cuspbifurc.py +++ b/examples/adiabaticparcel/cuspbifurc.py @@ -6,7 +6,7 @@ Author: Clara Bayley (CB) Additional Contributors: ----- -Last Modified: Friday 12th April 2024 +Last Modified: Thursday 18th April 2024 Modified By: CB ----- License: BSD 3-Clause "New" or "Revised" License @@ -149,7 +149,7 @@ def displacement(time, w_avg, thalf): supersat = thermo.supersaturation() time = pyzarr.get_time(dataset).secs sddata = pyzarr.get_supers(dataset, consts) -zprof = displacement(time, config["W_AVG"], config["T_HALF"]) +zprof = displacement(time, config["W_avg"], config["TAU_half"]) ### plot results # sample drops to plot from whole range of SD ids @@ -169,5 +169,5 @@ def displacement(time, w_avg, thalf): thermo.temp[:, 0, 0, 0], supersat[:, 0, 0, 0], sddata.IONIC, sddata.MR_SOL, - config["W_AVG"], numconc, + config["W_avg"], numconc, savename2) diff --git a/examples/adiabaticparcel/cuspbifurc.sh b/examples/adiabaticparcel/cuspbifurc.sh index 3cf2aabdc..00acf5f90 100755 --- a/examples/adiabaticparcel/cuspbifurc.sh +++ b/examples/adiabaticparcel/cuspbifurc.sh @@ -23,7 +23,7 @@ path2build=${HOME}/CLEO/build_adia0D/ executables="adia0D" pythonscript=${path2CLEO}/examples/adiabaticparcel/cuspbifurc.py -configfile=${path2CLEO}/examples/adiabaticparcel/src/config/cuspbifurc_config.txt +configfile=${path2CLEO}/examples/adiabaticparcel/src/config/cuspbifurc_config.yaml script_args="${configfile}" ### ---------------------------------------------------- ### ### ---------------------------------------------------- ### diff --git a/examples/adiabaticparcel/src/config/as2017_config.txt b/examples/adiabaticparcel/src/config/as2017_config.txt deleted file mode 100644 index 77ab26a28..000000000 --- a/examples/adiabaticparcel/src/config/as2017_config.txt +++ /dev/null @@ -1,70 +0,0 @@ -/* - * ----- CLEO ----- - * File: as2017_config.txt - * Project: config - * Created Date: Friday 13th October 2023 - * Author: Clara Bayley (CB) - * Additional Contributors: - * ----- - * Last Modified: Monday 11th March 2024 - * Modified By: CB - * ----- - * License: BSD 3-Clause "New" or "Revised" License - * https://opensource.org/licenses/BSD-3-Clause - * ----- - * Copyright (c) 2023 MPI-M, Clara Bayley - * ----- - * File Description: - * configuration input parameters for CLEO adiabatic parcel example - */ - - -### Initialisation parameters ### -constants_filename = ../libs/cleoconstants.hpp # name of file for values of physical constants -initsupers_filename = ./share/as2017_dimlessSDsinit.dat # binary filename for initialisation of SDs -grid_filename = ./share/as2017_dimlessGBxboundaries.dat # binary filename for initialisation of GBxs / GbxMaps - -### Output Data parameters ### -setuptxt = /home/m/m300950/CLEO/build_adia0D//bin/as2017_setup.txt# .txt filename to copy configuration to -stats_filename = /home/m/m300950/CLEO/build0/bin/as2017_stats.txt # .txt file to output runtime statistics to -zarrbasedir = /home/m/m300950/CLEO/build_adia0D//bin/as2017_sol8.zarr# zarr store base directory -maxchunk = 1250000 # maximum no. of elements in chunks of zarr store array - -### SDM Runtime parameters ### -# domain setup # -nspacedims = 0 # no. of spatial dimensions to model -ngbxs = 1 # total number of Gbxs -totnsupers = 64 # (initial) total no. of SDs - -# timestepping # -CONDTSTEP = 1 # time between SD condensation events [s] -COLLTSTEP = 1 # time between SD collision events [s] -MOTIONTSTEP = 1 # time between SDM motion [s] -COUPLTSTEP = 3 # time between dynamic couplings [s] -OBSTSTEP = 750 # time between SDM observations [s] -T_END = 150000 # time span of integration from 0s to T_END [s] - -# microphysics # -cond_iters = 2 # no. iterations of Newton Raphson Method before testing for convergence -cond_SUBTSTEP = 0.1 # smallest timestep in cases where substepping occurs [s] -cond_rtol = 0.0 # relative tolerance for implicit euler integration -cond_atol = 0.01 # abolute tolerance for implicit euler integration - -# superdroplets # -doAlterThermo = true # enable condensation to alter the thermodynamic state - -### Coupled Dynamics Solver Parameters ### -# type of coupling # -thermosolver = cvode # dynamics solver to configure - -### CVODE ODE solver paramters ### -# initial (uniform) thermodynamic conditions # -P_INIT = 100000.0 # initial pressure [Pa] -TEMP_INIT = 273.15 # initial parcel temperature [T] -relh_init = 98.0 # initial relative humidity (%) unphyical < 0.0 in this setup to prevent wetradius initialisation - -# ODE solver parameters # -W_AVG = 0.002 # average amplitude of sinusoidal vertical parcel speed [m/s] (dP/dt ~ w*dP/dz) -T_HALF = 75000 # timescale for w sinusoid, tau = THALF/pi [s] -cvode_rtol = 1e-6 # relative tolerance for [P, T, qv, qc] ODEs integration -cvode_atol = 1e-6 # absolute tolerance for [P, T, qv, qc] ODEs integration diff --git a/examples/adiabaticparcel/src/config/as2017_config.yaml b/examples/adiabaticparcel/src/config/as2017_config.yaml new file mode 100644 index 000000000..31409ff37 --- /dev/null +++ b/examples/adiabaticparcel/src/config/as2017_config.yaml @@ -0,0 +1,74 @@ +# ----- CLEO ----- +# File: as2017_config.yaml +# Project: config +# Created Date: Wednesday 17th April 2024 +# Author: Clara Bayley (CB) +# Additional Contributors: +# ----- +# Last Modified: Wednesday 17th April 2024 +# Modified By: CB +# ----- +# License: BSD 3-Clause "New" or "Revised" License +# https://opensource.org/licenses/BSD-3-Clause +# ----- +# Copyright (c) 2023 MPI-M, Clara Bayley +# ----- +# File Description: +# Configuration file for CLEO SDM coupled to a CVODE dynamics solver for an adiabatic parcel example +# Note: The inital superdroplets data read from file "initsupers_filename" can be made with +# CLEO's pySD module (see Python script "create_initsuperdropsbinary_script.py" for usage). +# Likewise the "grid_filename" can be made using pySD (see "create_gbxboundariesbinary_script.py"), +# and so can the thermodynamics files when using coupled thermodynamics "fromfile". +# + +### Initialisation Parameters ### +inputfiles: + constants_filename: ../libs/cleoconstants.hpp # name of file for values of physical constants + grid_filename: ./share/as2017_dimlessGBxboundaries.dat # binary filename for initialisation of GBxs / GbxMaps + +initsupers: + type: frombinary # type of initialisation of super-droplets + initsupers_filename: ./share/as2017_dimlessSDsinit.dat # binary filename for initialisation of SDs + totnsupers: 64 # initial total no. of SDs + +### Output Parameters ### +outputdata: + setup_filename: /home/m/m300950/CLEO/build_adia0D//bin/as2017_setup.txt # .txt filename to copy configuration to + stats_filename: /home/m/m300950/CLEO/build_adia0D//bin/as2017_stats.txt # .txt file to output runtime statistics to + zarrbasedir: /home/m/m300950/CLEO/build_adia0D//bin/as2017_sol8.zarr # zarr store base directory + maxchunk: 2500000 # maximum no. of elements in chunks of zarr store array + +### SDM Runtime Parameters ### +domain: + nspacedims: 0 # no. of spatial dimensions to model + ngbxs: 1 # total number of Gbxs + +timesteps: + CONDTSTEP: 1 # time between SD condensation [s] + COLLTSTEP: 1 # time between SD collision [s] + MOTIONTSTEP: 1 # time between SDM motion [s] + COUPLTSTEP: 3 # time between dynamic couplings [s] + OBSTSTEP: 750 # time between SDM observations [s] + T_END: 150000 # time span of integration from 0s to T_END [s] + +### Microphysics Parameters ### +microphysics: + condensation: + do_alter_thermo: true # true = cond/evap alters the thermodynamic state + niters: 2 # no. iterations of Newton Raphson Method before testing for convergence + SUBTSTEP: 0.1 # smallest subtimestep in cases of substepping [s] + rtol: 0.0 # relative tolerance for implicit Euler integration + atol: 0.01 # abolute tolerance for implicit Euler integration + +### Coupled Dynamics Parameters ### +coupled_dynamics: + type: cvode # type of coupled dynamics to configure + # initial (uniform) thermodynamic conditions # + P_init: 100000.0 # initial pressure [Pa] + TEMP_init: 273.15 # initial temperature [T] + relh_init: 98.0 # initial relative humidity (%) + # ODE solver parameters # + W_avg: 0.002 # average amplitude of sinusoidal w [m/s] (dP/dt ~ w*dP/dz) + TAU_half: 75000 # timescale for w sinusoid, tau_half = TAU_half/pi [s] + rtol: 1e-6 # relative tolerance for integration of [P, T, qv, qc] ODEs + atol: 1e-6 # relative tolerance for integration of [P, T, qv, qc] ODEs diff --git a/examples/adiabaticparcel/src/config/cuspbifurc_config.txt b/examples/adiabaticparcel/src/config/cuspbifurc_config.txt deleted file mode 100644 index 968ca2240..000000000 --- a/examples/adiabaticparcel/src/config/cuspbifurc_config.txt +++ /dev/null @@ -1,70 +0,0 @@ -/* - * ----- CLEO ----- - * File: cuspbifurc_config.txt - * Project: config - * Created Date: Friday 13th October 2023 - * Author: Clara Bayley (CB) - * Additional Contributors: - * ----- - * Last Modified: Tuesday 9th January 2024 - * Modified By: CB - * ----- - * License: BSD 3-Clause "New" or "Revised" License - * https://opensource.org/licenses/BSD-3-Clause - * ----- - * Copyright (c) 2023 MPI-M, Clara Bayley - * ----- - * File Description: - * configuration input parameters for CLEO cusp bifurcation example - */ - - -### Initialisation parameters ### -constants_filename = ../libs/cleoconstants.hpp # name of file for values of physical constants -initsupers_filename = ./share/cuspbifurc_dimlessSDsinit.dat # binary filename for initialisation of SDs -grid_filename = ./share/cuspbifurc_dimlessGBxboundaries.dat # binary filename for initialisation of GBxs / GbxMaps - -### Output Data parameters ### -setuptxt = ./bin/cuspbifurc_setup.txt # .txt filename to copy configuration to -stats_filename = ./bin/cuspbifurc_stats.txt # .txt file to output runtime statistics to -zarrbasedir = ./bin/cuspbifurc_sol.zarr # zarr store base directory -maxchunk = 1250000 # maximum no. of elements in chunks of zarr store array - -### SDM Runtime parameters ### -# domain setup # -nspacedims = 0 # no. of spatial dimensions to model -ngbxs = 1 # total number of Gbxs -totnsupers = 1 # (initial) total no. of SDs - -# timestepping # -CONDTSTEP = 0.01 # time between SD condensation events [s] -COLLTSTEP = 0.1 # time between SD collision events [s] -MOTIONTSTEP = 0.5 # time between SDM motion [s] -COUPLTSTEP = 0.5 # time between dynamic couplings [s] -OBSTSTEP = 5 # time between SDM observations [s] -T_END = 150000 # time span of integration from 0s to T_END [s] - -# microphysics # -cond_iters = 10 # no. iterations of Newton Raphson Method before testing for convergence -cond_SUBTSTEP = 0.1 # smallest timestep in cases where substepping occurs [s] -cond_rtol = 0.0 # relative tolerance for implicit euler integration -cond_atol = 0.01 # abolute tolerance for implicit euler integration - -# superdroplets # -doAlterThermo = true # enable condensation to alter the thermodynamic state - -### Coupled Dynamics Solver Parameters ### -# type of coupling # -thermosolver = cvode # dynamics solver to configure - -### CVODE ODE solver paramters ### -# initial (uniform) thermodynamic conditions # -P_INIT = 100000.0 # initial pressure [Pa] -TEMP_INIT = 298.15 # initial parcel temperature [T] -relh_init = 98.0 # initial relative humidity (%) unphyical < 0.0 in this setup to prevent wetradius initialisation - -# ODE solver parameters # -W_AVG = 0.002 # average amplitude of sinusoidal vertical parcel speed [m/s] (dP/dt ~ w*dP/dz) -T_HALF = 75000 # timescale for w sinusoid, tau = THALF/pi [s] -cvode_rtol = 1e-6 # relative tolerance for [P, T, qv, qc] ODEs integration -cvode_atol = 1e-6 # absolute tolerance for [P, T, qv, qc] ODEs integration diff --git a/examples/adiabaticparcel/src/config/cuspbifurc_config.yaml b/examples/adiabaticparcel/src/config/cuspbifurc_config.yaml new file mode 100644 index 000000000..74cedb879 --- /dev/null +++ b/examples/adiabaticparcel/src/config/cuspbifurc_config.yaml @@ -0,0 +1,75 @@ +--- +# ----- CLEO ----- +# File: cusbifurc_config.yaml +# Project: config +# Created Date: Wednesday 17th April 2024 +# Author: Clara Bayley (CB) +# Additional Contributors: +# ----- +# Last Modified: Wednesday 17th April 2024 +# Modified By: CB +# ----- +# License: BSD 3-Clause "New" or "Revised" License +# https://opensource.org/licenses/BSD-3-Clause +# ----- +# Copyright (c) 2023 MPI-M, Clara Bayley +# ----- +# File Description: +# Configuration file for CLEO SDM coupled to a CVODE dynamics solver for an adiabatic parcel example +# Note: The inital superdroplets data read from file "initsupers_filename" can be made with +# CLEO's pySD module (see Python script "create_initsuperdropsbinary_script.py" for usage). +# Likewise the "grid_filename" can be made using pySD (see "create_gbxboundariesbinary_script.py"), +# and so can the thermodynamics files when using coupled thermodynamics "fromfile". +# + +### Initialisation Parameters ### +inputfiles: + constants_filename : ../libs/cleoconstants.hpp # name of file for values of physical constants + grid_filename : ./share/cuspbifurc_dimlessGBxboundaries.dat # binary filename for initialisation of GBxs / GbxMaps + +initsupers: + type : frombinary # type of initialisation of super-droplets + initsupers_filename : ./share/cuspbifurc_dimlessSDsinit.dat # binary filename for initialisation of SDs + totnsupers : 1 # initial total no. of SDs + +### Output Parameters ### +outputdata: + setup_filename : ./bin/cuspbifurc_setup.txt # .txt filename to copy configuration to + stats_filename : ./bin/cuspbifurc_stats.txt # .txt file to output runtime statistics to + zarrbasedir : ./bin/cuspbifurc_sol.zarr # zarr store base directory + maxchunk : 2500000 # maximum no. of elements in chunks of zarr store array + +### SDM Runtime Parameters ### +domain: + nspacedims : 0 # no. of spatial dimensions to model + ngbxs : 1 # total number of Gbxs + +timesteps: + CONDTSTEP : 0.01 # time between SD condensation [s] + COLLTSTEP : 0.1 # time between SD collision [s] + MOTIONTSTEP : 0.5 # time between SDM motion [s] + COUPLTSTEP : 0.5 # time between dynamic couplings [s] + OBSTSTEP : 5 # time between SDM observations [s] + T_END : 150000 # time span of integration from 0s to T_END [s] + +### Microphysics Parameters ### +microphysics: + condensation: + do_alter_thermo : true # true = cond/evap alters the thermodynamic state + niters : 10 # no. iterations of Newton Raphson Method before testing for convergence + SUBTSTEP : 0.1 # smallest subtimestep in cases of substepping [s] + rtol : 0.0 # relative tolerance for implicit Euler integration + atol : 0.01 # abolute tolerance for implicit Euler integration + +### Coupled Dynamics Parameters ### +coupled_dynamics: + type : cvode # type of coupled dynamics to configure + # initial (uniform) thermodynamic conditions # + P_init : 100000.0 # initial pressure [Pa] + TEMP_init : 298.15 # initial temperature [T] + relh_init : 98.0 # initial relative humidity (%) + # ODE solver parameters # + W_avg : 0.002 # average amplitude of sinusoidal w [m/s] (dP/dt ~ w*dP/dz) + TAU_half : 75000 # timescale for w sinusoid, tau_half = TAU_half/pi [s] + rtol : 1e-6 # relative tolerance for integration of [P, T, qv, qc] ODEs + atol : 1e-6 # relative tolerance for integration of [P, T, qv, qc] ODEs diff --git a/examples/adiabaticparcel/src/main_adia0D.cpp b/examples/adiabaticparcel/src/main_adia0D.cpp index 58ceda4aa..5c8521c8d 100644 --- a/examples/adiabaticparcel/src/main_adia0D.cpp +++ b/examples/adiabaticparcel/src/main_adia0D.cpp @@ -9,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Tuesday 16th April 2024 + * Last Modified: Wednesday 17th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -17,7 +17,7 @@ * ----- * runs the CLEO super-droplet model (SDM) for adiabatic parcel model example. * After make/compiling, execute for example via: - * ./src/adia0D ../src/config/config.txt + * ./src/adia0D ../src/config/config.yaml */ #include @@ -55,18 +55,19 @@ #include "zarr/fsstore.hpp" inline CoupledDynamics auto create_coupldyn(const Config &config, const unsigned int couplstep) { - return CvodeDynamics(config, couplstep, &step2dimlesstime); + return CvodeDynamics(config.get_cvodedynamics(), couplstep, &step2dimlesstime); } inline InitialConditions auto create_initconds(const Config &config) { - const InitSupersFromBinary initsupers(config); - const InitGbxsCvode initgbxs(config); + const InitSupersFromBinary initsupers(config.get_initsupersfrombinary()); + const InitGbxsCvode initgbxs(config.get_cvodedynamics()); return InitConds(initsupers, initgbxs); } inline GridboxMaps auto create_gbxmaps(const Config &config) { - const auto gbxmaps = create_cartesian_maps(config.ngbxs, config.nspacedims, config.grid_filename); + const auto gbxmaps = create_cartesian_maps(config.get_ngbxs(), config.get_nspacedims(), + config.get_grid_filename()); return gbxmaps; } @@ -79,10 +80,10 @@ inline auto create_movement(const CartesianMaps &gbxmaps) { inline MicrophysicalProcess auto create_microphysics(const Config &config, const Timesteps &tsteps) { - const MicrophysicalProcess auto cond = Condensation( - tsteps.get_condstep(), config.doAlterThermo, config.cond_iters, &step2dimlesstime, - config.cond_rtol, config.cond_atol, config.cond_SUBTSTEP, &realtime2dimless); - return cond; + const auto c = config.get_condensation(); + + return Condensation(tsteps.get_condstep(), &step2dimlesstime, c.do_alter_thermo, c.niters, c.rtol, + c.atol, c.SUBTSTEP, &realtime2dimless); } template @@ -101,16 +102,17 @@ inline Observer auto create_superdrops_observer(const unsigned int interval, template inline Observer auto create_observer(const Config &config, const Timesteps &tsteps, Dataset &dataset) { - const auto obsstep = (unsigned int)tsteps.get_obsstep(); - const auto maxchunk = int{config.maxchunk}; + const auto obsstep = tsteps.get_obsstep(); + const auto maxchunk = config.get_maxchunk(); + const auto ngbxs = config.get_ngbxs(); const Observer auto obs1 = StreamOutObserver(obsstep * 10, &step2realtime); const Observer auto obs2 = TimeObserver(obsstep, dataset, maxchunk, &step2dimlesstime); - const Observer auto obs3 = GbxindexObserver(dataset, maxchunk, config.ngbxs); + const Observer auto obs3 = GbxindexObserver(dataset, maxchunk, ngbxs); - const Observer auto obs4 = StateObserver(obsstep, dataset, maxchunk, config.ngbxs); + const Observer auto obs4 = StateObserver(obsstep, dataset, maxchunk, ngbxs); const Observer auto obs5 = create_superdrops_observer(obsstep, dataset, maxchunk); @@ -136,12 +138,12 @@ int main(int argc, char *argv[]) { Kokkos::Timer kokkostimer; /* Read input parameters from configuration file(s) */ - const std::string_view config_filename(argv[1]); // path to configuration file + const std::filesystem::path config_filename(argv[1]); // path to configuration file const Config config(config_filename); - const Timesteps tsteps(config); // timesteps for model (e.g. coupling and end time) + const Timesteps tsteps(config.get_timesteps()); /* Create Xarray dataset wit Zarr backend for writing output data to a store */ - auto store = FSStore(config.zarrbasedir); + auto store = FSStore(config.get_zarrbasedir()); auto dataset = Dataset(store); /* Create coupldyn solver and coupling between coupldyn and SDM */ diff --git a/examples/boxmodelcollisions/golovin/src/main_golcolls.cpp b/examples/boxmodelcollisions/golovin/src/main_golcolls.cpp index 74790fb16..0e27f9498 100644 --- a/examples/boxmodelcollisions/golovin/src/main_golcolls.cpp +++ b/examples/boxmodelcollisions/golovin/src/main_golcolls.cpp @@ -9,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Tuesday 16th April 2024 + * Last Modified: Wednesday 17th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -18,7 +18,7 @@ * File Description: * runs the CLEO super-droplet model (SDM) for 0-D box model with Golovin's kernel. * After make/compiling, execute for example via: - * ./src/golcolls ../src/config/config.txt + * ./src/golcolls ../src/config/config.yaml */ #include @@ -57,14 +57,15 @@ #include "zarr/fsstore.hpp" inline InitialConditions auto create_initconds(const Config &config) { - const InitSupersFromBinary initsupers(config); - const InitGbxsNull initgbxs(config); + const InitSupersFromBinary initsupers(config.get_initsupersfrombinary()); + const InitGbxsNull initgbxs(config.get_ngbxs()); return InitConds(initsupers, initgbxs); } inline GridboxMaps auto create_gbxmaps(const Config &config) { - const auto gbxmaps = create_cartesian_maps(config.ngbxs, config.nspacedims, config.grid_filename); + const auto gbxmaps = create_cartesian_maps(config.get_ngbxs(), config.get_nspacedims(), + config.get_grid_filename()); return gbxmaps; } @@ -97,8 +98,8 @@ inline Observer auto create_superdrops_observer(const unsigned int interval, template inline Observer auto create_observer(const Config &config, const Timesteps &tsteps, Dataset &dataset) { - const auto obsstep = (unsigned int)tsteps.get_obsstep(); - const auto maxchunk = int{config.maxchunk}; + const auto obsstep = tsteps.get_obsstep(); + const auto maxchunk = config.get_maxchunk(); const Observer auto obs0 = StreamOutObserver(obsstep, &step2realtime); @@ -128,12 +129,12 @@ int main(int argc, char *argv[]) { Kokkos::Timer kokkostimer; /* Read input parameters from configuration file(s) */ - const std::string_view config_filename(argv[1]); // path to configuration file + const std::filesystem::path config_filename(argv[1]); // path to configuration file const Config config(config_filename); - const Timesteps tsteps(config); // timesteps for model (e.g. coupling and end time) + const Timesteps tsteps(config.get_timesteps()); /* Create Xarray dataset wit Zarr backend for writing output data to a store */ - auto store = FSStore(config.zarrbasedir); + auto store = FSStore(config.get_zarrbasedir()); auto dataset = Dataset(store); /* Create coupldyn solver and coupling between coupldyn and SDM */ diff --git a/examples/boxmodelcollisions/long/src/main_longcolls.cpp b/examples/boxmodelcollisions/long/src/main_longcolls.cpp index 58da4169c..66035eb6b 100644 --- a/examples/boxmodelcollisions/long/src/main_longcolls.cpp +++ b/examples/boxmodelcollisions/long/src/main_longcolls.cpp @@ -9,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Tuesday 16th April 2024 + * Last Modified: Thursday 18th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -18,7 +18,7 @@ * File Description: * runs the CLEO super-droplet model (SDM) for 0-D box model with Long's kernel. * After make/compiling, execute for example via: - * ./src/longcolls ../src/config/config.tx + * ./src/longcolls ../src/config/config.yaml */ #include @@ -57,14 +57,15 @@ #include "zarr/fsstore.hpp" inline InitialConditions auto create_initconds(const Config &config) { - const InitSupersFromBinary initsupers(config); - const InitGbxsNull initgbxs(config); + const InitSupersFromBinary initsupers(config.get_initsupersfrombinary()); + const InitGbxsNull initgbxs(config.get_ngbxs()); return InitConds(initsupers, initgbxs); } inline GridboxMaps auto create_gbxmaps(const Config &config) { - const auto gbxmaps = create_cartesian_maps(config.ngbxs, config.nspacedims, config.grid_filename); + const auto gbxmaps = create_cartesian_maps(config.get_ngbxs(), config.get_nspacedims(), + config.get_grid_filename()); return gbxmaps; } @@ -97,8 +98,8 @@ inline Observer auto create_superdrops_observer(const unsigned int interval, template inline Observer auto create_observer(const Config &config, const Timesteps &tsteps, Dataset &dataset) { - const auto obsstep = (unsigned int)tsteps.get_obsstep(); - const auto maxchunk = int{config.maxchunk}; + const auto obsstep = tsteps.get_obsstep(); + const auto maxchunk = config.get_maxchunk(); const Observer auto obs0 = StreamOutObserver(obsstep, &step2realtime); @@ -128,12 +129,12 @@ int main(int argc, char *argv[]) { Kokkos::Timer kokkostimer; /* Read input parameters from configuration file(s) */ - const std::string_view config_filename(argv[1]); // path to configuration file + const std::filesystem::path config_filename(argv[1]); // path to configuration file const Config config(config_filename); - const Timesteps tsteps(config); // timesteps for model (e.g. coupling and end time) + const Timesteps tsteps(config.get_timesteps()); /* Create Xarray dataset wit Zarr backend for writing output data to a store */ - auto store = FSStore(config.zarrbasedir); + auto store = FSStore(config.get_zarrbasedir()); auto dataset = Dataset(store); /* Create coupldyn solver and coupling between coupldyn and SDM */ diff --git a/examples/boxmodelcollisions/lowlist/src/main_lowlistcolls.cpp b/examples/boxmodelcollisions/lowlist/src/main_lowlistcolls.cpp index 47fa81b63..6ba18e1ca 100644 --- a/examples/boxmodelcollisions/lowlist/src/main_lowlistcolls.cpp +++ b/examples/boxmodelcollisions/lowlist/src/main_lowlistcolls.cpp @@ -9,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Tuesday 16th April 2024 + * Last Modified: Wednesday 17th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -18,7 +18,7 @@ * File Description: * runs the CLEO super-droplet model (SDM) for 0-D box model with Low and List's kernel. * After make/compiling, execute for example via: - * ./src/lowlistcolls ../src/config/config.txt + * ./src/lowlistcolls ../src/config/config.yaml */ #include @@ -57,14 +57,15 @@ #include "zarr/fsstore.hpp" inline InitialConditions auto create_initconds(const Config &config) { - const InitSupersFromBinary initsupers(config); - const InitGbxsNull initgbxs(config); + const InitSupersFromBinary initsupers(config.get_initsupersfrombinary()); + const InitGbxsNull initgbxs(config.get_ngbxs()); return InitConds(initsupers, initgbxs); } inline GridboxMaps auto create_gbxmaps(const Config &config) { - const auto gbxmaps = create_cartesian_maps(config.ngbxs, config.nspacedims, config.grid_filename); + const auto gbxmaps = create_cartesian_maps(config.get_ngbxs(), config.get_nspacedims(), + config.get_grid_filename()); return gbxmaps; } @@ -97,8 +98,8 @@ inline Observer auto create_superdrops_observer(const unsigned int interval, template inline Observer auto create_observer(const Config &config, const Timesteps &tsteps, Dataset &dataset) { - const auto obsstep = (unsigned int)tsteps.get_obsstep(); - const auto maxchunk = int{config.maxchunk}; + const auto obsstep = tsteps.get_obsstep(); + const auto maxchunk = config.get_maxchunk(); const Observer auto obs0 = StreamOutObserver(obsstep, &step2realtime); @@ -128,12 +129,12 @@ int main(int argc, char *argv[]) { Kokkos::Timer kokkostimer; /* Read input parameters from configuration file(s) */ - const std::string_view config_filename(argv[1]); // path to configuration file + const std::filesystem::path config_filename(argv[1]); // path to configuration file const Config config(config_filename); - const Timesteps tsteps(config); // timesteps for model (e.g. coupling and end time) + const Timesteps tsteps(config.get_timesteps()); /* Create Xarray dataset wit Zarr backend for writing output data to a store */ - auto store = FSStore(config.zarrbasedir); + auto store = FSStore(config.get_zarrbasedir()); auto dataset = Dataset(store); /* Create coupldyn solver and coupling between coupldyn and SDM */ diff --git a/examples/boxmodelcollisions/shima2009.sh b/examples/boxmodelcollisions/shima2009.sh index 95126bd45..122debf89 100755 --- a/examples/boxmodelcollisions/shima2009.sh +++ b/examples/boxmodelcollisions/shima2009.sh @@ -24,7 +24,7 @@ path2build=${HOME}/CLEO/build_shima2009/ executables="golcolls longcolls lowlistcolls" pythonscript=${path2CLEO}/examples/boxmodelcollisions/shima2009.py -configfile=${path2CLEO}/examples/boxmodelcollisions/shima2009_config.txt +configfile=${path2CLEO}/examples/boxmodelcollisions/shima2009_config.yaml script_args="${configfile} golovin long lowlist" ### ---------------------------------------------------- ### ### ---------------------------------------------------- ### diff --git a/examples/boxmodelcollisions/shima2009_config.txt b/examples/boxmodelcollisions/shima2009_config.txt deleted file mode 100644 index ef5dd3c9d..000000000 --- a/examples/boxmodelcollisions/shima2009_config.txt +++ /dev/null @@ -1,58 +0,0 @@ -/* - * ----- CLEO ----- - * File: shima2009_config.txt - * Project: boxmodelcollisions - * Created Date: Friday 17th November 2023 - * Author: Clara Bayley (CB) - * Additional Contributors: - * ----- - * Last Modified: Tuesday 9th January 2024 - * Modified By: CB - * ----- - * License: BSD 3-Clause "New" or "Revised" License - * https://opensource.org/licenses/BSD-3-Clause - * ----- - * Copyright (c) 2023 MPI-M, Clara Bayley - * ----- - * File Description: - * configuration input parameters for CLEO to run validation of - */ - - -### Initialisation parameters ### -constants_filename = ../libs/cleoconstants.hpp # name of file for values of physical constants -initsupers_filename = ./share/shima2009_dimlessSDsinit.dat # binary filename for initialisation of SDs -grid_filename = ./share/shima2009_dimlessGBxboundaries.dat # binary filename for initialisation of GBxs / GbxMaps - -### Output Data parameters ### -setuptxt = ./bin/shima2009_setup.txt # .txt filename to copy configuration to -stats_filename = ./bin/shima2009_stats.txt # .txt file to output runtime statistics to -zarrbasedir = ./bin/shima2009_sol.zarr # zarr store base directory -maxchunk = 1250000 # maximum no. of elements in chunks of zarr store array - -### SDM Runtime parameters ### -# domain setup # -nspacedims = 0 # no. of spatial dimensions to model -ngbxs = 1 # total number of Gbxs -totnsupers = 4096 # (initial) total no. of SDs - -# timestepping # -CONDTSTEP = 2 # time between SD condensation events [s] -COLLTSTEP = 1 # time between SD collision events [s] -MOTIONTSTEP = 5 # time between SDM motion [s] -COUPLTSTEP = 2000 # time between dynamic couplings [s] -OBSTSTEP = 200 # time between SDM observations [s] -T_END = 4000 # time span of integration from 0s to T_END [s] - -# microphysics # -cond_iters = 2 # no. iterations of Newton Raphson Method before testing for convergence -cond_SUBTSTEP = 0.1 # smallest timestep in cases where substepping occurs [s] -cond_rtol = 0.001 # relative tolerance for implicit euler integration -cond_atol = 0.001 # abolute tolerance for implicit euler integration - -# superdroplets # -doAlterThermo = false # enable condensation to alter the thermodynamic state - -### Coupled Dynamics Solver Parameters ### -# type of coupling # -thermosolver = null # dynamics solver to configure diff --git a/examples/boxmodelcollisions/shima2009_config.yaml b/examples/boxmodelcollisions/shima2009_config.yaml new file mode 100644 index 000000000..1769c3b3f --- /dev/null +++ b/examples/boxmodelcollisions/shima2009_config.yaml @@ -0,0 +1,53 @@ +--- +# ----- CLEO ----- +# File: shima2009_config.yaml +# Project: config +# Created Date: Wednesday 17th April 2024 +# Author: Clara Bayley (CB) +# Additional Contributors: +# ----- +# Last Modified: Wednesday 17th April 2024 +# Modified By: CB +# ----- +# License: BSD 3-Clause "New" or "Revised" License +# https://opensource.org/licenses/BSD-3-Clause +# ----- +# Copyright (c) 2023 MPI-M, Clara Bayley +# ----- +# File Description: +# Configuration file for example of collisions in CLEO SDM 0-D box model. +# Note: The inital superdroplets data read from file "initsupers_filename" can be made with +# CLEO's pySD module (see Python script "create_initsuperdropsbinary_script.py" for usage). +# Likewise the "grid_filename" can be made using pySD (see "create_gbxboundariesbinary_script.py"), +# and so can the thermodynamics files when using coupled thermodynamics "fromfile". +# + +### Initialisation Parameters ### +inputfiles: + constants_filename : ../libs/cleoconstants.hpp # name of file for values of physical constants + grid_filename : ./share/shima2009_dimlessGBxboundaries.dat # binary filename for initialisation of GBxs / GbxMaps + +initsupers: + type : frombinary # type of initialisation of super-droplets + initsupers_filename : ./share/shima2009_dimlessSDsinit.dat # binary filename for initialisation of SDs + totnsupers : 4096 # initial total no. of SDs + +### Output Parameters ### +outputdata: + setup_filename : ./bin/shima2009_setup.txt # .txt filename to copy configuration to + stats_filename : ./bin/shima2009_stats.txt # .txt file to output runtime statistics to + zarrbasedir : ./bin/shima2009_sol.zarr # zarr store base directory + maxchunk : 2500000 # maximum no. of elements in chunks of zarr store array + +### SDM Runtime Parameters ### +domain: + nspacedims : 0 # no. of spatial dimensions to model + ngbxs : 1 # total number of Gbxs + +timesteps: + CONDTSTEP : 200 # time between SD condensation [s] + COLLTSTEP : 1 # time between SD collision [s] + MOTIONTSTEP : 200 # time between SDM motion [s] + COUPLTSTEP : 2000 # time between dynamic couplings [s] + OBSTSTEP : 200 # time between SDM observations [s] + T_END : 4000 # time span of integration from 0s to T_END [s] diff --git a/examples/constthermo2d/constthermo2d.sh b/examples/constthermo2d/constthermo2d.sh index 23f52c345..5fc8c559d 100755 --- a/examples/constthermo2d/constthermo2d.sh +++ b/examples/constthermo2d/constthermo2d.sh @@ -24,7 +24,7 @@ path2build=${HOME}/CLEO/build_const2D/ executables="const2D" pythonscript=${path2CLEO}/examples/constthermo2d/constthermo2d.py -configfile=${path2CLEO}/examples/constthermo2d/src/config/const2d_config.txt +configfile=${path2CLEO}/examples/constthermo2d/src/config/const2d_config.yaml script_args="${configfile}" ### ---------------------------------------------------- ### ### ---------------------------------------------------- ### diff --git a/examples/constthermo2d/src/config/const2d_config.txt b/examples/constthermo2d/src/config/const2d_config.txt deleted file mode 100644 index 6219e91cd..000000000 --- a/examples/constthermo2d/src/config/const2d_config.txt +++ /dev/null @@ -1,67 +0,0 @@ -/* - * ----- CLEO ----- - * File: const2d_config.txt - * Project: config - * Created Date: Tuesday 21st November 2023 - * Author: Clara Bayley (CB) - * Additional Contributors: - * ----- - * Last Modified: Friday 1st March 2024 - * Modified By: CB - * ----- - * License: BSD 3-Clause "New" or "Revised" License - * https://opensource.org/licenses/BSD-3-Clause - * ----- - * Copyright (c) 2023 MPI-M, Clara Bayley - * ----- - * File Description: - * configuration input parameters for CLEO divergence free motion example - */ - - -### Initialisation parameters ### -constants_filename = ../libs/cleoconstants.hpp # name of file for values of physical constants -initsupers_filename = ./share/const2d_dimlessSDsinit.dat # binary filename for initialisation of SDs -grid_filename = ./share/const2d_dimlessGBxboundaries.dat # binary filename for initialisation of GBxs / GbxMaps - -### Output Data parameters ### -setuptxt = ./bin/const2d_setup.txt # .txt filename to copy configuration to -stats_filename = ./bin/const2d_stats.txt # .txt file to output runtime statistics to -zarrbasedir = ./bin/const2d_sol.zarr # zarr store base directory -maxchunk = 1250000 # maximum no. of elements in chunks of zarr store array - -### SDM Runtime parameters ### -# domain setup # -nspacedims = 2 # no. of spatial dimensions to model -ngbxs = 400 # total number of Gbxs -totnsupers = 960 # (initial) total no. of SDs - -# timestepping # -CONDTSTEP = 1 # time between SD condensation events [s] -COLLTSTEP = 1 # time between SD collision events [s] -MOTIONTSTEP = 2 # time between SDM motion [s] -COUPLTSTEP = 7200 # time between dynamic couplings [s] -OBSTSTEP = 120 # time between SDM observations [s] -T_END = 7200 # time span of integration from 0s to T_END [s] - -# microphysics # -cond_iters = 2 # no. iterations of Newton Raphson Method before testing for convergence -cond_SUBTSTEP = 0.1 # smallest timestep in cases where substepping occurs [s] -cond_rtol = 0.0 # relative tolerance for implicit euler integration -cond_atol = 0.01 # abolute tolerance for implicit euler integration - -# superdroplets # -doAlterThermo = false # enable condensation to alter the thermodynamic state - -### Coupled Dynamics Solver Parameters ### -# type of coupling # -thermosolver = fromfile # dynamics solver to configure - -### read in dynamics from file ### -press_filename = ./share/const2d_dimlessthermo_press.dat # binary filename for pressure -temp_filename = ./share/const2d_dimlessthermo_temp.dat # binary filename for temperature -qvap_filename = ./share/const2d_dimlessthermo_qvap.dat # binary filename for vapour mixing ratio -qcond_filename = ./share/const2d_dimlessthermo_qcond.dat # binary filename for liquid mixing ratio -wvel_filename = ./share/const2d_dimlessthermo_wvel.dat # binary filename for vertical (z) velocity -uvel_filename = ./share/const2d_dimlessthermo_uvel.dat # binary filename for horizontal x velocity -vvel_filename = ./share/const2d_dimlessthermo_vvel.dat # binary filename for horizontal y velocity diff --git a/examples/constthermo2d/src/config/const2d_config.yaml b/examples/constthermo2d/src/config/const2d_config.yaml new file mode 100644 index 000000000..5955eb497 --- /dev/null +++ b/examples/constthermo2d/src/config/const2d_config.yaml @@ -0,0 +1,72 @@ +--- +# ----- CLEO ----- +# File: const2d_config.yaml +# Project: config +# Created Date: Wednesday 17th April 2024 +# Author: Clara Bayley (CB) +# Additional Contributors: +# ----- +# Last Modified: Wednesday 17th April 2024 +# Modified By: CB +# ----- +# License: BSD 3-Clause "New" or "Revised" License +# https://opensource.org/licenses/BSD-3-Clause +# ----- +# Copyright (c) 2023 MPI-M, Clara Bayley +# ----- +# File Description: +# Configuration file for CLEO 2-D example with constant thermodynamics read from a file. +# Note: The inital superdroplets data read from file "initsupers_filename" can be made with +# CLEO's pySD module (see Python script "create_initsuperdropsbinary_script.py" for usage). +# Likewise the "grid_filename" can be made using pySD (see "create_gbxboundariesbinary_script.py"), +# and so can the thermodynamics files when using coupled thermodynamics "fromfile". +# + +### Initialisation Parameters ### +inputfiles: + constants_filename : ../libs/cleoconstants.hpp # name of file for values of physical constants + grid_filename : ./share/const2d_dimlessGBxboundaries.dat # binary filename for initialisation of GBxs / GbxMaps + +initsupers: + type : frombinary # type of initialisation of super-droplets + initsupers_filename : ./share/const2d_dimlessSDsinit.dat # binary filename for initialisation of SDs + totnsupers : 960 # initial total no. of SDs + +### Output Parameters ### +outputdata: + setup_filename : ./bin/const2d_setup.txt # .txt filename to copy configuration to + stats_filename : ./bin/const2d_stats.txt # .txt file to output runtime statistics to + zarrbasedir : ./bin/const2d_sol.zarr # zarr store base directory + maxchunk : 2500000 # maximum no. of elements in chunks of zarr store array + +### SDM Runtime Parameters ### +domain: + nspacedims : 2 # no. of spatial dimensions to model + ngbxs : 400 # total number of Gbxs + +timesteps: + CONDTSTEP : 1 # time between SD condensation [s] + COLLTSTEP : 1 # time between SD collision [s] + MOTIONTSTEP : 2 # time between SDM motion [s] + COUPLTSTEP : 7200 # time between dynamic couplings [s] + OBSTSTEP : 120 # time between SDM observations [s] + T_END : 7200 # time span of integration from 0s to T_END [s] + +### Microphysics Parameters ### +microphysics: + condensation: + do_alter_thermo : false # true = cond/evap alters the thermodynamic state + niters : 2 # no. iterations of Newton Raphson Method before testing for convergence + SUBTSTEP : 0.1 # smallest subtimestep in cases of substepping [s] + rtol : 0.0 # relative tolerance for implicit Euler integration + atol : 0.01 # abolute tolerance for implicit Euler integration + +### Coupled Dynamics Parameters ### +coupled_dynamics: + type : fromfile # type of coupled dynamics to configure + press : ./share/const2d_dimlessthermo_press.dat # binary filename for pressure + temp : ./share/const2d_dimlessthermo_temp.dat # binary filename for temperature + qvap : ./share/const2d_dimlessthermo_qvap.dat # binary filename for vapour mixing ratio + qcond : ./share/const2d_dimlessthermo_qcond.dat # binary filename for liquid mixing ratio + wvel : ./share/const2d_dimlessthermo_wvel.dat # binary filename for vertical (coord3) velocity + uvel : ./share/const2d_dimlessthermo_uvel.dat # binary filename for eastwards (coord1) velocity diff --git a/examples/constthermo2d/src/main_const2D.cpp b/examples/constthermo2d/src/main_const2D.cpp index ad50ee250..6c6ddbb0c 100644 --- a/examples/constthermo2d/src/main_const2D.cpp +++ b/examples/constthermo2d/src/main_const2D.cpp @@ -9,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Tuesday 16th April 2024 + * Last Modified: Thursday 18th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -18,7 +18,7 @@ * File Description: * runs the CLEO super-droplet model (SDM) for 2-D example with divergence free flow. * After make/compiling, execute for example via: - * ./src/const2D ../src/config/config.txt + * ./src/const2D ../src/config/config.yaml */ #include @@ -68,18 +68,19 @@ inline CoupledDynamics auto create_coupldyn(const Config &config, const Cartesia const auto nsteps = (unsigned int)(std::ceil(t_end / couplstep) + 1); - return FromFileDynamics(config, couplstep, ndims, nsteps); + return FromFileDynamics(config.get_fromfiledynamics(), couplstep, ndims, nsteps); } inline InitialConditions auto create_initconds(const Config &config) { - const InitSupersFromBinary initsupers(config); - const InitGbxsNull initgbxs(config); + const InitSupersFromBinary initsupers(config.get_initsupersfrombinary()); + const InitGbxsNull initgbxs(config.get_ngbxs()); return InitConds(initsupers, initgbxs); } inline GridboxMaps auto create_gbxmaps(const Config &config) { - const auto gbxmaps = create_cartesian_maps(config.ngbxs, config.nspacedims, config.grid_filename); + const auto gbxmaps = create_cartesian_maps(config.get_ngbxs(), config.get_nspacedims(), + config.get_grid_filename()); return gbxmaps; } @@ -95,9 +96,10 @@ inline auto create_movement(const unsigned int motionstep, const CartesianMaps & inline MicrophysicalProcess auto config_condensation(const Config &config, const Timesteps &tsteps) { - return Condensation(tsteps.get_condstep(), config.doAlterThermo, config.cond_iters, - &step2dimlesstime, config.cond_rtol, config.cond_atol, config.cond_SUBTSTEP, - &realtime2dimless); + const auto c = config.get_condensation(); + + return Condensation(tsteps.get_condstep(), &step2dimlesstime, c.do_alter_thermo, c.niters, c.rtol, + c.atol, c.SUBTSTEP, &realtime2dimless); } inline MicrophysicalProcess auto config_collisions(const Config &config, const Timesteps &tsteps) { @@ -133,18 +135,19 @@ inline Observer auto create_superdrops_observer(const unsigned int interval, template inline Observer auto create_observer(const Config &config, const Timesteps &tsteps, Dataset &dataset) { - const auto obsstep = (unsigned int)tsteps.get_obsstep(); - const auto maxchunk = int{config.maxchunk}; + const auto obsstep = tsteps.get_obsstep(); + const auto maxchunk = config.get_maxchunk(); + const auto ngbxs = config.get_ngbxs(); const Observer auto obs0 = StreamOutObserver(obsstep * 10, &step2realtime); const Observer auto obs1 = TimeObserver(obsstep, dataset, maxchunk, &step2dimlesstime); - const Observer auto obs2 = GbxindexObserver(dataset, maxchunk, config.ngbxs); + const Observer auto obs2 = GbxindexObserver(dataset, maxchunk, ngbxs); - const Observer auto obs3 = NsupersObserver(obsstep, dataset, maxchunk, config.ngbxs); + const Observer auto obs3 = NsupersObserver(obsstep, dataset, maxchunk, ngbxs); - const Observer auto obs4 = MassMomentsObserver(obsstep, dataset, maxchunk, config.ngbxs); + const Observer auto obs4 = MassMomentsObserver(obsstep, dataset, maxchunk, ngbxs); const Observer auto obssd = create_superdrops_observer(obsstep, dataset, maxchunk); @@ -170,12 +173,12 @@ int main(int argc, char *argv[]) { Kokkos::Timer kokkostimer; /* Read input parameters from configuration file(s) */ - const std::string_view config_filename(argv[1]); // path to configuration file + const std::filesystem::path config_filename(argv[1]); // path to configuration file const Config config(config_filename); - const Timesteps tsteps(config); // timesteps for model (e.g. coupling and end time) + const Timesteps tsteps(config.get_timesteps()); /* Create Xarray dataset wit Zarr backend for writing output data to a store */ - auto store = FSStore(config.zarrbasedir); + auto store = FSStore(config.get_zarrbasedir()); auto dataset = Dataset(store); /* Initial conditions for CLEO run */ diff --git a/examples/divfreemotion/divfree2d.sh b/examples/divfreemotion/divfree2d.sh index ab36b66e4..4d71a5e0a 100755 --- a/examples/divfreemotion/divfree2d.sh +++ b/examples/divfreemotion/divfree2d.sh @@ -23,7 +23,7 @@ path2build=${HOME}/CLEO/build_divfree2D/ executables="divfree2D" pythonscript=${path2CLEO}/examples/divfreemotion/divfree2d.py -configfile=${path2CLEO}/examples/divfreemotion/src/config/divfree2d_config.txt +configfile=${path2CLEO}/examples/divfreemotion/src/config/divfree2d_config.yaml script_args="${configfile}" ### ---------------------------------------------------- ### ### ---------------------------------------------------- ### diff --git a/examples/divfreemotion/src/config/divfree2d_config.txt b/examples/divfreemotion/src/config/divfree2d_config.txt deleted file mode 100644 index bcf30cc52..000000000 --- a/examples/divfreemotion/src/config/divfree2d_config.txt +++ /dev/null @@ -1,67 +0,0 @@ -/* - * ----- CLEO ----- - * File: divfree2d_config.txt - * Project: config - * Created Date: Tuesday 21st November 2023 - * Author: Clara Bayley (CB) - * Additional Contributors: - * ----- - * Last Modified: Tuesday 9th January 2024 - * Modified By: CB - * ----- - * License: BSD 3-Clause "New" or "Revised" License - * https://opensource.org/licenses/BSD-3-Clause - * ----- - * Copyright (c) 2023 MPI-M, Clara Bayley - * ----- - * File Description: - * configuration input parameters for CLEO divergence free motion example - */ - - -### Initialisation parameters ### -constants_filename = ../libs/cleoconstants.hpp # name of file for values of physical constants -initsupers_filename = ./share/df2d_dimlessSDsinit.dat # binary filename for initialisation of SDs -grid_filename = ./share/df2d_dimlessGBxboundaries.dat # binary filename for initialisation of GBxs / GbxMaps - -### Output Data parameters ### -setuptxt = ./bin/df2d_setup.txt # .txt filename to copy configuration to -stats_filename = ./bin/df2d_stats.txt # .txt file to output runtime statistics to -zarrbasedir = ./bin/df2d_sol.zarr # zarr store base directory -maxchunk = 1250000 # maximum no. of elements in chunks of zarr store array - -### SDM Runtime parameters ### -# domain setup # -nspacedims = 2 # no. of spatial dimensions to model -ngbxs = 900 # total number of Gbxs -totnsupers = 3600 # (initial) total no. of SDs - -# timestepping # -CONDTSTEP = 2 # time between SD condensation events [s] -COLLTSTEP = 2 # time between SD collision events [s] -MOTIONTSTEP = 3 # time between SDM motion [s] -COUPLTSTEP = 3600 # time between dynamic couplings [s] -OBSTSTEP = 180 # time between SDM observations [s] -T_END = 7200 # time span of integration from 0s to T_END [s] - -# microphysics # -cond_iters = 2 # no. iterations of Newton Raphson Method before testing for convergence -cond_SUBTSTEP = 0.1 # smallest timestep in cases where substepping occurs [s] -cond_rtol = 0.0 # relative tolerance for implicit euler integration -cond_atol = 0.01 # abolute tolerance for implicit euler integration - -# superdroplets # -doAlterThermo = false # enable condensation to alter the thermodynamic state - -### Coupled Dynamics Solver Parameters ### -# type of coupling # -thermosolver = fromfile # dynamics solver to configure - -### read in dynamics from file ### -press_filename = ./share/df2d_dimlessthermo_press.dat # binary filename for pressure -temp_filename = ./share/df2d_dimlessthermo_temp.dat # binary filename for temperature -qvap_filename = ./share/df2d_dimlessthermo_qvap.dat # binary filename for vapour mixing ratio -qcond_filename = ./share/df2d_dimlessthermo_qcond.dat # binary filename for liquid mixing ratio -wvel_filename = ./share/df2d_dimlessthermo_wvel.dat # binary filename for vertical (z) velocity -uvel_filename = ./share/df2d_dimlessthermo_uvel.dat # binary filename for horizontal x velocity -vvel_filename = ./share/df2d_dimlessthermo_vvel.dat # binary filename for horizontal y velocity diff --git a/examples/divfreemotion/src/config/divfree2d_config.yaml b/examples/divfreemotion/src/config/divfree2d_config.yaml new file mode 100644 index 000000000..6cfa09f27 --- /dev/null +++ b/examples/divfreemotion/src/config/divfree2d_config.yaml @@ -0,0 +1,63 @@ +--- +# ----- CLEO ----- +# File: divfree2d_config.yaml +# Project: config +# Created Date: Wednesday 17th April 2024 +# Author: Clara Bayley (CB) +# Additional Contributors: +# ----- +# Last Modified: Wednesday 17th April 2024 +# Modified By: CB +# ----- +# License: BSD 3-Clause "New" or "Revised" License +# https://opensource.org/licenses/BSD-3-Clause +# ----- +# Copyright (c) 2023 MPI-M, Clara Bayley +# ----- +# File Description: +# Configuration file for divergence free motion 2-D CLEO example. +# Note: The inital superdroplets data read from file "initsupers_filename" can be made with +# CLEO's pySD module (see Python script "create_initsuperdropsbinary_script.py" for usage). +# Likewise the "grid_filename" can be made using pySD (see "create_gbxboundariesbinary_script.py"), +# and so can the thermodynamics files when using coupled thermodynamics "fromfile". +# + +### Initialisation Parameters ### +inputfiles: + constants_filename : ../libs/cleoconstants.hpp # name of file for values of physical constants + grid_filename : ./share/df2d_dimlessGBxboundaries.dat # binary filename for initialisation of GBxs / GbxMaps + +initsupers: + type : frombinary # type of initialisation of super-droplets + initsupers_filename : ./share/df2d_dimlessSDsinit.dat # binary filename for initialisation of SDs + totnsupers : 3600 # initial total no. of SDs + +### Output Parameters ### +outputdata: + setup_filename : ./bin/df2d_setup.txt # .txt filename to copy configuration to + stats_filename : ./bin/df2d_stats.txt # .txt file to output runtime statistics to + zarrbasedir : ./bin/df2d_sol.zarr # zarr store base directory + maxchunk : 2500000 # maximum no. of elements in chunks of zarr store array + +### SDM Runtime Parameters ### +domain: + nspacedims : 2 # no. of spatial dimensions to model + ngbxs : 900 # total number of Gbxs + +timesteps: + CONDTSTEP : 3 # time between SD condensation [s] + COLLTSTEP : 3 # time between SD collision [s] + MOTIONTSTEP : 3 # time between SDM motion [s] + COUPLTSTEP : 3600 # time between dynamic couplings [s] + OBSTSTEP : 180 # time between SDM observations [s] + T_END : 7200 # time span of integration from 0s to T_END [s] + +### Coupled Dynamics Parameters ### +coupled_dynamics: + type : fromfile # type of coupled dynamics to configure + press : ./share/df2d_dimlessthermo_press.dat # binary filename for pressure + temp : ./share/df2d_dimlessthermo_temp.dat # binary filename for temperature + qvap : ./share/df2d_dimlessthermo_qvap.dat # binary filename for vapour mixing ratio + qcond : ./share/df2d_dimlessthermo_qcond.dat # binary filename for liquid mixing ratio + wvel : ./share/df2d_dimlessthermo_wvel.dat # binary filename for vertical (coord3) velocity + uvel : ./share/df2d_dimlessthermo_uvel.dat # binary filename for eastwards (coord1) velocity diff --git a/examples/divfreemotion/src/main_divfree2D.cpp b/examples/divfreemotion/src/main_divfree2D.cpp index 75fb44d84..85e9c21af 100644 --- a/examples/divfreemotion/src/main_divfree2D.cpp +++ b/examples/divfreemotion/src/main_divfree2D.cpp @@ -9,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Tuesday 16th April 2024 + * Last Modified: Thursday 18th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -18,7 +18,7 @@ * File Description: * runs the CLEO super-droplet model (SDM) for 2-D divergence free motion example * after make/compiling, execute for example via: - * ./src/divfree2D ../src/config/config.txt + * ./src/divfree2D ../src/config/config.yaml */ #include @@ -62,18 +62,19 @@ inline CoupledDynamics auto create_coupldyn(const Config &config, const Cartesia const auto nsteps = (unsigned int)(std::ceil(t_end / couplstep) + 1); - return FromFileDynamics(config, couplstep, ndims, nsteps); + return FromFileDynamics(config.get_fromfiledynamics(), couplstep, ndims, nsteps); } inline InitialConditions auto create_initconds(const Config &config) { - const InitSupersFromBinary initsupers(config); - const InitGbxsNull initgbxs(config); + const InitSupersFromBinary initsupers(config.get_initsupersfrombinary()); + const InitGbxsNull initgbxs(config.get_ngbxs()); return InitConds(initsupers, initgbxs); } inline GridboxMaps auto create_gbxmaps(const Config &config) { - const auto gbxmaps = create_cartesian_maps(config.ngbxs, config.nspacedims, config.grid_filename); + const auto gbxmaps = create_cartesian_maps(config.get_ngbxs(), config.get_nspacedims(), + config.get_grid_filename()); return gbxmaps; } @@ -107,8 +108,8 @@ inline Observer auto create_superdrops_observer(const unsigned int interval, template inline Observer auto create_observer(const Config &config, const Timesteps &tsteps, Dataset &dataset) { - const auto obsstep = (unsigned int)tsteps.get_obsstep(); - const auto maxchunk = int{config.maxchunk}; + const auto obsstep = tsteps.get_obsstep(); + const auto maxchunk = config.get_maxchunk(); const Observer auto obs0 = StreamOutObserver(obsstep, &step2realtime); @@ -138,12 +139,12 @@ int main(int argc, char *argv[]) { Kokkos::Timer kokkostimer; /* Read input parameters from configuration file(s) */ - const std::string_view config_filename(argv[1]); // path to configuration file + const std::filesystem::path config_filename(argv[1]); // path to configuration file const Config config(config_filename); - const Timesteps tsteps(config); // timesteps for model (e.g. coupling and end time) + const Timesteps tsteps(config.get_timesteps()); /* Create Xarray dataset wit Zarr backend for writing output data to a store */ - auto store = FSStore(config.zarrbasedir); + auto store = FSStore(config.get_zarrbasedir()); auto dataset = Dataset(store); /* Initial conditions for CLEO run */ diff --git a/examples/eurec4a1d/eurec4a1d.sh b/examples/eurec4a1d/eurec4a1d.sh index 782df5b93..9e7cfd7b5 100755 --- a/examples/eurec4a1d/eurec4a1d.sh +++ b/examples/eurec4a1d/eurec4a1d.sh @@ -22,7 +22,7 @@ path2CLEO=${HOME}/CLEO/ path2build=${HOME}/CLEO/build_eurec4a1D/ executables="eurec4a1D" -configfile=${path2CLEO}/examples/eurec4a1d/src/config/eurec4a1d_config.txt +configfile=${path2CLEO}/examples/eurec4a1d/src/config/eurec4a1d_config.yaml pythonscript="" script_args="" ### ---------------------------------------------------- ### diff --git a/examples/eurec4a1d/src/config/eurec4a1d_config.txt b/examples/eurec4a1d/src/config/eurec4a1d_config.txt deleted file mode 100644 index 1410d4a8e..000000000 --- a/examples/eurec4a1d/src/config/eurec4a1d_config.txt +++ /dev/null @@ -1,67 +0,0 @@ -/* - * ----- CLEO ----- - * File: eurec4a1d_config.txt - * Project: config - * Created Date: Tuesday 9th January 2024 - * Author: Clara Bayley (CB) - * Additional Contributors: - * ----- - * Last Modified: Tuesday 9th April 2024 - * Modified By: CB - * ----- - * License: BSD 3-Clause "New" or "Revised" License - * https://opensource.org/licenses/BSD-3-Clause - * ----- - * Copyright (c) 2023 MPI-M, Clara Bayley - * ----- - * File Description: - * configuration input parameters for CLEO eurec4a 1-D rainshaft example - */ - - -### Initialisation parameters ### -constants_filename = ../libs/cleoconstants.hpp # name of file for values of physical constants -initsupers_filename = ./share/eurec4a1d_dimlessSDsinit.dat # binary filename for initialisation of SDs -grid_filename = ./share/eurec4a1d_dimlessGBxboundaries.dat # binary filename for initialisation of GBxs / GbxMaps - -### Output Data parameters ### -setuptxt = ./bin/eurec4a1d_setup.txt # .txt filename to copy configuration to -stats_filename = ./bin/eurec4a1d_stats.txt # .txt file to output runtime statistics to -zarrbasedir = ./bin/eurec4a1d_sol.zarr # zarr store base directory -maxchunk = 1250000 # maximum no. of elements in chunks of zarr store array - -### SDM Runtime parameters ### -# domain setup # -nspacedims = 1 # no. of spatial dimensions to model -ngbxs = 60 # total number of Gbxs -totnsupers = 15360 # (initial) total no. of SDs - -# timestepping # -CONDTSTEP = 0.1 # time between SD condensation events [s] -COLLTSTEP = 1 # time between SD collision events [s] -MOTIONTSTEP = 2 # time between SDM motion [s] -COUPLTSTEP = 2400 # time between dynamic couplings [s] -OBSTSTEP = 5 # time between SDM observations [s] -T_END = 2400 # time span of integration from 0s to T_END [s] - -# microphysics # -cond_iters = 2 # no. iterations of Newton Raphson Method before testing for convergence -cond_SUBTSTEP = 0.1 # smallest timestep in cases where substepping occurs [s] -cond_rtol = 0.0 # relative tolerance for implicit euler integration -cond_atol = 0.01 # abolute tolerance for implicit euler integration - -# superdroplets # -doAlterThermo = false # enable condensation to alter the thermodynamic state - -### Coupled Dynamics Solver Parameters ### -# type of coupling # -thermosolver = fromfile # dynamics solver to configure - -### read in dynamics from file ### -press_filename = ./share/eurec4a1d_dimlessthermo_press.dat # binary filename for pressure -temp_filename = ./share/eurec4a1d_dimlessthermo_temp.dat # binary filename for temperature -qvap_filename = ./share/eurec4a1d_dimlessthermo_qvap.dat # binary filename for vapour mixing ratio -qcond_filename = ./share/eurec4a1d_dimlessthermo_qcond.dat # binary filename for liquid mixing ratio -wvel_filename = ./share/eurec4a1d_dimlessthermo_wvel.dat # binary filename for vertical (z) velocity -uvel_filename = ./share/eurec4a1d_dimlessthermo_uvel.dat # binary filename for horizontal x velocity -vvel_filename = ./share/eurec4a1d_dimlessthermo_vvel.dat # binary filename for horizontal y velocity diff --git a/examples/eurec4a1d/src/config/eurec4a1d_config.yaml b/examples/eurec4a1d/src/config/eurec4a1d_config.yaml new file mode 100644 index 000000000..49484b4a4 --- /dev/null +++ b/examples/eurec4a1d/src/config/eurec4a1d_config.yaml @@ -0,0 +1,71 @@ +--- +# ----- CLEO ----- +# File: eurec4a1d_config.yaml +# Project: config +# Created Date: Thursday 18th April 2024 +# Author: Clara Bayley (CB) +# Additional Contributors: +# ----- +# Last Modified: Thursday 18th April 2024 +# Modified By: CB +# ----- +# License: BSD 3-Clause "New" or "Revised" License +# https://opensource.org/licenses/BSD-3-Clause +# ----- +# Copyright (c) 2023 MPI-M, Clara Bayley +# ----- +# File Description: +# Configuration file for CLEO eurec4a 1-D rainshaft example. +# Note: The inital superdroplets data read from file "initsupers_filename" can be made with +# CLEO's pySD module (see Python script "create_initsuperdropsbinary_script.py" for usage). +# Likewise the "grid_filename" can be made using pySD (see "create_gbxboundariesbinary_script.py"), +# and so can the thermodynamics files when using coupled thermodynamics "fromfile". +# + +### Initialisation Parameters ### +inputfiles: + constants_filename : ../libs/cleoconstants.hpp # name of file for values of physical constants + grid_filename : ./share/eurec4a1d_ddimlessGBxboundaries.dat # binary filename for initialisation of GBxs / GbxMaps + +initsupers: + type : frombinary # type of initialisation of super-droplets + initsupers_filename : ./share/eurec4a1d_ddimlessSDsinit.dat # binary filename for initialisation of SDs + totnsupers : 15360 # initial total no. of SDs + +### Output Parameters ### +outputdata: + setup_filename : ./bin/eurec4a1d_setup.txt # .txt filename to copy configuration to + stats_filename : ./bin/eurec4a1d_stats.txt # .txt file to output runtime statistics to + zarrbasedir : ./bin/eurec4a1d_sol.zarr # zarr store base directory + maxchunk : 2500000 # maximum no. of elements in chunks of zarr store array + +### SDM Runtime Parameters ### +domain: + nspacedims : 1 # no. of spatial dimensions to model + ngbxs : 60 # total number of Gbxs + +timesteps: + CONDTSTEP : 0.1 # time between SD condensation [s] + COLLTSTEP : 1 # time between SD collision [s] + MOTIONTSTEP : 2 # time between SDM motion [s] + COUPLTSTEP : 2400 # time between dynamic couplings [s] + OBSTSTEP : 5 # time between SDM observations [s] + T_END : 2400 # time span of integration from 0s to T_END [s] + +### Microphysics Parameters ### +microphysics: + condensation: + do_alter_thermo : false # true = cond/evap alters the thermodynamic state + niters : 2 # no. iterations of Newton Raphson Method before testing for convergence + SUBTSTEP : 0.1 # smallest subtimestep in cases of substepping [s] + rtol : 0.0 # relative tolerance for implicit Euler integration + atol : 0.01 # abolute tolerance for implicit Euler integration + +### Coupled Dynamics Parameters ### +coupled_dynamics: + type : fromfile # type of coupled dynamics to configure + press : ./share/eurec4a1d_dimlessthermo_press.dat # binary filename for pressure + temp : ./share/eurec4a1d_dimlessthermo_temp.dat # binary filename for temperature + qvap : ./share/eurec4a1d_dimlessthermo_qvap.dat # binary filename for vapour mixing ratio + qcond : ./share/eurec4a1d_dimlessthermo_qcond.dat # binary filename for liquid mixing ratio + wvel : ./share/eurec4a1d_dimlessthermo_wvel.dat # binary filename for vertical (coord3) velocity diff --git a/examples/eurec4a1d/src/main_eurec4a1D.cpp b/examples/eurec4a1d/src/main_eurec4a1D.cpp index 92ab013c8..e1fb8f74e 100644 --- a/examples/eurec4a1d/src/main_eurec4a1D.cpp +++ b/examples/eurec4a1d/src/main_eurec4a1D.cpp @@ -9,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Tuesday 16th April 2024 + * Last Modified: Thursday 18th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -18,7 +18,7 @@ * File Description: * runs the CLEO super-droplet model (SDM) for eurec4a 1-D rainshaft example. * After make/compiling, execute for example via: - * ./src/eurec4a1D ../src/config/config.txt + * ./src/eurec4a1D ../src/config/config.yaml */ #include @@ -72,18 +72,19 @@ inline CoupledDynamics auto create_coupldyn(const Config &config, const Cartesia const auto nsteps = (unsigned int)(std::ceil(t_end / couplstep) + 1); - return FromFileDynamics(config, couplstep, ndims, nsteps); + return FromFileDynamics(config.get_fromfiledynamics(), couplstep, ndims, nsteps); } inline InitialConditions auto create_initconds(const Config &config) { - const InitSupersFromBinary initsupers(config); - const InitGbxsNull initgbxs(config); + const InitSupersFromBinary initsupers(config.get_initsupersfrombinary()); + const InitGbxsNull initgbxs(config.get_ngbxs()); return InitConds(initsupers, initgbxs); } inline GridboxMaps auto create_gbxmaps(const Config &config) { - const auto gbxmaps = create_cartesian_maps(config.ngbxs, config.nspacedims, config.grid_filename); + const auto gbxmaps = create_cartesian_maps(config.get_ngbxs(), config.get_nspacedims(), + config.get_grid_filename()); return gbxmaps; } @@ -100,9 +101,10 @@ inline auto create_movement(const Config &config, const Timesteps &tsteps, inline MicrophysicalProcess auto create_microphysics(const Config &config, const Timesteps &tsteps) { - const MicrophysicalProcess auto cond = Condensation( - tsteps.get_condstep(), config.doAlterThermo, config.cond_iters, &step2dimlesstime, - config.cond_rtol, config.cond_atol, config.cond_SUBTSTEP, &realtime2dimless); + const auto c = config.get_condensation(); + const MicrophysicalProcess auto cond = + Condensation(tsteps.get_condstep(), &step2dimlesstime, c.do_alter_thermo, c.niters, c.rtol, + c.atol, c.SUBTSTEP, &realtime2dimless); const PairProbability auto coalprob = LongHydroProb(1.0); const MicrophysicalProcess auto coal = CollCoal(tsteps.get_collstep(), &step2realtime, coalprob); @@ -140,22 +142,23 @@ inline Observer auto create_gridboxes_observer(const unsigned int interval, Data template inline Observer auto create_observer(const Config &config, const Timesteps &tsteps, Dataset &dataset) { - const auto obsstep = (unsigned int)tsteps.get_obsstep(); - const auto maxchunk = int{config.maxchunk}; + const auto obsstep = tsteps.get_obsstep(); + const auto maxchunk = config.get_maxchunk(); + const auto ngbxs = config.get_ngbxs(); - const Observer auto obs0 = RunStatsObserver(obsstep, config.stats_filename); + const Observer auto obs0 = RunStatsObserver(obsstep, config.get_stats_filename()); const Observer auto obs1 = StreamOutObserver(realtime2step(240), &step2realtime); const Observer auto obs2 = TimeObserver(obsstep, dataset, maxchunk, &step2dimlesstime); - const Observer auto obs3 = GbxindexObserver(dataset, maxchunk, config.ngbxs); + const Observer auto obs3 = GbxindexObserver(dataset, maxchunk, ngbxs); - const Observer auto obs5 = MassMomentsObserver(obsstep, dataset, maxchunk, config.ngbxs); + const Observer auto obs5 = MassMomentsObserver(obsstep, dataset, maxchunk, ngbxs); - const Observer auto obs6 = MassMomentsRaindropsObserver(obsstep, dataset, maxchunk, config.ngbxs); + const Observer auto obs6 = MassMomentsRaindropsObserver(obsstep, dataset, maxchunk, ngbxs); - const Observer auto obsgbx = create_gridboxes_observer(obsstep, dataset, maxchunk, config.ngbxs); + const Observer auto obsgbx = create_gridboxes_observer(obsstep, dataset, maxchunk, ngbxs); const Observer auto obssd = create_superdrops_observer(obsstep, dataset, maxchunk); @@ -181,12 +184,12 @@ int main(int argc, char *argv[]) { Kokkos::Timer kokkostimer; /* Read input parameters from configuration file(s) */ - const std::string_view config_filename(argv[1]); // path to configuration file + const std::filesystem::path config_filename(argv[1]); // path to configuration file const Config config(config_filename); - const Timesteps tsteps(config); // timesteps for model (e.g. coupling and end time) + const Timesteps tsteps(config.get_timesteps()); /* Create Xarray dataset wit Zarr backend for writing output data to a store */ - auto store = FSStore(config.zarrbasedir); + auto store = FSStore(config.get_zarrbasedir()); auto dataset = Dataset(store); /* Initial conditions for CLEO run */ diff --git a/examples/exampleplotting/plotssrc/as2017fig.py b/examples/exampleplotting/plotssrc/as2017fig.py index 04c596cb0..156055383 100644 --- a/examples/exampleplotting/plotssrc/as2017fig.py +++ b/examples/exampleplotting/plotssrc/as2017fig.py @@ -6,7 +6,7 @@ Author: Clara Bayley (CB) Additional Contributors: ----- -Last Modified: Friday 17th November 2023 +Last Modified: Wednesday 17th April 2024 Modified By: CB ----- License: BSD 3-Clause "New" or "Revised" License @@ -100,7 +100,7 @@ def condensation_validation_subplots(axs, time, radius, supersat, zprof, return axs def arabas_shima_2017_fig(time, zprof, radius, msol, temp, supersat, - IONIC, MR_SOL, W_AVG, numconc, savename=""): + IONIC, MR_SOL, W_avg, numconc, savename=""): ''' plots the same plots as in Figure 5 of "On the CCN (de)activation nonlinearities" S. Arabas and S. Shima 2017 to check radius @@ -118,7 +118,7 @@ def arabas_shima_2017_fig(time, zprof, radius, msol, temp, supersat, textlab = "N = "+str(numconc)+"cm$^{-3}$\n" +\ "r$_{dry}$ = "+"{:.2g}\u03BCm\n".format(radius[0]) +\ - " = {:.1f}".format(W_AVG*100)+"cm s$^{-1}$" + " = {:.1f}".format(W_avg*100)+"cm s$^{-1}$" axs[0].text(0.03, 0.82, textlab, transform=axs[0].transAxes) axs[0].set_xlim([-1, 1]) diff --git a/examples/rainshaft1d/rainshaft1d.sh b/examples/rainshaft1d/rainshaft1d.sh index e66a58da4..1ae9cf9ae 100755 --- a/examples/rainshaft1d/rainshaft1d.sh +++ b/examples/rainshaft1d/rainshaft1d.sh @@ -23,7 +23,7 @@ path2build=${HOME}/CLEO/build_rshaft1D/ executables="rshaft1D" pythonscript=${path2CLEO}/examples/rainshaft1d/rainshaft1d.py -configfile=${path2CLEO}/examples/rainshaft1d/src/config/rain1d_config.txt +configfile=${path2CLEO}/examples/rainshaft1d/src/config/rain1d_config.yaml script_args="${configfile}" ### ---------------------------------------------------- ### ### ---------------------------------------------------- ### diff --git a/examples/rainshaft1d/src/config/rain1d_config.txt b/examples/rainshaft1d/src/config/rain1d_config.txt deleted file mode 100644 index 3246915af..000000000 --- a/examples/rainshaft1d/src/config/rain1d_config.txt +++ /dev/null @@ -1,67 +0,0 @@ -/* - * ----- CLEO ----- - * File: rain1d_config.txt - * Project: config - * Created Date: Tuesday 9th January 2024 - * Author: Clara Bayley (CB) - * Additional Contributors: - * ----- - * Last Modified: Wednesday 17th January 2024 - * Modified By: CB - * ----- - * License: BSD 3-Clause "New" or "Revised" License - * https://opensource.org/licenses/BSD-3-Clause - * ----- - * Copyright (c) 2023 MPI-M, Clara Bayley - * ----- - * File Description: - * configuration input parameters for CLEO 1-D rainshaft example - */ - - -### Initialisation parameters ### -constants_filename = ../libs/cleoconstants.hpp # name of file for values of physical constants -initsupers_filename = ./share/rain1d_dimlessSDsinit.dat # binary filename for initialisation of SDs -grid_filename = ./share/rain1d_dimlessGBxboundaries.dat # binary filename for initialisation of GBxs / GbxMaps - -### Output Data parameters ### -setuptxt = ./bin/rain1d_setup.txt # .txt filename to copy configuration to -stats_filename = ./bin/rain1d_stats.txt # .txt file to output runtime statistics to -zarrbasedir = ./bin/rain1d_sol.zarr # zarr store base directory -maxchunk = 1250000 # maximum no. of elements in chunks of zarr store array - -### SDM Runtime parameters ### -# domain setup # -nspacedims = 1 # no. of spatial dimensions to model -ngbxs = 125 # total number of Gbxs -totnsupers = 21760 # (initial) total no. of SDs - -# timestepping # -CONDTSTEP = 1 # time between SD condensation events [s] -COLLTSTEP = 1 # time between SD collision events [s] -MOTIONTSTEP = 2 # time between SDM motion [s] -COUPLTSTEP = 2400 # time between dynamic couplings [s] -OBSTSTEP = 120 # time between SDM observations [s] -T_END = 2400 # time span of integration from 0s to T_END [s] - -# microphysics # -cond_iters = 2 # no. iterations of Newton Raphson Method before testing for convergence -cond_SUBTSTEP = 0.1 # smallest timestep in cases where substepping occurs [s] -cond_rtol = 0.0 # relative tolerance for implicit euler integration -cond_atol = 0.01 # abolute tolerance for implicit euler integration - -# superdroplets # -doAlterThermo = false # enable condensation to alter the thermodynamic state - -### Coupled Dynamics Solver Parameters ### -# type of coupling # -thermosolver = fromfile # dynamics solver to configure - -### read in dynamics from file ### -press_filename = ./share/rain1d_dimlessthermo_press.dat # binary filename for pressure -temp_filename = ./share/rain1d_dimlessthermo_temp.dat # binary filename for temperature -qvap_filename = ./share/rain1d_dimlessthermo_qvap.dat # binary filename for vapour mixing ratio -qcond_filename = ./share/rain1d_dimlessthermo_qcond.dat # binary filename for liquid mixing ratio -wvel_filename = ./share/rain1d_dimlessthermo_wvel.dat # binary filename for vertical (z) velocity -uvel_filename = ./share/rain1d_dimlessthermo_uvel.dat # binary filename for horizontal x velocity -vvel_filename = ./share/rain1d_dimlessthermo_vvel.dat # binary filename for horizontal y velocity diff --git a/examples/rainshaft1d/src/config/rain1d_config.yaml b/examples/rainshaft1d/src/config/rain1d_config.yaml new file mode 100644 index 000000000..9fe64b74d --- /dev/null +++ b/examples/rainshaft1d/src/config/rain1d_config.yaml @@ -0,0 +1,71 @@ +--- +# ----- CLEO ----- +# File: rain1d_config.yaml +# Project: config +# Created Date: Thursday 18th April 2024 +# Author: Clara Bayley (CB) +# Additional Contributors: +# ----- +# Last Modified: Thursday 18th April 2024 +# Modified By: CB +# ----- +# License: BSD 3-Clause "New" or "Revised" License +# https://opensource.org/licenses/BSD-3-Clause +# ----- +# Copyright (c) 2023 MPI-M, Clara Bayley +# ----- +# File Description: +# Configuration file for CLEO 1-D rainshaft example with constant thermodynamics. +# Note: The inital superdroplets data read from file "initsupers_filename" can be made with +# CLEO's pySD module (see Python script "create_initsuperdropsbinary_script.py" for usage). +# Likewise the "grid_filename" can be made using pySD (see "create_gbxboundariesbinary_script.py"), +# and so can the thermodynamics files when using coupled thermodynamics "fromfile". +# + +### Initialisation Parameters ### +inputfiles: + constants_filename : ../libs/cleoconstants.hpp # name of file for values of physical constants + grid_filename : ./share/rain1d_dimlessGBxboundaries.dat # binary filename for initialisation of GBxs / GbxMaps + +initsupers: + type : frombinary # type of initialisation of super-droplets + initsupers_filename : ./share/rain1d_dimlessSDsinit.dat # binary filename for initialisation of SDs + totnsupers : 21760 # initial total no. of SDs + +### Output Parameters ### +outputdata: + setup_filename : ./bin/rain1d_setup.txt # .txt filename to copy configuration to + stats_filename : ./bin/rain1d_stats.txt # .txt file to output runtime statistics to + zarrbasedir : ./bin/rain1d_sol.zarr # zarr store base directory + maxchunk : 2500000 # maximum no. of elements in chunks of zarr store array + +### SDM Runtime Parameters ### +domain: + nspacedims : 1 # no. of spatial dimensions to model + ngbxs : 125 # total number of Gbxs + +timesteps: + CONDTSTEP : 1 # time between SD condensation [s] + COLLTSTEP : 1 # time between SD collision [s] + MOTIONTSTEP : 2 # time between SDM motion [s] + COUPLTSTEP : 2400 # time between dynamic couplings [s] + OBSTSTEP : 120 # time between SDM observations [s] + T_END : 2400 # time span of integration from 0s to T_END [s] + +### Microphysics Parameters ### +microphysics: + condensation: + do_alter_thermo : false # true = cond/evap alters the thermodynamic state + niters : 2 # no. iterations of Newton Raphson Method before testing for convergence + SUBTSTEP : 0.1 # smallest subtimestep in cases of substepping [s] + rtol : 0.0 # relative tolerance for implicit Euler integration + atol : 0.01 # abolute tolerance for implicit Euler integration + +### Coupled Dynamics Parameters ### +coupled_dynamics: + type : fromfile # type of coupled dynamics to configure + press : ./share/rain1d_dimlessthermo_press.dat # binary filename for pressure + temp : ./share/rain1d_dimlessthermo_temp.dat # binary filename for temperature + qvap : ./share/rain1d_dimlessthermo_qvap.dat # binary filename for vapour mixing ratio + qcond : ./share/rain1d_dimlessthermo_qcond.dat # binary filename for liquid mixing ratio + wvel : ./share/rain1d_dimlessthermo_wvel.dat # binary filename for vertical (coord3) velocity diff --git a/examples/rainshaft1d/src/main_rshaft1D.cpp b/examples/rainshaft1d/src/main_rshaft1D.cpp index 1d613bf53..ba044050a 100644 --- a/examples/rainshaft1d/src/main_rshaft1D.cpp +++ b/examples/rainshaft1d/src/main_rshaft1D.cpp @@ -9,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Tuesday 16th April 2024 + * Last Modified: Thursday 18th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -18,7 +18,7 @@ * File Description: * runs the CLEO super-droplet model (SDM) for 1-D rainshaft example. * After make/compiling, execute for example via: - * ./src/rshaft1D ../src/config/config.txt + * ./src/rshaft1D ../src/config/config.yaml */ #include @@ -68,18 +68,19 @@ inline CoupledDynamics auto create_coupldyn(const Config &config, const Cartesia const auto nsteps = (unsigned int)(std::ceil(t_end / couplstep) + 1); - return FromFileDynamics(config, couplstep, ndims, nsteps); + return FromFileDynamics(config.get_fromfiledynamics(), couplstep, ndims, nsteps); } inline InitialConditions auto create_initconds(const Config &config) { - const InitSupersFromBinary initsupers(config); - const InitGbxsNull initgbxs(config); + const InitSupersFromBinary initsupers(config.get_initsupersfrombinary()); + const InitGbxsNull initgbxs(config.get_ngbxs()); return InitConds(initsupers, initgbxs); } inline GridboxMaps auto create_gbxmaps(const Config &config) { - const auto gbxmaps = create_cartesian_maps(config.ngbxs, config.nspacedims, config.grid_filename); + const auto gbxmaps = create_cartesian_maps(config.get_ngbxs(), config.get_nspacedims(), + config.get_grid_filename()); return gbxmaps; } @@ -95,9 +96,10 @@ inline auto create_movement(const unsigned int motionstep, const CartesianMaps & inline MicrophysicalProcess auto create_microphysics(const Config &config, const Timesteps &tsteps) { - const MicrophysicalProcess auto cond = Condensation( - tsteps.get_condstep(), config.doAlterThermo, config.cond_iters, &step2dimlesstime, - config.cond_rtol, config.cond_atol, config.cond_SUBTSTEP, &realtime2dimless); + const auto c = config.get_condensation(); + const MicrophysicalProcess auto cond = + Condensation(tsteps.get_condstep(), &step2dimlesstime, c.do_alter_thermo, c.niters, c.rtol, + c.atol, c.SUBTSTEP, &realtime2dimless); const PairProbability auto coalprob = LongHydroProb(1.0); const MicrophysicalProcess auto colls = CollCoal(tsteps.get_collstep(), &step2realtime, coalprob); @@ -121,18 +123,19 @@ inline Observer auto create_superdrops_observer(const unsigned int interval, template inline Observer auto create_observer(const Config &config, const Timesteps &tsteps, Dataset &dataset) { - const auto obsstep = (unsigned int)tsteps.get_obsstep(); - const auto maxchunk = int{config.maxchunk}; + const auto obsstep = tsteps.get_obsstep(); + const auto maxchunk = config.get_maxchunk(); + const auto ngbxs = config.get_ngbxs(); const Observer auto obs0 = StreamOutObserver(obsstep * 10, &step2realtime); const Observer auto obs1 = TimeObserver(obsstep, dataset, maxchunk, &step2dimlesstime); - const Observer auto obs2 = GbxindexObserver(dataset, maxchunk, config.ngbxs); + const Observer auto obs2 = GbxindexObserver(dataset, maxchunk, ngbxs); - const Observer auto obs3 = NsupersObserver(obsstep, dataset, maxchunk, config.ngbxs); + const Observer auto obs3 = NsupersObserver(obsstep, dataset, maxchunk, ngbxs); - const Observer auto obs4 = MassMomentsObserver(obsstep, dataset, maxchunk, config.ngbxs); + const Observer auto obs4 = MassMomentsObserver(obsstep, dataset, maxchunk, ngbxs); const Observer auto obssd = create_superdrops_observer(obsstep, dataset, maxchunk); @@ -158,12 +161,12 @@ int main(int argc, char *argv[]) { Kokkos::Timer kokkostimer; /* Read input parameters from configuration file(s) */ - const std::string_view config_filename(argv[1]); // path to configuration file + const std::filesystem::path config_filename(argv[1]); // path to configuration file const Config config(config_filename); - const Timesteps tsteps(config); // timesteps for model (e.g. coupling and end time) + const Timesteps tsteps(config.get_timesteps()); /* Create Xarray dataset wit Zarr backend for writing output data to a store */ - auto store = FSStore(config.zarrbasedir); + auto store = FSStore(config.get_zarrbasedir()); auto dataset = Dataset(store); /* Initial conditions for CLEO run */ diff --git a/examples/speedtest/speedtest.sh b/examples/speedtest/speedtest.sh index bd58a2b09..5757c93e1 100755 --- a/examples/speedtest/speedtest.sh +++ b/examples/speedtest/speedtest.sh @@ -22,7 +22,7 @@ path2build=${HOME}/CLEO/build_spdtest/ executables="spdtest" pythonscript=${path2CLEO}/examples/speedtest/speedtest.py -configfile=${path2CLEO}/examples/speedtest/src/config/speedtest_config.txt +configfile=${path2CLEO}/examples/speedtest/src/config/speedtest_config.yaml ### ---------------------------------------------------- ### ### ---------------------------------------------------- ### ### ---------------------------------------------------- ### diff --git a/examples/speedtest/src/config/speedtest_config.txt b/examples/speedtest/src/config/speedtest_config.txt deleted file mode 100644 index ed2bd7681..000000000 --- a/examples/speedtest/src/config/speedtest_config.txt +++ /dev/null @@ -1,67 +0,0 @@ -/* - * ----- CLEO ----- - * File: speedtest_config.txt - * Project: config - * Created Date: Friday 13th October 2023 - * Author: Clara Bayley (CB) - * Additional Contributors: - * ----- - * Last Modified: Tuesday 9th January 2024 - * Modified By: CB - * ----- - * License: BSD 3-Clause "New" or "Revised" License - * https://opensource.org/licenses/BSD-3-Clause - * ----- - * Copyright (c) 2023 MPI-M, Clara Bayley - * ----- - * File Description: - * configuration input parameters for CLEO - */ - - -### Initialisation parameters ### -constants_filename = ../../libs/cleoconstants.hpp # name of file for values of physical constants -initsupers_filename = ./share/spd_dimlessSDsinit.dat # binary filename for initialisation of SDs -grid_filename = ./share/spd_dimlessGBxboundaries.dat # binary filename for initialisation of GBxs / GbxMaps - -### Output Data parameters ### -setuptxt = ./bin/spd_setup.txt # .txt filename to copy configuration to -stats_filename = ./bin/spd_stats.txt # .txt file to output runtime statistics to -zarrbasedir = ./bin/spd_SDMdata.zarr # zarr store base directory -maxchunk = 1250000 # maximum no. of elements in chunks of zarr store array - -### SDM Runtime parameters ### -# domain setup # -nspacedims = 3 # no. of spatial dimensions to model -ngbxs = 1800 # total number of Gbxs -totnsupers = 7200 # (initial) total no. of SDs - -# timestepping # -CONDTSTEP = 1 # time between SD condensation events [s] -COLLTSTEP = 1 # time between SD collision events [s] -MOTIONTSTEP = 3 # time between SDM motion [s] -COUPLTSTEP = 600 # time between dynamic couplings [s] -OBSTSTEP = 10 # time between SDM observations [s] -T_END = 1200 # time span of integration from 0s to T_END [s] - -# microphysics # -cond_iters = 2 # no. iterations of Newton Raphson Method before testing for convergence -cond_SUBTSTEP = 0.1 # smallest timestep in cases where substepping occurs [s] -cond_rtol = 0.0 # relative tolerance for implicit euler integration -cond_atol = 0.01 # abolute tolerance for implicit euler integration - -# superdroplets # -doAlterThermo = false # enable condensation to alter the thermodynamic state - -### Coupled Dynamics Solver Parameters ### -# type of coupling # -thermosolver = fromfile # dynamics solver to configure - -### read in dynamics from file ### -press_filename = ./share/spd_dimlessthermo_press.dat # binary filename for pressure -temp_filename = ./share/spd_dimlessthermo_temp.dat # binary filename for temperature -qvap_filename = ./share/spd_dimlessthermo_qvap.dat # binary filename for vapour mixing ratio -qcond_filename = ./share/spd_dimlessthermo_qcond.dat # binary filename for liquid mixing ratio -wvel_filename = ./share/spd_dimlessthermo_wvel.dat # binary filename for vertical (z) velocity -uvel_filename = ./share/spd_dimlessthermo_uvel.dat # binary filename for horizontal x velocity -vvel_filename = ./share/spd_dimlessthermo_vvel.dat # binary filename for horizontal y velocity diff --git a/examples/speedtest/src/config/speedtest_config.yaml b/examples/speedtest/src/config/speedtest_config.yaml new file mode 100644 index 000000000..96becfe9b --- /dev/null +++ b/examples/speedtest/src/config/speedtest_config.yaml @@ -0,0 +1,73 @@ +--- +# ----- CLEO ----- +# File: speedtest_config.yaml +# Project: config +# Created Date: Thursday 18th April 2024 +# Author: Clara Bayley (CB) +# Additional Contributors: +# ----- +# Last Modified: Thursday 18th April 2024 +# Modified By: CB +# ----- +# License: BSD 3-Clause "New" or "Revised" License +# https://opensource.org/licenses/BSD-3-Clause +# ----- +# Copyright (c) 2023 MPI-M, Clara Bayley +# ----- +# File Description: +# Configuration file for CLEO SDM speed test with constant thermodynamics. +# Note: The inital superdroplets data read from file "initsupers_filename" can be made with +# CLEO's pySD module (see Python script "create_initsuperdropsbinary_script.py" for usage). +# Likewise the "grid_filename" can be made using pySD (see "create_gbxboundariesbinary_script.py"), +# and so can the thermodynamics files when using coupled thermodynamics "fromfile". +# + +### Initialisation Parameters ### +inputfiles: + constants_filename : ../libs/cleoconstants.hpp # name of file for values of physical constants + grid_filename : ./share/spd_dimlessGBxboundaries.dat # binary filename for initialisation of GBxs / GbxMaps + +initsupers: + type : frombinary # type of initialisation of super-droplets + initsupers_filename : ./share/spd_dimlessSDsinit.dat # binary filename for initialisation of SDs + totnsupers : 7200 # initial total no. of SDs + +### Output Parameters ### +outputdata: + setup_filename : ./bin/spd_setup.txt # .txt filename to copy configuration to + stats_filename : ./bin/spd_stats.txt # .txt file to output runtime statistics to + zarrbasedir : ./bin/spd_SDMdata.zarr # zarr store base directory + maxchunk : 2500000 # maximum no. of elements in chunks of zarr store array + +### SDM Runtime Parameters ### +domain: + nspacedims : 3 # no. of spatial dimensions to model + ngbxs : 1800 # total number of Gbxs + +timesteps: + CONDTSTEP : 1 # time between SD condensation [s] + COLLTSTEP : 1 # time between SD collision [s] + MOTIONTSTEP : 3 # time between SDM motion [s] + COUPLTSTEP : 600 # time between dynamic couplings [s] + OBSTSTEP : 10 # time between SDM observations [s] + T_END : 1200 # time span of integration from 0s to T_END [s] + +### Microphysics Parameters ### +microphysics: + condensation: + do_alter_thermo : false # true = cond/evap alters the thermodynamic state + niters : 2 # no. iterations of Newton Raphson Method before testing for convergence + SUBTSTEP : 0.1 # smallest subtimestep in cases of substepping [s] + rtol : 0.0 # relative tolerance for implicit Euler integration + atol : 0.01 # abolute tolerance for implicit Euler integration + +### Coupled Dynamics Parameters ### +coupled_dynamics: + type : fromfile # type of coupled dynamics to configure + press : ./share/spd_dimlessthermo_press.dat # binary filename for pressure + temp : ./share/spd_dimlessthermo_temp.dat # binary filename for temperature + qvap : ./share/spd_dimlessthermo_qvap.dat # binary filename for vapour mixing ratio + qcond : ./share/spd_dimlessthermo_qcond.dat # binary filename for liquid mixing ratio + wvel : ./share/spd_dimlessthermo_wvel.dat # binary filename for vertical (coord3) velocity + uvel : ./share/spd_dimlessthermo_uvel.dat # binary filename for eastwards (coord1) velocity + vvel : ./share/spd_dimlessthermo_vvel.dat # binary filename for northwards (coord2) velocity diff --git a/examples/speedtest/src/main_spdtest.cpp b/examples/speedtest/src/main_spdtest.cpp index 784012e29..3c7ab2a4e 100644 --- a/examples/speedtest/src/main_spdtest.cpp +++ b/examples/speedtest/src/main_spdtest.cpp @@ -9,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Tuesday 16th April 2024 + * Last Modified: Thursday 18th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -18,7 +18,7 @@ * File Description: * runs the CLEO super-droplet model (SDM) for speed test model example. * After make/compiling, execute for example via: - * ./src/spdtest ../src/config/config.txt + * ./src/spdtest ../src/config/config.yaml */ #include @@ -71,18 +71,19 @@ inline CoupledDynamics auto create_coupldyn(const Config &config, const Cartesia const auto nsteps = (unsigned int)(std::ceil(t_end / couplstep) + 1); - return FromFileDynamics(config, couplstep, ndims, nsteps); + return FromFileDynamics(config.get_fromfiledynamics(), couplstep, ndims, nsteps); } inline InitialConditions auto create_initconds(const Config &config) { - const InitSupersFromBinary initsupers(config); - const InitGbxsNull initgbxs(config); + const InitSupersFromBinary initsupers(config.get_initsupersfrombinary()); + const InitGbxsNull initgbxs(config.get_ngbxs()); return InitConds(initsupers, initgbxs); } inline GridboxMaps auto create_gbxmaps(const Config &config) { - const auto gbxmaps = create_cartesian_maps(config.ngbxs, config.nspacedims, config.grid_filename); + const auto gbxmaps = create_cartesian_maps(config.get_ngbxs(), config.get_nspacedims(), + config.get_grid_filename()); return gbxmaps; } @@ -98,9 +99,10 @@ inline auto create_movement(const unsigned int motionstep, const CartesianMaps & inline MicrophysicalProcess auto config_condensation(const Config &config, const Timesteps &tsteps) { - return Condensation(tsteps.get_condstep(), config.doAlterThermo, config.cond_iters, - &step2dimlesstime, config.cond_rtol, config.cond_atol, config.cond_SUBTSTEP, - &realtime2dimless); + const auto c = config.get_condensation(); + + return Condensation(tsteps.get_condstep(), &step2dimlesstime, c.do_alter_thermo, c.niters, c.rtol, + c.atol, c.SUBTSTEP, &realtime2dimless); } inline MicrophysicalProcess auto config_collisions(const Config &config, const Timesteps &tsteps) { @@ -168,14 +170,14 @@ inline Observer auto create_bulk_observer(const unsigned int interval, Dataset inline Observer auto create_observer(const Config &config, const Timesteps &tsteps, Dataset &dataset) { - const auto obsstep = (unsigned int)tsteps.get_obsstep(); - const auto maxchunk = int{config.maxchunk}; + const auto obsstep = tsteps.get_obsstep(); + const auto maxchunk = config.get_maxchunk(); - const Observer auto obs0 = RunStatsObserver(obsstep, config.stats_filename); + const Observer auto obs0 = RunStatsObserver(obsstep, config.get_stats_filename()); const Observer auto obs1 = StreamOutObserver(obsstep * 10, &step2realtime); - const Observer auto obsblk = create_bulk_observer(obsstep, dataset, maxchunk, config.ngbxs); + const Observer auto obsblk = create_bulk_observer(obsstep, dataset, maxchunk, config.get_ngbxs()); const Observer auto obssd = create_superdrops_observer(obsstep, dataset, maxchunk); @@ -201,12 +203,12 @@ int main(int argc, char *argv[]) { Kokkos::Timer kokkostimer; /* Read input parameters from configuration file(s) */ - const std::string_view config_filename(argv[1]); // path to configuration file + const std::filesystem::path config_filename(argv[1]); // path to configuration file const Config config(config_filename); - const Timesteps tsteps(config); // timesteps for model (e.g. coupling and end time) + const Timesteps tsteps(config.get_timesteps()); /* Create zarr store for writing output to storage */ - auto store = FSStore(config.zarrbasedir); + auto store = FSStore(config.get_zarrbasedir()); auto dataset = Dataset(store); /* Initial conditions for CLEO run */ diff --git a/examples/yac/divfreemotion/src/config/divfree2d_config.txt b/examples/yac/divfreemotion/src/config/divfree2d_config.txt deleted file mode 100644 index bcf30cc52..000000000 --- a/examples/yac/divfreemotion/src/config/divfree2d_config.txt +++ /dev/null @@ -1,67 +0,0 @@ -/* - * ----- CLEO ----- - * File: divfree2d_config.txt - * Project: config - * Created Date: Tuesday 21st November 2023 - * Author: Clara Bayley (CB) - * Additional Contributors: - * ----- - * Last Modified: Tuesday 9th January 2024 - * Modified By: CB - * ----- - * License: BSD 3-Clause "New" or "Revised" License - * https://opensource.org/licenses/BSD-3-Clause - * ----- - * Copyright (c) 2023 MPI-M, Clara Bayley - * ----- - * File Description: - * configuration input parameters for CLEO divergence free motion example - */ - - -### Initialisation parameters ### -constants_filename = ../libs/cleoconstants.hpp # name of file for values of physical constants -initsupers_filename = ./share/df2d_dimlessSDsinit.dat # binary filename for initialisation of SDs -grid_filename = ./share/df2d_dimlessGBxboundaries.dat # binary filename for initialisation of GBxs / GbxMaps - -### Output Data parameters ### -setuptxt = ./bin/df2d_setup.txt # .txt filename to copy configuration to -stats_filename = ./bin/df2d_stats.txt # .txt file to output runtime statistics to -zarrbasedir = ./bin/df2d_sol.zarr # zarr store base directory -maxchunk = 1250000 # maximum no. of elements in chunks of zarr store array - -### SDM Runtime parameters ### -# domain setup # -nspacedims = 2 # no. of spatial dimensions to model -ngbxs = 900 # total number of Gbxs -totnsupers = 3600 # (initial) total no. of SDs - -# timestepping # -CONDTSTEP = 2 # time between SD condensation events [s] -COLLTSTEP = 2 # time between SD collision events [s] -MOTIONTSTEP = 3 # time between SDM motion [s] -COUPLTSTEP = 3600 # time between dynamic couplings [s] -OBSTSTEP = 180 # time between SDM observations [s] -T_END = 7200 # time span of integration from 0s to T_END [s] - -# microphysics # -cond_iters = 2 # no. iterations of Newton Raphson Method before testing for convergence -cond_SUBTSTEP = 0.1 # smallest timestep in cases where substepping occurs [s] -cond_rtol = 0.0 # relative tolerance for implicit euler integration -cond_atol = 0.01 # abolute tolerance for implicit euler integration - -# superdroplets # -doAlterThermo = false # enable condensation to alter the thermodynamic state - -### Coupled Dynamics Solver Parameters ### -# type of coupling # -thermosolver = fromfile # dynamics solver to configure - -### read in dynamics from file ### -press_filename = ./share/df2d_dimlessthermo_press.dat # binary filename for pressure -temp_filename = ./share/df2d_dimlessthermo_temp.dat # binary filename for temperature -qvap_filename = ./share/df2d_dimlessthermo_qvap.dat # binary filename for vapour mixing ratio -qcond_filename = ./share/df2d_dimlessthermo_qcond.dat # binary filename for liquid mixing ratio -wvel_filename = ./share/df2d_dimlessthermo_wvel.dat # binary filename for vertical (z) velocity -uvel_filename = ./share/df2d_dimlessthermo_uvel.dat # binary filename for horizontal x velocity -vvel_filename = ./share/df2d_dimlessthermo_vvel.dat # binary filename for horizontal y velocity diff --git a/examples/yac/divfreemotion/src/config/divfree2d_config.yaml b/examples/yac/divfreemotion/src/config/divfree2d_config.yaml new file mode 100644 index 000000000..940f92594 --- /dev/null +++ b/examples/yac/divfreemotion/src/config/divfree2d_config.yaml @@ -0,0 +1,53 @@ +--- +# ----- CLEO ----- +# File: divfree2d_config.yaml +# Project: config +# Created Date: Wednesday 17th April 2024 +# Author: Clara Bayley (CB) +# Additional Contributors: +# ----- +# Last Modified: Wednesday 17th April 2024 +# Modified By: CB +# ----- +# License: BSD 3-Clause "New" or "Revised" License +# https://opensource.org/licenses/BSD-3-Clause +# ----- +# Copyright (c) 2023 MPI-M, Clara Bayley +# ----- +# File Description: +# Configuration file for divergence free motion 2-D CLEO example. +# Note: The inital superdroplets data read from file "initsupers_filename" can be made with +# CLEO's pySD module (see Python script "create_initsuperdropsbinary_script.py" for usage). +# Likewise the "grid_filename" can be made using pySD (see "create_gbxboundariesbinary_script.py"), +# and so can the thermodynamics files when using coupled thermodynamics "fromfile". +# + +### Initialisation Parameters ### +inputfiles: + constants_filename : ../libs/cleoconstants.hpp # name of file for values of physical constants + grid_filename : ./share/df2d_dimlessGBxboundaries.dat # binary filename for initialisation of GBxs / GbxMaps + +initsupers: + type : frombinary # type of initialisation of super-droplets + initsupers_filename : ./share/df2d_dimlessSDsinit.dat # binary filename for initialisation of SDs + totnsupers : 3600 # initial total no. of SDs + +### Output Parameters ### +outputdata: + setup_filename : ./bin/df2d_setup.txt # .txt filename to copy configuration to + stats_filename : ./bin/df2d_stats.txt # .txt file to output runtime statistics to + zarrbasedir : ./bin/df2d_sol.zarr # zarr store base directory + maxchunk : 2500000 # maximum no. of elements in chunks of zarr store array + +### SDM Runtime Parameters ### +domain: + nspacedims : 2 # no. of spatial dimensions to model + ngbxs : 900 # total number of Gbxs + +timesteps: + CONDTSTEP : 3 # time between SD condensation [s] + COLLTSTEP : 3 # time between SD collision [s] + MOTIONTSTEP : 3 # time between SDM motion [s] + COUPLTSTEP : 3600 # time between dynamic couplings [s] + OBSTSTEP : 180 # time between SDM observations [s] + T_END : 7200 # time span of integration from 0s to T_END [s] diff --git a/examples/yac/divfreemotion/src/main_divfree2D.cpp b/examples/yac/divfreemotion/src/main_divfree2D.cpp index cc46f04d8..81ee06f98 100644 --- a/examples/yac/divfreemotion/src/main_divfree2D.cpp +++ b/examples/yac/divfreemotion/src/main_divfree2D.cpp @@ -9,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Tuesday 16th April 2024 + * Last Modified: Wednesday 17th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -18,7 +18,7 @@ * File Description: * runs the CLEO super-droplet model (SDM) for divergence free motion example using YAC. * after make/compiling, execute for example via: - * ./src/divfree2D_yac ../src/config/config.txt + * ./src/divfree2D_yac ../src/config/config.yaml */ #include @@ -66,14 +66,15 @@ inline CoupledDynamics auto create_coupldyn(const Config &config, const Cartesia } inline InitialConditions auto create_initconds(const Config &config) { - const InitSupersFromBinary initsupers(config); - const InitGbxsNull initgbxs(config); + const InitSupersFromBinary initsupers(config.get_initsupersfrombinary()); + const InitGbxsNull initgbxs(config.get_ngbxs()); return InitConds(initsupers, initgbxs); } inline GridboxMaps auto create_gbxmaps(const Config &config) { - const auto gbxmaps = create_cartesian_maps(config.ngbxs, config.nspacedims, config.grid_filename); + const auto gbxmaps = create_cartesian_maps(config.get_ngbxs(), config.get_nspacedims(), + config.get_grid_filename()); return gbxmaps; } @@ -107,8 +108,8 @@ inline Observer auto create_superdrops_observer(const unsigned int interval, template inline Observer auto create_observer(const Config &config, const Timesteps &tsteps, Dataset &dataset) { - const auto obsstep = (unsigned int)tsteps.get_obsstep(); - const auto maxchunk = int{config.maxchunk}; + const auto obsstep = tsteps.get_obsstep(); + const auto maxchunk = config.get_maxchunk(); const Observer auto obs0 = StreamOutObserver(obsstep, &step2realtime); @@ -138,12 +139,12 @@ int main(int argc, char *argv[]) { Kokkos::Timer kokkostimer; /* Read input parameters from configuration file(s) */ - const std::string_view config_filename(argv[1]); // path to configuration file + const std::filesystem::path config_filename(argv[1]); // path to configuration file const Config config(config_filename); - const Timesteps tsteps(config); // timesteps for model (e.g. coupling and end time) + const Timesteps tsteps(config.get_timesteps()); /* Create Xarray dataset wit Zarr backend for writing output data to a store */ - auto store = FSStore(config.zarrbasedir); + auto store = FSStore(config.get_zarrbasedir()); auto dataset = Dataset(store); /* Initial conditions for CLEO run */ diff --git a/examples/yac/fromfile/src/config/yac1_fromfile_config.txt b/examples/yac/fromfile/src/config/yac1_fromfile_config.txt deleted file mode 100644 index 565c35cbf..000000000 --- a/examples/yac/fromfile/src/config/yac1_fromfile_config.txt +++ /dev/null @@ -1,67 +0,0 @@ -/* - * ----- CLEO ----- - * File: yac1_fromfile_config.txt - * Project: config - * Created Date: Tuesday 21st November 2023 - * Author: Clara Bayley (CB) - * Additional Contributors: - * ----- - * Last Modified: Tuesday 26th March 2024 - * Modified By: CB - * ----- - * License: BSD 3-Clause "New" or "Revised" License - * https://opensource.org/licenses/BSD-3-Clause - * ----- - * Copyright (c) 2023 MPI-M, Clara Bayley - * ----- - * File Description: - * configuration input parameters for CLEO yac test 1, with 3D time vayring - * thermodyanamics read from a file. - */ - -### Initialisation parameters ### -constants_filename = ../libs/cleoconstants.hpp # name of file for values of physical constants -initsupers_filename = ./share/yac1_dimlessSDsinit.dat # binary filename for initialisation of SDs -grid_filename = ./share/yac1_dimlessGBxboundaries.dat # binary filename for initialisation of GBxs / GbxMaps - -### Output Data parameters ### -setuptxt = ./bin/yac1_setup.txt # .txt filename to copy configuration to -stats_filename = ./bin/yac1_stats.txt # .txt file to output runtime statistics to -zarrbasedir = ./bin/yac1_sol.zarr # zarr store base directory -maxchunk = 1250000 # maximum no. of elements in chunks of zarr store array - -### SDM Runtime parameters ### -# domain setup # -nspacedims = 3 # no. of spatial dimensions to model -ngbxs = 2250 # total number of Gbxs -totnsupers = 2880 # (initial) total no. of SDs - -# timestepping # -CONDTSTEP = 2 # time between SD condensation events [s] -COLLTSTEP = 2 # time between SD collision events [s] -MOTIONTSTEP = 3 # time between SDM motion [s] -COUPLTSTEP = 1800 # time between dynamic couplings [s] -OBSTSTEP = 1800 # time between SDM observations [s] -T_END = 7200 # time span of integration from 0s to T_END [s] - -# microphysics # -cond_iters = 2 # no. iterations of Newton Raphson Method before testing for convergence -cond_SUBTSTEP = 0.1 # smallest timestep in cases where substepping occurs [s] -cond_rtol = 0.0 # relative tolerance for implicit euler integration -cond_atol = 0.01 # abolute tolerance for implicit euler integration - -# superdroplets # -doAlterThermo = false # enable condensation to alter the thermodynamic state - -### Coupled Dynamics Solver Parameters ### -# type of coupling # -thermosolver = fromfile # dynamics solver to configure - -### read in dynamics from file ### -press_filename = ./share/yac1_dimlessthermo_press.dat # binary filename for pressure -temp_filename = ./share/yac1_dimlessthermo_temp.dat # binary filename for temperature -qvap_filename = ./share/yac1_dimlessthermo_qvap.dat # binary filename for vapour mixing ratio -qcond_filename = ./share/yac1_dimlessthermo_qcond.dat # binary filename for liquid mixing ratio -wvel_filename = ./share/yac1_dimlessthermo_wvel.dat # binary filename for vertical (z) velocity -uvel_filename = ./share/yac1_dimlessthermo_uvel.dat # binary filename for horizontal x velocity -vvel_filename = ./share/yac1_dimlessthermo_vvel.dat # binary filename for horizontal y velocity diff --git a/examples/yac/fromfile/src/config/yac1_fromfile_config.yaml b/examples/yac/fromfile/src/config/yac1_fromfile_config.yaml new file mode 100644 index 000000000..4a0a27736 --- /dev/null +++ b/examples/yac/fromfile/src/config/yac1_fromfile_config.yaml @@ -0,0 +1,64 @@ +--- +# ----- CLEO ----- +# File: yac1_fromfile_config.txt +# Project: config +# Created Date: Thursday 18th April 2024 +# Author: Clara Bayley (CB) +# Additional Contributors: +# ----- +# Last Modified: Thursday 18th April 2024 +# Modified By: CB +# ----- +# License: BSD 3-Clause "New" or "Revised" License +# https://opensource.org/licenses/BSD-3-Clause +# ----- +# Copyright (c) 2023 MPI-M, Clara Bayley +# ----- +# File Description: +# Configuration file for contol example of 3D time varying thermodyanamics read from a file. +# Note: The inital superdroplets data read from file "initsupers_filename" can be made with +# CLEO's pySD module (see Python script "create_initsuperdropsbinary_script.py" for usage). +# Likewise the "grid_filename" can be made using pySD (see "create_gbxboundariesbinary_script.py"), +# and so can the thermodynamics files when using coupled thermodynamics "fromfile". +# + +### Initialisation Parameters ### +inputfiles: + constants_filename : ../libs/cleoconstants.hpp # name of file for values of physical constants + grid_filename : ./share/yac1_dimlessGBxboundaries.dat # binary filename for initialisation of GBxs / GbxMaps + +initsupers: + type : frombinary # type of initialisation of super-droplets + initsupers_filename : ./share/yac1_dimlessSDsinit.dat # binary filename for initialisation of SDs + totnsupers : 2880 # initial total no. of SDs + +### Output Parameters ### +outputdata: + setup_filename : ./bin/yac1_setup.txt # .txt filename to copy configuration to + stats_filename : ./bin/yac1_stats.txt # .txt file to output runtime statistics to + zarrbasedir : ./bin/yac1_sol.zarr # zarr store base directory + maxchunk : 2500000 # maximum no. of elements in chunks of zarr store array + +### SDM Runtime Parameters ### +domain: + nspacedims : 3 # no. of spatial dimensions to model + ngbxs : 2250 # total number of Gbxs + +timesteps: + CONDTSTEP : 2 # time between SD condensation [s] + COLLTSTEP : 2 # time between SD collision [s] + MOTIONTSTEP : 3 # time between SDM motion [s] + COUPLTSTEP : 1800 # time between dynamic couplings [s] + OBSTSTEP : 1800 # time between SDM observations [s] + T_END : 7200 # time span of integration from 0s to T_END [s] + +### Coupled Dynamics Parameters ### +coupled_dynamics: + type : fromfile # type of coupled dynamics to configure + press : ./share/yac1_dimlessthermo_press.dat # binary filename for pressure + temp : ./share/yac1_dimlessthermo_temp.dat # binary filename for temperature + qvap : ./share/yac1_dimlessthermo_qvap.dat # binary filename for vapour mixing ratio + qcond : ./share/yac1_dimlessthermo_qcond.dat # binary filename for liquid mixing ratio + wvel : ./share/yac1_dimlessthermo_wvel.dat # binary filename for vertical (coord3) velocity + uvel : ./share/yac1_dimlessthermo_uvel.dat # binary filename for eastwards (coord1) velocity + vvel : ./share/yac1_dimlessthermo_vvel.dat # binary filename for eastwards (coord1) velocity diff --git a/examples/yac/fromfile/src/gen_input_thermo.py b/examples/yac/fromfile/src/gen_input_thermo.py index ab47fb652..f5f488565 100644 --- a/examples/yac/fromfile/src/gen_input_thermo.py +++ b/examples/yac/fromfile/src/gen_input_thermo.py @@ -9,7 +9,7 @@ Author: Clara Bayley (CB) Additional Contributors: ----- -Last Modified: Monday 25th March 2024 +Last Modified: Wednesday 17th April 2024 Modified By: CB ----- License: BSD 3-Clause "New" or "Revised" License @@ -25,7 +25,6 @@ import numpy as np sys.path.append("../../../..") # for imports from pySD package -from pySD import cxx2py from pySD.thermobinary_src.create_thermodynamics import thermoinputsdict from pySD.gbxboundariesbinary_src import read_gbxboundaries as rgrid diff --git a/examples/yac/fromfile/src/main_yac1.cpp b/examples/yac/fromfile/src/main_yac1.cpp index 3286d65d0..05c4ad4f4 100644 --- a/examples/yac/fromfile/src/main_yac1.cpp +++ b/examples/yac/fromfile/src/main_yac1.cpp @@ -9,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Tuesday 16th April 2024 + * Last Modified: Thursday 18th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -18,7 +18,7 @@ * File Description: * runs the CLEO super-droplet model (SDM) for 3-D setup as control for yac_3d example * after make/compiling, execute for example via: - * ./src/yac1 ../src/config/config.txt + * ./src/yac1 ../src/config/config.yaml */ #include @@ -63,18 +63,19 @@ inline CoupledDynamics auto create_coupldyn(const Config &config, const Cartesia const auto nsteps = (unsigned int)(std::ceil(t_end / couplstep) + 1); - return FromFileDynamics(config, couplstep, ndims, nsteps); + return FromFileDynamics(config.get_fromfiledynamics(), couplstep, ndims, nsteps); } inline InitialConditions auto create_initconds(const Config &config) { - const InitSupersFromBinary initsupers(config); - const InitGbxsNull initgbxs(config); + const InitSupersFromBinary initsupers(config.get_initsupersfrombinary()); + const InitGbxsNull initgbxs(config.get_ngbxs()); return InitConds(initsupers, initgbxs); } inline GridboxMaps auto create_gbxmaps(const Config &config) { - const auto gbxmaps = create_cartesian_maps(config.ngbxs, config.nspacedims, config.grid_filename); + const auto gbxmaps = create_cartesian_maps(config.get_ngbxs(), config.get_nspacedims(), + config.get_grid_filename()); return gbxmaps; } @@ -108,16 +109,17 @@ inline Observer auto create_superdrops_observer(const unsigned int interval, template inline Observer auto create_observer(const Config &config, const Timesteps &tsteps, Dataset &dataset) { - const auto obsstep = (unsigned int)tsteps.get_obsstep(); - const auto maxchunk = int{config.maxchunk}; + const auto obsstep = tsteps.get_obsstep(); + const auto maxchunk = config.get_maxchunk(); + const auto ngbxs = config.get_ngbxs(); const Observer auto obs0 = StreamOutObserver(obsstep, &step2realtime); const Observer auto obs1 = TimeObserver(obsstep, dataset, maxchunk, &step2dimlesstime); - const Observer auto obs2 = GbxindexObserver(dataset, maxchunk, config.ngbxs); + const Observer auto obs2 = GbxindexObserver(dataset, maxchunk, ngbxs); - const Observer auto obs3 = StateObserver(obsstep, dataset, maxchunk, config.ngbxs); + const Observer auto obs3 = StateObserver(obsstep, dataset, maxchunk, ngbxs); const Observer auto obssd = create_superdrops_observer(obsstep, dataset, maxchunk); @@ -143,12 +145,12 @@ int main(int argc, char *argv[]) { Kokkos::Timer kokkostimer; /* Read input parameters from configuration file(s) */ - const std::string_view config_filename(argv[1]); // path to configuration file + const std::filesystem::path config_filename(argv[1]); // path to configuration file const Config config(config_filename); - const Timesteps tsteps(config); // timesteps for model (e.g. coupling and end time) + const Timesteps tsteps(config.get_timesteps()); /* Create Xarray dataset wit Zarr backend for writing output data to a store */ - auto store = FSStore(config.zarrbasedir); + auto store = FSStore(config.get_zarrbasedir()); auto dataset = Dataset(store); /* Initial conditions for CLEO run */ diff --git a/examples/yac/fromfile/yac1_fromfile.sh b/examples/yac/fromfile/yac1_fromfile.sh index aff321fa1..d6c3c361e 100755 --- a/examples/yac/fromfile/yac1_fromfile.sh +++ b/examples/yac/fromfile/yac1_fromfile.sh @@ -23,7 +23,7 @@ path2build=${HOME}/CLEO/build_yac1/ executables="yac1" pythonscript=${path2CLEO}/examples/yac/fromfile/yac1_fromfile.py -configfile=${path2CLEO}/examples/yac/fromfile/src/config/yac1_fromfile_config.txt +configfile=${path2CLEO}/examples/yac/fromfile/src/config/yac1_fromfile_config.yaml script_args="${configfile}" ### ---------------------------------------------------- ### ### ---------------------------------------------------- ### diff --git a/examples/yac/yac_3d/src/config/yac1_fromfile_config.txt b/examples/yac/yac_3d/src/config/yac1_fromfile_config.txt deleted file mode 100644 index 565c35cbf..000000000 --- a/examples/yac/yac_3d/src/config/yac1_fromfile_config.txt +++ /dev/null @@ -1,67 +0,0 @@ -/* - * ----- CLEO ----- - * File: yac1_fromfile_config.txt - * Project: config - * Created Date: Tuesday 21st November 2023 - * Author: Clara Bayley (CB) - * Additional Contributors: - * ----- - * Last Modified: Tuesday 26th March 2024 - * Modified By: CB - * ----- - * License: BSD 3-Clause "New" or "Revised" License - * https://opensource.org/licenses/BSD-3-Clause - * ----- - * Copyright (c) 2023 MPI-M, Clara Bayley - * ----- - * File Description: - * configuration input parameters for CLEO yac test 1, with 3D time vayring - * thermodyanamics read from a file. - */ - -### Initialisation parameters ### -constants_filename = ../libs/cleoconstants.hpp # name of file for values of physical constants -initsupers_filename = ./share/yac1_dimlessSDsinit.dat # binary filename for initialisation of SDs -grid_filename = ./share/yac1_dimlessGBxboundaries.dat # binary filename for initialisation of GBxs / GbxMaps - -### Output Data parameters ### -setuptxt = ./bin/yac1_setup.txt # .txt filename to copy configuration to -stats_filename = ./bin/yac1_stats.txt # .txt file to output runtime statistics to -zarrbasedir = ./bin/yac1_sol.zarr # zarr store base directory -maxchunk = 1250000 # maximum no. of elements in chunks of zarr store array - -### SDM Runtime parameters ### -# domain setup # -nspacedims = 3 # no. of spatial dimensions to model -ngbxs = 2250 # total number of Gbxs -totnsupers = 2880 # (initial) total no. of SDs - -# timestepping # -CONDTSTEP = 2 # time between SD condensation events [s] -COLLTSTEP = 2 # time between SD collision events [s] -MOTIONTSTEP = 3 # time between SDM motion [s] -COUPLTSTEP = 1800 # time between dynamic couplings [s] -OBSTSTEP = 1800 # time between SDM observations [s] -T_END = 7200 # time span of integration from 0s to T_END [s] - -# microphysics # -cond_iters = 2 # no. iterations of Newton Raphson Method before testing for convergence -cond_SUBTSTEP = 0.1 # smallest timestep in cases where substepping occurs [s] -cond_rtol = 0.0 # relative tolerance for implicit euler integration -cond_atol = 0.01 # abolute tolerance for implicit euler integration - -# superdroplets # -doAlterThermo = false # enable condensation to alter the thermodynamic state - -### Coupled Dynamics Solver Parameters ### -# type of coupling # -thermosolver = fromfile # dynamics solver to configure - -### read in dynamics from file ### -press_filename = ./share/yac1_dimlessthermo_press.dat # binary filename for pressure -temp_filename = ./share/yac1_dimlessthermo_temp.dat # binary filename for temperature -qvap_filename = ./share/yac1_dimlessthermo_qvap.dat # binary filename for vapour mixing ratio -qcond_filename = ./share/yac1_dimlessthermo_qcond.dat # binary filename for liquid mixing ratio -wvel_filename = ./share/yac1_dimlessthermo_wvel.dat # binary filename for vertical (z) velocity -uvel_filename = ./share/yac1_dimlessthermo_uvel.dat # binary filename for horizontal x velocity -vvel_filename = ./share/yac1_dimlessthermo_vvel.dat # binary filename for horizontal y velocity diff --git a/examples/yac/yac_3d/src/config/yac1_fromfile_config.yaml b/examples/yac/yac_3d/src/config/yac1_fromfile_config.yaml new file mode 100644 index 000000000..6414957d7 --- /dev/null +++ b/examples/yac/yac_3d/src/config/yac1_fromfile_config.yaml @@ -0,0 +1,53 @@ +--- +# ----- CLEO ----- +# File: yac1_fromfile_config.txt +# Project: config +# Created Date: Thursday 18th April 2024 +# Author: Clara Bayley (CB) +# Additional Contributors: +# ----- +# Last Modified: Thursday 18th April 2024 +# Modified By: CB +# ----- +# License: BSD 3-Clause "New" or "Revised" License +# https://opensource.org/licenses/BSD-3-Clause +# ----- +# Copyright (c) 2023 MPI-M, Clara Bayley +# ----- +# File Description: +# Configuration file for test of YAC with 3D time varying thermodyanamics example. +# Note: The inital superdroplets data read from file "initsupers_filename" can be made with +# CLEO's pySD module (see Python script "create_initsuperdropsbinary_script.py" for usage). +# Likewise the "grid_filename" can be made using pySD (see "create_gbxboundariesbinary_script.py"), +# and so can the thermodynamics files when using coupled thermodynamics "fromfile". +# + +### Initialisation Parameters ### +inputfiles: + constants_filename : ../libs/cleoconstants.hpp # name of file for values of physical constants + grid_filename : ./share/yac1_dimlessGBxboundaries.dat # binary filename for initialisation of GBxs / GbxMaps + +initsupers: + type : frombinary # type of initialisation of super-droplets + initsupers_filename : ./share/yac1_dimlessSDsinit.dat # binary filename for initialisation of SDs + totnsupers : 2880 # initial total no. of SDs + +### Output Parameters ### +outputdata: + setup_filename : ./bin/yac1_setup.txt # .txt filename to copy configuration to + stats_filename : ./bin/yac1_stats.txt # .txt file to output runtime statistics to + zarrbasedir : ./bin/yac1_sol.zarr # zarr store base directory + maxchunk : 2500000 # maximum no. of elements in chunks of zarr store array + +### SDM Runtime Parameters ### +domain: + nspacedims : 3 # no. of spatial dimensions to model + ngbxs : 2250 # total number of Gbxs + +timesteps: + CONDTSTEP : 2 # time between SD condensation [s] + COLLTSTEP : 2 # time between SD collision [s] + MOTIONTSTEP : 3 # time between SDM motion [s] + COUPLTSTEP : 1800 # time between dynamic couplings [s] + OBSTSTEP : 1800 # time between SDM observations [s] + T_END : 7200 # time span of integration from 0s to T_END [s] diff --git a/examples/yac/yac_3d/src/gen_input_thermo.py b/examples/yac/yac_3d/src/gen_input_thermo.py index d06776302..56dd32593 100644 --- a/examples/yac/yac_3d/src/gen_input_thermo.py +++ b/examples/yac/yac_3d/src/gen_input_thermo.py @@ -9,7 +9,7 @@ Author: Clara Bayley (CB) Additional Contributors: ----- -Last Modified: Monday 8th April 2024 +Last Modified: Wednesday 17th April 2024 Modified By: CB ----- License: BSD 3-Clause "New" or "Revised" License @@ -25,7 +25,6 @@ import numpy as np sys.path.append("../../../..") # for imports from pySD package -from pySD import cxx2py from pySD.thermobinary_src.create_thermodynamics import thermoinputsdict from pySD.gbxboundariesbinary_src import read_gbxboundaries as rgrid diff --git a/examples/yac/yac_3d/src/main_yac1.cpp b/examples/yac/yac_3d/src/main_yac1.cpp index a38225e41..81b4b3ced 100644 --- a/examples/yac/yac_3d/src/main_yac1.cpp +++ b/examples/yac/yac_3d/src/main_yac1.cpp @@ -9,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Tuesday 16th April 2024 + * Last Modified: Wednesday 17th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -18,7 +18,7 @@ * File Description: * runs the CLEO super-droplet model (SDM) for yac_3d example using YAC. * after make/compiling, execute for example via: - * ./src/yac1 ../src/config/config.txt + * ./src/yac1 ../src/config/config.yaml */ #include @@ -67,14 +67,15 @@ inline CoupledDynamics auto create_coupldyn(const Config &config, const Cartesia } inline InitialConditions auto create_initconds(const Config &config) { - const InitSupersFromBinary initsupers(config); - const InitGbxsNull initgbxs(config); + const InitSupersFromBinary initsupers(config.get_initsupersfrombinary()); + const InitGbxsNull initgbxs(config.get_ngbxs()); return InitConds(initsupers, initgbxs); } inline GridboxMaps auto create_gbxmaps(const Config &config) { - const auto gbxmaps = create_cartesian_maps(config.ngbxs, config.nspacedims, config.grid_filename); + const auto gbxmaps = create_cartesian_maps(config.get_ngbxs(), config.get_nspacedims(), + config.get_grid_filename()); return gbxmaps; } @@ -108,16 +109,17 @@ inline Observer auto create_superdrops_observer(const unsigned int interval, template inline Observer auto create_observer(const Config &config, const Timesteps &tsteps, Dataset &dataset) { - const auto obsstep = (unsigned int)tsteps.get_obsstep(); - const auto maxchunk = int{config.maxchunk}; + const auto obsstep = tsteps.get_obsstep(); + const auto maxchunk = config.get_maxchunk(); + const auto ngbxs = config.get_ngbxs(); const Observer auto obs0 = StreamOutObserver(obsstep, &step2realtime); const Observer auto obs1 = TimeObserver(obsstep, dataset, maxchunk, &step2dimlesstime); - const Observer auto obs2 = GbxindexObserver(dataset, maxchunk, config.ngbxs); + const Observer auto obs2 = GbxindexObserver(dataset, maxchunk, ngbxs); - const Observer auto obs3 = StateObserver(obsstep, dataset, maxchunk, config.ngbxs); + const Observer auto obs3 = StateObserver(obsstep, dataset, maxchunk, ngbxs); const Observer auto obssd = create_superdrops_observer(obsstep, dataset, maxchunk); @@ -143,12 +145,12 @@ int main(int argc, char *argv[]) { Kokkos::Timer kokkostimer; /* Read input parameters from configuration file(s) */ - const std::string_view config_filename(argv[1]); // path to configuration file + const std::filesystem::path config_filename(argv[1]); // path to configuration file const Config config(config_filename); - const Timesteps tsteps(config); // timesteps for model (e.g. coupling and end time) + const Timesteps tsteps(config.get_timesteps()); /* Create Xarray dataset wit Zarr backend for writing output data to a store */ - auto store = FSStore(config.zarrbasedir); + auto store = FSStore(config.get_zarrbasedir()); auto dataset = Dataset(store); /* Initial conditions for CLEO run */ diff --git a/extern/yaml-cpp/CMakeLists.txt b/extern/yaml-cpp/CMakeLists.txt new file mode 100644 index 000000000..8d1ef8d99 --- /dev/null +++ b/extern/yaml-cpp/CMakeLists.txt @@ -0,0 +1,16 @@ +# set cmake version +if(NOT DEFINED CMAKE_MINIMUM_REQUIRED_VERSION) + cmake_minimum_required(VERSION 3.18.0) +endif() + +# fetch and make yaml-cpp library available +include(FetchContent) +FetchContent_Declare( + yaml-cpp + DOWNLOAD_EXTRACT_TIMESTAMP TRUE + URL https://github.com/jbeder/yaml-cpp/archive/refs/tags/0.8.0.tar.gz + GIT_TAG f7320141120f720aecc4c32be25586e7da9eb978 +) +FetchContent_MakeAvailable(yaml-cpp) + +message(STATUS "yaml-cpp installation in: ${CMAKE_BINARY_DIR}/_deps/yaml-cpp") diff --git a/libs/cartesiandomain/createcartesianmaps.cpp b/libs/cartesiandomain/createcartesianmaps.cpp index 7d3427e80..7ebf5a807 100644 --- a/libs/cartesiandomain/createcartesianmaps.cpp +++ b/libs/cartesiandomain/createcartesianmaps.cpp @@ -9,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Tuesday 16th April 2024 + * Last Modified: Thursday 18th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -61,8 +61,8 @@ however the area and volume of each gridbox remains finite. E.g. In the 0-D case, the bounds maps all have 1 {key, value} where key=gbxidx=0 and value = {max, min} numerical limits, meanwhile volume function returns a value determined from the gridfile 'grid_filename' */ -CartesianMaps create_cartesian_maps(const unsigned int ngbxs, const unsigned int nspacedims, - std::string_view grid_filename) { +CartesianMaps create_cartesian_maps(const size_t ngbxs, const unsigned int nspacedims, + const std::filesystem::path grid_filename) { std::cout << "\n--- create cartesian gridbox maps ---\n"; const GbxBoundsFromBinary gfb(ngbxs, nspacedims, grid_filename); diff --git a/libs/cartesiandomain/createcartesianmaps.hpp b/libs/cartesiandomain/createcartesianmaps.hpp index 0b8e8e593..4020277b1 100644 --- a/libs/cartesiandomain/createcartesianmaps.hpp +++ b/libs/cartesiandomain/createcartesianmaps.hpp @@ -9,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Tuesday 16th April 2024 + * Last Modified: Thursday 18th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -46,7 +47,7 @@ gridbox remains finite. E.g. In the 0-D case, the bounds maps all have 1 {key, value} where key=gbxidx=0 and value = {max, min} numerical limits, meanwhile volume function returns a value determined from the gridfile 'grid_filename' */ -CartesianMaps create_cartesian_maps(const unsigned int ngbxs, const unsigned int nspacedims, - std::string_view grid_filename); +CartesianMaps create_cartesian_maps(const size_t ngbxs, const unsigned int nspacedims, + const std::filesystem::path grid_filename); #endif // LIBS_CARTESIANDOMAIN_CREATECARTESIANMAPS_HPP_ diff --git a/libs/cartesiandomain/withreset.hpp b/libs/cartesiandomain/withreset.hpp index 31a1c9ac9..6174457f2 100644 --- a/libs/cartesiandomain/withreset.hpp +++ b/libs/cartesiandomain/withreset.hpp @@ -9,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Tuesday 16th April 2024 + * Last Modified: Thursday 18th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -90,11 +90,11 @@ struct ProbDistrib { struct ResetSuperdrop { GenRandomPool genpool4reset; Kokkos::View log10redges; // edges to radius bins - Kokkos::pair gbxidxs; + Kokkos::pair gbxidxs; uint64_t nbins; ProbDistrib prob_distrib; - ResetSuperdrop(const unsigned int ngbxs, const unsigned int ngbxs4reset) + ResetSuperdrop(const size_t ngbxs, const size_t ngbxs4reset) : genpool4reset(std::random_device {}()), log10redges("log10redges"), gbxidxs({ngbxs - ngbxs4reset, ngbxs}), @@ -210,7 +210,7 @@ coord3(...){...} function */ struct CartesianChangeIfNghbrWithReset { ResetSuperdrop reset_superdrop; - CartesianChangeIfNghbrWithReset(const unsigned int ngbxs, const unsigned int ngbxs4reset) + CartesianChangeIfNghbrWithReset(const size_t ngbxs, const size_t ngbxs4reset) : reset_superdrop(ResetSuperdrop(ngbxs, ngbxs4reset)) {} KOKKOS_INLINE_FUNCTION unsigned int coord3(const CartesianMaps &gbxmaps, unsigned int idx, @@ -237,7 +237,7 @@ template inline PredCorrMotion CartesianMotionWithReset(const unsigned int motionstep, const std::function int2time, const TV terminalv, - const unsigned int ngbxs, const unsigned int ngbxs4reset) { + const size_t ngbxs, const size_t ngbxs4reset) { const auto cin = CartesianChangeIfNghbrWithReset(ngbxs, ngbxs4reset); return PredCorrMotion( motionstep, int2time, terminalv, cin, CartesianCheckBounds{}); diff --git a/libs/coupldyn_cvode/cvodedynamics.cpp b/libs/coupldyn_cvode/cvodedynamics.cpp index 06a76e5df..aedd73759 100644 --- a/libs/coupldyn_cvode/cvodedynamics.cpp +++ b/libs/coupldyn_cvode/cvodedynamics.cpp @@ -1,4 +1,6 @@ -/* Copyright (c) 2023 MPI-M, Clara Bayley +/* + * Copyright (c) 2024 MPI-M, Clara Bayley + * * * ----- CLEO ----- * File: cvodedynamics.cpp @@ -7,15 +9,14 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Thursday 14th December 2023 + * Last Modified: Wednesday 17th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License * https://opensource.org/licenses/BSD-3-Clause * ----- * File Description: - * functionality for coupleddynamics concept for - * dynamics solver in CLEO where coupling is + * functionality for coupleddynamics concept for dynamics solver in CLEO where coupling is * two-way to cvode adiabatic parcel ODE solver */ @@ -81,7 +82,8 @@ int CvodeDynamics::reinitialise(const double next_t, const std::vector & } /* construct instance of CVODE ODE solver with initial conditions */ -CvodeDynamics::CvodeDynamics(const Config &config, const unsigned int couplstep, +CvodeDynamics::CvodeDynamics(const OptionalConfigParams::CvodeDynamicsParams &config, + const unsigned int couplstep, const std::function step2dimlesstime) : interval(couplstep), step2dimlesstime(step2dimlesstime), @@ -99,12 +101,12 @@ CvodeDynamics::CvodeDynamics(const Config &config, const unsigned int couplstep, const auto wmax = double{ (M_PI / 2) * - (config.W_AVG / + (config.W_avg / dlc::W0)}; // dimensionless w velocity passed to thermo ODEs eg. dp_dt(t,y,ydot,w,...) const auto tauhalf = - double{(config.T_HALF / dlc::TIME0) / M_PI}; // dimensionless timescale for w sinusoid + double{(config.TAU_half / dlc::TIME0) / M_PI}; // dimensionless timescale for w sinusoid init_userdata(neq, wmax, tauhalf); - setup_ODE_solver(config.cvode_rtol, config.cvode_atol); + setup_ODE_solver(config.rtol, config.atol); } /* print final statistics to the terminal screen */ @@ -125,9 +127,10 @@ CvodeDynamics::~CvodeDynamics() { /* return vector of dimensionless initial conditions for thermodynamic variables (p, temp, qv, qc) to initialise cvode thermodynamics solver */ -std::vector CvodeDynamics::initial_conditions(const Config &config) const { - const auto press_i = double{config.P_INIT / dlc::P0}; - const auto temp_i = double{config.TEMP_INIT / dlc::TEMP0}; +std::vector CvodeDynamics::initial_conditions( + const OptionalConfigParams::CvodeDynamicsParams &config) const { + const auto press_i = double{config.P_init / dlc::P0}; + const auto temp_i = double{config.TEMP_init / dlc::TEMP0}; const auto qcond_i = double{0.0}; const auto psat = double{cvode_saturationpressure(temp_i)}; diff --git a/libs/coupldyn_cvode/cvodedynamics.hpp b/libs/coupldyn_cvode/cvodedynamics.hpp index 491a0758e..947d79bac 100644 --- a/libs/coupldyn_cvode/cvodedynamics.hpp +++ b/libs/coupldyn_cvode/cvodedynamics.hpp @@ -1,4 +1,6 @@ -/* Copyright (c) 2023 MPI-M, Clara Bayley +/* + * Copyright (c) 2024 MPI-M, Clara Bayley + * * * ----- CLEO ----- * File: cvodedynamics.hpp @@ -7,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Tuesday 21st November 2023 + * Last Modified: Wednesday 17th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -36,7 +38,7 @@ #include "../cleoconstants.hpp" #include "./differentialfuncs.hpp" -#include "initialise/config.hpp" +#include "initialise/optional_config_params.hpp" namespace dlc = dimless_constants; @@ -76,7 +78,8 @@ struct CvodeDynamics { /* return vector of dimensionless initial conditions for thermodynamic variables (p, temp, qv, qc) to initialise cvode thermodynamics solver */ - std::vector initial_conditions(const Config &config) const; + std::vector initial_conditions( + const OptionalConfigParams::CvodeDynamicsParams &config) const; /* set values in UserData structure for odes_func */ void init_userdata(const size_t neq, const double wmax, const double tauhalf); @@ -91,7 +94,8 @@ struct CvodeDynamics { public: /* construct instance of CVODE ODE solver with initial conditions */ - CvodeDynamics(const Config &config, const unsigned int couplstep, + CvodeDynamics(const OptionalConfigParams::CvodeDynamicsParams &config, + const unsigned int couplstep, const std::function step2dimlesstime); /* print final statistics to the diff --git a/libs/coupldyn_cvode/initgbxs_cvode.hpp b/libs/coupldyn_cvode/initgbxs_cvode.hpp index bf373a7b0..8db61f12e 100644 --- a/libs/coupldyn_cvode/initgbxs_cvode.hpp +++ b/libs/coupldyn_cvode/initgbxs_cvode.hpp @@ -1,4 +1,6 @@ -/* Copyright (c) 2023 MPI-M, Clara Bayley +/* + * Copyright (c) 2024 MPI-M, Clara Bayley + * * * ----- CLEO ----- * File: initgbxs_cvode.hpp @@ -7,17 +9,15 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Thursday 14th December 2023 + * Last Modified: Wednesday 17th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License * https://opensource.org/licenses/BSD-3-Clause * ----- * File Description: - * struct for griboxes' initial conditions - * for CLEO SDM (e.g. thermodynamics) - * when coupled to cvode thermodynamics solver. - * Struct can be used by InitConds as + * struct for griboxes' initial conditions for CLEO SDM (e.g. thermodynamics) + * when coupled to cvode thermodynamics solver. Struct can be used by InitConds as * GbxInitConds type */ @@ -29,7 +29,7 @@ #include "../cleoconstants.hpp" #include "coupldyn_cvode/differentialfuncs.hpp" -#include "initialise/config.hpp" +#include "initialise/optional_config_params.hpp" namespace dlc = dimless_constants; @@ -46,21 +46,21 @@ struct InitGbxsCvode { double qcond_i; // initial liquid water mixing ratio public: - explicit InitGbxsCvode(const Config &config) + explicit InitGbxsCvode(const OptionalConfigParams::CvodeDynamicsParams &config) : ngbxs(config.ngbxs), - press_i(config.P_INIT / dlc::P0), - temp_i(config.TEMP_INIT / dlc::TEMP0), + press_i(config.P_init / dlc::P0), + temp_i(config.TEMP_init / dlc::TEMP0), relh_init(config.relh_init), qcond_i(0.0) {} size_t get_ngbxs() const { return ngbxs; } /* pressure for all gbxs is same initial - (dimless) 'press_i' given by PRESS_INIT */ + (dimless) 'press_i' given by PRESS_init */ std::vector press() const { return std::vector(ngbxs, press_i); } /* temperature for all gbxs is same initial - (dimless) 'temp' given by TEMP_INIT */ + (dimless) 'temp' given by TEMP_init */ std::vector temp() const { return std::vector(ngbxs, temp_i); } /* vapour mass mixing ratio, 'qvap' for all diff --git a/libs/coupldyn_fromfile/fromfile_cartesian_dynamics.cpp b/libs/coupldyn_fromfile/fromfile_cartesian_dynamics.cpp index 237dd42d4..f45377c45 100644 --- a/libs/coupldyn_fromfile/fromfile_cartesian_dynamics.cpp +++ b/libs/coupldyn_fromfile/fromfile_cartesian_dynamics.cpp @@ -1,4 +1,6 @@ -/* Copyright (c) 2023 MPI-M, Clara Bayley +/* + * Copyright (c) 2024 MPI-M, Clara Bayley + * * * ----- CLEO ----- * File: fromfile_cartesian_dynamics.cpp @@ -7,23 +9,21 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Sunday 17th December 2023 + * Last Modified: Wednesday 17th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License * https://opensource.org/licenses/BSD-3-Clause * ----- * File Description: - * functionality for dynamics solver in CLEO - * where coupling is one-way and dynamics - * are read from file + * functionality for dynamics solver in CLEO where dynamics are read from files */ #include "coupldyn_fromfile/fromfile_cartesian_dynamics.hpp" /* open file called 'filename' and return vector of doubles for first variable in that file */ -std::vector thermodynamicvar_from_binary(std::string_view filename) { +std::vector thermodynamicvar_from_binary(const std::filesystem::path filename) { /* open file and read in the metatdata for all the variables in that file */ std::ifstream file(open_binary(filename)); @@ -59,8 +59,8 @@ void CartesianDynamics::increment_position() { pos_yface += ndims[0] * ndims[1] * (ndims[2] + 1); } -CartesianDynamics::CartesianDynamics(const Config &config, const std::array i_ndims, - const unsigned int nsteps) +CartesianDynamics::CartesianDynamics(const OptionalConfigParams::FromFileDynamicsParams &config, + const std::array i_ndims, const unsigned int nsteps) : ndims(i_ndims), pos(0), pos_zface(0), @@ -71,10 +71,10 @@ CartesianDynamics::CartesianDynamics(const Config &config, const std::array +#include #include #include #include @@ -33,7 +35,7 @@ #include #include -#include "initialise/config.hpp" +#include "initialise/optional_config_params.hpp" #include "initialise/readbinary.hpp" /* contains 1-D vector for each (thermo)dynamic @@ -66,14 +68,12 @@ struct CartesianDynamics { /* depending on nspacedims, read in data for 1-D, 2-D or 3-D wind velocity components */ - void set_winds(const Config &config); + void set_winds(const OptionalConfigParams::FromFileDynamicsParams &config); /* Read in data from binary files for wind velocity components in 1D, 2D or 3D model and check they have correct size */ - std::string set_winds_from_binaries(const unsigned int nspacedims, std::string_view wvel_filename, - std::string_view uvel_filename, - std::string_view vvel_filename); + std::string set_winds_from_binaries(const OptionalConfigParams::FromFileDynamicsParams &config); /* nullwinds retuns an empty function 'func' that returns {0.0, 0.0}. Useful for setting get_[X]vel[Y]faces functions @@ -101,8 +101,8 @@ struct CartesianDynamics { const unsigned int nsteps) const; public: - CartesianDynamics(const Config &config, const std::array i_ndims, - const unsigned int nsteps); + CartesianDynamics(const OptionalConfigParams::FromFileDynamicsParams &config, + const std::array i_ndims, const unsigned int nsteps); get_winds_func get_wvel; // funcs to get velocity defined in construction of class get_winds_func get_uvel; // warning: these functions are not const member funcs by default @@ -137,8 +137,9 @@ struct FromFileDynamics { void run_dynamics(const unsigned int t_mdl) const { dynvars->increment_position(); } public: - FromFileDynamics(const Config &config, const unsigned int couplstep, - const std::array ndims, const unsigned int nsteps) + FromFileDynamics(const OptionalConfigParams::FromFileDynamicsParams &config, + const unsigned int couplstep, const std::array ndims, + const unsigned int nsteps) : interval(couplstep), dynvars(std::make_shared(config, ndims, nsteps)) {} auto get_couplstep() const { return interval; } diff --git a/libs/coupldyn_yac/yac_cartesian_dynamics.cpp b/libs/coupldyn_yac/yac_cartesian_dynamics.cpp index 0f6be1c06..e286fa83b 100644 --- a/libs/coupldyn_yac/yac_cartesian_dynamics.cpp +++ b/libs/coupldyn_yac/yac_cartesian_dynamics.cpp @@ -1,4 +1,6 @@ -/* Copyright (c) 2023 MPI-M, Clara Bayley +/* + * Copyright (c) 2024 MPI-M, Clara Bayley + * * * ----- CLEO ----- * File: yac_cartesian_dynamics.cpp @@ -7,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Sunday 17th December 2023 + * Last Modified: Wednesday 17th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -20,10 +22,11 @@ */ #include "coupldyn_yac/yac_cartesian_dynamics.hpp" + #include extern "C" { - #include "yac_interface.h" +#include "yac_interface.h" } /* return (k,i,j) indicies from idx for a flattened 3D array @@ -44,8 +47,7 @@ std::array kijfromindex(const std::array &ndims, const siz * The received values are press, temp, qvap, qcond defined on the cell-centers. * united_edge_data receives the data for all the edge-centers, and component * velocities are then placed in uvel and wvel according to their positions.*/ -void CartesianDynamics::receive_hor_slice_from_yac(int cell_offset, - int u_edges_offset, +void CartesianDynamics::receive_hor_slice_from_yac(int cell_offset, int u_edges_offset, int w_edges_offset) { int info, error; double *yac_raw_data = NULL; @@ -70,13 +72,13 @@ void CartesianDynamics::receive_hor_slice_from_yac(int cell_offset, std::vector::iterator uvel_it = uvel.begin() + u_edges_offset; std::vector::iterator wvel_it = wvel.begin() + w_edges_offset; for (size_t lat_index = 0; lat_index < vertex_latitudes.size() * 2 - 1; lat_index++) { - if (lat_index % 2 == 0) { - for (size_t index = 0; index < ndims[0]; index++, uvel_it++, source_it++) - *uvel_it = *source_it; - } else { - for (size_t index = 0; index < ndims[0] + 1; index++, wvel_it++, source_it++) - *wvel_it = *source_it; - } + if (lat_index % 2 == 0) { + for (size_t index = 0; index < ndims[0]; index++, uvel_it++, source_it++) + *uvel_it = *source_it; + } else { + for (size_t index = 0; index < ndims[0] + 1; index++, wvel_it++, source_it++) + *wvel_it = *source_it; + } } } @@ -91,27 +93,25 @@ void CartesianDynamics::receive_fields_from_yac() { int total_w_edges = ndims[1] * (ndims[0] + 1); int info, error; - double * yac_raw_data = NULL; + double *yac_raw_data = NULL; - if (config.nspacedims == 3) { + if (config.get_nspacedims() == 3) { yac_raw_data = vvel.data(); yac_cget(vvel_yac_id, 1, &yac_raw_data, &info, &error); } for (int vertical_index = 0; vertical_index < ndims[2]; vertical_index++) { receive_hor_slice_from_yac(vertical_index * total_horizontal_cells, - vertical_index * total_u_edges, - vertical_index * total_w_edges); + vertical_index * total_u_edges, vertical_index * total_w_edges); - if (config.nspacedims == 3) { + if (config.get_nspacedims() == 3) { yac_raw_data += total_horizontal_cells; yac_cget(vvel_yac_id, 1, &yac_raw_data, &info, &error); } } } -CartesianDynamics::CartesianDynamics(const Config &config, - const std::array i_ndims, +CartesianDynamics::CartesianDynamics(const Config &config, const std::array i_ndims, const unsigned int nsteps) : ndims(i_ndims), config(config), @@ -135,19 +135,17 @@ CartesianDynamics::CartesianDynamics(const Config &config, std::string cleo_grid_name = "cleo_grid"; int cyclic_dimension[2] = {0, 0}; - int total_cells[2] = {static_cast(ndims[0]), - static_cast(ndims[1])}; - int total_vertices[2] = {static_cast(ndims[0] + 1), - static_cast(ndims[1] + 1)}; - int total_edges[2] = {static_cast(ndims[0] * (ndims[1] + 1)), - static_cast(ndims[1] * (ndims[0] + 1))}; + int total_cells[2] = {static_cast(ndims[0]), static_cast(ndims[1])}; + int total_vertices[2] = {static_cast(ndims[0] + 1), static_cast(ndims[1] + 1)}; + int total_edges[2] = {static_cast(ndims[0] * (ndims[1] + 1)), + static_cast(ndims[1] * (ndims[0] + 1))}; int cell_point_id = -1; int edge_point_id = -1; - vertex_longitudes = std::vector(ndims[0] + 1, 0); - vertex_latitudes = std::vector(ndims[1] + 1, 0); + vertex_longitudes = std::vector(ndims[0] + 1, 0); + vertex_latitudes = std::vector(ndims[1] + 1, 0); auto cell_center_longitudes = std::vector(ndims[0]); - auto cell_center_latitudes = std::vector(ndims[1]); + auto cell_center_latitudes = std::vector(ndims[1]); std::vector edge_centers_longitudes; std::vector edge_centers_latitudes; @@ -157,13 +155,11 @@ CartesianDynamics::CartesianDynamics(const Config &config, vertex_longitudes[i] = i * (2 * std::numbers::pi / (ndims[0] + 1)); for (size_t i = 0; i < vertex_latitudes.size(); i++) - vertex_latitudes[i] = (-0.5 * std::numbers::pi) + - (i + 1) * (std::numbers::pi / (ndims[1] + 2)); + vertex_latitudes[i] = (-0.5 * std::numbers::pi) + (i + 1) * (std::numbers::pi / (ndims[1] + 2)); // Defines a regular 2D grid - yac_cdef_grid_reg2d(cleo_grid_name.c_str(), total_vertices, - cyclic_dimension, vertex_longitudes.data(), - vertex_latitudes.data(), &grid_id); + yac_cdef_grid_reg2d(cleo_grid_name.c_str(), total_vertices, cyclic_dimension, + vertex_longitudes.data(), vertex_latitudes.data(), &grid_id); // --- Point definitions --- @@ -173,7 +169,7 @@ CartesianDynamics::CartesianDynamics(const Config &config, cell_center_longitudes[i] = vertex_longitudes[i] + std::numbers::pi / (ndims[0] + 2); for (size_t i = 0; i < cell_center_latitudes.size(); i++) - cell_center_latitudes[i] = vertex_latitudes[i] + std::numbers::pi / (2 * (ndims[1] + 3)); + cell_center_latitudes[i] = vertex_latitudes[i] + std::numbers::pi / (2 * (ndims[1] + 3)); // Defines the edge center longitude and latitude values in radians. // Since it is not possible to generate edge center coordinates with a single @@ -183,28 +179,23 @@ CartesianDynamics::CartesianDynamics(const Config &config, // these arrays will have a size equal to the number of edges. for (size_t lat_index = 0; lat_index < vertex_latitudes.size() * 2 - 1; lat_index++) { if (lat_index % 2 == 0) { - edge_centers_longitudes.insert(edge_centers_longitudes.end(), - cell_center_longitudes.begin(), + edge_centers_longitudes.insert(edge_centers_longitudes.end(), cell_center_longitudes.begin(), cell_center_longitudes.end()); - edge_centers_latitudes.insert(edge_centers_latitudes.end(), - cell_center_longitudes.size(), + edge_centers_latitudes.insert(edge_centers_latitudes.end(), cell_center_longitudes.size(), vertex_latitudes[lat_index / 2]); } else { - edge_centers_longitudes.insert(edge_centers_longitudes.end(), - vertex_longitudes.begin(), + edge_centers_longitudes.insert(edge_centers_longitudes.end(), vertex_longitudes.begin(), vertex_longitudes.end()); - edge_centers_latitudes.insert(edge_centers_latitudes.end(), - vertex_longitudes.size(), + edge_centers_latitudes.insert(edge_centers_latitudes.end(), vertex_longitudes.size(), cell_center_latitudes[(lat_index - 1) / 2]); } } - yac_cdef_points_reg2d(grid_id, total_cells, YAC_LOCATION_CELL, - cell_center_longitudes.data(), cell_center_latitudes.data(), - &cell_point_id); + yac_cdef_points_reg2d(grid_id, total_cells, YAC_LOCATION_CELL, cell_center_longitudes.data(), + cell_center_latitudes.data(), &cell_point_id); yac_cdef_points_unstruct(grid_id, total_edges[0] + total_edges[1], YAC_LOCATION_EDGE, - edge_centers_longitudes.data(), edge_centers_latitudes.data(), - &edge_point_id); + edge_centers_longitudes.data(), edge_centers_latitudes.data(), + &edge_point_id); // --- Interpolation stack --- int interp_stack_id; @@ -215,73 +206,56 @@ CartesianDynamics::CartesianDynamics(const Config &config, int num_point_sets = 1; int collection_size = 1; - yac_cdef_field("pressure", component_id, &cell_point_id, - num_point_sets, collection_size, "PT1M", + yac_cdef_field("pressure", component_id, &cell_point_id, num_point_sets, collection_size, "PT1M", YAC_TIME_UNIT_ISO_FORMAT, &pressure_yac_id); - yac_cdef_field("temperature", component_id, &cell_point_id, - num_point_sets, collection_size, "PT1M", - YAC_TIME_UNIT_ISO_FORMAT, &temp_yac_id); + yac_cdef_field("temperature", component_id, &cell_point_id, num_point_sets, collection_size, + "PT1M", YAC_TIME_UNIT_ISO_FORMAT, &temp_yac_id); - yac_cdef_field("qvap", component_id, &cell_point_id, - num_point_sets, collection_size, "PT1M", + yac_cdef_field("qvap", component_id, &cell_point_id, num_point_sets, collection_size, "PT1M", YAC_TIME_UNIT_ISO_FORMAT, &qvap_yac_id); - yac_cdef_field("qcond", component_id, &cell_point_id, - num_point_sets, collection_size, "PT1M", + yac_cdef_field("qcond", component_id, &cell_point_id, num_point_sets, collection_size, "PT1M", YAC_TIME_UNIT_ISO_FORMAT, &qcond_yac_id); - yac_cdef_field("vvel", component_id, &cell_point_id, - num_point_sets, collection_size, "PT1M", + yac_cdef_field("vvel", component_id, &cell_point_id, num_point_sets, collection_size, "PT1M", YAC_TIME_UNIT_ISO_FORMAT, &vvel_yac_id); - yac_cdef_field("hor_wind_velocities", component_id, &edge_point_id, - num_point_sets, collection_size, "PT1M", - YAC_TIME_UNIT_ISO_FORMAT, &hor_wind_velocities_yac_id); - + yac_cdef_field("hor_wind_velocities", component_id, &edge_point_id, num_point_sets, + collection_size, "PT1M", YAC_TIME_UNIT_ISO_FORMAT, &hor_wind_velocities_yac_id); // --- Field coupling definitions --- - yac_cdef_couple("yac_reader", "yac_reader_grid", "pressure", - "cleo", "cleo_grid", "pressure", - "PT1M", YAC_TIME_UNIT_ISO_FORMAT, YAC_REDUCTION_TIME_NONE, - interp_stack_id, 0, 0); + yac_cdef_couple("yac_reader", "yac_reader_grid", "pressure", "cleo", "cleo_grid", "pressure", + "PT1M", YAC_TIME_UNIT_ISO_FORMAT, YAC_REDUCTION_TIME_NONE, interp_stack_id, 0, 0); - yac_cdef_couple("yac_reader", "yac_reader_grid", "temperature", - "cleo", "cleo_grid", "temperature", - "PT1M", YAC_TIME_UNIT_ISO_FORMAT, YAC_REDUCTION_TIME_NONE, + yac_cdef_couple("yac_reader", "yac_reader_grid", "temperature", "cleo", "cleo_grid", + "temperature", "PT1M", YAC_TIME_UNIT_ISO_FORMAT, YAC_REDUCTION_TIME_NONE, interp_stack_id, 0, 0); - yac_cdef_couple("yac_reader", "yac_reader_grid", "qvap", - "cleo", "cleo_grid", "qvap", - "PT1M", YAC_TIME_UNIT_ISO_FORMAT, YAC_REDUCTION_TIME_NONE, - interp_stack_id, 0, 0); + yac_cdef_couple("yac_reader", "yac_reader_grid", "qvap", "cleo", "cleo_grid", "qvap", "PT1M", + YAC_TIME_UNIT_ISO_FORMAT, YAC_REDUCTION_TIME_NONE, interp_stack_id, 0, 0); - yac_cdef_couple("yac_reader", "yac_reader_grid", "qcond", - "cleo", "cleo_grid", "qcond", - "PT1M", YAC_TIME_UNIT_ISO_FORMAT, YAC_REDUCTION_TIME_NONE, - interp_stack_id, 0, 0); + yac_cdef_couple("yac_reader", "yac_reader_grid", "qcond", "cleo", "cleo_grid", "qcond", "PT1M", + YAC_TIME_UNIT_ISO_FORMAT, YAC_REDUCTION_TIME_NONE, interp_stack_id, 0, 0); - yac_cdef_couple("yac_reader", "yac_reader_grid", "vvel", - "cleo", "cleo_grid", "vvel", - "PT1M", YAC_TIME_UNIT_ISO_FORMAT, YAC_REDUCTION_TIME_NONE, - interp_stack_id, 0, 0); + yac_cdef_couple("yac_reader", "yac_reader_grid", "vvel", "cleo", "cleo_grid", "vvel", "PT1M", + YAC_TIME_UNIT_ISO_FORMAT, YAC_REDUCTION_TIME_NONE, interp_stack_id, 0, 0); - yac_cdef_couple("yac_reader", "yac_reader_grid", "hor_wind_velocities", - "cleo", "cleo_grid", "hor_wind_velocities", - "PT1M", YAC_TIME_UNIT_ISO_FORMAT, YAC_REDUCTION_TIME_NONE, + yac_cdef_couple("yac_reader", "yac_reader_grid", "hor_wind_velocities", "cleo", "cleo_grid", + "hor_wind_velocities", "PT1M", YAC_TIME_UNIT_ISO_FORMAT, YAC_REDUCTION_TIME_NONE, interp_stack_id, 0, 0); // --- End of YAC definitions --- yac_cenddef(); // Initialization of target containers for receiving data - press = std::vector(total_cells[0] * total_cells[1] * ndims[2], 0); - temp = std::vector(total_cells[0] * total_cells[1] * ndims[2], 0); - qvap = std::vector(total_cells[0] * total_cells[1] * ndims[2], 0); - qcond = std::vector(total_cells[0] * total_cells[1] * ndims[2], 0); - uvel = std::vector(total_edges[0] * ndims[2], 0); - wvel = std::vector(total_edges[1] * ndims[2], 0); - vvel = std::vector(total_cells[0] * total_cells[1] * (ndims[2] + 1), 0); + press = std::vector(total_cells[0] * total_cells[1] * ndims[2], 0); + temp = std::vector(total_cells[0] * total_cells[1] * ndims[2], 0); + qvap = std::vector(total_cells[0] * total_cells[1] * ndims[2], 0); + qcond = std::vector(total_cells[0] * total_cells[1] * ndims[2], 0); + uvel = std::vector(total_edges[0] * ndims[2], 0); + wvel = std::vector(total_edges[1] * ndims[2], 0); + vvel = std::vector(total_cells[0] * total_cells[1] * (ndims[2] + 1), 0); united_edge_data = std::vector(total_edges[0] + total_edges[1], 0); // Calls the first data retrieval from YAC to have thermodynamic data for first timestep @@ -304,7 +278,7 @@ CartesianDynamics::~CartesianDynamics() { yac_cfinalize(); } /* depending on nspacedims, read in data for 1-D, 2-D or 3-D wind velocity components */ void CartesianDynamics::set_winds(const Config &config) { - const auto nspacedims = (unsigned int)config.nspacedims; + const auto nspacedims = config.get_nspacedims(); switch (nspacedims) { case 0: @@ -366,7 +340,7 @@ CartesianDynamics::get_winds_func CartesianDynamics::get_wvel_from_yac() const { const size_t nzfaces(ndims[0] + 1); // no. z faces to same 3D grid size_t lpos(ndims[1] * nzfaces * kij[2] + nzfaces * kij[1] + - kij[0]); // position of z lower face in 1D wvel vector + kij[0]); // position of z lower face in 1D wvel vector const size_t uppos(lpos + 1); // position of z upper face return std::pair(wvel.at(lpos), wvel.at(uppos)); @@ -385,7 +359,7 @@ CartesianDynamics::get_winds_func CartesianDynamics::get_uvel_from_yac() const { const size_t nxfaces(ndims[1] + 1); // no. x faces to same 3D grid size_t lpos(nxfaces * ndims[0] * kij[2] + ndims[0] * kij[1] + - kij[0]); // position of x lower face in 1D uvel vector + kij[0]); // position of x lower face in 1D uvel vector const size_t uppos(lpos + ndims[0]); // position of x upper face return std::pair(uvel.at(lpos), uvel.at(uppos)); @@ -397,7 +371,7 @@ CartesianDynamics::get_winds_func CartesianDynamics::get_uvel_from_yac() const { CartesianDynamics::get_winds_func CartesianDynamics::get_vvel_from_yac() const { const auto func = [&](const unsigned int gbxindex) { const size_t lpos(static_cast(gbxindex)); // position of y lower face in 1D vvel vector - const size_t uppos(lpos + ndims[1] * ndims[0]); // position of x upper face + const size_t uppos(lpos + ndims[1] * ndims[0]); // position of x upper face return std::pair(vvel.at(lpos), vvel.at(uppos)); }; diff --git a/libs/coupldyn_yac/yac_cartesian_dynamics.hpp b/libs/coupldyn_yac/yac_cartesian_dynamics.hpp index 0f17b08fe..5d10253a7 100644 --- a/libs/coupldyn_yac/yac_cartesian_dynamics.hpp +++ b/libs/coupldyn_yac/yac_cartesian_dynamics.hpp @@ -1,4 +1,6 @@ -/* Copyright (c) 2023 MPI-M, Clara Bayley +/* + * Copyright (c) 2024 MPI-M, Clara Bayley + * * * ----- CLEO ----- * File: yac_cartesian_dynamics.hpp @@ -7,15 +9,14 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Tuesday 7th November 2023 + * Last Modified: Wednesday 17th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License * https://opensource.org/licenses/BSD-3-Clause * ----- * File Description: - * struct obeying coupleddynamics concept for - * dynamics solver in CLEO where coupling is + * struct obeying coupleddynamics concept for dynamics solver in CLEO where coupling is * one-way and dynamics are read from file */ @@ -47,7 +48,7 @@ struct CartesianDynamics { // number of (centres of) gridboxes in [coord3, coord1, coord2] directions const std::array ndims; - const Config & config; + const Config &config; /* --- (thermo)dynamic variables received from YAC --- */ @@ -139,14 +140,13 @@ struct YacDynamics { std::shared_ptr dynvars; // pointer to (thermo)dynamic variables /* Calls the get operations to receive data from YAC for each of the fields of interest */ - void run_dynamics(const unsigned int t_mdl) const { - dynvars->receive_fields_from_yac(); - } + void run_dynamics(const unsigned int t_mdl) const { dynvars->receive_fields_from_yac(); } public: - YacDynamics(const Config &config, const unsigned int couplstep, - const std::array ndims, const unsigned int nsteps) - : interval(couplstep), end_time(config.T_END), + YacDynamics(const Config &config, const unsigned int couplstep, const std::array ndims, + const unsigned int nsteps) + : interval(couplstep), + end_time(config.T_END), dynvars(std::make_shared(config, ndims, nsteps)) {} auto get_couplstep() const { return interval; } diff --git a/libs/initialise/CMakeLists.txt b/libs/initialise/CMakeLists.txt index 9986c33c1..b2de4f81d 100644 --- a/libs/initialise/CMakeLists.txt +++ b/libs/initialise/CMakeLists.txt @@ -12,13 +12,14 @@ set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib) # Add executables and create library target set(SOURCES - "config.cpp" - "copyfiles2txt.cpp" - "gbxbounds_frombinary.cpp" - "initsupers_frombinary.cpp" - "readbinary.cpp" - "timesteps.cpp" - ) +"copyfiles2txt.cpp" +"gbxbounds_frombinary.cpp" +"initsupers_frombinary.cpp" +"optional_config_params.cpp" +"readbinary.cpp" +"required_config_params.cpp" +"timesteps.cpp" +) # must use STATIC (not(!) SHARED) lib for linking to executable if build is CUDA enabled with Kokkos add_library("${LIBNAME}" STATIC ${SOURCES}) @@ -27,7 +28,7 @@ target_include_directories(${LIBNAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}") target_include_directories(${LIBNAME} PRIVATE "${CMAKE_SOURCE_DIR}/libs") # CLEO libs directory # Link libraries to target library -target_link_libraries(${LIBNAME} PUBLIC Kokkos::kokkos) +target_link_libraries(${LIBNAME} PUBLIC Kokkos::kokkos yaml-cpp::yaml-cpp) # set specific C++ compiler options for target (optional) #target_compile_options(${LIBNAME} PRIVATE) diff --git a/libs/initialise/config.cpp b/libs/initialise/config.cpp deleted file mode 100644 index cc1b456bc..000000000 --- a/libs/initialise/config.cpp +++ /dev/null @@ -1,214 +0,0 @@ -/* Copyright (c) 2023 MPI-M, Clara Bayley - * - * ----- CLEO ----- - * File: config.cpp - * Project: initialise - * Created Date: Friday 13th October 2023 - * Author: Clara Bayley (CB) - * Additional Contributors: - * ----- - * Last Modified: Friday 8th December 2023 - * Modified By: CB - * ----- - * License: BSD 3-Clause "New" or "Revised" License - * https://opensource.org/licenses/BSD-3-Clause - * ----- - * File Description: - * Functions involved in reading values from config files using - * Config class - */ - -#include "initialise/config.hpp" - -/* read configuration file given by config_filename - then calls configvariable to assign value to corresponding - member of Config structure */ -void Config::loadconfiguration(const std::string_view config_filename) { - std::ifstream file; - open_file(config_filename, file); - - std::string line; - std::cout << "----- Reading config file contents -----\n"; - while (getline(file, line)) { - line.erase(std::remove_if(line.begin(), line.end(), ::isspace), line.end()); - - if (line[0] == '*' || line[0] == '#' || line[0] == '/' || line.empty()) { - continue; - } else { - NameValue nv = getvariable_fromline(line); - configvariable(nv.name, nv.value); - } - } - - file.close(); - std::cout << "---- Contents has been read, config file closed -----\n"; -} - -/* opens file or throws error if opening fails */ -void Config::open_file(const std::string_view config_filename, std::ifstream &file) const { - const std::string filestr(config_filename); - std::cout << "opening config file: " << filestr << '\n'; - file.open(filestr); - - if (!file.is_open()) { - throw std::invalid_argument("Cannot open " + filestr); - } -} - -/* extracts name of variable and it's value from a string -of the form 'variable_name = value #comment' */ -Config::NameValue Config::getvariable_fromline(const std::string line) const { - const std::string::size_type delimiter_pos = line.find("="); - const std::string::size_type end_pos = line.find("#"); - const std::string name = line.substr(0, delimiter_pos); - const std::string value = line.substr(delimiter_pos + 1, end_pos - delimiter_pos - 1); - - return {name, value}; -} - -/* if string == 'true', 'True' or '1', returns true -C++ boolean, else returns false */ -bool Config::string2bool(const std::string value) const { - if (value == "true" || value == "True" || value == "1") { - return true; - } else { - return false; - } -} - -/* setter function. assigns value of member of Config struct - called 'name' by coverting strings containing - value into actual value for that members's type. If - 'name' member cannot be assigned, throw error */ -void Config::configvariable(const std::string name, const std::string value) { - bool issuccess = false; - - /*** Initialisation and Output Data parameters ***/ - if (name == "constants_filename") { - constants_filename = value; - issuccess = true; - } else if (name == "initsupers_filename") { - initsupers_filename = value; - issuccess = true; - } else if (name == "grid_filename") { - grid_filename = value; - issuccess = true; - } else if (name == "setuptxt") { - setuptxt = value; - issuccess = true; - } else if (name == "stats_filename") { - stats_filename = value; - issuccess = true; - } else if (name == "zarrbasedir") { - zarrbasedir = value; - issuccess = true; - } else if (name == "maxchunk") { - maxchunk = stoi(value); - issuccess = true; - } else if (name == "nspacedims") { /*** SDM Runtime parameters ***/ - nspacedims = stoi(value); /* domain setup */ - issuccess = true; - } else if (name == "ngbxs") { - ngbxs = stoi(value); - issuccess = true; - } else if (name == "totnsupers") { - totnsupers = stoi(value); - issuccess = true; - } else if (name == "CONDTSTEP") { /* timestepping */ - CONDTSTEP = stod(value); - issuccess = true; - } else if (name == "COLLTSTEP") { - COLLTSTEP = stod(value); - issuccess = true; - } else if (name == "MOTIONTSTEP") { - MOTIONTSTEP = stod(value); - issuccess = true; - } else if (name == "COUPLTSTEP") { - COUPLTSTEP = stod(value); - issuccess = true; - } else if (name == "OBSTSTEP") { - OBSTSTEP = stod(value); - issuccess = true; - } else if (name == "T_END") { - T_END = stod(value); - issuccess = true; - } else if (name == "cond_iters") { /* microphysics */ - cond_iters = stoul(value); - issuccess = true; - } else if (name == "cond_SUBTSTEP") { - cond_SUBTSTEP = stod(value); - issuccess = true; - } else if (name == "cond_rtol") { - cond_rtol = stod(value); - issuccess = true; - } else if (name == "cond_atol") { - cond_atol = stod(value); - issuccess = true; - } else if (name == "doAlterThermo") { /* superdroplets */ - doAlterThermo = string2bool(value); - issuccess = true; - } else if (name == "thermosolver") { /*** Coupled Dynamics Solver Parameters ***/ - thermosolver = value; - issuccess = true; - } - - if (thermosolver == "fromfile") { - /* read in dynamics from file */ - configvariable_thermosolverfromfile(name, value); - issuccess = true; - } else if (thermosolver == "cvode") { - /* CVODE ODE solver parameters */ - configvariable_thermosolvercvode(name, value); - issuccess = true; - } - - if (issuccess) { - std::cout << "assigned " << name << " = " << value << '\n'; - } else { - throw std::invalid_argument(name + " cannot be assigned with input value"); - } -} - -/* setter function for assigning 'value' to members of -Config struct called 'name' specifically for members -involved when thermosolver == 'fromfile'. Returns false only if -name is one of these specific members and also cannot be assigned */ -void Config::configvariable_thermosolverfromfile(const std::string name, const std::string value) { - if (name == "press_filename") { - press_filename = value; - } else if (name == "temp_filename") { - temp_filename = value; - } else if (name == "qvap_filename") { - qvap_filename = value; - } else if (name == "qcond_filename") { - qcond_filename = value; - } else if (name == "wvel_filename") { - wvel_filename = value; - } else if (name == "uvel_filename") { - uvel_filename = value; - } else if (name == "vvel_filename") { - vvel_filename = value; - } -} - -/* setter function for assigning 'value' to members of -Config struct called 'name' specifically for members -involved when thermosolver == 'cvode' */ -void Config::configvariable_thermosolvercvode(const std::string name, const std::string value) { - /* initial (uniform) thermodynamic conditions */ - if (name == "P_INIT") { - P_INIT = stod(value); - } else if (name == "TEMP_INIT") { - TEMP_INIT = stod(value); - } else if (name == "relh_init") { - relh_init = stod(value); - } else if (name == "W_AVG") { /* ODE parameters */ - W_AVG = stod(value); - } else if (name == "T_HALF") { - T_HALF = stod(value); - } else if (name == "cvode_rtol") { - cvode_rtol = stod(value); - } else if (name == "cvode_atol") { - cvode_atol = stod(value); - } -} diff --git a/libs/initialise/config.hpp b/libs/initialise/config.hpp index 9e4ec05a6..2adbbbaa4 100644 --- a/libs/initialise/config.hpp +++ b/libs/initialise/config.hpp @@ -1,4 +1,6 @@ -/* Copyright (c) 2023 MPI-M, Clara Bayley +/* + * Copyright (c) 2024 MPI-M, Clara Bayley + * * * ----- CLEO ----- * File: config.hpp @@ -7,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Friday 8th December 2023 + * Last Modified: Wednesday 17th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -21,131 +23,76 @@ #ifndef LIBS_INITIALISE_CONFIG_HPP_ #define LIBS_INITIALISE_CONFIG_HPP_ -#include #include -#include #include -#include -#include #include -#include +#include #include "./copyfiles2txt.hpp" +#include "./optional_config_params.hpp" +#include "./required_config_params.hpp" +/** + * @brief Struct storing configuration parameters read from a YAML file. + * + * This struct represents configuration settings for CLEO read in from + * a configuration YAML file. + */ struct Config { private: - struct NameValue { - std::string name; - std::string value; - }; - - /* read configuration file given by config_filename - then calls configvariable to assign value to corresponding - member of Config structure */ - void loadconfiguration(const std::string_view config_filename); - - /* opens file or throws error if opening fails */ - void open_file(const std::string_view config_filename, std::ifstream &file) const; - - /* extracts name of variable and it's value from a string - of the form 'variable_name = value #comment' */ - NameValue getvariable_fromline(const std::string line) const; - - /* if string == 'true', 'True' or '1', returns true - C++ boolean, else returns false */ - bool string2bool(const std::string value) const; - - /* setter function. assigns value of member of Config struct - called 'name' by coverting strings containing - value into actual value for that members's type */ - void configvariable(const std::string name, const std::string value); - - /* setter function for assigning 'value' to members of - Config struct called 'name' specifically for members - involved when thermosolver == 'fromfile' */ - void configvariable_thermosolverfromfile(const std::string name, const std::string value); - - /* setter function for assigning 'value' to members of - Config struct called 'name' specifically for members - involved when thermosolver == 'cvode' */ - void configvariable_thermosolvercvode(const std::string name, const std::string value); + RequiredConfigParams required; /**< required configuration parameters of CLEO */ + OptionalConfigParams optional; /**< optional configuration parameters of CLEO */ public: - /*** Initialisation and Output Data parameters ***/ - std::string constants_filename; // filename containing values of physical constants - std::string initsupers_filename; // binary filename for initialisation of SDs - std::string grid_filename; // binary filename for GBx boundaries - std::string setuptxt; // name of .txt output file to copy setup to - std::string stats_filename; // name of .txt file to output runtime statistics to - std::filesystem::path zarrbasedir; // zarr store base directory - int maxchunk; // maximum no. of elements in chunks of zarr store array - - /*** SDM Runtime parameters ***/ - /* domain setup */ - int nspacedims; // no. of spatial dimensions to model - int ngbxs; // total number of Gbxs - int totnsupers; // (initial) total no. of SDs - - /* timestepping */ - double CONDTSTEP; // time between SD condensation events [s] - double COLLTSTEP; // time between SD collision events [s] - double MOTIONTSTEP; // time between SDM motion [s] - double COUPLTSTEP; // time between thermodynamic couplings [s] - double OBSTSTEP; // time between SDM observations [s] - double T_END; // time span of integration from 0s to T_END [s] - - /* microphysics */ - unsigned int cond_iters; // suggested no. iterations of Newton Raphson Method - double cond_SUBTSTEP; // smallest timestep in cases where substepping occurs [s] - double cond_rtol; // relative tolerance for implicit euler integration - double cond_atol; // abolute tolerance for implicit euler integration - - /* superdroplets */ - bool doAlterThermo; // enable condensation to alter the thermodynamic state - - /*** Coupled Dynamics Solver Parameters ***/ - std::string thermosolver; // type of dynamics solver to configure - - /* read in dynamics from file (default to empty) */ - std::string press_filename = ""; // binary filename for pressure - std::string temp_filename = ""; // binary filename for temperature - std::string qvap_filename = ""; // binary filename for vapour mixing ratio - std::string qcond_filename = ""; // binary filename for liquid mixing ratio - std::string wvel_filename = ""; // binary filename for vertical (z) velocity - std::string uvel_filename = ""; // binary filename for horizontal x velocity - std::string vvel_filename = ""; // binary filename for horizontal y velocity - - /* CVODE ODE solver parameters (default to type's quiet_NAN) */ - /* initial uniform thermodynamics */ - double P_INIT = std::numeric_limits::signaling_NaN(); // initial pressure [Pa] - double TEMP_INIT = - std::numeric_limits::signaling_NaN(); // initial parcel temperature [T] - double relh_init = std::numeric_limits::signaling_NaN(); // initial relative humidity (%) - - /* ODE parameters */ - double W_AVG = - std::numeric_limits::signaling_NaN(); // average amplitude of sinusoidal vertical - // parcel speed [m/s] (dP/dt ~ w*dP/dz) - double T_HALF = std::numeric_limits::signaling_NaN(); // timescale for w sinusoid, - // tau_half = T_HALF/pi [s] - double cvode_rtol = std::numeric_limits::signaling_NaN(); // relative tolerance for [P, - // T, qv, qc] ODEs integration - double cvode_atol = std::numeric_limits::signaling_NaN(); // absolute tolerances for [P, - // T, qv, qc] ODEs integration - - /* set input paramters as members of config - class instance from txt configuration file */ - explicit Config(const std::string_view config_filename) { + /** + * @brief Constructor for Config. + * + * Initializes a Config instance by loading the configuration from the specified YAML + * configuration file "config_filename". Then copy the setup to an output file "setup_filename". + * + * @param config_filename The name of the YAML configuration file. + */ + explicit Config(const std::filesystem::path config_filename) + : required(config_filename), optional(config_filename) { std::cout << "\n--- configuration ---\n"; - loadconfiguration(config_filename); - /* copy setup (config and constants files) to a txt file */ - const std::string filestr(config_filename); - copyfiles2txt(setuptxt, {filestr, constants_filename}); + const auto files2copy = + std::vector{config_filename, required.inputfiles.constants_filename}; + copyfiles2txt(required.outputdata.setup_filename, files2copy); std::cout << "--- configuration: success ---\n"; } + + std::filesystem::path get_grid_filename() const { return required.inputfiles.grid_filename; } + + std::filesystem::path get_stats_filename() const { return required.outputdata.stats_filename; } + + std::filesystem::path get_zarrbasedir() const { return required.outputdata.zarrbasedir; } + + size_t get_maxchunk() const { return required.outputdata.maxchunk; } + + unsigned int get_nspacedims() const { return required.domain.nspacedims; } + + size_t get_ngbxs() const { return required.domain.ngbxs; } + + RequiredConfigParams::TimestepsParams get_timesteps() const { return required.timesteps; } + + OptionalConfigParams::CondensationParams get_condensation() const { + return optional.condensation; + } + + OptionalConfigParams::InitSupersFromBinaryParams get_initsupersfrombinary() const { + return optional.initsupersfrombinary; + } + + OptionalConfigParams::CvodeDynamicsParams get_cvodedynamics() const { + return optional.cvodedynamics; + } + + OptionalConfigParams::FromFileDynamicsParams get_fromfiledynamics() const { + return optional.fromfiledynamics; + } }; #endif // LIBS_INITIALISE_CONFIG_HPP_ diff --git a/libs/initialise/copyfiles2txt.cpp b/libs/initialise/copyfiles2txt.cpp index 497e43218..43b7d86ae 100644 --- a/libs/initialise/copyfiles2txt.cpp +++ b/libs/initialise/copyfiles2txt.cpp @@ -1,4 +1,6 @@ -/* Copyright (c) 2023 MPI-M, Clara Bayley +/* + * Copyright (c) 2024 MPI-M, Clara Bayley + * * * ----- CLEO ----- * File: copyfiles2txt.cpp @@ -7,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Friday 3rd November 2023 + * Last Modified: Wednesday 17th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -24,36 +26,39 @@ /* open a file called filename and copy text line by line into wfile */ -void copyfile(std::ofstream &wfile, const std::string filename); +void copyfile(std::ofstream &wfile, const std::filesystem::path filename); -/* creates new empty file called setuptxt and copies contents of +/* creates new empty file called setup_filename and copies contents of files listed in files2copy vector one by one */ -void copyfiles2txt(const std::string setuptxt, const std::vector files2copy) { - std::cout << "----- writing to new setuptxt file: " << setuptxt << " -----\n"; +void copyfiles2txt(const std::filesystem::path setup_filename, + const std::vector &files2copy) { + const auto setup_filestr = setup_filename.string(); + std::cout << "----- writing to new setup file: " << setup_filestr << " -----\n"; std::ofstream wfile; - wfile.open(setuptxt, std::ios::out | std::ios::trunc); // clear previous contents + wfile.open(setup_filestr, std::ios::out | std::ios::trunc); // clear previous contents wfile.close(); - wfile.open(setuptxt, std::ios::app); // copy files one by one + wfile.open(setup_filestr, std::ios::app); // copy files one by one for (auto &filename : files2copy) { copyfile(wfile, filename); } wfile.close(); - std::cout << "---- copy complete, setuptxt file closed -----\n"; + std::cout << "---- copy complete, setup file closed -----\n"; } /* open a file called filename and copy text line by line into wfile */ -void copyfile(std::ofstream &wfile, const std::string filename) { - std::ifstream readfile(filename); +void copyfile(std::ofstream &wfile, const std::filesystem::path filename) { + const auto filestr = filename.string(); + std::ifstream readfile(filestr); - std::cout << " copying " + filename + " to setuptxt file\n"; + std::cout << " copying " + filestr + " to setup file\n"; wfile << "// ----------------------------- //\n"; - wfile << "// --------- " + filename + " --------- //\n"; + wfile << "// --------- " + filestr + " --------- //\n"; wfile << "// ----------------------------- //\n"; std::string line; diff --git a/libs/initialise/copyfiles2txt.hpp b/libs/initialise/copyfiles2txt.hpp index b4a767aad..41362ad88 100644 --- a/libs/initialise/copyfiles2txt.hpp +++ b/libs/initialise/copyfiles2txt.hpp @@ -1,4 +1,6 @@ -/* Copyright (c) 2023 MPI-M, Clara Bayley +/* + * Copyright (c) 2024 MPI-M, Clara Bayley + * * * ----- CLEO ----- * File: copyfiles2txt.hpp @@ -7,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Friday 3rd November 2023 + * Last Modified: Wednesday 17th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -23,13 +25,15 @@ #ifndef LIBS_INITIALISE_COPYFILES2TXT_HPP_ #define LIBS_INITIALISE_COPYFILES2TXT_HPP_ +#include #include #include #include #include -/* creates new empty file called setuptxt and copies contents +/* creates new empty file called setup_filename and copies contents of files listed in files2copy vector one by one */ -void copyfiles2txt(const std::string setuptxt, const std::vector files2copy); +void copyfiles2txt(const std::filesystem::path setup_filename, + const std::vector &files2copy); #endif // LIBS_INITIALISE_COPYFILES2TXT_HPP_ diff --git a/libs/initialise/gbxbounds_frombinary.cpp b/libs/initialise/gbxbounds_frombinary.cpp index d9bad24f4..12ebb0678 100644 --- a/libs/initialise/gbxbounds_frombinary.cpp +++ b/libs/initialise/gbxbounds_frombinary.cpp @@ -1,4 +1,6 @@ -/* Copyright (c) 2023 MPI-M, Clara Bayley +/* + * Copyright (c) 2024 MPI-M, Clara Bayley + * * * ----- CLEO ----- * File: gbxbounds_frombinary.cpp @@ -7,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Thursday 14th December 2023 + * Last Modified: Thursday 18th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -24,8 +26,8 @@ /* read metadata and data in binary file called 'gridfile', then return GbxBoundsFromBinary instance created from that data */ -GbxBoundsFromBinary::GbxBoundsFromBinary(const unsigned int ngbxs, const unsigned int nspacedims, - std::string_view grid_filename) { +GbxBoundsFromBinary::GbxBoundsFromBinary(const size_t ngbxs, const unsigned int nspacedims, + const std::filesystem::path grid_filename) { /* open file and read in the metatdata for all the variables in gridfile */ std::ifstream file(open_binary(grid_filename)); @@ -51,7 +53,7 @@ GbxBoundsFromBinary::GbxBoundsFromBinary(const unsigned int ngbxs, const unsigne /* Throws error if ngbxs is not consistent with number of gridboxes from gridfile as calculated via the get_ngbxs() function */ -void GbxBoundsFromBinary::is_ngbxs_compatible(const unsigned int ngbxs) const { +void GbxBoundsFromBinary::is_ngbxs_compatible(const size_t ngbxs) const { if (ngbxs != get_ngbxs()) { std::string err = "number of gridboxes read from gridfile" diff --git a/libs/initialise/gbxbounds_frombinary.hpp b/libs/initialise/gbxbounds_frombinary.hpp index 3fc4b39bc..2ea5be1fa 100644 --- a/libs/initialise/gbxbounds_frombinary.hpp +++ b/libs/initialise/gbxbounds_frombinary.hpp @@ -1,4 +1,6 @@ -/* Copyright (c) 2023 MPI-M, Clara Bayley +/* + * Copyright (c) 2024 MPI-M, Clara Bayley + * * * ----- CLEO ----- * File: gbxbounds_frombinary.hpp @@ -7,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Thursday 9th November 2023 + * Last Modified: Thursday 18th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -23,8 +25,11 @@ #ifndef LIBS_INITIALISE_GBXBOUNDS_FROMBINARY_HPP_ #define LIBS_INITIALISE_GBXBOUNDS_FROMBINARY_HPP_ +#include +#include #include #include +#include #include #include #include @@ -32,9 +37,6 @@ #include #include -#include -#include - #include "initialise/readbinary.hpp" /* holds vectors containing gridbox indexes and their @@ -43,7 +45,7 @@ coordinate boundaries which are read from gridfile and used in construction of GridboxMaps */ struct GbxBoundsFromBinary { private: - void is_ngbxs_compatible(const unsigned int ngbxs) const; + void is_ngbxs_compatible(const size_t ngbxs) const; void is_nspacedims_compatible(const unsigned int nspacedims) const; bool check_0Dmodel_gbxbounds() const; @@ -59,8 +61,8 @@ struct GbxBoundsFromBinary { std::vector gbxbounds; // corresponding [coord3 {l, u}, coord1 {l, u}, coord2 {l, u}] // lower and upper coordinate boundaries - GbxBoundsFromBinary(const unsigned int ngbxs, const unsigned int nspacedims, - std::string_view grid_filename); + GbxBoundsFromBinary(const size_t ngbxs, const unsigned int nspacedims, + const std::filesystem::path grid_filename); /* returns coord3 {lower, upper} gridbox bounds from position in gbxbounds vector which corresponds diff --git a/libs/initialise/initgbxs_null.hpp b/libs/initialise/initgbxs_null.hpp index 1a90587a3..8bae52845 100644 --- a/libs/initialise/initgbxs_null.hpp +++ b/libs/initialise/initgbxs_null.hpp @@ -1,4 +1,6 @@ -/* Copyright (c) 2023 MPI-M, Clara Bayley +/* + * Copyright (c) 2024 MPI-M, Clara Bayley + * * * ----- CLEO ----- * File: initgbxs_null.hpp @@ -7,17 +9,15 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Tuesday 7th November 2023 + * Last Modified: Wednesday 17th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License * https://opensource.org/licenses/BSD-3-Clause * ----- * File Description: - * struct for griboxes' - * initial conditions for CLEO SDM - * (e.g. thermodynamics) which can be used - * by InitConds struct as GbxInitConds type + * struct for griboxes' initial conditions for CLEO SDM (e.g. thermodynamics) + * which can be used by InitConds struct as GbxInitConds type. */ #ifndef LIBS_INITIALISE_INITGBXS_NULL_HPP_ @@ -26,8 +26,6 @@ #include #include -#include "initialise/config.hpp" - /* struct containing functions which return zero for all initial conditions to create gridboxes' states e.g. via the create_gbxs function */ @@ -36,7 +34,7 @@ struct InitGbxsNull { size_t ngbxs; public: - explicit InitGbxsNull(const Config &config) : ngbxs(config.ngbxs) {} + explicit InitGbxsNull(const size_t ngbxs) : ngbxs(ngbxs) {} size_t get_ngbxs() const { return ngbxs; } diff --git a/libs/initialise/initsupers_frombinary.hpp b/libs/initialise/initsupers_frombinary.hpp index 0a2887749..d4b2b22e2 100644 --- a/libs/initialise/initsupers_frombinary.hpp +++ b/libs/initialise/initsupers_frombinary.hpp @@ -1,4 +1,6 @@ -/* Copyright (c) 2023 MPI-M, Clara Bayley +/* + * Copyright (c) 2024 MPI-M, Clara Bayley + * * * ----- CLEO ----- * File: initsupers_frombinary.hpp @@ -7,29 +9,28 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Thursday 2nd November 2023 + * Last Modified: Wednesday 17th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License * https://opensource.org/licenses/BSD-3-Clause * ----- * File Description: - * struct for superdroplets' initial conditions - * for CLEO SDM (e.g. superdroplet attributes) - * by reading binary file. InitSupersFromBinary - * instance can be used by InitConds - * struct as SuperdropInitConds type + * struct for superdroplets' initial conditions for CLEO SDM (e.g. superdroplet attributes) + * by reading binary file. InitSupersFromBinary instance can be used by InitConds + * struct as SuperdropInitConds type. */ #ifndef LIBS_INITIALISE_INITSUPERS_FROMBINARY_HPP_ #define LIBS_INITIALISE_INITSUPERS_FROMBINARY_HPP_ +#include #include #include #include -#include "./config.hpp" #include "./initconds.hpp" +#include "./optional_config_params.hpp" #include "./readbinary.hpp" #include "superdrops/superdrop_attrs.hpp" @@ -38,10 +39,9 @@ for the initial conditions needed to create superdroplets e.g. via the CreateSupers struct */ struct InitSupersFromBinary { private: + std::filesystem::path initsupers_filename; // filename for some of superdrops' initial conditons size_t totnsupers; // total number of superdroplets (in kokkos view on device initially) unsigned int nspacedims; // number of spatial dimensions to model (0-D, 1-D, 2-D of 3-D) - std::string_view - initsupers_filename; // name of binary file for some of superdrops' initial conditons /* sets initial data for solutes as a single SoluteProprties instance */ @@ -61,10 +61,10 @@ struct InitSupersFromBinary { void check_initdata_sizes(const InitSupersData &initdata) const; public: - explicit InitSupersFromBinary(const Config &config) - : totnsupers(config.totnsupers), - nspacedims(config.nspacedims), - initsupers_filename(config.initsupers_filename) {} + explicit InitSupersFromBinary(const OptionalConfigParams::InitSupersFromBinaryParams &config) + : initsupers_filename(config.initsupers_filename), + totnsupers(config.totnsupers), + nspacedims(config.nspacedims) {} auto get_totnsupers() const { return totnsupers; } diff --git a/libs/initialise/optional_config_params.cpp b/libs/initialise/optional_config_params.cpp new file mode 100644 index 000000000..758cd9ae4 --- /dev/null +++ b/libs/initialise/optional_config_params.cpp @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2024 MPI-M, Clara Bayley + * + * + * ----- CLEO ----- + * File: optional_config_params.cpp + * Project: initialise + * Created Date: Friday 13th October 2023 + * Author: Clara Bayley (CB) + * Additional Contributors: + * ----- + * Last Modified: Wednesday 17th April 2024 + * Modified By: CB + * ----- + * License: BSD 3-Clause "New" or "Revised" License + * https://opensource.org/licenses/BSD-3-Clause + * ----- + * File Description: + * Functions involved in reading optional configuration parameters from a config file. + */ + +#include "initialise/optional_config_params.hpp" + +/* read configuration file given by config_filename to set members of required configuration */ +OptionalConfigParams::OptionalConfigParams(const std::filesystem::path config_filename) { + const YAML::Node config = YAML::LoadFile(std::string{config_filename}); + + if (config["microphysics"]) { + set_microphysics(config); + } + + if (config["initsupers"]) { + set_initsupers(config); + } + + if (config["coupled_dynamics"]) { + set_coupled_dynamics(config); + } +} + +void OptionalConfigParams::set_microphysics(const YAML::Node &config) { + const YAML::Node yaml = config["microphysics"]; + + if (yaml["condensation"]) { + condensation.set_params(config); + condensation.print_params(); + } +} + +void OptionalConfigParams::set_initsupers(const YAML::Node &config) { + const auto type = config["initsupers"]["type"].as(); + + if (type == "frombinary") { + initsupersfrombinary.set_params(config); + initsupersfrombinary.print_params(); + } else { + throw std::invalid_argument("unknown initsupers 'type' : " + type); + } +} + +void OptionalConfigParams::set_coupled_dynamics(const YAML::Node &config) { + const auto type = config["coupled_dynamics"]["type"].as(); + + if (type == "fromfile") { + fromfiledynamics.set_params(config); + fromfiledynamics.print_params(); + } else if (type == "cvode") { + cvodedynamics.set_params(config); + cvodedynamics.print_params(); + } else { + throw std::invalid_argument("unknown coupled_dynamics 'type' : " + type); + } +} + +void OptionalConfigParams::CondensationParams::set_params(const YAML::Node &config) { + const YAML::Node yaml = config["microphysics"]["condensation"]; + + do_alter_thermo = yaml["do_alter_thermo"].as(); + niters = yaml["niters"].as(); + SUBTSTEP = yaml["SUBTSTEP"].as(); + rtol = yaml["rtol"].as(); + atol = yaml["atol"].as(); +} + +void OptionalConfigParams::CondensationParams::print_params() const { + std::cout << "\n-------- DoCondensation Configuration Parameters --------------" + << "\ndo_alter_thermo : " << do_alter_thermo << "\nniters : " << niters + << "\nSUBSTEP : " << SUBTSTEP << "\nrtol : " << rtol << "\natol : " << atol + << "\n---------------------------------------------------------\n"; +} + +void OptionalConfigParams::InitSupersFromBinaryParams::set_params(const YAML::Node &config) { + const YAML::Node yaml = config["initsupers"]; + + assert((yaml["type"].as() == "frombinary")); + + initsupers_filename = std::filesystem::path(yaml["initsupers_filename"].as()); + totnsupers = yaml["totnsupers"].as(); + nspacedims = config["domain"]["nspacedims"].as(); +} + +void OptionalConfigParams::InitSupersFromBinaryParams::print_params() const { + std::cout << "\n-------- InitSupersFromBinary Configuration Parameters --------------" + << "\nnspacedims : " << nspacedims << "\ninitsupers_filename : " << initsupers_filename + << "\ntotnsupers : " << totnsupers + << "\n---------------------------------------------------------\n"; +} + +void OptionalConfigParams::FromFileDynamicsParams::set_params(const YAML::Node &config) { + const YAML::Node yaml = config["coupled_dynamics"]; + + assert((yaml["type"].as() == "fromfile")); + + /* convert string to std::filesystem::path type */ + auto fspath_from_yaml = [&yaml](const std::string &key) { + return std::filesystem::path(yaml[key].as()); + }; + + nspacedims = config["domain"]["nspacedims"].as(); + press = fspath_from_yaml("press"); + temp = fspath_from_yaml("temp"); + qvap = fspath_from_yaml("qvap"); + qcond = fspath_from_yaml("qcond"); + switch (nspacedims) { + case 3: // 3-D model + vvel = fspath_from_yaml("vvel"); + case 2: // 3-D or 2-D model + uvel = fspath_from_yaml("uvel"); + case 1: // 3-D, 2-D or 1-D model + wvel = fspath_from_yaml("wvel"); + } +} + +void OptionalConfigParams::FromFileDynamicsParams::print_params() const { + std::cout << "\n-------- FromFileDynamics Configuration Parameters --------------" + << "\nnspacedims : " << nspacedims << "\npress : " << press << "\ntemp : " << temp + << "\nqvap : " << qvap << "\nqcond : " << qcond << "\nwvel : " << wvel + << "\nuvel : " << uvel << "\nvvel : " << vvel + << "\n---------------------------------------------------------\n"; +} + +void OptionalConfigParams::CvodeDynamicsParams::set_params(const YAML::Node &config) { + const YAML::Node yaml = config["coupled_dynamics"]; + + assert((yaml["type"].as() == "cvode")); + + ngbxs = config["domain"]["ngbxs"].as(); + P_init = yaml["P_init"].as(); + TEMP_init = yaml["TEMP_init"].as(); + relh_init = yaml["relh_init"].as(); + W_avg = yaml["W_avg"].as(); + TAU_half = yaml["TAU_half"].as(); + rtol = yaml["rtol"].as(); + atol = yaml["atol"].as(); +} + +void OptionalConfigParams::CvodeDynamicsParams::print_params() const { + std::cout << "\n-------- CvodeDynamics Configuration Parameters --------------" + << "\nngbxs : " << ngbxs << "\nP_init : " << P_init << "\nTEMP_init : " << TEMP_init + << "\nrelh_init : " << relh_init << "\nW_avg : " << W_avg << "\nTAU_half : " << TAU_half + << "\nrtol : " << rtol << "\natol : " << atol + << "\n---------------------------------------------------------\n"; +} diff --git a/libs/initialise/optional_config_params.hpp b/libs/initialise/optional_config_params.hpp new file mode 100644 index 000000000..065173b5a --- /dev/null +++ b/libs/initialise/optional_config_params.hpp @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2024 MPI-M, Clara Bayley + * + * + * ----- CLEO ----- + * File: optional_config_params.hpp + * Project: initialise + * Created Date: Friday 13th October 2023 + * Author: Clara Bayley (CB) + * Additional Contributors: + * ----- + * Last Modified: Thursday 18th April 2024 + * Modified By: CB + * ----- + * License: BSD 3-Clause "New" or "Revised" License + * https://opensource.org/licenses/BSD-3-Clause + * ----- + * File Description: + * Header file for members of Config struct which determine CLEO's optional configuration + * parameters read from a config file. + */ + +#ifndef LIBS_INITIALISE_OPTIONAL_CONFIG_PARAMS_HPP_ +#define LIBS_INITIALISE_OPTIONAL_CONFIG_PARAMS_HPP_ + +#include + +#include +#include +#include +#include +#include + +namespace NaNVals { +inline double dbl() { return std::numeric_limits::signaling_NaN(); }; +inline unsigned int uint() { return std::numeric_limits::signaling_NaN(); }; +inline size_t sizet() { return std::numeric_limits::signaling_NaN(); }; +} // namespace NaNVals + +/** + * @brief Struct storing optional configuration parameters for CLEO + * + * Optional means parameters have default values and therefore need not be set upon + * construction. Default values are not intended to be used and may caused model errors at runtime. + * + */ +struct OptionalConfigParams { + /* read configuration file given by config_filename to set members of required configuration */ + explicit OptionalConfigParams(const std::filesystem::path config_filename); + + void set_initsupers(const YAML::Node& config); + + void set_microphysics(const YAML::Node& config); + + void set_coupled_dynamics(const YAML::Node& config); + + /*** Super-Droplet Microphysics Parameters ***/ + struct CondensationParams { + void set_params(const YAML::Node& config); + void print_params() const; + bool do_alter_thermo = false; /**< true = cond/evap alters the thermodynamic state */ + unsigned int niters = NaNVals::uint(); /**< suggested no. iterations of Newton Raphson Method */ + double SUBTSTEP = NaNVals::dbl(); /**< smallest subtimestep in cases of substepping [s] */ + double rtol = NaNVals::dbl(); /**< relative tolerance for implicit Euler integration */ + double atol = NaNVals::dbl(); /**< abolute tolerance for implicit Euler integration */ + } condensation; + + /*** Super-Droplet Initialisation Parameters ***/ + struct InitSupersFromBinaryParams { + using fspath = std::filesystem::path; + void set_params(const YAML::Node& config); + void print_params() const; + fspath initsupers_filename = fspath(); /**< filename for initialisation of super-droplets */ + size_t totnsupers = NaNVals::sizet(); /**< initial total no. of Super-Droplets in the domain */ + unsigned int nspacedims = NaNVals::uint(); /**< no. of spatial dimensions to model */ + } initsupersfrombinary; + + /*** Coupled Dynamics Parameters ***/ + struct FromFileDynamicsParams { + void set_params(const YAML::Node& config); + void print_params() const; + using fspath = std::filesystem::path; + unsigned int nspacedims = NaNVals::uint(); /**< no. of spatial dimensions to model */ + fspath press = fspath(); /**< name of file for pressure data */ + fspath temp = fspath(); /**< name of file for temperature data */ + fspath qvap = fspath(); /**< name of file for vapour mixing ratio data */ + fspath qcond = fspath(); /**< name of file for liquid mixing ratio data */ + fspath wvel = fspath(); /**< name of file for vertical (z) velocity data */ + fspath uvel = fspath(); /**< name of file for horizontal x velocity data */ + fspath vvel = fspath(); /**< name of file for horizontal y velocity data */ + } fromfiledynamics; + + struct CvodeDynamicsParams { + void set_params(const YAML::Node& config); + void print_params() const; + size_t ngbxs = NaNVals::sizet(); /**< no. of spatial dimensions to model */ + /* initial (uniform) thermodynamic conditions */ + double P_init = NaNVals::dbl(); /**< initial pressure [Pa] */ + double TEMP_init = NaNVals::dbl(); /**< initial temperature [T] */ + double relh_init = NaNVals::dbl(); /**< initial relative humidity (%) */ + /* ODE solver parameters */ + double W_avg = NaNVals::dbl(); /**< average amplitude of sinusoidal w [m/s] (dP/dt ~ w*dP/dz) */ + double TAU_half = NaNVals::dbl(); /**< timescale for w sinusoid, tau_half = TAU_half/pi [s] */ + double rtol = NaNVals::dbl(); /**< relative tolerance for integration of [P, T, qv, qc] ODEs */ + double atol = NaNVals::dbl(); /**< absolute tolerances for integration of [P, T, qv, qc] ODEs */ + } cvodedynamics; +}; + +#endif // LIBS_INITIALISE_OPTIONAL_CONFIG_PARAMS_HPP_ diff --git a/libs/initialise/readbinary.cpp b/libs/initialise/readbinary.cpp index 176d81c7a..226da70d4 100644 --- a/libs/initialise/readbinary.cpp +++ b/libs/initialise/readbinary.cpp @@ -1,4 +1,6 @@ -/* Copyright (c) 2023 MPI-M, Clara Bayley +/* + * Copyright (c) 2024 MPI-M, Clara Bayley + * * * ----- CLEO ----- * File: readbinary.cpp @@ -7,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Thursday 14th December 2023 + * Last Modified: Wednesday 17th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -74,8 +76,8 @@ VarMetadata::VarMetadata(std::ifstream &file, const int off) { } /* open binary file for reading or raise error */ -std::ifstream open_binary(std::string_view filename) { - std::string filestr = static_cast(filename); +std::ifstream open_binary(const std::filesystem::path filename) { + std::string filestr = filename.string(); std::cout << "opening binary file: " << filestr << '\n'; std::ifstream file(filestr, std::ios::in | std::ios::binary); diff --git a/libs/initialise/readbinary.hpp b/libs/initialise/readbinary.hpp index afabef8e3..53f64a271 100644 --- a/libs/initialise/readbinary.hpp +++ b/libs/initialise/readbinary.hpp @@ -1,4 +1,6 @@ -/* Copyright (c) 2023 MPI-M, Clara Bayley +/* + * Copyright (c) 2024 MPI-M, Clara Bayley + * * * ----- CLEO ----- * File: readbinary.hpp @@ -7,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Tuesday 31st October 2023 + * Last Modified: Wednesday 17th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -21,6 +23,7 @@ #ifndef LIBS_INITIALISE_READBINARY_HPP_ #define LIBS_INITIALISE_READBINARY_HPP_ +#include #include #include #include @@ -60,7 +63,7 @@ struct VarMetadata { }; /* open binary file for reading or raise error */ -std::ifstream open_binary(std::string_view filename); +std::ifstream open_binary(const std::filesystem::path filename); /* Given a binary file that follows the correct layout, read and print the global metadata string at the start of the file, diff --git a/libs/initialise/required_config_params.cpp b/libs/initialise/required_config_params.cpp new file mode 100644 index 000000000..54ce6e407 --- /dev/null +++ b/libs/initialise/required_config_params.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2024 MPI-M, Clara Bayley + * + * + * ----- CLEO ----- + * File: required_config_params.cpp + * Project: initialise + * Created Date: Friday 13th October 2023 + * Author: Clara Bayley (CB) + * Additional Contributors: + * ----- + * Last Modified: Wednesday 17th April 2024 + * Modified By: CB + * ----- + * License: BSD 3-Clause "New" or "Revised" License + * https://opensource.org/licenses/BSD-3-Clause + * ----- + * File Description: + * Functions involved in reading required configuration parameters from a config file. + */ + +#include "initialise/required_config_params.hpp" + +/* read configuration file given by config_filename to set members of required configuration */ +RequiredConfigParams::RequiredConfigParams(const std::filesystem::path config_filename) { + const YAML::Node config = YAML::LoadFile(std::string{config_filename}); + + /* convert string to std::filesystem::path type */ + auto fspath_from_yaml = [](YAML::Node& yaml, const std::string& key) { + return std::filesystem::path(yaml[key].as()); + }; + + YAML::Node yaml = config["inputfiles"]; + inputfiles.constants_filename = fspath_from_yaml(yaml, "constants_filename"); + inputfiles.grid_filename = fspath_from_yaml(yaml, "grid_filename"); + + yaml = config["outputdata"]; + outputdata.setup_filename = fspath_from_yaml(yaml, "setup_filename"); + outputdata.stats_filename = fspath_from_yaml(yaml, "stats_filename"); + outputdata.zarrbasedir = fspath_from_yaml(yaml, "zarrbasedir"); + outputdata.maxchunk = yaml["maxchunk"].as(); + + yaml = config["domain"]; + domain.nspacedims = yaml["nspacedims"].as(); + domain.ngbxs = yaml["ngbxs"].as(); + + yaml = config["timesteps"]; + timesteps.CONDTSTEP = yaml["CONDTSTEP"].as(); + timesteps.COLLTSTEP = yaml["COLLTSTEP"].as(); + timesteps.MOTIONTSTEP = yaml["MOTIONTSTEP"].as(); + timesteps.COUPLTSTEP = yaml["COUPLTSTEP"].as(); + timesteps.OBSTSTEP = yaml["OBSTSTEP"].as(); + timesteps.T_END = yaml["T_END"].as(); + + print_params(); +} + +void RequiredConfigParams::print_params() const { + std::cout << "\n-------- Required Configuration Parameters --------------" + << "\nconstants_filename : " << inputfiles.constants_filename + << "\ngrid_filename : " << inputfiles.grid_filename + << "\nsetup_filename : " << outputdata.setup_filename + << "\nstats_filename : " << outputdata.stats_filename + << "\nzarrbasedir : " << outputdata.zarrbasedir + << "\nmaxchunk : " << outputdata.maxchunk << "\nnspacedims : " << domain.nspacedims + << "\nngbxs : " << domain.ngbxs << "\nCONDTSTEP : " << timesteps.CONDTSTEP + << "\nCOLLTSTEP : " << timesteps.COLLTSTEP + << "\nMOTIONTSTEP : " << timesteps.MOTIONTSTEP + << "\nCOUPLTSTEP : " << timesteps.COUPLTSTEP << "\nOBSTSTEP : " << timesteps.OBSTSTEP + << "\nT_END : " << timesteps.T_END + << "\n---------------------------------------------------------\n"; +} diff --git a/libs/initialise/required_config_params.hpp b/libs/initialise/required_config_params.hpp new file mode 100644 index 000000000..cc0802dee --- /dev/null +++ b/libs/initialise/required_config_params.hpp @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2024 MPI-M, Clara Bayley + * + * + * ----- CLEO ----- + * File: required_config_params.hpp + * Project: initialise + * Created Date: Friday 13th October 2023 + * Author: Clara Bayley (CB) + * Additional Contributors: + * ----- + * Last Modified: Wednesday 17th April 2024 + * Modified By: CB + * ----- + * License: BSD 3-Clause "New" or "Revised" License + * https://opensource.org/licenses/BSD-3-Clause + * ----- + * File Description: + * Header file for members of Config struct which determine CLEO's required configuration + * parameters read from a config file. + */ + +#ifndef LIBS_INITIALISE_REQUIRED_CONFIG_PARAMS_HPP_ +#define LIBS_INITIALISE_REQUIRED_CONFIG_PARAMS_HPP_ + +#include + +#include +#include +#include +#include + +/** + * @brief Struct storing required configuration parameters for CLEO + * + * Required means parameters have no default values and therefore must be set upon + * construction. + * + */ +struct RequiredConfigParams { + /* read configuration file given by config_filename to set members of required configuration */ + explicit RequiredConfigParams(const std::filesystem::path config_filename); + + void print_params() const; + + struct InputFilesParams { + std::filesystem::path constants_filename; /**< filename for values of physical constants */ + std::filesystem::path grid_filename; /**< filename for initialisation of GbxMaps */ + } inputfiles; + + struct OutputDataParams { + std::filesystem::path setup_filename; /**< filename to copy model setup to */ + std::filesystem::path stats_filename; /**< filename to output runtime statistics to */ + std::filesystem::path zarrbasedir; /**< name of base directory of zarr output */ + size_t maxchunk; /**< maximum number of elements in zarr array chunks */ + } outputdata; + + struct DomainParams { + unsigned int nspacedims; /**< no. of spatial dimensions to model */ + size_t ngbxs; /**< total number of Gbxs */ + } domain; + + struct TimestepsParams { + double CONDTSTEP; /**< time between SD condensation [s] */ + double COLLTSTEP; /**< time between SD collision [s] */ + double MOTIONTSTEP; /**< time between SDM motion [s] */ + double COUPLTSTEP; /**< time between thermodynamic couplings [s] */ + double OBSTSTEP; /**< time between SDM observations [s] */ + double T_END; /**< time span of integration from 0s to T_END [s] */ + } timesteps; +}; + +#endif // LIBS_INITIALISE_REQUIRED_CONFIG_PARAMS_HPP_ diff --git a/libs/initialise/timesteps.cpp b/libs/initialise/timesteps.cpp index 5df0e13a7..9f3ef91d5 100644 --- a/libs/initialise/timesteps.cpp +++ b/libs/initialise/timesteps.cpp @@ -1,4 +1,6 @@ -/* Copyright (c) 2023 MPI-M, Clara Bayley +/* + * Copyright (c) 2024 MPI-M, Clara Bayley + * * * ----- CLEO ----- * File: timesteps.cpp @@ -7,13 +9,14 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Thursday 14th December 2023 + * Last Modified: Wednesday 17th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License * https://opensource.org/licenses/BSD-3-Clause * ----- * File Description: + * File Description: * functionality for handling model timesteps and * their conversions to/from real times */ @@ -25,7 +28,7 @@ are converted into integer values of model timesteps using model_step and secd template functions created using std::chrono library. Throw error if after convertion into model timestep, any timestep = 0. Substeps for sdmprocess must be larger than steps! */ -Timesteps::Timesteps(const Config &config) +Timesteps::Timesteps(const RequiredConfigParams::TimestepsParams &config) : condstep(realtime2step(config.CONDTSTEP)), collstep(realtime2step(config.COLLTSTEP)), motionstep(realtime2step(config.MOTIONTSTEP)), diff --git a/libs/initialise/timesteps.hpp b/libs/initialise/timesteps.hpp index 07baa86b4..3eb21da6a 100644 --- a/libs/initialise/timesteps.hpp +++ b/libs/initialise/timesteps.hpp @@ -1,4 +1,6 @@ -/* Copyright (c) 2023 MPI-M, Clara Bayley +/* + * Copyright (c) 2024 MPI-M, Clara Bayley + * * * ----- CLEO ----- * File: timesteps.hpp @@ -7,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Wednesday 22nd November 2023 + * Last Modified: Wednesday 17th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -28,7 +30,7 @@ #include #include "../cleoconstants.hpp" -#include "./config.hpp" +#include "./required_config_params.hpp" namespace dlc = dimless_constants; @@ -76,7 +78,7 @@ class Timesteps { std::chrono library. Throw error if after convertion into model timestep, any timestep = 0 or if a sub-timestep is longer than a timestep */ - explicit Timesteps(const Config &config); + explicit Timesteps(const RequiredConfigParams::TimestepsParams &config_tsteps); auto get_condstep() const { return condstep; } auto get_collstep() const { return collstep; } diff --git a/libs/observers/gbxindex_observer.hpp b/libs/observers/gbxindex_observer.hpp index 05fdb888d..1b649c62d 100644 --- a/libs/observers/gbxindex_observer.hpp +++ b/libs/observers/gbxindex_observer.hpp @@ -9,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Tuesday 9th April 2024 + * Last Modified: Wednesday 17th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -94,7 +94,7 @@ class GbxindexObserver { * @param maxchunk Maximum number of elements in a chunk (1-D vector size). * @param ngbxs Number of gridboxes in final array. */ - GbxindexObserver(Dataset &dataset, const int maxchunk, const size_t ngbxs) + GbxindexObserver(Dataset &dataset, const size_t maxchunk, const size_t ngbxs) : dataset(dataset), xzarr_ptr(std::make_shared>( dataset.template create_coordinate_array("gbxindex", "", " create_massmom2_xarray(const Dataset &datas */ template inline Observer auto MassMomentsObserver(const unsigned int interval, const Dataset &dataset, - const int maxchunk, const size_t ngbxs) { + const size_t maxchunk, const size_t ngbxs) { const auto xzarr_mom0 = create_massmom0_xarray(dataset, "massmom0", maxchunk, ngbxs); const auto xzarr_mom1 = create_massmom1_xarray(dataset, "massmom1", maxchunk, ngbxs); const auto xzarr_mom2 = create_massmom2_xarray(dataset, "massmom2", maxchunk, ngbxs); @@ -417,8 +417,8 @@ inline Observer auto MassMomentsObserver(const unsigned int interval, const Data */ template inline Observer auto MassMomentsRaindropsObserver(const unsigned int interval, - const Dataset &dataset, const int maxchunk, - const size_t ngbxs) { + const Dataset &dataset, + const size_t maxchunk, const size_t ngbxs) { const auto xzarr_mom0 = create_massmom0_xarray(dataset, "massmom0_raindrops", maxchunk, ngbxs); const auto xzarr_mom1 = create_massmom1_xarray(dataset, "massmom1_raindrops", maxchunk, ngbxs); const auto xzarr_mom2 = create_massmom2_xarray(dataset, "massmom2_raindrops", maxchunk, ngbxs); diff --git a/libs/observers/nsupers_observer.hpp b/libs/observers/nsupers_observer.hpp index c31d21e8e..e00cdabd9 100644 --- a/libs/observers/nsupers_observer.hpp +++ b/libs/observers/nsupers_observer.hpp @@ -9,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Thursday 11th April 2024 + * Last Modified: Wednesday 17th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -74,7 +74,7 @@ struct NsupersFunc { */ template inline CollectDataForDataset auto CollectNsupers(const Dataset &dataset, - const int maxchunk, const size_t ngbxs) { + const size_t maxchunk, const size_t ngbxs) { const auto chunkshape = good2Dchunkshape(maxchunk, ngbxs); const auto dimnames = std::vector{"time", "gbxindex"}; const auto xzarr = @@ -96,7 +96,7 @@ inline CollectDataForDataset auto CollectNsupers(const Dataset &da */ template inline Observer auto NsupersObserver(const unsigned int interval, const Dataset &dataset, - const int maxchunk, const size_t ngbxs) { + const size_t maxchunk, const size_t ngbxs) { return WriteToDatasetObserver(interval, dataset, CollectNsupers(dataset, maxchunk, ngbxs)); } diff --git a/libs/observers/runstats_observer.cpp b/libs/observers/runstats_observer.cpp index 00e300501..536510992 100644 --- a/libs/observers/runstats_observer.cpp +++ b/libs/observers/runstats_observer.cpp @@ -9,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Tuesday 9th April 2024 + * Last Modified: Wednesday 17th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -43,7 +43,7 @@ void RunStatsObserver::print_summary() const { * Writes timing statistics out to a text file called stats_filename. */ void RunStatsObserver::write_to_file() const { - std::ofstream file(stats_filename); + std::ofstream file(stats_filename.string()); if (file.is_open()) { const std::string header( diff --git a/libs/observers/runstats_observer.hpp b/libs/observers/runstats_observer.hpp index a11478cf6..be15c4a79 100644 --- a/libs/observers/runstats_observer.hpp +++ b/libs/observers/runstats_observer.hpp @@ -9,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Tuesday 9th April 2024 + * Last Modified: Wednesday 17th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -25,6 +25,7 @@ #define LIBS_OBSERVERS_RUNSTATS_OBSERVER_HPP_ #include +#include #include #include #include @@ -70,9 +71,9 @@ struct RunStats { */ class RunStatsObserver { private: - unsigned int interval; /**< Timestep between runtime observations. */ - std::shared_ptr stats; /**< Pointer to runtime statistics. */ - std::string stats_filename; /**< Filename to output runtime statistics. */ + unsigned int interval; /**< Timestep between runtime observations. */ + std::shared_ptr stats; /**< Pointer to runtime statistics. */ + std::filesystem::path stats_filename; /**< Filename to output runtime statistics. */ /** * @brief Function to be executed at the start of each timestep. @@ -100,7 +101,7 @@ class RunStatsObserver { * @param obsstep Model timestep between runstats observations. * @param stats_filename Filename to output run statistics. */ - RunStatsObserver(const unsigned int obsstep, const std::string stats_filename) + RunStatsObserver(const unsigned int obsstep, const std::filesystem::path stats_filename) : interval(obsstep), stats(std::make_shared()), stats_filename(stats_filename) {} /** diff --git a/libs/observers/state_observer.hpp b/libs/observers/state_observer.hpp index 6185e7b80..bdb509e99 100644 --- a/libs/observers/state_observer.hpp +++ b/libs/observers/state_observer.hpp @@ -9,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Thursday 11th April 2024 + * Last Modified: Wednesday 17th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -57,7 +57,7 @@ */ template inline Observer auto StateObserver(const unsigned int interval, const Dataset &dataset, - const int maxchunk, const size_t ngbxs) { + const size_t maxchunk, const size_t ngbxs) { const CollectDataForDataset auto thermo = CollectThermo(dataset, maxchunk, ngbxs); const CollectDataForDataset auto windvel = CollectWindVel(dataset, maxchunk, ngbxs); diff --git a/libs/observers/superdrops_observer.hpp b/libs/observers/superdrops_observer.hpp index 0850bffbc..9e0250967 100644 --- a/libs/observers/superdrops_observer.hpp +++ b/libs/observers/superdrops_observer.hpp @@ -9,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Thursday 11th April 2024 + * Last Modified: Wednesday 17th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -39,8 +39,6 @@ #include "superdrops/superdrop.hpp" #include "zarr/dataset.hpp" -// TODO(CB) docstrings - /** * @brief A struct for collecting ragged count data. * @@ -169,7 +167,7 @@ struct SdgbxindexFunc { */ template CollectDataForDataset auto CollectSdgbxindex(const Dataset &dataset, - const int maxchunk) { + const size_t maxchunk) { return CollectSuperdropVariable( dataset, SdgbxindexFunc{}, "sdgbxindex", "", " -CollectDataForDataset auto CollectSdId(const Dataset &dataset, const int maxchunk) { +CollectDataForDataset auto CollectSdId(const Dataset &dataset, + const size_t maxchunk) { return CollectSuperdropVariable(dataset, SdIdFunc{}, "sdId", "", " An instance of CollectDataForDataset for collecting xi data. */ template -CollectDataForDataset auto CollectXi(const Dataset &dataset, const int maxchunk) { +CollectDataForDataset auto CollectXi(const Dataset &dataset, const size_t maxchunk) { return CollectSuperdropVariable(dataset, XiFunc{}, "xi", "", " An instance of CollectDataForDataset for collecting radius. */ template -CollectDataForDataset auto CollectRadius(const Dataset &dataset, const int maxchunk) { +CollectDataForDataset auto CollectRadius(const Dataset &dataset, + const size_t maxchunk) { return CollectSuperdropVariable( dataset, RadiusFunc{}, "radius", "micro-m", " An instance of CollectDataForDataset for collecting msol. */ template -CollectDataForDataset auto CollectMsol(const Dataset &dataset, const int maxchunk) { +CollectDataForDataset auto CollectMsol(const Dataset &dataset, + const size_t maxchunk) { return CollectSuperdropVariable(dataset, MsolFunc{}, "msol", "g", " An instance of CollectDataForDataset for collecting coord3. */ template -CollectDataForDataset auto CollectCoord3(const Dataset &dataset, const int maxchunk) { +CollectDataForDataset auto CollectCoord3(const Dataset &dataset, + const size_t maxchunk) { return CollectSuperdropVariable(dataset, Coord3Func{}, "coord3", "m", " An instance of CollectDataForDataset for collecting coord1. */ template -CollectDataForDataset auto CollectCoord1(const Dataset &dataset, const int maxchunk) { +CollectDataForDataset auto CollectCoord1(const Dataset &dataset, + const size_t maxchunk) { return CollectSuperdropVariable(dataset, Coord1Func{}, "coord1", "m", " An instance of CollectDataForDataset for collecting coord2. */ template -CollectDataForDataset auto CollectCoord2(const Dataset &dataset, const int maxchunk) { +CollectDataForDataset auto CollectCoord2(const Dataset &dataset, + const size_t maxchunk) { return CollectSuperdropVariable(dataset, Coord2Func{}, "coord2", "m", " auto CollectCoord2(const Dataset &dataset, c */ template inline Observer auto SuperdropsObserver(const unsigned int interval, const Dataset &dataset, - const int maxchunk, + const size_t maxchunk, CollectDataForDataset auto collect_data) { const CollectRaggedCount auto ragged_count = RaggedCount(dataset, maxchunk); return WriteToDatasetObserver(interval, dataset, collect_data, ragged_count); diff --git a/libs/observers/thermo_observer.hpp b/libs/observers/thermo_observer.hpp index 7271da77e..2f62b5514 100644 --- a/libs/observers/thermo_observer.hpp +++ b/libs/observers/thermo_observer.hpp @@ -9,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Thursday 11th April 2024 + * Last Modified: Wednesday 17th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -174,7 +174,7 @@ struct QcondFunc { */ template inline CollectDataForDataset auto CollectThermo(const Dataset &dataset, - const int maxchunk, const size_t ngbxs) { + const size_t maxchunk, const size_t ngbxs) { const CollectDataForDataset auto press = CollectThermoVariable( dataset, PressFunc{}, "press", "hPa", dlc::P0 / 100, maxchunk, ngbxs); @@ -204,7 +204,7 @@ inline CollectDataForDataset auto CollectThermo(const Dataset &dat */ template inline Observer auto ThermoObserver(const unsigned int interval, const Dataset &dataset, - const int maxchunk, const size_t ngbxs) { + const size_t maxchunk, const size_t ngbxs) { const CollectDataForDataset auto thermo = CollectThermo(dataset, maxchunk, ngbxs); return WriteToDatasetObserver(interval, dataset, thermo); } diff --git a/libs/observers/time_observer.hpp b/libs/observers/time_observer.hpp index 312a6e9e9..8bd496e51 100644 --- a/libs/observers/time_observer.hpp +++ b/libs/observers/time_observer.hpp @@ -9,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Wednesday 10th April 2024 + * Last Modified: Wednesday 17th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -131,7 +131,7 @@ class DoTimeObs { */ template inline Observer auto TimeObserver(const unsigned int interval, Dataset &dataset, - const int maxchunk, + const size_t maxchunk, const std::function step2dimlesstime) { return ConstTstepObserver(interval, DoTimeObs(dataset, maxchunk, step2dimlesstime)); } diff --git a/libs/observers/totnsupers_observer.hpp b/libs/observers/totnsupers_observer.hpp index 683a8d978..c1d25590b 100644 --- a/libs/observers/totnsupers_observer.hpp +++ b/libs/observers/totnsupers_observer.hpp @@ -9,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Wednesday 10th April 2024 + * Last Modified: Wednesday 17th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -120,7 +120,7 @@ class DoTotNsupersObs { */ template inline Observer auto TotNsupersObserver(const unsigned int interval, Dataset &dataset, - const int maxchunk) { + const size_t maxchunk) { return ConstTstepObserver(interval, DoTotNsupersObs(dataset, maxchunk)); } diff --git a/libs/observers/windvel_observer.hpp b/libs/observers/windvel_observer.hpp index b3265f713..a34d69750 100644 --- a/libs/observers/windvel_observer.hpp +++ b/libs/observers/windvel_observer.hpp @@ -9,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Thursday 11th April 2024 + * Last Modified: Wednesday 17th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -152,7 +152,7 @@ struct VvelFunc { */ template inline CollectDataForDataset auto CollectWindVel(const Dataset &dataset, - const int maxchunk, const size_t ngbxs) { + const size_t maxchunk, const size_t ngbxs) { const CollectDataForDataset auto wvel = CollectWindVariable(dataset, WvelFunc{}, "wvel", maxchunk, ngbxs); @@ -179,7 +179,7 @@ inline CollectDataForDataset auto CollectWindVel(const Dataset &da */ template inline Observer auto WindVelObserver(const unsigned int interval, const Dataset &dataset, - const int maxchunk, const size_t ngbxs) { + const size_t maxchunk, const size_t ngbxs) { const CollectDataForDataset auto windvel = CollectWindVel(dataset, maxchunk, ngbxs); return WriteToDatasetObserver(interval, dataset, windvel); } diff --git a/libs/superdrops/condensation.cpp b/libs/superdrops/condensation.cpp index 49602e5bd..13f578549 100644 --- a/libs/superdrops/condensation.cpp +++ b/libs/superdrops/condensation.cpp @@ -9,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Monday 11th March 2024 + * Last Modified: Wednesday 17th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -20,7 +20,6 @@ * microphysical process in SDM */ - #include "./condensation.hpp" /** @@ -104,7 +103,7 @@ double DoCondensation::superdroplets_change(const TeamMember &team_member, * @param s_ratio The saturation ratio. * @param ffactor The sum of the diffusion factors. * @return The mass of liquid condensed or evaporated. -*/ + */ KOKKOS_FUNCTION double DoCondensation::superdrop_mass_change(Superdrop &drop, const double temp, const double s_ratio, const double ffactor) const { @@ -126,7 +125,7 @@ double DoCondensation::superdrop_mass_change(Superdrop &drop, const double temp, /** * @brief Applies the effect of condensation / evaporation on the thermodynamics of the State. * - * if doAlterThermo is true, use a single team member to change the thermodynamics of the + * if do_alter_thermo is true, use a single team member to change the thermodynamics of the * State due to the effect of condensation / evaporation. * * @param team_member The Kokkos team member. @@ -141,7 +140,7 @@ void DoCondensation::effect_on_thermodynamic_state(const TeamMember &team_member Kokkos::single( Kokkos::PerTeam(team_member), [&, this](State &state) { - if (doAlterThermo) { + if (do_alter_thermo) { const auto VOLUME = double{state.get_volume() * dlc::VOL0}; // volume in which condensation occurs [m^3] const auto totrho_condensed = diff --git a/libs/superdrops/condensation.hpp b/libs/superdrops/condensation.hpp index f55c12d20..4e5a89a6c 100644 --- a/libs/superdrops/condensation.hpp +++ b/libs/superdrops/condensation.hpp @@ -8,7 +8,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: Shin-ichiro Shima (SiS) * ----- - * Last Modified: Monday 11th March 2024 + * Last Modified: Wednesday 17th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -24,11 +24,10 @@ #ifndef LIBS_SUPERDROPS_CONDENSATION_HPP_ #define LIBS_SUPERDROPS_CONDENSATION_HPP_ -#include - #include #include // for pi #include +#include #include "../cleoconstants.hpp" #include "./impliciteuler.hpp" @@ -46,7 +45,7 @@ namespace dlc = dimless_constants; */ struct DoCondensation { private: - bool doAlterThermo; /**< Whether to make condensation alter State or not */ + bool do_alter_thermo; /**< Whether to make condensation/evaporation alter State or not */ ImplicitEuler impe; /**< instance of ImplicitEuler ODE solver */ /** @@ -106,7 +105,7 @@ struct DoCondensation { * @param s_ratio The saturation ratio. * @param ffactor The sum of the diffusion factors. * @return The mass of liquid condensed or evaporated. - */ + */ KOKKOS_FUNCTION double superdrop_mass_change(Superdrop &drop, const double temp, const double s_ratio, const double ffactor) const; @@ -114,7 +113,7 @@ struct DoCondensation { /** * @brief Applies the effect of condensation / evaporation on the thermodynamics of the State. * - * if doAlterThermo is true, use a single team member to change the thermodynamics of the + * if do_alter_thermo is true, use a single team member to change the thermodynamics of the * State due to the effect of condensation / evaporation. * * @param team_member The Kokkos team member. @@ -144,16 +143,16 @@ struct DoCondensation { public: /** * @brief Constructs a DoCondensation object. - * @param doAlterThermo Whether to alter the thermodynamics of the State. + * @param do_alter_thermo Whether to alter the thermodynamics of the State. * @param niters Number of iterations of implicit Euler method. * @param delt Time step to integrate ODE using implcit Euler method. * @param maxrtol Maximum relative tolerance for implicit Euler method. * @param maxatol Maximum absolute tolerance for implicit Euler method. * @param subdelt Sub-time step size in implicit Euler method. */ - DoCondensation(const bool doAlterThermo, const unsigned int niters, const double delt, + DoCondensation(const bool do_alter_thermo, const unsigned int niters, const double delt, const double maxrtol, const double maxatol, const double subdelt) - : doAlterThermo(doAlterThermo), impe(niters, delt, maxrtol, maxatol, subdelt) {} + : do_alter_thermo(do_alter_thermo), impe(niters, delt, maxrtol, maxatol, subdelt) {} /** * @brief Operator used as an "adaptor" for using condensation as the function-like type @@ -182,7 +181,7 @@ struct DoCondensation { * with a constant time-step 'interval'. * * @param interval The constant time-step for condensation. - * @param doAlterThermo Whether to alter the thermodynamic state after condensation / evaporation. + * @param do_alter_thermo Whether to alter the thermodynamic state after condensation / evaporation. * @param niters Number of iterations of implicit Euler method. * @param step2dimlesstime A function to convert 'interval' time-step to a dimensionless time. * @param maxrtol Maximum relative tolerance for implicit Euler method. @@ -192,14 +191,14 @@ struct DoCondensation { * @return The constructed microphysical process for condensation / evaporation. */ inline MicrophysicalProcess auto Condensation( - const unsigned int interval, const bool doAlterThermo, const unsigned int niters, - const std::function step2dimlesstime, const double maxrtol, + const unsigned int interval, const std::function step2dimlesstime, + const bool do_alter_thermo, const unsigned int niters, const double maxrtol, const double maxatol, const double SUBDELT, const std::function realtime2dimless) { const auto delt = step2dimlesstime(interval); // dimensionless time equivlent to interval const auto subdelt = realtime2dimless(SUBDELT); // dimensionless time equivlent to SUBDELT [s] - const auto do_cond = DoCondensation(doAlterThermo, niters, delt, maxrtol, maxatol, subdelt); + const auto do_cond = DoCondensation(do_alter_thermo, niters, delt, maxrtol, maxatol, subdelt); return ConstTstepMicrophysics(interval, do_cond); } diff --git a/libs/zarr/zarr_array.hpp b/libs/zarr/zarr_array.hpp index c9bd7249d..4243f1932 100644 --- a/libs/zarr/zarr_array.hpp +++ b/libs/zarr/zarr_array.hpp @@ -9,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Tuesday 9th April 2024 + * Last Modified: Wednesday 17th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -37,19 +37,19 @@ #include "./chunks.hpp" /** - * @brief Given maximum chunk size 'maxchunksize' and length of inner dimension of one chunk of + * @brief Given maximum chunk size 'maxchunk' and length of inner dimension of one chunk of * array 'dim1size', function returns the largest possible chunk shape that has the length of its * inner dimension = dim1size. * - * dim1size must also be <= maxchunksize and to ensure good chunking, dim1size should itself be + * dim1size must also be <= maxchunk and to ensure good chunking, dim1size should itself be * completely divisible by the final length of the inner dimension of the 2-D array. * - * @param maxchunksize The maximum chunk size (maximum number of elements in chunk). + * @param maxchunk The maximum chunk size (maximum number of elements in chunk). * @param dim1size The length of (number of elements along) the inner dimension of one chunk. * @return std::vector The largest possible 2-D chunk shape. */ -inline std::vector good2Dchunkshape(const size_t maxchunksize, const size_t dim1size) { - const auto shape0 = size_t{maxchunksize / dim1size}; // same as floor for +ve integers +inline std::vector good2Dchunkshape(const size_t maxchunk, const size_t dim1size) { + const auto shape0 = size_t{maxchunk / dim1size}; // same as floor for +ve integers return {shape0, dim1size}; } diff --git a/pySD/cxx2py.py b/pySD/cxx2py.py index 14d5c4d79..6fe8e5214 100644 --- a/pySD/cxx2py.py +++ b/pySD/cxx2py.py @@ -6,7 +6,7 @@ Author: Clara Bayley (CB) Additional Contributors: ----- -Last Modified: Monday 8th April 2024 +Last Modified: Wednesday 17th April 2024 Modified By: CB ----- License: BSD 3-Clause "New" or "Revised" License @@ -121,36 +121,3 @@ def derive_more_floats(consts): mconsts["MASS0"] = (consts["R0"]**3) * mconsts["RHO0"] # characteristic mass [Kg] return mconsts - -def read_configparams_into_floats(filename): - """returns dictionary of value: float from - values assigned in a config .txt file. - Also returns dictionary of notfloats - for values that couldn't be converted. """ - - floats = {} - notfloats = {} - with open(filename) as file: - rlines=[] - filelines = file.readlines() - for line in filelines: - if line[0] != "#" and line[0] != "/" and "=" in line: - goodline = remove_excess_line(line) - rlines.append(goodline) - - for line in rlines: - ind = line.find("=") - name = line[:ind] - value = line[ind+1:] - - try: - floats[name] = float(value) - except ValueError: - notfloats[name] = value - - try: - floats["nspacedims"] = int(floats["nspacedims"]) # no spatial coords to SDs - except: - pass - - return floats diff --git a/pySD/editconfigfile.py b/pySD/editconfigfile.py index a9c124c55..524ae2707 100644 --- a/pySD/editconfigfile.py +++ b/pySD/editconfigfile.py @@ -1,30 +1,62 @@ -def edit_config_params(filename, params2change): - """rewrites config file with parameters listed in - dict params2change edited to new values also in dict""" +''' +Copyright (c) 2024 MPI-M, Clara Bayley + + +----- CLEO ----- +File: editconfigfile.py +Project: pySD +Created Date: Wednesday 17th January 2024 +Author: Clara Bayley (CB) +Additional Contributors: +----- +Last Modified: Thursday 18th April 2024 +Modified By: CB +----- +License: BSD 3-Clause "New" or "Revised" License +https://opensource.org/licenses/BSD-3-Clause +----- +File Description: +''' - wlines=[] +from ruamel.yaml import YAML - with open(filename) as file: - filelines = file.readlines() - for line in filelines: - wlines.append(line) +def update_param(node, param, new_value): + '''Function to recursively searches for 'param' key in YAML node + and updates it's value to with 'new_value' when found ''' - for l, line in enumerate(wlines): - if line[0] != "#" and line[0] != "/" and "=" in line: - for key, value in params2change.items(): - if key in line: + if isinstance(node, dict): + if param in node: + node[param] = new_value # update value + return True + else: + for key, val in node.items(): + is_success = update_param(val, param, new_value) + if is_success: + return True + elif isinstance(node, list): + for item in node: + is_success = update_param(item, param, new_value) + if is_success: + return True + return False + +def edit_config_params(filename, params2change): + ''' rewrites config YAML file with key,value pairs listed in params2change updated to new values + whilst preserving original YAML file's formatting and comments etc. ''' - # create line with new value for key - newline = key+" = "+str(value) - newline = newline.ljust(40) + yaml = YAML() - # add comment to new line if there is one - ind = line.find("#") - newline = newline+line[ind:] + # Load the YAML file + with open(filename, 'r') as file: + data = yaml.load(file) - # overwrite line with newline - wlines[l] = newline + # Update the parameters from the YAML file + for param, new_value in params2change.items(): + is_success = update_param(data, param, new_value) + if not is_success: + errmsg = param+" could not be updated to new value: "+str(new_value) + raise ValueError(errmsg) - file = open(filename, "w") - file.writelines(wlines) - file.close() + # Overwrite the YAML file + with open(filename, 'w') as file: + yaml.dump(data, file) diff --git a/pySD/gbxboundariesbinary_src/create_gbxboundaries.py b/pySD/gbxboundariesbinary_src/create_gbxboundaries.py index 95bf56c70..9bc6f8bc2 100644 --- a/pySD/gbxboundariesbinary_src/create_gbxboundaries.py +++ b/pySD/gbxboundariesbinary_src/create_gbxboundaries.py @@ -6,7 +6,7 @@ Author: Clara Bayley (CB) Additional Contributors: ----- -Last Modified: Tuesday 24th October 2023 +Last Modified: Wednesday 17th April 2024 Modified By: CB ----- License: BSD 3-Clause "New" or "Revised" License @@ -23,8 +23,7 @@ from .. import cxx2py, writebinary def get_COORD0_from_constsfile(constsfile, returnconsts=False): - ''' create values from constants file & config file - required as inputs to create initial + ''' create values from constants file required as inputs to create initial superdroplet conditions ''' consts = cxx2py.read_cxxconsts_into_floats(constsfile) diff --git a/pySD/gbxboundariesbinary_src/read_gbxboundaries.py b/pySD/gbxboundariesbinary_src/read_gbxboundaries.py index 99db823ca..ec8769437 100644 --- a/pySD/gbxboundariesbinary_src/read_gbxboundaries.py +++ b/pySD/gbxboundariesbinary_src/read_gbxboundaries.py @@ -1,3 +1,23 @@ +''' +Copyright (c) 2024 MPI-M, Clara Bayley + + +----- CLEO ----- +File: read_gbxboundaries.py +Project: gbxboundariesbinary_src +Created Date: Wednesday 17th January 2024 +Author: Clara Bayley (CB) +Additional Contributors: +----- +Last Modified: Wednesday 17th April 2024 +Modified By: CB +----- +License: BSD 3-Clause "New" or "Revised" License +https://opensource.org/licenses/BSD-3-Clause +----- +File Description: +''' + import numpy as np import matplotlib.pyplot as plt @@ -248,9 +268,7 @@ def grid_dimensions(gbxbounds): return extents, spacings, griddims def print_domain_info(constsfile, gridfile): - ''' create values from constants file & config file - required as inputs to create initial - superdroplet conditions ''' + ''' prints information about domain reda from gridfile and constants file ''' isprint=True COORD0 = get_COORD0_from_constsfile(constsfile) diff --git a/pySD/initsuperdropsbinary_src/create_initsuperdrops.py b/pySD/initsuperdropsbinary_src/create_initsuperdrops.py index f7d3adaf2..6c4967e96 100644 --- a/pySD/initsuperdropsbinary_src/create_initsuperdrops.py +++ b/pySD/initsuperdropsbinary_src/create_initsuperdrops.py @@ -6,7 +6,7 @@ Author: Clara Bayley (CB) Additional Contributors: ----- -Last Modified: Friday 22nd December 2023 +Last Modified: Wednesday 17th April 2024 Modified By: CB ----- License: BSD 3-Clause "New" or "Revised" License @@ -20,7 +20,7 @@ import numpy as np from os.path import isfile -from .. import cxx2py, writebinary +from .. import cxx2py, readconfigfile, writebinary from ..gbxboundariesbinary_src.read_gbxboundaries import read_dimless_gbxboundaries_binary class ManyAttrs: @@ -62,7 +62,7 @@ def initSDsinputsdict(configfile, constsfile): consts = cxx2py.read_cxxconsts_into_floats(constsfile) mconsts = cxx2py.derive_more_floats(consts) - config = cxx2py.read_configparams_into_floats(configfile) + config = readconfigfile.read_configparams_into_floats(configfile) inputs = { # for creating SD attribute distirbutions diff --git a/pySD/readconfigfile.py b/pySD/readconfigfile.py new file mode 100644 index 000000000..2ab11e9ee --- /dev/null +++ b/pySD/readconfigfile.py @@ -0,0 +1,61 @@ +''' +Copyright (c) 2024 MPI-M, Clara Bayley + + +----- CLEO ----- +File: readconfigfile.py +Project: pySD +Created Date: Wednesday 17th April 2024 +Author: Clara Bayley (CB) +Additional Contributors: +----- +Last Modified: Wednesday 17th April 2024 +Modified By: CB +----- +License: BSD 3-Clause "New" or "Revised" License +https://opensource.org/licenses/BSD-3-Clause +----- +File Description: +''' + +from ruamel.yaml import YAML + +def extract_floats(node, floats, notfloats): + '''Function to recursively searches YAML node + and add any value that is convertible to a float to a dictionary + with its key ''' + + if isinstance(node, dict): + for key, value in node.items(): + if isinstance(value, (dict, list)): + extract_floats(value, floats, notfloats) + else: + try: + floats[key] = float(value) + except: + notfloats[key] = value + elif isinstance(node, list): + for item in node: + extract_floats(item, floats, notfloats) + + return floats, notfloats + +def read_configparams_into_floats(filename): + '''returns dictionary of {key, values} pairs from + keys from a config yaml file which can be assigned float values. + Also obtains dictionary of notfloats for values that couldn't be converted + and converts nspacedims to integer if found in floats.''' + + yaml = YAML(typ='safe') + with open(filename, 'r') as file: + config = yaml.load(file) + + floats, notfloats = {}, {} + floats, notfloats = extract_floats(config, floats, notfloats) + + try: + floats["nspacedims"] = int(floats["nspacedims"]) # no spatial coords to SDs + except: + pass + + return floats diff --git a/pySD/sdmout_src/ensembzarr.py b/pySD/sdmout_src/ensembzarr.py index e858add7e..42151643c 100644 --- a/pySD/sdmout_src/ensembzarr.py +++ b/pySD/sdmout_src/ensembzarr.py @@ -6,7 +6,7 @@ Author: Clara Bayley (CB) Additional Contributors: ----- -Last Modified: Friday 19th January 2024 +Last Modified: Thursday 18th April 2024 Modified By: CB ----- License: BSD 3-Clause "New" or "Revised" License @@ -54,7 +54,7 @@ def write_ensemb_setupfile(ensembsetupfile, setupfile, datasets): os.system('cp '+setupfile+" "+ensembsetupfile) params = { "initsupers_filename" : "[ensemble, see below]", - "setuptxt" : "[ensemble, see below]", + "setup_filename" : "[ensemble, see below]", "zarrbasedir" : "[ensemble, see below]", "stats_filename" : "[ensemble, see below]" } diff --git a/pySD/sdmout_src/pysetuptxt.py b/pySD/sdmout_src/pysetuptxt.py index c0e749f9e..3b1c83005 100644 --- a/pySD/sdmout_src/pysetuptxt.py +++ b/pySD/sdmout_src/pysetuptxt.py @@ -6,7 +6,7 @@ Author: Clara Bayley (CB) Additional Contributors: ----- -Last Modified: Monday 20th November 2023 +Last Modified: Thursday 18th April 2024 Modified By: CB ----- License: BSD 3-Clause "New" or "Revised" License @@ -21,21 +21,30 @@ from .. import cxx2py +def get_consts(setuptxt, isprint=True): + '''returns dictionary of constants + read from from setup.txt file ''' + + return consts_dict(setuptxt, isprint=isprint) + def get_config(setuptxt, nattrs=3, isprint=True): '''returns dictionary of configuration parameters read from from setup.txt file ''' return config_dict(setuptxt, nattrs=nattrs, isprint=isprint) -def get_consts(setuptxt, isprint=True): - '''returns dictionary of constants - read from from setup.txt file ''' +def consts_dict(setuptxt, isprint): + consts = cxx2py.read_cxxconsts_into_floats(setuptxt) + consts.update(cxx2py.derive_more_floats(consts)) - return consts_dict(setuptxt, isprint=isprint) + if isprint: + cxx2py.print_dict_statement(setuptxt, "consts", consts) + + return consts def config_dict(setuptxt, nattrs, isprint): - config = cxx2py.read_configparams_into_floats(setuptxt) + config = read_configparams_fromsetuptxt_into_floats(setuptxt) config["numSDattrs"] = config["nspacedims"] + nattrs config["ntime"] = round(config["T_END"]/config["OBSTSTEP"])+1 @@ -44,11 +53,35 @@ def config_dict(setuptxt, nattrs, isprint): return config -def consts_dict(setuptxt, isprint): - consts = cxx2py.read_cxxconsts_into_floats(setuptxt) - consts.update(cxx2py.derive_more_floats(consts)) +def read_configparams_fromsetuptxt_into_floats(filename): + """returns dictionary of value: float from + values assigned in a config .txt file. + Also returns dictionary of notfloats + for values that couldn't be converted. """ - if isprint: - cxx2py.print_dict_statement(setuptxt, "consts", consts) + floats = {} + notfloats = {} + with open(filename) as file: + rlines=[] + filelines = file.readlines() + for line in filelines: + if ((line[0] != "#") and (line[0] != "/") and (":" in line)): + goodline = cxx2py.remove_excess_line(line) + rlines.append(goodline) - return consts + for line in rlines: + ind = line.find(":") + name = line[:ind] + value = line[ind+1:] + + try: + floats[name] = float(value) + except ValueError: + notfloats[name] = value + + try: + floats["nspacedims"] = int(floats["nspacedims"]) # no spatial coords to SDs + except: + pass + + return floats diff --git a/pySD/thermobinary_src/create_thermodynamics.py b/pySD/thermobinary_src/create_thermodynamics.py index 938505b87..0f1245284 100644 --- a/pySD/thermobinary_src/create_thermodynamics.py +++ b/pySD/thermobinary_src/create_thermodynamics.py @@ -6,7 +6,7 @@ Author: Clara Bayley (CB) Additional Contributors: ----- -Last Modified: Monday 30th October 2023 +Last Modified: Wednesday 17th April 2024 Modified By: CB ----- License: BSD 3-Clause "New" or "Revised" License @@ -20,7 +20,7 @@ import numpy as np from os.path import isfile -from .. import cxx2py, writebinary +from .. import cxx2py, readconfigfile, writebinary from ..gbxboundariesbinary_src.read_gbxboundaries import read_dimless_gbxboundaries_binary def thermoinputsdict(configfile, constsfile): @@ -30,7 +30,7 @@ def thermoinputsdict(configfile, constsfile): consts = cxx2py.read_cxxconsts_into_floats(constsfile) mconsts = cxx2py.derive_more_floats(consts) - config = cxx2py.read_configparams_into_floats(configfile) + config = readconfigfile.read_configparams_into_floats(configfile) inputs = { # for creating thermodynamic profiles diff --git a/requirements.txt b/requirements.txt index 5f50c9b35..d9ec4e1f1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,3 +12,4 @@ awkward zarr pre-commit mpi4py +ruamel.yaml diff --git a/roughpaper/main.cpp b/roughpaper/main.cpp index 7e1356a80..3e22bd3d4 100644 --- a/roughpaper/main.cpp +++ b/roughpaper/main.cpp @@ -9,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Tuesday 16th April 2024 + * Last Modified: Wednesday 17th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -59,8 +59,8 @@ template inline Observer auto create_superdrops_observer(const Config &config, const Timesteps &tsteps, Dataset &dataset) { - const auto obsstep = (unsigned int)tsteps.get_obsstep(); - const auto maxchunk = int{config.maxchunk}; + const auto obsstep = tsteps.get_obsstep(); + const auto maxchunk = config.get_maxchunk(); CollectDataForDataset auto sdid = CollectSdId(dataset, maxchunk); CollectDataForDataset auto sdgbxindex = CollectSdgbxindex(dataset, maxchunk); @@ -79,37 +79,39 @@ inline Observer auto create_superdrops_observer(const Config &config, const Time template inline Observer auto create_gridbox_observer(const Config &config, const Timesteps &tsteps, Dataset &dataset) { - const auto obsstep = (unsigned int)tsteps.get_obsstep(); - const auto maxchunk = int{config.maxchunk}; + const auto obsstep = tsteps.get_obsstep(); + const auto maxchunk = config.get_maxchunk(); + const auto ngbxs = config.get_ngbxs(); - const CollectDataForDataset auto thermo = CollectThermo(dataset, maxchunk, config.ngbxs); - const CollectDataForDataset auto windvel = CollectWindVel(dataset, maxchunk, config.ngbxs); - const CollectDataForDataset auto nsupers = CollectNsupers(dataset, maxchunk, config.ngbxs); + const CollectDataForDataset auto thermo = CollectThermo(dataset, maxchunk, ngbxs); + const CollectDataForDataset auto windvel = CollectWindVel(dataset, maxchunk, ngbxs); + const CollectDataForDataset auto nsupers = CollectNsupers(dataset, maxchunk, ngbxs); const CollectDataForDataset auto collect_data = nsupers >> windvel >> thermo; return WriteToDatasetObserver(obsstep, dataset, collect_data); - // const Observer auto obst = ThermoObserver(obsstep, dataset, maxchunk, config.ngbxs); - // const Observer auto obsw = WindVelObserver(obsstep, dataset, maxchunk, config.ngbxs); + // const Observer auto obst = ThermoObserver(obsstep, dataset, maxchunk, ngbxs); + // const Observer auto obsw = WindVelObserver(obsstep, dataset, maxchunk, ngbxs); // return obsw >> obst; - // const Observer auto obsx = StateObserver(obsstep, dataset, maxchunk, config.ngbxs); + // const Observer auto obsx = StateObserver(obsstep, dataset, maxchunk, ngbxs); // return obsx; - // const Observer auto obsn = NsupersObserver(obsstep, dataset, maxchunk, config.ngbxs); + // const Observer auto obsn = NsupersObserver(obsstep, dataset, maxchunk, ngbxs); // return obsn; } template inline Observer auto create_observer2(const Config &config, const Timesteps &tsteps, Dataset &dataset) { - const auto obsstep = (unsigned int)tsteps.get_obsstep(); - const auto maxchunk = int{config.maxchunk}; + const auto obsstep = tsteps.get_obsstep(); + const auto maxchunk = config.get_maxchunk(); + const auto ngbxs = config.get_ngbxs(); - const Observer auto obs0 = RunStatsObserver(obsstep, config.stats_filename); + const Observer auto obs0 = RunStatsObserver(obsstep, config.get_stats_filename()); const Observer auto obs1 = TimeObserver(obsstep, dataset, maxchunk, &step2dimlesstime); - const Observer auto obs2 = GbxindexObserver(dataset, maxchunk, config.ngbxs); - const Observer auto obs3 = MassMomentsObserver(obsstep, dataset, maxchunk, config.ngbxs); - const Observer auto obs4 = MassMomentsRaindropsObserver(obsstep, dataset, maxchunk, config.ngbxs); + const Observer auto obs2 = GbxindexObserver(dataset, maxchunk, ngbxs); + const Observer auto obs3 = MassMomentsObserver(obsstep, dataset, maxchunk, ngbxs); + const Observer auto obs4 = MassMomentsRaindropsObserver(obsstep, dataset, maxchunk, ngbxs); const Observer auto obs6 = TotNsupersObserver(obsstep, dataset, maxchunk); const Observer auto obsx = create_gridbox_observer(config, tsteps, dataset); const Observer auto obssd = create_superdrops_observer(config, tsteps, dataset); @@ -123,7 +125,7 @@ inline Observer auto create_observer2(const Config &config, const Timesteps &tst template inline Observer auto create_observer(const Config &config, const Timesteps &tsteps, Dataset &dataset) { - const auto obsstep = (unsigned int)tsteps.get_obsstep(); + const auto obsstep = tsteps.get_obsstep(); const Observer auto obs0 = StreamOutObserver(obsstep, &step2realtime); @@ -140,8 +142,8 @@ inline auto create_movement(const CartesianMaps &gbxmaps) { } inline InitialConditions auto create_initconds(const Config &config) { - const InitSupersFromBinary initsupers(config); - const InitGbxsNull initgbxs(config); + const InitSupersFromBinary initsupers(config.get_initsupersfrombinary()); + const InitGbxsNull initgbxs(config.get_ngbxs()); return InitConds(initsupers, initgbxs); } @@ -154,14 +156,14 @@ inline CoupledDynamics auto create_coupldyn(const Config &config, const Cartesia const auto nsteps = (unsigned int)(std::ceil(t_end / couplstep) + 1); - return FromFileDynamics(config, couplstep, ndims, nsteps); + return FromFileDynamics(config.get_fromfiledynamics(), couplstep, ndims, nsteps); } template inline auto create_sdm(const Config &config, const Timesteps &tsteps, Dataset &dataset) { const auto couplstep = (unsigned int)tsteps.get_couplstep(); - const GridboxMaps auto gbxmaps = - create_cartesian_maps(config.ngbxs, config.nspacedims, config.grid_filename); + const GridboxMaps auto gbxmaps = create_cartesian_maps( + config.get_ngbxs(), config.get_nspacedims(), config.get_grid_filename()); const MicrophysicalProcess auto microphys = NullMicrophysicalProcess{}; const MoveSupersInDomain movesupers(create_movement(gbxmaps)); const Observer auto obs = create_observer(config, tsteps, dataset); @@ -172,11 +174,11 @@ int main(int argc, char *argv[]) { Kokkos::Timer kokkostimer; /* Read input parameters from configuration file(s) */ - const Config config("/home/m/m300950/CLEO/roughpaper/share/config.txt"); - const Timesteps tsteps(config); // timesteps for model (e.g. coupling and end time) + const Config config("/home/m/m300950/CLEO/roughpaper/share/config.yaml"); + const Timesteps tsteps(config.get_timesteps()); /* Create zarr store for writing output to storage */ - auto store = FSStore(config.zarrbasedir); + auto store = FSStore(config.get_zarrbasedir()); auto dataset = Dataset(store); /* Initial conditions for CLEO run */ diff --git a/scripts/compile_run_cleocoupledsdm.sh b/scripts/compile_run_cleocoupledsdm.sh index b06015d28..5580d0b15 100755 --- a/scripts/compile_run_cleocoupledsdm.sh +++ b/scripts/compile_run_cleocoupledsdm.sh @@ -25,7 +25,7 @@ buildtype=$1 path2CLEO=${HOME}/CLEO/ path2build=$2 # get from command line argument executable="cleocoupledsdm" -configfile=${HOME}/CLEO/src/config/config.txt +configfile=${HOME}/CLEO/src/config/config.yaml run_executable=${path2build}/src/${executable} if [ "${path2build}" == "" ] diff --git a/scripts/create_gbxboundariesbinary_script.py b/scripts/create_gbxboundariesbinary_script.py index d5ea016bc..c5572fd78 100644 --- a/scripts/create_gbxboundariesbinary_script.py +++ b/scripts/create_gbxboundariesbinary_script.py @@ -6,7 +6,7 @@ Author: Clara Bayley (CB) Additional Contributors: ----- -Last Modified: Monday 15th April 2024 +Last Modified: Wednesday 17th April 2024 Modified By: CB ----- License: BSD 3-Clause "New" or "Revised" License @@ -41,7 +41,7 @@ binariespath = path2build+"/share/" savefigpath = path2build+"/bin/" -gridfile = binariespath+"/dimlessGBxboundaries.dat" # note this should match config.txt +gridfile = binariespath+"/dimlessGBxboundaries.dat" # note this should match config.yaml ### input parameters for zcoords of gridbox boundaries zmax = 820 # maximum z coord [m] diff --git a/scripts/create_initsuperdropsbinary_script.py b/scripts/create_initsuperdropsbinary_script.py index 74ab35159..d63033a44 100644 --- a/scripts/create_initsuperdropsbinary_script.py +++ b/scripts/create_initsuperdropsbinary_script.py @@ -6,7 +6,7 @@ Author: Clara Bayley (CB) Additional Contributors: ----- -Last Modified: Monday 15th April 2024 +Last Modified: Wednesday 17th April 2024 Modified By: CB ----- License: BSD 3-Clause "New" or "Revised" License @@ -45,8 +45,8 @@ binariespath = path2build+"/share/" savefigpath = path2build+"/bin/" -gridfile = binariespath+"/dimlessGBxboundaries.dat" # note this should match config.txt -initsupersfile = binariespath+"/dimlessSDsinit.dat" # note this should match config.txt +gridfile = binariespath+"/dimlessGBxboundaries.dat" # note this should match config.yaml +initsupersfile = binariespath+"/dimlessSDsinit.dat" # note this should match config.yaml ### --- Number of Superdroplets per Gridbox --- ### ### --- (an int or dict of ints) --- ### diff --git a/scripts/create_thermobinaries_script.py b/scripts/create_thermobinaries_script.py index 6661cebf9..d4acb1666 100644 --- a/scripts/create_thermobinaries_script.py +++ b/scripts/create_thermobinaries_script.py @@ -6,7 +6,7 @@ Author: Clara Bayley (CB) Additional Contributors: ----- -Last Modified: Monday 15th April 2024 +Last Modified: Wednesday 17th April 2024 Modified By: CB ----- License: BSD 3-Clause "New" or "Revised" License @@ -45,7 +45,7 @@ binariespath = path2build+"/share/" savefigpath = path2build+"/bin/" -gridfile = binariespath+"/dimlessGBxboundaries.dat" # note this should match config.txt +gridfile = binariespath+"/dimlessGBxboundaries.dat" # note this should match config.yaml thermofile = binariespath+"/dimlessthermo.dat" ### --- Choose Initial Thermodynamic Conditions for Gridboxes --- ### diff --git a/src/config/config.txt b/src/config/config.txt deleted file mode 100644 index 3d34422e4..000000000 --- a/src/config/config.txt +++ /dev/null @@ -1,73 +0,0 @@ -/* - * ----- CLEO ----- - * File: config.txt - * Project: config - * Created Date: Friday 13th October 2023 - * Author: Clara Bayley (CB) - * Additional Contributors: - * ----- - * Last Modified: Monday 15th April 2024 - * Modified By: CB - * ----- - * License: BSD 3-Clause "New" or "Revised" License - * https://opensource.org/licenses/BSD-3-Clause - * ----- - * Copyright (c) 2023 MPI-M, Clara Bayley - * ----- - * File Description: - * configuration input parameters for CLEO - * Note: inital superdroplets data (xi, r0 and msol etc.) - * read from file "initsupers_filename" is made with PYSD module - * using python script "create_initsuperdropsbinary_script". - * Likewise data to make gridboxmap from gridbox boundaries is - * read from file "grid_filename" created using python - * "create_gbxboundariesbinary_script" script. - */ - - -### Initialisation parameters ### -constants_filename = ../libs/cleoconstants.hpp # name of file for values of physical constants -initsupers_filename = ./share/dimlessSDsinit.dat # binary filename for initialisation of SDs -grid_filename = ./share/dimlessGBxboundaries.dat # binary filename for initialisation of GBxs / GbxMaps - -### Output Data parameters ### -setuptxt = ./bin/setup.txt # .txt filename to copy configuration to -stats_filename = ./bin/stats.txt # .txt file to output runtime statistics to -zarrbasedir = ./bin/SDMdata.zarr # zarr store base directory -maxchunk = 1250000 # maximum no. of elements in chunks of zarr store array - -### SDM Runtime parameters ### -# domain setup # -nspacedims = 1 # no. of spatial dimensions to model -ngbxs = 41 # total number of Gbxs -totnsupers = 2048 # (initial) total no. of SDs - -# timestepping # -CONDTSTEP = 0.1 # time between SD condensation events [s] -COLLTSTEP = 1 # time between SD collision events [s] -MOTIONTSTEP = 2 # time between SDM motion [s] -COUPLTSTEP = 120 # time between dynamic couplings [s] -OBSTSTEP = 2 # time between SDM observations [s] -T_END = 120 # time span of integration from 0s to T_END [s] - -# microphysics # -cond_iters = 2 # no. iterations of Newton Raphson Method before testing for convergence -cond_SUBTSTEP = 0.1 # smallest timestep in cases where substepping occurs [s] -cond_rtol = 0.0 # relative tolerance for implicit euler integration -cond_atol = 0.01 # abolute tolerance for implicit euler integration - -# superdroplets # -doAlterThermo = false # enable condensation to alter the thermodynamic state - -### Coupled Dynamics Solver Parameters ### -# type of coupling # -thermosolver = fromfile # dynamics solver to configure - -### read in dynamics from file ### -press_filename = ./share/dimlessthermo_press.dat # binary filename for pressure -temp_filename = ./share/dimlessthermo_temp.dat # binary filename for temperature -qvap_filename = ./share/dimlessthermo_qvap.dat # binary filename for vapour mixing ratio -qcond_filename = ./share/dimlessthermo_qcond.dat # binary filename for liquid mixing ratio -wvel_filename = ./share/dimlessthermo_wvel.dat # binary filename for vertical (coord3) velocity -uvel_filename = ./share/dimlessthermo_uvel.dat # binary filename for eastwards (coord1) velocity -vvel_filename = ./share/dimlessthermo_vvel.dat # binary filename for northwards (coord2) velocity diff --git a/src/config/config.yaml b/src/config/config.yaml new file mode 100644 index 000000000..36dc3e4e0 --- /dev/null +++ b/src/config/config.yaml @@ -0,0 +1,73 @@ +--- +# ----- CLEO ----- +# File: config.yaml +# Project: config +# Created Date: Wednesday 17th April 2024 +# Author: Clara Bayley (CB) +# Additional Contributors: +# ----- +# Last Modified: Wednesday 17th April 2024 +# Modified By: CB +# ----- +# License: BSD 3-Clause "New" or "Revised" License +# https://opensource.org/licenses/BSD-3-Clause +# ----- +# Copyright (c) 2023 MPI-M, Clara Bayley +# ----- +# File Description: +# Configuration file for CLEO SDM coupled to a dynamics solver. +# Note: The inital superdroplets data read from file "initsupers_filename" can be made with +# CLEO's pySD module (see Python script "create_initsuperdropsbinary_script.py" for usage). +# Likewise the "grid_filename" can be made using pySD (see "create_gbxboundariesbinary_script.py"), +# and so can the thermodynamics files when using coupled thermodynamics "fromfile". +# + +### Initialisation Parameters ### +inputfiles: + constants_filename : ../libs/cleoconstants.hpp # name of file for values of physical constants + grid_filename : ./share/dimlessGBxboundaries.dat # binary filename for initialisation of GBxs / GbxMaps + +initsupers: + type : frombinary # type of initialisation of super-droplets + initsupers_filename : ./share/dimlessSDsinit.dat # binary filename for initialisation of SDs + totnsupers : 2048 # initial total no. of SDs + +### Output Parameters ### +outputdata: + setup_filename : ./bin/setup.txt # .txt filename to copy configuration to + stats_filename : ./bin/stats.txt # .txt file to output runtime statistics to + zarrbasedir : ./bin/SDMdata.zarr # zarr store base directory + maxchunk : 2500000 # maximum no. of elements in chunks of zarr store array + +### SDM Runtime Parameters ### +domain: + nspacedims : 1 # no. of spatial dimensions to model + ngbxs : 41 # total number of Gbxs + +timesteps: + CONDTSTEP : 0.1 # time between SD condensation [s] + COLLTSTEP : 1 # time between SD collision [s] + MOTIONTSTEP : 2 # time between SDM motion [s] + COUPLTSTEP : 120 # time between dynamic couplings [s] + OBSTSTEP : 2 # time between SDM observations [s] + T_END : 120 # time span of integration from 0s to T_END [s] + +### Microphysics Parameters ### +microphysics: + condensation: + do_alter_thermo : false # true = cond/evap alters the thermodynamic state + niters : 2 # no. iterations of Newton Raphson Method before testing for convergence + SUBTSTEP : 0.1 # smallest subtimestep in cases of substepping [s] + rtol : 0.0 # relative tolerance for implicit Euler integration + atol : 0.01 # abolute tolerance for implicit Euler integration + +### Coupled Dynamics Parameters ### +coupled_dynamics: + type : fromfile # type of coupled dynamics to configure + press : ./share/dimlessthermo_press.dat # binary filename for pressure + temp : ./share/dimlessthermo_temp.dat # binary filename for temperature + qvap : ./share/dimlessthermo_qvap.dat # binary filename for vapour mixing ratio + qcond : ./share/dimlessthermo_qcond.dat # binary filename for liquid mixing ratio + wvel : ./share/dimlessthermo_wvel.dat # binary filename for vertical (coord3) velocity + uvel : ./share/dimlessthermo_uvel.dat # binary filename for eastwards (coord1) velocity + vvel : ./share/dimlessthermo_vvel.dat # binary filename for northwards (coord2) velocity diff --git a/src/main.cpp b/src/main.cpp index e6d96e5be..bfb53a254 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Tuesday 16th April 2024 + * Last Modified: Wednesday 17th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -18,7 +18,7 @@ * File Description: * runs the CLEO super-droplet model (SDM) * after make/compiling, execute for example via: - * ./src/cleocoupledsdm ../src/config/config.txt + * ./src/cleocoupledsdm ../src/config/config.yaml */ #include "./main_impl.hpp" @@ -31,12 +31,12 @@ int main(int argc, char *argv[]) { Kokkos::Timer kokkostimer; /* Read input parameters from configuration file(s) */ - const std::string_view config_filename(argv[1]); // path to configuration file + const std::filesystem::path config_filename(argv[1]); // path to configuration file const Config config(config_filename); - const Timesteps tsteps(config); // timesteps for model (e.g. coupling and end time) + const Timesteps tsteps(config.get_timesteps()); /* Create Xarray dataset wit Zarr backend for writing output data to a store */ - auto store = FSStore(config.zarrbasedir); + auto store = FSStore(config.get_zarrbasedir()); auto dataset = Dataset(store); /* Initial conditions for CLEO run */ diff --git a/src/main_impl.hpp b/src/main_impl.hpp index 7ea2cb3a6..ea83cdff1 100644 --- a/src/main_impl.hpp +++ b/src/main_impl.hpp @@ -9,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Tuesday 16th April 2024 + * Last Modified: Wednesday 17th April 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -80,18 +81,19 @@ inline CoupledDynamics auto create_coupldyn(const Config &config, const Cartesia const auto nsteps = (unsigned int)(std::ceil(t_end / couplstep) + 1); - return FromFileDynamics(config, couplstep, ndims, nsteps); + return FromFileDynamics(config.get_fromfiledynamics(), couplstep, ndims, nsteps); } inline InitialConditions auto create_initconds(const Config &config) { - const InitSupersFromBinary initsupers(config); - const InitGbxsNull initgbxs(config); + const InitSupersFromBinary initsupers(config.get_initsupersfrombinary()); + const InitGbxsNull initgbxs(config.get_ngbxs()); return InitConds(initsupers, initgbxs); } inline GridboxMaps auto create_gbxmaps(const Config &config) { - const auto gbxmaps = create_cartesian_maps(config.ngbxs, config.nspacedims, config.grid_filename); + const auto gbxmaps = create_cartesian_maps(config.get_ngbxs(), config.get_nspacedims(), + config.get_grid_filename()); return gbxmaps; } @@ -130,9 +132,10 @@ inline auto create_movement(const Config &config, const Timesteps &tsteps, const inline MicrophysicalProcess auto config_condensation(const Config &config, const Timesteps &tsteps) { - return Condensation(tsteps.get_condstep(), config.doAlterThermo, config.cond_iters, - &step2dimlesstime, config.cond_rtol, config.cond_atol, config.cond_SUBTSTEP, - &realtime2dimless); + const auto c = config.get_condensation(); + + return Condensation(tsteps.get_condstep(), &step2dimlesstime, c.do_alter_thermo, c.niters, c.rtol, + c.atol, c.SUBTSTEP, &realtime2dimless); } inline MicrophysicalProcess auto config_collisions(const Config &config, const Timesteps &tsteps) { @@ -177,7 +180,7 @@ inline MicrophysicalProcess auto create_microphysics(const Config &config, template inline Observer auto create_superdrops_observer(const unsigned int interval, - Dataset &dataset, const int maxchunk) { + Dataset &dataset, const size_t maxchunk) { CollectDataForDataset auto sdid = CollectSdId(dataset, maxchunk); CollectDataForDataset auto sdgbxindex = CollectSdgbxindex(dataset, maxchunk); CollectDataForDataset auto xi = CollectXi(dataset, maxchunk); @@ -193,7 +196,7 @@ inline Observer auto create_superdrops_observer(const unsigned int interval, template inline Observer auto create_gridboxes_observer(const unsigned int interval, Dataset &dataset, - const int maxchunk, const size_t ngbxs) { + const size_t maxchunk, const size_t ngbxs) { const CollectDataForDataset auto thermo = CollectThermo(dataset, maxchunk, ngbxs); const CollectDataForDataset auto windvel = CollectWindVel(dataset, maxchunk, ngbxs); const CollectDataForDataset auto nsupers = CollectNsupers(dataset, maxchunk, ngbxs); @@ -205,24 +208,25 @@ inline Observer auto create_gridboxes_observer(const unsigned int interval, Data template inline Observer auto create_observer(const Config &config, const Timesteps &tsteps, Dataset &dataset) { - const auto obsstep = (unsigned int)tsteps.get_obsstep(); - const auto maxchunk = int{config.maxchunk}; + const auto obsstep = tsteps.get_obsstep(); + const auto maxchunk = config.get_maxchunk(); + const auto ngbxs = config.get_ngbxs(); - const Observer auto obs0 = RunStatsObserver(obsstep, config.stats_filename); + const Observer auto obs0 = RunStatsObserver(obsstep, config.get_stats_filename()); const Observer auto obs1 = StreamOutObserver(obsstep * 10, &step2realtime); const Observer auto obs2 = TimeObserver(obsstep, dataset, maxchunk, &step2dimlesstime); - const Observer auto obs3 = GbxindexObserver(dataset, maxchunk, config.ngbxs); + const Observer auto obs3 = GbxindexObserver(dataset, maxchunk, ngbxs); const Observer auto obs4 = TotNsupersObserver(obsstep, dataset, maxchunk); - const Observer auto obs5 = MassMomentsObserver(obsstep, dataset, maxchunk, config.ngbxs); + const Observer auto obs5 = MassMomentsObserver(obsstep, dataset, maxchunk, ngbxs); - const Observer auto obs6 = MassMomentsRaindropsObserver(obsstep, dataset, maxchunk, config.ngbxs); + const Observer auto obs6 = MassMomentsRaindropsObserver(obsstep, dataset, maxchunk, ngbxs); - const Observer auto obsgbx = create_gridboxes_observer(obsstep, dataset, maxchunk, config.ngbxs); + const Observer auto obsgbx = create_gridboxes_observer(obsstep, dataset, maxchunk, ngbxs); const Observer auto obssd = create_superdrops_observer(obsstep, dataset, maxchunk);