Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle load in merit order conversion #130

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -12,15 +12,26 @@
import com.powsybl.glsk.commons.CountryEICode;
import com.powsybl.glsk.commons.GlskException;
import com.powsybl.iidm.modification.scalable.Scalable;
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.Country;
import com.powsybl.iidm.network.DanglingLine;
import com.powsybl.iidm.network.Generator;
import com.powsybl.iidm.network.Load;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.Substation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiFunction;
import java.util.function.Function;

/**
* Convert a single GlskPoint to Scalable
*
* @author Pengbo Wang {@literal <pengbo.wang@rte-international.com>}
*/
public final class GlskPointScalableConverter {
Expand All @@ -31,7 +42,7 @@ private GlskPointScalableConverter() {
}

/**
* @param network IIDM network
* @param network IIDM network
* @param glskPoint GLSK Point
* @return powsybl-core Scalable
*/
Expand Down Expand Up @@ -135,21 +146,28 @@ private static Scalable convertMeritOrder(Network network, GlskPoint glskPoint)
Scalable upScalable = Scalable.stack(glskPoint.getGlskShiftKeys().stream()
.filter(glskShiftKey -> glskShiftKey.getMeritOrderPosition() > 0)
.sorted(Comparator.comparingInt(GlskShiftKey::getMeritOrderPosition))
.map(glskShiftKey -> {
GlskRegisteredResource resource = Objects.requireNonNull(glskShiftKey.getRegisteredResourceArrayList()).get(0);
return isGenerator(network, resource) ? getGeneratorScalableWithLimits(network, resource) : getDanglingLineScalableWithLimits(network, resource);
}).toArray(Scalable[]::new));
.map(getGlskShiftKeyScalableFunction(network)).toArray(Scalable[]::new));

Scalable downScalable = Scalable.stack(glskPoint.getGlskShiftKeys().stream()
.filter(glskShiftKey -> glskShiftKey.getMeritOrderPosition() < 0)
.sorted(Comparator.comparingInt(GlskShiftKey::getMeritOrderPosition).reversed())
.map(glskShiftKey -> {
GlskRegisteredResource resource = Objects.requireNonNull(glskShiftKey.getRegisteredResourceArrayList()).get(0);
return isGenerator(network, resource) ? getGeneratorScalableWithLimits(network, resource) : getDanglingLineScalableWithLimits(network, resource);
}).toArray(Scalable[]::new));
.map(getGlskShiftKeyScalableFunction(network)).toArray(Scalable[]::new));
return Scalable.upDown(upScalable, downScalable);
}

private static Function<GlskShiftKey, Scalable> getGlskShiftKeyScalableFunction(Network network) {
return glskShiftKey -> {
GlskRegisteredResource resource = Objects.requireNonNull(glskShiftKey.getRegisteredResourceArrayList()).get(0);
if (isGenerator(network, resource)) {
return getGeneratorScalableWithLimits(network, resource);
} else if (isLoad(network, resource)) {
return getLoadScalableWithLimits(network, resource);
} else {
return getDanglingLineScalableWithLimits(network, resource);
}
};
}

/**
* convert country proportional glsk point to scalable
* @param network iidm network
Expand Down Expand Up @@ -306,6 +324,10 @@ private static boolean isGenerator(Network network, GlskRegisteredResource glskR
return network.getGenerator(glskRegisteredResource.getGeneratorId()) != null;
}

private static boolean isLoad(Network network, GlskRegisteredResource glskRegisteredResource) {
return network.getLoad(glskRegisteredResource.getLoadId()) != null;
}

private static Scalable getGeneratorScalableWithLimits(Network network, GlskRegisteredResource generatorRegisteredResource) {
String generatorId = generatorRegisteredResource.getGeneratorId();
double incomingMaxP = generatorRegisteredResource.getMaximumCapacity().orElse(Double.MAX_VALUE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,16 @@ void checkCseGlskDocumentImporterCorrectlyConvertMeritOrderGskBlocksDownWithDang
assertEquals(2000., network.getDanglingLine("BBE2AA1 XNODE_1B 1").getP0(), EPSILON); // -1000
assertEquals(2000., network.getDanglingLine("DDE3AA1 XNODE_1A 1").getP0(), EPSILON); // -3000
assertEquals(1500., network.getGenerator("FFR1AA1 _generator").getTargetP(), EPSILON); // -500
}

@Test
void checkCseGlskDocumentImporterCorrectlyConvertMeritOrderGskBlocksWithLoads() {
Network network = Network.read("testCaseWithLoadss.xiidm", getClass().getResourceAsStream("/testCaseWithLoads.xiidm"));
GlskDocument glskDocument = GlskDocumentImporters.importGlsk(getClass().getResourceAsStream("/testGlskWithLoads.xml"));
Scalable meritOrderGskScalable = glskDocument.getZonalScalable(network).getData("FR_MERITORDER");

assertNotNull(meritOrderGskScalable);
assertEquals(-100., network.getLoad("IMESM121_load").getP0(), EPSILON);
}

@Test
Expand Down
Loading