Skip to content

Commit

Permalink
add test for function inputs to functions
Browse files Browse the repository at this point in the history
  • Loading branch information
rfranke committed Aug 23, 2015
1 parent e23617b commit cb21b1c
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 \
functionPointerTest.mos \
recordTupleReturnTest.mos \
solveTest.mos

Expand Down
66 changes: 66 additions & 0 deletions openmodelica/cppruntime/functionPointerTest.mos
@@ -0,0 +1,66 @@
// name: functionPointer
// keywords: function pointer
// status: correct
// teardown_command: rm -f *FunctionPointer.Test*

setCommandLineOptions("+simCodeTarget=Cpp");

loadModel(Modelica);
loadString("
package FunctionPointer
partial function pfunc
input Real u;
output Real y;
end pfunc;

function func
input Real u;
input Real v;
output Real y;
algorithm
y := u + v;
end func;

function feval
input FunctionPointer.pfunc f;
input Real u;
output Real y;
algorithm
y := f(u);
end feval;

function feval2
input FunctionPointer.pfunc f;
input Real u;
output Real y;
algorithm
y := f(u) + feval(function func(v = u), u);
end feval2;

model Test
input Real u = 0; // prevent presolving
Real y;
equation
y = feval2(function func(v = 2), u + 1);
end Test;
end FunctionPointer;
");
getErrorString();

simulate(FunctionPointer.Test);
val(y, 0);
getErrorString();

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

0 comments on commit cb21b1c

Please sign in to comment.