Abstract adapter interface for C++ classes to interact with the essential aspects of external models that implement the BMI spec but that are written in some other programming language.
More...
|
| Bmi_Adapter (std::string model_name, std::string bmi_init_config, bool has_fixed_time_step) |
|
| Bmi_Adapter (Bmi_Adapter const &)=delete |
|
| Bmi_Adapter (Bmi_Adapter &&)=delete |
|
virtual | ~Bmi_Adapter ()=0 |
|
virtual bool | is_model_initialized ()=0 |
| Whether the backing model has been initialized yet.
|
|
double | get_time_convert_factor () |
| Determine backing model's time units and return an appropriate conversion factor.
|
|
double | convert_model_time_to_seconds (const double &model_time_val) |
| Convert model time value to value in seconds.
|
|
double | convert_seconds_to_model_time (const double &seconds_val) |
| Convert a given number of seconds to equivalent in model time units.
|
|
virtual const std::string | get_analogous_cxx_type (const std::string &external_type_name, const size_t item_size)=0 |
| Get the name string for the C++ type analogous to the described type in the backing model.
|
|
void | Initialize () |
| Initialize the wrapped BMI model functionality using the value from the bmi_init_config member variable and the API's Initialize function.
|
|
void | Initialize (std::string config_file) override |
| Initialize the wrapped BMI model object using the given config file and the object's Initialize function.
|
|
bool | isInitialized () |
| Get whether this instance has been initialized properly.
|
|
std::string | get_model_name () |
| Get the model name.
|
|
virtual void | Update ()=0 |
|
virtual void | UpdateUntil (double time)=0 |
|
virtual void | Finalize ()=0 |
|
virtual std::string | GetComponentName ()=0 |
|
virtual int | GetInputItemCount ()=0 |
|
virtual int | GetOutputItemCount ()=0 |
|
virtual std::vector< std::string > | GetInputVarNames ()=0 |
|
virtual std::vector< std::string > | GetOutputVarNames ()=0 |
|
virtual int | GetVarGrid (std::string name)=0 |
|
virtual std::string | GetVarType (std::string name)=0 |
|
virtual std::string | GetVarUnits (std::string name)=0 |
|
virtual int | GetVarItemsize (std::string name)=0 |
|
virtual int | GetVarNbytes (std::string name)=0 |
|
virtual std::string | GetVarLocation (std::string name)=0 |
|
virtual double | GetCurrentTime ()=0 |
|
virtual double | GetStartTime ()=0 |
|
virtual double | GetEndTime ()=0 |
|
virtual std::string | GetTimeUnits ()=0 |
|
virtual double | GetTimeStep ()=0 |
|
virtual void | GetValue (std::string name, void *dest)=0 |
|
virtual void * | GetValuePtr (std::string name)=0 |
|
virtual void | GetValueAtIndices (std::string name, void *dest, int *inds, int count)=0 |
|
virtual void | SetValue (std::string name, void *src)=0 |
|
virtual void | SetValueAtIndices (std::string name, int *inds, int count, void *src)=0 |
|
virtual int | GetGridRank (const int grid)=0 |
|
virtual int | GetGridSize (const int grid)=0 |
|
virtual std::string | GetGridType (const int grid)=0 |
|
virtual void | GetGridShape (const int grid, int *shape)=0 |
|
virtual void | GetGridSpacing (const int grid, double *spacing)=0 |
|
virtual void | GetGridOrigin (const int grid, double *origin)=0 |
|
virtual void | GetGridX (const int grid, double *x)=0 |
|
virtual void | GetGridY (const int grid, double *y)=0 |
|
virtual void | GetGridZ (const int grid, double *z)=0 |
|
virtual int | GetGridNodeCount (const int grid)=0 |
|
virtual int | GetGridEdgeCount (const int grid)=0 |
|
virtual int | GetGridFaceCount (const int grid)=0 |
|
virtual void | GetGridEdgeNodes (const int grid, int *edge_nodes)=0 |
|
virtual void | GetGridFaceEdges (const int grid, int *face_edges)=0 |
|
virtual void | GetGridFaceNodes (const int grid, int *face_nodes)=0 |
|
virtual void | GetGridNodesPerFace (const int grid, int *nodes_per_face)=0 |
|
|
std::string | bmi_init_config |
| Path (as a string) to the BMI config file for initializing the backing model (empty if none).
|
|
bool | bmi_model_has_fixed_time_step = true |
| Whether this particular model has a time step size that cannot be changed internally or externally.
|
|
double | bmi_model_time_convert_factor |
| Conversion factor for converting values for model time in model's unit type to equivalent in seconds.
|
|
std::shared_ptr< double > | bmi_model_time_step_size = nullptr |
| Pointer to stored time step size value of backing model, if it is fixed and has been retrieved.
|
|
std::string | init_exception_msg |
| Message from an exception (if encountered) on the first attempt to initialize the backing model.
|
|
std::shared_ptr< std::vector< std::string > > | input_var_names |
| Pointer to collection of input variable names for backing model, used by GetInputVarNames() .
|
|
bool | model_initialized = false |
| Whether the backing model has been initialized yet, which is always initially false .
|
|
std::string | model_name |
|
std::shared_ptr< std::vector< std::string > > | output_var_names |
| Pointer to collection of output variable names for backing model, used by GetOutputVarNames() .
|
|
Abstract adapter interface for C++ classes to interact with the essential aspects of external models that implement the BMI spec but that are written in some other programming language.
virtual void models::bmi::Bmi_Adapter::construct_and_init_backing_model |
( |
| ) |
|
|
protectedpure virtual |
Construct the backing BMI model object, then call its BMI-native Initialize()
function.
Implementations should return immediately without taking any further action if model_initialized
is already true
.
The call to the BMI native Initialize(string)
should pass the value stored in bmi_init_config
.
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
Referenced by Initialize().
virtual const std::string models::bmi::Bmi_Adapter::get_analogous_cxx_type |
( |
const std::string & | external_type_name, |
|
|
const size_t | item_size ) |
|
pure virtual |
Get the name string for the C++ type analogous to the described type in the backing model.
The supported languages for BMI modules support different types than C++ in general, but it is necessary to map "external" types to the appropriate C++ type for certain interactions; e.g., setting a variable value. This function encapsulates the translation specific to the particular language.
Note that the size of an individual item is also required, as this can vary in certain situations depending on the implementation language of a backing model.
Implementations should all throw the same type of exception (currently, std::runtime_error) if/when an unrecognized external type name parameter is provided.
- Parameters
-
external_type_name | The string name of some type in backing model's implementation language. |
item_size | The particular size in bytes for items of the involved analogous types. |
- Returns
- The name string for the C++ type analogous to the described type in the backing model.
- Exceptions
-
std::runtime_error | If an unrecognized external type name parameter is provided. |
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
Referenced by models::bmi::GetValue(), realization::Bmi_Module_Formulation::set_initial_bmi_parameters(), and realization::Bmi_Module_Formulation::set_model_inputs_prior_to_update().
double models::bmi::Bmi_Adapter::get_time_convert_factor |
( |
| ) |
|
Determine backing model's time units and return an appropriate conversion factor.
A backing BMI model may use arbitrary units for time, but it will expose what those units are via the BMI GetTimeUnits
function. This function retrieves (and interprets) its model's units and return an appropriate factor for converting its internal time values to equivalent representations within the model, and vice versa. This function complies with the BMI get_time_units standard
- Exceptions
-
runtime_error | If the delegated BMI functions to query time throw an exception, the exception is caught and wrapped in a runtime_error |
References UnitsHelper::get_converted_value(), and bmi::Bmi::GetTimeUnits().
Referenced by models::bmi::Bmi_C_Adapter::Bmi_C_Adapter(), models::bmi::Bmi_Cpp_Adapter::Bmi_Cpp_Adapter(), and Initialize().
void models::bmi::Bmi_Adapter::Initialize |
( |
| ) |
|
Initialize the wrapped BMI model functionality using the value from the bmi_init_config
member variable and the API's Initialize
function.
If no attempt to initialize the model has yet been made (i.e., model_initialized
is false
when this function is called), then an initialization is attempted for the model. This is handled by a nested call to the construct_and_init_backing_model
function. If initialization fails, an exception will be raised, with it's message saved as part of this object's state. However, regardless of the success of initialization, model_initialized
is set to true
after the attempt.
Additionally, if a successful model initialization is performed, bmi_model_time_convert_factor
is immediately thereafter set by passing it by reference in a call to acquire_time_conversion_factor
.
If an attempt to initialize the model has already been made (i.e., model_initialized
is true
), this function will either simply return or will throw a runtime_error, with its message including the message of the exception from the earlier attempt.
- Exceptions
-
runtime_error | If called again after earlier call that resulted in an exception, or if BMI config file could not be read. |
models::external::State_Exception | If initialize() in nested model does not return successful. |
References bmi_init_config, bmi_model_time_convert_factor, construct_and_init_backing_model(), utils::FileChecker::file_is_readable(), get_time_convert_factor(), init_exception_msg, model_initialized, and model_name.
Referenced by Initialize().
void models::bmi::Bmi_Adapter::Initialize |
( |
std::string | config_file | ) |
|
|
overridevirtual |
Initialize the wrapped BMI model object using the given config file and the object's Initialize
function.
If the given file is not the same as what is in bmi_init_config
and the model object has not already been initialized, this function will produce a warning message about the difference, then subsequently update
bmi_init_config`` to the given file. It will then proceed with initialization.
However, if the given file is not the same as what is in bmi_init_config
`, but the model has already been initialized, a runtime_error exception is thrown.
This otherwise operates using the logic of Initialize()
.
- Parameters
-
- See also
- Initialize()
- Exceptions
-
models::external::State_Exception | If initialize() in nested model is not successful. |
runtime_error | If already initialized but using a different file than the passed argument. |
Implements bmi::Bmi.
References bmi_init_config, Initialize(), model_initialized, logging::warning(), and models::external::State_Exception::what().