Skip to content

Commit

Permalink
add test for tuple return with records
Browse files Browse the repository at this point in the history
See: Modelica.Electrical.Spice3.Examples.Graetz
Additionally let the record contain an array.
  • Loading branch information
rfranke committed Aug 13, 2015
1 parent d8f3d68 commit 07dceac
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions openmodelica/cppruntime/Makefile
Expand Up @@ -4,6 +4,7 @@ TESTFILES = \
tearnonlin1.mos \
WhenStatement1.mos \
BouncingBall.mos \
recordTupleReturnTest.mos \
solveTest.mos

FAILINGTESTFILES=
Expand Down
66 changes: 66 additions & 0 deletions openmodelica/cppruntime/recordTupleReturnTest.mos
@@ -0,0 +1,66 @@
// name: recordTupleReturnTest
// keywords: return tuple record array
// status: correct
// teardown_command: rm -f *RecordTupleReturn*

setCommandLineOptions("+simCodeTarget=Cpp");

loadModel(Modelica);
loadString("
model RecordTupleReturn
record R // record with array member
Real u;
Real[3] a;
end R;

function f // return two values, one of them a record
input Real u;
output Real y;
output R r;
algorithm
y := 2*u;
r.u := u;
r.a := {1, 2, 3};
end f;

function g // process tuple return with record in a function
input Real u;
output Real y;
output R r;
protected
R r2;
algorithm
(y, r2) := f(u);
r.u := r2.u;
r.a := u*r2.a;
end g;

model Test // process tuple return with a record in a model
input Real u = 0; // prevent presolving
Real y;
R r;
equation
(y, r) = g(u + 1);
end Test;
end RecordTupleReturn;
");
getErrorString();

simulate(RecordTupleReturn.Test);
val(y, 0);
val(r.a[3], 0);
getErrorString();

// Result:
// true
// true
// true
// ""
// record SimulationResult
// resultFile = "RecordTupleReturn.Test_res.mat",
// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'RecordTupleReturn.Test', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
// messages = ""
// end SimulationResult;
// 2.0
// 3.0
// ""

0 comments on commit 07dceac

Please sign in to comment.