You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Stephen Berry edited this page Sep 18, 2017
·
1 revision
Ascent provides a Sampler class, which changes the time step according to desired sampling rates and events.
Example
#include"ascent/Ascent.h"usingnamespaceasc;structODE
{
voidoperator()(conststate_t& x, state_t& xd, constdouble t)
{
xd[0] = cos(t);
}
};
intmain()
{
state_t x = { 0.0 };
double t = 0.0;
double dt = 0.1;
double t_end = 10.0;
RK4 integrator;
ODE system;
Recorder recorder;
while (t < t_end)
{
Sampler sampler(t, dt);
// We force the system to be evaluated at all increments of 0.33 and 0.41, as well as trigger a single event evaluation at 0.617if (sampler(0.33) || sampler(0.41) || sampler.event(0.617))
recorder({ t, x[0] });
integrator(system, x, t, dt);
}
recorder.csv("sampling", { "t", "x0" }); // generate a file of comma separated valuesreturn0;
}