Public Member Functions | Protected Member Functions

dsim_model Class Reference

Superclass for all simulated objects. More...

Inheritance diagram for dsim_model:

List of all members.

Public Member Functions

 dsim_model (dsim_model_setup *setup)
 Constructor. Should have few if any side effects.
virtual ~dsim_model ()
 Destructor.
const char * name () const
 The name given to this object in the setup file.
const char * path () const
 The full path to this object.
dsim_modelparent () const
 The parent of this object; NULL if it is a top level object.
unsigned int child_count () const
 The number of child objects of this object.
dsim_modelchild_at_index (unsigned int index) const
 Retrieve a child model by index.
dsim_modelchild_with_name (const char *name) const
 Retrieve a child model by name.
virtual void * describe_setup (void *ds)
 Overridden by subclasses to describe the custom setup data that they can handle.
void describe_setup_command (void *ds, const char *command, const char *description)
 Called by subclasses from within describe_setup() to describe a setup command that they accept.
virtual bool parse_setup (const char *command, const char *data)
 Overridden by subclasses to handle custom setup data.
virtual void initialize_data ()
 Overridden by subclasses to create variables and outlets.
virtual void initialization_complete ()
 Overridden by subclasses to request variables and set up for propagation.
virtual void initialize_timestep ()
 Overridden by subclasses to prepare for the timestep.
virtual void pre_calculate ()
 Overridden by subclasses to do any single-time calculations necessary before integration.
virtual void post_calculate ()
 Overridden by subclasses to do any single-time calculations necessary after integration.
virtual void complete_timestep ()
 Overridden by subclasses to do any necessary post-timestep cleanup.
virtual void rhs (double t, double jd)
 Overridden by subclasses to set the derivatives of integrated states.
dsim_variable request_local_variable (const char *name, bool quiet=false)
 Look up a variable created by this object.
dsim_value current_value_for_variable (const char *name)
 Look up the current value of a variable created by this object.
bool connect_outlet (const char *name, const dsim_variable &source, const char *source_object=NULL)
 Connect one of this object's outlets to a variable.
void set_attribute (const std::string &ame, const std::string &value)
 Set an attribute at this object.
bool has_attribute (const std::string &name)
 Determine whether or not an attribute for this object has been set.
std::string get_attribute (const std::string &name)
 Get the value of an attribute at this object.
std::map< std::string,
std::string >::iterator 
attribute_iterator ()
 Get an iterator for moving through the attributes of this object.
std::map< std::string,
std::string >::iterator 
end_attribute_iterator ()
 Get the endpoint iterator for the stopping condition when moving through the attibutes of this object.
virtual dsim_value handle_message (const std::string &sender_path, const std::string &message_name, const dsim_value &argument)
 Overridden by subclasses to handle messages sent by other objects.

Protected Member Functions

void configure_timestep (bool call_pre, bool call_rhs, bool call_post)
 Called to set which functions are called during a timestep.
dsim_variable create_parameter (const char *name, int data_type, void *init_value, int rows, int cols, const char *units, const char *description)
 Create a new variable that will be marked for usage as a parameter.
dsim_variable create_input (const char *name, int data_type, void *init_value, int rows, int cols, const char *units, const char *description)
 Create a new variable that will be marked for usage as an input.
dsim_variable create_output (const char *name, int data_type, void *init_value, int rows, int cols, const char *units, const char *description)
 Create a new variable that will be marked for usage as an output.
dsim_variable create_state (const char *name, int data_type, void *init_value, int rows, int cols, const char *units, const char *description)
 Create a new variable that will be marked for usage as a state.
dsim_variable create_integrated_state (const char *name, int data_type, void *init_value, int rows, int cols, const char *units, const char *description)
 Create a new variable that will be marked for usage as an integrated state.
void create_outlet (dsim_variable &outlet, const char *name, int data_type, const char *units, const char *description, bool dependent=false)
 Create an outlet to which a variable will be connected in a setup file.
dsim_variable request_variable (const char *path, bool quiet=false, bool store=true)
 Request a variable created elsewhere in the simulation.
dsim_variable request_hierarchy_variable (const char *path, bool quiet=false)
void create_target (const char *toarget_name, const char *target_description, bool multiple=false)
 Create a target to be set in a setup file.
const char * lookup_target (const char *target_name)
 Look up the target that was set in a setup file.
bool set_target (const char *target_name, const char *target_path)
 Set the a target's path.
const std::vector< std::string > & target_destinations (const std::string &target_name)
 Get the vector of destinations for a multi-valued target.
dsim_value send_message (const char *destination, const char *message_name, const dsim_value &argument)
 Send a message to a destination object, and receive a value in return.
dsim_networkcreate_managed_network (const char *name, const char *description)
 Create a new object network managed by this model.
dsim_networkmanaged_network_with_name (const char *name)
 Managed network with name.
double sim_jd () const
 Current simulation julian date.
double sim_time () const
 Current simulation elapsed time.
double sim_dt () const
 Current simulation time step.
void error (const char *msg,...) const
 Report an error and stop the simulation.
void warning (const char *msg,...) const
 Report a warning.
void log (const char *msg,...) const
 Report an informative notification.

Detailed Description

Superclass for all simulated objects.

The dsim_model class is the ultimate superclass for all objects within a simulation. It is rarely if ever directly used; rather, builtin and user subclasses of it are instantiated within simulations. When a new type of object needs to be simulated, a new subclass of dsim_model or one of its subclasses is generated.

Subclasses provide behavior by overriding the constructor and the various virtual functions. Exactly which functions need to be overridden vary based on the functionality that the subclass intends to overwrite; it is likely that, at the least, each subclass will overwrite initialize_data(), initialization_complete(), and at least one of the timestep/integration functions: initialize_timestep(), pre_calculate(), post_caluclate(), complete_timestep(), and rhs().

The non-virtual functions provided by dsim_model are intended to be used by subclasses to handle object customization (creating variables, configuring the timestep functions, describing accepted setup commands, etc) and interacting with the simulation (getting current simulation timestep, looking up other objects and variables, etc).

All objects are automatically instantiated by the simulation and should never be created or destroyed directly by the user. There is only one constructor, which subclasses may choose to override; however, initialize_data() may also take the place of a constructor for the purposes of object initialization. Many dsim_model functions are not yet available during the constructor, and so most initialization is not possible there.

All models must have an associated factory function conforming to dsim_model_factory_t.


Constructor & Destructor Documentation

dsim_model::dsim_model ( dsim_model_setup *  setup )

Constructor. Should have few if any side effects.

If a subclass provides a custom constructor, it is important that the setup parameter be passed unchanged to the dsim_model constructor.

Do not call DSim methods within your constructor. The object is not fully set up during construction, and so any method calls will have unpredictable results. Any initialization that depends on DSim methods should be delayed until initialize_data() or initialization_complete(), as appropriate.

Parameters:
setupAn opaque pointer to a model setup structure, used internally by the simulation engine. Do not modify.

Member Function Documentation

void dsim_model::error ( const char *  msg,
  ... 
) const [protected]

Report an error and stop the simulation.

Output a message at the error priority level. The message will be sent to the simulation's output handler, if on is installed; it will also be sent to the simulation's output log file.

Parameters:
msgThe format string for the message. See printf documentation for details on the format string.
...The additional arguments required by the format string.
void dsim_model::log ( const char *  msg,
  ... 
) const [protected]

Report an informative notification.

Output a message at the info priority level. The message will be sent to the simulation's output handler, if on is installed; it will also be sent to the simulation's output log file.

Parameters:
msgThe format string for the message. See printf documentation for details on the format string.
...The additional arguments required by the format string.
double dsim_model::sim_dt (  ) const [protected]

Current simulation time step.

Returns the current simulation time delta, the amount by which simulation time increases each timestep.

Returns:
The current simulation time delta.
double dsim_model::sim_jd (  ) const [protected]

Current simulation julian date.

Returns the current simulation Julian Date. Note that during integration, the jd provided to the rhs() call should be used instead.

Returns:
The current Julian Date associated with the start of the current timestep.
double dsim_model::sim_time (  ) const [protected]

Current simulation elapsed time.

Returns the current simulation time (in seconds). Note that during integration, the time provided to the rhs() call should be used instead.

Returns:
The current simulation time associated with the start of the current timestep.
void dsim_model::warning ( const char *  msg,
  ... 
) const [protected]

Report a warning.

Output a message at the warning priority level. The message will be sent to the simulation's output handler, if on is installed; it will also be sent to the simulation's output log file.

Parameters:
msgThe format string for the message. See printf documentation for details on the format string.
...The additional arguments required by the format string.
 All Classes Files Functions Typedefs Enumerations Enumerator