Skip to content

Commit

Permalink
use get_values interface for update calls when appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
hellkite500 committed Apr 4, 2022
1 parent 2070d96 commit f50a658
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions include/realizations/catchment/Bmi_Module_Formulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1071,16 +1071,25 @@ namespace realization {
// this type of behavior
// TODO: account for arrays later
int varItemSize = get_bmi_model()->GetVarItemsize(var_name);
if (varItemSize != get_bmi_model()->GetVarNbytes(var_name)) {
throw std::runtime_error(
"BMI input variable '" + var_name + "' is an array - not currently supported");
}
double value = provider->get_value(var_map_alias, model_epoch_time, t_delta,
get_bmi_model()->GetVarUnits(var_name));
std::shared_ptr<void> value_ptr;
// Finally, use the value obtained to set the model input
std::string type = get_bmi_model()->get_analogous_cxx_type(get_bmi_model()->GetVarType(var_name),
varItemSize);
std::shared_ptr<void> value_ptr = get_value_as_type(type, value);
if (varItemSize != get_bmi_model()->GetVarNbytes(var_name)) {
//more than a single value needed for var_name
auto values = provider->get_values(var_map_alias, model_epoch_time, t_delta,
get_bmi_model()->GetVarUnits(var_name));
//need to marshal data types to the reciever as well
//this could be done a little more elegantly if the provider interface were
//"type aware", but for now, this will do (but requires yet another copy)
value_ptr = get_values_as_type( type, values.begin(), values.end() );

} else {
//scalar value
double value = provider->get_value(var_map_alias, model_epoch_time, t_delta,
get_bmi_model()->GetVarUnits(var_name));
value_ptr = get_value_as_type(type, value);
}
get_bmi_model()->SetValue(var_name, value_ptr.get());
}
}
Expand Down

0 comments on commit f50a658

Please sign in to comment.