Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
bd42536
Base submodule interface class added
djmallum Mar 19, 2025
a799caa
Adding classes for a soil module divided into parts:
djmallum Mar 19, 2025
e409132
Adding soil module
djmallum Mar 19, 2025
0ab0ecd
Adjusted ET names to be more accurate
djmallum Mar 19, 2025
cbb5cdb
Added .swp files to .gitignore
djmallum Mar 19, 2025
5b968ce
Added an infiltration module and a soil data table
djmallum Mar 19, 2025
4f65b1d
gitignore now includes .swo files
djmallum Mar 19, 2025
878d56c
Adding ET baseclass evapbase
djmallum Mar 19, 2025
f6cbd20
Extra lines removed from gitignore
djmallum Mar 19, 2025
221717b
/CMakeLists.txt editted to work with local spack
djmallum Mar 19, 2025
4cc02e6
Added soil attribute functions to triangulation
djmallum Mar 19, 2025
bb25015
Changing name of ET variables in soil_module
djmallum Mar 19, 2025
a2bd539
Added air heat capacity, and velocity profile constant kappa to Atmos…
djmallum Mar 19, 2025
807a80a
Adding an ET module and submodules
djmallum Mar 19, 2025
53b8348
Added new (sub)modules to CMakeLists
djmallum Mar 19, 2025
11fe9e2
Added soil_storage as dependency for Green-Ampt
djmallum Mar 20, 2025
b642a24
Encapsulating components of Infil_All
djmallum Apr 4, 2025
a3289ad
Changes to Soil::soils_na class
djmallum Apr 4, 2025
9681c57
Google tests for infiltration submodules
djmallum Apr 4, 2025
8cc159e
CMakeLists updated
djmallum Apr 4, 2025
e08e02e
Infil_All: ensured SoilDataObj remains const
djmallum Apr 8, 2025
4b36fcc
Uncommented main.cpp for tests
djmallum Apr 22, 2025
9546acf
Added CSV reader class to aid with google tests
djmallum Apr 22, 2025
274fa9b
Fixed logger comment warning
djmallum Apr 22, 2025
67596dd
Infil_All: Updating after unit tests
djmallum Apr 22, 2025
3a57bdc
K_Estimate: Interface from submodule_base, updating internal functino…
djmallum Apr 22, 2025
d2e4a9f
soil_two_layer calculations encapsulated
djmallum Jul 7, 2025
1cf0bcf
Changes to crack to enable unit tests only
djmallum Mar 27, 2025
d48112c
soil_two_layer simplified with new soil_classes
djmallum Jul 7, 2025
e7d98d1
Added const specifier to soil object getter
djmallum Apr 24, 2025
fb5c066
Outputted `runoff_to_depression`
djmallum Jul 7, 2025
3ab5ca3
Infil_All: Re-adding removed is_new_day function
djmallum Apr 24, 2025
14a007a
Added runoff_to_depression to two_layer_DTO
djmallum Jul 7, 2025
db10bc0
Google Tests: Ayers now expects const soil object
djmallum Apr 24, 2025
13a54c1
Introducing interface for freeze/thaw depths
djmallum Jul 7, 2025
c63283e
Added descriptive comment to allow_runoff_from_infiltration
djmallum Jul 7, 2025
7ac14c6
Googletest of the accumulator class
djmallum Jul 4, 2025
8488937
GoogleTests Crack rain_on_snow calculation fix
djmallum Apr 24, 2025
1447843
Adding XG_algorithm class
djmallum Jul 7, 2025
e4b169f
Adding get_new_day to two_layer_DTO
djmallum Jul 7, 2025
6149db0
Utility class daily_accumulator added
djmallum Jul 4, 2025
58c662d
New submodule base_class: base_step
djmallum Jun 25, 2025
fd8036e
Updated googletest to commit 571930618fa96eabcd05b573285edbee9fc13bae
djmallum Jun 25, 2025
bf13a14
Adding set up functions for XG algorithm to soil_module
djmallum Jul 7, 2025
ec260b3
Updated K_estimate and soil_DTO with new get_dt()
djmallum Jul 7, 2025
f09debf
Including isostream into base_step
djmallum Jul 4, 2025
410cc64
New base class base_step for submodules.
djmallum Jun 25, 2025
1e67a83
Modifying soil_module run to use XG
djmallum Jul 7, 2025
5e53ac3
Default values of cfg.get changes to match expected type
djmallum Jul 7, 2025
ad82a60
Changes to is_lake, get_dt and get_new_day functions
djmallum Jul 7, 2025
4e6be3a
Merge branch 'utility/daily_accumulator' into develop
djmallum Jul 4, 2025
9c9c959
Updated depends/provides
djmallum Jul 7, 2025
3e8e768
f4 now correctly divided by the minimum stomatal resistance
djmallum Jul 7, 2025
0054404
Merge branch 'refactor/soil_module' into develop
djmallum Jul 7, 2025
683d4a9
Added missing .cpp to CMakeLists
djmallum Jul 7, 2025
266b13c
Merge branch 'bug-fix/ET_module' into develop
djmallum Jul 7, 2025
0309fa6
XG google test added
djmallum Jul 7, 2025
bc41309
Fixed typo in Infil_All comment
djmallum Jul 7, 2025
a4dff9a
Merge branch 'new_submodule/XG_algorithm' into develop
djmallum Jul 7, 2025
e9fb8d7
Removed hard-coded porosity from soil_module
djmallum Jul 7, 2025
5586667
Removed crhm test components of XG
djmallum Jul 8, 2025
788febb
including concepts in base_step
djmallum Jul 8, 2025
76c0be4
Updated is_lake from function to variable in Soil_ET
djmallum Jul 16, 2025
7e6b5f3
Removing .hpps from CMakeLists.txt
djmallum Jul 16, 2025
9179c9b
Merge remote-tracking branch 'upstream/develop' into develop
djmallum Jul 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ third_party/snowpack/plugins/SnowpackIO.cc
*.bak
CRHMr.log
.Rhistory
**/*.swp
**/*.swo

/.idea/
/.spack-env/
Expand All @@ -27,4 +29,4 @@ CRHMr.log
/docs/api/*
/docs/_build/*
/docs/doxygen/*
/docs/_ext/__pycache__
/docs/_ext/__pycache__
6 changes: 3 additions & 3 deletions CMakeLists.txt
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change can probably be rejected and is specific to the build on my mac

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required (VERSION 3.30)
cmake_minimum_required (VERSION 3.27)
project (CHM-project C CXX Fortran)

# MACOSX_RPATH is enabled by default.
Expand All @@ -16,7 +16,7 @@ cmake_policy(SET CMP0144 NEW)

# The NEW behavior is for find_package(Boost) to search for the upstream BoostConfig.cmake
# https://cmake.org/cmake/help/latest/policy/CMP0167.html
cmake_policy(SET CMP0167 NEW)
#cmake_policy(SET CMP0167 NEW)

# Needed in addition to the target cxx standard set later
set(CMAKE_CXX_STANDARD 20)
Expand Down Expand Up @@ -337,4 +337,4 @@ add_subdirectory(src)

if(BUILD_DOCS)
add_subdirectory(docs)
endif()
endif()
60 changes: 44 additions & 16 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ set(MODULE_SRCS
modules/Marsh_shading_iswr.cpp
modules/Sicart_ilwr.cpp
modules/PenmanMonteith_evaporation.cpp
modules/Evapotranspiration_All.cpp
modules/interp_met/Thornton_p.cpp
modules/Walcek_cloud.cpp
modules/Harder_precip_phase.cpp
Expand All @@ -50,7 +51,9 @@ set(MODULE_SRCS
modules/Richard_albedo.cpp
modules/snowpack.cpp
modules/Gray_inf.cpp
modules/Simple_Canopy.cpp
modules/Infil_All.cpp
modules/soil_module.cpp
modules/Simple_Canopy.cpp
modules/scale_wind_vert.cpp
modules/sub_grid.cpp
modules/snow_slide.cpp
Expand All @@ -68,6 +71,21 @@ set(MODULE_SRCS

CACHE INTERNAL "" FORCE )

set(MODEL_SRCS
modules/EvapotranspirationModels/evapbase.cpp
modules/EvapotranspirationModels/PenmanMonteith.cpp
modules/EvapotranspirationModels/PriestleyTaylor.cpp

modules/soil_submodules/soil_two_layer.cpp
modules/soil_submodules/soil_ET.cpp
modules/soil_submodules/soil_classes.cpp

modules/soil_submodules/K_estimate.cpp

modules/soil_submodules/XG_algorithm.cpp

modules/infil_submodules/Crack.cpp
CACHE INTERNAL "" FORCE )

set(CHM_SRCS
#main.cpp needs to be added below so we can re use CHM_SRCS in the gtest build
Expand All @@ -77,6 +95,7 @@ set(CHM_SRCS
metdata.cpp

physics/Atmosphere.cpp
physics/Soil.cpp

mesh/triangulation.cpp
# mesh/ugrid.cpp
Expand Down Expand Up @@ -109,7 +128,10 @@ set (HEADER_FILES
modules/interp_met
modules/snobal
modules/testing
math
modules/EvapotranspirationModels/
modules/soil_submodules/
modules/infil_submodules/
math
libmaw
interpolation
timeseries
Expand Down Expand Up @@ -227,7 +249,8 @@ add_executable(
main.cpp # this needs to be here so we can reuse CHM_SRCS in the gtest build. but since it links it's own main, we cannot have this one.
${CHM_SRCS}
${FILTER_SRCS}
${MODULE_SRCS}
${MODEL_SRCS}
${MODULE_SRCS}
)


Expand Down Expand Up @@ -394,34 +417,39 @@ endif()

if (BUILD_TESTS)
message(STATUS "Tests enabled. Run with make check")
add_subdirectory (tests/googletest/googletest)
add_subdirectory (tests/googletest)

set(TEST_SRCS
tests/test_station.cpp
tests/test_interpolation.cpp
tests/test_timeseries.cpp
tests/test_core.cpp
tests/test_variablestorage.cpp
tests/test_metdata.cpp
tests/test_netcdf.cpp
#tests/test_station.cpp
#tests/test_interpolation.cpp
#tests/test_timeseries.cpp
#tests/test_core.cpp
#tests/test_variablestorage.cpp
#tests/test_metdata.cpp
#tests/test_netcdf.cpp
# test_mesh.cpp
tests/test_regexptokenizer.cpp
#tests/test_regexptokenizer.cpp
# test_daily.cpp
tests/test_triangulation.cpp
tests/main.cpp
)
#tests/test_triangulation.cpp
tests/main.cpp
tests/submoduletests/test_crack.cpp
tests/submoduletests/test_ayers.cpp
tests/submoduletests/test_CSVreader.cpp
tests/submoduletests/test_daily_accumulator.cpp
)


set( GTEST_LINK
gtest
gmock
)



add_executable(
runUnitTests
${CHM_SRCS}
${FILTER_SRCS}
${MODEL_SRCS}
${MODULE_SRCS}
${TEST_SRCS}
)
Expand Down
12 changes: 6 additions & 6 deletions src/logger.hpp
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was getting an odd build warning with this one, even commented, so I removed the . But obviously didn't need to...

Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
};

//#ifdef USE_MPI
//#define MPI_RANK_DBG(RANK) if(_comm_world.rank() == RANK) \
// {\
// LOG_DEBUG << "\n\n-----------------------------\n\nI am PID " << getpid() <<", attach within 45s\n\n-----------------------------\n\n"; \
// sleep(45);\
// }
//#endif
//#define MPI_RANK_DBG(RANK) if(_comm_world.rank() == RANK)
// {
// LOG_DEBUG << "\n\n-----------------------------\n\nI am PID " << getpid() <<", attach within 45s\n\n-----------------------------\n\n";
// sleep(45);
// t }
//#endif
81 changes: 81 additions & 0 deletions src/mesh/triangulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,32 @@ class face : public Fb
*/
double veg_attribute(const std::string &variable);

/**
* Checks if the face has soil by loading the soil_storage_max parameter
* and then checking if it is greater than zero.
*/
bool has_soil();

/**
* Retrieves a soil attribute for the face. With a templated return type to allow for
* double, int or std::string types. Distributed variables will only be double/int. But
* look-up tables can point to strings or another type.
* */
template <typename T>
T soil_attribute(const std::string variable);

/**
* This version of the function specifies that you need a look-up table.
* It is essentially identical to veg_attribute except it does not include the first if statement
* and it allows you to specify the look up map category name. For soils, it will always be soils.
* The obvious problem si that with veg_attribute you can keep a module unchanged and only change the
* config with or without a look-up. This version requires changing the module to stop using a look up.
* Consider changing in the future.
* This is only found in the one argument version of this function
* */
template <typename T>
T soil_attribute(const std::string variable,const std::string category);

/**
* Sets the vector for the given variable.
* Does not support timeseries output.
Expand Down Expand Up @@ -1737,6 +1763,61 @@ double face<Gt, Fb>::veg_attribute(const std::string &variable)
return result;
};

template < class Gt, class Fb >
bool face<Gt, Fb>::has_soil()
{
if (has_parameter("soil_storage_max"_s) )
{
double result = parameter("soil_storage_max"_s);
if (result >= 0.0)
return true;
}

return false;
}

template < class Gt, class Fb >
template< typename T >
T face<Gt, Fb>::soil_attribute(const std::string variable)
{

T result{};
// first see if we have a distributed map of this parameter
if(has_parameter(variable))
result = parameter(variable);
else
{
CHM_THROW_EXCEPTION(module_error, "Parameter " + variable +" does not exist.");
}
return result;
};

template < class Gt, class Fb >
template< typename T >
T face<Gt, Fb>::soil_attribute(const std::string variable,const std::string category)
{
T result{};
if (has_parameter(variable))
{
int LC = parameter(variable);
auto param = _domain->_global->parameters;
try
{
result = param.get<T>(category + "." + variable + "." + std::to_string(LC));
}
catch(const boost::property_tree::ptree_bad_path& e)
{
CHM_THROW_EXCEPTION(module_error, "Parameter " + variable + " in category " + category +" does not exist.");
}
}
else
{
CHM_THROW_EXCEPTION(module_error, "Parameter " + variable + " in category " + category +" does not exist.");
}
return result;
};


template < class Gt, class Fb>
Vector_3 face<Gt, Fb>::face_vector(const std::string& variable)
{
Expand Down
114 changes: 114 additions & 0 deletions src/modules/EvapotranspirationModels/PenmanMonteith.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#include "PenmanMonteith.hpp"


PenmanMonteith::PenmanMonteith(double& LAI, double& LAImax, double& veg_Ht, double& wind_height, double& stomatal_res_min, double& soil_d, double& F_to_g, const double Cp, const double K, const double tension, const double pore_sz, const double theta_pwp, const double phi)
: leaf_area_index(LAI), leaf_area_index_max(LAImax), Veg_height(veg_Ht), wind_measurement_height(wind_height), stomatal_resistance_min(stomatal_res_min), soil_depth(soil_d), Frac_to_ground(F_to_g), heat_capacity_air(Cp), kappa(K), air_entry_tension(tension), pore_size_dist(pore_sz), wilt_point(theta_pwp), porosity(phi)
{
if (leaf_area_index == 0)
has_vegetation = false;
else
has_vegetation = true;


// TODO other checks on values might be good
}

PenmanMonteith::~PenmanMonteith()
{
//Do nothing
}

void PenmanMonteith::CalcHeights()
{
Z0 = Veg_height/7.6;
d = Veg_height*0.67;
}

double PenmanMonteith::CalcAeroResistance(const PM_vars& var)
{
if (wind_measurement_height - d > 0)
{
return pow( log((wind_measurement_height - d)/Z0),2) /
(pow(kappa,2) * var.wind_speed);
}
else
{
return 0; // I don't know if this is right, but it is at least... safe.
}
}

double PenmanMonteith::CalcStomatalResistance(const PM_vars& var)
{
double rcstar = stomatal_resistance_min;

// In CRHM, the below calculation is an option, for now just use the minimum option.
if (has_vegetation)
{

double LAI = Veg_height/2.0*leaf_area_index_max; //TODO ad hoc for test
rcstar = stomatal_resistance_min * leaf_area_index_max / LAI;
// rcstar = stomatal_resistance_min * leaf_area_index_max / leaf_area_index; TODO commented for test
}
// TODO check units. for example, short_wave_in - 1.5 is suspect
double f1 = 1.0;
if (var.short_wave_in > 0.0)
f1 = std::max(1.0, 500.0/var.short_wave_in - 1.5);
//max <double> (1.0, 500.0/(var.short_wave_in - 1.5));

double f2 = std::max(1.0, 2.0 * (var.saturated_vapour_pressure - var.vapour_pressure) );
//<double> (1.0, 2.0 * (var.saturated_vapour_pressure - var.vapour_pressure) );

double p = air_entry_tension * pow(porosity / (var.soil_storage/soil_depth/1000.0 + wilt_point), pore_size_dist);
double f3 = std::max(1.0, p/40.0);

double f4 = 1.0;
if (var.t < 5.0 || var.t > 40.0)
f4 = 5000/stomatal_resistance_min;

if (var.short_wave_in <= 0)
return 5000;
else
{
return std::min(rcstar * f1 * f2 * f3 * f4, 5000.0);
}

}

void PenmanMonteith::CalcEvapT(var_base& basevar, model_output& output)
{

const PM_vars & var = static_cast<const PM_vars&>(basevar);
PM_output &out = static_cast<PM_output&>(output);

double Q = var.all_wave_net * (1 - Frac_to_ground);

if (IsFirstRun)
{
CalcHeights();
IsFirstRun = false;
}

double aero_resistance = CalcAeroResistance(var);
double stomatal_resistance = CalcStomatalResistance(var);

double radiation = delta(var.t) * Q * 24; //24 --> hours/day, should be generalized or encoded in Q in a future version
// Actual units are mm/day

double mass = AirDensity(var.t,var.vapour_pressure,var.P_atm) * heat_capacity_air *
(var.saturated_vapour_pressure - var.vapour_pressure)/ ( aero_resistance * lambda(var.t) * water_density );
mass *= m_per_s_to_mm_per_day;

out.ET = (radiation + mass) / ( delta(var.t) + gamma(var.P_atm, var.t, heat_capacity_air) * ( 1 + stomatal_resistance / aero_resistance ));

out.ET *= 1.0 / 24.0; // As with the radiation variable, assumed the timestep is hours here. TODO for the future.
out.stomatal_resistance = stomatal_resistance;
}

// TODO make delta, gamma, density fucntions

double PenmanMonteith::AirDensity(double& t, double& ea, double& Pa) // atmospheric density (kg/m^3)
{
const double R0 = 2870;
return (1E4*Pa /(R0*( 273.15 + t))*(1.0 - 0.379*(ea/Pa))); //
}

Loading