Ascent  0.1.1
An open source architecture for time-based simulations.
asc::Module Class Reference

#include <Module.h>

Inheritance diagram for asc::Module:

Public Member Functions

 Module (size_t sim)
 
void integrationTolerance (double tolerance)
 
bool error (const std::string &description)
 
std::pair< bool, std::vector< std::string > > error ()
 
void printErrors (bool b)
 
bool run (const double dt, const double tend)
 
bool run ()
 
void dtChange (double new_dt)
 
const std::vector< double > & timeHistory () const
 
template<typename T >
std::deque< T > history (const std::string &id)
 
template<typename T >
void runBefore (Link< T > &link)
 
template<typename T , typename... Trest>
void runBefore (Link< T > &link, Trest &...rest)
 
void runBefore (Module &module)
 
template<typename... Trest>
void runBefore (Module &module, Trest &...rest)
 
std::string name () const
 
template<typename T >
bool name (const std::string &name)
 
void directory (const std::string &directory)
 
template<typename T >
Link< T > linkFromThis ()
 
bool trackable (const std::string &var_name)
 
void track (const std::string &var_name)
 
void track (Module &module, const std::string &var_name)
 
template<typename T >
void track (Link< T > &link, const std::string &var_name)
 
void outputTrack ()
 
void txtFiles ()
 
template<typename T , typename... Types>
asc::Link< T > addManipulator (Types &&...args)
 

Public Attributes

bool frozen = false
 
bool freeze_integration = false
 
bool stop = false
 
const double & t
 
const double & dt
 
const bool & first_update = simulator.tickfirst
 
const bool & first_report = simulator.tickfirst
 
const bool & last_report = simulator.ticklast
 
const bool & time_advanced = simulator.time_advanced
 
const size_t sim
 
const size_t module_id
 
ChaiEnginechai
 

Protected Member Functions

void stopSimulation (bool b=true)
 
void addIntegrator (double &x, double &xd, const double tolerance=-1.0)
 
template<typename T >
void addIntegrator (T &x, T &xd, const double tolerance=-1.0)
 
virtual void init ()
 
virtual void update ()
 
virtual void postcalc ()
 
virtual void check ()
 
virtual void report ()
 
virtual void reset ()
 
template<typename T >
T & define (const std::string &id, T &x, bool infinite=false)
 
void steps (const std::string &id, size_t steps)
 
void steps (const std::string &id, bool infinite=true)
 
bool sample () const
 
bool sample (double sdt)
 
bool event (double t_event)
 
void addStopper (Module &module)
 
template<typename T >
void addStopper (Link< T > &module)
 
template<typename T , typename... Trest>
void addStopper (Link< T > &first, Trest &...rest)
 

Friends

template<typename T >
class Link
 
class Simulator
 
class Stopper
 
template<typename E >
class HistoryVector
 
template<typename T >
void integrator (size_t sim)
 
void integrationTolerance (size_t sim, const double tolerance)
 

Detailed Description

Provides the core functionality of the Ascent architecture. A module in Ascent should always inherit from the Module class.

Member Function Documentation

void asc::Module::addIntegrator ( double &  x,
double &  xd,
const double  tolerance = -1.0 
)
protected

Add a state and its derivative to be integrated.

Parameters
xState.
xdState derivative.
toleranceThe integration tolerance for this state. Only applicable when using an adaptively stepping integration method. The default negative tolerance means that this state will not be considered for adaptive stepping, even if an adaptive solver is used.
template<typename T >
void asc::Module::addIntegrator ( T &  x,
T &  xd,
const double  tolerance = -1.0 
)
inlineprotected

Add a std::vector, std::deque, Eigen::Vector3d, etc. to be integrated.

Parameters
xState vector.
xdState derivatives vector.
toleranceThe integration tolerance for these states. Only applicable when using an adaptively stepping integration method. The default negative tolerance means that this state will not be considered for adaptive stepping, even if an adaptive solver is used.
template<typename T , typename... Types>
asc::Link<T> asc::Module::addManipulator ( Types &&...  args)
inline

Generate a manipulator module whose memory is owned by this module as long as the manipulator isn't also stored elsewhere (if Link<T> isn't saved). Manipulators should usually only mess with parameters from this module. Manipulators are ordered via the runBefore method, so they always run before the module they are manipulating.

void asc::Module::addStopper ( Module module)
inlineprotected

Add an uncontained module as a stopper. Uncontained modules must be added one at a time.

template<typename T >
void asc::Module::addStopper ( Link< T > &  module)
inlineprotected

Add a Link contained module as a stopper.

template<typename T , typename... Trest>
void asc::Module::addStopper ( Link< T > &  first,
Trest &...  rest 
)
inlineprotected

Add a collection of Link contained module as a cummulative stopper.

virtual void asc::Module::check ( )
inlineprotectedvirtual

Called at the end of every full time step before report() in order to check whether the simulation should be stopped (set stoppers here).

template<typename T >
T& asc::Module::define ( const std::string &  id,
T &  x,
bool  infinite = false 
)
inlineprotected

Enables a variable in this Module to be tracked and/or externally accessed and set.

Parameters
idThe string identification used to access the variable.
xVariable to be tracked via a pointer. Hence the variable's memory should be owned by this class.
infiniteSet infinite to true in order to record history of the variable indefinitely.
void asc::Module::directory ( const std::string &  directory)
inline

Sets a new default directory for output files.

void asc::Module::dtChange ( double  new_dt)
inline

Change the time step of this module's simulator.

Parameters
new_dtNew time step size.
bool asc::Module::error ( const std::string &  description)
inline

Puts this module's simulator in an error state, which will shut down the simulator as soon as possible.

Parameters
descriptionDescribe the error. Collected errors are retrieved via the getError() method.
Returns
Always returns false.
std::pair<bool, std::vector<std::string> > asc::Module::error ( )
inline

Check if the simulator is in an error state and get a vector of recorded error descriptions.

Returns
Returns a pair whose first value is true if the simulator is in an error state. The second value is a vector of error descriptions.
bool asc::Module::event ( double  t_event)
inlineprotected

Discrete run time event.

Parameters
t_eventThe time of the desired event.
Returns
Returns true if at the first pass of the integration method and at the specified event time (t_event).
template<typename T >
std::deque<T> asc::Module::history ( const std::string &  id)
inline

Obtain time history of a tracked variable.

Parameters
idThe string identification of the variable.
Returns
Returns a pair of time history matched with the variable's state history.
virtual void asc::Module::init ( )
inlineprotectedvirtual

For initialization computations.

void asc::Module::integrationTolerance ( double  tolerance)
inline

Set relative error integration tolerance for this module's states.

Parameters
toleranceThe integration tolerance for this module's states. A negative value turns off step resizing for this module's states.
template<typename T >
Link<T> asc::Module::linkFromThis ( )
inline

Generate a Link<T> container from this class; similar to std::shared_from_this().

std::string asc::Module::name ( ) const

Access this module's name, which is printed with output data.

template<typename T >
bool asc::Module::name ( const std::string &  name)
inline

Define this module for external access.

Parameters
nameUsed in output files if this module is used for tracking.
void asc::Module::outputTrack ( )

Create output file for this Module's tracked parameters.

virtual void asc::Module::postcalc ( )
inlineprotectedvirtual

Runs once per full integration step and after propagate states for computations based on updated states, runs before check() and report().

void asc::Module::printErrors ( bool  b)
inline

Set whether or not error messages should be printed to the console.

virtual void asc::Module::report ( )
inlineprotectedvirtual

End of full time step report (for a 4th order Runge Kutta, report() is called once after four update() calls).

virtual void asc::Module::reset ( )
inlineprotectedvirtual

Used to reset Module parameters after update() and report() have been called (runs for internal kpass steps as well).

bool asc::Module::run ( const double  dt,
const double  tend 
)
inline

Runs this module's associated simulator.

Parameters
dtThe time step of for the simulator.
tendThe end time to run the simulator until.
bool asc::Module::run ( )
inline

Runs this module's associated simulator at currently set dt and tend values.

template<typename T >
void asc::Module::runBefore ( Link< T > &  link)
inline

Specifies that the module within the link container must run before this module. The runBefore method applies to the update() and postcalc() simulation phases.

Parameters
linkA Link contained module.
template<typename T , typename... Trest>
void asc::Module::runBefore ( Link< T > &  link,
Trest &...  rest 
)
inline

A variadic implementation of runBefore(Link<T>& link).

Parameters
linkThe first module that must run before this module.
restAny number of modules that must be run before this module. Example:
runBefore(spring0, damper1, spring4);
Within the update() and postcalc() phases, this Module will run before the spring0, damper1, and spring4 update() and postcalc() methods.
void asc::Module::runBefore ( Module module)
inline

Specifies that the module within the link container must run before this module. The runBefore method applies to the update() and postcalc() simulation phases.

template<typename... Trest>
void asc::Module::runBefore ( Module module,
Trest &...  rest 
)
inline

A variadic implementation of runBefore(Module& module).

Parameters
moduleThe first module that must run before this module.
restAny number of modules that must be run before this module.
bool asc::Module::sample ( ) const
inlineprotected

Discrete sampling per time step.

Returns
Returns true if at the first pass of the integration method.
bool asc::Module::sample ( double  sdt)
inlineprotected

Discrete sampling with a specified sampling rate. The simulator will be stepped to exact multiples of the sampling rate.

Parameters
sdtThe sampling rate. This number doesn't need to be fixed and is allowed to be changed during the simulation.
Returns
Returns true if at the first pass of the integration method at the specified sampling time.
void asc::Module::steps ( const std::string &  id,
size_t  steps 
)
inlineprotected

Set the number of time steps to keep track of for a tracked variable.

Parameters
idThe string identification of the variable.
stepsThe number of steps to keep track of.
void asc::Module::steps ( const std::string &  id,
bool  infinite = true 
)
inlineprotected

Set a variable to be tracked indefinitely; in other words, to have an infinite number of steps recorded.

Parameters
idThe string identification of the variable.
infiniteWhether or not to have an infinite number of steps tracked.
void asc::Module::stopSimulation ( bool  b = true)
inlineprotected

Stops this Module's simulator at the end the current integration step.

Parameters
bAllows the command to stop the simulation to be turned on and off, so module's can compete and ordering can decide ending the simulation.
const std::vector<double>& asc::Module::timeHistory ( ) const
inline

Retrieve a vector of the time history, with the time at each full step recorded.

void asc::Module::track ( const std::string &  var_name)

Specify a variable to be tracked.

Parameters
var_nameAssociated variable name.
void asc::Module::track ( Module module,
const std::string &  var_name 
)

Specify a variable to be tracked.

Parameters
moduleAn uncontained Module.
var_nameAssociated variable name.
template<typename T >
void asc::Module::track ( Link< T > &  link,
const std::string &  var_name 
)
inline

Specify a variable in a Link contained Module to be tracked.

Parameters
linkLink contained Module.
var_nameAssociated variable name.
bool asc::Module::trackable ( const std::string &  var_name)
inline

Check if a variable in a module is setup for tracking.

Parameters
module_idModule ID for the module that contains the variable of interest.
var_nameAssociated variable name.
Returns
Returns true if the variable was setup for tracking.
void asc::Module::txtFiles ( )
inline

Change output file type to .txt instead of .csv

virtual void asc::Module::update ( )
inlineprotectedvirtual

Called for every kpass internal step (for example: called four times for a 4th order Runge Kutta integrator).

Friends And Related Function Documentation

void integrationTolerance ( size_t  sim,
const double  tolerance 
)
friend

Set the relative error integration tolerance for the entire simulator associated with this module.

Parameters
simThe simulator number.
toleranceThe integration tolerance. If negative, it will turn off step resizing for all states in this module's simulator.
template<typename T >
void integrator ( size_t  sim)
friend

Set the integrator for the simulator whose number is input.

Parameters
simThe simulator number.

Member Data Documentation

ChaiEngine& asc::Module::chai

ChaiScript interface, unique to the simulator that this module belongs to.

const double& asc::Module::dt

The simulator's current time step size.

const bool& asc::Module::first_report = simulator.tickfirst

True if at the first report of the current simulation run.

const bool& asc::Module::first_update = simulator.tickfirst

True if at the first update of the current simulation run. True only for the first pass on update() for the current run() call.

bool asc::Module::freeze_integration = false

Specifies whether the integration (state propagation) should be frozen for this module.

bool asc::Module::frozen = false

Specifies whether the module should be frozen (init(), update(), postcalc(), check(), report(), reset(), and integration (state propagation) will not be called on the module), useful for testing purposes or handling stages.

const bool& asc::Module::last_report = simulator.ticklast

True if at the final report for the current simulation run.

const size_t asc::Module::module_id

This Module's unique identification across all simulators.

const size_t asc::Module::sim

This Module's simulator identification.

bool asc::Module::stop = false

Whether this module wants to stop the simulation, used for building stoppers.

const double& asc::Module::t

The simulator's current time.

const bool& asc::Module::time_advanced = simulator.time_advanced

If time advanced in the last simulation pass


The documentation for this class was generated from the following file: