|
@@ -23,12 +23,15 @@ public class HolegGateway {
|
|
|
for (HolonObject object : network.getHolonObjectList()) {
|
|
|
double power = object.getEnergyAtTimeStep(iteration);
|
|
|
SimpleGridNode node;
|
|
|
+
|
|
|
+
|
|
|
if (power <= 0)
|
|
|
node = gridBuilder.addHouse(new ComplexNumber(-power, 0));
|
|
|
else
|
|
|
node = gridBuilder.addGenerator(new ComplexNumber(power, 0));
|
|
|
node.tag = object;
|
|
|
|
|
|
+
|
|
|
if (object.getElements().stream().anyMatch(e -> e.getEleName().equalsIgnoreCase("SLACK")))
|
|
|
node.typeByDesign = NodeType.Slack;
|
|
|
else if (object.getElements().stream().anyMatch(e -> e.getEleName().equalsIgnoreCase("TRANSFORMER")))
|
|
@@ -37,12 +40,15 @@ public class HolegGateway {
|
|
|
node.typeByDesign = NodeType.Bus;
|
|
|
canvasToGrid.put(object, node);
|
|
|
}
|
|
|
+
|
|
|
for (AbstractCanvasObject object : network.getNodeAndSwitches()) {
|
|
|
SimpleGridNode node = gridBuilder.addHouse(new ComplexNumber(0, 0));
|
|
|
node.tag = object;
|
|
|
node.typeByDesign = NodeType.Bus;
|
|
|
canvasToGrid.put(object, node);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
for (IntermediateCableWithState cable : network.getEdgeList()) {
|
|
|
SimpleGridNode a = canvasToGrid.get(cable.getModel().getA());
|
|
|
SimpleGridNode b = canvasToGrid.get(cable.getModel().getB());
|
|
@@ -59,8 +65,12 @@ public class HolegGateway {
|
|
|
private static void decorateNetwork(MinimumNetwork network, int iteration, FlexManager flexManager, DecoratedNetwork decoratedNetwork, Grid grid) {
|
|
|
synchronized (decoratedNetwork.getLockObject()) {
|
|
|
decoratedNetwork.clear();
|
|
|
+
|
|
|
+
|
|
|
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.typeSolved == NodeType.Slack));
|
|
|
else if (node.getPowerConsumption().lenSquared() > 0)
|
|
@@ -68,6 +78,8 @@ public class HolegGateway {
|
|
|
else if (simpleNode.tag instanceof HolonObject)
|
|
|
decoratedNetwork.getPassivNoEnergyList().add(new Passiv((HolonObject) simpleNode.tag));
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
for (GridEdge edge : grid.getEdges()) {
|
|
|
SimpleGridEdge simpleGridEdge = (SimpleGridEdge) edge;
|
|
|
decoratedNetwork.getDecoratedCableList().add(
|
|
@@ -85,7 +97,7 @@ public class HolegGateway {
|
|
|
boolean solve = !PowerFlowAnalysisMenu.getInstance().areUpdatesDisabled();
|
|
|
Grid grid = convert(minimumNetwork, iteration, flexManager);
|
|
|
|
|
|
-
|
|
|
+
|
|
|
if (context != null) {
|
|
|
for (Grid lastSolved : context.lastSolvedGrids) {
|
|
|
if (GridComparator.isEqual(lastSolved, grid)) {
|
|
@@ -109,6 +121,7 @@ public class HolegGateway {
|
|
|
if (context != null && context.solverJob != null) {
|
|
|
try {
|
|
|
context.solverJob.interrupt();
|
|
|
+
|
|
|
context.solverJob.join(200);
|
|
|
}
|
|
|
catch(InterruptedException ignored) {
|
|
@@ -121,6 +134,8 @@ public class HolegGateway {
|
|
|
Thread solverJob = new Thread(() -> {
|
|
|
long start = System.nanoTime();
|
|
|
GridSolverResult result = null;
|
|
|
+
|
|
|
+
|
|
|
if (solve) {
|
|
|
HolegPowerFlow powerFlow = new HolegPowerFlow();
|
|
|
result = powerFlow.solve(grid, PowerFlowSettings.getDefault());
|
|
@@ -130,9 +145,11 @@ public class HolegGateway {
|
|
|
decorateNetwork(minimumNetwork, iteration, flexManager, network, grid);
|
|
|
if (context != null)
|
|
|
context.solverTimeMilliseconds = (System.nanoTime() - start) / 1e6f;
|
|
|
+
|
|
|
+
|
|
|
SingletonControl.getInstance().getControl().calculateVisual();
|
|
|
|
|
|
-
|
|
|
+
|
|
|
if (result != null && PowerFlowAnalysisMenu.getInstance().shouldShowResult())
|
|
|
SolveResultMessageBox.show(result);
|
|
|
});
|
|
@@ -141,10 +158,12 @@ public class HolegGateway {
|
|
|
|
|
|
try {
|
|
|
if (context == null || context.settings.waitForSolverJob) {
|
|
|
+
|
|
|
solverJob.start();
|
|
|
solverJob.join();
|
|
|
}
|
|
|
else {
|
|
|
+
|
|
|
decorateNetwork(minimumNetwork, iteration, flexManager, network, grid);
|
|
|
context.solverJob = solverJob;
|
|
|
solverJob.start();
|