#include <stdlib.h>
struct Wheel {
Parameter M, D, k;
Integrator v, y;
Wheel(Input
F,
double _M,
double _D,
double _k):
M(_M), D(_D), k(_k),
v( (
F - D*v - k*y) / M ),
y( v ) { }
void SetM(double _M) { M=_M; }
void SetD(double _D) { D=_D; }
void Setk(double _k) { k=_k; }
void PrintParameters() {
Print("# mass = %g kg ", M.Value());
Print(" damping = %g ", D.Value());
Print(" stiffness = %g \n", k.Value());
}
};
double _m=5, _d=500, _k=5e4;
Print(
"%6.3f %.4g %.4g\n", T.
Value(), w.y.Value(), w.v.Value());
}
int main(
int argc,
char *argv[]) {
Print(
"# wheel2 --- multiple experiments\n");
if(argc==4) {
_m = atof(argv[1]);
_d = atof(argv[2]);
_k = atof(argv[3]);
}
for(double m=_m/2; m<=_m*5; m*=1.2) {
w.SetM(m);
w.SetD(_d);
w.Setk(_k);
w.PrintParameters();
}
}
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 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