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

GS17のコードを以下に示します。GS17はBGSPによるシミュレーションは困難です。代数ループが必然的に生じ、回避のためには遅延素子が必要なのにBGSPにはないからです。従って、ここに示すソースコードとは20-Simにおける各要素の式です。20-Simでは式は自動的に入力されますが、必ずしも正しいとは言えないので十分点検する必要があります。ここでは表の値も示しました。便宜上表はc:\usr\data*.txtにあるとしましたが、任意です。
方法1と方法2に分けて記述します。table1とtable2は方法1、2に共通です。

GS17のコード

方法1のコード

C
parameters
	real c = 1;
equations
    state = int(p.f);
    p.e = state / c;

I
parameters
	real i = 1;
   string f1='c:\usr\data1.txt';
   string f2='c:\usr\data2.txt';
equations
    state = int(p.e);
    if p.e >0 then
    p.f =table(f2,state) / i;
    else
    p.f=table(f1,state)/i;
    end;

R
parameters
	real r = 0.0;
equations					
	p.e = r * p.f;

Se
parameters
	real effort = 1.5;
variables
	real flow;
equations
	p.e = effort;
	flow = p.f;
	
data1.txt
-1.00000       -1.20000
-0.98000       -1.00000
-0.93000       -0.90000
-0.86000       -0.80000
-0.77000       -0.70000
-0.53000       -0.50000
-0.40000       -0.40000
0.150000       0.00000
0.670000       0.40000
0.810000       0.50000
0.930000       0.70000
0.980000       0.80000
0.990000       0.90000
1.000000       1.00000
1.020000       1.20000

data2.txt
-1.02000       -1.20000
-1.00000       -1.00000
-0.99000       -0.90000
-0.98000       -0.80000
-0.93000       -0.70000
-0.81000       -0.50000
-0.67000       -0.40000
-0.150000       0.00000
0.400000       0.40000
0.530000       0.50000
0.770000       0.70000
0.860000       0.80000
0.930000       0.90000
0.980000       1.00000
1.000000       1.20000

Runge-Kutta4
Step Size 0.01
Algebraic Relations Solver 1e-7

方法2のコード

C
parameters
	real c = 1;
equations
    state = int(p.f);
    p.e = state / c;
I
parameters
	real i = 1;
equations
    state = int(p.e);
    p.f =port1 / i;

R
parameters
	real r = 0.0;
equations					
	p.e = r * p.f;

Se
parameters
	real effort = 1.5;
variables
	real flow;
equations
	p.e = effort;
	flow = p.f;

Delay
parameters
	real delay = 1.0e-3 {s};	// time delay (s)
	real initial = 0;		// initial value
variables
	real delayOutput;
equations
	delayOutput =  tdelay (input,delay);
	if (time <= delay) then
		output = initial;
	else
		output = delayOutput;
	end;
       
Switch
equations
	output = if condition >= 0.0 then
		input_high
	else
		if condition < 0.0 then
			input_low
		else
			0.0
		end
	end;        
Table
parameters					
	string f2='c:\usr\data2.txt';
equations					
	output = table (f2, input);
   
Table1
parameters					
	string f1='c:\usr\data1.txt';
equations					
	output = table (f1, input);