#include <adevs_rk4.h>
Public Member Functions | |
rk4 (int num_state_vars, double h_max, int zero_crossing_funcs=1) | |
void | init (int i, double q0) |
const double * | getStateVars () const |
int | getNumStateVars () const |
virtual void | der_func (const double *q, double *dq)=0 |
virtual void | state_event_func (const double *q, double *z)=0 |
virtual double | time_event_func (const double *q)=0 |
virtual void | discrete_action (double *q, const Bag< X > &xb)=0 |
virtual void | discrete_output (const double *q, Bag< X > &yb)=0 |
virtual void | state_changed (const double *q) |
void | evolve_func (double h) |
double | next_event_func (bool &is_event) |
void | discrete_action_func (const Bag< X > &xb) |
void | discrete_output_func (Bag< X > &yb) |
void | state_changed () |
~rk4 () | |
Destructor. |
This class can be used to simulate a set of ordinary differential equations with state and time events. This classes uses a fourth order Runge-Kutta integration scheme and interval halving for event detection.
adevs::rk4< X >::rk4 | ( | int | num_state_vars, | |
double | h_max, | |||
int | zero_crossing_funcs = 1 | |||
) | [inline] |
The constructor requires the number of continuous state variables and the maximum allowed integration time step. The number of zero crossing functions in this system are supplied with the last argument (the default value is 1).
virtual void adevs::rk4< X >::der_func | ( | const double * | q, | |
double * | dq | |||
) | [pure virtual] |
Compute the derivative function using the supplied state variable values. The derivatives should be stored in dq.
virtual void adevs::rk4< X >::discrete_action | ( | double * | q, | |
const Bag< X > & | xb | |||
) | [pure virtual] |
This function is called when an event occurs. The event can be due to the zero crossing function reaching zero or because of an external input. The continuous and discrete variables can be updated here. The q array contains continuous state when the event occurs, and can be modified if desired.
Referenced by adevs::rk4< X >::discrete_action_func().
void adevs::rk4< X >::discrete_action_func | ( | const Bag< X > & | xb | ) | [inline, virtual] |
This is the discrete action function. The input bag contains the discrete events that are available at this time (if any).
Implements adevs::DESS< X >.
References adevs::rk4< X >::discrete_action().
virtual void adevs::rk4< X >::discrete_output | ( | const double * | q, | |
Bag< X > & | yb | |||
) | [pure virtual] |
This output function is evaluated when internal events occur. Output events should be placed into the bag yb.
Referenced by adevs::rk4< X >::discrete_output_func().
void adevs::rk4< X >::discrete_output_func | ( | Bag< X > & | yb | ) | [inline, virtual] |
This is the output function. The output function is evaluated when the next_event_func() elapses. The bag should be filled with output events.
Implements adevs::DESS< X >.
References adevs::rk4< X >::discrete_output().
void adevs::rk4< X >::evolve_func | ( | double | h | ) | [inline, virtual] |
This virtual function is the continuous evolution function. Its purpose is to advance the continuous state variables for h units of time. A derived class should implement its integration scheme in this function.
Implements adevs::DESS< X >.
int adevs::rk4< X >::getNumStateVars | ( | ) | const [inline] |
Get the number of state variables.
const double* adevs::rk4< X >::getStateVars | ( | ) | const [inline] |
Get read-only access to the state variable array.
void adevs::rk4< X >::init | ( | int | i, | |
double | q0 | |||
) | [inline] |
Initialize the ith state variable
double adevs::rk4< X >::next_event_func | ( | bool & | is_event | ) | [inline, virtual] |
This function should return the time until the next state or time event in the continuous system. This method can also return the time until the next integration step, in which case the variable is_event should be set to false. If the is_event flag is true, then next state change will be treated as an internal event of the DEVS model.
Implements adevs::DESS< X >.
References adevs::rk4< X >::state_event_func(), and adevs::rk4< X >::time_event_func().
void adevs::rk4< X >::state_changed | ( | ) | [inline, virtual] |
This method is executed initially (i.e., at simulation start or just following creation if added dynamically), after every evaluation of the evolution function, and after every evaluation of the discrete_action_func method. This method is intended to facilitate writing the continuous system trajectory to an output file. The overridden method should call some integrator specific method that the user can implement for that purpose.
Implements adevs::DESS< X >.
References adevs::rk4< X >::state_changed().
Referenced by adevs::rk4< X >::state_changed().
virtual void adevs::rk4< X >::state_changed | ( | const double * | q | ) | [inline, virtual] |
This method is called initially and whenever a state change due to an event or integration step occurs. It is meant to be used for recording the state trajectory of the model.
virtual void adevs::rk4< X >::state_event_func | ( | const double * | q, | |
double * | z | |||
) | [pure virtual] |
This function should fill the array z with the value of the zero crossing functions. The z array will have a number of entries equal to the zero_crossing_funcs argument that was passed to the constructor. An event occurs when any of these functions are equal to zero.
Referenced by adevs::rk4< X >::next_event_func().
virtual double adevs::rk4< X >::time_event_func | ( | const double * | q | ) | [pure virtual] |
This method is used to schedule time event. The returned value is the time remaining until the next time event.
Referenced by adevs::rk4< X >::next_event_func().