Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Belonging to [master]: - OpenModelica/OMCompiler#2549 - OpenModelica/OpenModelica-testsuite#994
- Loading branch information
1 parent
bfcb389
commit 299bfbc
Showing
7 changed files
with
222 additions
and
6 deletions.
There are no files selected for viewing
10 changes: 5 additions & 5 deletions
10
...elica/scodeinst/FuncBuiltinCardinality.mo → ...tening/modelica/scodeinst/Cardinality1.mo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
// name: FuncBuiltinCardinality | ||
// name: Cardinality1 | ||
// keywords: cardinality | ||
// status: correct | ||
// cflags: -d=newInst | ||
// | ||
// Tests the builtin cardinality operator. | ||
// | ||
|
||
model FuncBuiltinCardinality | ||
model Cardinality1 | ||
connector C | ||
Real e; | ||
flow Real f; | ||
end C; | ||
|
||
C c; | ||
Integer r1 = cardinality(c); | ||
end FuncBuiltinCardinality; | ||
end Cardinality1; | ||
|
||
// Result: | ||
// class FuncBuiltinCardinality | ||
// class Cardinality1 | ||
// Real c.e; | ||
// Real c.f; | ||
// Integer r1 = 0; | ||
// equation | ||
// c.f = 0.0; | ||
// end FuncBuiltinCardinality; | ||
// end Cardinality1; | ||
// endResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// name: Cardinality2 | ||
// keywords: cardinality | ||
// status: correct | ||
// cflags: -d=newInst | ||
// | ||
// Tests the builtin cardinality operator. | ||
// | ||
|
||
connector Pin | ||
Real v; | ||
flow Real i; | ||
end Pin; | ||
|
||
model Resistor | ||
Pin p; | ||
Pin n; | ||
Pin q; | ||
parameter Integer n_conn = cardinality(p); | ||
equation | ||
connect(p, q); | ||
end Resistor; | ||
|
||
model Cardinality2 | ||
Pin p; | ||
Resistor R1, R2; | ||
equation | ||
connect(R1.p, p); | ||
end Cardinality2; | ||
|
||
// Result: | ||
// class Cardinality2 | ||
// Real p.v; | ||
// Real p.i; | ||
// Real R1.p.v; | ||
// Real R1.p.i; | ||
// Real R1.n.v; | ||
// Real R1.n.i; | ||
// Real R1.q.v; | ||
// Real R1.q.i; | ||
// parameter Integer R1.n_conn = 2; | ||
// Real R2.p.v; | ||
// Real R2.p.i; | ||
// Real R2.n.v; | ||
// Real R2.n.i; | ||
// Real R2.q.v; | ||
// Real R2.q.i; | ||
// parameter Integer R2.n_conn = 1; | ||
// equation | ||
// R1.p.v = R1.q.v; | ||
// (-R1.p.i) + (-R1.q.i) = 0.0; | ||
// R2.p.v = R2.q.v; | ||
// (-R2.p.i) + (-R2.q.i) = 0.0; | ||
// R1.p.v = p.v; | ||
// p.i = 0.0; | ||
// R1.p.i + (-p.i) = 0.0; | ||
// R1.n.i = 0.0; | ||
// R1.q.i = 0.0; | ||
// R2.p.i = 0.0; | ||
// R2.n.i = 0.0; | ||
// R2.q.i = 0.0; | ||
// end Cardinality2; | ||
// endResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// name: Cardinality3 | ||
// keywords: cardinality | ||
// status: correct | ||
// cflags: -d=newInst | ||
// | ||
// Tests the builtin cardinality operator. | ||
// | ||
|
||
connector BooleanInput = input Boolean; | ||
connector BooleanOutput = output Boolean; | ||
|
||
block And | ||
BooleanInput u1; | ||
BooleanInput u2; | ||
BooleanOutput y; | ||
equation | ||
y = u1 and u2; | ||
end And; | ||
|
||
model Cardinality3 | ||
BooleanInput u; | ||
And and1; | ||
parameter Integer c = cardinality(u); | ||
parameter Integer c1 = cardinality(and1.u1); | ||
parameter Integer c2 = cardinality(and1.u2); | ||
equation | ||
connect(u, and1.u1); | ||
connect(u, and1.u2); | ||
end Cardinality3; | ||
|
||
// Result: | ||
// class Cardinality3 | ||
// input Boolean u; | ||
// Boolean and1.u1; | ||
// Boolean and1.u2; | ||
// Boolean and1.y; | ||
// parameter Integer c = 2; | ||
// parameter Integer c1 = 1; | ||
// parameter Integer c2 = 1; | ||
// equation | ||
// u = and1.u2; | ||
// u = and1.u1; | ||
// and1.y = and1.u1 and and1.u2; | ||
// end Cardinality3; | ||
// endResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// name: Cardinality4 | ||
// keywords: cardinality | ||
// status: correct | ||
// cflags: -d=newInst | ||
// | ||
// Tests the builtin cardinality operator. | ||
// | ||
|
||
connector C | ||
Real e; | ||
flow Real f; | ||
end C; | ||
|
||
model A | ||
C c; | ||
end A; | ||
|
||
model Cardinality4 | ||
A a1[2], a2[2]; | ||
Integer c = cardinality(a1[1].c); | ||
equation | ||
connect(a1.c, a2.c); | ||
end Cardinality4; | ||
|
||
// Result: | ||
// class Cardinality4 | ||
// Real a1[1].c.e; | ||
// Real a1[1].c.f; | ||
// Real a1[2].c.e; | ||
// Real a1[2].c.f; | ||
// Real a2[1].c.e; | ||
// Real a2[1].c.f; | ||
// Real a2[2].c.e; | ||
// Real a2[2].c.f; | ||
// Integer c = 1; | ||
// equation | ||
// a1[1].c.e = a2[1].c.e; | ||
// a1[2].c.e = a2[2].c.e; | ||
// a2[1].c.f + a1[1].c.f = 0.0; | ||
// a2[2].c.f + a1[2].c.f = 0.0; | ||
// end Cardinality4; | ||
// endResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// name: CardinalityInvalidArg1 | ||
// keywords: cardinality | ||
// status: incorrect | ||
// cflags: -d=newInst | ||
// | ||
// Tests the builtin cardinality operator. | ||
// | ||
|
||
model CardinalityInvalidArg1 | ||
connector C | ||
Real e; | ||
flow Real f; | ||
end C; | ||
|
||
Integer r1 = cardinality(C); | ||
end CardinalityInvalidArg1; | ||
|
||
// Result: | ||
// Error processing file: CardinalityInvalidArg1.mo | ||
// [flattening/modelica/scodeinst/CardinalityInvalidArg1.mo:15:3-15:30:writable] Error: Expected C to be a component, but found class instead. | ||
// | ||
// # Error encountered! Exiting... | ||
// # Please check the error message and the flags. | ||
// | ||
// Execution failed! | ||
// endResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// name: CardinalityInvalidArg2 | ||
// keywords: cardinality | ||
// status: incorrect | ||
// cflags: -d=newInst | ||
// | ||
// Cardinality can only be applied to scalar connectors. | ||
// | ||
|
||
connector C | ||
Real e; | ||
flow Real f; | ||
end C; | ||
|
||
model A | ||
C c; | ||
end A; | ||
|
||
model CardinalityInvalidArg2 | ||
A a1[2], a2[2]; | ||
Integer c = cardinality(a1.c); | ||
equation | ||
connect(a1.c, a2.c); | ||
end CardinalityInvalidArg2; | ||
|
||
// Result: | ||
// Error processing file: CardinalityInvalidArg2.mo | ||
// [flattening/modelica/scodeinst/CardinalityInvalidArg2.mo:20:3-20:32:writable] Error: Type mismatch for positional argument 1 in cardinality(=a1.c). The argument has type: | ||
// C[2] | ||
// expected type: | ||
// connector | ||
// | ||
// # Error encountered! Exiting... | ||
// # Please check the error message and the flags. | ||
// | ||
// Execution failed! | ||
// endResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters