|
@@ -11,6 +11,7 @@ import holeg.simple_grid.SimpleGridNode;
|
|
|
import holeg.ui.PowerFlowAnalysisMenu;
|
|
|
import holeg.ui.SolveResultMessageBox;
|
|
|
import ui.controller.FlexManager;
|
|
|
+import ui.controller.SingletonControl;
|
|
|
import ui.model.*;
|
|
|
|
|
|
import java.util.HashMap;
|
|
@@ -39,6 +40,7 @@ public class HolegGateway {
|
|
|
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()) {
|
|
@@ -55,23 +57,27 @@ public class HolegGateway {
|
|
|
}
|
|
|
|
|
|
private static void decorateNetwork(MinimumNetwork network, int iteration, FlexManager flexManager, DecoratedNetwork decoratedNetwork, Grid grid) {
|
|
|
- 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)
|
|
|
- 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));
|
|
|
- }
|
|
|
- for (GridEdge edge : grid.getEdges()) {
|
|
|
- SimpleGridEdge simpleGridEdge = (SimpleGridEdge) edge;
|
|
|
- decoratedNetwork.getDecoratedCableList().add(
|
|
|
- new DecoratedCable(
|
|
|
- ((IntermediateCableWithState)simpleGridEdge.tag).getModel(),
|
|
|
- DecoratedCable.CableState.Working,
|
|
|
- (float)simpleGridEdge.power.real,
|
|
|
- (float)simpleGridEdge.loss.real));
|
|
|
+ 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)
|
|
|
+ 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));
|
|
|
+ }
|
|
|
+ for (GridEdge edge : grid.getEdges()) {
|
|
|
+ SimpleGridEdge simpleGridEdge = (SimpleGridEdge) edge;
|
|
|
+ decoratedNetwork.getDecoratedCableList().add(
|
|
|
+ new DecoratedCable(
|
|
|
+ ((IntermediateCableWithState) simpleGridEdge.tag).getModel(),
|
|
|
+ DecoratedCable.CableState.Working,
|
|
|
+ (float) simpleGridEdge.power.real,
|
|
|
+ (float) simpleGridEdge.loss.real));
|
|
|
+ }
|
|
|
+ decoratedNetwork.calculateStates();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -99,18 +105,53 @@ public class HolegGateway {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // Start solver
|
|
|
- GridSolverResult result = null;
|
|
|
- if (solve) {
|
|
|
- HolegPowerFlow powerFlow = new HolegPowerFlow();
|
|
|
- result = powerFlow.solve(grid, PowerFlowSettings.getDefault());
|
|
|
+ // Stop old solver
|
|
|
+ if (context != null && context.solverJob != null) {
|
|
|
+ try {
|
|
|
+ context.solverJob.interrupt();
|
|
|
+ context.solverJob.join(200);
|
|
|
+ }
|
|
|
+ catch(InterruptedException ignored) {
|
|
|
+
|
|
|
+ }
|
|
|
+ context.solverJob = null;
|
|
|
}
|
|
|
|
|
|
- // Decorate network
|
|
|
- decorateNetwork(minimumNetwork, iteration, flexManager, network, grid);
|
|
|
+ // Create solver job
|
|
|
+ Thread solverJob = new Thread(() -> {
|
|
|
+ long start = System.nanoTime();
|
|
|
+ GridSolverResult result = null;
|
|
|
+ if (solve) {
|
|
|
+ HolegPowerFlow powerFlow = new HolegPowerFlow();
|
|
|
+ result = powerFlow.solve(grid, PowerFlowSettings.getDefault());
|
|
|
+ }
|
|
|
|
|
|
- // Show result
|
|
|
- if (result != null && PowerFlowAnalysisMenu.getInstance().shouldShowResult())
|
|
|
- SolveResultMessageBox.show(result);
|
|
|
+ // Decorate network
|
|
|
+ decorateNetwork(minimumNetwork, iteration, flexManager, network, grid);
|
|
|
+ if (context != null)
|
|
|
+ context.solverTimeMilliseconds = (System.nanoTime() - start) / 1e6f;
|
|
|
+ SingletonControl.getInstance().getControl().calculateVisual();
|
|
|
+
|
|
|
+ // Show result
|
|
|
+ if (result != null && PowerFlowAnalysisMenu.getInstance().shouldShowResult())
|
|
|
+ SolveResultMessageBox.show(result);
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ // Wait or save solver job
|
|
|
+ try {
|
|
|
+ if (context == null || context.settings.waitForSolverJob) {
|
|
|
+ solverJob.start();
|
|
|
+ solverJob.join();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ decorateNetwork(minimumNetwork, iteration, flexManager, network, grid);
|
|
|
+ context.solverJob = solverJob;
|
|
|
+ solverJob.start();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
}
|