Search in sources :

Example 1 with MeterNature

use of io.openems.api.device.nature.meter.MeterNature in project openems by OpenEMS.

the class SimulatorGridMeter method update.

@Override
protected void update() {
    super.update();
    long activePower = 0;
    long activePowerL1 = 0;
    long activePowerL2 = 0;
    long activePowerL3 = 0;
    if (activePowerLoad != null) {
        factorL1 = SimulatorTools.addRandomDouble(factorL1, 0, 1, 0.01);
        factorL2 = SimulatorTools.addRandomDouble(factorL2, 0, 1 - factorL1, 0.01);
        factorL3 = 1 - factorL1 - factorL2;
        long load = activePowerLoad.getLoad();
        activePower = load;
        activePowerL1 = (long) (load * factorL1);
        activePowerL2 = (long) (load * factorL2);
        activePowerL3 = (long) (load * factorL3);
    }
    long reactivePower = 0;
    long reactivePowerL1 = 0;
    long reactivePowerL2 = 0;
    long reactivePowerL3 = 0;
    if (reactivePowerLoad != null) {
        reactivePower = reactivePowerLoad.getLoad();
        reactivePowerL1 = reactivePower / 3;
        reactivePowerL2 = reactivePower / 3;
        reactivePowerL3 = reactivePower / 3;
    }
    for (EssNature entry : essNatures) {
        if (entry instanceof SymmetricEssNature) {
            SymmetricEssNature ess = (SymmetricEssNature) entry;
            activePower -= ess.activePower().valueOptional().orElse(0L);
            activePowerL1 -= ess.activePower().valueOptional().orElse(0L) / 3;
            activePowerL2 -= ess.activePower().valueOptional().orElse(0L) / 3;
            activePowerL3 -= ess.activePower().valueOptional().orElse(0L) / 3;
            reactivePower -= ess.reactivePower().valueOptional().orElse(0L);
            reactivePowerL1 -= ess.reactivePower().valueOptional().orElse(0L) / 3;
            reactivePowerL2 -= ess.reactivePower().valueOptional().orElse(0L) / 3;
            reactivePowerL3 -= ess.reactivePower().valueOptional().orElse(0L) / 3;
        } else if (entry instanceof AsymmetricEssNature) {
            AsymmetricEssNature ess = (AsymmetricEssNature) entry;
            activePower -= ess.activePowerL1().valueOptional().orElse(0L) + ess.activePowerL2().valueOptional().orElse(0L) + ess.activePowerL3().valueOptional().orElse(0L);
            activePowerL1 -= ess.activePowerL1().valueOptional().orElse(0L);
            activePowerL2 -= ess.activePowerL2().valueOptional().orElse(0L);
            activePowerL3 -= ess.activePowerL3().valueOptional().orElse(0L);
            reactivePower -= ess.reactivePowerL1().valueOptional().orElse(0L) + ess.reactivePowerL2().valueOptional().orElse(0L) + ess.reactivePowerL3().valueOptional().orElse(0L);
            reactivePowerL1 -= ess.reactivePowerL1().valueOptional().orElse(0L);
            reactivePowerL2 -= ess.reactivePowerL2().valueOptional().orElse(0L);
            reactivePowerL3 -= ess.reactivePowerL3().valueOptional().orElse(0L);
        }
    }
    for (MeterNature entry : meterNatures) {
        if (entry instanceof SymmetricMeterNature) {
            SymmetricMeterNature meter = (SymmetricMeterNature) entry;
            activePower -= meter.activePower().valueOptional().orElse(0L);
            activePowerL1 -= meter.activePower().valueOptional().orElse(0L) / 3;
            activePowerL2 -= meter.activePower().valueOptional().orElse(0L) / 3;
            activePowerL3 -= meter.activePower().valueOptional().orElse(0L) / 3;
            reactivePower -= meter.reactivePower().valueOptional().orElse(0L);
            reactivePowerL1 -= meter.reactivePower().valueOptional().orElse(0L) / 3;
            reactivePowerL2 -= meter.reactivePower().valueOptional().orElse(0L) / 3;
            reactivePowerL3 -= meter.reactivePower().valueOptional().orElse(0L) / 3;
        } else if (entry instanceof AsymmetricMeterNature) {
            AsymmetricMeterNature meter = (AsymmetricMeterNature) entry;
            activePower -= meter.activePowerL1().valueOptional().orElse(0L) + meter.activePowerL2().valueOptional().orElse(0L) + meter.activePowerL3().valueOptional().orElse(0L);
            activePowerL1 -= meter.activePowerL1().valueOptional().orElse(0L);
            activePowerL2 -= meter.activePowerL2().valueOptional().orElse(0L);
            activePowerL3 -= meter.activePowerL3().valueOptional().orElse(0L);
            reactivePower -= meter.reactivePowerL1().valueOptional().orElse(0L) + meter.reactivePowerL2().valueOptional().orElse(0L) + meter.reactivePowerL3().valueOptional().orElse(0L);
            reactivePowerL1 -= meter.reactivePowerL1().valueOptional().orElse(0L);
            reactivePowerL2 -= meter.reactivePowerL2().valueOptional().orElse(0L);
            reactivePowerL3 -= meter.reactivePowerL3().valueOptional().orElse(0L);
        }
    }
    if (isOffGrid(essNatures)) {
        this.activePower.updateValue(null);
        this.activePowerL1.updateValue(null);
        this.activePowerL2.updateValue(null);
        this.activePowerL3.updateValue(null);
        this.reactivePower.updateValue(null);
        this.reactivePowerL1.updateValue(null);
        this.reactivePowerL2.updateValue(null);
        this.reactivePowerL3.updateValue(null);
    } else {
        this.activePower.updateValue(activePower);
        this.activePowerL1.updateValue(activePowerL1);
        this.activePowerL2.updateValue(activePowerL2);
        this.activePowerL3.updateValue(activePowerL3);
        this.reactivePower.updateValue(reactivePower);
        this.reactivePowerL1.updateValue(reactivePowerL1);
        this.reactivePowerL2.updateValue(reactivePowerL2);
        this.reactivePowerL3.updateValue(reactivePowerL3);
    }
}
Also used : AsymmetricEssNature(io.openems.api.device.nature.ess.AsymmetricEssNature) EssNature(io.openems.api.device.nature.ess.EssNature) SymmetricEssNature(io.openems.api.device.nature.ess.SymmetricEssNature) SymmetricMeterNature(io.openems.api.device.nature.meter.SymmetricMeterNature) AsymmetricMeterNature(io.openems.api.device.nature.meter.AsymmetricMeterNature) MeterNature(io.openems.api.device.nature.meter.MeterNature) SymmetricMeterNature(io.openems.api.device.nature.meter.SymmetricMeterNature) AsymmetricMeterNature(io.openems.api.device.nature.meter.AsymmetricMeterNature) SymmetricEssNature(io.openems.api.device.nature.ess.SymmetricEssNature) AsymmetricEssNature(io.openems.api.device.nature.ess.AsymmetricEssNature)

Aggregations

AsymmetricEssNature (io.openems.api.device.nature.ess.AsymmetricEssNature)1 EssNature (io.openems.api.device.nature.ess.EssNature)1 SymmetricEssNature (io.openems.api.device.nature.ess.SymmetricEssNature)1 AsymmetricMeterNature (io.openems.api.device.nature.meter.AsymmetricMeterNature)1 MeterNature (io.openems.api.device.nature.meter.MeterNature)1 SymmetricMeterNature (io.openems.api.device.nature.meter.SymmetricMeterNature)1