소스 검색

discharge storages in normal operation

David Heck 5 년 전
부모
커밋
f826c467d0

+ 12 - 9
src/blackstart/StorageProductionController.java

@@ -7,17 +7,17 @@ import java.util.ArrayList;
 public class StorageProductionController {
 	private ArrayList<StorageElement> storages;
 
-	public StorageProductionController(){}
+//	public StorageProductionController(){}
 
-//	public StorageProductionController(ArrayList<StorageElement> storages) {
-//		this.storages = storages;
-//	}
-
-
-	public void setStorages(ArrayList<StorageElement> storages) {
+	public StorageProductionController(ArrayList<StorageElement> storages) {
 		this.storages = storages;
 	}
 
+
+//	public void setStorages(ArrayList<StorageElement> storages) {
+//		this.storages = storages;
+//	}
+
 	public float currentPossibleStorageProduction() {
 		float possibleEnergy = 0;
 		for (StorageElement so : storages) {
@@ -40,7 +40,7 @@ public class StorageProductionController {
 		return producedEnergy;
 	}
 
-	public void enableStorageProduction(final float energyNeeded) {
+	public void enableStorageDischarging(final float energyNeeded) {
 		System.out.println("energy needed from storage" + energyNeeded);
         float energyLeftToEnabled = energyNeeded;
 
@@ -70,7 +70,7 @@ public class StorageProductionController {
 	}
 
 	//TODO: redo algorithm to actually us it right...
-	public void disableStorageProduction(float energyNotNeeded) {
+	public void disableStorageDischarging(float energyNotNeeded) {
 		if(energyNotNeeded == -1) {
 			for (StorageElement se : storages) {
 				se.setStatusAndSetEnergy(StorageElement.Mode.STANDBY, 0);
@@ -94,4 +94,7 @@ public class StorageProductionController {
 //			}
 //		}
 	}
+	public void enableStorageCharging(float energyAvailable){
+
+	}
 }

+ 19 - 28
src/blackstart/controlAlgorithm.java

@@ -243,12 +243,12 @@ public class controlAlgorithm implements AddOn {
 	private void initAlgo() {
 		try {
 			// init
-//			SPC = new StorageProductionController(getStorageElements());// DANGER DONT GIVE NULL
-			control.getModel().setStorageProductionController();
-			SPC = control.getModel().getStorageProductionController();
+			SPC = new StorageProductionController(getStorageElements());// DANGER DONT GIVE NULL
+//			control.getModel().setStorageProductionController();
+//			SPC = control.getModel().getStorageProductionController();
 			renewableProducers = getRenewableProducers();
 			consumers = getConsumers();
-			powerPlant = getPowerPlant();// DANGER DONT GIVE NULL
+			powerPlant = control.getSimManager().getPowerPlant();// DANGER DONT GIVE NULL
 			if(powerPlant == null){
 				println("No Power Plant in Model");
 				return;
@@ -262,7 +262,7 @@ public class controlAlgorithm implements AddOn {
 			/////////
 			setPowerplantProduction(0);
 			enableAllConsumers();
-			SPC.disableStorageProduction(-1); //disable all storage production
+			SPC.disableStorageDischarging(-1); //disable all storage production
 
 //			StorageElement ele = new StorageElement("Storage", 1, 0, control.getModel());
 //			ele.setStatusAndSetEnergy(Mode.EMIT, 5000);
@@ -285,7 +285,7 @@ public class controlAlgorithm implements AddOn {
 			blackstartStartTime = Integer.parseInt(blackstartStartTimeTextfield.getText());
 			control.getModel().setIterations(Integer.parseInt(simulationDurationTextfield.getText()));
 			for (StorageElement se :
-					control.getModel().getStorageElements()) {
+					getStorageElements()) {
 				se.setStateOfCharge(Integer.parseInt(storageStartCharge.getText()));
 			}
 
@@ -323,7 +323,7 @@ public class controlAlgorithm implements AddOn {
 				blackstartRunningCounter++;
 				if (blackstartRunningCounter == blackstartSuccessTime) {
 					// blackstart was successfull for the needed iterations
-					SPC.disableStorageProduction(-1);
+					SPC.disableStorageDischarging(-1);
 					deactivateBlackstart();
 					enableAllConsumers();
 					updateVisual();
@@ -350,9 +350,9 @@ public class controlAlgorithm implements AddOn {
 	/**
 	 * TODO:HOLEG UNTERVERSORGUNG CHECKEN
 	 * TODO: storage laden
-	 * TODO: run houses / elements from storage storage entladen
 	 * TODO: storage im GUI hinzufuegen
 	 * TODO: prios fuer elemente anschalten
+	 * TODO: elements und amount nachschauen
 	 *
 	 * @param curIteration
 	 * @return true or false depending on whether the blackstart was successful for
@@ -363,14 +363,14 @@ public class controlAlgorithm implements AddOn {
 			// renewable energy production is not sufficient for the blackstart
 			if (SPC.currentPossibleStorageProduction() >= getPowerPlantBlackstartResistance()
 					- currentRenewableProduction()) {// is there currently enough power available from storage?
-				SPC.disableStorageProduction(-1);// emergency fix
-				SPC.enableStorageProduction(getPowerPlantBlackstartResistance() - currentRenewableProduction());
+				SPC.disableStorageDischarging(-1);// emergency fix
+				SPC.enableStorageDischarging(getPowerPlantBlackstartResistance() - currentRenewableProduction());
 				rampUpPowerplant();
 				enableConsumers(getPowerplantProduction());
 				return true;
 			} else {
 				// blackstart has failed
-				SPC.disableStorageProduction(-1);//TODO:disable all
+				SPC.disableStorageDischarging(-1);//TODO:disable all
 				println("Not enough storage energy available");
 				return false;
 			}
@@ -384,16 +384,16 @@ public class controlAlgorithm implements AddOn {
 		}
 	}
 
-	private HolonObject getPowerPlant() {
-		for (AbstractCpsObject cps : control.getModel().getAllHolonObjectsOnCanvas()) {
-			// geht nur wenn nur ein power plant vorhanden ist
-			if (cps instanceof HolonObject) {
-				if (cps.getObjName().equals("Power Plant")) {
-					return (HolonObject) cps;
+	public ArrayList<StorageElement> getStorageElements() {
+		ArrayList<StorageElement> storageElements = new ArrayList<StorageElement>();
+		for (HolonObject holonObject : control.getModel().getAllHolonObjectsOnCanvas()) {
+			for (HolonElement ele : holonObject.getElements()) {
+				if(ele instanceof StorageElement){
+					storageElements.add((StorageElement) ele);
 				}
 			}
 		}
-		return null;
+		return storageElements;
 	}
 
 	private void setDistanceToCalcResistance() {
@@ -592,16 +592,7 @@ public class controlAlgorithm implements AddOn {
 	}
 
 	private boolean blackstartRunning() {
-		for (HolonElement ele : powerPlant.getElements()) {
-			if (ele.getEleName().equals("Blackstart")) {
-				if (ele.isActive()) {
-					return true;
-				} else {
-					return false;
-				}
-			}
-		}
-		return false;
+		return control.getSimManager().blackstartRunning();
 	}
 
 	private void activateBlackstart() {

+ 90 - 14
src/ui/controller/SimulationManager.java

@@ -97,25 +97,28 @@ public class SimulationManager {
 			list = calculateNetworks(minimumModel, timestep, leftOver);
 			for(MinimumNetwork net : list) {
 				//if there is storage and it is needed turn it on//TODO:!!!
-//				if(!blackstartrunning() && storageexists()){
-//					turnOnStorage(energy needed())
-//				}
+				if(!blackstartRunning() && !net.getStorageElementList().isEmpty()) {
 
-                StorageProductionController SPC = model.getStorageProductionController();
-                SPC.disableStorageProduction(-1);
-                float consumption = 0;
-				float production = 0;
+                    StorageProductionController SPC = new StorageProductionController(net.getStorageElementList()); //TODO: unschoen
+                    SPC.disableStorageDischarging(-1);
 
+                    //calc consuption and production
+                    float consumption = calculateConsumption(net);
+                    float production = calculateProduction(net);
 
 
-				float difference = production - consumption;
-                System.out.println("Consumption " + consumption);
-                System.out.println("production " + production);
-				System.out.println("Difference " + difference);
-
-					//enable/load storage
-
+                    float difference = production - consumption;
+                    System.out.println("Consumption " + consumption);
+                    System.out.println("production " + production);
+                    System.out.println("Difference " + difference);
 
+                    if(difference > 0){
+                        SPC.enableStorageCharging(difference);
+                    }
+                    if(difference < 0){
+                        SPC.enableStorageDischarging(-difference);
+                    }
+                }
 
 				float energyOnCables = net.getHolonObjectList()
 						.stream()
@@ -144,6 +147,16 @@ public class SimulationManager {
 					cable.setState(CableState.Burned);
 					doAnotherLoop = true;
 				}
+
+
+                float consumption = calculateConsumption(net);
+                float production = calculateProduction(net);
+
+
+                float difference = production - consumption;
+                System.out.println("Consumption " + consumption);
+                System.out.println("production " + production);
+                System.out.println("Difference " + difference);
 			}
 		}
 		ArrayList<DecoratedNetwork> decorNetworks = new ArrayList<DecoratedNetwork>();
@@ -218,6 +231,15 @@ public class SimulationManager {
 				
 				neighbors.removeFirst();
 			}
+			//add storages
+            for (HolonObject holonObject : actualNetwork.getHolonObjectList()) {
+                for (HolonElement ele : holonObject.getElements()) {
+                    if(ele instanceof StorageElement){
+                        actualNetwork.getStorageElementList().add((StorageElement) ele);
+                    }
+                }
+            }
+
 			listOfNetworks.add(actualNetwork);
 		}	
 		if(leftOver!= null) {
@@ -305,5 +327,59 @@ public class SimulationManager {
 		return savesVisual.getOrDefault(timestep, null);
 	}
 
+	////////////////////////////////////////TODO:comments
+
+	public boolean blackstartRunning(){
+        for (HolonElement ele : getPowerPlant().getElements()) {
+            if (ele.getEleName().equals("Blackstart")) {
+                if (ele.isActive()) {
+                    return true;
+                } else {
+                    return false;
+                }
+            }
+        }
+        return false;
+    }
+
+    public HolonObject getPowerPlant() {
+        for (AbstractCpsObject cps : model.getAllHolonObjectsOnCanvas()) {
+            // geht nur wenn nur ein power plant vorhanden ist
+            if (cps instanceof HolonObject) {
+                if (cps.getObjName().equals("Power Plant")) {
+                    return (HolonObject) cps;
+                }
+            }
+        }
+        return null;
+    }
+
+    public float calculateProduction(MinimumNetwork net){
+	    float production = 0;
+        for (HolonObject holonObject : net.getHolonObjectList()) {
+            for(HolonElement holonElement : holonObject.getElements()){
+                if(holonElement.isActive()){
+                    if(holonElement.getEnergyPerElement() > 0){
+                        production = production + holonElement.getEnergyPerElement() * holonElement.getAmount();
+                    }
+                }
+            }
+        }
+        return production;
+    }
+
+    public float calculateConsumption(MinimumNetwork net){
+        float consumption = 0;
+        for (HolonObject holonObject : net.getHolonObjectList()) {
+            for(HolonElement holonElement : holonObject.getElements()){
+                if(holonElement.isActive()){
+                    if(holonElement.getEnergyPerElement() < 0){
+                        consumption = consumption - holonElement.getEnergyPerElement() * holonElement.getAmount();
+                    }
+                }
+            }
+        }
+        return consumption;
+    }
 
 }

+ 6 - 0
src/ui/model/MinimumNetwork.java

@@ -2,10 +2,12 @@ package ui.model;
 
 import java.util.ArrayList;
 import classes.HolonObject;
+import classes.StorageElement;
 
 public class MinimumNetwork {
 	private ArrayList<HolonObject> holonObjectList = new ArrayList<HolonObject>();
 	private ArrayList<IntermediateCableWithState> edgeList = new ArrayList<IntermediateCableWithState>();
+	ArrayList<StorageElement> storageElements = new ArrayList<StorageElement>();
 	public MinimumNetwork(ArrayList<HolonObject> holonObjectList, ArrayList<IntermediateCableWithState> edgeList){
 		this.holonObjectList = holonObjectList;
 		this.edgeList = edgeList;
@@ -16,6 +18,10 @@ public class MinimumNetwork {
 	public ArrayList<IntermediateCableWithState> getEdgeList() {
 		return edgeList;
 	}
+	public ArrayList<StorageElement> getStorageElementList() {
+		return storageElements;
+	}
+
 	public String toString()
 	{
 		String objecte = "[";

+ 28 - 25
src/ui/model/Model.java

@@ -159,10 +159,10 @@ public class Model {
     private StatisticPanel statPanel;
 
 
-    /*
-    Blackstart needs
-     */
-    private StorageProductionController storageProductionController;
+//    /* //TODO: remove
+//    Blackstart needs
+//     */
+//    private StorageProductionController storageProductionController;
 
     /**
      * Constructor for the model. It initializes the categories and
@@ -185,7 +185,7 @@ public class Model {
         setPropertyTable(new DefaulTable(1000, colNames.length));
         getPropertyTable().setColumnIdentifiers(colNames);
         setTableHolonElement(new JTable());
-        storageProductionController = new StorageProductionController();
+//        storageProductionController = new StorageProductionController(); //TODO:remove
         initGson();
     }
 
@@ -1105,25 +1105,28 @@ public class Model {
 		}
 	}
 
-    public StorageProductionController getStorageProductionController() {
-        return storageProductionController;
-    }
-
-    public void setStorageProductionController() {
-        this.storageProductionController.setStorages(getStorageElements());
-    }
 
-
-    //TODO: DAS GEHOERT NICHT IN MODEL
-    public ArrayList<StorageElement> getStorageElements() {
-        ArrayList<StorageElement> storageElements = new ArrayList<StorageElement>();
-        for (HolonObject holonObject : getAllHolonObjectsOnCanvas()) {
-            for (HolonElement ele : holonObject.getElements()) {
-                if(ele instanceof StorageElement){
-                    storageElements.add((StorageElement) ele);
-                }
-            }
-        }
-        return storageElements;
-    }
+//	//TODO: will ich das hier wirklich haben?
+//
+//    public StorageProductionController getStorageProductionController() {
+//        return storageProductionController;
+//    }
+//
+//    public void setStorageProductionController() {
+//        this.storageProductionController.setStorages(getStorageElements());
+//    }
+//
+//
+//    //TODO: DAS GEHOERT NICHT IN MODEL
+//    public ArrayList<StorageElement> getStorageElements() {
+//        ArrayList<StorageElement> storageElements = new ArrayList<StorageElement>();
+//        for (HolonObject holonObject : getAllHolonObjectsOnCanvas()) {
+//            for (HolonElement ele : holonObject.getElements()) {
+//                if(ele instanceof StorageElement){
+//                    storageElements.add((StorageElement) ele);
+//                }
+//            }
+//        }
+//        return storageElements;
+//    }
 }