Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added_assertions #12

Merged
merged 2 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/soil_moisture_profile.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ namespace soil_moisture_profile {
void InitFromConfigFile(std::string config_file, struct soil_profile_parameters* parameters);

// reading 1D array from the config file
std::vector<double> ReadVectorData(std::string key);
std::vector<double> ReadVectorData(std::string param_name, std::string param_value);

// update the profile for the current timestep
void SoilMoistureProfileUpdate(struct soil_profile_parameters* parameters);
Expand Down
33 changes: 18 additions & 15 deletions src/soil_moisture_profile.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ InitFromConfigFile(string config_file, struct soil_profile_parameters* parameter
param_value = line.substr(loc_eq,loc_u - loc_eq);

if (param_key == "soil_z") {
vector<double> vec = ReadVectorData(param_value);
vector<double> vec = ReadVectorData(param_key, param_value);

parameters->soil_z = new double[vec.size()];

Expand All @@ -131,7 +131,7 @@ InitFromConfigFile(string config_file, struct soil_profile_parameters* parameter
parameters->soil_depth_layers_bmi = true;
}
else {
vector<double> vec = ReadVectorData(param_value);
vector<double> vec = ReadVectorData(param_key,param_value);
parameters->soil_depth_layers = new double[vec.size()];

for (unsigned int i=0; i < vec.size(); i++)
Expand All @@ -151,11 +151,13 @@ InitFromConfigFile(string config_file, struct soil_profile_parameters* parameter
parameters->smcmax_bmi = true;
}
else {
vector<double> vec = ReadVectorData(param_value);
vector<double> vec = ReadVectorData(param_key, param_value);
parameters->smcmax = new double[vec.size()];

for (unsigned int i=0; i < vec.size(); i++)
for (unsigned int i=0; i < vec.size(); i++) {
assert (vec[i] > 0);
parameters->smcmax[i] = vec[i];
}

parameters->smcmax_bmi = false;
parameters->num_layers = vec.size();
Expand All @@ -175,6 +177,7 @@ InitFromConfigFile(string config_file, struct soil_profile_parameters* parameter
// NOTE: `soil_params.satpsi` may be deprecated in the future in favor of `satpsi`
else if (param_key == "satpsi" || param_key == "soil_params.satpsi") {
parameters->satpsi = stod(param_value);
assert (parameters->satpsi > 0.0);
is_satpsi_set = true;
continue;
}
Expand Down Expand Up @@ -432,8 +435,8 @@ SoilMoistureProfileFromConceptualReservoir(struct soil_profile_parameters* param
double soil_storage_change_per_timestep_cm = fabs(parameters->soil_storage_change_per_timestep * 100.0);
double soil_storage_current_timestep_cm = 100.0 * parameters->soil_storage; // storage at the current timestep

assert(parameters->soil_storage >= 0.0); /* to ensure that soil storage is non-negative due to unexpected
bugs in cfe (or any other conceptual models) */
assert(parameters->soil_storage > 0.0); /* to ensure that soil storage is non-zero due to unexpected
bugs (either in the models or calibration tools) */

int count = 0;

Expand Down Expand Up @@ -912,38 +915,38 @@ Reads 1D data from the config file
*/

vector<double> soil_moisture_profile::
ReadVectorData(string key)
ReadVectorData(string param_name, string param_value)
{
int pos =0;
string delimiter = ",";
vector<double> value(0.0);
string z1 = key;
vector<double> values(0.0);
string z1 = param_value;

if (z1.find(delimiter) == string::npos) {
double v = stod(z1);
if (v == 0.0) {
if (v <= 0.0) {
stringstream errMsg;
errMsg << "soil_z (depth of soil reservior) should be greater than zero. It it set to "<< v << " in the config file "<< "\n";
errMsg << "Input provided in the config file for parameter "<< param_name << " is " << v << ". It should be positive."<< "\n";
throw runtime_error(errMsg.str());
}

value.push_back(v);
values.push_back(v);

}
else {
while (z1.find(delimiter) != string::npos) {
pos = z1.find(delimiter);
string z_v = z1.substr(0, pos);

value.push_back(stod(z_v.c_str()));
values.push_back(stod(z_v.c_str()));

z1.erase(0, pos + delimiter.length());
if (z1.find(delimiter) == string::npos)
value.push_back(stod(z1));
values.push_back(stod(z1));
}
}

return value;
return values;
}

void soil_moisture_profile::
Expand Down
Loading