Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
1d784db
initial parameter set value
hellkite500 Sep 1, 2021
adad555
make bmi_config file work for framework run
hellkite500 Sep 1, 2021
459e74b
refactor parameter initialization into its own function
hellkite500 Feb 23, 2022
7e00ac1
don't allow setting params on null model
hellkite500 Feb 23, 2022
b4c8b32
Add a variant type for JSONProperty
hellkite500 Mar 3, 2022
e576423
Initialize PropertyVariant member
hellkite500 Mar 3, 2022
619edef
Define a visitor for filtering PropertyVariants into vectors
hellkite500 Mar 3, 2022
96df72c
Add function as_vector to JSONProperty
hellkite500 Mar 3, 2022
bfdc366
Add PropertyVisitor specialization to support as_vector numeric seman…
hellkite500 Mar 3, 2022
bcc59a3
Unit tests for JSONProperty::as_vector
hellkite500 Mar 3, 2022
a7b4cb5
Add helper function for converting iterator range to c-like array
hellkite500 Mar 3, 2022
47b51ad
Add helper function for getting range of values as type
hellkite500 Mar 3, 2022
9dbc646
Add type safety and list support to set_initial_bmi_parameters
hellkite500 Mar 3, 2022
ff84045
Add some test parameters to C bmi test model
hellkite500 Mar 3, 2022
aeb5581
Add param support to BMI c test lib
hellkite500 Mar 3, 2022
7c70e4d
Modify GetValue in BMI C test lib to set a list of parameter values
hellkite500 Mar 3, 2022
4f23396
Add model_params to BMI_C_Formulation test config
hellkite500 Mar 3, 2022
0e8cba3
Unit test validating parameter values set properly in C BMI lib
hellkite500 Mar 3, 2022
ea14565
TODO optimization comment
hellkite500 Mar 3, 2022
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
1 change: 1 addition & 0 deletions data/bmi/c/cfe/cat-27_bmi_config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ K_lf=0.01
K_nash=0.03
nash_storage=0.0,0.0
giuh_ordinates=0.06,0.51,0.28,0.12,0.03
num_timesteps=720
4 changes: 4 additions & 0 deletions extern/test_bmi_c/include/test_bmi_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ struct test_bmi_c_model {

double* output_var_1;
double* output_var_2;

int param_var_1;
double param_var_2;
double* param_var_3;
};
typedef struct test_bmi_c_model test_bmi_c_model;

Expand Down
71 changes: 67 additions & 4 deletions extern/test_bmi_c/src/bmi_test_bmi_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#define INPUT_VAR_NAME_COUNT 2
#define OUTPUT_VAR_NAME_COUNT 2

#define PARAM_VAR_NAME_COUNT 3

// Don't forget to update Get_value/Get_value_at_indices (and setter) implementation if these are adjusted
static const char *output_var_names[OUTPUT_VAR_NAME_COUNT] = { "OUTPUT_VAR_1", "OUTPUT_VAR_2" };
Expand All @@ -26,6 +26,13 @@ static const int input_var_item_count[INPUT_VAR_NAME_COUNT] = { 1, 1 };
static const char *input_var_grids[INPUT_VAR_NAME_COUNT] = { 0, 0 };
static const char *input_var_locations[INPUT_VAR_NAME_COUNT] = { "node", "node" };

// Don't forget to update Get_value/Get_value_at_indices (and setter) implementation if these are adjusted
static const char *param_var_names[PARAM_VAR_NAME_COUNT] = { "PARAM_VAR_1", "PARAM_VAR_2", "PARAM_VAR_3" };
static const char *param_var_types[PARAM_VAR_NAME_COUNT] = { "int", "double", "double" };
static const char *param_var_units[PARAM_VAR_NAME_COUNT] = { "m", "m/s", "m"};
static const int param_var_item_count[PARAM_VAR_NAME_COUNT] = { 1, 1, 2 };
static const char *param_var_grids[PARAM_VAR_NAME_COUNT] = { 0, 0, 0 };
static const char *param_var_locations[PARAM_VAR_NAME_COUNT] = { "node", "node", "node" };

static int Finalize (Bmi *self)
{
Expand All @@ -40,6 +47,8 @@ static int Finalize (Bmi *self)
free(model->output_var_1);
if( model->output_var_2 != NULL )
free(model->output_var_2);
if (model->param_var_3 != NULL )
free(model->param_var_3);
free(self->data);
}

Expand Down Expand Up @@ -272,9 +281,28 @@ static int Get_time_units (Bmi *self, char * units)

static int Get_value (Bmi *self, const char *name, void *dest)
{
// Since all the variables are scalar, use nested call to "by index" version, with just index 0
int inds[] = {0};
return self->get_value_at_indices(self, name, dest, inds, 1);
int i = 0;
int item_count = -1;
for (i = 0; i < PARAM_VAR_NAME_COUNT; i++) {
if (strcmp(name, param_var_names[i]) == 0) {
item_count = param_var_item_count[i];
break;
}
}

if( item_count < 1 ){
// Since all the variables are scalar, use nested call to "by index" version, with just index 0
int inds[] = {0};
return self->get_value_at_indices(self, name, dest, inds, 1);
}
else{
//All linear indicies
int inds[item_count];
for(i = 0; i < item_count; i++){
inds[i] = i;
}
return self->get_value_at_indices(self, name, dest, inds, item_count);
}
}


Expand Down Expand Up @@ -345,6 +373,20 @@ static int Get_value_ptr (Bmi *self, const char *name, void **dest)
return BMI_SUCCESS;
}

if (strcmp (name, "PARAM_VAR_1") == 0) {
*dest = &((test_bmi_c_model *)(self->data))->param_var_1;
return BMI_SUCCESS;
}

if (strcmp (name, "PARAM_VAR_2") == 0) {
*dest = &((test_bmi_c_model *)(self->data))->param_var_2;
return BMI_SUCCESS;
}

if (strcmp (name, "PARAM_VAR_3") == 0) {
*dest = ((test_bmi_c_model *)(self->data))->param_var_3;
return BMI_SUCCESS;
}
return BMI_FAILURE;
}

Expand Down Expand Up @@ -433,6 +475,14 @@ static int Get_var_nbytes (Bmi *self, const char *name, int * nbytes)
}
}
}
if (item_count < 1) {
for (i = 0; i < PARAM_VAR_NAME_COUNT; i++) {
if (strcmp(name, param_var_names[i]) == 0) {
item_count = param_var_item_count[i];
break;
}
}
}
if (item_count < 1)
item_count = ((test_bmi_c_model *) self->data)->num_time_steps;

Expand All @@ -458,6 +508,13 @@ static int Get_var_type (Bmi *self, const char *name, char * type)
return BMI_SUCCESS;
}
}
// Finally check to see if in param array
for (i = 0; i < PARAM_VAR_NAME_COUNT; i++) {
if (strcmp(name, param_var_names[i]) == 0) {
strncpy(type, param_var_types[i], BMI_MAX_TYPE_NAME);
return BMI_SUCCESS;
}
}
// If we get here, it means the variable name wasn't recognized
type[0] = '\0';
return BMI_FAILURE;
Expand Down Expand Up @@ -529,6 +586,12 @@ static int Initialize (Bmi *self, const char *file)
model->output_var_1 = malloc(sizeof(double));
model->output_var_2 = malloc(sizeof(double));

model->param_var_1 = 0;
model->param_var_2 = 0.0;
model->param_var_3 = malloc(2*sizeof(double));
model->param_var_3[0] = 0.0;
model->param_var_3[1] = 0.0;

return BMI_SUCCESS;
}

Expand Down
Loading