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

Allow defining GLSK on DanglingLine #99

Merged
merged 12 commits into from
Sep 25, 2023
Merged
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,28 @@ 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();
totalP += generators.stream().mapToDouble(NetworkUtil::pseudoTargetP).sum();
double finalTotalP = totalP;
murgeyseb marked this conversation as resolved.
Show resolved Hide resolved
generators.forEach(generator -> weightedSensitivityVariables.add(new WeightedSensitivityVariable(generator.getId(),
glskShiftKey.getQuantity().floatValue() * (float) NetworkUtil.pseudoTargetP(generator) / (float) totalP)));
glskShiftKey.getQuantity().floatValue() * (float) NetworkUtil.pseudoTargetP(generator) / (float) finalTotalP)));
} 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();
totalP += loads.stream().mapToDouble(NetworkUtil::pseudoP0).sum();
double finalTotalP = totalP;
loads.forEach(load -> weightedSensitivityVariables.add(new WeightedSensitivityVariable(load.getId(),
glskShiftKey.getQuantity().floatValue() * (float) NetworkUtil.pseudoP0(load) / (float) totalLoad)));
glskShiftKey.getQuantity().floatValue() * (float) NetworkUtil.pseudoP0(load) / (float) finalTotalP)));
} else {
//unknown PsrType
throw new GlskException("convertExplicitProportional PsrType not supported");
}
double finalTotalP = totalP;
danglingLines.forEach(danglingLine -> weightedSensitivityVariables.add(new WeightedSensitivityVariable(danglingLine.getId(),
glskShiftKey.getQuantity().floatValue() * (float) NetworkUtil.pseudoP0(danglingLine) / (float) finalTotalP)));
}

/**
Expand All @@ -153,31 +166,41 @@ 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");
}
double finalTotalFactor2 = totalFactor;
generatorResources.forEach(generatorResource -> weightedSensitivityVariables.add(new WeightedSensitivityVariable(generatorResource.getGeneratorId(),
glskShiftKey.getQuantity().floatValue() * (float) generatorResource.getParticipationFactor() / (float) totalFactor)));
glskShiftKey.getQuantity().floatValue() * (float) generatorResource.getParticipationFactor() / (float) finalTotalFactor2)));
} 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");
}
double finalTotalFactor = totalFactor;
loadResources.forEach(loadResource -> weightedSensitivityVariables.add(new WeightedSensitivityVariable(loadResource.getLoadId(),
glskShiftKey.getQuantity().floatValue() * (float) loadResource.getParticipationFactor() / (float) totalFactor)));
glskShiftKey.getQuantity().floatValue() * (float) loadResource.getParticipationFactor() / (float) finalTotalFactor)));
} else {
//unknown PsrType
throw new GlskException("convertParticipationFactor PsrType not supported");
}
double finalTotalFactor = totalFactor;
danglingLineResources.forEach(danglingLineResource -> weightedSensitivityVariables.add(new WeightedSensitivityVariable(danglingLineResource.getDanglingLineId(network),
glskShiftKey.getQuantity().floatValue() * (float) danglingLineResource.getParticipationFactor() / (float) finalTotalFactor)));
}
}
Loading