Skip to content

Commit

Permalink
[NF] Add function derivative tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
perost authored and OpenModelica-Hudson committed Jun 11, 2018
1 parent 82c85da commit 3cc7e9d
Show file tree
Hide file tree
Showing 6 changed files with 183 additions and 0 deletions.
44 changes: 44 additions & 0 deletions flattening/modelica/scodeinst/FunctionDerivative1.mo
@@ -0,0 +1,44 @@
// name: FunctionDerivative1
// status: correct
// cflags: -d=newInst
//
//

function f1
input Real x;
input Real y;
output Real z = x + y;
algorithm
annotation(derivative = f2);
end f1;

function f2
input Real x;
input Real y;
input Real der_x;
output Real z = 0;
end f2;

model FunctionDerivative1
Real x = f1(time, time);
end FunctionDerivative1;

// Result:
// function f1
// input Real x;
// input Real y;
// output Real z = x + y;
// algorithm
// end f1;
//
// function f2
// input Real x;
// input Real y;
// input Real der_x;
// output Real z = 0.0;
// end f2;
//
// class FunctionDerivative1
// Real x = f1(time, time);
// end FunctionDerivative1;
// endResult
34 changes: 34 additions & 0 deletions flattening/modelica/scodeinst/FunctionDerivativeInvalidInput1.mo
@@ -0,0 +1,34 @@
// name: FunctionDerivativeInvalidInput1
// status: incorrect
// cflags: -d=newInst
//
//

function f1
input Real x;
input Real y;
output Real z = x + y;
algorithm
annotation(derivative(zeroDerivative = z) = f2);
end f1;

function f2
input Real x;
input Real y;
input Real der_x;
output Real z = 0;
end f2;

model FunctionDerivativeInvalidInput1
Real x = f1(time, time);
end FunctionDerivativeInvalidInput1;

// Result:
// Error processing file: FunctionDerivativeInvalidInput1.mo
// [flattening/modelica/scodeinst/FunctionDerivativeInvalidInput1.mo:12:14-12:49:writable] Error: ‘z‘ is not an input of function ‘f1‘.
//
// # Error encountered! Exiting...
// # Please check the error message and the flags.
//
// Execution failed!
// endResult
34 changes: 34 additions & 0 deletions flattening/modelica/scodeinst/FunctionDerivativeInvalidOrder1.mo
@@ -0,0 +1,34 @@
// name: FunctionDerivativeInvalidOrder1
// status: incorrect
// cflags: -d=newInst
//
//

function f1
input Real x;
input Real y;
output Real z = x + y;
algorithm
annotation(derivative(order = z) = f2);
end f1;

function f2
input Real x;
input Real y;
input Real der_x;
output Real z = 0;
end f2;

model FunctionDerivativeInvalidOrder1
Real x = f1(time, time);
end FunctionDerivativeInvalidOrder1;

// Result:
// Error processing file: FunctionDerivativeInvalidOrder1.mo
// [flattening/modelica/scodeinst/FunctionDerivativeInvalidOrder1.mo:7:1-13:7:writable] Error: Type mismatch in binding order = z, expected subtype of Integer, got type Real.
//
// # Error encountered! Exiting...
// # Please check the error message and the flags.
//
// Execution failed!
// endResult
34 changes: 34 additions & 0 deletions flattening/modelica/scodeinst/FunctionDerivativeInvalidOrder2.mo
@@ -0,0 +1,34 @@
// name: FunctionDerivativeInvalidOrder2
// status: incorrect
// cflags: -d=newInst
//
//

function f1
input Real x;
input Real y;
output Integer z = integer(x + y);
algorithm
annotation(derivative(order = z) = f2);
end f1;

function f2
input Real x;
input Real y;
input Real der_x;
output Real z = 0;
end f2;

model FunctionDerivativeInvalidOrder2
Real x = f1(time, time);
end FunctionDerivativeInvalidOrder2;

// Result:
// Error processing file: FunctionDerivativeInvalidOrder2.mo
// [flattening/modelica/scodeinst/FunctionDerivativeInvalidOrder2.mo:7:1-13:7:writable] Error: Component order of variability constant has binding z of higher variability discrete.
//
// # Error encountered! Exiting...
// # Please check the error message and the flags.
//
// Execution failed!
// endResult
32 changes: 32 additions & 0 deletions flattening/modelica/scodeinst/FunctionDerivativeMissingName1.mo
@@ -0,0 +1,32 @@
// name: FunctionDerivativeMissingName1
// status: correct
// cflags: -d=newInst
//
//

function f1
input Real x;
input Real y;
output Real z = x + y;
algorithm
annotation(derivative(order = 1));
end f1;

model FunctionDerivativeMissingName1
Real x = f1(time, time);
end FunctionDerivativeMissingName1;

// Result:
// function f1
// input Real x;
// input Real y;
// output Real z = x + y;
// algorithm
// end f1;
//
// class FunctionDerivativeMissingName1
// Real x = f1(time, time);
// end FunctionDerivativeMissingName1;
// [flattening/modelica/scodeinst/FunctionDerivativeMissingName1.mo:12:14-12:35:writable] Warning: Derivative annotation for function ‘f1‘ does not specify a derivative function.
//
// endResult
5 changes: 5 additions & 0 deletions flattening/modelica/scodeinst/Makefile
Expand Up @@ -438,6 +438,11 @@ FuncVectorizatioBuiltin.mo \
FuncVectorizatioMap1.mo \
FuncWildcard.mo \
FuncWrongType.mo \
FunctionDerivative1.mo \
FunctionDerivativeInvalidInput1.mo \
FunctionDerivativeInvalidOrder1.mo \
FunctionDerivativeInvalidOrder2.mo \
FunctionDerivativeMissingName1.mo \
FunctionExtends1.mo \
FunctionMultiOutput1.mo \
FunctionMultiOutput2.mo \
Expand Down

0 comments on commit 3cc7e9d

Please sign in to comment.