Skip to content

Commit bcab6f6

Browse files
author
vruge
committed
added test for inline function
from wibraun/OpenModelica-testsuite/
1 parent 6665a46 commit bcab6f6

19 files changed

+1262
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
TEST = ../../../rtest -v
2+
3+
TESTFILES = \
4+
inlineArray1.mos \
5+
inlineArray2.mos \
6+
inlineArray3.mos \
7+
inlineArrayRecord.mos \
8+
inlineFunction1.mos \
9+
inlineFunction2.mos \
10+
inlineFunction3.mos \
11+
inlineFunction4.mos \
12+
inlineFunction5.mos \
13+
inlineFunction6.mos \
14+
inlineFunction7.mos \
15+
inlineFunction8.mos \
16+
inlineFunction9.mos \
17+
inlineFunction10.mos \
18+
inlineFunction11.mos \
19+
testBug3687.mos \
20+
testComplexMath.mos \
21+
22+
23+
# test that currently fail. Move up when fixed.
24+
# Run make failingtest
25+
FAILINGTESTFILES = \
26+
27+
# Dependency files that are not .mo .mos or Makefile
28+
# Add them here or they will be cleaned.
29+
DEPENDENCIES = \
30+
*.mo \
31+
*.mos \
32+
Makefile \
33+
34+
CLEAN = `ls | grep -w -v -f deps.tmp`
35+
36+
.PHONY : test clean getdeps failingtest
37+
38+
test:
39+
@echo
40+
@echo Running tests...
41+
@echo
42+
@echo OPENMODELICAHOME=" $(OPENMODELICAHOME) "
43+
@$(TEST) $(TESTFILES)
44+
45+
# Cleans all files that are not listed as dependencies
46+
clean:
47+
@echo $(DEPENDENCIES) | sed 's/ /\\|/g' > deps.tmp
48+
@rm -f $(CLEAN)
49+
50+
# Run this if you want to list out the files (dependencies).
51+
# do it after cleaning and updating the folder
52+
# then you can get a list of file names (which must be dependencies
53+
# since you got them from repository + your own new files)
54+
# then add them to the DEPENDENCIES. You can find the
55+
# list in deps.txt
56+
getdeps:
57+
@echo $(DEPENDENCIES) | sed 's/ /\\|/g' > deps.tmp
58+
@echo $(CLEAN) | sed -r 's/deps.txt|deps.tmp//g' | sed 's/ / \\\n/g' > deps.txt
59+
@echo Dependency list saved in deps.txt.
60+
@echo Copy the list from deps.txt and add it to the Makefile @DEPENDENCIES
61+
62+
failingtest:
63+
@echo
64+
@echo Running failing tests...
65+
@echo
66+
@$(TEST) $(FAILINGTESTFILES)
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// name: inlineArray1
2+
// status: correct
3+
4+
// use new inline method
5+
setCommandLineOptions("+inlineMethod=append");
6+
7+
loadString("
8+
model foo
9+
function f
10+
input Real[5] x;
11+
output Real[7] y;
12+
protected
13+
Real abs1 = abs(sum(x));
14+
Real sumx = exp(-sqrt(abs1));
15+
Real tmpy;
16+
Real tmpyy;
17+
algorithm
18+
y[1] := sumx^2;
19+
y[2] := 2*sumx^2;
20+
y[3] := 3*sumx^2;
21+
y[4] := 4*sumx^2;
22+
y[5] := 5*sumx^2;
23+
y[6] := 6*sumx^2;
24+
tmpy := 7*sumx^2;
25+
tmpyy := abs(tmpy/sum(y[i] for i in 1:6));
26+
y[7] := exp(-sqrt(tmpyy)/tmpy);
27+
annotation(Inline=true);
28+
end f;
29+
Real y(fixed = true, start = 0);
30+
protected
31+
Real[5] a(each start = 1);
32+
Real c;
33+
Real[5] x(each start =0);
34+
Real[:] z = {i*sin(time) + 1 for i in 1:10};
35+
equation
36+
x[1] = a[1] + a[2];
37+
x[2] = z[1] + a[1];
38+
x[3] = z[2] + a[3] + a[1] + 2*a[2] + sum(z);
39+
x[4] = z[2] + a[3] + a[1] + 2*a[2];
40+
x[5] = z[2] + x[3] + a[1] + 2*a[2] + cos(sum(a));
41+
a[1] = sum(f(x))/10;
42+
a[2] = sum(f(z[1:5]))/10;
43+
a[3] = sum(f(z[6:10]))/10;
44+
a[4] = sum(f(z[2:6]))/10;
45+
a[5] = sum(f(z[3:7]))/10;
46+
c = exp(-sum(f(a)));
47+
der(y) = sin(c) - cos(sum(f(x))) + sum(a)/10;
48+
end foo;
49+
");
50+
getErrorString();
51+
52+
setCommandLineOptions("+simplifyLoops=2");
53+
//setCommandLineOptions("+d=backenddaeinfo");
54+
getErrorString();
55+
simulate(foo);
56+
getErrorString();
57+
val(y,{0,0.5,1.0}); // 0, -1
58+
setCommandLineOptions("+inlineMethod=replace");
59+
getErrorString();
60+
simulate(foo);
61+
getErrorString();
62+
val(y,{0,0.5,1.0}); // 0, -1
63+
64+
// Result:
65+
// true
66+
// true
67+
// ""
68+
// true
69+
// ""
70+
// record SimulationResult
71+
// resultFile = "foo_res.mat",
72+
// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'foo', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
73+
// messages = ""
74+
// end SimulationResult;
75+
// "Warning: There are iteration variables with default zero start attribute. Use +d=initialization for more information.
76+
// "
77+
// {0.0,-0.4988765073162942,-0.9987936798262338}
78+
// true
79+
// ""
80+
// record SimulationResult
81+
// resultFile = "foo_res.mat",
82+
// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'foo', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
83+
// messages = ""
84+
// end SimulationResult;
85+
// ""
86+
// {0.0,-0.4988765881077395,-0.9987937622066468}
87+
// endResult
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// name: inlineArray2
2+
// status: correct
3+
4+
// use new inline method
5+
setCommandLineOptions("+inlineMethod=append");
6+
7+
loadString("
8+
model foo
9+
function f
10+
input Real[5] x;
11+
output Real[7] y;
12+
protected
13+
Real sumx = exp(-sqrt(sum(x)));
14+
Real tmpy;
15+
algorithm
16+
y[1] := sumx^2;
17+
y[2] := 2*sumx^2;
18+
y[3] := 3*sumx^2;
19+
y[4] := 4*sumx^2;
20+
y[5] := 5*sumx^2;
21+
y[6] := 6*sumx^2;
22+
tmpy := 7*sumx^2;
23+
y[7] := exp(-sqrt(tmpy/sum(y[i] for i in 1:6))/tmpy);
24+
annotation(Inline=true);
25+
end f;
26+
27+
function f1
28+
input Real[7] y;
29+
output Real[5] x;
30+
protected
31+
Real[5] tmpx = {y[1] + y[2], y[2] + y[3], y[4] + y[5], y[6] + y[7], y[7]};
32+
Real[7] xx = f(tmpx);
33+
algorithm
34+
x[1] := xx[1] + xx[6];
35+
x[2] := xx[2] + x[1];
36+
x[3] := xx[3] + x[2];
37+
x[4] := xx[4] + x[3];
38+
x[5] := xx[5] + x[4];
39+
end f1;
40+
41+
Real y(fixed = true, start = 1);
42+
Real v(fixed = true, start = -1);
43+
protected
44+
Real[5] a;
45+
Real c;
46+
Real d;
47+
48+
Real[5] x;
49+
Real[:] z = {i*sin(time) + 1 for i in 1:10};
50+
Real[5] w = f1(z[1:7]);
51+
equation
52+
x[1] = a[1] + a[2] + w[1];
53+
x[2] = z[1] + a[1];
54+
x[3] = z[2] + a[3] + a[1] + 2*a[2] + sum(z);
55+
x[4] = z[2] + a[3] + a[1] + 2*a[2];
56+
x[5] = z[2] + x[3] + a[1] + 2*a[2] + cos(sum(a)) + w[2];
57+
a[1] = sum(f(x))/10;
58+
a[2] = sum(f(z[1:5]))/10;
59+
a[3] = sum(f(z[6:10]))/10;
60+
a[4] = sum(f(z[2:6]))/10;
61+
a[5] = sum(f(z[3:7]))/10;
62+
c = exp(-sum(f(a))) - sum(w);
63+
d = sum(w);
64+
der(y) = (sin(c) - cos(sum(f(x))) + sum(a)/10)*der(v) + cos(time);
65+
der(v) = der(y)*d;
66+
end foo;
67+
");
68+
getErrorString();
69+
70+
//setCommandLineOptions("+d=backenddaeinfo");
71+
setCommandLineOptions("+simplifyLoops=2");
72+
getErrorString();
73+
simulate(foo);
74+
getErrorString();
75+
val(v,{0,0.5,1.0}); // -1, -0.986
76+
val(y,{0,0.5,1.0}); // 1, 1.823
77+
78+
// Result:
79+
// true
80+
// true
81+
// ""
82+
// true
83+
// ""
84+
// record SimulationResult
85+
// resultFile = "foo_res.mat",
86+
// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'foo', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
87+
// messages = ""
88+
// end SimulationResult;
89+
// "Warning: There are iteration variables with default zero start attribute. Use +d=initialization for more information.
90+
// "
91+
// {-1.0,-0.9862025310764797,-0.9859173056116497}
92+
// {1.0,1.464675331140519,1.826435278620429}
93+
// endResult
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// name: inlineArray3
2+
// status: correct
3+
4+
// use new inline method
5+
setCommandLineOptions("+inlineMethod=append");
6+
7+
loadString("
8+
model foo
9+
function f
10+
input Real[5] x;
11+
output Real[7] y;
12+
protected
13+
Real sumx = exp(-sqrt(sum(x)));
14+
Real tmpy;
15+
algorithm
16+
y[1] := sumx^2;
17+
y[2] := 2*sumx^2;
18+
y[3] := 3*sumx^2;
19+
y[4] := 4*sumx^2;
20+
y[5] := 5*sumx^2;
21+
y[6] := 6*sumx^2;
22+
tmpy := 7*sumx^2;
23+
y[7] := exp(-sqrt(tmpy/sum(y[i] for i in 1:6))/tmpy);
24+
annotation(Inline=true);
25+
end f;
26+
27+
Real y(fixed = true, start = 1);
28+
Real v(fixed = true, start = -1);
29+
Real h(start = 0);
30+
protected
31+
Real[5] a;
32+
Real c;
33+
Real d;
34+
35+
Real[5] x;
36+
Real[:] z = {i*sin(time) + 1 for i in 1:10};
37+
Real[5] w = {z[i]^i/sum(z) for i in 1:5};
38+
equation
39+
x[1] = a[1] + a[2] + w[1];
40+
x[2] = z[1] + a[1];
41+
x[3] = z[2] + a[3] + a[1] + 2*a[2] + sum(z);
42+
x[4] = z[2] + a[3] + a[1] + 2*a[2];
43+
x[5] = z[2] + x[3] + a[1] + 2*a[2] + cos(sum(a)) + w[2];
44+
a[1] = sum(f(x))/10;
45+
a[2] = sum(f(z[1:5]))/10;
46+
a[3] = sum(f(z[6:10]))/10;
47+
a[4] = sum(f(z[2:6]))/10;
48+
a[5] = sum(f(z[3:7]))/10;
49+
c = exp(-sum(f(a))) - sum(w);
50+
d = sum(w);
51+
der(y) = sin(c) - cos(sum(f(x))) + sum(a)/10;
52+
der(v) = y - d;
53+
54+
when sample(0,0.1) then
55+
h = v + y + sum(f(z[1:5]))/10 + sum(f(z[6:10]))/10;
56+
end when;
57+
end foo;
58+
");
59+
getErrorString();
60+
61+
setCommandLineOptions("+simplifyLoops=2");
62+
//setCommandLineOptions("+d=backenddaeinfo");
63+
getErrorString();
64+
simulate(foo);
65+
getErrorString();
66+
val(h,{0,0.5,1.0}); // 0, -17.139
67+
68+
setCommandLineOptions("+inlineMethod=replace");
69+
getErrorString();
70+
simulate(foo);
71+
getErrorString();
72+
val(h,{0,0.5,1.0}); // 0, -17.139
73+
74+
75+
// Result:
76+
// true
77+
// true
78+
// ""
79+
// true
80+
// ""
81+
// record SimulationResult
82+
// resultFile = "foo_res.mat",
83+
// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'foo', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
84+
// messages = ""
85+
// end SimulationResult;
86+
// "Warning: The initial conditions are not fully specified. Use +d=initialization for more information.
87+
// Warning: There are iteration variables with default zero start attribute. Use +d=initialization for more information.
88+
// "
89+
// {0.04812243429093915,-2.749810253792299,-24.0237961570759}
90+
// true
91+
// ""
92+
// record SimulationResult
93+
// resultFile = "foo_res.mat",
94+
// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'foo', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
95+
// messages = ""
96+
// end SimulationResult;
97+
// "Warning: The initial conditions are not fully specified. Use +d=initialization for more information.
98+
// Warning: There are iteration variables with default zero start attribute. Use +d=initialization for more information.
99+
// "
100+
// {0.04812243429093915,-2.749810335170811,-24.02379626652539}
101+
// endResult

0 commit comments

Comments
 (0)