Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,10 @@ public static PointValuePair apply(Coefficients coefficients, List<ManagedSymmet
var reactivePowerSolved = solvePowerIfNotNaN(setReactivePower, essList, Pwr.REACTIVE, direction);

var mergedResult = mergeResults(coefficients, esss, activePowerSolved, reactivePowerSolved);
if (mergedResult == null) {
if (mergedResult == null || mergedResult.length == 0) {
return null;
}

var result = Arrays.stream(mergedResult)//
.map(d -> reverseAbsoluteData(d, direction))//
.toArray();
if (result.length == 0) {
return null;
}
return new PointValuePair(result, 0);
return new PointValuePair(mergedResult, 0);
}

/**
Expand Down Expand Up @@ -188,7 +181,6 @@ private static double getPowerSetPoint(List<ManagedSymmetricEss> esss, List<Cons
.filter(constraint -> clusterEssId.equals(constraint.getCoefficients()[0].getCoefficient().getEssId()))
.filter(constraint -> constraint.getCoefficients()[0].getCoefficient().getPwr() == pwr)
.mapToDouble(constraint -> constraint.getValue().get())//
.map(c -> absoluteData(c, direction))//
.findFirst()//
.orElse(noPowerSetPoint);
}
Expand All @@ -199,36 +191,6 @@ private static List<ManagedSymmetricEss> getGenericEssList(List<ManagedSymmetric
.toList();
}

/**
* Calculate absolute value or zero based on the TargetDirection.
*
* @param d the input value to be processed
* @param direction the {@link TargetDirection}
* @return the processed value based on the direction
*/
private static double absoluteData(double d, TargetDirection direction) {
return switch (direction) {
case CHARGE -> Math.abs(d);
case DISCHARGE -> d;
case KEEP_ZERO -> 0.0;
};
}

/**
* Calculate reverse absolute value or zero based on the TargetDirection.
*
* @param d the input value to be processed
* @param direction the {@link TargetDirection}
* @return the processed value based on the direction
*/
private static double reverseAbsoluteData(double d, TargetDirection direction) {
return switch (direction) {
case CHARGE -> -d;
case DISCHARGE -> d;
case KEEP_ZERO -> 0.0;
};
}

/**
* Get the maximum power from a {@link ManagedSymmetricEss}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ public void testMultilayerCluster() throws Exception {
*
* @throws Exception on exception
*/
// @Test
@Test
public void testNearEqualDistribution() throws Exception {
EssPower powerComponent = new EssPowerImpl();

Expand Down Expand Up @@ -647,10 +647,10 @@ public void testNearEqualDistribution() throws Exception {
ess4.withAllowedDischargePower(1900);

// Should be
expect("#3.1", ess1, 2701, 0);
expect("#3.2", ess2, 2701, 0);
expect("#3.3", ess3, 2701, 0);
expect("#3.4", ess4, 1897, 0);
expect("#3.1", ess1, 3240, 0);
expect("#3.2", ess2, 3240, 0);
expect("#3.3", ess3, 1620, 0);
expect("#3.4", ess4, 1900, 0);

ess0.addPowerConstraint("SetActivePowerEquals", ALL, ACTIVE, EQUALS, 10000);
componentTest.next(new TestCase("#3"));
Expand All @@ -659,10 +659,10 @@ public void testNearEqualDistribution() throws Exception {
ess4.withAllowedDischargePower(12000);
ess4.withAllowedChargePower(-1900);

expect("#4.1", ess1, -9899, 0);
expect("#4.2", ess2, -9899, 0);
expect("#4.3", ess3, -9900, 0);
expect("#4.4", ess4, -1881, 0);
expect("#4.1", ess1, -2160, 0);
expect("#4.2", ess2, -2160, 0);
expect("#4.3", ess3, -3780, 0);
expect("#4.4", ess4, -1900, 0);

ess0.addPowerConstraint("SetActivePowerEquals", ALL, ACTIVE, EQUALS, -10000);
componentTest.next(new TestCase("#4"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.openems.edge.ess.core.power;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;

import java.util.Arrays;
Expand Down Expand Up @@ -181,6 +182,23 @@ public void test9() {
assertEquals(-30000.0, Arrays.stream(solution).sum(), 1e-6);
}

@Test
public void testLowerBoundsForLowSoc() {

double[] upperBound = { 12_000, 12_000, 12_000, 12_000 };
double[] lowerBound = { -12_000, -12_000, -12_000, -1_900 };
double[] socDistribution = { 60, 60, 30, 60 };
double powerSetValue = -10000;

double[] solution = SolverBySocOptimization.solveDistribution(upperBound, lowerBound, socDistribution,
powerSetValue, getDirection(powerSetValue));
// Print this if test fails
printing(socDistribution, upperBound, solution, lowerBound, powerSetValue);

assertEquals(-10000, Arrays.stream(solution).sum(), 1e-6);
assertArrayEquals(new double[] {-2160, -2160, -3779.9, -1900}, solution, 0.1);
}

private static String formatArray(String label, double[] array) {
StringJoiner joiner = new StringJoiner(", ");
for (double v : array) {
Expand Down