SIMLIB/C++
3.09
Toggle main menu visibility
Loading...
Searching...
No Matches
_test_.cc
This is simple example for basic testing of SIMLIB/C++.
Usage: make test
//! \file _test_.cc Simple test model.
#define SIMLIB_DEBUG
// next define guards against excessive use of WaitUntil
#define I_REALLY_KNOW_HOW_TO_USE_WAITUNTIL
#include "
simlib.h
"
struct
Test
{
Lim
limitation
;
Integrator
v
;
Status
y
;
Test
(Input
F
):
limitation
(
v
, -1, 1),
v
(
Sin
(
T
)*
F
, 0.5 ),
y
(
limitation
*
F
, 1) {}
};
class
TestProcess
:
public
Process
{
public
:
void
Behavior
()
override
{
Wait
(1);
Wait
(1);
WaitUntil(
Time
>3);
WaitUntil(
true
);
Wait
(5);
}
};
// objects ...
//Problem!!! Constant F = 1.0; // no copy ctr available
Constant
F
(1.0);
Test
t
(
F
);
//
TestProcess
globalprocess
;
// sampling ...
void
Sample
() {
Print
(
"%f %f %f\n"
,
T
.
Value
(),
t
.
y
.
Value
(),
t
.
v
.
Value
());
}
Sampler
S
(
Sample
, 1);
// periodic event
int
main
() {
// popis experimentu ...
Print
(
"Model _TEST_ --- test model for SIMLIB/C++ \n"
);
Init
(0,5);
//
SetStep
(0.1,1.0);
//
SetAccuracy
(1e-5,0.01);
//
(
new
TestProcess
)->
Activate
();
globalprocess
.
Activate
();
//DebugOFF();
Run
();
// simulation
Print
(
"# end of test t=%g\n"
, Time);
//DebugON();
return
0;
}
// end
t
Test t(F)
S
Sampler S(Sample, 1)
globalprocess
TestProcess globalprocess
Definition
_test_.cc:35
F
Constant F(1.0)
Sample
void Sample()
Definition
_test_.cc:38
main
int main()
Definition
_test_.cc:44
TestProcess
Definition
_test_.cc:20
TestProcess::Behavior
void Behavior() override
behavior description
Definition
_test_.cc:22
simlib3::Integrator::Value
double Value() override
the state of integrator
Definition
intg.cc:249
simlib3::Process::Wait
virtual void Wait(double dtime)
wait for dtime interval
Definition
process.cc:256
simlib3::Process::Activate
virtual void Activate(double t) override
activate at time t (schedule)
Definition
process.cc:244
simlib3::Process::Process
Process(Priority_t p=DEFAULT_PRIORITY)
Process constructor sets state to PREPARED.
Definition
process.cc:173
simlib3::Status::Value
virtual double Value() override
value of state variable
Definition
intg.cc:448
simlib3::aContiBlock::Value
virtual double Value()=0
simlib3::Activate
void Activate(Entity *e)
activate entity e
Definition
simlib.h:436
simlib3::Time
const double & Time
model time (is NOT the block)
Definition
run.cc:48
simlib3::T
aContiBlock & T
simulation time block reference
Definition
continuous.cc:276
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::Sin
Input Sin(Input x)
Definition
fun.cc:96
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
simlib.h
Main SIMLIB/C++ interface.
Test
Definition
_test_.cc:10
Test::limitation
Lim limitation
Definition
_test_.cc:11
Test::Test
Test(Input F)
Definition
_test_.cc:14
Test::v
Integrator v
Definition
_test_.cc:12
Test::y
Status y
Definition
_test_.cc:13
Generated on
for SIMLIB/C++ by
1.18.0