Bouncing ball example.
const double g = 9.81;
class Ball : ConditionDown {
Integrator v,y;
unsigned count;
void Action() {
Print("# Bounce#%u:\n", ++count);
Out();
v = -0.8 * v.Value();
y = 0;
if(count>=20)
Stop();
}
public:
Ball(double initialposition) :
ConditionDown(y),
v(-g),
y(v, initialposition),
count(0) {}
void Out() {
Print("%-9.3f % -9.3g % -9.3g\n",
T.
Value(), y.Value(), v.Value());
}
};
Ball m1(1.0);
Print(
"# Ball --- model of bouncing ball\n");
}
virtual double Value()=0
get block output value this method should be defined in classes derived from aContiBlock
void SetAccuracy(double _abserr, double _relerr)
set max.
void SetStep(double _dtmin, double _dtmax)
Set integration step interval.
void SetOutput(const char *name)
redirects Output(), Print() to file
void Run()
run simulation experiment
int Print(const char *fmt,...)
for Output methods, can be redirected
void Init(double t0, double t1=SIMLIB_MAXTIME)
Initialize simulator and model time.
const SIMLIB_statistics_t & SIMLIB_statistics
interface to internal run-time statistics structure
Main SIMLIB/C++ interface.
void Output() const
print run-time statistics to output