Skip to content

Commit

Permalink
CGMES import: active power control extension is optional (#2462)
Browse files Browse the repository at this point in the history
Signed-off-by: Anne Tilloy <anne.tilloy@rte-france.com>
Co-authored-by: Luma <zamarrenolm@aia.es>
  • Loading branch information
2 people authored and miovd committed Feb 2, 2023
1 parent 78af3a9 commit 7bc1440
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,12 @@ private Conversion.Config config(ReadOnlyDataSource ds, Properties p) {
getFormat(),
p,
STORE_CGMES_CONVERSION_CONTEXT_AS_NETWORK_EXTENSION_PARAMETER,
defaultValueConfig))
.setCreateActivePowerControlExtension(
Parameter.readBoolean(
getFormat(),
p,
CREATE_ACTIVE_POWER_CONTROL_EXTENSION_PARAMETER,
defaultValueConfig));
String namingStrategy = Parameter.readString(getFormat(), p, ID_MAPPING_FILE_NAMING_STRATEGY_PARAMETER, defaultValueConfig);
String idMappingFilePath = Parameter.readString(getFormat(), p, ID_MAPPING_FILE_PATH_PARAMETER, defaultValueConfig);
Expand Down Expand Up @@ -298,6 +304,7 @@ private void copyStream(ReadOnlyDataSource from, DataSource to, String fromName,
public static final String SOURCE_FOR_IIDM_ID = "iidm.import.cgmes.source-for-iidm-id";
public static final String STORE_CGMES_MODEL_AS_NETWORK_EXTENSION = "iidm.import.cgmes.store-cgmes-model-as-network-extension";
public static final String STORE_CGMES_CONVERSION_CONTEXT_AS_NETWORK_EXTENSION = "iidm.import.cgmes.store-cgmes-conversion-context-as-network-extension";
public static final String CREATE_ACTIVE_POWER_CONTROL_EXTENSION = "iidm.import.cgmes.create-active-power-control-extension";

public static final String SOURCE_FOR_IIDM_ID_MRID = "mRID";
public static final String SOURCE_FOR_IIDM_ID_RDFID = "rdfID";
Expand Down Expand Up @@ -377,6 +384,11 @@ private void copyStream(ReadOnlyDataSource from, DataSource to, String fromName,
ParameterType.BOOLEAN,
"Store the CGMES-IIDM terminal mapping as a network extension",
Boolean.FALSE);
private static final Parameter CREATE_ACTIVE_POWER_CONTROL_EXTENSION_PARAMETER = new Parameter(
CREATE_ACTIVE_POWER_CONTROL_EXTENSION,
ParameterType.BOOLEAN,
"Create active power control extension during import",
Boolean.FALSE);
private static final Parameter STORE_CGMES_MODEL_AS_NETWORK_EXTENSION_PARAMETER = new Parameter(
STORE_CGMES_MODEL_AS_NETWORK_EXTENSION,
ParameterType.BOOLEAN,
Expand Down Expand Up @@ -405,7 +417,8 @@ private void copyStream(ReadOnlyDataSource from, DataSource to, String fromName,
PROFILE_FOR_INITIAL_VALUES_SHUNT_SECTIONS_TAP_POSITIONS_PARAMETER,
SOURCE_FOR_IIDM_ID_PARAMETER,
STORE_CGMES_CONVERSION_CONTEXT_AS_NETWORK_EXTENSION_PARAMETER,
STORE_CGMES_MODEL_AS_NETWORK_EXTENSION_PARAMETER);
STORE_CGMES_MODEL_AS_NETWORK_EXTENSION_PARAMETER,
CREATE_ACTIVE_POWER_CONTROL_EXTENSION_PARAMETER);

private final Parameter boundaryLocationParameter;
private final Parameter postProcessorsParameter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,15 @@ public Config setStoreCgmesConversionContextAsNetworkExtension(boolean storeCgme
return this;
}

public boolean createActivePowerControlExtension() {
return createActivePowerControlExtension;
}

public Config setCreateActivePowerControlExtension(boolean createActivePowerControlExtension) {
this.createActivePowerControlExtension = createActivePowerControlExtension;
return this;
}

public boolean isEnsureIdAliasUnicity() {
return ensureIdAliasUnicity;
}
Expand Down Expand Up @@ -896,6 +905,7 @@ public void setXfmr3StructuralRatio(Xfmr3StructuralRatioInterpretationAlternativ
private StateProfile profileForInitialValuesShuntSectionsTapPositions = SSH;
private boolean storeCgmesModelAsNetworkExtension = true;
private boolean storeCgmesConversionContextAsNetworkExtension = false;
private boolean createActivePowerControlExtension = false;

private boolean ensureIdAliasUnicity = false;
private boolean importControlAreas = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,14 @@ public void convert() {
}
double normalPF = p.asDouble("normalPF");
if (!Double.isNaN(normalPF)) {
g.newExtension(ActivePowerControlAdder.class)
.withParticipate(normalPF != 0.0)
.withParticipationFactor(normalPF)
.add();
if (context.config().createActivePowerControlExtension()) {
g.newExtension(ActivePowerControlAdder.class)
.withParticipate(true)
.withParticipationFactor(normalPF)
.add();
} else {
g.setProperty(Conversion.CGMES_PREFIX_ALIAS_PROPERTIES + "normalPF", String.valueOf(normalPF));
}
}
String generatingUnit = p.getId("GeneratingUnit");
if (generatingUnit != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -648,10 +648,14 @@ private static void writeGeneratingUnitsParticitationFactors(Network network, St
}

private static GeneratingUnit generatingUnitForGenerator(Generator g, CgmesExportContext context) {
if (g.hasProperty(GENERATING_UNIT_PROPERTY) && (g.getExtension(ActivePowerControl.class) != null)) {
if (g.hasProperty(GENERATING_UNIT_PROPERTY) && ((g.getExtension(ActivePowerControl.class) != null) || g.hasProperty(Conversion.CGMES_PREFIX_ALIAS_PROPERTIES + "normalPF"))) {
GeneratingUnit gu = new GeneratingUnit();
gu.id = context.getNamingStrategy().getCgmesIdFromProperty(g, GENERATING_UNIT_PROPERTY);
gu.participationFactor = g.getExtension(ActivePowerControl.class).getParticipationFactor();
if (g.getExtension(ActivePowerControl.class) != null) {
gu.participationFactor = g.getExtension(ActivePowerControl.class).getParticipationFactor();
} else {
gu.participationFactor = Double.valueOf(g.getProperty(Conversion.CGMES_PREFIX_ALIAS_PROPERTIES + "normalPF"));
}
gu.className = generatingUnitClassname(g);
return gu;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.powsybl.cgmes.conversion.test.ConversionTester;
import com.powsybl.cgmes.conversion.test.network.compare.ComparisonConfig;
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.extensions.ActivePowerControl;
import com.powsybl.triplestore.api.TripleStoreFactory;
import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -289,6 +290,27 @@ public void smallNodeBreakerHvdcOnlyEQ() {
assertNotNull(new CgmesImport().importData(CgmesConformity1Catalog.smallNodeBreakerHvdcOnlyEQ().dataSource(), NetworkFactory.findDefault(), null));
}

@Test
public void microNLActivePowerControlNoExtensionByDefault() {
Network network = new CgmesImport().importData(CgmesConformity1Catalog.microGridBaseCaseNL().dataSource(), NetworkFactory.findDefault(), null);
Generator g = network.getGenerator("9c3b8f97-7972-477d-9dc8-87365cc0ad0e");
ActivePowerControl<Generator> ext = g.getExtension(ActivePowerControl.class);
assertNull(ext);
}

@Test
public void microNLActivePowerControlExtension() {
Properties importParams = new Properties();
importParams.put(CgmesImport.CREATE_ACTIVE_POWER_CONTROL_EXTENSION, "true");
Network network = new CgmesImport().importData(CgmesConformity1Catalog.microGridBaseCaseNL().dataSource(), NetworkFactory.findDefault(), importParams);
Generator g = network.getGenerator("9c3b8f97-7972-477d-9dc8-87365cc0ad0e");
ActivePowerControl<Generator> ext = g.getExtension(ActivePowerControl.class);
assertNotNull(ext);
assertTrue(Double.isNaN(ext.getDroop()));
assertEquals(1.0, ext.getParticipationFactor(), 0.0);
assertTrue(ext.isParticipate());
}

private static class TxData {
TxData(int numEnds, int rtc1, int ptc1, int rtc2, int ptc2) {
this.numEnds = numEnds;
Expand Down

0 comments on commit 7bc1440

Please sign in to comment.