SIMLIB/C++ 3.09
Loading...
Searching...
No Matches
simlib.h
Go to the documentation of this file.
1/////////////////////////////////////////////////////////////////////////////
2//! \file simlib.h Main SIMLIB/C++ interface.
3//!
4//! \defgroup simlib SIMLIB/C++
5
6#ifndef __SIMLIB__
7
8#define __SIMLIB__ 0x0309 // version of SIMLIB (numerical)
9#define SIMLIB_VERSION "3.09" // version of SIMLIB (string)
10
11#define SIMLIB_COPYRIGHT "(c) Petr Peringer, 1991-2022"
12// -------------------------------------------------------------------------
13// SIMLIB/C++ (SIMulation LIBrary for C++)
14// -------------------------------------------------------------------------
15// This library is free software; you can redistribute it and/or
16// modify it under the terms of the GNU Library General Public
17// License as published by the Free Software Foundation; either
18// version 2 of the License, or (at your option) any later version.
19//
20// This library is distributed in the hope that it will be useful,
21// but WITHOUT ANY WARRANTY; without even the implied warranty of
22// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23// Library General Public License for more details.
24//
25// You should have received a copy of the GNU Library General Public
26// License along with this library; if not, write to the Free Software
27// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
28// USA.
29// -------------------------------------------------------------------------
30//
31// This is main header file for SIMLIB/C++
32//
33// Supported platforms:
34// Linux: GNU C++ compiler, architectures: i386+, x86_64
35// Portable to:
36// FreeBSD: GNU C++, i386+
37// Windows XP: MinGW
38//
39// Send bug reports to: peringer AT fit.vutbr.cz
40//
41
42#ifndef __cplusplus
43# error "Use C++ compiler, please."
44#endif
45
46#if (__cplusplus < 201103L)
47# error "Use C++11 (or newer) compiler, please."
48#endif
49
50////////////////////////////////////////////////////////////////////////////
51// includes
52#include <cstdlib> // size_t
53#include <list> // std::list<>
54#include <string> // std::string
55
56// /////////////////////////////////////////////////////////////////////////
57//! \namespace simlib3 Main SIMLIB (version 3+) namespace.
58//!
59//! Usage: using namespace simlib3;
60namespace simlib3 {
61
62extern const unsigned SIMLIB_version; // for header compatibility check only
63const char *SIMLIB_version_string(); // get SIMLIB version string
64
65////////////////////////////////////////////////////////////////////////////
66// System and compiler dependent part
67#if defined(__MSDOS__)
68# error "MSDOS not supported - please, use older version of SIMLIB"
69
70#elif defined(__linux__) && defined(__GNUC__)
71
72# define SIMLIB_SYSTEM "Linux"
73# define SIMLIB_COMPILER "GNU C++"
74
75#elif defined(__WIN32__)
76
77# define SIMLIB_SYSTEM "WIN32"
78# if defined(__BCPLUSPLUS__)
79# define SIMLIB_COMPILER "Borland C++"
80# elif defined(__GNUC__)
81# define SIMLIB_COMPILER "GNU C++"
82# endif
83
84#elif defined(__DragonFly__) && defined(__GNUC__)
85
86# define SIMLIB_SYSTEM "DragonFly"
87# define SIMLIB_COMPILER "GNU C++"
88
89#elif defined(__FreeBSD__) && defined(__GNUC__)
90
91# define SIMLIB_SYSTEM "FreeBSD"
92# define SIMLIB_COMPILER "GNU C++"
93
94#else
95# warning "SIMLIB is not tested on this system/compiler"
96#endif
97
98////////////////////////////////////////////////////////////////////////////
99// DEBUGGING: print debug info ON/OFF/mode
100//
101void DebugON(); //!< start debugging output
102void DebugOFF(); //!< stop debugging output
103unsigned long Debug(unsigned long mode=~0UL); // start/stop partial debugging
104// experimental code for start/stop debugging at global level
105#ifdef SIMLIB_DEBUG
106static unsigned long SIMLIB_old_debug_flags = Debug(SIMLIB_DEBUG);
107#endif
108
109////////////////////////////////////////////////////////////////////////////
110// overwiew of basic SIMLIB classes (abstractions)
111//
112
113class SimObject; // base abstract class
114// discrete:
115class Link; // list item base class (Simula-like)
116class Entity; // discrete model entity
117class Process; // process base
118class Event; // event base
119class Sampler; // periodic calls of global function
120class List; // list of objects of class Link descendants
121class Queue; // priority queue
122class Stat; // statistics
123class TStat; // time dependent statistics
124class Histogram; // histogram
125class Facility; // SOL-like facility
126class Store; // SOL-like store
127class Barrier; // barrier
128class Semaphore; // semaphore
129// continuous:
130class aBlock; // abstract block
131class aContiBlock; // blocks with continuous output
132class Integrator; // integrator
133class Status; // status variables
134class Hyst; // hysteresis
135class Blash; // backlash
136class Relay; // general relay
137class Function; // general function
138class Constant; // constant
139class Variable; // variable
140class Parameter; // parameter (simulation run constant)
141// combined:
142class aCondition; // state condition base class
143class Condition; // state event detector (Boolean version)
144class ConditionUp; // action by FALSE-->TRUE change
145class ConditionDown; // action by TRUE-->FALSE
146
147////////////////////////////////////////////////////////////////////////////
148// CATEGORY: global constants
149
150////////////////////////////////////////////////////////////////////////////
151// model time limits
152const double SIMLIB_MINTIME = 0.0; //!< minimal time value
153const double SIMLIB_MAXTIME = 1.0e30; //!< maximum time (1e30 works for float, too)
154
155////////////////////////////////////////////////////////////////////////////
156// CATEGORY: global variables
157// Warning: NOT THREAD-SAFE! --- TODO: change to methods of SimulationContext
158
159extern Entity *const &Current; //!< pointer to active (now running) entity
160
161// time values:
162extern const double & StartTime; //!< time of simulation start
163extern const double & NextTime; //!< next-event time
164extern const double & EndTime; //!< time of simulation end
165
166// WARNING: Time cannot be used in block expressions!
167extern const double & Time; //!< model time (is NOT the block)
168extern aContiBlock & T; //!< model time (continuous block)
169
170// read-only step limits of numerical integration method
171extern const double &MinStep; //!< minimal step size
172extern const double &StepSize; //!< current step size
173extern const double &OptStep; //!< optimal step size
174extern const double &MaxStep; //!< maximal step size
175
176// error params for numerical integration methods
177extern const double &AbsoluteError; //!< max absolute error
178extern const double &RelativeError; //!< max relative error
179
180////////////////////////////////////////////////////////////////////////////
181// CATEGORY: global functions ...
182
183//! Initialize simulator and model time
184//! @param t0 simulation start time
185//! @param t1 simulation end time
186inline void Init(double t0, double t1=SIMLIB_MAXTIME) {
187 extern void SIMLIB_Init(double t0, double t1, unsigned version);
188 SIMLIB_Init(t0,t1,__SIMLIB__); // version consistency check
189}
190
191//! Set calendar implementation.
192//! @param name String identification of calendar: "list", "cq"
193void SetCalendar(const char *name);
194
195//! Set integration step interval.
196//! @param dtmin min. step size
197//! @param dtmax max. step size (can be slightly increased)
198void SetStep(double dtmin, double dtmax);
199//! set fixed integration step
200//! @param dt (almost) fixed step size
201inline void SetStep(double dt) { SetStep(dt,dt); }
202
203//! set max. error estimate for numerical integration method
204//! used for adaptive stepsize control
205//! @param abserr absolute tolerance
206//! @param relerr tolerance relative to integrator value
207void SetAccuracy(double abserr, double relerr);
208//! set max. relative error estimate for numerical integration method
209//! @param relerr tolerance relative to integrator value
210void SetAccuracy(double relerr);
211
212//! run simulation experiment
213void Run();
214//! stop current simulation run
215void Stop();
216//! end simulation program
217void Abort();
218
219//! print message and terminate program
220[[noreturn]] void Error(const char *fmt, ...);
221
222// TODO: convert to iostreams (SIMLIB4)
223//! for Output methods, can be redirected
224int Print(const char *fmt, ...);
225//! output of messages to stdout, too
226//! @param fmt format string (the same as for printf() )
227int _Print(const char *fmt, ...);
228
229//! output single value
230//! @param x value to print
231int Print(const double x);
232//! output 2 values
233//! @param x value to print
234//! @param y value to print
235int Print(const double x, const double y);
236//! output 3 values
237//! @param x value to print
238//! @param y value to print
239//! @param z value to print
240int Print(const double x, const double y, const double z);
241
242//! redirects Output(), Print() to file
243//! @param name name of output file
244void SetOutput(const char *name);
245
246// functions for special blocks implementation (public)
247//! request for shorter step of num. integ.
248void ContractStep();
249//! request for step end (at most) at given time
250void ContractStep(double time);
251
252
253////////////////////////////////////////////////////////////////////////////
254// CATEGORY: pseudorandom number generators
255
256//! initialize random number seed
257//! @param seed initial value of generator state
258void RandomSeed(long seed);
259//! base uniform generator (range 0-0.999999...)
260//! the default implementation is simple LCG 32bit
261double Random();
262//! set another random generator
263//! default Random() implementation can be replaced
264//! @param new_gen pointer to user-defined function
265void SetBaseRandomGenerator(double (*new_gen)());
266
267// following generators depend on Random()
268//! Beta distribution generator @param th @param fi @param min @param max
269double Beta(double th, double fi, double min, double max);
270//! Erlang distribution generator @param alfa @param beta
271double Erlang(double alfa, int beta);
272//! Exponential distribution generator @param mv mean value
273double Exponential(double mv);
274//! Gamma distribution generator @param alfa @param beta
275double Gamma(double alfa, double beta);
276
277int Geom(double q);
278int HyperGeom(double p, int n, int m);
279double Logar(double mi, double delta);
280int NegBinM(double p,int m);
281int NegBin(double q, int k);
282
283//! Gauss distribution generator @param mi mean value @param sigma std. deviation
284double Normal(double mi, double sigma);
285//! Poisson distribution generator @param lambda
286int Poisson(double lambda);
287double Rayle(double delta);
288double Triag(double mod, double min, double max);
289//! Uniform distribution generator @param l low limit @param h high limit
290double Uniform(double l, double h);
291//! Weibul distribution generator @param lambda @param alfa
292double Weibul(double lambda, double alfa);
293
294
295////////////////////////////////////////////////////////////////////////////
296// CATEGORY: basics
297
298////////////////////////////////////////////////////////////////////////////
299//! Base class for almost all SIMLIB classes.
300//!
301//! - objects can have name
302//! - objects know if they are created dynamically (using new)
303//! \ingroup simlib
305 public:
306 enum _Flags { //!< internal flags (bitmasks: 1bit set)
308 _ALLOCATED_FLAG = 1<<0, // object is on heap
309 _EVAL_FLAG = 1<<1, // currently evaluated (aBlock)
310 _HAS_NAME_FLAG = 1<<2 // object has name (in dictionary)
311 };
312 protected:
313 unsigned _flags; //!< bool flags for internal use (TODO bitfield?)
314 public:
315 bool TestAndSetFlag(bool new_value, unsigned n); // internal use only
316 SimObject();
317 virtual ~SimObject();
318 void *operator new(size_t size); //!< allocate object, set _flags
319 void operator delete(void *ptr); //!< deallocate object
320 void *operator new[](size_t size) = delete;
321 void operator delete[](void *ptr) = delete;
322// TODO: FIXME inconsistent name:
323 bool isAllocated() const { return (_flags & _ALLOCATED_FLAG)!=0; }
324
325 virtual std::string Name() const; //!< get object name
326 bool HasName() const { return (_flags & _HAS_NAME_FLAG)!=0; }
327 void SetName(const std::string &name); //!< assign the name
328
329 // TODO: define friend operator <<
330 virtual void Output() const; //!< print object to default output
331 private:
332 SimObject(const SimObject &) = delete; //!< disable copy operation
333 SimObject &operator= (const SimObject &) = delete; //!< disable assign operation
334};
335
336////////////////////////////////////////////////////////////////////////////
337//! base class for all double-linked list items
338//! <br> item can be at single place only (identified by where() method)
339//! <br> used for Queue implementation
340//! \ingroup simlib
341class Link : public SimObject {
342 Link *pred; //!< previous object in List
343 Link *succ; //!< next object in List
344 List *head; //!< pointer to List (if any)
345 friend class List; // only list can access pred,succ,head
346 protected:
347 Link(Link *p, Link *s, List *h);
348 public:
349 Link();
350 virtual ~Link();
351 virtual void Into(List *l); //!< insert last
352 virtual void Out(); //!< remove from list
353 List *Where() { return head; } //!< where is linked
354 virtual bool isInQueue() { return Where()!=NULL; } //!< present in queue
355};
356
357////////////////////////////////////////////////////////////////////////////
358// CATEGORY: discrete blocks
359
360//! entity/process priority values
361//! <br> (Warning: changed from 0..255 in SIMLIB v 3.03)
362enum {
366};
367//! Priority of the process/event
368typedef signed char EntityPriority_t;
369//! Service priority (see Facility::Seize)
370typedef unsigned char ServicePriority_t;
371
372//! struct EventNotice is private to calendar implementation
373struct EventNotice; // we use only pointer to this class here
374
375////////////////////////////////////////////////////////////////////////////
376//! abstract base class for active entities (Process, Event)
377//! instances of derived classes provide Behavior() method implementation,
378//! execution can be scheduled in calendar
379//! \ingroup simlib
380class Entity : public Link {
381 protected:
382 static unsigned long _Number; //!< current number of entities
383 unsigned long _Ident; //!< unique identification number of entity
384 ////////////////////////////////////////////////////////////////////////////
385 // TODO: next attributes will be changed/removed:
386 // all should be in special records stored into queues
387 // Queue stores insertion time for statistics:
388 friend class Queue; // ### remove
389 double _MarkTime; // beginning of waiting in queue ###!!!
390 // Facility and Store use these data
391 friend class Facility;
392 friend class Store;
393 // TODO: this should be stored in queues at Facility/Store
394 union {
395 double _RemainingTime; // rest of time of interrupted service (Facility) ###
396 unsigned long _RequiredCapacity; // required store capacity of Store
397 };
398 ServicePriority_t _SPrio; //!< priority of service in Facility
399 ////////////////////////////////////////////////////////////////////////////
400 public:
401 unsigned long id() const { return _Ident; }
403 //! priority of the entity (scheduling,queues)
404 Priority_t Priority; //!< priority of the entity
406 virtual ~Entity();
407
408 // common interface for Events and Processes
409 operator Entity* () { return this; } // default conversion
410// virtual const char *Name() const; //!< name of the entity
411 double ActivationTime(); // get activation time if scheduled
412
413 void Activate() { Activate(Time); } //!< activate now
414 virtual void Activate(double t); //!< activate at time t (schedule)
415 virtual void Passivate(); //!< deactivation
416 virtual void Terminate() = 0; //!< end Behavior() and remove entity
417 bool Idle() { return _evn==0; } //!< entity activation is not scheduled in calendar
418 void Cancel() { Terminate(); } //!< end Behavior() and remove entity
419// virtual void Into(Queue *q); // insert itself into queue
420 virtual void Out() override; //!< remove entity from queue
421
422 private:
423 // Simulation control algorithm interface:
424 virtual void _Run() noexcept = 0; //!< run the Behavior() function
425 // friends:
426 friend void SIMLIB_DoActions(); // internal function - event dispatcher
427
428 // Calendar interface:
429 friend struct EventNotice; // internal calendar class sets _Ev
430 EventNotice *_evn; //!< points to calendar item, iff scheduled
431 public:
433};
434
435// global wrapper functions:
436inline void Activate(Entity *e) { e->Activate(); } //!< activate entity e
437inline void Passivate(Entity *e) { e->Passivate(); } //!< passivate entity e
438
439////////////////////////////////////////////////////////////////////////////
440//! Abstract base class for all simulation processes
441//! @ingroup process
442//! Process behavior is specified by Behavior method and can be interrupted
443//! during execution by e.g. Wait method call (it is a coroutine)
444//! \ingroup simlib
445class Process : public Entity {
446 void * _context; //!< process context pointer
447 virtual void _Run() noexcept override; // internal point of activation
448
449 //! possible process status values
453 bool isPrepared() const { return (_status==_PREPARED); } // before start
454 bool isCurrent() const { return (_status==_RUNNING); } // Behavior() runs
455 bool isInterrupted() const{ return (_status==_INTERRUPTED); } // can continue
456 bool isTerminated() const { return (_status==_TERMINATED); } // zombie
457
458 friend class WaitUntilList;
459 bool _wait_until; // waiting for condition
460 void _WaitUntilRemove();
461
462 public:
464 virtual ~Process();
465 virtual void Behavior() = 0; //!< behavior description
466 virtual void Output() const override; //!< print object to default output
467 virtual std::string Name() const override; //!< name of object
468 using Entity::Activate; // inherited: Activate()
469 virtual void Activate(double t) override; //!< activate at time t (schedule)
470 virtual void Passivate() override; //!< process deactivation (sleep)
471 virtual void Wait(double dtime); //!< wait for dtime interval
472 bool _WaitUntil(bool test); //!< wait for condition (slow!)
473#ifdef I_REALLY_KNOW_HOW_TO_USE_WAITUNTIL
474//! wait until the condition is true (lazy evaluation of condition)
475# define WaitUntil(condition) while(_WaitUntil(condition)) /*empty body*/;
476#endif
477 void Interrupt(); //!< test of WaitUntil list, allow running others
478 virtual void Terminate() override; //!< kill process
479
480 void Seize(Facility &f, ServicePriority_t sp=0); //!< seize facility
481 void Release(Facility &f); //!< release facility
482 void Enter(Store &s, unsigned long ReqCap=1); //!< acquire some capacity
483 void Leave(Store &s, unsigned long ReqCap=1); //!< return some capacity
484
485 using Entity::Into;
486 virtual void Into(Queue &q); //!< insert process into queue
487};
488
489////////////////////////////////////////////////////////////////////////////
490//! abstract base class for events
491//! Event behavior is simple function (can not be interrupted)
492//! \ingroup simlib
493class Event : public Entity {
494 virtual void _Run() noexcept override;
495 virtual void Terminate() override; // do not use (deprecated)
496 public:
498 virtual ~Event();
499 virtual void Behavior() = 0; //!< behavior description
500 virtual void Output() const override; //!< print object to default output
501 virtual std::string Name() const override; //!< name of object
502 // public inherited: Passivate(), Cancel()
503 virtual void Activate(double t) override; //!< activate at time t (schedule)
504 using Entity::Activate; // inherited: Activate()
505};
506
507////////////////////////////////////////////////////////////////////////////
508//! objects of this class call global function periodically
509//! (typicaly used for output of continuous model)
510//! \ingroup simlib
511class Sampler: public Event {
512 static Sampler *First; // list of objects TODO: use container
513 Sampler *Next; // next object
514 protected:
515 void (*function)(); //!< function to call periodically
516 double last; //!< last sample time -- prevents sample duplication
517 double step; //!< step of sampling
518 bool on; //!< switch on/off
519 virtual void Behavior() override; //!< behavior description
520 public:
521 Sampler(void (*pf)(), double dt=0.0);
522 virtual ~Sampler();
523 virtual void Output() const override; //!< print object to default output
524 void Start(); //!< start + sample
525 void Stop(); //!< sample + stop
526 void Sample(); //!< performs sample (function call)
527 double SetStep(double dt=0.0); //!< change step
528 double GetStep() const { return step; } //!< get current step
529 private:
530 static void InitAll(); //!< initialize all samplers (Init)
531 static void ActivateAll(); //!< start all samplers (Run)
532};
533
534
535////////////////////////////////////////////////////////////////////////////
536// CATEGORY: discrete blocks - pasive
537
538#ifdef new_version
539////////////////////////////////////////////////////////////////////////////
540//! abstract base class of all statistics
541//! TODO:
542class aStat : public SimObject {
543 protected:
544 double min; // minimal recorded value
545 double max; // maximal recorded value
546 unsigned long n; // number of values recorded
547 public:
548 //class aStatException {};
549 aStat();
550 aStat(const char *name);
551 ~aStat();
552 virtual void Clear() = 0; // initialize
553
554 virtual void operator () (double x) = 0; //!< record value
555 virtual void Record(double x) = 0; //!< record value
556
557 virtual double MeanValue() = 0; //!< compute mean value
558 double Min() const { /* test n==0 +exception */ return min; }
559 double Max() const { /* test n==0 */ return max; }
560 unsigned long NumberOfRecords() const { return n; }
561 virtual void Output() const override; //!< Print all values to output file
562};
563#endif
564
565////////////////////////////////////////////////////////////////////////////
566//! class for statistical information gathering
567//! \ingroup simlib
568class Stat : public SimObject {
569 protected:
570 double sx; // sum of values
571 double sx2; // sum of value square
572 double min; // min value
573 double max; // max value
574 unsigned long n; // number of values recorded
575 public:
576 Stat();
577 explicit Stat(const char *name);
578 ~Stat();
579 virtual void Clear(); //!< initialize
580 void operator () (double x); //!< record the value
581// Stat &operator = (Stat &x); // TODO: copy semantics
582// Stat &operator += (Stat &x); // sum two statistics + template operator +
583 virtual void Output() const override; //!< print statistics
584 unsigned long Number() const { return n; }
585 double Min() const { /* TODO: test n==0 */ return min; }
586 double Max() const { /* test n==0 */ return max; }
587 double Sum() const { return sx; }
588 double SumSquare() const { return sx2; }
589 double MeanValue() const;
590 double StdDev() const;
591};
592
593
594////////////////////////////////////////////////////////////////////////////
595//! time dependent statistic
596//! \ingroup simlib
597class TStat : public SimObject {
598 protected:
599 double sxt; // sum of x*time
600 double sx2t; // sum of squares
601 double min; // min value x
602 double max; // max value x
603 double t0; // time of initialization
604 double tl; // last record time
605 double xl; // last recorded value x
606 unsigned long n; // number of records
607 friend class Facility; // needs to correct n -- TODO: remove
608 friend class Store;
609 friend class Queue;
610 public:
611 explicit TStat(double initval=0.0);
612 explicit TStat(const char *name, double initval=0.0);
613 ~TStat();
614 virtual void Clear(double initval=0.0); //!< initialize
615 virtual void Output() const override; //!< print object to default output
616 virtual void operator () (double x); //!< record the value
617 unsigned long Number() const { return n; }
618 double Min() const { /*TODO: only if(n>0)*/ return min; }
619 double Max() const { return max; }
620 double Sum() const { return sxt; }
621 double SumSquare() const { return sx2t; }
622 double StartTime() const { return t0; }
623 double LastTime() const { return tl; }
624 double LastValue() const { return xl; }
625 double MeanValue() const;
626};
627
628
629////////////////////////////////////////////////////////////////////////////
630//! list of Link* items, uses data from Link
631//
632// prehistoric implementation, TODO: use list<Link*>
633//
634//! \ingroup simlib
635class List : public Link { // circular list of Link items
636 static Link *next(Link*p) { return p->succ; }
637 static Link *previous(Link*p) { return p->pred; }
638 unsigned n; // number of objects in list
639 protected:
640 class iterator {
641 Link *p; // position in List
642 public:
643 iterator(const iterator&x): p(x.p) {}
644 iterator &operator=(const iterator&x) { p = x.p; return *this; }
645 // explicit?
646 iterator(Link *pos) : p(pos) {}
647 iterator &operator++() { p = List::next(p); return *this; }
648 iterator &operator--() { p = List::previous(p); return *this; }
650 Link *tmp = p; p = List::next(p); return tmp;
651 }
653 Link *tmp = p; p = List::previous(p); return tmp;
654 }
655 Link * operator*() const { return p; }
656 bool operator != (iterator q) const { return p!=q.p; }
657 bool operator == (iterator q) const { return p==q.p; }
658 }; // iterator
659 friend class iterator;
660 public:
661 List();
662 explicit List(const char *_name);
663 ~List();
664 virtual void Output() const override; //!< print object to default output
665 // should be renamed:
666 void InsFirst(Link *e); // insert operation
667 void InsLast (Link *e);
668 void PredIns(Link *e, iterator pos); //
669 void PostIns(Link *e, iterator pos); //
670 Link *GetFirst(); //!< remove first
671 Link *GetLast(); //!< remove last
672 virtual Link *Get(iterator pos); //!< remove at position
673 // unsigned Length() { return size(); } // COMPATIBILITY
674 // virtual void Clear() { clear(); } // remove all items
675 // new-style:
676 unsigned size() const { return n; }
678 iterator end() { return this; }
679 Link *front() { return empty() ? 0 : Link::succ; }
680 Link *back() { return empty() ? 0 : Link::pred; }
681 bool empty() { return Link::succ == this; }
682 void clear();
683}; // List
684
685
686////////////////////////////////////////////////////////////////////////////
687//! priority queue
688//
689//! \ingroup simlib
690class Queue : public List { // don't inherit interface for now
691//TODO:remove
692 friend class Facility;
693 friend class Store;
694 public:
697 Stat StatDT; // statistics
698 Queue();
699 explicit Queue(const char *_name);
700 ~Queue(); // list destructor clears content
701 //virtual const char *Name() const;
702 virtual void Output() const override; //!< print statistics
703 operator Queue* () { return this; } // allows Queue instead Queue*
704 iterator begin() { return List::begin(); }
705 iterator end() { return List::end(); }
706 Entity *front() { return static_cast<Entity*>(List::front()); }
707 Entity *back() { return static_cast<Entity*>(List::back()); }
708 void clear(); //!< initialize
709 // size(), empty() inherited
710 // backward COMPATIBILITY
711 void Clear() { clear(); }
712 bool Empty() { return empty(); }
713 unsigned Length() { return size(); }
714 // to rename:
715 virtual void Insert (Entity *e); // priority insert
716 void InsFirst(Entity *e);
717 void InsLast (Entity *e);
718 void PredIns (Entity *e, iterator pos); // insert at position
719 void PostIns (Entity *e, iterator pos);
720 virtual Entity *Get(iterator pos); // remove entity
721 Entity *GetFirst();
722 Entity *GetLast();
723};
724
725////////////////////////////////////////////////////////////////////////////
726//! histogram
727//! statistics
728//! \ingroup simlib
729class Histogram : public SimObject {
730 protected:
731 unsigned *dptr; // value array
732 double low; // low bound
733 double step; // interval width
734 unsigned count; // number of intervals
735 public:
736 Stat stat; // statistics
737 Histogram();
738 Histogram(double low, double step, unsigned count=10);
739 Histogram(const char *_name, double low, double step, unsigned count=10);
740 ~Histogram();
741 virtual void Output() const override; //!< print to default output
742 void Init(double low, double step, unsigned count);
743 void operator () (double x); // record value x
744 virtual void Clear(); // initialize (zero) value array
745 double Low() const { return low; }
746 double High() const { return low + step*count; }
747 double Step() const { return step; }
748 unsigned Count() const { return count; }
749 unsigned operator [](unsigned i) const; // # of items in interval[i]
750};
751
752
753
754////////////////////////////////////////////////////////////////////////////
755//! (SOL-like) facility
756//! Facility with exclusive access and service priority
757//! \ingroup simlib
758class Facility : public SimObject {
759 unsigned char _Qflag; //!< true if facility is owner of input queue
760 protected:
761 Entity *in; //!< Entity currently in service
762 Queue *Q1; //!< Input queue
763 Queue *Q2; //!< Interrupted requests queue
764 TStat tstat; //!< usage statistics
765 public:
766 Facility(); // for arrays only, TODO: FacilityArray
767 explicit Facility(const char *_name);
768 explicit Facility(Queue *_queue1);
769 Facility(const char *_name, Queue *_queue1);
770 virtual ~Facility();
771 virtual void Output() const override; //!< print statistics
772 operator Facility* () { return this; }
773 void SetQueue(Queue *queue1); //!< change input queue
774 bool OwnQueue() const; //!< test for default queue
775 bool Busy() const { return in!=nullptr; } //!< in service
776 Entity * In() const { return in; } //!< current entity or nullptr
777 unsigned QueueLen() const { return Q1->size(); }
778 virtual void Seize(Entity *e, ServicePriority_t sp=DEFAULT_PRIORITY);
779 virtual void Release(Entity *e);
780 virtual void QueueIn(Entity *e, ServicePriority_t sp); // go into queue Q1
781 virtual void Clear(); //!< initialize
782 protected:
783 virtual void QueueIn2(Entity *e); // go into Q2
784};
785
786////////////////////////////////////////////////////////////////////////////
787//! (SOL-like) store
788//! store capacity can be changed dynamically
789//! \ingroup simlib
790class Store : public SimObject {
791 unsigned char _Qflag; //!< true if store is owner of input queue
792 protected:
793 unsigned long capacity; //!< Capacity of store
794 unsigned long used; //!< Currently used capacity
795 Queue *Q; //!< input queue
796 TStat tstat; //!< usage statistics
797 public:
798 Store();
799 explicit Store(unsigned long _capacity);
800 Store(const char *_name, unsigned long _capacity);
801 Store(unsigned long _capacity, Queue *queue);
802 Store(const char *_name, unsigned long _capacity, Queue *queue);
803 virtual ~Store();
804 virtual void Output() const override; //!< print statistics
805 operator Store* () { return this; }
806 void SetCapacity(unsigned long _capacity); //!< change the capacity
807 void SetQueue(Queue *queue); //!< change input queue
808 unsigned long Free() const { return capacity - used; }//!< free capacity
809 unsigned long Used() const { return used; } //!< used capacity
810 unsigned long Capacity() const { return capacity; } //!< max capacity
811 bool Full() const { return Free() == 0; } //!< store is full
812 bool Empty() const { return Used() == 0; } //!< store is empty
813 bool OwnQueue() const;
814 unsigned QueueLen() const { return Q->size(); }
815 virtual void Enter(Entity *e, unsigned long rcap); //!< allocate capacity
816 virtual void Leave(unsigned long rcap); //!< deallocate capacity
817 virtual void QueueIn(Entity *e, unsigned long c); //!< insert entity into queue
818 virtual void Clear(); //!< initialize
819};
820
821
822////////////////////////////////////////////////////////////////////////////
823// CATEGORY: continuous blocks
824//
825
826////////////////////////////////////////////////////////////////////////////
827//! abstract base class for all blocks
828//! \ingroup simlib
829/// blocks/SimObject have not copy semantics (TODO: add move semantics)
830class aBlock : public SimObject { // base class
831};
832
833////////////////////////////////////////////////////////////////////////////
834//! abstract base for continuous blocks with single output
835//! suitable for expression-tree building and evaluation
836//! \ingroup simlib
837class aContiBlock : public aBlock {
838 //! evaluate without loop detection
839 virtual void Eval() {};
840 protected:
841 bool isEvaluated; //TODO:remove this flag for algebraic loop detection
842 public:
844 virtual void _Eval(); //!< evaluate block (with loop detection)
845 //! get block output value <br>
846 //! this method should be defined in classes derived from aContiBlock
847 virtual double Value() = 0;
848};
849
850////////////////////////////////////////////////////////////////////////////
851//! block: constant (value can not be changed)
852//! \ingroup simlib
853class Constant : public aContiBlock {
854 const double value;
855 public:
856 explicit Constant(double x) : value(x) {}
857 virtual double Value () override { return value; }
858};
859
860////////////////////////////////////////////////////////////////////////////
861//! block: variable (value can be changed)
862//! \ingroup simlib
863class Variable : public aContiBlock {
864 double value;
865 public:
866 explicit Variable(double x=0) : value(x) {}
867 Variable &operator= (double x) { value = x; return *this; }
868 virtual double Value () override { return value; }
869};
870
871////////////////////////////////////////////////////////////////////////////
872//! block: parameter (can not be changed during simulation run)
873//! \ingroup simlib
874class Parameter : public aContiBlock {
875 double value;
876 public:
877 explicit Parameter(double x) : value(x) {}
878 Parameter &operator= (double x) { value = x; return *this; }
879 virtual double Value () override { return value; }
880};
881
882
883
884//TODO: add map<aContiBlockPtr,int> for reference counting or use shared_ptr
885// speed is not important, Inputs are created only in the model construction phase
886// (and in dynamical structure models at simulation time, too).
887#define RegisterReference(aContiBlockPtr)
888#define UnRegisterReference(aContiBlockPtr)
889
890////////////////////////////////////////////////////////////////////////////
891//! continuous block connection (transparent reference)
892//! wrapper for pointer to objects of aContiBlock derived classes <br>
893//! (small object, without virtual methods)
894//! <br>
895//! It is used for referencing of continuous blocks in block-expressions.
896//! All references are transparent. There is a problem with initialization
897//! order. Using uninitialized Input is an error. If you
898//! need a block independent on initialization order, use Expression.
899//! \ingroup simlib
900class Input {
902 Input() = delete; // disable default constructor
903 public:
904 //! transparent copy of block reference
905 Input(const Input &i): bp(i.bp) { RegisterReference(bp); }
906
907 // ## we use implicit conversions to simplify block expressions
908 Input(aContiBlock &cb): bp(&cb) { RegisterReference(bp); } //!< reference to block
909 Input(aContiBlock *cb): bp(cb) { RegisterReference(bp); } //!< pointer to block
910
911 //! create block of type Constant
912 //! WARNING: using C++ variable in block expression creates Constant block
913 Input(const double c): bp(new Constant(c)) { RegisterReference(bp); }
914
916
917 //! Redirect the reference
919 Input p = bp; // old value
921 bp=i.bp;
923 // TODO: LoopCheck();
924 return p; // returns old value
925 }
926
927 //! Redirect the reference
930 bp = x.bp;
932 // TODO: LoopCheck();
933 return *this;
934 }
935
936 double Value() const { return bp->Value(); } //!< get target block value
937
938 bool operator ==(aContiBlock *p) const { return bp==p; } // for tests only
939};
940
941
942////////////////////////////////////////////////////////////////////////////
943//! base for continuous blocks with single input and algebraic loop check
944//! \ingroup simlib
945class aContiBlock1 : public aContiBlock {
947 public:
948 explicit aContiBlock1(Input i);
949 double InputValue() { return input.Value(); }
950};
951
952////////////////////////////////////////////////////////////////////////////
953//! reference to block expression
954//! This block can be used as handle for block expression trees
955//! \ingroup simlib
956struct Expression : public aContiBlock1 {
957 explicit Expression(Input i) : aContiBlock1(i) {}
958 double Value() override; //!< Evaluate expression and return the value
959};
960
961////////////////////////////////////////////////////////////////////////////
962//! base for continuous blocks with two inputs
963//! \ingroup simlib
964class aContiBlock2 : public aContiBlock {
967 public:
968 aContiBlock2(Input i1, Input i2);
969 double Input1Value() { return input1.Value(); }
970 double Input2Value() { return input2.Value(); }
971};
972
973////////////////////////////////////////////////////////////////////////////
974//! base for continuous blocks vith three inputs and algebraic loop check
975//! \ingroup simlib
976class aContiBlock3 : public aContiBlock {
980 public:
981 aContiBlock3(Input i1, Input i2, Input i3);
982 double Input1Value() { return input1.Value(); }
983 double Input2Value() { return input2.Value(); }
984 double Input3Value() { return input3.Value(); }
985};
986
987
988////////////////////////////////////////////////////////////////////////////
989//! IntegratorContainer - internal container of integrators (singleton)
990//TODO: move to implementation header
992private:
993 static std::list<Integrator*> * ListPtr; // list of integrators
994 IntegratorContainer(); // forbid constructor
995 static std::list<Integrator*> * Instance(void); // return list (& create)
996public:
997 typedef std::list<Integrator*>::iterator iterator;
998 // is there any integrator in the list? (e.g. list is not empty)
999 static bool isAny(void) {
1000 return ListPtr!=0 && !(ListPtr->empty());
1001 }
1002 // # of elements in the list
1003 static size_t Size(void) {
1004 return (ListPtr!=0) ? (ListPtr->size()) : 0;
1005 }
1006 // return iterator to the first element
1007 static iterator Begin(void) {
1008 return Instance()->begin();
1009 }
1010 // return iterator to the end (not to the last element!)
1011 static iterator End(void) {
1012 return Instance()->end();
1013 }
1014 static iterator Insert(Integrator* ptr); // insert element into container
1015 static void Erase(iterator it); // exclude element
1016 static void InitAll(); // initialize all
1017 static void EvaluateAll(); // evaluate all integrators
1018 static void LtoN(); // last -> now
1019 static void NtoL(); // now -> last
1020}; // class IntegratorContainer
1021
1022
1023////////////////////////////////////////////////////////////////////////////
1024//! StatusContainer - internal container of status variables (singleton)
1025//TODO: move to implementation header
1027private:
1028 static std::list<Status*>* ListPtr; // list of integrators
1029 StatusContainer(); // forbid constructor
1030 static std::list<Status*>* Instance(void); // return list (& create)
1031public:
1032 typedef std::list<Status*>::iterator iterator;
1033 // is there any integrator in the list? (e.g. list is not empty)
1034 static bool isAny(void) {
1035 return ListPtr!=0 && !(ListPtr->empty());
1036 }
1037 // # of elements in the list
1038 static size_t Size(void) {
1039 return (ListPtr!=0) ? (ListPtr->size()) : 0;
1040 }
1041 // return iterator to the first element
1042 static iterator Begin(void) {
1043 return Instance()->begin();
1044 }
1045 // return iterator to the end (not to the last element!)
1046 static iterator End(void) {
1047 return Instance()->end();
1048 }
1049 static iterator Insert(Status* ptr); // insert element into container
1050 static void Erase(iterator it); // exclude element
1051 static void InitAll(); // initialize all
1052 static void ClearAllValueOK(); // invalidate values of all items
1053 static void EvaluateAll(); // evaluate all integrators
1054 static void LtoN(); // last -> now
1055 static void NtoL(); // now -> last
1056}; // class StatusContainer
1057
1058
1059////////////////////////////////////////////////////////////////////////////
1060//! IntegrationMethod - Abstract base class for integration methods
1061//TODO: reduce to simple public interface,
1062// delegate implementation to internal (hidden) class
1066private:
1067 static IntegrationMethod* CurrentMethodPtr; // method used at present
1068 static std::list<IntegrationMethod*>* MthLstPtr; // list of registrated methods
1069 std::list<IntegrationMethod*>::iterator ItList; // position in the list
1070 const char* method_name; // C-string --- the name of the method
1071protected: //## repair
1072 class Memory; // forward declaration
1073 friend class Memory;
1074private: //## repair
1075 size_t PrevINum; // # of integrators in previous step
1076 std::list<Memory*> MList; // list of auxiliary memories
1077 static std::list<Memory*> * PtrMList; // pointer to list being filled
1078 IntegrationMethod(); // forbid implicit constructor
1079 IntegrationMethod(IntegrationMethod&); // forbid implicit copy-constructor
1080 static bool Prepare(void); // prepare system for integration step
1081 static void Iterate(void); // compute new values of state blocks
1082 static void Summarize(void); // set up new state after integration
1083protected:
1084 static bool IsEndStepEvent; // flag - will be event at the end of the step?
1085 typedef IntegratorContainer::iterator Iterator; // iterator of intg. list
1086 static Iterator FirstIntegrator(void) { // it. to first integrator in list
1088 }
1089 static Iterator LastIntegrator(void) { // it. to last integrator in list
1090 return IntegratorContainer::End();
1091 }
1092 static bool StateCond(void); // check on changes of state conditions
1093 static IntegrationMethod* SearchMethod(const char* name); // find method
1094
1095 /* memory of auxiliary values */
1096
1097 class Memory {
1098 Memory(const Memory&) = delete;
1099 Memory&operator=(const Memory&) = delete;
1100 private:
1101 static const size_t page_size; // size of memory page
1102 double *arr; // array
1103 size_t mem_size; // allocated memory size
1104 std::list<Memory*>::iterator it_list; // position in list
1105 std::list<Memory*> * ListPtr; // which list is memory in
1106 public:
1107 explicit Memory(std::list<Memory*> * PtrList=PtrMList); // create empty memory
1108 virtual ~Memory();
1109 double& operator[](size_t ind) { // access the element of the array
1110 // dprintf(("IntegrationMethod::Memory::operator[](%lu) = %g",
1111 // (long unsigned)ind, arr[ind]));
1112 return arr[ind];
1113 }
1114 virtual void Resize(size_t cs); // change size, content will be undefined!
1115 }; // class Memory
1116
1117public:
1118 explicit IntegrationMethod(const char* name); // register the method with name
1119 virtual ~IntegrationMethod(); // destructor unregistrates method
1120 virtual bool IsSingleStep(void)=0; // is it a single-step method?
1121 virtual void TurnOff(void); // turn off integration method
1122 virtual void Integrate(void) = 0; // the method does integration
1123 virtual bool PrepareStep(void); // prepare object for integration step
1124 virtual void Resize(size_t size); // resize all memories to given size
1125 static void StepSim(void); // single step of numerical integration method
1126 static void IntegrationDone(void) { // terminate integration
1127 CurrentMethodPtr->TurnOff(); // suspend present method
1128 }
1129 static void SetMethod(const char* name); // set method which will be used
1130 static const char* GetMethod(void) { // get name of method which is used
1132 }
1133 // auxiliary functions (interface) for user to add own method
1134 static void InitStep(double step_frag); // initialize step
1135 static void FunCall(double step_frag); // evaluate y'(t) = f(t, y(t))
1136 static void SetOptStep(double opt_step); // set optimal step size
1137 static void SetStepSize(double step_size); // set step size
1138 static bool IsConditionFlag(void); // any changes of condition vector?
1139 static int GetErrNo(void); // return # of errors
1140 static void SetErrNo(int num); // set # of errors
1141}; // class IntegrationMethod
1142
1143
1144////////////////////////////////////////////////////////////////////////////
1145//! base for single-step integration methods
1147private:
1148 // flag: single-step method is used to start multi-step method
1149 // (e. g. to restrict step increasing)
1151public:
1152 explicit SingleStepMethod(const char* name):
1153 IntegrationMethod(name),
1154 StartMode(false) { /* NOTHING */ }
1155 virtual bool IsSingleStep(void) override { return true; }
1156 void SetStartMode(bool start_mode) { // set flag on/off
1157 StartMode=start_mode;
1158 }
1159 bool IsStartMode(void) { // is method used to start multi-step method?
1160 return StartMode;
1161 }
1162}; // class SingleStepMethod
1163
1164
1165////////////////////////////////////////////////////////////////////////////
1166//! base for multi-step integration method
1168private:
1169 char* SlaveName; // the name of the method used for starting
1170 SingleStepMethod* Slave_Ptr; // pointer to the method used for starting
1171protected:
1172 SingleStepMethod* SlavePtr(void); // return pointer to the starting method
1173public:
1174 // initialize method
1175 MultiStepMethod(const char* name, const char* slave_name);
1176 ~MultiStepMethod(); // destructor frees dynamic data
1177 virtual bool IsSingleStep(void) override { return false; }
1178 // set starting method for given method
1179 static void SetStarter(const char* name, const char* slave_name);
1180 // set starting method for the method
1181 virtual void SetStarter(const char* slave_name);
1182 // get the name of starting method of given method
1183 static const char* GetStarter(const char* name);
1184 virtual bool PrepareStep(void) override; // prepare the object for the step
1185 virtual void TurnOff(void) override; // turn off method & its slave
1186}; // class MultiStepMethod
1187
1188
1189////////////////////////////////////////////////////////////////////////////
1190//! Abstract base class for integration methods with status auxiliary memories
1192private:
1193 StatusMethod(const StatusMethod&) = delete;
1194 size_t PrevStatusNum; // # of status variables in previous step
1195 std::list<Memory*> StatusMList; // list of auxiliary memories
1196 static std::list<Memory*>* PtrStatusMList; // pointer to list being filled
1197protected:
1198 typedef StatusContainer::iterator StatusIterator; // iterator of intg. list
1199 static StatusIterator FirstStatus(void) { // it. to first status in list
1200 return StatusContainer::Begin();
1201 }
1202 static StatusIterator LastStatus(void) { // it. to last status in list
1203 return StatusContainer::End();
1204 }
1205
1206//## repair
1207 friend class EULER;
1208 friend class RKE;
1209 /* memory of auxiliary status values */
1210 class StatusMemory : public Memory {
1211 private:
1212 StatusMemory(const StatusMemory&) = delete;
1213 void operator= (const StatusMemory&) = delete;
1214 public:
1215 // create empty memory
1216 explicit StatusMemory(std::list<Memory*>* PtrList=PtrStatusMList) : Memory(PtrList) { }
1217 // free dynamic data
1218 virtual ~StatusMemory() { }
1219 }; // class StatusMemory
1220
1221 friend class StatusMemory;
1222
1223 // store state of integrators and status variables
1224 static void StoreState(Memory& di, Memory& si, StatusMemory& xi);
1225 // restore state of integrators and status variables
1226 static void RestoreState(double dthlf, Memory& di,
1227 Memory& si, StatusMemory& xi);
1228 // move startpoint to given state
1229 static void GoToState(Memory& di, Memory& si, StatusMemory& xi);
1230
1231public:
1232 explicit StatusMethod(const char* name); // initailization
1233 virtual ~StatusMethod() { } // free dynamic datas
1234 virtual void TurnOff(void) override; // turn off integration method
1235 virtual bool PrepareStep(void) override; // prepare integration step
1236 virtual void StatusResize(size_t size); // resize status memories
1237}; // StatusMethod
1238
1239
1240////////////////////////////////////////////////////////////////////////////
1241// interface for class IntegrationMethod & its descendants
1242//
1243
1244//! select the integration method
1245//! @param name "abm4", "euler", "fw", "rke"(default), "rkf3", "rkf5", "rkf8"
1246//! \ingroup simlib
1247inline void SetMethod(const char* name)
1248{
1250}
1251
1252//! get the name of the method which is used
1253//! \ingroup simlib
1254inline const char* GetMethod(void)
1255{
1257}
1258
1259//! set the method which will be used to start given multistep method
1260//! \ingroup simlib
1261inline void SetStarter(const char* name, const char* slave_name)
1262{
1263 MultiStepMethod::SetStarter(name, slave_name);
1264}
1265
1266//! set the method which will be used to start currently used multistep method
1267//! \ingroup simlib
1268inline void SetStarter(const char* slave_name)
1269{
1271}
1272
1273//! get the name of the method which is used to start given multistep method
1274//! \ingroup simlib
1275inline const char* GetStarter(const char* name)
1276{
1277 return MultiStepMethod::GetStarter(name);
1278}
1279
1280//! get the name of the method which is used
1281//! to start currently used multistep method
1282//! \ingroup simlib
1283inline const char* GetStarter(void)
1284{
1286}
1287
1288
1289////////////////////////////////////////////////////////////////////////////
1290//! block for numerical integration
1291//! input is derivative, output is state
1292//! \ingroup simlib
1293class Integrator : public aContiBlock { // integrator
1294 Integrator &operator= (const Integrator &x) = delete; // disable assignment
1295 double dd; // input value: y'=f(t,y)
1296 double ddl; // the same from previous step
1297 double ss; // status: y = S f(t,y) dt
1298 double ssl; // the same from previous step
1299 protected:
1300 Input input; //!< input expression: f(t,y)
1301 double initval; //!< initial value: y(t0)
1302 void CtrInit();
1303 IntegratorContainer::iterator it_list; //!< position in list of integrators
1304 public:
1305 Integrator(); // implicit CTR (input = 0)
1306 // we use implicit conversions in block expressions
1307 Integrator(Input i, double initvalue=0);
1308 Integrator(Integrator &i, double initvalue=0); // copy-ctr
1309 ~Integrator();
1310 void Init(double initvalue); // set value
1311 void Init() { Init(initval); } //!< use preset initial value
1312 void Set(double value); // set integrator state value
1313 //! set integrator state value
1314 Integrator &operator= (double x) { Set(x); return *this; }
1315 //! set integrator input block expression
1316 Input SetInput(Input inp) { return input.Set(inp); }
1317 void Eval() override; // integrator input evaluation
1318 double Value() override; //!< the state of integrator
1319 double InputValue() { return input.Value(); } //!< current input value
1320 //virtual const char *Name() const;
1321
1322 // private interface
1323 void Save(void) { ddl=dd; ssl=ss; } // save status
1324 void Restore(void) { dd=ddl; ss=ssl; } // restore saved status
1325 void SetState(double s) { ss=s; }
1326 double GetState(void) { return ss; }
1327 void SetOldState(double s) { ssl=s; }
1328 double GetOldState(void) { return ssl; }
1329 void SetDiff(double d) { dd=d; }
1330 double GetDiff(void) { return dd; }
1331 void SetOldDiff(double d) { ddl=d; }
1332 double GetOldDiff(void) { return ddl; }
1333};
1334
1335
1336////////////////////////////////////////////////////////////////////////////
1337//! State variables (memory)
1338//! base for blocks with internal state (Relay, ...)
1339//! \ingroup simlib
1340class Status : public aContiBlock1 { // state-variables
1341 protected:
1342 double initval; //!< initial value
1343 bool ValueOK; // valid-flag ###
1344 void CtrInit();
1345 StatusContainer::iterator it_list; //!< position in list of status variables
1346 public:
1347 double st; //!< status
1348 double stl; //!< status from previous step
1349 Status(Input i, double initvalue=0);
1350 ~Status();
1351 void Init(double initvalue); // value initialization
1352 void Init() { Init(initval); }
1353 void Set(double value); // set status of block
1354 virtual void Eval() override; // block evaluation
1355 virtual double Value() override; // block status
1356 //virtual const char *Name() const;
1357 // internal interface
1358 void Save() { stl = st; } // save status
1359 void Restore(); // restore saved status
1360 void SetState(double s) { st=s; }
1361 double GetState(void) { return st; }
1362 void SetOldState(double s) { stl=s; }
1363 double GetOldState(void) { return stl; }
1364 void SetValid(bool flag) { ValueOK = flag; } // set valid flag
1365};
1366
1367
1368////////////////////////////////////////////////////////////////////////////
1369// Nonlinear blocks
1370
1371////////////////////////////////////////////////////////////////////////////
1372//! nonlinear block - hysteresis
1373//! \ingroup simlib
1374class Hyst : public Status {
1375 protected:
1376 double p1,p2;
1377 double y1,y2;
1378 double tga;
1379 virtual void Eval() override; // block evaluation
1380 public:
1381 Hyst(Input i, double p1, double p2, double y1, double y2, double tga);
1382 //virtual const char *Name() const;
1383};
1384
1385typedef Hyst Hysteresis; // alias name
1386
1387
1388////////////////////////////////////////////////////////////////////////////
1389//! nonlinear block - backlash
1390//! \ingroup simlib
1391class Blash : public Status { // backlash
1392 protected:
1393 double p1,p2;
1394 double tga;
1395 public:
1396 Blash(Input i, double p1, double p2, double tga);
1397 virtual void Eval() override; // block evaluation
1398 //virtual const char *Name() const;
1399};
1400
1401typedef Blash Backlash; // alias
1402
1403////////////////////////////////////////////////////////////////////////////
1404//! Relay
1405//! this implementation detects exact time of switch
1406//! \ingroup simlib
1407class Relay : public Status { // general relay block
1408 protected:
1409 double p1,p2,p3,p4; // points on x-axis
1410 double y1,y2; // points on y-axis
1411 public:
1412 Relay(Input i, double p1, double p2, double p3, double p4,
1413 double y1, double y2);
1414 virtual void Eval() override; //!< block evaluation
1415 //virtual const char *Name() const;
1416};
1417
1418
1419////////////////////////////////////////////////////////////////////////////
1420// Continuous block functions
1421//
1422
1423// Block arithmetic binary operators:
1428
1429// Block unary operators:
1431
1432// Block functions:
1433Input Abs(Input x); // abs(x) absolute value
1434Input Sin(Input x); // sin(x)
1435Input Cos(Input x); // cos(x)
1436Input Tan(Input x); // tan(x)
1437Input ASin(Input x); // asin(x)
1438Input ACos(Input x); // acos(x)
1439Input ATan(Input x); // atan(x)
1440Input ATan2(Input y, Input x); // atan2(y,x)
1441Input Exp(Input x); // exp(x) e ** x
1442Input Log10(Input x); // log10(x)
1443Input Ln(Input x); // ln(x) natural logarithm
1444Input Pow(Input x, Input y); // pow(x,y) x ** y
1445Input Sqr(Input x); // square x * x
1446Input Sqrt(Input x); // square root
1447Input Min(Input x, Input y); // minimum
1448Input Max(Input x, Input y); // maximum
1449Input Sign(Input x); // signum ###warning-steps-not-detected
1450
1451
1452////////////////////////////////////////////////////////////////////////////
1453//! block parametrized by function with single argument
1454//
1455//! \ingroup simlib
1456class Function1 : public aContiBlock1 {
1457 Function1(const Function1&) = delete;
1459 double (*f)(double); // pointer to function
1460 public:
1461 Function1(Input i, double (*pf)(double));
1462 virtual double Value() override;
1463 //virtual const char *Name() const;
1464};
1465
1466////////////////////////////////////////////////////////////////////////////
1467//! block parametrized by function with two arguments
1468//
1469//! \ingroup simlib
1470class Function2 : public aContiBlock2 {
1471 Function2(const Function2&) = delete;
1473 double (*f)(double,double); // pointer to function
1474 public:
1475 Function2(Input i1, Input i2, double (*pf)(double,double));
1476 virtual double Value() override;
1477 //virtual const char *Name() const;
1478};
1479
1480
1481////////////////////////////////////////////////////////////////////////////
1482// CATEGORY: state conditions
1483
1484////////////////////////////////////////////////////////////////////////////
1485//! abstract base class for all state-condition blocks
1486//! State event in combined model is executed at the time when the condition
1487//! changes its boolean value
1488//! \ingroup simlib
1489class aCondition : public aBlock {
1490 static aCondition *First; // list of all state conditions
1491 aCondition *Next; // next condition in list
1492 void operator= (const aCondition&) = delete;
1493 aCondition(const aCondition&) = delete;
1494 public:
1495 aCondition();
1496 ~aCondition();
1497 static void InitAll();
1498 static void SetAll();
1499 static void TestAll();
1500 static void AllActions();
1501 static bool isAny();
1502 private:
1503 virtual void Init()=0; //!< initialize
1504 virtual void SetNewStatus()=0; //!< update
1505 virtual bool Test()=0; //!< test of the condition
1506 virtual void Action()=0; //!< state event description
1507};
1508
1509////////////////////////////////////////////////////////////////////////////
1510//! change detector - Boolean version (int)
1511class Condition : public aCondition { // state condition
1512 Input in; // block input
1513 unsigned char cc; //!< state
1514 unsigned char ccl; //!< old state
1515 virtual void Init() override;
1516 virtual void SetNewStatus() override;
1517 protected:
1518 virtual bool Test() override; // test function (input >= 0.0)
1519 bool Up() { return ccl<cc; } // change: FALSE->TRUE
1520 bool Down() { return ccl>cc; } // change: TRUE->FALSE
1521 bool Change() { return ccl!=cc; } // both changes
1522 public:
1523 explicit Condition(Input i);
1524 ~Condition();
1525 bool Value() { return cc; } //!< boolean state of condition
1526 Input SetInput(Input inp) { return in.Set(inp); } // change input block
1527 //virtual const char *Name() const;
1528};
1529
1530////////////////////////////////////////////////////////////////////////////
1531//! detector of FALSE-->TRUE
1532//! \ingroup simlib
1533class ConditionUp : public Condition { // state event on FALSE-->TRUE change
1534 public:
1535 explicit ConditionUp(Input i) : Condition(i) {}
1536 bool Test() override { return Condition::Test() && Up(); }
1537 //virtual const char *Name() const;
1538};
1539
1540////////////////////////////////////////////////////////////////////////////
1541//! detector of TRUE-->FALSE
1542//! \ingroup simlib
1543class ConditionDown : public Condition { // state event on TRUE-->FALSE change
1544 public:
1545 explicit ConditionDown(Input i) : Condition(i) {}
1546 bool Test() override { return Condition::Test() && Down(); }
1547 //virtual const char *Name() const;
1548};
1549
1550
1551
1552
1553////////////////////////////////////////////////////////////////////////////
1554// CATEGORY: non-linear blocks
1555
1556
1557////////////////////////////////////////////////////////////////////////////
1558//! nonlinear block: limitation
1559//
1560//! \ingroup simlib
1561class Lim : public aContiBlock1 {
1562 protected:
1563 double low, high; // limits
1564 double tgalpha; //
1565 public:
1566 Lim(Input in, double l, double h, double tga=1.0);
1567 virtual void _Eval() override; // evaluation with loop check
1568 virtual double Value() override; // returned value
1569 //virtual const char *Name() const;
1570};
1571
1573
1574////////////////////////////////////////////////////////////////////////////
1575//! nonlinear block: dead zone
1576//
1577//! \ingroup simlib
1578class Insv : public aContiBlock1 {
1579 protected:
1580 double low, high; // limits
1581 double tgalpha,tgbeta; //
1582 public:
1583 Insv(Input in, double l, double h, double tga=1.0, double tgb=1.0);
1584 virtual void _Eval() override; // evaluation with loop check
1585 virtual double Value() override; // returned value
1586 //virtual const char *Name() const;
1587};
1588
1590
1591////////////////////////////////////////////////////////////////////////////
1592//! nonlinear block: quantizer
1593//
1594//! \ingroup simlib
1595class Qntzr : public aContiBlock1 {
1596 protected:
1597 double step; // quantum
1598 public:
1599 Qntzr(Input in, double qstep=1.0);
1600 virtual void _Eval() override; // evaluation with loop check
1601 virtual double Value() override; // returned value
1602 //virtual const char *Name() const;
1603};
1604
1606
1607////////////////////////////////////////////////////////////////////////////
1608//! nonlinear block: friction
1609//
1610//! \ingroup simlib
1611class Frict : public aContiBlock1 {
1612 protected:
1613 double low, high; // limits
1614 double tgalpha; //
1615 public:
1616 Frict(Input in, double l, double h, double tga=1.0);
1617 virtual void _Eval() override; // evaluation with loop check
1618 virtual double Value() override; // returned value
1619 //virtual const char *Name() const;
1620};
1621
1623
1624////////////////////////////////////////////////////////////////////////////
1625//! nonlinear block: function defined by given table of values
1626//
1627//TODO: reimplement with std::vector
1628//! \ingroup simlib
1629class Rline : public aContiBlock1 {
1630 protected:
1631 int n; // table item number
1632 double *tableX; // tabulka X
1633 double *tableY; // tabulka Y
1634 public:
1635 Rline(Input in, int num, double *X, double *Y);
1636//TODO Rline(Input in, int num, double table[][2]);
1637 ~Rline();
1638 virtual void _Eval() override; // evaluation with loop check
1639 virtual double Value() override; // returned value
1640 //virtual const char *Name() const;
1641};
1642
1643////////////////////////////////////////////////////////////////////////////
1644// CATEGORY: algebraic loop solvers
1645
1646
1647////////////////////////////////////////////////////////////////////////////
1648//! abstract base for algebraic loop solvers
1649// (not checked, needs improvements)
1650//! \ingroup simlib
1651class AlgLoop : public aContiBlock1 {
1652 protected:
1653 double Eps; // required accuracy
1654 unsigned long MaxIt; // max. number of iterations
1655 double TA; // boundary values of interval
1656 double TB; // (also used for convergency check)
1657 double T0; // initial value
1658 bool was_cycle; // flag for going through loop
1659 int phase; // phase of computation
1660 double root; // root of equation
1661 public:
1662 AlgLoop(Input i, double eps, unsigned long max_it, // constructor
1663 double t_min, double t_max, double t0);
1664 void Set(double eps, unsigned long max_it, // set parameters
1665 double t_min, double t_max, double t0);
1666 void Set(double eps, unsigned long max_it, // set parameters
1667 double t_min, double t_max);
1668 //virtual const char *Name() const;
1669}; // AlgLoop
1670
1671
1672////////////////////////////////////////////////////////////////////////////
1673//! solve using iterations
1674//
1675//! \ingroup simlib
1676class Iterations : public AlgLoop {
1677 public:
1678 Iterations(Input i, double eps, unsigned long max_it,
1679 double t_min, double t_max, double t0):
1680 AlgLoop(i, eps, max_it, t_min, t_max, t0)
1681 {/*nothing*/}
1682 virtual double Value() override; // returned value
1683};
1684
1685
1686////////////////////////////////////////////////////////////////////////////
1687//! solve using bisection method
1688//
1689//! \ingroup simlib
1690class Bisect : public AlgLoop {
1691 public:
1692 Bisect(Input i, double eps, unsigned long max_it,
1693 double t_min, double t_max):
1694 AlgLoop(i, eps, max_it, t_min, t_max, t_min)
1695 {/*nothing*/}
1696 virtual double Value() override; // returned value
1697};
1698
1699
1700////////////////////////////////////////////////////////////////////////////
1701//! solve using regula falsi method
1702//
1703//! \ingroup simlib
1704class RegulaFalsi : public AlgLoop {
1705 double eps_root; // root for force precision test
1706 public:
1707 RegulaFalsi(Input i, double eps, unsigned long max_it,
1708 double t_min, double t_max):
1709 AlgLoop(i, eps, max_it, t_min, t_max, t_min),
1710 eps_root(0)
1711 {/*nothing*/}
1712 virtual double Value() override; // returned value
1713};
1714
1715
1716////////////////////////////////////////////////////////////////////////////
1717//! solve using modified Newton's method
1718//
1719//! \ingroup simlib
1720class Newton : public AlgLoop {
1721 double eps_root; // root for force precision test
1722 double prev_root; // root from previous iteration step
1723 public:
1724 Newton(Input i, double eps, unsigned long max_it,
1725 double t_min, double t_max, double t0):
1726 AlgLoop(i, eps, max_it, t_min, t_max, t0),
1727 eps_root(0),
1728 prev_root(0)
1729 {/*nothing*/}
1730 virtual double Value() override; // returned value
1731};
1732
1733
1734////////////////////////////////////////////////////////////////////////////
1735// CATEGORY: global functions
1736
1737////////////////////////////////////////////////////////////////////////////
1738// Naming Subsystem --- SimObject names (text identifiers for printing)
1739// this is system dictionary: relation: objectptr---textname
1740// ### TODO: use strings in objects OR unordered_map
1741//
1742void SetName(SimObject &o, const std::string &name);
1743void SetName(SimObject *o, const std::string &name);
1744void RemoveName(SimObject &o);
1745void RemoveName(SimObject *o);
1746std::string GetName(SimObject &o);
1747std::string GetName(SimObject *o);
1748
1749
1750////////////////////////////////////////////////////////////////////////////
1751//! InstallBreak --- set function for checking if user breaks simulation
1752//! @param f is called at each step of simulation
1753//! f can call Stop() or Abort()
1754//! \ingroup simlib
1755void InstallBreak(void (*f)());
1756
1757
1758////////////////////////////////////////////////////////////////////////////
1759//! basic synchronization tool for processes
1760//! simplified implementation
1761//! \ingroup simlib
1762class Semaphore : public SimObject {
1763 protected:
1764 int n;
1765 public:
1766 Queue Q; //!< internal quqeue
1767 Semaphore(); // constructor
1768 explicit Semaphore(const char *_name); // with associated name
1769 virtual ~Semaphore();
1770 void Clear(); //!< initialization
1771 virtual void Output() const override;
1772 virtual void P(); //!< P operation
1773 virtual void V(); //!< V operation
1774// operator Semaphore* () { return this; }
1775};
1776
1777////////////////////////////////////////////////////////////////////////////
1778//! synchronization tool for processes
1779//
1780//! \ingroup simlib
1781class Barrier : public SimObject {
1782 protected:
1783 Entity **waiting; //!< array of waiting entities (fixed size)
1784 unsigned n; //!< current number of waiting entities
1785 unsigned maxn; //!< barrier height/size
1786 void Init(); //!< initialization
1787 public:
1788 explicit Barrier(unsigned N);
1789 Barrier(const char *_name, unsigned N);
1790 virtual ~Barrier();
1791 void ChangeHeight(unsigned new_maxn); //!< change size
1792 unsigned Height() const { return maxn; } //!< barrier size
1793 virtual void Enter(Entity *e); //!< wait for barrier break TODO: remove/rename
1794 virtual bool Wait(); //!< wait for barrier break (Current)
1795 virtual int Break(); //!< activate all waiting entities
1796 void Clear(); //!< initialization
1797 virtual void Output() const override; //!< print status
1798};
1799
1800/////////////////////////////////////////////////////////////////////////////
1801//! internal statistics structure
1802//! <br> contains basic statistics of simulator execution
1803// TODO: add interface and hide variables
1804// TODO: add real time of execution ?
1805//! \ingroup simlib
1808 double EndTime;
1809 long EventCount; // for discrete simulation
1810 long StepCount; // for continuous simulation
1811 double MinStep;
1812 double MaxStep;
1813 //! constructor runs SIMLIB_statistics_t::Init()
1815 //! initialize - used at the start of each Run()
1816 void Init();
1817 //! print run-time statistics to output
1818 void Output() const;
1819};
1820
1821//! interface to internal run-time statistics structure
1823
1824} // namespace simlib3
1825
1826using namespace simlib3; // default for "simlib.h"
1827
1828#endif // ifndef __SIMLIB__
1829
Test t(F)
#define SIMLIB_DEBUG
Definition _test_.cc:4
AlgLoop(Input i, double eps, unsigned long max_it, double t_min, double t_max, double t0)
Definition algloop.cc:39
void Set(double eps, unsigned long max_it, double t_min, double t_max, double t0)
Definition algloop.cc:63
unsigned long MaxIt
Definition simlib.h:1654
synchronization tool for processes
Definition simlib.h:1781
virtual bool Wait()
wait for barrier break (Current)
Definition barrier.cc:78
unsigned n
current number of waiting entities
Definition simlib.h:1784
void Init()
initialization
Definition barrier.cc:113
void ChangeHeight(unsigned new_maxn)
change size
Definition barrier.cc:125
virtual void Enter(Entity *e)
wait for barrier break TODO: remove/rename
Definition barrier.cc:62
Entity ** waiting
array of waiting entities (fixed size)
Definition simlib.h:1783
virtual int Break()
activate all waiting entities
Definition barrier.cc:97
virtual void Output() const override
print status
Definition barrier.cc:154
Barrier(unsigned N)
constructor
Definition barrier.cc:32
void Clear()
initialization
Definition barrier.cc:144
unsigned maxn
barrier height/size
Definition simlib.h:1785
unsigned Height() const
barrier size
Definition simlib.h:1792
Bisect(Input i, double eps, unsigned long max_it, double t_min, double t_max)
Definition simlib.h:1692
virtual double Value() override
Definition algloop.cc:179
nonlinear block - backlash
Definition simlib.h:1391
Blash(Input i, double p1, double p2, double tga)
blash constructor
Definition stdblock.cc:262
virtual void Eval() override
evaluate without loop detection
Definition stdblock.cc:268
detector of TRUE-->FALSE
Definition simlib.h:1543
bool Test() override
Condition::operator ().
Definition simlib.h:1546
detector of FALSE-->TRUE
Definition simlib.h:1533
ConditionUp(Input i)
Definition simlib.h:1535
bool Test() override
Condition::operator ().
Definition simlib.h:1536
change detector - Boolean version (int)
Definition simlib.h:1511
Condition(Input i)
Definition cond.cc:75
Input SetInput(Input inp)
Definition simlib.h:1526
virtual void SetNewStatus() override
update
Definition cond.cc:97
bool Value()
boolean state of condition
Definition simlib.h:1525
virtual bool Test() override
Condition::operator ().
Definition cond.cc:106
unsigned char ccl
old state
Definition simlib.h:1514
unsigned char cc
state
Definition simlib.h:1513
virtual void Init() override
initialize
Definition cond.cc:89
block: constant (value can not be changed)
Definition simlib.h:853
const double value
Definition simlib.h:854
Constant(double x)
Definition simlib.h:856
virtual double Value() override
Definition simlib.h:857
abstract base class for active entities (Process, Event) instances of derived classes provide Behavio...
Definition simlib.h:380
EventNotice * GetEventNotice()
Definition simlib.h:432
virtual void _Run() noexcept=0
run the Behavior() function
EntityPriority_t Priority_t
Definition simlib.h:402
Entity(Priority_t p=DEFAULT_PRIORITY)
constructor
Definition entity.cc:33
double _MarkTime
Definition simlib.h:389
bool Idle()
entity activation is not scheduled in calendar
Definition simlib.h:417
unsigned long id() const
Definition simlib.h:401
friend class Queue
Definition simlib.h:388
void Activate()
activate now
Definition simlib.h:413
friend class Store
Definition simlib.h:392
EventNotice * _evn
points to calendar item, iff scheduled
Definition simlib.h:430
Priority_t Priority
priority of the entity (scheduling,queues)
Definition simlib.h:404
static unsigned long _Number
current number of entities
Definition simlib.h:382
void Cancel()
end Behavior() and remove entity
Definition simlib.h:418
virtual void Terminate()=0
end Behavior() and remove entity
Definition entity.cc:97
double ActivationTime()
get activation time of entity - iff scheduled it is here, because Entity has no knowledge of calend...
Definition calendar.cc:1358
ServicePriority_t _SPrio
priority of service in Facility
Definition simlib.h:398
friend void SIMLIB_DoActions()
Definition run.cc:135
virtual void Out() override
remove entity from queue
Definition entity.cc:90
virtual void Passivate()
deactivation
Definition entity.cc:68
friend class Facility
Definition simlib.h:391
unsigned long _Ident
unique identification number of entity
Definition simlib.h:383
friend struct EventNotice
Definition simlib.h:429
abstract base class for events Event behavior is simple function (can not be interrupted)
Definition simlib.h:493
virtual void Output() const override
print object to default output
Definition output1.cc:35
virtual void Behavior()=0
behavior description
virtual void Terminate() override
passivate event, it will be destroyed if not activated later in Behavior() Should not be used.
Definition event.cc:52
virtual void Activate(double t) override
activate at time t (schedule)
Definition event.cc:62
virtual std::string Name() const override
name of object
Definition event.cc:71
virtual void _Run() noexcept override
activation method, called from simulation control algorithm
Definition event.cc:42
Event(Priority_t p=DEFAULT_PRIORITY)
constructor, default priority if not specified
Definition event.cc:28
(SOL-like) facility Facility with exclusive access and service priority
Definition simlib.h:758
virtual void QueueIn2(Entity *e)
Definition facility.cc:246
virtual void QueueIn(Entity *e, ServicePriority_t sp)
Definition facility.cc:200
bool Busy() const
in service
Definition simlib.h:775
virtual void Seize(Entity *e, ServicePriority_t sp=DEFAULT_PRIORITY)
Definition facility.cc:111
virtual void Release(Entity *e)
Definition facility.cc:151
unsigned char _Qflag
true if facility is owner of input queue
Definition simlib.h:759
virtual void Clear()
initialize
Definition facility.cc:266
TStat tstat
usage statistics
Definition simlib.h:764
virtual void Output() const override
print statistics
Definition output2.cc:35
Queue * Q1
Input queue.
Definition simlib.h:762
Queue * Q2
Interrupted requests queue.
Definition simlib.h:763
Entity * in
Entity currently in service.
Definition simlib.h:761
bool OwnQueue() const
test for default queue
Definition facility.cc:282
void SetQueue(Queue *queue1)
change input queue
Definition facility.cc:95
unsigned QueueLen() const
Definition simlib.h:777
Entity * In() const
current entity or nullptr
Definition simlib.h:776
nonlinear block: friction
Definition simlib.h:1611
virtual void _Eval() override
evaluation with algebraic loop detection
Definition stdblock.cc:159
virtual double Value() override
Definition stdblock.cc:163
double tgalpha
Definition simlib.h:1614
double high
Definition simlib.h:1613
Frict(Input in, double l, double h, double tga=1.0)
friction constructor
Definition stdblock.cc:151
virtual double Value() override
Definition fun.cc:39
double(*) f(double)
Definition simlib.h:1459
Function1 & operator=(const Function1 &)=delete
Function1(const Function1 &)=delete
Function2(const Function2 &)=delete
Function2 & operator=(const Function2 &)=delete
virtual double Value() override
Definition fun.cc:60
double(*) f(double, double)
Definition simlib.h:1473
histogram statistics
Definition simlib.h:729
unsigned operator[](unsigned i) const
Definition histo.cc:93
unsigned Count() const
Definition simlib.h:748
unsigned * dptr
Definition simlib.h:731
double High() const
Definition simlib.h:746
void operator()(double x)
Definition histo.cc:102
double Low() const
Definition simlib.h:745
virtual void Output() const override
print to default output
Definition output2.cc:76
virtual void Clear()
Definition histo.cc:143
void Init(double low, double step, unsigned count)
Definition histo.cc:120
double Step() const
Definition simlib.h:747
unsigned count
Definition simlib.h:734
nonlinear block - hysteresis
Definition simlib.h:1374
double tga
Definition simlib.h:1378
virtual void Eval() override
evaluate without loop detection
Definition stdblock.cc:192
double p2
Definition simlib.h:1376
Hyst(Input i, double p1, double p2, double y1, double y2, double tga)
hysteresis constructor
Definition stdblock.cc:186
double y1
Definition simlib.h:1377
double y2
Definition simlib.h:1377
double p1
Definition simlib.h:1376
continuous block connection (transparent reference) wrapper for pointer to objects of aContiBlock der...
Definition simlib.h:900
bool operator==(aContiBlock *p) const
Definition simlib.h:938
Input Set(Input i)
Redirect the reference.
Definition simlib.h:918
Input(const double c)
Definition simlib.h:913
Input(const Input &i)
transparent copy of block reference
Definition simlib.h:905
double Value() const
get target block value
Definition simlib.h:936
aContiBlock * bp
Definition simlib.h:901
Input(aContiBlock &cb)
reference to block
Definition simlib.h:908
Input & operator=(const Input &x)
Redirect the reference.
Definition simlib.h:928
Input()=delete
Input(aContiBlock *cb)
pointer to block
Definition simlib.h:909
nonlinear block: dead zone
Definition simlib.h:1578
virtual void _Eval() override
evaluation with algebraic loop detection
Definition stdblock.cc:91
Insv(Input in, double l, double h, double tga=1.0, double tgb=1.0)
dead space
Definition stdblock.cc:83
double high
Definition simlib.h:1580
double tgalpha
Definition simlib.h:1581
double low
Definition simlib.h:1580
double tgbeta
Definition simlib.h:1581
virtual double Value() override
Definition stdblock.cc:95
static const size_t page_size
Definition simlib.h:1101
std::list< Memory * >::iterator it_list
Definition simlib.h:1104
Memory(const Memory &)=delete
double & operator[](size_t ind)
Definition simlib.h:1109
std::list< Memory * > * ListPtr
Definition simlib.h:1105
Memory & operator=(const Memory &)=delete
IntegrationMethod - Abstract base class for integration methods.
Definition simlib.h:1063
virtual void Resize(size_t size)
resize all the memories to the given size
Definition numint.cc:271
static std::list< Memory * > * PtrMList
Definition simlib.h:1077
static IntegrationMethod * CurrentMethodPtr
pointer to the method currently used "rke" is a predefined method (historical reasons,...
Definition simlib.h:1067
virtual bool IsSingleStep(void)=0
static void Summarize(void)
set up new state after execution of integration step
Definition numint.cc:114
static Iterator LastIntegrator(void)
Definition simlib.h:1089
const char * method_name
Definition simlib.h:1070
virtual void Integrate(void)=0
virtual void TurnOff(void)
turn off integration method: flush memories etc...
Definition numint.cc:261
static void SetErrNo(int num)
static void Iterate(void)
compute new values of state blocks in model without integrators
Definition numint.cc:88
IntegrationMethod(IntegrationMethod &)
static bool IsEndStepEvent
Definition simlib.h:1084
static int GetErrNo(void)
Definition numint.cc:322
static const char * GetMethod(void)
Definition simlib.h:1130
static bool Prepare(void)
initialize integration step
Definition numint.cc:128
IntegrationMethod & operator=(const IntegrationMethod &)=delete
static void InitStep(double step_frag)
initialize step
Definition numint.cc:298
IntegrationMethod(const IntegrationMethod &)=delete
static IntegrationMethod * SearchMethod(const char *name)
search method in the list of registrated methods
Definition numint.cc:239
IntegratorContainer::iterator Iterator
Definition simlib.h:1085
static std::list< IntegrationMethod * > * MthLstPtr
Definition simlib.h:1068
static bool StateCond(void)
check on changes of state conditions
Definition numint.cc:175
virtual bool PrepareStep(void)
prepare object for integration step
Definition numint.cc:282
static bool IsConditionFlag(void)
Definition numint.cc:317
static void IntegrationDone(void)
Definition simlib.h:1126
static void SetMethod(const char *name)
set method which will be used
Definition numint.cc:75
static void SetOptStep(double opt_step)
Definition numint.cc:307
static void StepSim(void)
step of numerical integration method
Definition numint.cc:52
std::list< Memory * > MList
Definition simlib.h:1076
static void SetStepSize(double step_size)
Definition numint.cc:312
static Iterator FirstIntegrator(void)
Definition simlib.h:1086
std::list< IntegrationMethod * >::iterator ItList
Definition simlib.h:1069
static void FunCall(double step_frag)
Definition numint.cc:337
static iterator Insert(Integrator *ptr)
Definition intg.cc:292
static bool isAny(void)
Definition simlib.h:999
static void InitAll()
Definition intg.cc:346
static void Erase(iterator it)
Definition intg.cc:303
static void EvaluateAll()
Definition intg.cc:363
static std::list< Integrator * > * ListPtr
list of integrators
Definition simlib.h:993
static iterator End(void)
Definition simlib.h:1011
static iterator Begin(void)
Definition simlib.h:1007
std::list< Integrator * >::iterator iterator
Definition simlib.h:997
static std::list< Integrator * > * Instance(void)
Definition intg.cc:277
static size_t Size(void)
Definition simlib.h:1003
block for numerical integration input is derivative, output is state
Definition simlib.h:1293
double GetState(void)
Definition simlib.h:1326
void SetState(double s)
Definition simlib.h:1325
void Save(void)
Definition simlib.h:1323
double Value() override
the state of integrator
Definition intg.cc:249
void SetOldState(double s)
Definition simlib.h:1327
Input SetInput(Input inp)
set integrator input block expression
Definition simlib.h:1316
double GetOldDiff(void)
Definition simlib.h:1332
double GetDiff(void)
Definition simlib.h:1330
void SetDiff(double d)
Definition simlib.h:1329
double initval
initial value: y(t0)
Definition simlib.h:1301
void Set(double value)
set the integrator status value (step change)
Definition intg.cc:230
void Restore(void)
Definition simlib.h:1324
Integrator()
constructor for special cases (arrays of integrators) Input can be set using method Integrator::Set
Definition intg.cc:174
void SetOldDiff(double d)
Definition simlib.h:1331
double GetOldState(void)
Definition simlib.h:1328
double InputValue()
current input value
Definition simlib.h:1319
IntegratorContainer::iterator it_list
position in list of integrators
Definition simlib.h:1303
Input input
input expression: f(t,y)
Definition simlib.h:1300
void Eval() override
evaluate integrator input
Definition intg.cc:239
void Init(double initvalue)
set initial value of integrator
Definition intg.cc:222
void Init()
use preset initial value
Definition simlib.h:1311
Integrator & operator=(const Integrator &x)=delete
virtual double Value() override
Definition algloop.cc:114
Iterations(Input i, double eps, unsigned long max_it, double t_min, double t_max, double t0)
Definition simlib.h:1678
nonlinear block: limitation
Definition simlib.h:1561
double tgalpha
Definition simlib.h:1564
double low
Definition simlib.h:1563
virtual void _Eval() override
evaluation with algebraic loop detection
Definition stdblock.cc:55
virtual double Value() override
Definition stdblock.cc:59
double high
Definition simlib.h:1563
Lim(Input in, double l, double h, double tga=1.0)
constructor of limitation block
Definition stdblock.cc:47
iterator(const iterator &x)
Definition simlib.h:643
iterator operator--(int)
Definition simlib.h:652
iterator & operator=(const iterator &x)
Definition simlib.h:644
iterator operator++(int)
Definition simlib.h:649
iterator & operator++()
Definition simlib.h:647
iterator & operator--()
Definition simlib.h:648
iterator(Link *pos)
Definition simlib.h:646
bool operator==(iterator q) const
Definition simlib.h:657
bool operator!=(iterator q) const
Definition simlib.h:656
Link * operator*() const
Definition simlib.h:655
list of Link* items, uses data from Link
Definition simlib.h:635
virtual Link * Get(iterator pos)
remove at position
Definition list.cc:140
Link * GetLast()
remove last
Definition list.cc:132
bool empty()
Definition simlib.h:681
iterator begin()
Definition simlib.h:677
unsigned size() const
Definition simlib.h:676
iterator end()
Definition simlib.h:678
void InsFirst(Link *e)
Definition list.cc:56
Link * back()
Definition simlib.h:680
void PredIns(Link *e, iterator pos)
Definition list.cc:106
void clear()
Definition list.cc:159
static Link * next(Link *p)
Definition simlib.h:636
void PostIns(Link *e, iterator pos)
Definition list.cc:86
Link * front()
Definition simlib.h:679
virtual void Output() const override
print object to default output
Definition output1.cc:44
unsigned n
Definition simlib.h:638
void InsLast(Link *e)
Definition list.cc:71
static Link * previous(Link *p)
Definition simlib.h:637
Link * GetFirst()
remove first
Definition list.cc:124
MultiStepMethod(const char *name, const char *slave_name)
initialize multistep method
Definition numint.cc:410
SingleStepMethod * Slave_Ptr
Definition simlib.h:1170
SingleStepMethod * SlavePtr(void)
return pointer to the starting method (initialize it also)
Definition numint.cc:435
static const char * GetStarter(const char *name)
obtain the name of the starting method of given method
Definition numint.cc:503
static void SetStarter(const char *name, const char *slave_name)
set starting method for given multi-step method
Definition numint.cc:474
virtual void TurnOff(void) override
turn off integration method and its slave (starter)
Definition numint.cc:463
virtual bool PrepareStep(void) override
prepare the object for the step of integration
Definition numint.cc:449
virtual bool IsSingleStep(void) override
Definition simlib.h:1177
double prev_root
Definition simlib.h:1722
virtual double Value() override
Definition algloop.cc:402
double eps_root
Definition simlib.h:1721
Newton(Input i, double eps, unsigned long max_it, double t_min, double t_max, double t0)
Definition simlib.h:1724
block: parameter (can not be changed during simulation run)
Definition simlib.h:874
Parameter & operator=(double x)
Definition simlib.h:878
virtual double Value() override
Definition simlib.h:879
Parameter(double x)
Definition simlib.h:877
Abstract base class for all simulation processesProcess behavior is specified by Behavior method and ...
Definition simlib.h:445
void Leave(Store &s, unsigned long ReqCap=1)
return some capacity
Definition process.cc:292
bool _WaitUntil(bool test)
wait for condition (slow!)
Definition waitunti.cc:123
virtual void Terminate() override
kill process
Definition process.cc:328
ProcessStatus_t
possible process status values
Definition simlib.h:450
virtual void Wait(double dtime)
wait for dtime interval
Definition process.cc:256
void Release(Facility &f)
release facility
Definition process.cc:276
void _WaitUntilRemove()
Definition waitunti.cc:142
bool isCurrent() const
Definition simlib.h:454
void Seize(Facility &f, ServicePriority_t sp=0)
seize facility
Definition process.cc:268
bool isTerminated() const
Definition simlib.h:456
virtual void Activate(double t) override
activate at time t (schedule)
Definition process.cc:244
virtual void Into(Queue &q)
insert process into queue
Definition process.cc:301
virtual void Passivate() override
process deactivation (sleep)
Definition process.cc:314
virtual void _Run() noexcept override
Process dispatch method.
Definition process.cc:412
virtual void Output() const override
print object to default output
Definition output2.cc:108
bool isPrepared() const
Definition simlib.h:453
enum simlib3::Process::ProcessStatus_t _status
bool isInterrupted() const
Definition simlib.h:455
void Enter(Store &s, unsigned long ReqCap=1)
acquire some capacity
Definition process.cc:284
friend class WaitUntilList
Definition simlib.h:458
void * _context
process context pointer
Definition simlib.h:446
Process(Priority_t p=DEFAULT_PRIORITY)
Process constructor sets state to PREPARED.
Definition process.cc:173
void Interrupt()
test of WaitUntil list, allow running others
Definition process.cc:229
virtual void Behavior()=0
behavior description
virtual std::string Name() const override
name of object
Definition process.cc:214
nonlinear block: quantizer
Definition simlib.h:1595
virtual void _Eval() override
evaluation with algebraic loop detection
Definition stdblock.cc:126
double step
Definition simlib.h:1597
Qntzr(Input in, double qstep=1.0)
quantizer constructor
Definition stdblock.cc:118
virtual double Value() override
Definition stdblock.cc:130
priority queue
Definition simlib.h:690
unsigned Length()
Definition simlib.h:713
virtual void Output() const override
print statistics
Definition output2.cc:116
iterator end()
Definition simlib.h:705
virtual Entity * Get(iterator pos)
remove at position
Definition queue.cc:133
Entity * GetFirst()
Definition queue.cc:113
void InsFirst(Entity *e)
Definition queue.cc:73
void PredIns(Entity *e, iterator pos)
Definition queue.cc:102
friend class Store
Definition simlib.h:693
virtual void Insert(Entity *e)
Definition queue.cc:50
iterator begin()
Definition simlib.h:704
Entity * front()
Definition simlib.h:706
List::iterator iterator
Definition simlib.h:695
Entity * GetLast()
Definition queue.cc:123
TStat StatN
Definition simlib.h:696
void Clear()
Definition simlib.h:711
void clear()
initialize
Definition queue.cc:145
Entity * back()
Definition simlib.h:707
void InsLast(Entity *e)
Definition queue.cc:82
friend class Facility
Definition simlib.h:692
bool Empty()
Definition simlib.h:712
void PostIns(Entity *e, iterator pos)
Definition queue.cc:91
virtual double Value() override
Definition algloop.cc:285
RegulaFalsi(Input i, double eps, unsigned long max_it, double t_min, double t_max)
Definition simlib.h:1707
Relay this implementation detects exact time of switch.
Definition simlib.h:1407
Relay(Input i, double p1, double p2, double p3, double p4, double y1, double y2)
relay constructor
Definition stdblock.cc:221
virtual void Eval() override
block evaluation
Definition stdblock.cc:229
virtual double Value() override
Definition stdblock.cc:334
double * tableX
Definition simlib.h:1632
virtual void _Eval() override
evaluation with algebraic loop detection
Definition stdblock.cc:330
Rline(Input in, int num, double *X, double *Y)
constructor of class Rline implements table-defined function (linear interpolation)
Definition stdblock.cc:297
double * tableY
Definition simlib.h:1633
objects of this class call global function periodically (typicaly used for output of continuous model...
Definition simlib.h:511
static Sampler * First
Definition simlib.h:512
double SetStep(double dt=0.0)
change step
Definition sampler.cc:157
static void InitAll()
initialize all samplers (Init)
Definition sampler.cc:103
void(*) function()
function to call periodically
Definition simlib.h:515
Sampler(void(*pf)(), double dt=0.0)
Definition sampler.cc:39
double step
step of sampling
Definition simlib.h:517
double last
last sample time – prevents sample duplication
Definition simlib.h:516
virtual void Output() const override
print object to default output
Definition sampler.cc:80
void Start()
start + sample
Definition sampler.cc:126
void Stop()
sample + stop
Definition sampler.cc:135
virtual void Behavior() override
behavior description
Definition sampler.cc:90
bool on
switch on/off
Definition simlib.h:518
static void ActivateAll()
start all samplers (Run)
Definition sampler.cc:113
Sampler * Next
Definition simlib.h:513
void Sample()
performs sample (function call)
Definition sampler.cc:147
double GetStep() const
get current step
Definition simlib.h:528
basic synchronization tool for processes simplified implementation
Definition simlib.h:1762
virtual void V()
V operation.
Definition semaphor.cc:92
virtual void Output() const override
print object to default output
Definition semaphor.cc:69
Queue Q
internal quqeue
Definition simlib.h:1766
virtual void P()
P operation.
Definition semaphor.cc:77
void Clear()
initialization
Definition semaphor.cc:59
Base class for almost all SIMLIB classes.
Definition simlib.h:304
bool TestAndSetFlag(bool new_value, unsigned n)
internal method for flag manipulation is used for algebraic loop checking in continuous blocks
Definition internal.h:293
bool isAllocated() const
Definition simlib.h:323
@ _CLEAR_ALL_FLAGS
internal flags (bitmasks: 1bit set)
Definition simlib.h:307
virtual void Output() const
print object to default output
Definition object.cc:144
unsigned _flags
bool flags for internal use (TODO bitfield?)
Definition simlib.h:313
bool HasName() const
Definition simlib.h:326
SimObject()
constructor
Definition object.cc:100
virtual std::string Name() const
get object name
Definition object.cc:134
SimObject(const SimObject &)=delete
disable copy operation
SimObject & operator=(const SimObject &)=delete
disable assign operation
base for single-step integration methods
Definition simlib.h:1146
virtual bool IsSingleStep(void) override
Definition simlib.h:1155
void SetStartMode(bool start_mode)
Definition simlib.h:1156
SingleStepMethod(const char *name)
Definition simlib.h:1152
class for statistical information gathering
Definition simlib.h:568
unsigned long Number() const
Definition simlib.h:584
double StdDev() const
Definition stat.cc:97
virtual void Clear()
initialize
Definition stat.cc:77
double min
Definition simlib.h:572
void operator()(double x)
record the value
Definition stat.cc:34
double Sum() const
Definition simlib.h:587
double Max() const
Definition simlib.h:586
double max
Definition simlib.h:573
double Min() const
Definition simlib.h:585
double MeanValue() const
Definition stat.cc:88
double SumSquare() const
Definition simlib.h:588
unsigned long n
Definition simlib.h:574
double sx
Definition simlib.h:570
double sx2
Definition simlib.h:571
virtual void Output() const override
print statistics
Definition output2.cc:166
static std::list< Status * > * Instance(void)
Definition intg.cc:488
static iterator Insert(Status *ptr)
Definition intg.cc:503
static iterator Begin(void)
Definition simlib.h:1042
static void NtoL()
Definition intg.cc:527
std::list< Status * >::iterator iterator
Definition simlib.h:1032
static void EvaluateAll()
Definition intg.cc:573
static std::list< Status * > * ListPtr
list of status variables
Definition simlib.h:1028
static void LtoN()
Definition intg.cc:542
static iterator End(void)
Definition simlib.h:1046
static void InitAll()
Definition intg.cc:557
static size_t Size(void)
Definition simlib.h:1038
static bool isAny(void)
Definition simlib.h:1034
static void ClearAllValueOK()
Definition intg.cc:589
static void Erase(iterator it)
Definition intg.cc:514
StatusMemory(const StatusMemory &)=delete
StatusMemory(std::list< Memory * > *PtrList=PtrStatusMList)
Definition simlib.h:1216
void operator=(const StatusMemory &)=delete
static void StoreState(Memory &di, Memory &si, StatusMemory &xi)
store state of integrators and status variables
Definition numint.cc:570
static StatusIterator LastStatus(void)
Definition simlib.h:1202
friend class EULER
Definition simlib.h:1207
StatusMethod(const StatusMethod &)=delete
StatusContainer::iterator StatusIterator
Definition simlib.h:1198
friend class RKE
Definition simlib.h:1208
virtual ~StatusMethod()
Definition simlib.h:1233
std::list< Memory * > StatusMList
Definition simlib.h:1195
static std::list< Memory * > * PtrStatusMList
Definition simlib.h:1196
virtual void StatusResize(size_t size)
resize status memories to the given size
Definition numint.cc:557
static void RestoreState(double dthlf, Memory &di, Memory &si, StatusMemory &xi)
restore state of integrators and status variables
Definition numint.cc:594
virtual void TurnOff(void) override
turn off integration method: flush memories etc...
Definition numint.cc:528
static void GoToState(Memory &di, Memory &si, StatusMemory &xi)
move startpoint to given state
Definition numint.cc:622
virtual bool PrepareStep(void) override
prepare object for integration step
Definition numint.cc:539
static StatusIterator FirstStatus(void)
Definition simlib.h:1199
State variables (memory) base for blocks with internal state (Relay, ...).
Definition simlib.h:1340
void Restore()
Definition intg.cc:439
virtual void Eval() override
evaluate without loop detection
Definition intg.cc:469
void SetOldState(double s)
Definition simlib.h:1362
void Set(double value)
set state variable value (step change)
Definition intg.cc:429
double st
status
Definition simlib.h:1347
virtual double Value() override
value of state variable
Definition intg.cc:448
void SetState(double s)
Definition simlib.h:1360
double stl
status from previous step
Definition simlib.h:1348
double GetState(void)
Definition simlib.h:1361
void Init(double initvalue)
set initial value
Definition intg.cc:419
Status(Input i, double initvalue=0)
Definition intg.cc:398
void SetValid(bool flag)
Definition simlib.h:1364
double GetOldState(void)
Definition simlib.h:1363
double initval
initial value
Definition simlib.h:1342
void CtrInit()
Definition intg.cc:383
StatusContainer::iterator it_list
position in list of status variables
Definition simlib.h:1345
(SOL-like) store store capacity can be changed dynamically
Definition simlib.h:790
void SetQueue(Queue *queue)
change input queue
Definition store.cc:113
void SetCapacity(unsigned long _capacity)
change the capacity
Definition store.cc:102
unsigned char _Qflag
true if store is owner of input queue
Definition simlib.h:791
unsigned long Capacity() const
max capacity
Definition simlib.h:810
bool Full() const
store is full
Definition simlib.h:811
virtual void Output() const override
print statistics
Definition output2.cc:187
virtual void Leave(unsigned long rcap)
deallocate capacity
Definition store.cc:152
unsigned long capacity
Capacity of store.
Definition simlib.h:793
virtual void Enter(Entity *e, unsigned long rcap)
allocate capacity
Definition store.cc:128
bool OwnQueue() const
OwnQueue.
Definition store.cc:203
unsigned long Free() const
free capacity
Definition simlib.h:808
TStat tstat
usage statistics
Definition simlib.h:796
bool Empty() const
store is empty
Definition simlib.h:812
unsigned long Used() const
used capacity
Definition simlib.h:809
Queue * Q
input queue
Definition simlib.h:795
unsigned QueueLen() const
Definition simlib.h:814
virtual void Clear()
initialize
Definition store.cc:191
unsigned long used
Currently used capacity.
Definition simlib.h:794
virtual void QueueIn(Entity *e, unsigned long c)
insert entity into queue
Definition store.cc:181
time dependent statistic
Definition simlib.h:597
double MeanValue() const
Definition tstat.cc:96
double sx2t
Definition simlib.h:600
double min
Definition simlib.h:601
double LastValue() const
Definition simlib.h:624
double Max() const
Definition simlib.h:619
friend class Queue
Definition simlib.h:609
unsigned long n
Definition simlib.h:606
friend class Store
Definition simlib.h:608
double xl
Definition simlib.h:605
double StartTime() const
Definition simlib.h:622
virtual void operator()(double x)
record the value
Definition tstat.cc:64
double tl
Definition simlib.h:604
double Sum() const
Definition simlib.h:620
TStat(double initval=0.0)
Definition tstat.cc:32
double t0
Definition simlib.h:603
virtual void Clear(double initval=0.0)
initialize
Definition tstat.cc:83
double SumSquare() const
Definition simlib.h:621
virtual void Output() const override
print object to default output
Definition output2.cc:223
unsigned long Number() const
Definition simlib.h:617
double max
Definition simlib.h:602
double sxt
Definition simlib.h:599
friend class Facility
Definition simlib.h:607
double Min() const
Definition simlib.h:618
double LastTime() const
Definition simlib.h:623
block: variable (value can be changed)
Definition simlib.h:863
virtual double Value() override
Definition simlib.h:868
Variable(double x=0)
Definition simlib.h:866
Variable & operator=(double x)
Definition simlib.h:867
abstract base class for all blocksblocks/SimObject have not copy semantics (TODO: add move semantics)
Definition simlib.h:830
abstract base class for all state-condition blocks State event in combined model is executed at the t...
Definition simlib.h:1489
aCondition * Next
Definition simlib.h:1491
static void InitAll()
Definition cond.cc:56
static aCondition * First
Definition simlib.h:1490
static void TestAll()
Definition cond.cc:123
aCondition(const aCondition &)=delete
virtual void Action()=0
state event description
static bool isAny()
Definition cond.cc:70
virtual bool Test()=0
test of the condition
virtual void SetNewStatus()=0
update
virtual void Init()=0
initialize
static void AllActions()
Definition cond.cc:130
static void SetAll()
Definition cond.cc:65
void operator=(const aCondition &)=delete
aContiBlock1(Input i)
constructor for blocks with single input
Definition continuous.cc:61
double InputValue()
Definition simlib.h:949
double Input2Value()
Definition simlib.h:970
aContiBlock2(Input i1, Input i2)
ctr for blocks with 2 inputs
Definition continuous.cc:79
double Input1Value()
Definition simlib.h:969
double Input2Value()
Definition simlib.h:983
aContiBlock3(Input i1, Input i2, Input i3)
ctr for blocks with 3 inputs
Definition continuous.cc:88
double Input1Value()
Definition simlib.h:982
double Input3Value()
Definition simlib.h:984
abstract base for continuous blocks with single output suitable for expression-tree building and eval...
Definition simlib.h:837
virtual double Value()=0
virtual void Eval()
evaluate without loop detection
Definition simlib.h:839
virtual void _Eval()
evaluation with algebraic loop detection
Definition continuous.cc:48
void SetStarter(const char *name, const char *slave_name)
Definition simlib.h:1261
const char * GetStarter(const char *name)
Definition simlib.h:1275
void InstallBreak(void(*f)())
InstallBreak — set function for checking if user breaks simulation.
Definition run.cc:104
const char * GetMethod(void)
Definition simlib.h:1254
void SetMethod(const char *name)
Definition simlib.h:1247
Implementation of class CalendarList interface is static - using global functions in SQS namespace.
Definition algloop.cc:32
void Activate(Entity *e)
activate entity e
Definition simlib.h:436
const double & Time
model time (is NOT the block)
Definition run.cc:48
const double & StepSize
actual integration step
Definition intg.cc:48
void Stop()
stop current simulation run
Definition run.cc:147
Input Cos(Input x)
Definition fun.cc:97
const double & NextTime
next-event time
Definition run.cc:49
Input Max(Input x, Input y)
Definition fun.cc:115
double Gamma(double alfa, double beta)
Gamma distribution generator.
Definition random2.cc:141
void DebugOFF()
stop debugging output
Definition debug.cc:42
void Abort()
end simulation program
Definition run.cc:159
double Rayle(double delta)
Definition random2.cc:219
const double & StartTime
time of simulation start
Definition run.cc:47
Input operator-(Input a, Input b)
block operator -
Input ATan(Input x)
Definition fun.cc:102
Input Min(Input x, Input y)
Definition fun.cc:114
const double & RelativeError
max. rel. error
Definition intg.cc:54
Input Sign(Input x)
Definition fun.cc:110
aContiBlock & T
simulation time block reference
const unsigned SIMLIB_version
library version
Definition version.cc:9
std::string GetName(SimObject &o)
get name of object
Definition name.cc:66
void Passivate(Entity *e)
passivate entity e
Definition simlib.h:437
Frict Friction
Definition simlib.h:1622
Insv DeadZone
Definition simlib.h:1589
Input operator+(Input a, Input b)
block operator +
const double & MaxStep
maximal integration step
Definition intg.cc:47
Input Abs(Input x)
Definition fun.cc:94
double Triag(double mod, double min, double max)
Definition random2.cc:193
const double & AbsoluteError
max. abs. error of integration
Definition intg.cc:53
void DebugON()
start debugging output
Definition debug.cc:36
Input Ln(Input x)
Definition fun.cc:107
void SetOutput(const char *name)
Definition print.cc:50
double Beta(double th, double fi, double min, double max)
Beta distribution generator.
Definition random2.cc:181
const double & EndTime
time of simulation end
Definition run.cc:50
void SetCalendar(const char *name)
choose calendar implementation default is list
Definition calendar.cc:1250
double Uniform(double l, double h)
Uniform distribution generator.
Definition random2.cc:71
void RemoveName(SimObject &o)
remove name
Definition name.cc:54
int NegBinM(double p, int m)
Definition random2.cc:164
double Weibul(double lambda, double alfa)
Weibul distribution generator.
Definition random2.cc:94
Input operator*(Input a, Input b)
block operator *
Input Exp(Input x)
Definition fun.cc:105
Input ATan2(Input y, Input x)
Definition fun.cc:103
unsigned char ServicePriority_t
Service priority (see Facility::Seize).
Definition simlib.h:370
unsigned long Debug(unsigned long mode)
Definition debug.cc:48
Input Tan(Input x)
Definition fun.cc:98
Input Pow(Input x, Input y)
Definition fun.cc:108
int _Print(const char *fmt,...)
Definition print.cc:68
Lim Limitation
Definition simlib.h:1572
double min(double a, double b)
Definition internal.h:285
int NegBin(double q, int k)
Definition random2.cc:121
const double SIMLIB_MINTIME
minimal time value
Definition simlib.h:152
Qntzr Quantizer
Definition simlib.h:1605
double max(double a, double b)
Definition internal.h:286
int Geom(double q)
Definition random2.cc:257
void SetName(SimObject &o, const std::string &name)
assign name to object
Definition name.cc:42
void SetStep(double _dtmin, double _dtmax)
Definition intg.cc:92
@ DEFAULT_PRIORITY
Definition simlib.h:365
@ LOWEST_PRIORITY
Definition simlib.h:363
@ HIGHEST_PRIORITY
Definition simlib.h:364
void Error(const char *fmt,...)
print message and terminate program
Definition print.cc:123
void Run()
run simulation experiment
Definition run.cc:228
const double & MinStep
minimal integration step
Definition intg.cc:46
signed char EntityPriority_t
Priority of the process/event.
Definition simlib.h:368
int Print(const char *fmt,...)
for Output methods, can be redirected
Definition print.cc:92
void SIMLIB_Init(double T0, double T1, unsigned version)
Definition run.cc:177
Input Log10(Input x)
Definition fun.cc:106
double Erlang(double alfa, int beta)
Erlang distribution generator.
Definition random2.cc:109
Input Sqrt(Input x)
Definition fun.cc:112
const double & OptStep
optimal integration step
Definition intg.cc:49
Input Sin(Input x)
Definition fun.cc:96
double Normal(double mi, double sigma)
Gauss distribution generator.
Definition random2.cc:82
int HyperGeom(double p, int n, int m)
Definition random2.cc:270
void RandomSeed(long seed)
Definition random1.cc:64
double Exponential(double mv)
Exponential distribution generator.
Definition random2.cc:152
int Poisson(double lambda)
Poisson distribution generator.
Definition random2.cc:229
double Random()
Definition random1.cc:95
void Init(double t0, double t1=SIMLIB_MAXTIME)
Definition simlib.h:186
void SetAccuracy(double _abserr, double _relerr)
Definition intg.cc:106
const double SIMLIB_MAXTIME
maximum time (1e30 works for float, too)
Definition simlib.h:153
Blash Backlash
Definition simlib.h:1401
Input ASin(Input x)
Definition fun.cc:100
double Logar(double mi, double delta)
Definition random2.cc:210
Input Sqr(Input x)
square function
Entity *const & Current
pointer to active (now running) entity
Definition run.cc:54
Input operator/(Input a, Input b)
block operator /
Hyst Hysteresis
Definition simlib.h:1385
void ContractStep()
contract step of integration
Definition intg.cc:64
Input ACos(Input x)
Definition fun.cc:101
const SIMLIB_statistics_t & SIMLIB_statistics
interface to internal run-time statistics structure
Definition run.cc:78
const char * SIMLIB_version_string()
Definition version.cc:13
void SetBaseRandomGenerator(double(*new_gen)())
Definition random1.cc:103
#define __SIMLIB__
Definition simlib.h:8
#define UnRegisterReference(aContiBlockPtr)
Definition simlib.h:888
#define RegisterReference(aContiBlockPtr)
Definition simlib.h:887
Test(Input F)
Definition _test_.cc:14
activation record
Definition calendar.cc:145
double Value() override
Evaluate expression and return the value.
Expression(Input i)
Definition simlib.h:957
internal statistics structure contains basic statistics of simulator execution
Definition simlib.h:1806
void Output() const
print run-time statistics to output
Definition output1.cc:63
SIMLIB_statistics_t()
constructor runs SIMLIB_statistics_t::Init()
Definition run.cc:65
void Init()
initialize - used at the start of each Run()
Definition run.cc:68