シミュレーションの演習のコード

BGSA4のコードを以下に示します。このコードは20-Sim用です。

BGSA4のコード

C
parameters
	real c = 4;
variables
	real global ce1;
equations
	state = int(p.f);
	p.e = state / c;
	ce1=p.e;

I
parameters
	real i = 1;
	real global lmt;
variables
	real global ss;
	boolean reset;
equations
 reset=if abs(ss) >=  lmt then true else false end;
    state = resint(p.e,0,reset,0);
    p.f = state / i;

Integrate
parameters
	real initial = 0;		// initial value
variables
	real global ss;
equations
	output = int (input, initial);
	ss=output;
     
MSe
variables
	real flow;
	real global f1;

equations
	p.e=effort;
	flow = p.f;
	f1=p.e;

R
parameters
	real r = 1.0;
variables
	real global r1;
equations
	p.e = r * p.f;
	r1=p.e;

Ramp
parameters
	real slope = 5 {1/s};
	real start_time = 1.0 {s};
variables
	boolean hidden change;
equations
	"calculate at least at the start time"
	change = timeevent (start_time);

	"calculate the ramp signal"
	pre= slope * ramp (start_time)+10.0;
     
Se
parameters
	real effort = 0;
	real global lmt=2.0;
variables
	real flow;
	real global ce1;
	real global ss;
	real global r1;
	real global f1;
equations
	p.e =if abs(ss) >= lmt  then
		- (f1+ce1+r1)*sign(ss)
		else
		effort
		end;
	flow = p.f;

Sine
parameters
	
	real omega = 3.1456{rad/s};		// angular frequency of the wave
variables
	boolean hidden change;
	real hidden half;
equations
	"calculate at least 2 points per cycle to get a triangle"
	half = pi / omega;
	change = frequencyevent (half, half / 2);

	"calculate the sine wave"
	output = pre* sin ( omega * time);