Skip to content

Commit

Permalink
Update tests for improved treatment of array equations
Browse files Browse the repository at this point in the history
  • Loading branch information
rfranke authored and OpenModelica-Hudson committed Nov 20, 2018
1 parent 4b5e4db commit a3d1bab
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 51 deletions.
34 changes: 18 additions & 16 deletions openmodelica/cppruntime/VectorizedPowerSystemTotal.mo
Expand Up @@ -27,10 +27,10 @@ model VectorizedPowerSystemTest

PowerSystems.Generic.FixedVoltageSource fixedVoltageSource1;
inner PowerSystems.System system;
PowerSystems.Generic.FixedCurrent[n] fixedCurrent1(I = 100:100:100 * n, phi = 0.1:0.1:0.1 * n);
PowerSystems.Generic.FixedLoad[n] fixedLoad1(P = 1e6:1e6:1e6 * n, phi = 0.1:0.1:0.1 * n);
BusBar busBar1;
equation
connect(busBar1.terminal_n, fixedCurrent1.terminal);
connect(busBar1.terminal_n, fixedLoad1.terminal);
connect(fixedVoltageSource1.terminal, busBar1.terminal_p);
end VectorizedPowerSystemTest;

Expand Down Expand Up @@ -127,12 +127,12 @@ package PowerSystems "Library for electrical power systems"
output Voltage[n] v "phase voltages";
end phaseVoltages;

replaceable partial function phaseCurrents "Return phase currents"
replaceable partial function phasePowers "Return phase powers"
extends Modelica.Icons.Function;
input Current I "system current";
input SI.ActivePower P "active system power";
input SI.Angle phi = 0 "phase angle";
output Current[n] i "phase currents";
end phaseCurrents;
output SI.Power[n] p "phase powers";
end phasePowers;

replaceable partial function phasePowers_vi "Return phase powers"
extends Modelica.Icons.Function;
Expand Down Expand Up @@ -193,15 +193,15 @@ package PowerSystems "Library for electrical power systems"
annotation(Inline = true);
end phaseVoltages;

redeclare function phaseCurrents "Return phase currents"
redeclare function phasePowers "Return phase powers"
extends Modelica.Icons.Function;
input Current I "system current";
input SI.ActivePower P "active system power";
input SI.Angle phi = 0 "phase angle";
output Current[n] i "phase currents";
output SI.Power[n] p "phase powers";
algorithm
i := {I};
p := {P};
annotation(Inline = true);
end phaseCurrents;
end phasePowers;

redeclare function phasePowers_vi "Return phase powers"
extends Modelica.Icons.Function;
Expand Down Expand Up @@ -266,13 +266,13 @@ package PowerSystems "Library for electrical power systems"
terminal.v = PhaseSystem.phaseVoltages(V, PhaseSystem.thetaRel(terminal.theta));
end FixedVoltageSource;

model FixedCurrent
model FixedLoad
extends PowerSystems.Generic.Ports.PartialLoad;
parameter SI.Current I = 0 "rms value of constant current";
parameter SI.Power P = 0 "rms value of constant active power";
parameter SI.Angle phi = 0 "phase angle";
equation
terminal.i = PhaseSystem.phaseCurrents(I, phi);
end FixedCurrent;
PhaseSystem.phasePowers_vi(terminal.v, terminal.i) = PhaseSystem.phasePowers(P, phi);
end FixedLoad;

package Ports "Interfaces for generic components"
extends Modelica.Icons.InterfacesPackage;
Expand Down Expand Up @@ -354,6 +354,7 @@ package PowerSystems "Library for electrical power systems"
type Voltage = MSI.Voltage(displayUnit = "kV");
type Current = MSI.Current;
type Power = MSI.Power(displayUnit = "MW");
type ActivePower = MSI.ActivePower(displayUnit = "MW");
end SI;

type SystemFrequency = enumeration(Parameter "Parameter f", Signal "Signal omega_in", Average "Average generators") "Options for specification of frequency in system object";
Expand All @@ -374,7 +375,7 @@ package PowerSystems "Library for electrical power systems"
end equalityConstraint;
end ReferenceAngle;
end Types;
annotation(version = "0.7 dev", versionDate = "2018-02-05");
annotation(version = "1.0.0", versionDate = "2018-11-12");
end PowerSystems;

package ModelicaServices "ModelicaServices (OpenModelica implementation) - Models and functions used in the Modelica Standard Library requiring a tool specific implementation"
Expand Down Expand Up @@ -534,6 +535,7 @@ package Modelica "Modelica Standard Library - Version 3.2.2"
type Current = ElectricCurrent;
type ElectricPotential = Real(final quantity = "ElectricPotential", final unit = "V");
type Voltage = ElectricPotential;
type ActivePower = Real(final quantity = "Power", final unit = "W");
type FaradayConstant = Real(final quantity = "FaradayConstant", final unit = "C/mol");
end SIunits;
annotation(version = "3.2.2", versionBuild = 3, versionDate = "2016-04-03", dateModified = "2016-04-03 08:44:41Z");
Expand Down
44 changes: 22 additions & 22 deletions openmodelica/cppruntime/testVectorizedPowerSystem.mos
Expand Up @@ -206,26 +206,26 @@ val(fixedVoltageSource1.p[1], 1.0);
// 5: busBar1.terminal_n.i:VARIABLE(flow=true unit = "A" nominal = 1.0 ) "current vector" type: Real[3, 1] [3,1]
// 6: busBar1.terminal_p.i:VARIABLE(flow=true unit = "A" nominal = 1.0 ) "current vector" type: Real[1] [1]
// 7: busBar1.terminal_p.v:VARIABLE(flow=false unit = "V" nominal = 1000.0 ) "voltage vector" type: Real[1] [1]
// 8: fixedCurrent1.terminal.v:VARIABLE(flow=false start = fixedCurrent1.v_start unit = "V" nominal = 1000.0 ) "voltage vector" type: Real[3, 1] [3,1]
// 9: fixedCurrent1.terminal.i:VARIABLE(flow=true unit = "A" nominal = 1.0 ) "current vector" type: Real[3, 1] [3,1]
// 10: fixedCurrent1.p:VARIABLE(flow=false unit = "W" ) type: Real[3, 1] [3,1]
// 8: fixedLoad1.terminal.v:VARIABLE(flow=false start = fixedLoad1.v_start unit = "V" nominal = 1000.0 ) "voltage vector" type: Real[3, 1] [3,1]
// 9: fixedLoad1.terminal.i:VARIABLE(flow=true unit = "A" nominal = 1.0 ) "current vector" type: Real[3, 1] [3,1]
// 10: fixedLoad1.p:VARIABLE(flow=false unit = "W" ) type: Real[3, 1] [3,1]
// 11: fixedVoltageSource1.p:VARIABLE(flow=false unit = "W" ) type: Real[1] [1]
// 12: fixedVoltageSource1.terminal.i:VARIABLE(flow=true unit = "A" nominal = 1.0 ) "current vector" type: Real[1] [1]
// 13: fixedVoltageSource1.terminal.v:VARIABLE(flow=false unit = "V" nominal = 1000.0 ) "voltage vector" type: Real[1] [1]
//
//
// Equations (13, 13)
// ========================================
// 1/1 (3): busBar1.terminal_n.v = fixedCurrent1.terminal.v [dynamic |0|0|0|0|]
// 2/4 (3): busBar1.terminal_n.i + fixedCurrent1.terminal.i = 0.0 [dynamic |0|0|0|0|]
// 1/1 (3): busBar1.terminal_n.v = fixedLoad1.terminal.v [dynamic |0|0|0|0|]
// 2/4 (3): busBar1.terminal_n.i + fixedLoad1.terminal.i = 0.0 [dynamic |0|0|0|0|]
// 3/7 (1): fixedVoltageSource1.terminal.v = busBar1.terminal_p.v [dynamic |0|0|0|0|]
// 4/8 (1): fixedVoltageSource1.terminal.i + busBar1.terminal_p.i = 0.0 [dynamic |0|0|0|0|]
// 5/9 (1): fixedVoltageSource1.p = {fixedVoltageSource1.terminal.v * fixedVoltageSource1.terminal.i} [dynamic |0|0|0|0|]
// 6/10 (1): fixedVoltageSource1.terminal.v = {fixedVoltageSource1.V} [dynamic |0|0|0|0|]
// 7/11 (3): for $i in 1 : 3 loop
// fixedCurrent1[$i].p = {fixedCurrent1[$i].terminal.v * fixedCurrent1[$i].terminal.i}; end for; [dynamic |0|0|0|0|]
// fixedLoad1[$i].p = {fixedLoad1[$i].terminal.v * fixedLoad1[$i].terminal.i}; end for; [dynamic |0|0|0|0|]
// 8/14 (3): for $i in 1 : 3 loop
// fixedCurrent1[$i].terminal.i = {fixedCurrent1[$i].I}; end for; [dynamic |0|0|0|0|]
// fixedLoad1[$i].terminal.v * fixedLoad1[$i].terminal.i = fixedLoad1[$i].P; end for; [dynamic |0|0|0|0|]
// 9/17 (1): busBar1.v = busBar1.terminal_p.v [dynamic |0|0|0|0|]
// 10/18 (1): busBar1.i = busBar1.terminal_p.i [dynamic |0|0|0|0|]
// 11/19 (1): busBar1.p = {busBar1.v * busBar1.i} [dynamic |0|0|0|0|]
Expand Down Expand Up @@ -350,9 +350,9 @@ val(fixedVoltageSource1.p[1], 1.0);
// 1: busBar1.n_n:PARAM(flow=false ) = 3 type: Integer
// 2: busBar1.i_start:PARAM(flow=false unit = "A" nominal = 1.0 ) = {0.0} "Start value for current" type: Real[1] [1]
// 3: busBar1.v_start:PARAM(flow=false unit = "V" nominal = 1000.0 ) = {0.0} "Start value for voltage drop" type: Real[1] [1]
// 4: fixedCurrent1.v_start:PARAM(flow=false unit = "V" nominal = 1000.0 ) = {1.0} "Start value for voltage drop" type: Real[3, 1] [3,1]
// 5: fixedCurrent1.I:PARAM(flow=false unit = "A" ) = /*Real[max(div(100 * n - 100, 100) + 1, 0)]*/(100:100:300) "rms value of constant current" type: Real[3] [3]
// 6: fixedCurrent1.phi:PARAM(flow=false unit = "rad" ) = 0.1:0.1:0.3 "phase angle" type: Real[3] [3]
// 4: fixedLoad1.v_start:PARAM(flow=false unit = "V" nominal = 1000.0 ) = {1.0} "Start value for voltage drop" type: Real[3, 1] [3,1]
// 5: fixedLoad1.P:PARAM(flow=false unit = "W" ) = 1000000.0:1000000.0:3000000.0 "rms value of constant active power" type: Real[3] [3]
// 6: fixedLoad1.phi:PARAM(flow=false unit = "rad" ) = 0.1:0.1:0.3 "phase angle" type: Real[3] [3]
// 7: system.synRef:PARAM(flow=false final = true ) = true type: Boolean
// 8: system.w_nom:PARAM(flow=false unit = "rad/s" final = true ) = 314.1592653589793 "nom r.p.m." type: Real
// 9: system.omega_nom:PARAM(flow=false unit = "rad/s" final = true ) = 314.1592653589793 "nominal angular frequency" type: Real
Expand Down Expand Up @@ -563,26 +563,26 @@ val(fixedVoltageSource1.p[1], 1.0);
// 5: busBar1.terminal_n.i:VARIABLE(flow=true unit = "A" nominal = 1.0 ) "current vector" type: Real[3, 1] [3,1]
// 6: busBar1.terminal_p.i:VARIABLE(flow=true unit = "A" nominal = 1.0 ) "current vector" type: Real[1] [1]
// 7: busBar1.terminal_p.v:VARIABLE(flow=false unit = "V" nominal = 1000.0 ) "voltage vector" type: Real[1] [1]
// 8: fixedCurrent1.terminal.v:VARIABLE(flow=false start = fixedCurrent1.v_start unit = "V" nominal = 1000.0 ) "voltage vector" type: Real[3, 1] [3,1]
// 9: fixedCurrent1.terminal.i:VARIABLE(flow=true unit = "A" nominal = 1.0 ) "current vector" type: Real[3, 1] [3,1]
// 10: fixedCurrent1.p:VARIABLE(flow=false unit = "W" ) type: Real[3, 1] [3,1]
// 8: fixedLoad1.terminal.v:VARIABLE(flow=false start = fixedLoad1.v_start unit = "V" nominal = 1000.0 ) "voltage vector" type: Real[3, 1] [3,1]
// 9: fixedLoad1.terminal.i:VARIABLE(flow=true unit = "A" nominal = 1.0 ) "current vector" type: Real[3, 1] [3,1]
// 10: fixedLoad1.p:VARIABLE(flow=false unit = "W" ) type: Real[3, 1] [3,1]
// 11: fixedVoltageSource1.p:VARIABLE(flow=false unit = "W" ) type: Real[1] [1]
// 12: fixedVoltageSource1.terminal.i:VARIABLE(flow=true unit = "A" nominal = 1.0 ) "current vector" type: Real[1] [1]
// 13: fixedVoltageSource1.terminal.v:VARIABLE(flow=false unit = "V" nominal = 1000.0 ) "voltage vector" type: Real[1] [1]
//
//
// Equations (13, 13)
// ========================================
// 1/1 (3): busBar1.terminal_n.v = fixedCurrent1.terminal.v [dynamic |0|0|0|0|]
// 2/4 (3): busBar1.terminal_n.i + fixedCurrent1.terminal.i = 0.0 [dynamic |0|0|0|0|]
// 1/1 (3): busBar1.terminal_n.v = fixedLoad1.terminal.v [dynamic |0|0|0|0|]
// 2/4 (3): busBar1.terminal_n.i + fixedLoad1.terminal.i = 0.0 [dynamic |0|0|0|0|]
// 3/7 (1): fixedVoltageSource1.terminal.v = busBar1.terminal_p.v [dynamic |0|0|0|0|]
// 4/8 (1): fixedVoltageSource1.terminal.i + busBar1.terminal_p.i = 0.0 [dynamic |0|0|0|0|]
// 5/9 (1): fixedVoltageSource1.p = {fixedVoltageSource1.terminal.v * fixedVoltageSource1.terminal.i} [dynamic |0|0|0|0|]
// 6/10 (1): fixedVoltageSource1.terminal.v = {fixedVoltageSource1.V} [dynamic |0|0|0|0|]
// 7/11 (3): for $i in 1 : 3 loop
// fixedCurrent1[$i].p = {fixedCurrent1[$i].terminal.v * fixedCurrent1[$i].terminal.i}; end for; [dynamic |0|0|0|0|]
// fixedLoad1[$i].p = {fixedLoad1[$i].terminal.v * fixedLoad1[$i].terminal.i}; end for; [dynamic |0|0|0|0|]
// 8/14 (3): for $i in 1 : 3 loop
// fixedCurrent1[$i].terminal.i = {fixedCurrent1[$i].I}; end for; [dynamic |0|0|0|0|]
// fixedLoad1[$i].terminal.v * fixedLoad1[$i].terminal.i = fixedLoad1[$i].P; end for; [dynamic |0|0|0|0|]
// 9/17 (1): busBar1.v = busBar1.terminal_p.v [dynamic |0|0|0|0|]
// 10/18 (1): busBar1.i = busBar1.terminal_p.i [dynamic |0|0|0|0|]
// 11/19 (1): busBar1.p = {busBar1.v * busBar1.i} [dynamic |0|0|0|0|]
Expand Down Expand Up @@ -621,16 +621,16 @@ val(fixedVoltageSource1.p[1], 1.0);
// ========================================
// {13:6}
// Array {{10:2}}
// {8:9}
// Array {{6:13}}
// Array {{4:12}}
// Array {{5:11}}
// Array {{3:7}}
// Array {{9:3}}
// Array {{11:1}}
// Array {{12:4}}
// Array {{2:5}}
// Array {{1:8}}
// {8:9}
// Array {{2:5}}
// {7:10}
//
//
Expand Down Expand Up @@ -853,9 +853,9 @@ val(fixedVoltageSource1.p[1], 1.0);
// 1: busBar1.n_n:PARAM(flow=false ) = 3 type: Integer
// 2: busBar1.i_start:PARAM(flow=false unit = "A" nominal = 1.0 ) = {0.0} "Start value for current" type: Real[1] [1]
// 3: busBar1.v_start:PARAM(flow=false unit = "V" nominal = 1000.0 ) = {0.0} "Start value for voltage drop" type: Real[1] [1]
// 4: fixedCurrent1.v_start:PARAM(flow=false unit = "V" nominal = 1000.0 ) = {1.0} "Start value for voltage drop" type: Real[3, 1] [3,1]
// 5: fixedCurrent1.I:PARAM(flow=false unit = "A" ) = 100.0:100.0:300.0 "rms value of constant current" type: Real[3] [3]
// 6: fixedCurrent1.phi:PARAM(flow=false unit = "rad" ) = 0.1:0.1:0.3 "phase angle" type: Real[3] [3]
// 4: fixedLoad1.v_start:PARAM(flow=false unit = "V" nominal = 1000.0 ) = {1.0} "Start value for voltage drop" type: Real[3, 1] [3,1]
// 5: fixedLoad1.P:PARAM(flow=false unit = "W" ) = 1000000.0:1000000.0:3000000.0 "rms value of constant active power" type: Real[3] [3]
// 6: fixedLoad1.phi:PARAM(flow=false unit = "rad" ) = 0.1:0.1:0.3 "phase angle" type: Real[3] [3]
// 7: system.synRef:PARAM(flow=false final = true ) = true type: Boolean
// 8: system.w_nom:PARAM(flow=false unit = "rad/s" final = true ) = 314.1592653589793 "nom r.p.m." type: Real
// 9: system.omega_nom:PARAM(flow=false unit = "rad/s" final = true ) = 314.1592653589793 "nominal angular frequency" type: Real
Expand Down
17 changes: 4 additions & 13 deletions openmodelica/cppruntime/testVectorizedSolarSystem.mos
Expand Up @@ -3,10 +3,7 @@
// status: correct
// teardown_command: rm -f *VectorizedSolarSystemTest*

setCommandLineOptions("--std=3.3"); getErrorString();
setCommandLineOptions("-d=newInst,-nfScalarize"); getErrorString();
setCommandLineOptions("--preOptModules-=removeSimpleEquations"); getErrorString();
setCommandLineOptions("--postOptModules-=removeSimpleEquations"); getErrorString();
setCommandLineOptions("--preOptModules+=dumpDAE"); getErrorString();
setCommandLineOptions("--postOptModules+=dumpDAE"); getErrorString();
setCommandLineOptions("--simCodeTarget=Cpp"); getErrorString();
Expand All @@ -31,12 +28,6 @@ val(grid.P_grid, 0.0);
// ""
// true
// ""
// true
// ""
// true
// ""
// true
// ""
//
// ########################################
// dumpDAE
Expand Down Expand Up @@ -87,10 +78,10 @@ val(grid.P_grid, 0.0);
//
// Known variables only depending on parameters and constants - globalKnownVars (4)
// ========================================
// 1: grid.V:PARAM(flow=false unit = "V" ) = 1000.0 type: Real
// 2: grid.n:PARAM(flow=false ) = 1000 type: Integer
// 3: plant.eta:PARAM(flow=false ) = 0.9 "Efficiency" type: Real[1000] [1000]
// 4: n:PARAM(flow=false ) = 1000 type: Integer
// 1: n:PARAM(flow=false ) = 1000 type: Integer
// 2: plant.eta:PARAM(flow=false ) = 0.9 "Efficiency" type: Real[1000] [1000]
// 3: grid.n:PARAM(flow=false ) = 1000 type: Integer
// 4: grid.V:PARAM(flow=false unit = "V" ) = 1000.0 type: Real
//
//
// Known variables only depending on states and inputs - localKnownVars (0)
Expand Down

0 comments on commit a3d1bab

Please sign in to comment.