123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- package algo;
- import com.google.gson.annotations.Expose;
- import algo.StorageObject.Mode;
- import classes.HolonElement;
- import ui.model.Model;
- public class StorageElement extends HolonElement {
- @Expose
- private Mode status;
-
- @Expose
- private float stateOfCharge;
-
- @Expose
- private float capacity;
-
- @Expose
- private float maxInRatio;
-
- @Expose
- private float maxOutRatio;
- public StorageElement(String eleName, int amount, float energy, Model model) {
- super(eleName, amount, energy, model);
- this.stateOfCharge = 4000;
- this.maxInRatio = 5000;
- this.maxOutRatio = 5000;
- this.capacity = 10000 * 60;// for example tesla power wall 10kwh, 10kw per hour thus * 60 if iteration =
- // minutes//TODO:!
- this.status = Mode.STANDBY;
- }
- public float getEnergyPerElement() {
- switch (status) {
- case STANDBY:
- return 0;
- default:
- return this.energyPerElement;
- }
- }
- public float getPossibleProduction() {
- if (stateOfCharge > 0) {
- if (stateOfCharge >= maxOutRatio) {
- return maxOutRatio;
- } else {
- return stateOfCharge;
- }
- } else {
- return 0;
- }
- }
- /**
- *
- * @param status Mode of currect operation
- * @param energy float how much energy is needed from storage/ can be collected
- * by the storage
- * @return float how much energy was collected/emited
- */
- public float setStatusAndSetEnergy(Mode status, float energy) {
- this.status = status;
- switch (status) {
- case STANDBY:
- this.setEnergyPerElement(0);
- return 0;
- case EMIT:
- if (stateOfCharge >= energy) { // enough energy stored than wanted
- if (energy >= maxInRatio) { // more energy wanted than can be given
- this.setEnergyPerElement(maxOutRatio);
- // stateOfCharge = stateOfCharge - maxOutRatio;//TODO: not hear but in simulation manager
- return maxOutRatio;
- } else { // less energy wanted that can be given
- this.setEnergyPerElement(energy);
- // stateOfCharge = stateOfCharge - energy;
- return energy;
- }
- } else {// not enough energy stored than wanted
- if (stateOfCharge == 0) { // no energy stored at all
- this.status = Mode.STANDBY;
- return 0;
- } else { // emit energy that is available even though is less that wanted
- this.setEnergyPerElement(stateOfCharge);
- // stateOfCharge = 0;
- return stateOfCharge;
- }
- }
- case COLLECT:
- if (energy >= 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));
- // stateOfCharge = capacity;
- return capacity - stateOfCharge;
- } else { // load with maximal of what can be collected
- this.setEnergyPerElement(-maxInRatio);
- // stateOfCharge = stateOfCharge + maxInRatio;
- return maxInRatio;
- }
- } else { // less engery given than can be taken in
- if (capacity == stateOfCharge) { // storage full no energy collected
- this.status = Mode.STANDBY;
- return 0;
- } else {
- if (stateOfCharge + energy > capacity) { // Storage nearly full only load rest to get full
- this.setEnergyPerElement(-(capacity - stateOfCharge));
- // stateOfCharge = capacity;
- return capacity - stateOfCharge;
- } else { // take all engery that is available
- this.setEnergyPerElement(-energy);
- // stateOfCharge = stateOfCharge + energy;
- return energy;
- }
- }
- }
- default:
- System.out.println("no status available");
- return 0;
- }
- }
- public Mode getStatus() {
- return this.status;
- }
- public void chargeCalc(){
- switch (status){
- case COLLECT:
- stateOfCharge = stateOfCharge - getEnergyPerElement();
- break;
- case EMIT:
- stateOfCharge = stateOfCharge + getEnergyPerElement();
- break;
- default:
- }
- if(stateOfCharge <= 0 || stateOfCharge >= capacity){
- status = Mode.STANDBY;
- setEnergyPerElement(0);
- }
- }
- public void setStateOfCharge(float stateOfCharge){
- if(stateOfCharge < capacity){
- this.stateOfCharge = stateOfCharge;
- }else{
- this.stateOfCharge = capacity;
- }
- }
- public enum Mode {
- COLLECT, EMIT, STANDBY
- }
- }
|