Henrik Kunzelmann 3 лет назад
Родитель
Сommit
0ed181ce68

+ 11 - 5
src/holeg/HolegGateway.java

@@ -76,6 +76,7 @@ public class HolegGateway {
     }
 
     public static void solve(HolegPowerFlowContext context, MinimumNetwork minimumNetwork, int iteration, FlexManager flexManager, DecoratedNetwork network) {
+        boolean solve = !PowerFlowAnalysisMenu.getInstance().areUpdatesDisabled();
         Grid grid = convert(minimumNetwork, iteration, flexManager);
 
         // Check if the grid is equal to the one already solved
@@ -87,15 +88,20 @@ public class HolegGateway {
                 }
             }
 
-            // Keep size constrained to 32 saved grids
-            if (context.lastSolvedGrids.size() >= 32)
-                context.lastSolvedGrids.remove(0);
-            context.lastSolvedGrids.add(grid);
+            // Only remember grid when solving
+            if (solve) {
+                // Keep size constrained to 32 saved grids
+                if (context.lastSolvedGrids.size() >= 32)
+                    context.lastSolvedGrids.remove(0);
+
+                // Grid is updated by solver directly, so we can save the reference to the grid
+                context.lastSolvedGrids.add(grid);
+            }
         }
 
         // Start solver
         GridSolverResult result = null;
-        if (!PowerFlowAnalysisMenu.getInstance().areUpdatesDisabled()) {
+        if (solve) {
             HolegPowerFlow powerFlow = new HolegPowerFlow();
             result = powerFlow.solve(grid, PowerFlowSettings.getDefault());
         }

+ 2 - 0
src/holeg/model/GridComparator.java

@@ -80,6 +80,8 @@ public class GridComparator {
             return false;
         if (!ComplexNumber.equals(a.getPowerGeneration(), b.getPowerGeneration()))
             return false;
+        if (!a.getTag().equals(b.getTag()))
+            return false;
         return true;
     }
 

+ 1 - 0
src/holeg/model/GridNode.java

@@ -11,6 +11,7 @@ public interface GridNode {
     NodeType getTypeSolved();
     ComplexNumber getPowerConsumption();
     ComplexNumber getPowerGeneration();
+    Object getTag();
 
     void setVoltage(double voltage);
     void setPhase(double phaseDegrees);

+ 5 - 0
src/holeg/simple_grid/SimpleGridNode.java

@@ -44,6 +44,11 @@ public class SimpleGridNode implements GridNode {
         return powerGeneration;
     }
 
+    @Override
+    public Object getTag() {
+        return tag;
+    }
+
     @Override
     public void setVoltage(double voltage) {
         this.voltage = voltage;

+ 22 - 2
src/holeg/ui/PowerFlowAnalysisMenu.java

@@ -13,12 +13,15 @@ public class PowerFlowAnalysisMenu extends JMenu {
     private JMenuItem showFlow;
     private JMenuItem clearCache;
     private JMenuItem solve;
+    private JMenuItem clearCacheAndSolve;
     private JCheckBoxMenuItem disableUpdates;
     private JCheckBoxMenuItem showResultMessageBox;
     private JCheckBoxMenuItem showDebugMessageBox;
 
     private static PowerFlowAnalysisMenu instance;
 
+    private boolean overwriteDisableUpdatesToForceUpdates = false;
+
     public PowerFlowAnalysisMenu(Model model) {
         super("Power flow");
 
@@ -27,8 +30,9 @@ public class PowerFlowAnalysisMenu extends JMenu {
         addSeparator();
         clearCache = add(new JMenuItem("Clear cache"));
         solve = add(new JMenuItem("Solve"));
+        clearCacheAndSolve = add(new JMenuItem("Clear cache and solve"));
         addSeparator();
-        disableUpdates = (JCheckBoxMenuItem) add(new JCheckBoxMenuItem("Disable updates"));
+        disableUpdates = (JCheckBoxMenuItem) add(new JCheckBoxMenuItem("Disable automatic updates"));
         showResultMessageBox = (JCheckBoxMenuItem) add(new JCheckBoxMenuItem("Show result message"));
         showDebugMessageBox = (JCheckBoxMenuItem) add(new JCheckBoxMenuItem("Show debug message"));
 
@@ -36,11 +40,27 @@ public class PowerFlowAnalysisMenu extends JMenu {
             SingletonControl.getInstance().getControl().getSimManager().getHolegPowerFlowContext().clearCache();
         });
 
+        solve.addActionListener((e) -> {
+            solve(false);
+        });
+
+        clearCacheAndSolve.addActionListener((e) -> {
+            solve(true);
+        });
+
         instance = this;
     }
 
+    private void solve(boolean clearCache) {
+        overwriteDisableUpdatesToForceUpdates = true;
+        if (clearCache)
+            SingletonControl.getInstance().getControl().getSimManager().getHolegPowerFlowContext().clearCache();
+        SingletonControl.getInstance().getControl().calculateStateAndVisualForCurrentTimeStep();
+        overwriteDisableUpdatesToForceUpdates = false;
+    }
+
     public boolean areUpdatesDisabled() {
-        return disableUpdates.getState();
+        return !overwriteDisableUpdatesToForceUpdates && disableUpdates.getState();
     }
 
     public boolean shouldShowResult() {

+ 0 - 1
src/ui/model/DecoratedNetwork.java

@@ -30,7 +30,6 @@ public class DecoratedNetwork {
 			calculateMinimumDemandFirstNetwork(minimumNetwork, Iteration, flexManager);
 			break;
 		case PowerFlowAnalysis:
-			// TODO: (Henrik)
 			HolegGateway.solve(context, minimumNetwork, Iteration, flexManager, this);
 			calculateStates();
 			break;