99#define INPUT_VAR_NAME_COUNT 2
1010#define OUTPUT_VAR_NAME_COUNT 2
1111#define PARAM_VAR_NAME_COUNT 3
12+ #define MASS_BALANCE_VAR_NAME_COUNT 4
1213
1314// Don't forget to update Get_value/Get_value_at_indices (and setter) implementation if these are adjusted
1415static const char * output_var_names [OUTPUT_VAR_NAME_COUNT ] = { "OUTPUT_VAR_1" , "OUTPUT_VAR_2" };
@@ -34,6 +35,13 @@ static const int param_var_item_count[PARAM_VAR_NAME_COUNT] = { 1, 1, 2 };
3435static const char * param_var_grids [PARAM_VAR_NAME_COUNT ] = { 0 , 0 , 0 };
3536static const char * param_var_locations [PARAM_VAR_NAME_COUNT ] = { "node" , "node" , "node" };
3637
38+ static const char * mass_balance_var_names [MASS_BALANCE_VAR_NAME_COUNT ] = { NGEN_MASS_IN , NGEN_MASS_OUT , NGEN_MASS_STORED , NGEN_MASS_LEAKED };
39+ static const char * mass_balance_var_types [MASS_BALANCE_VAR_NAME_COUNT ] = { "double" , "double" , "double" , "double" };
40+ static const char * mass_balance_var_units [MASS_BALANCE_VAR_NAME_COUNT ] = { "m" , "m" , "m" , "m" };
41+ static const int mass_balance_var_item_count [MASS_BALANCE_VAR_NAME_COUNT ] = { 1 , 1 , 1 , 1 };
42+ static const char * mass_balance_var_grids [MASS_BALANCE_VAR_NAME_COUNT ] = { 0 , 0 , 0 , 0 };
43+ static const char * mass_balance_var_locations [MASS_BALANCE_VAR_NAME_COUNT ] = { "node" , "node" , "node" , "node" };
44+
3745static int Finalize (Bmi * self )
3846{
3947 // Function assumes everything that is needed is retrieved from the model before Finalize is called.
@@ -387,6 +395,23 @@ static int Get_value_ptr (Bmi *self, const char *name, void **dest)
387395 * dest = ((test_bmi_c_model * )(self -> data ))-> param_var_3 ;
388396 return BMI_SUCCESS ;
389397 }
398+
399+ if (strcmp (name , NGEN_MASS_IN ) == 0 ) {
400+ * dest = ((test_bmi_c_model * )(self -> data ))-> input_var_1 ;
401+ return BMI_SUCCESS ;
402+ }
403+ if (strcmp (name , NGEN_MASS_OUT ) == 0 ) {
404+ * dest = ((test_bmi_c_model * )(self -> data ))-> output_var_1 ;
405+ return BMI_SUCCESS ;
406+ }
407+ if (strcmp (name , NGEN_MASS_STORED ) == 0 ) {
408+ * dest = & ((test_bmi_c_model * )(self -> data ))-> mass_stored ;
409+ return BMI_SUCCESS ;
410+ }
411+ if (strcmp (name , NGEN_MASS_LEAKED ) == 0 ) {
412+ * dest = & ((test_bmi_c_model * )(self -> data ))-> mass_leaked ;
413+ return BMI_SUCCESS ;
414+ }
390415 return BMI_FAILURE ;
391416}
392417
@@ -483,6 +508,14 @@ static int Get_var_nbytes (Bmi *self, const char *name, int * nbytes)
483508 }
484509 }
485510 }
511+ if (item_count < 1 ) {
512+ for (i = 0 ; i < MASS_BALANCE_VAR_NAME_COUNT ; i ++ ) {
513+ if (strcmp (name , mass_balance_var_names [i ]) == 0 ) {
514+ item_count = mass_balance_var_item_count [i ];
515+ break ;
516+ }
517+ }
518+ }
486519 if (item_count < 1 )
487520 item_count = ((test_bmi_c_model * ) self -> data )-> num_time_steps ;
488521
@@ -515,6 +548,13 @@ static int Get_var_type (Bmi *self, const char *name, char * type)
515548 return BMI_SUCCESS ;
516549 }
517550 }
551+ // Finally check to see if in mass balance array
552+ for (i = 0 ; i < MASS_BALANCE_VAR_NAME_COUNT ; i ++ ) {
553+ if (strcmp (name , mass_balance_var_names [i ]) == 0 ) {
554+ snprintf (type , BMI_MAX_TYPE_NAME , "%s" , mass_balance_var_types [i ]);
555+ return BMI_SUCCESS ;
556+ }
557+ }
518558 // If we get here, it means the variable name wasn't recognized
519559 type [0 ] = '\0' ;
520560 return BMI_FAILURE ;
@@ -538,6 +578,13 @@ static int Get_var_units (Bmi *self, const char *name, char * units)
538578 return BMI_SUCCESS ;
539579 }
540580 }
581+ //Check for mass balance
582+ for (i = 0 ; i < MASS_BALANCE_VAR_NAME_COUNT ; i ++ ) {
583+ if (strcmp (name , mass_balance_var_names [i ]) == 0 ) {
584+ snprintf (units , BMI_MAX_UNITS_NAME , "%s" , mass_balance_var_units [i ]);
585+ return BMI_SUCCESS ;
586+ }
587+ }
541588 // If we get here, it means the variable name wasn't recognized
542589 units [0 ] = '\0' ;
543590 return BMI_FAILURE ;
@@ -560,6 +607,9 @@ static int Initialize (Bmi *self, const char *file)
560607 else
561608 model = (test_bmi_c_model * ) self -> data ;
562609
610+ model -> mass_stored = 0.0 ;
611+ model -> mass_leaked = 0.0 ;
612+
563613 if (read_init_config (file , model ) == BMI_FAILURE )
564614 return BMI_FAILURE ;
565615
0 commit comments