Skip to content

Commit

Permalink
Refactor RegulatingCondEq RegulatingControl EQ export (#2920).
Browse files Browse the repository at this point in the history
Signed-off-by: stojkovicn <nemanja.stojkovic@rte-france.com>
  • Loading branch information
stojkovicn committed May 10, 2024
1 parent f8ef9c6 commit fd91efc
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.powsybl.commons.exceptions.UncheckedXmlStreamException;
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.Identifiable;
import com.powsybl.iidm.network.extensions.RemoteReactivePowerControl;
import com.powsybl.iidm.network.extensions.VoltagePerReactivePowerControl;

import org.apache.commons.lang3.tuple.Pair;
Expand Down Expand Up @@ -365,7 +366,15 @@ private static void writeGenerators(Network network, Map<Terminal, String> mapTe
Set<String> generatingUnitsWritten = new HashSet<>();
for (Generator generator : network.getGenerators()) {
String cgmesOriginalClass = generator.getProperty(Conversion.PROPERTY_CGMES_ORIGINAL_CLASS, CgmesNames.SYNCHRONOUS_MACHINE);

Terminal regulatingTerminal = generator.getRegulatingTerminal();
String mode = RegulatingControlEq.REGULATING_CONTROL_VOLTAGE;

// Not possible to re-export local reactive power control.
RemoteReactivePowerControl rrpc = generator.getExtension(RemoteReactivePowerControl.class);
if (rrpc != null) {
regulatingTerminal = rrpc.getRegulatingTerminal();
mode = RegulatingControlEq.REGULATING_CONTROL_REACTIVE_POWER;
}
switch (cgmesOriginalClass) {
case CgmesNames.EQUIVALENT_INJECTION:
String reactiveCapabilityCurveId = writeReactiveCapabilityCurve(generator, cimNamespace, writer, context);
Expand All @@ -375,14 +384,14 @@ private static void writeGenerators(Network network, Map<Terminal, String> mapTe
cimNamespace, writer, context);
break;
case CgmesNames.EXTERNAL_NETWORK_INJECTION:
String regulatingControlId = RegulatingControlEq.writeKindVoltage(generator, exportedTerminalId(mapTerminal2Id, generator.getRegulatingTerminal()), regulatingControlsWritten, cimNamespace, writer, context);
String regulatingControlId = RegulatingControlEq.writeRegulatingControlEq(generator, exportedTerminalId(mapTerminal2Id, regulatingTerminal), regulatingControlsWritten, mode, cimNamespace, writer, context);
ExternalNetworkInjectionEq.write(context.getNamingStrategy().getCgmesId(generator), generator.getNameOrId(),
context.getNamingStrategy().getCgmesId(generator.getTerminal().getVoltageLevel()),
obtainGeneratorGovernorScd(generator), generator.getMaxP(), obtainMaxQ(generator), generator.getMinP(), obtainMinQ(generator),
regulatingControlId, cimNamespace, writer, context);
break;
case CgmesNames.SYNCHRONOUS_MACHINE:
regulatingControlId = RegulatingControlEq.writeKindVoltage(generator, exportedTerminalId(mapTerminal2Id, generator.getRegulatingTerminal()), regulatingControlsWritten, cimNamespace, writer, context);
regulatingControlId = RegulatingControlEq.writeRegulatingControlEq(generator, exportedTerminalId(mapTerminal2Id, regulatingTerminal), regulatingControlsWritten, mode, cimNamespace, writer, context);
writeSynchronousMachine(generator, cimNamespace, writeInitialP,
generator.getMinP(), generator.getMaxP(), generator.getTargetP(), generator.getRatedS(), generator.getEnergySource(),
regulatingControlId, writer, context, generatingUnitsWritten);
Expand Down Expand Up @@ -556,13 +565,15 @@ private static void writeShuntCompensators(Network network, Map<Terminal, String
context.getNamingStrategy().getCgmesId(s.getTerminal().getVoltageLevel()),
cimNamespace, writer, context);
} else {
// Shunt can only regulate voltage
String mode = RegulatingControlEq.REGULATING_CONTROL_VOLTAGE;
double bPerSection = 0.0;
double gPerSection = Double.NaN;
if (s.getModelType().equals(ShuntCompensatorModelType.LINEAR)) {
bPerSection = ((ShuntCompensatorLinearModel) s.getModel()).getBPerSection();
gPerSection = ((ShuntCompensatorLinearModel) s.getModel()).getGPerSection();
}
String regulatingControlId = RegulatingControlEq.writeKindVoltage(s, exportedTerminalId(mapTerminal2Id, s.getRegulatingTerminal()), regulatingControlsWritten, cimNamespace, writer, context);
String regulatingControlId = RegulatingControlEq.writeRegulatingControlEq(s, exportedTerminalId(mapTerminal2Id, s.getRegulatingTerminal()), regulatingControlsWritten, mode, cimNamespace, writer, context);
ShuntCompensatorEq.write(context.getNamingStrategy().getCgmesId(s), s.getNameOrId(), s.getSectionCount(), s.getMaximumSectionCount(), s.getTerminal().getVoltageLevel().getNominalV(), s.getModelType(), bPerSection, gPerSection, regulatingControlId,
context.getNamingStrategy().getCgmesId(s.getTerminal().getVoltageLevel()), cimNamespace, writer, context);
if (s.getModelType().equals(ShuntCompensatorModelType.NON_LINEAR)) {
Expand All @@ -582,13 +593,35 @@ private static void writeShuntCompensators(Network network, Map<Terminal, String
private static void writeStaticVarCompensators(Network network, Map<Terminal, String> mapTerminal2Id, Set<String> regulatingControlsWritten, String cimNamespace,
XMLStreamWriter writer, CgmesExportContext context) throws XMLStreamException {
for (StaticVarCompensator svc : network.getStaticVarCompensators()) {
String regulatingControlId = RegulatingControlEq.writeKindVoltage(svc, exportedTerminalId(mapTerminal2Id, svc.getRegulatingTerminal()), regulatingControlsWritten, cimNamespace, writer, context);
String mode = getSvcMode(svc);
String regulatingControlId = RegulatingControlEq.writeRegulatingControlEq(svc, exportedTerminalId(mapTerminal2Id, svc.getRegulatingTerminal()), regulatingControlsWritten, mode, cimNamespace, writer, context);
double inductiveRating = svc.getBmin() != 0 ? 1 / svc.getBmin() : 0;
double capacitiveRating = svc.getBmax() != 0 ? 1 / svc.getBmax() : 0;
StaticVarCompensatorEq.write(context.getNamingStrategy().getCgmesId(svc), svc.getNameOrId(), context.getNamingStrategy().getCgmesId(svc.getTerminal().getVoltageLevel()), regulatingControlId, inductiveRating, capacitiveRating, svc.getExtension(VoltagePerReactivePowerControl.class), svc.getRegulationMode(), svc.getVoltageSetpoint(), cimNamespace, writer, context);
}
}

private static String getSvcMode(StaticVarCompensator svc) {
String mode = RegulatingControlEq.REGULATING_CONTROL_VOLTAGE;
StaticVarCompensator.RegulationMode regulationMode = svc.getRegulationMode();
// FIXME: remove RegulationMode.OFF when #2790 is done
if (regulationMode == StaticVarCompensator.RegulationMode.REACTIVE_POWER
|| regulationMode == StaticVarCompensator.RegulationMode.OFF
&& isValidSvcReactivePowerSetpoint(svc.getReactivePowerSetpoint())
&& !isValidSvcVoltageSetpoint(svc.getVoltageSetpoint())) {
mode = RegulatingControlEq.REGULATING_CONTROL_REACTIVE_POWER;
}
return mode;
}

private static boolean isValidSvcVoltageSetpoint(double v) {
return Double.isFinite(v) && v > 0;
}

private static boolean isValidSvcReactivePowerSetpoint(double q) {
return Double.isFinite(q);
}

private static void writeLines(Network network, Map<Terminal, String> mapTerminal2Id, String cimNamespace, String euNamespace, String valueAttributeName, String limitTypeAttributeName, String limitKindClassName, boolean writeInfiniteDuration, XMLStreamWriter writer, CgmesExportContext context) throws XMLStreamException {
for (Line line : network.getLines()) {
String baseVoltage = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,22 @@
public final class RegulatingControlEq {

public static final String REGULATING_CONTROL_VOLTAGE = "RegulatingControlModeKind.voltage";
public static final String REGULATING_CONTROL_REACTIVE_POWER = "RegulatingControlModeKind.reactivePower";

public static String writeKindVoltage(Connectable<?> c, String terminalId, Set<String> regulatingControlsWritten, String cimNamespace, XMLStreamWriter writer, CgmesExportContext context) throws XMLStreamException {
public static String writeRegulatingControlEq(Connectable<?> c, String terminalId, Set<String> regulatingControlsWritten, String mode, String cimNamespace, XMLStreamWriter writer, CgmesExportContext context) throws XMLStreamException {
String regulatingControlId = context.getNamingStrategy().getCgmesIdFromProperty(c, Conversion.CGMES_PREFIX_ALIAS_PROPERTIES + "RegulatingControl");
if (regulatingControlId != null && !regulatingControlsWritten.contains(regulatingControlId)) {
String regulatingControlName = "RC_" + c.getNameOrId();
RegulatingControlEq.writeKindVoltage(regulatingControlId, regulatingControlName, terminalId, cimNamespace, writer, context);
CgmesExportUtil.writeStartIdName("RegulatingControl", regulatingControlId, regulatingControlName, cimNamespace, writer, context);
CgmesExportUtil.writeReference("RegulatingControl.Terminal", terminalId, cimNamespace, writer, context);
writer.writeEmptyElement(cimNamespace, "RegulatingControl.mode");
writer.writeAttribute(RDF_NAMESPACE, CgmesNames.RESOURCE, cimNamespace + mode);
writer.writeEndElement();
regulatingControlsWritten.add(regulatingControlId);
}
return regulatingControlId;
}

private static void writeKindVoltage(String id, String regulatingControlName, String terminalId, String cimNamespace, XMLStreamWriter writer, CgmesExportContext context) throws XMLStreamException {
CgmesExportUtil.writeStartIdName("RegulatingControl", id, regulatingControlName, cimNamespace, writer, context);
CgmesExportUtil.writeReference("RegulatingControl.Terminal", terminalId, cimNamespace, writer, context);
writer.writeEmptyElement(cimNamespace, "RegulatingControl.mode");
writer.writeAttribute(RDF_NAMESPACE, CgmesNames.RESOURCE, cimNamespace + REGULATING_CONTROL_VOLTAGE);
writer.writeEndElement();
}

private RegulatingControlEq() {
}
}

0 comments on commit fd91efc

Please sign in to comment.