Skip to content

Commit

Permalink
Allow defining GLSK on DanglingLine (#99)
Browse files Browse the repository at this point in the history
* Allow defining GLSK on DanglingLine

Signed-off-by: Peter Mitri <peter.mitri@rte-france.com>
  • Loading branch information
pet-mit authored Sep 25, 2023
1 parent dca2a82 commit de70297
Show file tree
Hide file tree
Showing 26 changed files with 7,691 additions and 6,033 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
*/
package com.powsybl.glsk.api;

import com.powsybl.iidm.network.Network;

import java.util.Optional;

/**
* Registered Resource: a generator or a load, with its participation factor
* @author Pengbo Wang {@literal <pengbo.wang@rte-international.com>}
* @author Peter Mitri {@literal <peter.mitri@rte-france.com>}
*/
public interface GlskRegisteredResource {

Expand Down Expand Up @@ -50,12 +53,17 @@ public interface GlskRegisteredResource {
Optional<Double> getMinimumCapacity();

/**
* @return the genrator Id according to type of Glsk File
* @return the generator Id according to type of Glsk File
*/
String getGeneratorId();

/**
* @return the load Id according to the type of Glsk File
*/
String getLoadId();

/**
* @return the dangling line Id according to the type of Glsk File
*/
String getDanglingLineId(Network network);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@
package com.powsybl.glsk.api.util;

import com.powsybl.glsk.commons.GlskException;
import com.powsybl.iidm.network.Identifiable;
import com.powsybl.iidm.network.Network;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

/**
* @author Joris Mancini {@literal <joris.mancini at rte-france.com>}
* @author Peter Mitri {@literal <peter.mitri@rte-france.com>}
*/
public final class Util {

Expand All @@ -25,4 +30,16 @@ public static Node getUniqueNode(Element glskBlockElement, String tag) {
return Optional.ofNullable(glskBlockElement.getElementsByTagName(tag).item(0))
.orElseThrow(() -> new GlskException(String.format("Impossible to import GLSK: <%s> tag is missing", tag)));
}

public static String findDanglingLineIdForXndoe(Network network, String xnode) {
Set<String> danglingLines = network.getDanglingLineStream()
.filter(dl -> dl.getUcteXnodeCode().equals(xnode))
.map(Identifiable::getId)
.collect(Collectors.toSet());
if (danglingLines.size() != 1) {
// No / multiple dangling lines found for Xnode
return null;
}
return danglingLines.iterator().next();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
/**
* Convert a single GlskPoint to LinearGlsk
* @author Pengbo Wang {@literal <pengbo.wang@rte-international.com>}
* @author Peter Mitri {@literal <peter.mitri@rte-france.com>}
*/
public final class GlskPointLinearGlskConverter {
private static final Logger LOGGER = LoggerFactory.getLogger(GlskPointLinearGlskConverter.class);
Expand Down Expand Up @@ -119,6 +120,13 @@ private static void convertCountryProportional(Network network, GlskShiftKey gls
* @param weightedSensitivityVariables linearGlsk to be filled
*/
private static void convertExplicitProportional(Network network, GlskShiftKey glskShiftKey, List<WeightedSensitivityVariable> weightedSensitivityVariables) {
List<DanglingLine> danglingLines = glskShiftKey.getRegisteredResourceArrayList().stream()
.map(rr -> rr.getDanglingLineId(network))
.filter(Objects::nonNull)
.map(network::getDanglingLine)
.filter(NetworkUtil::isCorrect)
.collect(Collectors.toList());
double totalP = danglingLines.stream().mapToDouble(NetworkUtil::pseudoP0).sum();
//Generator A04 or Load A05
if (glskShiftKey.getPsrType().equals("A04")) {
//Generator A04
Expand All @@ -127,23 +135,31 @@ private static void convertExplicitProportional(Network network, GlskShiftKey gl
.map(network::getGenerator)
.filter(NetworkUtil::isCorrect)
.collect(Collectors.toList());
double totalP = generators.stream().mapToDouble(NetworkUtil::pseudoTargetP).sum();
generators.forEach(generator -> weightedSensitivityVariables.add(new WeightedSensitivityVariable(generator.getId(),
glskShiftKey.getQuantity().floatValue() * (float) NetworkUtil.pseudoTargetP(generator) / (float) totalP)));
totalP += generators.stream().mapToDouble(NetworkUtil::pseudoTargetP).sum();
for (Generator generator : generators) {
weightedSensitivityVariables.add(new WeightedSensitivityVariable(generator.getId(),
glskShiftKey.getQuantity().floatValue() * (float) NetworkUtil.pseudoTargetP(generator) / (float) totalP));
}
} else if (glskShiftKey.getPsrType().equals("A05")) {
//Load A05
List<Load> loads = glskShiftKey.getRegisteredResourceArrayList().stream()
.map(GlskRegisteredResource::getLoadId)
.map(network::getLoad)
.filter(NetworkUtil::isCorrect)
.collect(Collectors.toList());
double totalLoad = loads.stream().mapToDouble(NetworkUtil::pseudoP0).sum();
loads.forEach(load -> weightedSensitivityVariables.add(new WeightedSensitivityVariable(load.getId(),
glskShiftKey.getQuantity().floatValue() * (float) NetworkUtil.pseudoP0(load) / (float) totalLoad)));
totalP += loads.stream().mapToDouble(NetworkUtil::pseudoP0).sum();
for (Load load : loads) {
weightedSensitivityVariables.add(new WeightedSensitivityVariable(load.getId(),
glskShiftKey.getQuantity().floatValue() * (float) NetworkUtil.pseudoP0(load) / (float) totalP));
}
} else {
//unknown PsrType
throw new GlskException("convertExplicitProportional PsrType not supported");
}
for (DanglingLine danglingLine : danglingLines) {
weightedSensitivityVariables.add(new WeightedSensitivityVariable(danglingLine.getId(),
glskShiftKey.getQuantity().floatValue() * (float) NetworkUtil.pseudoP0(danglingLine) / (float) totalP));
}
}

/**
Expand All @@ -153,31 +169,44 @@ private static void convertExplicitProportional(Network network, GlskShiftKey gl
*/
private static void convertParticipationFactor(Network network, GlskShiftKey glskShiftKey, List<WeightedSensitivityVariable> weightedSensitivityVariables) {
//Generator A04 or Load A05
List<GlskRegisteredResource> danglingLineResources = glskShiftKey.getRegisteredResourceArrayList().stream()
.filter(danglingLineResource -> danglingLineResource.getDanglingLineId(network) != null &&
NetworkUtil.isCorrect(network.getDanglingLine(danglingLineResource.getDanglingLineId(network))))
.collect(Collectors.toList());
double totalFactor = danglingLineResources.stream().mapToDouble(GlskRegisteredResource::getParticipationFactor).sum();
if (glskShiftKey.getPsrType().equals("A04")) {
//Generator A04
List<GlskRegisteredResource> generatorResources = glskShiftKey.getRegisteredResourceArrayList().stream()
.filter(generatorResource -> NetworkUtil.isCorrect(network.getGenerator(generatorResource.getGeneratorId())))
.collect(Collectors.toList());
double totalFactor = generatorResources.stream().mapToDouble(GlskRegisteredResource::getParticipationFactor).sum();
.filter(generatorResource -> NetworkUtil.isCorrect(network.getGenerator(generatorResource.getGeneratorId())))
.collect(Collectors.toList());
totalFactor += generatorResources.stream().mapToDouble(GlskRegisteredResource::getParticipationFactor).sum();
if (totalFactor < 1e-10) {
throw new GlskException("total factor is zero");
}
generatorResources.forEach(generatorResource -> weightedSensitivityVariables.add(new WeightedSensitivityVariable(generatorResource.getGeneratorId(),
glskShiftKey.getQuantity().floatValue() * (float) generatorResource.getParticipationFactor() / (float) totalFactor)));
for (GlskRegisteredResource generatorResource : generatorResources) {
weightedSensitivityVariables.add(new WeightedSensitivityVariable(generatorResource.getGeneratorId(),
glskShiftKey.getQuantity().floatValue() * (float) generatorResource.getParticipationFactor() / (float) totalFactor));
}
} else if (glskShiftKey.getPsrType().equals("A05")) {
//Load A05
List<GlskRegisteredResource> loadResources = glskShiftKey.getRegisteredResourceArrayList().stream()
.filter(loadResource -> NetworkUtil.isCorrect(network.getLoad(loadResource.getLoadId())))
.collect(Collectors.toList());
double totalFactor = loadResources.stream().mapToDouble(GlskRegisteredResource::getParticipationFactor).sum();
.filter(loadResource -> NetworkUtil.isCorrect(network.getLoad(loadResource.getLoadId())))
.collect(Collectors.toList());
totalFactor += loadResources.stream().mapToDouble(GlskRegisteredResource::getParticipationFactor).sum();
if (totalFactor < 1e-10) {
throw new GlskException("total factor is zero");
}
loadResources.forEach(loadResource -> weightedSensitivityVariables.add(new WeightedSensitivityVariable(loadResource.getLoadId(),
glskShiftKey.getQuantity().floatValue() * (float) loadResource.getParticipationFactor() / (float) totalFactor)));
for (GlskRegisteredResource loadResource : loadResources) {
weightedSensitivityVariables.add(new WeightedSensitivityVariable(loadResource.getLoadId(),
glskShiftKey.getQuantity().floatValue() * (float) loadResource.getParticipationFactor() / (float) totalFactor));
}
} else {
//unknown PsrType
throw new GlskException("convertParticipationFactor PsrType not supported");
}
for (GlskRegisteredResource danglingLineResource : danglingLineResources) {
weightedSensitivityVariables.add(new WeightedSensitivityVariable(danglingLineResource.getDanglingLineId(network),
glskShiftKey.getQuantity().floatValue() * (float) danglingLineResource.getParticipationFactor() / (float) totalFactor));
}
}
}
Loading

0 comments on commit de70297

Please sign in to comment.