SIMLIB/C++  3.07
_test_.cc
Go to the documentation of this file.
1 
2 //! \file _test_.cc Simple test model.
3 
4 #define SIMLIB_DEBUG
5 
6 // next define guards against excessive use of WaitUntil
7 #define I_REALLY_KNOW_HOW_TO_USE_WAITUNTIL
8 #include "simlib.h"
9 
10 struct Test {
15  limitation( v, -1, 1),
16  v( Sin(T)*F, 0.5 ),
17  y( limitation*F, 1) {}
18 };
19 
20 class TestProcess : public Process {
21  public:
22  void Behavior() override {
23  Wait(1);
24  Wait(1);
25  WaitUntil(Time>3);
26  WaitUntil(true);
27  Wait(5);
28  }
29 };
30 
31 // objects ...
32 //Problem!!! Constant F = 1.0; // no copy ctr available
33 Constant F(1.0);
34 Test t(F); //
36 
37 // sampling ...
38 void Sample() {
39  Print("%f %f %f\n", T.Value(), t.y.Value(), t.v.Value());
40 }
41 Sampler S(Sample, 1); // periodic event
42 
43 
44 int main() { // popis experimentu ...
45  Print("Model _TEST_ --- test model for SIMLIB/C++ \n");
46  Init(0,5); //
47  SetStep(0.1,1.0); //
48  SetAccuracy(1e-5,0.01); //
49  (new TestProcess)->Activate();
50  globalprocess.Activate();
51 //DebugOFF();
52  Run(); // simulation
53  Print("# end of test t=%g\n", Time);
54 //DebugON();
55  return 0;
56 }
57 
58 // end
void Behavior() override
behavior description
Definition: _test_.cc:22
void SetAccuracy(double _abserr, double _relerr)
set max.
Definition: intg.cc:106
nonlinear block: limitation
Definition: simlib.h:1556
Test(Input F)
Definition: _test_.cc:14
Sampler S(Sample, 1)
Integrator v
Definition: _test_.cc:12
State variables (memory) base for blocks with internal state (Relay, ...)
Definition: simlib.h:1335
Input Sin(Input x)
Definition: fun.cc:96
continuous block connection (transparent reference) wrapper for pointer to objects of aContiBlock der...
Definition: simlib.h:895
Status y
Definition: _test_.cc:13
void Run()
run simulation experiment
Definition: run.cc:228
aContiBlock & T
simulation time block reference
Definition: continuous.cc:276
virtual double Value() override
value of state variable
Definition: intg.cc:448
int Print(const char *fmt,...)
for Output methods, can be redirected
Definition: print.cc:92
objects of this class call global function periodically (typicaly used for output of continuous model...
Definition: simlib.h:506
const double & Time
model time (is NOT the block)
Definition: run.cc:48
void SetStep(double _dtmin, double _dtmax)
Set integration step interval.
Definition: intg.cc:92
Lim limitation
Definition: _test_.cc:11
Test t(F)
void Sample()
Definition: _test_.cc:38
TestProcess globalprocess
Definition: _test_.cc:35
void Init(double t0, double t1=SIMLIB_MAXTIME)
Initialize simulator and model time.
Definition: simlib.h:181
Constant F(1.0)
void Activate(Entity *e)
activate entity e
Definition: simlib.h:431
virtual void Activate(double t) override
activate at time t (schedule)
Definition: process.cc:323
Main SIMLIB/C++ interface.
block: constant (value can not be changed)
Definition: simlib.h:848
Abstract base class for all simulation processesProcess behavior is specified by Behavior method and ...
Definition: simlib.h:440
int main()
Definition: _test_.cc:44
virtual double Value()=0
get block output value this method should be defined in classes derived from aContiBlock ...
block for numerical integration input is derivative, output is state
Definition: simlib.h:1288
Definition: _test_.cc:10
double Value() override
the state of integrator
Definition: intg.cc:249