|
NGen
|
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...
#include <Bmi_Adapter.hpp>
Inheritance diagram for models::bmi::Bmi_Adapter:
Collaboration diagram for models::bmi::Bmi_Adapter:Public Member Functions | |
| 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) |
| Reduce a type name the backing model reports to one models::bmi::with_bmi_type resolves. | |
| 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 |
Protected Member Functions | |
| virtual void | construct_and_init_backing_model ()=0 |
Construct the backing BMI model object, then call its BMI-native Initialize() function. | |
Protected Attributes | |
| 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.
| models::bmi::Bmi_Adapter::Bmi_Adapter | ( | std::string | model_name, |
| std::string | bmi_init_config, | ||
| bool | has_fixed_time_step ) |
References utils::FileChecker::file_is_readable(), and init_exception_msg.
|
delete |
|
delete |
|
pure virtualdefault |
|
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().
| double models::bmi::Bmi_Adapter::convert_model_time_to_seconds | ( | const double & | model_time_val | ) |
Convert model time value to value in seconds.
Performs necessary lookup and conversion of some given model time value - as from GetCurrentTime() or GetStartTime() - and returns the equivalent value when represented in seconds.
| model_time_val | Arbitrary model time value in units provided by GetTimeUnits() |
References bmi_model_time_convert_factor.
Referenced by realization::Bmi_C_Formulation::convert_model_time(), and realization::Bmi_Cpp_Formulation::convert_model_time().
| double models::bmi::Bmi_Adapter::convert_seconds_to_model_time | ( | const double & | seconds_val | ) |
Convert a given number of seconds to equivalent in model time units.
| seconds_val |
References bmi_model_time_convert_factor.
Referenced by realization::Bmi_Module_Formulation::update().
|
pure virtualinherited |
Implemented in models::bmi::AbstractCLibBmiAdapter, models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
|
inlinevirtual |
Reduce a type name the backing model reports to one models::bmi::with_bmi_type resolves.
Most languages need no reduction: the table carries the C and C++ keyword spellings and the Fortran ones alike, so the name a model reports is already a name the table knows, and the default returns it unchanged.
The exception is a language whose type names do not determine a type. A Python model reports "int" for any width, so the name alone cannot be resolved and the item size has to settle it. That is what an override is for, and why the size is a parameter here.
| external_type_name | The string name of some type in the backing model's language. |
| item_size | The size in bytes of one item, where the name alone does not imply it. |
| std::runtime_error | If an override cannot reduce the name to one the table carries. |
Referenced by models::bmi::GetValue(), and realization::Bmi_Module_Formulation::set_initial_bmi_parameters().
| std::string models::bmi::Bmi_Adapter::get_model_name | ( | ) |
Get the model name.
References model_name.
Referenced by realization::Bmi_Module_Formulation::get_value(), realization::Bmi_Module_Formulation::get_values(), models::bmi::GetValue(), models::bmi::GetValuePtr(), and realization::Bmi_Module_Formulation::perform_set().
| 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
| 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().
|
pure virtualinherited |
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
|
pure virtualinherited |
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
Referenced by realization::Bmi_Module_Formulation::get_model_current_time(), and realization::Bmi_Module_Formulation::update().
|
pure virtualinherited |
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
Referenced by realization::Bmi_Module_Formulation::get_model_end_time().
|
pure virtualinherited |
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
|
pure virtualinherited |
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
|
pure virtualinherited |
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
|
pure virtualinherited |
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
|
pure virtualinherited |
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
|
pure virtualinherited |
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
|
pure virtualinherited |
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
|
pure virtualinherited |
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
|
pure virtualinherited |
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
|
pure virtualinherited |
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
|
pure virtualinherited |
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
|
pure virtualinherited |
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
|
pure virtualinherited |
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
|
pure virtualinherited |
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
|
pure virtualinherited |
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
|
pure virtualinherited |
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
|
pure virtualinherited |
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
|
pure virtualinherited |
|
pure virtualinherited |
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
|
pure virtualinherited |
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
Referenced by realization::Bmi_Module_Formulation::get_bmi_output_var_name(), realization::Bmi_Module_Formulation::get_bmi_output_variables(), realization::Bmi_C_Formulation::is_bmi_output_variable(), and realization::Bmi_Cpp_Formulation::is_bmi_output_variable().
|
pure virtualinherited |
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
Referenced by realization::Bmi_Module_Formulation::get_data_start_time().
|
pure virtualinherited |
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
|
pure virtualinherited |
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
Referenced by get_time_convert_factor().
|
pure virtualinherited |
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
Referenced by models::bmi::GetValue().
|
pure virtualinherited |
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
|
pure virtualinherited |
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
Referenced by models::bmi::GetValuePtr().
|
pure virtualinherited |
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
|
pure virtualinherited |
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
Referenced by realization::Bmi_Module_Formulation::do_bmi_sets_with_full_refetch(), models::bmi::GetValue(), models::bmi::GetValuePtr(), realization::Bmi_Module_Formulation::initialize_bmi_input_var_metadata(), and realization::Bmi_Module_Formulation::set_initial_bmi_parameters().
|
pure virtualinherited |
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
|
pure virtualinherited |
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
Referenced by models::bmi::GetValue(), and realization::Bmi_Module_Formulation::set_initial_bmi_parameters().
|
pure virtualinherited |
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
Referenced by models::bmi::GetValue().
|
pure virtualinherited |
| 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.
| 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().
|
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_configand the model object has not already been initialized, this function will produce a warning message about the difference, then subsequently updatebmi_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().
| config_file |
| 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().
|
pure virtual |
Whether the backing model has been initialized yet.
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
Referenced by realization::Bmi_Module_Formulation::inner_create_formulation(), and realization::Bmi_Cpp_Formulation::is_model_initialized().
| bool models::bmi::Bmi_Adapter::isInitialized | ( | ) |
Get whether this instance has been initialized properly.
References model_initialized.
|
pure virtualinherited |
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
Referenced by realization::Bmi_Module_Formulation::perform_set(), and realization::Bmi_Module_Formulation::set_initial_bmi_parameters().
|
pure virtualinherited |
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
|
pure virtualinherited |
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
Referenced by realization::Bmi_Module_Formulation::update().
|
pure virtualinherited |
Implemented in models::bmi::Bmi_C_Adapter, and models::bmi::Bmi_Cpp_Adapter.
Referenced by realization::Bmi_Module_Formulation::update().
|
protected |
Path (as a string) to the BMI config file for initializing the backing model (empty if none).
Referenced by models::bmi::Bmi_C_Adapter::construct_and_init_backing_model_for_type(), models::bmi::Bmi_Cpp_Adapter::construct_and_init_backing_model_for_type(), Initialize(), and Initialize().
|
protected |
Whether this particular model has a time step size that cannot be changed internally or externally.
Referenced by models::bmi::Bmi_C_Adapter::get_bmi_model_time_step_size_ptr(), and models::bmi::Bmi_Cpp_Adapter::get_bmi_model_time_step_size_ptr().
|
protected |
Conversion factor for converting values for model time in model's unit type to equivalent in seconds.
Referenced by models::bmi::Bmi_C_Adapter::Bmi_C_Adapter(), models::bmi::Bmi_Cpp_Adapter::Bmi_Cpp_Adapter(), convert_model_time_to_seconds(), convert_seconds_to_model_time(), and Initialize().
|
protected |
Pointer to stored time step size value of backing model, if it is fixed and has been retrieved.
Referenced by models::bmi::Bmi_C_Adapter::get_bmi_model_time_step_size_ptr(), and models::bmi::Bmi_Cpp_Adapter::get_bmi_model_time_step_size_ptr().
|
protected |
Message from an exception (if encountered) on the first attempt to initialize the backing model.
Referenced by Bmi_Adapter(), models::bmi::Bmi_C_Adapter::construct_and_init_backing_model_for_type(), models::bmi::AbstractCLibBmiAdapter::dynamic_library_load(), models::bmi::AbstractCLibBmiAdapter::dynamic_load_symbol(), models::bmi::Bmi_Cpp_Adapter::execModuleCreation(), models::bmi::Bmi_C_Adapter::execModuleRegistration(), and Initialize().
|
protected |
Pointer to collection of input variable names for backing model, used by GetInputVarNames().
Referenced by models::bmi::Bmi_C_Adapter::GetInputVarNames().
|
protected |
Whether the backing model has been initialized yet, which is always initially false.
Referenced by models::bmi::Bmi_C_Adapter::Bmi_C_Adapter(), models::bmi::Bmi_Cpp_Adapter::Bmi_Cpp_Adapter(), models::bmi::Bmi_C_Adapter::construct_and_init_backing_model_for_type(), models::bmi::Bmi_Cpp_Adapter::construct_and_init_backing_model_for_type(), models::bmi::Bmi_C_Adapter::finalizeForCAdapter(), models::bmi::Bmi_Cpp_Adapter::finalizeForCppAdapter(), Initialize(), Initialize(), models::bmi::Bmi_C_Adapter::is_model_initialized(), models::bmi::Bmi_Cpp_Adapter::is_model_initialized(), and isInitialized().
|
protected |
|
protected |
Pointer to collection of output variable names for backing model, used by GetOutputVarNames().
Referenced by models::bmi::Bmi_C_Adapter::GetOutputVarNames().