package classes; import com.google.gson.annotations.Expose; import ui.model.Model; public class StorageElement extends HolonElement implements Comparable { @Expose private Mode status; @Expose private float stateOfCharge; @Expose private float capacity; @Expose private float maxInRatio; @Expose private float nominalOutRatio; @Expose private float currentMaxOutRatio; @Expose private float chargingRatio; @Expose private resistanceCalculator resistanceCalculator; public StorageElement(String eleName, int amount, float energy, Model model, float capacity, float maxInRatio, float nominalOutRatio) { super(eleName, amount, energy, model); this.stateOfCharge = 0; this.maxInRatio = maxInRatio; this.nominalOutRatio = nominalOutRatio; this.capacity = capacity * 60;// we save in watts per minute for ease of use this.status = Mode.STANDBY; this.chargingRatio = 0; this.resistanceCalculator = new resistanceCalculator(230, 20000,10, 25, 0.017, 0.017);//TODO } public float getEnergyPerElement() { if (status == Mode.STANDBY) { return 0; } return this.energyPerElement; } public float getPossibleProduction(float energyRequiredForPowerplantBlackstart) { if (stateOfCharge > 0) { if (stateOfCharge >= currentMaxOutRatio) { return energyAfterResistance(currentMaxOutRatio, energyRequiredForPowerplantBlackstart); } else { return energyAfterResistance(stateOfCharge, energyRequiredForPowerplantBlackstart); } } else { return 0; } } private float getPossiblePower(){ if (stateOfCharge > 0) { if (stateOfCharge >= nominalOutRatio) { return nominalOutRatio; } else { return stateOfCharge; } } else { return 0; } } private float energyAfterResistance(float energy, float energyRequiredForPowerplantBlackstart){ return resistanceCalculator.calcEnergyAfterResistance(energy, getLowDistance(), getHighDistance(), energyRequiredForPowerplantBlackstart); } /** * * @param status Mode of currect operation * @param energyWanted float how much energy is needed from storage/ can be collected * by the storage * @return float how much energy was collected/emited */ public double setStatusAndSetEnergy(Mode status, double energyWanted, float energyRequiredForPowerplantBlackstart) { double energyNeed = resistanceCalculator.calcEnergyNeededForCertainEnergyAfterResistance( energyWanted, getLowDistance(), getHighDistance(), energyRequiredForPowerplantBlackstart); this.status = status; switch (status) { case STANDBY: this.setEnergyPerElement(0); chargingRatio = 0; return 0; case EMIT: if (energyNeed >= currentMaxOutRatio) { // more energy wanted than can be giving if (stateOfCharge >= currentMaxOutRatio) { // more energy wanted than can be given return emitWantedEnergy(currentMaxOutRatio, energyRequiredForPowerplantBlackstart); } } else {// less wanted than what can be max be given if(stateOfCharge >= energyNeed){ //das kann doch garnicht funktioniern! // doch geht need 'vor abzuegen'ist das was abgezogen wird want 'nach abzuegen' das eingespeist wird // return emitWantedEnergy(energyNeed, energyRequiredForPowerplantBlackstart);//zurueckrechnungs problem! float nicht genau genug this.setEnergyPerElement((float) energyWanted); chargingRatio = (float) energyNeed; return energyWanted; } } return notEnoughChargedToEmitWantedEnergy(energyRequiredForPowerplantBlackstart); case COLLECT://TODO: more testing IGNORES resistanceses! if (energyWanted >= maxInRatio) { // more engery given than can be collected if (stateOfCharge + maxInRatio > capacity) { // Storage nearly full only load rest to get full this.setEnergyPerElement(-(capacity - stateOfCharge)); chargingRatio = -(capacity - stateOfCharge); return capacity - stateOfCharge; } else { // load with maximal of what can be collected this.setEnergyPerElement(-maxInRatio); chargingRatio = -maxInRatio; return maxInRatio; } } else { // less engery given than can be taken in if (capacity == stateOfCharge) { // storage full no energy collected this.status = Mode.STANDBY; chargingRatio = 0; return 0; } else { if (stateOfCharge + energyWanted > capacity) { // Storage nearly full only load rest to get full this.setEnergyPerElement(-(capacity - stateOfCharge)); chargingRatio = -(capacity - stateOfCharge); return capacity - stateOfCharge; } else { // take all engery that is available this.setEnergyPerElement((float) -energyWanted); chargingRatio = (float) -energyWanted; return energyWanted; } } } default: System.out.println("no status available"); return 0; } } public Mode getStatus() { return this.status; } public void stateOfChargeCalculation(){ // System.out.println("stateofcharge" + getId()+ "before:" + stateOfCharge + " with incomming " + status + " after resi " + getEnergyPerElement() +" before resi "+ chargingRatio); switch (status){ case COLLECT: case EMIT: stateOfCharge = stateOfCharge - chargingRatio; setCurrentMaxOutRatio(); break; default: } //TODO: fix for gui error comment out bottom if (not sure if side effects should work since storage gets disabled every iteration) if(stateOfCharge <= 0 || stateOfCharge >= capacity){ status = Mode.STANDBY; chargingRatio = 0; setEnergyPerElement(0); } // System.out.println("stateofcharge after:" + stateOfCharge + " now as " + status + " " + getEnergyPerElement() ); } public void setStateOfCharge(float percentage){ this.stateOfCharge = capacity * (percentage / 100); setCurrentMaxOutRatio(); } public float getStateOfChargeInPercent(){// 1.0 = 100% return stateOfCharge / capacity; } private void setCurrentMaxOutRatio(){ if(getStateOfChargeInPercent() > 0.8){ currentMaxOutRatio = (float) (nominalOutRatio * (1 + (0.005 * (getStateOfChargeInPercent() * 100 - 0.8 * 100)))); }else if(getStateOfChargeInPercent() < 0.2){ currentMaxOutRatio = (float) (nominalOutRatio * (1 - (0.01 * (0.2 * 100 - getStateOfChargeInPercent() * 100)))); }else{ currentMaxOutRatio = nominalOutRatio; } } private float notEnoughChargedToEmitWantedEnergy(float energyRequiredForPowerplantBlackstart){ if(stateOfCharge <= 0){ this.status = Mode.STANDBY; this.setEnergyPerElement(0); return 0; }else{ return emitWantedEnergy(stateOfCharge, energyRequiredForPowerplantBlackstart); } } private float emitWantedEnergy(float maxEnergy, float energyRequiredForPowerplantBlackstart){ float energyAfterResistance = energyAfterResistance(maxEnergy, energyRequiredForPowerplantBlackstart); this.setEnergyPerElement(energyAfterResistance); chargingRatio = maxEnergy; return energyAfterResistance; } public double getUtilization(float energyRequiredForPowerplantBlackstart){ if(currentMaxOutRatio == 0){ return 0; }else { return (resistanceCalculator.calcEnergyNeededForCertainEnergyAfterResistance(getEnergyPerElement(), getLowDistance(), getHighDistance(), energyRequiredForPowerplantBlackstart) * 100) / currentMaxOutRatio; } } public float getStateOfCharge() { return stateOfCharge; } public float getNominalOutRatio() { return nominalOutRatio; } public float getCurrentMaxOutRatio() { return currentMaxOutRatio; } public boolean chargeDepleted(){ return stateOfCharge <= 0; } public boolean fullyCharged(){ return stateOfCharge >= capacity; } public float getChargingRatio() { return chargingRatio; } @Override public int compareTo(StorageElement storageElement) {//TODO:!!! if(this.getPossiblePower() < storageElement.getPossiblePower()){ return 1; }else if(this.getPossiblePower() > storageElement.getPossiblePower()){ return -1; }else if(this.stateOfCharge < storageElement.getStateOfCharge()){ return -1; }else if(this.stateOfCharge > storageElement.getStateOfCharge()){ return 1; }else{ return Double.compare(storageElement.getLowDistance()+storageElement.getHighDistance(), this.getLowDistance() + this.getHighDistance()); } } public enum Mode { COLLECT, EMIT, STANDBY } }