Relay example.
const double T1 = 10,
T2 = 50,
K1 = 50,
K2 = 1;
const double XValue = 10;
const double StepPrn = 0.1;
class System : public aContiBlock {
Integrator y2, y1;
public:
System(Input inp, double T1, double T2, double K1, double K2) :
y2( (K1*inp-y2)/T1 ),
y1( (K2*y2-y1)/T2 ) {}
double Value() { return y1.Value(); }
};
class Model : public aContiBlock {
Relay r;
System s;
public:
Model(Input inp, double T1, double T2, double K1, double K2) :
r( inp - s, 0, 0, 1, 1, 0, 1 ),
s( r, T1, T2, K1, K2 ) {}
double Value() { return s.Value(); }
double relayValue() { return r.Value(); }
};
Model s(XValue, T1, T2, K1, K2);
Print(
"%-8.2f %g %g\n",
T.
Value(), s.Value(), s.relayValue());
}
Print(
"# heating --- model of temperatre regulation\n");
Print(
"# Time temp relay\n");
}
virtual double Value()=0
get block output value this method should be defined in classes derived from aContiBlock
aContiBlock & T
simulation time block reference
void SetAccuracy(double _abserr, double _relerr)
set max.
void SetStep(double _dtmin, double _dtmax)
Set integration step interval.
void SetOutput(const char *name)
redirects Output(), Print() to file
void Run()
run simulation experiment
int Print(const char *fmt,...)
for Output methods, can be redirected
void Init(double t0, double t1=SIMLIB_MAXTIME)
Initialize simulator and model time.
const SIMLIB_statistics_t & SIMLIB_statistics
interface to internal run-time statistics structure
Main SIMLIB/C++ interface.
void Output() const
print run-time statistics to output