diff --git a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/elements/EnergyConsumerConversion.java b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/elements/EnergyConsumerConversion.java index 72c656963ff..dcb265f057b 100644 --- a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/elements/EnergyConsumerConversion.java +++ b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/elements/EnergyConsumerConversion.java @@ -26,9 +26,6 @@ */ public class EnergyConsumerConversion extends AbstractConductingEquipmentConversion { - private static final String P_FIXED = "pFixed"; - private static final String Q_FIXED = "qFixed"; - public EnergyConsumerConversion(PropertyBag ec, Context context) { super(CgmesNames.ENERGY_CONSUMER, ec, context); loadKind = ec.getLocal("type"); @@ -44,8 +41,8 @@ public void convert() { } else { loadType = LoadType.UNDEFINED; } - double pFixed = p.asDouble(P_FIXED, 0.0); - double qFixed = p.asDouble(Q_FIXED, 0.0); + double pFixed = p.asDouble(CgmesNames.P_FIXED, 0.0); + double qFixed = p.asDouble(CgmesNames.Q_FIXED, 0.0); LoadAdder adder = voltageLevel().newLoad() .setLoadType(loadType); identify(adder); @@ -61,8 +58,8 @@ public void convert() { private void addSpecificProperties(Load newLoad, double pFixed, double qFixed) { newLoad.setProperty(Conversion.PROPERTY_CGMES_ORIGINAL_CLASS, loadKind); - newLoad.setProperty(Conversion.CGMES_PREFIX_ALIAS_PROPERTIES + P_FIXED, String.valueOf(pFixed)); - newLoad.setProperty(Conversion.CGMES_PREFIX_ALIAS_PROPERTIES + Q_FIXED, String.valueOf(qFixed)); + newLoad.setProperty(Conversion.CGMES_PREFIX_ALIAS_PROPERTIES + CgmesNames.P_FIXED, String.valueOf(pFixed)); + newLoad.setProperty(Conversion.CGMES_PREFIX_ALIAS_PROPERTIES + CgmesNames.Q_FIXED, String.valueOf(qFixed)); } private void model(LoadAdder adder) { @@ -145,8 +142,8 @@ private static void setLoadDetail(String type, Load newLoad, double pFixed, doub public static void update(Load load, PropertyBag cgmesData, Context context) { updateTerminals(load, context, load.getTerminal()); - double pFixed = Double.parseDouble(load.getProperty(Conversion.CGMES_PREFIX_ALIAS_PROPERTIES + P_FIXED)); - double qFixed = Double.parseDouble(load.getProperty(Conversion.CGMES_PREFIX_ALIAS_PROPERTIES + Q_FIXED)); + double pFixed = Double.parseDouble(load.getProperty(Conversion.CGMES_PREFIX_ALIAS_PROPERTIES + CgmesNames.P_FIXED)); + double qFixed = Double.parseDouble(load.getProperty(Conversion.CGMES_PREFIX_ALIAS_PROPERTIES + CgmesNames.Q_FIXED)); PowerFlow updatedPowerFlow = updatedPowerFlow(load, cgmesData, context); load.setP0(updatedPowerFlow.defined() ? updatedPowerFlow.p() : defaultValue(pFixed, load.getP0(), 0.0, Double.NaN, getDefaultValueSelector(context))); diff --git a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/LoadUpdateTest.java b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/LoadUpdateTest.java index 4dfcec64ea2..8764cff19dd 100644 --- a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/LoadUpdateTest.java +++ b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/LoadUpdateTest.java @@ -7,6 +7,8 @@ */ package com.powsybl.cgmes.conversion.test; +import com.powsybl.cgmes.conversion.Conversion; +import com.powsybl.cgmes.model.CgmesNames; import com.powsybl.iidm.network.Load; import com.powsybl.iidm.network.Network; import org.junit.jupiter.api.Test; @@ -28,13 +30,13 @@ void importEqTest() { assertEquals(3, network.getLoadCount()); Load loadEnergyConsumer = network.getLoad("EnergyConsumer"); - assertTrue(checkNaNLoad(loadEnergyConsumer)); + assertTrue(checkEq(loadEnergyConsumer)); Load loadEnergySource = network.getLoad("EnergySource"); - assertTrue(checkNaNLoad(loadEnergySource)); + assertTrue(checkEq(loadEnergySource)); Load loadAsynchronousMachine = network.getLoad("AsynchronousMachine"); - assertTrue(checkNaNLoad(loadAsynchronousMachine)); + assertTrue(checkEq(loadAsynchronousMachine)); } @Test @@ -43,67 +45,73 @@ void importEqAndSshTogetherTest() { assertEquals(3, network.getLoadCount()); Load loadEnergyConsumer = network.getLoad("EnergyConsumer"); - assertTrue(checkLoad(loadEnergyConsumer, 10.0, 5.0)); + assertTrue(checkSsh(loadEnergyConsumer, 10.0, 5.0)); Load loadEnergySource = network.getLoad("EnergySource"); - assertTrue(checkLoad(loadEnergySource, -200.0, -90.0)); + assertTrue(checkSsh(loadEnergySource, -200.0, -90.0)); Load loadAsynchronousMachine = network.getLoad("AsynchronousMachine"); - assertTrue(checkLoad(loadAsynchronousMachine, 200.0, 50.0)); + assertTrue(checkSsh(loadAsynchronousMachine, 200.0, 50.0)); } @Test - void importEAndSshSeparatelyTest() { + void importEqAndSshSeparatelyTest() { Network network = readCgmesResources(DIR, "load_EQ.xml"); assertEquals(3, network.getLoadCount()); Load loadEnergyConsumer = network.getLoad("EnergyConsumer"); - assertTrue(checkNaNLoad(loadEnergyConsumer)); + assertTrue(checkEq(loadEnergyConsumer)); Load loadEnergySource = network.getLoad("EnergySource"); - assertTrue(checkNaNLoad(loadEnergySource)); + assertTrue(checkEq(loadEnergySource)); Load loadAsynchronousMachine = network.getLoad("AsynchronousMachine"); - assertTrue(checkNaNLoad(loadAsynchronousMachine)); + assertTrue(checkEq(loadAsynchronousMachine)); readCgmesResources(network, DIR, "load_SSH.xml"); - assertTrue(checkLoad(loadEnergyConsumer, 10.0, 5.0)); - assertTrue(checkLoad(loadEnergySource, -200.0, -90.0)); - assertTrue(checkLoad(loadAsynchronousMachine, 200.0, 50.0)); + assertTrue(checkSsh(loadEnergyConsumer, 10.0, 5.0)); + assertTrue(checkSsh(loadEnergySource, -200.0, -90.0)); + assertTrue(checkSsh(loadAsynchronousMachine, 200.0, 50.0)); } @Test - void importEAndTwoSshsTest() { + void importEqAndTwoSshsTest() { Network network = readCgmesResources(DIR, "load_EQ.xml"); assertEquals(3, network.getLoadCount()); Load loadEnergyConsumer = network.getLoad("EnergyConsumer"); - assertTrue(checkNaNLoad(loadEnergyConsumer)); + assertTrue(checkEq(loadEnergyConsumer)); Load loadEnergySource = network.getLoad("EnergySource"); - assertTrue(checkNaNLoad(loadEnergySource)); + assertTrue(checkEq(loadEnergySource)); Load loadAsynchronousMachine = network.getLoad("AsynchronousMachine"); - assertTrue(checkNaNLoad(loadAsynchronousMachine)); + assertTrue(checkEq(loadAsynchronousMachine)); readCgmesResources(network, DIR, "load_SSH.xml"); - assertTrue(checkLoad(loadEnergyConsumer, 10.0, 5.0)); - assertTrue(checkLoad(loadEnergySource, -200.0, -90.0)); - assertTrue(checkLoad(loadAsynchronousMachine, 200.0, 50.0)); + assertTrue(checkSsh(loadEnergyConsumer, 10.0, 5.0)); + assertTrue(checkSsh(loadEnergySource, -200.0, -90.0)); + assertTrue(checkSsh(loadAsynchronousMachine, 200.0, 50.0)); readCgmesResources(network, DIR, "load_SSH_1.xml"); - assertTrue(checkLoad(loadEnergyConsumer, 10.5, 5.5)); - assertTrue(checkLoad(loadEnergySource, -200.5, -90.5)); - assertTrue(checkLoad(loadAsynchronousMachine, 200.5, 50.5)); + assertTrue(checkSsh(loadEnergyConsumer, 10.5, 5.5)); + assertTrue(checkSsh(loadEnergySource, -200.5, -90.5)); + assertTrue(checkSsh(loadAsynchronousMachine, 200.5, 50.5)); } - private static boolean checkNaNLoad(Load load) { + private static boolean checkEq(Load load) { assertNotNull(load); assertTrue(Double.isNaN(load.getP0())); assertTrue(Double.isNaN(load.getQ0())); + String originalClass = load.getProperty(Conversion.PROPERTY_CGMES_ORIGINAL_CLASS); + if (originalClass.equals(CgmesNames.ENERGY_CONSUMER)) { + assertNotNull(load.getProperty(Conversion.CGMES_PREFIX_ALIAS_PROPERTIES + CgmesNames.P_FIXED)); + assertNotNull(load.getProperty(Conversion.CGMES_PREFIX_ALIAS_PROPERTIES + CgmesNames.Q_FIXED)); + } + load.getPropertyNames().forEach(pn -> System.err.printf("Property %s %s %n", pn, load.getProperty(pn))); return true; } - private static boolean checkLoad(Load load, double p0, double q0) { + private static boolean checkSsh(Load load, double p0, double q0) { assertNotNull(load); assertEquals(p0, load.getP0()); assertEquals(q0, load.getQ0()); diff --git a/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/CgmesNames.java b/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/CgmesNames.java index af5b71cdc0a..6c2bc975b70 100644 --- a/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/CgmesNames.java +++ b/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/CgmesNames.java @@ -144,6 +144,8 @@ public final class CgmesNames { public static final String CURRENT_LIMIT = "CurrentLimit"; public static final String ACTIVE_POWER_LIMIT = "ActivePowerLimit"; public static final String APPARENT_POWER_LIMIT = "ApparentPowerLimit"; + public static final String P_FIXED = "pFixed"; + public static final String Q_FIXED = "qFixed"; private CgmesNames() { }