|
@@ -3,10 +3,7 @@ package holeg;
|
|
|
import classes.AbstractCanvasObject;
|
|
|
import classes.HolonObject;
|
|
|
import classes.Node;
|
|
|
-import holeg.model.Grid;
|
|
|
-import holeg.model.GridEdge;
|
|
|
-import holeg.model.GridNode;
|
|
|
-import holeg.model.NodeType;
|
|
|
+import holeg.model.*;
|
|
|
import holeg.power_flow.ComplexNumber;
|
|
|
import holeg.simple_grid.SimpleGridBuilder;
|
|
|
import holeg.simple_grid.SimpleGridEdge;
|
|
@@ -32,11 +29,11 @@ public class HolegGateway {
|
|
|
node.tag = object;
|
|
|
|
|
|
if (object.getElements().stream().anyMatch(e -> e.getEleName().equalsIgnoreCase("SLACK")))
|
|
|
- node.setType(NodeType.Slack);
|
|
|
+ node.typeByDesign = NodeType.Slack;
|
|
|
else if (object.getElements().stream().anyMatch(e -> e.getEleName().equalsIgnoreCase("TRANSFORMER")))
|
|
|
- node.setType(NodeType.Transformer);
|
|
|
+ node.typeByDesign = NodeType.Transformer;
|
|
|
else
|
|
|
- node.setType(NodeType.Bus);
|
|
|
+ node.typeByDesign = NodeType.Bus;
|
|
|
canvasToGrid.put(object, node);
|
|
|
}
|
|
|
for (AbstractCanvasObject object : network.getNodeAndSwitches()) {
|
|
@@ -50,6 +47,8 @@ public class HolegGateway {
|
|
|
if (a == null || b == null)
|
|
|
continue;
|
|
|
SimpleGridEdge edge = gridBuilder.connect(a, b, cable.getModel().getRealLength());
|
|
|
+ edge.overrideImpedance = new ComplexNumber(cable.getModel().getOverrideResistance(), cable.getModel().getOverrideReactance());
|
|
|
+ edge.overrideShuntSusceptance = cable.getModel().getOverrideShuntSusceptance();
|
|
|
edge.tag = cable;
|
|
|
}
|
|
|
return gridBuilder.getGrid();
|
|
@@ -59,9 +58,9 @@ public class HolegGateway {
|
|
|
for (GridNode node : grid.getNodes()) {
|
|
|
SimpleGridNode simpleNode = (SimpleGridNode) node;
|
|
|
if (node.getPowerGeneration().lenSquared() > 0)
|
|
|
- decoratedNetwork.getSupplierList().add(new Supplier((HolonObject) simpleNode.tag, (float) node.getPowerGeneration().real, 0, simpleNode.voltage, simpleNode.phaseDegrees, simpleNode.type == NodeType.Slack));
|
|
|
+ decoratedNetwork.getSupplierList().add(new Supplier((HolonObject) simpleNode.tag, (float) node.getPowerGeneration().real, 0, simpleNode.voltage, simpleNode.phaseDegrees, simpleNode.typeSolved == NodeType.Slack));
|
|
|
else if (node.getPowerConsumption().lenSquared() > 0)
|
|
|
- decoratedNetwork.getConsumerList().add(new Consumer((HolonObject) simpleNode.tag, (float) node.getPowerConsumption().real, simpleNode.voltage, simpleNode.phaseDegrees, Math.cos(simpleNode.getPowerConsumption().angle()), simpleNode.type == NodeType.Slack));
|
|
|
+ decoratedNetwork.getConsumerList().add(new Consumer((HolonObject) simpleNode.tag, (float) node.getPowerConsumption().real, simpleNode.voltage, simpleNode.phaseDegrees, Math.cos(simpleNode.getPowerConsumption().angle()), simpleNode.typeSolved == NodeType.Slack));
|
|
|
else if (simpleNode.tag instanceof HolonObject)
|
|
|
decoratedNetwork.getPassivNoEnergyList().add(new Passiv((HolonObject) simpleNode.tag));
|
|
|
}
|
|
@@ -76,9 +75,24 @@ public class HolegGateway {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static void solve(MinimumNetwork minimumNetwork, int iteration, FlexManager flexManager, DecoratedNetwork network) {
|
|
|
+ public static void solve(HolegPowerFlowContext context, MinimumNetwork minimumNetwork, int iteration, FlexManager flexManager, DecoratedNetwork network) {
|
|
|
Grid grid = convert(minimumNetwork, iteration, flexManager);
|
|
|
|
|
|
+ // Check if the grid is equal to the one already solved
|
|
|
+ if (context != null) {
|
|
|
+ for (Grid lastSolved : context.lastSolvedGrids) {
|
|
|
+ if (GridComparator.isEqual(lastSolved, grid)) {
|
|
|
+ decorateNetwork(minimumNetwork, iteration, flexManager, network, lastSolved);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Keep size constrained to 32 saved grids
|
|
|
+ if (context.lastSolvedGrids.size() >= 32)
|
|
|
+ context.lastSolvedGrids.remove(0);
|
|
|
+ context.lastSolvedGrids.add(grid);
|
|
|
+ }
|
|
|
+
|
|
|
HolegPowerFlow powerFlow = new HolegPowerFlow();
|
|
|
GridSolverResult result = powerFlow.solve(grid, PowerFlowSettings.getDefault());
|
|
|
decorateNetwork(minimumNetwork, iteration, flexManager, network, grid);
|