Skip to content

Commit

Permalink
Merge branch 'xiidm_version_1_11' into write-properties-for-calculate…
Browse files Browse the repository at this point in the history
…d-buses
  • Loading branch information
olperr1 committed Jul 18, 2023
2 parents f0d3f58 + bba935d commit 1023117
Show file tree
Hide file tree
Showing 24 changed files with 1,119 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ public void export(Network network, Properties params, DataSource ds, Reporter r
context.getTpModelDescription().setModelingAuthoritySet(Parameter.readString(getFormat(), params, MODELING_AUTHORITY_SET_PARAMETER, defaultValueConfig));
context.getSshModelDescription().setModelingAuthoritySet(Parameter.readString(getFormat(), params, MODELING_AUTHORITY_SET_PARAMETER, defaultValueConfig));
context.getSvModelDescription().setModelingAuthoritySet(Parameter.readString(getFormat(), params, MODELING_AUTHORITY_SET_PARAMETER, defaultValueConfig));
String modelDescription = Parameter.readString(getFormat(), params, MODEL_DESCRIPTION_PARAMETER, defaultValueConfig);
if (modelDescription != null) {
context.getEqModelDescription().setDescription(modelDescription);
context.getTpModelDescription().setDescription(modelDescription);
context.getSshModelDescription().setDescription(modelDescription);
context.getSvModelDescription().setDescription(modelDescription);
}
String cimVersionParam = Parameter.readString(getFormat(), params, CIM_VERSION_PARAMETER, defaultValueConfig);
if (cimVersionParam != null) {
context.setCimVersion(Integer.parseInt(cimVersionParam));
Expand Down Expand Up @@ -182,6 +189,7 @@ public String getFormat() {
public static final String NAMING_STRATEGY = "iidm.export.cgmes.naming-strategy";
public static final String PROFILES = "iidm.export.cgmes.profiles";
public static final String MODELING_AUTHORITY_SET = "iidm.export.cgmes.modeling-authority-set";
public static final String MODEL_DESCRIPTION = "iidm.export.cgmes.model-description";

private static final Parameter BASE_NAME_PARAMETER = new Parameter(
BASE_NAME,
Expand Down Expand Up @@ -238,6 +246,12 @@ public String getFormat() {
"Modeling authority set",
"powsybl.org");

private static final Parameter MODEL_DESCRIPTION_PARAMETER = new Parameter(
MODEL_DESCRIPTION,
ParameterType.STRING,
"Model description",
null);

private static final List<Parameter> STATIC_PARAMETERS = List.of(
BASE_NAME_PARAMETER,
CIM_VERSION_PARAMETER,
Expand All @@ -247,7 +261,8 @@ public String getFormat() {
PROFILES_PARAMETER,
BOUNDARY_EQ_ID_PARAMETER,
BOUNDARY_TP_ID_PARAMETER,
MODELING_AUTHORITY_SET_PARAMETER);
MODELING_AUTHORITY_SET_PARAMETER,
MODEL_DESCRIPTION_PARAMETER);

private static final Logger LOG = LoggerFactory.getLogger(CgmesExport.class);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class CgmesExportContextTest {
void testExporter() {
var exporter = new CgmesExport();
assertEquals("ENTSO-E CGMES version 2.4.15", exporter.getComment());
assertEquals(9, exporter.getParameters().size());
assertEquals(10, exporter.getParameters().size());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.powsybl.cgmes.conversion.CgmesExport;
import com.powsybl.cgmes.conversion.Conversion;
import com.powsybl.cgmes.conversion.export.CgmesExportUtil;
import com.powsybl.cgmes.extensions.CgmesSshMetadata;
import com.powsybl.cgmes.model.CgmesModel;
import com.powsybl.cgmes.model.CgmesModelFactory;
import com.powsybl.cgmes.model.CgmesNames;
Expand All @@ -22,9 +23,11 @@
import com.powsybl.commons.datasource.GenericReadOnlyDataSource;
import com.powsybl.commons.datasource.ReadOnlyDataSource;
import com.powsybl.commons.datasource.ResourceSet;
import com.powsybl.commons.datasource.ZipFileDataSource;
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.test.BatteryNetworkFactory;
import com.powsybl.iidm.network.test.DanglingLineNetworkFactory;
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
import com.powsybl.iidm.network.test.FictitiousSwitchFactory;
import com.powsybl.iidm.network.util.Networks;
import com.powsybl.triplestore.api.TripleStoreFactory;
Expand All @@ -36,7 +39,10 @@
import javax.xml.stream.XMLStreamReader;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.*;
import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.List;
import java.util.Properties;

Expand Down Expand Up @@ -457,6 +463,48 @@ void testLineContainersNotInBoundaries() throws IOException {
}
}

@Test
void testModelDescription() throws IOException {
Network network = EurostagTutorialExample1Factory.create();

String modelDescription = "powsybl community";
Properties params = new Properties();
params.put(CgmesExport.MODEL_DESCRIPTION, modelDescription);

try (FileSystem fileSystem = Jimfs.newFileSystem(Configuration.unix())) {
Path tmpDir = Files.createDirectory(fileSystem.getPath("tmp"));
ZipFileDataSource zip = new ZipFileDataSource(tmpDir.resolve("."), "output");
new CgmesExport().export(network, params, zip);
Network network2 = Network.read(tmpDir.resolve("output.zip"));
CgmesSshMetadata sshMetadata = network2.getExtension(CgmesSshMetadata.class);
assertEquals(modelDescription, sshMetadata.getDescription());
}
}

@Test
void testModelDescriptionClosingXML() throws IOException {
Network network = EurostagTutorialExample1Factory.create();

// Security test
// Checking that putting end-tag does not corrupt the file
String modelDescription = "powsybl community</md:Model.modelingAuthoritySet></md:FullModel>";
Properties params = new Properties();
params.put(CgmesExport.MODEL_DESCRIPTION, modelDescription);

try (FileSystem fileSystem = Jimfs.newFileSystem(Configuration.unix())) {
Path tmpDir = Files.createDirectory(fileSystem.getPath("tmp"));
ZipFileDataSource zip = new ZipFileDataSource(tmpDir.resolve("."), "output");
new CgmesExport().export(network, params, zip);

// check network can be reimported and that ModelDescription still includes end-tag
Network network2 = Network.read(tmpDir.resolve("output.zip"));

CgmesSshMetadata sshMetadata = network2.getExtension(CgmesSshMetadata.class);
assertEquals(modelDescription, sshMetadata.getDescription());
}

}

private static void checkDanglingLineParams(DanglingLine expected, DanglingLine actual) {
assertEquals(expected.getR(), actual.getR(), EPSILON);
assertEquals(expected.getX(), actual.getX(), EPSILON);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,10 @@ default IdentifiableType getType() {

void remove();

/**
* Remove the tie line with an update of underlying dangling lines to reflect the tie line flows.
*/
void remove(boolean updateDanglingLines);

Network getNetwork();
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,19 @@ public double getB2() {

@Override
public void remove() {
remove(false);
}

@Override
public void remove(boolean updateDanglingLines) {
NetworkImpl network = getNetwork();
network.getListeners().notifyBeforeRemoval(this);

if (updateDanglingLines) {
updateDanglingLine(danglingLine1);
updateDanglingLine(danglingLine2);
}

// Remove dangling lines
danglingLine1.removeTieLine();
danglingLine2.removeTieLine();
Expand Down Expand Up @@ -363,4 +373,22 @@ public Branch.Overload checkTemporaryLimits2(LimitType type) {
public double getValueForLimit(Terminal t, LimitType type) {
return BranchUtil.getValueForLimit(t, type);
}

private static void updateDanglingLine(DanglingLine danglingLine) {
// Only update if we have values
if (!Double.isNaN(danglingLine.getBoundary().getP())) {
danglingLine.setP0(-danglingLine.getBoundary().getP());
if (danglingLine.getGeneration() != null) {
// We do not reset regulation if we only have computed a dc load flow
danglingLine.getGeneration().setTargetP(0.0);
}
}
if (!Double.isNaN(danglingLine.getBoundary().getQ())) {
danglingLine.setQ0(-danglingLine.getBoundary().getQ());
if (danglingLine.getGeneration() != null) {
// If q values are available a complete ac load flow has been computed, we reset regulation
danglingLine.getGeneration().setTargetQ(0.0).setVoltageRegulationOn(false).setTargetV(Double.NaN);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/**
* Copyright (c) 2023, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.iidm.modification;

import com.powsybl.commons.reporter.Reporter;
import com.powsybl.computation.ComputationManager;
import com.powsybl.iidm.network.Network;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Objects;
import java.util.OptionalDouble;

/**
* Simple {@link NetworkModification} for elements that needs to modify
* their voltage and reactive setpoints. This is used for SVCs and for VSC
* converter stations. Note that a VSC converter station follows a generator
* convention but SVCs follow a load convention.
*
* @author Nicolas PIERRE <nicolas.pierre at artelys.com>
*/
public abstract class AbstractSetpointModification<T> extends AbstractNetworkModification {
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractSetpointModification.class);

private final String elementId;
private final Double voltageSetpoint;
private final Double reactivePowerSetpoint;

protected AbstractSetpointModification(String elementId, Double voltageSetpoint, Double reactivePowerSetpoint) {
if (voltageSetpoint == null && reactivePowerSetpoint == null) {
LOGGER.warn("Creating a {} modification with no modification", getElementName());
}
this.elementId = Objects.requireNonNull(elementId);
this.voltageSetpoint = voltageSetpoint;
this.reactivePowerSetpoint = reactivePowerSetpoint;
}

@Override
public void apply(Network network, boolean throwException, ComputationManager computationManager,
Reporter reporter) {
T networkElement = getNetworkElement(network, elementId);

if (networkElement == null) {
logOrThrow(throwException, getElementName() + " '" + elementId + "' not found");
return;
}
if (voltageSetpoint != null) {
setVoltageSetpoint(networkElement, voltageSetpoint);
}
if (reactivePowerSetpoint != null) {
setReactivePowerSetpoint(networkElement, reactivePowerSetpoint);
}
}

public abstract String getElementName();

protected abstract void setVoltageSetpoint(T networkElement, Double voltageSetpoint);

protected abstract void setReactivePowerSetpoint(T networkElement, Double reactivePowerSetpoint);

public abstract T getNetworkElement(Network network, String elementID);

protected String getElementId() {
return elementId;
}

public Double getReactivePowerSetpoint() {
return reactivePowerSetpoint;
}

public OptionalDouble getOptionalReactivePowerSetpoint() {
return reactivePowerSetpoint == null ? OptionalDouble.empty() : OptionalDouble.of(reactivePowerSetpoint);
}

public Double getVoltageSetpoint() {
return voltageSetpoint;
}

public OptionalDouble getOptionalVoltageSetpoint() {
return voltageSetpoint == null ? OptionalDouble.empty() : OptionalDouble.of(voltageSetpoint);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* Copyright (c) 2023, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.iidm.modification;

import com.powsybl.commons.reporter.Reporter;
import com.powsybl.computation.ComputationManager;
import com.powsybl.iidm.network.Battery;
import com.powsybl.iidm.network.Network;

import java.util.Objects;

/**
* Simple {@link NetworkModification} for a battery.
*
* @author Nicolas PIERRE <nicolas.pierre at artelys.com>
*/
public class BatteryModification extends AbstractNetworkModification {

private final String batteryId;
private final Double targetQ;
private final Double targetP;

public BatteryModification(String batteryId, Double targetP, Double targetQ) {
this.batteryId = Objects.requireNonNull(batteryId);
this.targetP = targetP;
this.targetQ = targetQ;
}

@Override
public void apply(Network network, boolean throwException, ComputationManager computationManager,
Reporter reporter) {
Battery battery = network.getBattery(batteryId);
if (battery == null) {
logOrThrow(throwException, "Battery '" + batteryId + "' not found");
return;
}
if (targetP != null) {
battery.setTargetP(targetP);
}
if (targetQ != null) {
battery.setTargetQ(targetQ);
}
}

public String getBatteryId() {
return batteryId;
}

public Double getTargetP() {
return targetP;
}

public Double getTargetQ() {
return targetQ;
}
}
Loading

0 comments on commit 1023117

Please sign in to comment.