SIMLIB/C++
3.09
Toggle main menu visibility
Loading...
Searching...
No Matches
examples/wheel.cc
mass+spring+damper
////////////////////////////////////////////////////////////////////////////
// Model wheel.cc SIMLIB/C++
//
// Wheel on spring with damper model (Version 1)
//
// System description (governing equation):
// y'' = ( F - D * y' - k * y ) / M
// where:
// M is wheel mass
// y height of wheel center
// D damping coefficient
// k stiffness of spring
// F input force
//
#include "
simlib.h
"
struct
Wheel {
// wheel model
Integrator v, y;
Wheel(Input
F
,
double
M,
double
D,
double
k):
v( (
F
- D*v - k*y) / M ),
// speed
y( v ) {}
// height
};
// objects
Constant
F
(100);
// constant input force
Wheel w(
F
, 10, 500, 5e4);
// model
// print model state
void
Sample
() {
Print(
"%6.3f %.4g %.4g\n"
, T.
Value
(), w.y.Value(), w.v.Value());
}
Sampler
S
(
Sample
, 0.001);
// periodic sampling
int
main
() {
// experiment description
SetOutput
(
"wheel.dat"
);
Print
(
"# wheel --- model of wheel+spring+damper\n"
);
Print
(
"# Time y v \n"
);
Init
(0, 0.5);
// set initial state and time
SetStep
(1e-3, 0.1);
// numerical method step size range
SetAccuracy
(1e-5, 0.001);
// allowed (abs.+rel.) error tolerance
Run
();
// simulation run
SIMLIB_statistics
.
Output
();
// print run statistics
}
S
Sampler S(Sample, 1)
F
Constant F(1.0)
Sample
void Sample()
Definition
_test_.cc:38
main
int main()
Definition
_test_.cc:44
simlib3::aContiBlock::Value
virtual double Value()=0
simlib3::SetOutput
void SetOutput(const char *name)
Definition
print.cc:50
simlib3::SetStep
void SetStep(double _dtmin, double _dtmax)
Definition
intg.cc:92
simlib3::Run
void Run()
run simulation experiment
Definition
run.cc:228
simlib3::Print
int Print(const char *fmt,...)
for Output methods, can be redirected
Definition
print.cc:92
simlib3::Init
void Init(double t0, double t1=SIMLIB_MAXTIME)
Definition
simlib.h:186
simlib3::SetAccuracy
void SetAccuracy(double _abserr, double _relerr)
Definition
intg.cc:106
simlib3::SIMLIB_statistics
const SIMLIB_statistics_t & SIMLIB_statistics
interface to internal run-time statistics structure
Definition
run.cc:78
simlib.h
Main SIMLIB/C++ interface.
simlib3::SIMLIB_statistics_t::Output
void Output() const
print run-time statistics to output
Definition
output1.cc:63
Generated on
for SIMLIB/C++ by
1.18.0