Rperesents a variable or outlet created and managed by an object in a simulation. More...
Public Types | |
enum | dsim_variable_usage { dsim_invalid_value = 0, dsim_parameter_value = 1, dsim_input_value = 2, dsim_output_value = 3, dsim_state_value = 4, dsim_integrated_value = 5 } |
Variable usage types. More... | |
Public Member Functions | |
dsim_variable () | |
Default constructor. | |
dsim_variable (const dsim_variable &base) | |
Copy constructor. | |
dsim_variable & | operator= (const dsim_variable &base) |
Assignment operator. | |
bool | valid () const |
Returns whether or not this variable is valid. | |
dsim_variable::dsim_variable_usage | usage () const |
Returns the expected usage for this variable. | |
int | type () const |
Returns the type of this variable. | |
dsim_value | value () const |
Returns the current value of this variable, dependent on whether or not it is in co-integrated mode. | |
dsim_value | base_value () const |
Returns the current base value of this variable, even if it is in co-integrated mode. | |
dsim_value | cointegrated_value () const |
Returns the current co-integrated value of this, even it if is not in co-integrated mode. | |
void * | raw_value () const |
Returns the raw pointer for the value held by this variable. | |
bool | extract_raw_value (void *destination) const |
Copies the raw value of the variable into a provided location. | |
const char * | units () const |
Returns the units assigned to this variable. | |
const char * | description () const |
Returns the human-readable description of this variable. | |
int | nominal_rows () const |
Returns the nominal number of rows for values held by this variable. | |
int | nominal_columns () const |
Returns the nominal number of columns for values held by this variable. | |
void | set_nominal_dimensions (int rows, int columns) |
Change the nominal rows and columns for values held by this variable. | |
bool | cointegrated () const |
Returns whether or not the object is in co-integrated mode. | |
void | set_cointegrated (bool flag) |
Sets whether or not the object is in co-integrated mode. | |
int | value_as_int () const |
Returns the current value of this variable as an integer. | |
void | set_value_as_int (int val) |
Sets the current value of this variable as an integer. | |
double | value_as_double () const |
Returns the current value of this variable as a double. | |
void | set_value_as_double (double val) |
Sets the current value of this variable as a double. | |
ml_matrix | value_as_matrix () const |
Returns the current value of this variable as a matrix. | |
void | set_value_as_matrix (const ml_matrix &val) |
Sets the current value of this variable as a matrix. | |
const char * | value_as_string () const |
Returns the current value of this variable as a string. | |
void | set_value_as_string (const char *val) |
Sets the current value of this variable as a string. | |
void | set_value (int type, void *new_value) |
Sets the current value of this variable by providing a data type and a raw value pointer. | |
void | set_value (const dsim_value &new_value) |
Sets the current value of this variable to the provided value. | |
void | set_derivative (int type, void *deriv) throw (dsim_type_mismatch_exception) |
Sets the current derivative of this variable by providing a data type and a raw value pointer. | |
void | set_derivative (const dsim_value &deriv) throw (dsim_type_mismatch_exception) |
Sets the current derivative of this variable by providing a value. | |
dsim_value | derivative () const |
Returns the current derivative of this variable. | |
void * | integration_ptr () |
Retrieve the stored integration pointer for this variable. | |
void | set_integration_ptr (void *ptr) |
Store an integration pointer in this variable. | |
void | set_attribute (const std::string &name, const std::string &value) |
Sets an attribute for this variable. | |
bool | has_attribute (const std::string &name) |
Tests whether or not a variable has a specific attribute. | |
std::string | get_attribute (const std::string &name) |
Gets the value of an attribute. | |
std::map< std::string, std::string >::iterator | attribute_iterator () |
Gets the starting iterator for the attributes at this variable. | |
std::map< std::string, std::string >::iterator | end_attribute_iterator () |
Gets the ending iterator for the attributes at this variable. | |
void | mark_telemetry () |
Marks this variable as telemetry. | |
void | mark_command () |
Marks this variable as a command. | |
void | mark_command_and_telemetry () |
Marks this variable as both a command and telemetry. | |
void | mark_telemetry_and_command () |
Marks this variable as both a command and telemetry. | |
bool | is_telemetry () const |
Tests whether or not this variable has been marked as telemetry. | |
bool | is_command () const |
Tests whether or not this variable has been marked as a command. | |
bool | has_changed () const |
Indicates whether or not the value of this variable has changed. | |
void | mark_unchanged () |
Clears the has-changed flag for this variable. |
Rperesents a variable or outlet created and managed by an object in a simulation.
Variables are the primary data storage and propagation mechanism within DSim. Objects create dsim_variable objects, look up variables at other objects in the simulation, and read and set the values of those variables.
All variables have a specific data type that they store. For those variables which are integrated states, the variables actually store the data twice- once for the base value that is updated each timestep, and once for the co-integrated version of the value, which may be updated many times each timestep according to the variable's integrator. Objects can choose to work with the co-integrated version of the variable by calling set_cointegrated().
Variables may or may not be valid at a certain time. A dsim_variable object that is freshly created is in an invalid state; it can be made valid if a valid dsim_variable is assigned to it, usually from either a variable lookup or a variable creation function call at dsim_model. The validity of a variable can (and should) be checked with the valid() function call.
Variable usage types.
Variables have a usage associated with them. With the exception of the dsim_integrated_value usage, these usages are merely hints to the system and to users as to the purpose of the variable; they have no effect on how the variable operates. Each usage (except for invalid) matches one of the create_* functions of dism_model. See those functions for more information.
std::map< std::string, std::string >::iterator dsim_variable::attribute_iterator | ( | ) |
Gets the starting iterator for the attributes at this variable.
Returns the starting iterator for the map of attributes, suitable for use in iterating over the attributes of the variable.
dsim_value dsim_variable::base_value | ( | ) | const |
Returns the current base value of this variable, even if it is in co-integrated mode.
dsim_value dsim_variable::cointegrated_value | ( | ) | const |
Returns the current co-integrated value of this, even it if is not in co-integrated mode.
dsim_value dsim_variable::derivative | ( | ) | const |
Returns the current derivative of this variable.
const char * dsim_variable::description | ( | ) | const |
Returns the human-readable description of this variable.
std::map< std::string, std::string >::iterator dsim_variable::end_attribute_iterator | ( | ) |
Gets the ending iterator for the attributes at this variable.
Returns the ending iterator for the map of attributes, suitable for use as the end condition of a loop over the attributes of an variable.
bool dsim_variable::extract_raw_value | ( | void * | destination ) | const |
Copies the raw value of the variable into a provided location.
destination | A pointer to the location to which the value should be copied. The destination must hold the appropriate amount of space for a value of the type held by the variable. |
std::string dsim_variable::get_attribute | ( | const std::string & | name ) |
Gets the value of an attribute.
Returns the string value associated with the requested attribute.
name | The name of the attribute to look up. |
bool dsim_variable::has_attribute | ( | const std::string & | name ) |
Tests whether or not a variable has a specific attribute.
Determines whether or not an attribute with a specific name has been set for this object.
name | The name of the attribute. |
bool dsim_variable::has_changed | ( | ) | const |
Indicates whether or not the value of this variable has changed.
Each variable keeps a has-changed flag, which is set to true whenever the value of the variable is modified. The flag is not cleared at any time by DSim itself, and its use is generally confined to external entities running DSim simulations.
Note that a variable is "changed" if any of the value setting functions have been called on it, even if they are not setting a distinct value.
void * dsim_variable::integration_ptr | ( | ) |
Retrieve the stored integration pointer for this variable.
This function is intended to be called only by the integrator instance responsible for this variable.
bool dsim_variable::is_command | ( | ) | const |
Tests whether or not this variable has been marked as a command.
bool dsim_variable::is_telemetry | ( | ) | const |
Tests whether or not this variable has been marked as telemetry.
void dsim_variable::mark_command | ( | ) |
Marks this variable as a command.
The command flag for a variable has no meaning for DSim; it exists to allow variables to have special meaning for an external application running the simulation.
void dsim_variable::mark_command_and_telemetry | ( | ) |
Marks this variable as both a command and telemetry.
Marks as both telemetry and command
void dsim_variable::mark_telemetry | ( | ) |
Marks this variable as telemetry.
The telemetry flag for a variable has no meaning for DSim; it exists to allow variables to have special meaning for an external application running the simulation.
void dsim_variable::mark_unchanged | ( | ) |
Clears the has-changed flag for this variable.
After a change has been noted, the has-changed flag should generally be cleared via this method to ensure that subsequent changes can be detected.
int dsim_variable::nominal_columns | ( | ) | const |
Returns the nominal number of columns for values held by this variable.
Variables are given a nominal number of columns during creation. This number is only a guide- values stored in the variable are not required to match the nominal number of columns.
int dsim_variable::nominal_rows | ( | ) | const |
Returns the nominal number of rows for values held by this variable.
Variables are given a nominal number of rows during creation. This number is only a guide- values stored in the variable are not required to match the nominal number of rows.
void * dsim_variable::raw_value | ( | ) | const |
Returns the raw pointer for the value held by this variable.
void dsim_variable::set_attribute | ( | const std::string & | name, |
const std::string & | value | ||
) |
Sets an attribute for this variable.
Sets the value associated with a named attribute, creating that attribute if it does not yet exist.
name | The name of the attribute. |
value | The value to associate with the attribute. |
void dsim_variable::set_derivative | ( | int | type, |
void * | deriv | ||
) | throw (dsim_type_mismatch_exception) |
Sets the current derivative of this variable by providing a data type and a raw value pointer.
Sets the current derviative for the variable, which will be used by the variable's integrator. If the type provided does not match the type of the variable, a dsim_type_mismatch_exception will be thrown.
type | The type of the provided derivative value. |
deriv | A pointer to the derivative value. |
void dsim_variable::set_derivative | ( | const dsim_value & | deriv ) | throw (dsim_type_mismatch_exception) |
Sets the current derivative of this variable by providing a value.
Sets the current derviative for the variable, which will be used by the variable's integrator. If the type provided does not match the type of the variable, a dsim_type_mismatch_exception will be thrown.
deriv | The value to set as the derivative. |
void dsim_variable::set_integration_ptr | ( | void * | ptr ) |
Store an integration pointer in this variable.
This function is intended to be called only by the integrator instance responsible for this variable.
When a new integration pointer is set, the previous pointer is discarded.
ptr | The new pointer to store with the variable. |
void dsim_variable::set_nominal_dimensions | ( | int | rows, |
int | columns | ||
) |
Change the nominal rows and columns for values held by this variable.
Variables are given a nominal number of rows and columns during creation. These numbers are only a guide- values stored in the variable are not required to match the nominal number of columns. This function allows the nominal dimensions of the variable to be changed.
rows | The new nominal number of rows |
columns | The new nominal number of columns |
void dsim_variable::set_value | ( | int | type, |
void * | new_value | ||
) |
Sets the current value of this variable by providing a data type and a raw value pointer.
Attempts to set the value of the variable to a new value provided via pointer and of the specified type. If the provided type does not match the the type of the variable, the provided value will be converted, if possible, to the type of the variable. If the conversion attempt fails, the set will fail.
type | The type of the value pointed to by new_value. |
new_value | A pointer to the value to be stored in the variable. |
void dsim_variable::set_value | ( | const dsim_value & | new_value ) |
Sets the current value of this variable to the provided value.
Attempts to set the value of the variable to a new value provided via pointer and of the specified type. If the provided type does not match the the type of the variable, the provided value will be converted, if possible, to the type of the variable. If the conversion attempt fails, the set will fail.
new_value | The value to be stored in the variable. |
void dsim_variable::set_value_as_double | ( | double | val ) |
Sets the current value of this variable as a double.
Attempts to set the value of the variable to a double. If the variable's data type is not sd_type_double, the double value provided will first be converted, if possible, to the data type of the variable; if it cannot be, the set will fail.
val | The double value to store in the variable |
void dsim_variable::set_value_as_int | ( | int | val ) |
Sets the current value of this variable as an integer.
Attempts to set the value of the variable to an integer. If the variable's data type is not sd_type_int, the integer value provided will first be converted, if possible, to the data type of the variable; if it cannot be, the set will fail.
val | The integer value to store in the variable |
void dsim_variable::set_value_as_matrix | ( | const ml_matrix & | val ) |
Sets the current value of this variable as a matrix.
Attempts to set the value of the variable to a matrix. If the variable's data type is not sd_type_matrix, the matrix value provided will first be converted, if possible, to the data type of the variable; if it cannot be, the set will fail.
val | The matrix value to store in the variable |
void dsim_variable::set_value_as_string | ( | const char * | val ) |
Sets the current value of this variable as a string.
Attempts to set the value of the variable to a string. If the variable's data type is not sd_type_string, the string value provided will first be converted, if possible, to the data type of the variable; if it cannot be, the set will fail.
val | The string value to store in the variable |
int dsim_variable::type | ( | ) | const |
Returns the type of this variable.
const char * dsim_variable::units | ( | ) | const |
Returns the units assigned to this variable.
dsim_variable::dsim_variable_usage dsim_variable::usage | ( | ) | const |
Returns the expected usage for this variable.
dsim_value dsim_variable::value | ( | ) | const |
Returns the current value of this variable, dependent on whether or not it is in co-integrated mode.
The value referenced by this function depends on whether or not this variable is currently in co-integrated mode. If so, it will return the current cointegrated value; if not, it will return the current base value.
double dsim_variable::value_as_double | ( | ) | const |
Returns the current value of this variable as a double.
If the variable's type is not sd_type_double, the value in the variable will be converted to a double and returned.
int dsim_variable::value_as_int | ( | ) | const |
Returns the current value of this variable as an integer.
If the variable's type is not sd_type_int, the value in the variable will be converted to an integer and returned.
ml_matrix dsim_variable::value_as_matrix | ( | ) | const |
Returns the current value of this variable as a matrix.
If the variable's type is not sd_type_matrix, the value in the variable will be converted to a matrix and returned.
const char * dsim_variable::value_as_string | ( | ) | const |
Returns the current value of this variable as a string.
If the variable's type is not sd_type_string, the value in the variable will be converted to a string and returned.