From 8babc95c2d0d6179365920b7935edb8295b7d6db Mon Sep 17 00:00:00 2001 From: marqueslanauja <51124986+marqueslanauja@users.noreply.github.com> Date: Wed, 22 May 2024 09:49:09 +0200 Subject: [PATCH] copy of the imported PSSE model to make the updates and export (deep copy) (#2946) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Antonio Marqués --- .../powsybl/psse/converter/BusConverter.java | 18 +++---- .../FixedShuntCompensatorConverter.java | 14 ++--- .../psse/converter/GeneratorConverter.java | 16 +++--- .../powsybl/psse/converter/LineConverter.java | 12 ++--- .../powsybl/psse/converter/LoadConverter.java | 16 +++--- .../powsybl/psse/converter/PsseExporter.java | 41 +++++---------- .../SwitchedShuntCompensatorConverter.java | 16 +++--- .../psse/converter/TransformerConverter.java | 52 +++++++++---------- .../psse/converter/PsseExporterTest.java | 47 +++++++++++++++++ .../com/powsybl/psse/model/pf/PsseBus.java | 18 +++++++ .../powsybl/psse/model/pf/PsseFixedShunt.java | 10 ++++ .../powsybl/psse/model/pf/PsseGenerator.java | 28 ++++++++++ .../com/powsybl/psse/model/pf/PsseLoad.java | 24 +++++++++ .../model/pf/PsseNonTransformerBranch.java | 21 ++++++++ .../psse/model/pf/PssePowerFlowModel.java | 33 ++++++++++++ .../com/powsybl/psse/model/pf/PsseRates.java | 20 +++++++ .../psse/model/pf/PsseSwitchedShunt.java | 42 +++++++++++++++ .../psse/model/pf/PsseTransformer.java | 43 +++++++++++++++ .../psse/model/pf/PsseTransformerWinding.java | 20 +++++++ 19 files changed, 378 insertions(+), 113 deletions(-) diff --git a/psse/psse-converter/src/main/java/com/powsybl/psse/converter/BusConverter.java b/psse/psse-converter/src/main/java/com/powsybl/psse/converter/BusConverter.java index 8f318263ebe..aff238867ca 100644 --- a/psse/psse-converter/src/main/java/com/powsybl/psse/converter/BusConverter.java +++ b/psse/psse-converter/src/main/java/com/powsybl/psse/converter/BusConverter.java @@ -7,7 +7,6 @@ */ package com.powsybl.psse.converter; -import java.util.Collections; import java.util.Objects; import com.powsybl.iidm.network.Bus; @@ -39,20 +38,17 @@ void create(VoltageLevel voltageLevel) { } // At the moment we do not consider new buses - static void updateBuses(Network network, PssePowerFlowModel psseModel, PssePowerFlowModel updatePsseModel) { + static void updateBuses(Network network, PssePowerFlowModel psseModel) { psseModel.getBuses().forEach(psseBus -> { - updatePsseModel.addBuses(Collections.singletonList(psseBus)); - PsseBus updatePsseBus = updatePsseModel.getBuses().get(updatePsseModel.getBuses().size() - 1); - - String busId = AbstractConverter.getBusId(updatePsseBus.getI()); + String busId = AbstractConverter.getBusId(psseBus.getI()); Bus bus = network.getBusBreakerView().getBus(busId); if (bus == null) { - updatePsseBus.setVm(0.0); - updatePsseBus.setVa(0.0); - updatePsseBus.setIde(4); + psseBus.setVm(0.0); + psseBus.setVa(0.0); + psseBus.setIde(4); } else { - updatePsseBus.setVm(bus.getV() / bus.getVoltageLevel().getNominalV()); - updatePsseBus.setVa(bus.getAngle()); + psseBus.setVm(bus.getV() / bus.getVoltageLevel().getNominalV()); + psseBus.setVa(bus.getAngle()); } }); } diff --git a/psse/psse-converter/src/main/java/com/powsybl/psse/converter/FixedShuntCompensatorConverter.java b/psse/psse-converter/src/main/java/com/powsybl/psse/converter/FixedShuntCompensatorConverter.java index 2d29ea5c27c..45e6e035bf6 100644 --- a/psse/psse-converter/src/main/java/com/powsybl/psse/converter/FixedShuntCompensatorConverter.java +++ b/psse/psse-converter/src/main/java/com/powsybl/psse/converter/FixedShuntCompensatorConverter.java @@ -7,7 +7,6 @@ */ package com.powsybl.psse.converter; -import java.util.Collections; import java.util.Objects; import com.powsybl.iidm.network.*; @@ -62,18 +61,15 @@ private static String getShuntId(String busId, String fixedShuntId) { } // At the moment we do not consider new fixedShunts - static void updateFixedShunts(Network network, PssePowerFlowModel psseModel, PssePowerFlowModel updatePsseModel) { + static void updateFixedShunts(Network network, PssePowerFlowModel psseModel) { psseModel.getFixedShunts().forEach(psseFixedShunt -> { - updatePsseModel.addFixedShunts(Collections.singletonList(psseFixedShunt)); - PsseFixedShunt updatePsseFixedShunt = updatePsseModel.getFixedShunts().get(updatePsseModel.getFixedShunts().size() - 1); - - String fixedShuntId = getShuntId(getBusId(updatePsseFixedShunt.getI()), updatePsseFixedShunt.getId()); + String fixedShuntId = getShuntId(getBusId(psseFixedShunt.getI()), psseFixedShunt.getId()); ShuntCompensator fixedShunt = network.getShuntCompensator(fixedShuntId); if (fixedShunt == null) { - updatePsseFixedShunt.setStatus(0); + psseFixedShunt.setStatus(0); } else { - updatePsseFixedShunt.setStatus(getStatus(fixedShunt)); - updatePsseFixedShunt.setBl(getQ(fixedShunt)); + psseFixedShunt.setStatus(getStatus(fixedShunt)); + psseFixedShunt.setBl(getQ(fixedShunt)); } }); } diff --git a/psse/psse-converter/src/main/java/com/powsybl/psse/converter/GeneratorConverter.java b/psse/psse-converter/src/main/java/com/powsybl/psse/converter/GeneratorConverter.java index 74cb1391c88..266a824fff6 100644 --- a/psse/psse-converter/src/main/java/com/powsybl/psse/converter/GeneratorConverter.java +++ b/psse/psse-converter/src/main/java/com/powsybl/psse/converter/GeneratorConverter.java @@ -7,7 +7,6 @@ */ package com.powsybl.psse.converter; -import java.util.Collections; import java.util.Objects; import org.slf4j.Logger; @@ -121,19 +120,16 @@ private static String getGeneratorId(String busId, String generatorId) { } // At the moment we do not consider new generators - static void updateGenerators(Network network, PssePowerFlowModel psseModel, PssePowerFlowModel updatePsseModel) { + static void updateGenerators(Network network, PssePowerFlowModel psseModel) { psseModel.getGenerators().forEach(psseGen -> { - updatePsseModel.addGenerators(Collections.singletonList(psseGen)); - PsseGenerator updatePsseGen = updatePsseModel.getGenerators().get(updatePsseModel.getGenerators().size() - 1); - - String genId = getGeneratorId(getBusId(updatePsseGen.getI()), updatePsseGen.getId()); + String genId = getGeneratorId(getBusId(psseGen.getI()), psseGen.getId()); Generator gen = network.getGenerator(genId); if (gen == null) { - updatePsseGen.setStat(0); + psseGen.setStat(0); } else { - updatePsseGen.setStat(getStatus(gen)); - updatePsseGen.setPg(getP(gen)); - updatePsseGen.setQg(getQ(gen)); + psseGen.setStat(getStatus(gen)); + psseGen.setPg(getP(gen)); + psseGen.setQg(getQ(gen)); } }); } diff --git a/psse/psse-converter/src/main/java/com/powsybl/psse/converter/LineConverter.java b/psse/psse-converter/src/main/java/com/powsybl/psse/converter/LineConverter.java index 96bff3a0327..542b219ae03 100644 --- a/psse/psse-converter/src/main/java/com/powsybl/psse/converter/LineConverter.java +++ b/psse/psse-converter/src/main/java/com/powsybl/psse/converter/LineConverter.java @@ -24,7 +24,6 @@ import static com.powsybl.psse.model.PsseVersion.Major.V35; -import java.util.Collections; import java.util.Objects; /** @@ -119,17 +118,14 @@ private static String getLineId(PsseNonTransformerBranch psseLine) { } // At the moment we do not consider new lines and antenna lines are exported as open - static void updateLines(Network network, PssePowerFlowModel psseModel, PssePowerFlowModel updatePsseModel) { + static void updateLines(Network network, PssePowerFlowModel psseModel) { psseModel.getNonTransformerBranches().forEach(psseLine -> { - updatePsseModel.addNonTransformerBranches(Collections.singletonList(psseLine)); - PsseNonTransformerBranch updatePsseLine = updatePsseModel.getNonTransformerBranches().get(updatePsseModel.getNonTransformerBranches().size() - 1); - - String lineId = getLineId(updatePsseLine); + String lineId = getLineId(psseLine); Line line = network.getLine(lineId); if (line == null) { - updatePsseLine.setSt(0); + psseLine.setSt(0); } else { - updatePsseLine.setSt(getStatus(line)); + psseLine.setSt(getStatus(line)); } }); } diff --git a/psse/psse-converter/src/main/java/com/powsybl/psse/converter/LoadConverter.java b/psse/psse-converter/src/main/java/com/powsybl/psse/converter/LoadConverter.java index 7abac0c7f5a..d4bcc25ab5e 100644 --- a/psse/psse-converter/src/main/java/com/powsybl/psse/converter/LoadConverter.java +++ b/psse/psse-converter/src/main/java/com/powsybl/psse/converter/LoadConverter.java @@ -7,7 +7,6 @@ */ package com.powsybl.psse.converter; -import java.util.Collections; import java.util.Objects; import com.powsybl.iidm.network.Load; @@ -93,19 +92,16 @@ private static String getLoadId(String busId, String loadId) { } // At the moment we do not consider new loads - static void updateLoads(Network network, PssePowerFlowModel psseModel, PssePowerFlowModel updatePsseModel) { + static void updateLoads(Network network, PssePowerFlowModel psseModel) { psseModel.getLoads().forEach(psseLoad -> { - updatePsseModel.addLoads(Collections.singletonList(psseLoad)); - PsseLoad updatePsseLoad = updatePsseModel.getLoads().get(updatePsseModel.getLoads().size() - 1); - - String loadId = getLoadId(getBusId(updatePsseLoad.getI()), updatePsseLoad.getId()); + String loadId = getLoadId(getBusId(psseLoad.getI()), psseLoad.getId()); Load load = network.getLoad(loadId); if (load == null) { - updatePsseLoad.setStatus(0); + psseLoad.setStatus(0); } else { - updatePsseLoad.setStatus(getStatus(load)); - updatePsseLoad.setPl(getP(load)); - updatePsseLoad.setQl(getQ(load)); + psseLoad.setStatus(getStatus(load)); + psseLoad.setPl(getP(load)); + psseLoad.setQl(getQ(load)); } }); } diff --git a/psse/psse-converter/src/main/java/com/powsybl/psse/converter/PsseExporter.java b/psse/psse-converter/src/main/java/com/powsybl/psse/converter/PsseExporter.java index db048a1b2ee..f0abca731b2 100644 --- a/psse/psse-converter/src/main/java/com/powsybl/psse/converter/PsseExporter.java +++ b/psse/psse-converter/src/main/java/com/powsybl/psse/converter/PsseExporter.java @@ -109,36 +109,23 @@ private void exportNotJson(Context context, PssePowerFlowModel updatePsseModel, } } + // New equipment is not supported + // Antennas (Branches connected only at one end) are exported as out of service (both sides open) private static PssePowerFlowModel createUpdatePsseModel(Network network, PssePowerFlowModel psseModel) { - PssePowerFlowModel updatePsseModel = new PssePowerFlowModel(psseModel.getCaseIdentification()); - - copyPermanentBlocks(psseModel, updatePsseModel); - updateModifiedBlocks(network, psseModel, updatePsseModel); - return updatePsseModel; + // Only the updated blocks are copied, non-updated blocks are referenced + PssePowerFlowModel referencedAndCopiedPsseModel = psseModel.referenceAndCopyPssePowerFlowModel(); + updateModifiedBlocks(network, referencedAndCopiedPsseModel); + return referencedAndCopiedPsseModel; } - private static void copyPermanentBlocks(PssePowerFlowModel psseModel, PssePowerFlowModel updatePsseModel) { - updatePsseModel.addAreas(psseModel.getAreas()); - updatePsseModel.addTwoTerminalDcTransmissionLines(psseModel.getTwoTerminalDcTransmissionLines()); - updatePsseModel.addVoltageSourceConverterDcTransmissionLines(psseModel.getVoltageSourceConverterDcTransmissionLines()); - updatePsseModel.addTransformerImpedanceCorrections(psseModel.getTransformerImpedanceCorrections()); - updatePsseModel.addMultiTerminalDcTransmissionLines(psseModel.getMultiTerminalDcTransmissionLines()); - updatePsseModel.addLineGrouping(psseModel.getLineGrouping()); - updatePsseModel.addZones(psseModel.getZones()); - updatePsseModel.addInterareaTransfer(psseModel.getInterareaTransfer()); - updatePsseModel.addOwners(psseModel.getOwners()); - updatePsseModel.addFacts(psseModel.getFacts()); - updatePsseModel.addGneDevice(psseModel.getGneDevice()); - updatePsseModel.addInductionMachines(psseModel.getInductionMachines()); - } + private static void updateModifiedBlocks(Network network, PssePowerFlowModel referencedAndCopiedPsseModel) { - private static void updateModifiedBlocks(Network network, PssePowerFlowModel psseModel, PssePowerFlowModel updatePsseModel) { - BusConverter.updateBuses(network, psseModel, updatePsseModel); - LoadConverter.updateLoads(network, psseModel, updatePsseModel); - FixedShuntCompensatorConverter.updateFixedShunts(network, psseModel, updatePsseModel); - GeneratorConverter.updateGenerators(network, psseModel, updatePsseModel); - LineConverter.updateLines(network, psseModel, updatePsseModel); - TransformerConverter.updateTransformers(network, psseModel, updatePsseModel); - SwitchedShuntCompensatorConverter.updateSwitchedShunts(network, psseModel, updatePsseModel); + BusConverter.updateBuses(network, referencedAndCopiedPsseModel); + LoadConverter.updateLoads(network, referencedAndCopiedPsseModel); + FixedShuntCompensatorConverter.updateFixedShunts(network, referencedAndCopiedPsseModel); + GeneratorConverter.updateGenerators(network, referencedAndCopiedPsseModel); + LineConverter.updateLines(network, referencedAndCopiedPsseModel); + TransformerConverter.updateTransformers(network, referencedAndCopiedPsseModel); + SwitchedShuntCompensatorConverter.updateSwitchedShunts(network, referencedAndCopiedPsseModel); } } diff --git a/psse/psse-converter/src/main/java/com/powsybl/psse/converter/SwitchedShuntCompensatorConverter.java b/psse/psse-converter/src/main/java/com/powsybl/psse/converter/SwitchedShuntCompensatorConverter.java index 195ff3324f2..068c6776900 100644 --- a/psse/psse-converter/src/main/java/com/powsybl/psse/converter/SwitchedShuntCompensatorConverter.java +++ b/psse/psse-converter/src/main/java/com/powsybl/psse/converter/SwitchedShuntCompensatorConverter.java @@ -8,7 +8,6 @@ package com.powsybl.psse.converter; import java.util.ArrayList; -import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Objects; @@ -268,19 +267,16 @@ private static String getShuntId(String busId, String id) { } // At the moment we do not consider new switchedShunts - static void updateSwitchedShunts(Network network, PssePowerFlowModel psseModel, PssePowerFlowModel updatePsseModel) { - PsseVersion version = PsseVersion.fromRevision(updatePsseModel.getCaseIdentification().getRev()); + static void updateSwitchedShunts(Network network, PssePowerFlowModel psseModel) { + PsseVersion version = PsseVersion.fromRevision(psseModel.getCaseIdentification().getRev()); psseModel.getSwitchedShunts().forEach(psseSwitchedShunt -> { - updatePsseModel.addSwitchedShunts(Collections.singletonList(psseSwitchedShunt)); - PsseSwitchedShunt updatePsseSwitchedShunt = updatePsseModel.getSwitchedShunts().get(updatePsseModel.getSwitchedShunts().size() - 1); - - String switchedShuntId = getShuntId(getBusId(updatePsseSwitchedShunt.getI()), defineShuntId(updatePsseSwitchedShunt, version)); + String switchedShuntId = getShuntId(getBusId(psseSwitchedShunt.getI()), defineShuntId(psseSwitchedShunt, version)); ShuntCompensator switchedShunt = network.getShuntCompensator(switchedShuntId); if (switchedShunt == null) { - updatePsseSwitchedShunt.setStat(0); + psseSwitchedShunt.setStat(0); } else { - updatePsseSwitchedShunt.setStat(getStatus(switchedShunt)); - updatePsseSwitchedShunt.setBinit(getQ(switchedShunt)); + psseSwitchedShunt.setStat(getStatus(switchedShunt)); + psseSwitchedShunt.setBinit(getQ(switchedShunt)); } }); } diff --git a/psse/psse-converter/src/main/java/com/powsybl/psse/converter/TransformerConverter.java b/psse/psse-converter/src/main/java/com/powsybl/psse/converter/TransformerConverter.java index cdc471bebc7..fea2c97589c 100644 --- a/psse/psse-converter/src/main/java/com/powsybl/psse/converter/TransformerConverter.java +++ b/psse/psse-converter/src/main/java/com/powsybl/psse/converter/TransformerConverter.java @@ -8,7 +8,6 @@ package com.powsybl.psse.converter; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Objects; @@ -840,31 +839,28 @@ private static String getTransformerId(int i, int j, int k, String ckt) { } // At the moment we do not consider new transformers and antenna twoWindingsTransformers are exported as open - static void updateTransformers(Network network, PssePowerFlowModel psseModel, PssePowerFlowModel updatePsseModel) { + static void updateTransformers(Network network, PssePowerFlowModel psseModel) { psseModel.getTransformers().forEach(psseTransformer -> { - updatePsseModel.addTransformers(Collections.singletonList(psseTransformer)); - PsseTransformer updatePsseTransformer = updatePsseModel.getTransformers().get(updatePsseModel.getTransformers().size() - 1); - - if (isTwoWindingsTransformer(updatePsseTransformer)) { - updateTwoWindingsTransformer(network, updatePsseTransformer); + if (isTwoWindingsTransformer(psseTransformer)) { + updateTwoWindingsTransformer(network, psseTransformer); } else { - updateThreeWindingsTransformer(network, updatePsseTransformer); + updateThreeWindingsTransformer(network, psseTransformer); } }); } - private static void updateTwoWindingsTransformer(Network network, PsseTransformer updatePsseTransformer) { - String transformerId = getTransformerId(updatePsseTransformer.getI(), updatePsseTransformer.getJ(), updatePsseTransformer.getCkt()); + private static void updateTwoWindingsTransformer(Network network, PsseTransformer psseTransformer) { + String transformerId = getTransformerId(psseTransformer.getI(), psseTransformer.getJ(), psseTransformer.getCkt()); TwoWindingsTransformer tw2t = network.getTwoWindingsTransformer(transformerId); if (tw2t == null) { - updatePsseTransformer.setStat(0); + psseTransformer.setStat(0); } else { double baskv1 = tw2t.getTerminal1().getVoltageLevel().getNominalV(); - double nomV1 = getNomV(updatePsseTransformer.getWinding1(), tw2t.getTerminal1().getVoltageLevel()); - updatePsseTransformer.getWinding1().setWindv(defineWindV(getRatio(tw2t.getRatioTapChanger(), tw2t.getPhaseTapChanger()), baskv1, nomV1, updatePsseTransformer.getCw())); - updatePsseTransformer.getWinding1().setAng(getAngle(tw2t.getPhaseTapChanger())); + double nomV1 = getNomV(psseTransformer.getWinding1(), tw2t.getTerminal1().getVoltageLevel()); + psseTransformer.getWinding1().setWindv(defineWindV(getRatio(tw2t.getRatioTapChanger(), tw2t.getPhaseTapChanger()), baskv1, nomV1, psseTransformer.getCw())); + psseTransformer.getWinding1().setAng(getAngle(tw2t.getPhaseTapChanger())); - updatePsseTransformer.setStat(getStatus(tw2t)); + psseTransformer.setStat(getStatus(tw2t)); } } @@ -876,28 +872,28 @@ private static int getStatus(TwoWindingsTransformer tw2t) { } } - private static void updateThreeWindingsTransformer(Network network, PsseTransformer updatePsseTransformer) { - String transformerId = getTransformerId(updatePsseTransformer.getI(), updatePsseTransformer.getJ(), updatePsseTransformer.getK(), updatePsseTransformer.getCkt()); + private static void updateThreeWindingsTransformer(Network network, PsseTransformer psseTransformer) { + String transformerId = getTransformerId(psseTransformer.getI(), psseTransformer.getJ(), psseTransformer.getK(), psseTransformer.getCkt()); ThreeWindingsTransformer tw3t = network.getThreeWindingsTransformer(transformerId); if (tw3t == null) { - updatePsseTransformer.setStat(0); + psseTransformer.setStat(0); } else { double baskv1 = tw3t.getLeg1().getTerminal().getVoltageLevel().getNominalV(); - double nomV1 = getNomV(updatePsseTransformer.getWinding1(), tw3t.getLeg1().getTerminal().getVoltageLevel()); - updatePsseTransformer.getWinding1().setWindv(defineWindV(getRatio(tw3t.getLeg1().getRatioTapChanger(), tw3t.getLeg1().getPhaseTapChanger()), baskv1, nomV1, updatePsseTransformer.getCw())); - updatePsseTransformer.getWinding1().setAng(getAngle(tw3t.getLeg1().getPhaseTapChanger())); + double nomV1 = getNomV(psseTransformer.getWinding1(), tw3t.getLeg1().getTerminal().getVoltageLevel()); + psseTransformer.getWinding1().setWindv(defineWindV(getRatio(tw3t.getLeg1().getRatioTapChanger(), tw3t.getLeg1().getPhaseTapChanger()), baskv1, nomV1, psseTransformer.getCw())); + psseTransformer.getWinding1().setAng(getAngle(tw3t.getLeg1().getPhaseTapChanger())); double baskv2 = tw3t.getLeg2().getTerminal().getVoltageLevel().getNominalV(); - double nomV2 = getNomV(updatePsseTransformer.getWinding2(), tw3t.getLeg2().getTerminal().getVoltageLevel()); - updatePsseTransformer.getWinding2().setWindv(defineWindV(getRatio(tw3t.getLeg2().getRatioTapChanger(), tw3t.getLeg2().getPhaseTapChanger()), baskv2, nomV2, updatePsseTransformer.getCw())); - updatePsseTransformer.getWinding2().setAng(getAngle(tw3t.getLeg2().getPhaseTapChanger())); + double nomV2 = getNomV(psseTransformer.getWinding2(), tw3t.getLeg2().getTerminal().getVoltageLevel()); + psseTransformer.getWinding2().setWindv(defineWindV(getRatio(tw3t.getLeg2().getRatioTapChanger(), tw3t.getLeg2().getPhaseTapChanger()), baskv2, nomV2, psseTransformer.getCw())); + psseTransformer.getWinding2().setAng(getAngle(tw3t.getLeg2().getPhaseTapChanger())); double baskv3 = tw3t.getLeg3().getTerminal().getVoltageLevel().getNominalV(); - double nomV3 = getNomV(updatePsseTransformer.getWinding3(), tw3t.getLeg3().getTerminal().getVoltageLevel()); - updatePsseTransformer.getWinding3().setWindv(defineWindV(getRatio(tw3t.getLeg3().getRatioTapChanger(), tw3t.getLeg3().getPhaseTapChanger()), baskv3, nomV3, updatePsseTransformer.getCw())); - updatePsseTransformer.getWinding3().setAng(getAngle(tw3t.getLeg3().getPhaseTapChanger())); + double nomV3 = getNomV(psseTransformer.getWinding3(), tw3t.getLeg3().getTerminal().getVoltageLevel()); + psseTransformer.getWinding3().setWindv(defineWindV(getRatio(tw3t.getLeg3().getRatioTapChanger(), tw3t.getLeg3().getPhaseTapChanger()), baskv3, nomV3, psseTransformer.getCw())); + psseTransformer.getWinding3().setAng(getAngle(tw3t.getLeg3().getPhaseTapChanger())); - updatePsseTransformer.setStat(getStatus(tw3t)); + psseTransformer.setStat(getStatus(tw3t)); } } diff --git a/psse/psse-converter/src/test/java/com/powsybl/psse/converter/PsseExporterTest.java b/psse/psse-converter/src/test/java/com/powsybl/psse/converter/PsseExporterTest.java index f51116da6ea..919c66ce9d6 100644 --- a/psse/psse-converter/src/test/java/com/powsybl/psse/converter/PsseExporterTest.java +++ b/psse/psse-converter/src/test/java/com/powsybl/psse/converter/PsseExporterTest.java @@ -7,13 +7,21 @@ */ package com.powsybl.psse.converter; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ser.FilterProvider; +import com.fasterxml.jackson.databind.ser.PropertyWriter; +import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter; +import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; import com.google.common.collect.ImmutableList; +import com.google.common.io.ByteStreams; import com.powsybl.commons.test.AbstractSerDeTest; import com.powsybl.commons.datasource.DataSource; import com.powsybl.commons.datasource.FileDataSource; import com.powsybl.commons.datasource.ReadOnlyDataSource; import com.powsybl.commons.datasource.ResourceDataSource; import com.powsybl.commons.datasource.ResourceSet; +import com.powsybl.commons.test.TestUtil; import com.powsybl.iidm.network.Generator; import com.powsybl.iidm.network.Line; import com.powsybl.iidm.network.Load; @@ -21,10 +29,21 @@ import com.powsybl.iidm.network.ShuntCompensator; import com.powsybl.iidm.network.TwoWindingsTransformer; import com.powsybl.iidm.network.impl.NetworkFactoryImpl; + +import java.io.UncheckedIOException; +import java.nio.charset.StandardCharsets; import java.time.ZonedDateTime; + +import com.powsybl.psse.converter.extensions.PsseModelExtension; +import com.powsybl.psse.model.PsseVersion; +import com.powsybl.psse.model.PsseVersioned; +import com.powsybl.psse.model.Revision; +import com.powsybl.psse.model.pf.PssePowerFlowModel; import org.junit.jupiter.api.Test; import static com.powsybl.commons.test.ComparisonUtils.assertTxtEquals; +import static com.powsybl.psse.model.PsseVersion.fromRevision; + import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; @@ -80,6 +99,11 @@ void importExportTest24() throws IOException { Network network = importTest("IEEE_24_bus", "IEEE_24_bus.raw", false); changeIEEE24BusNetwork(network); exportTest(network, "IEEE_24_bus_updated_exported", "IEEE_24_bus_updated_exported.raw"); + + // check that the psseModel associated with the network has not been changed + PssePowerFlowModel psseModel = network.getExtension(PsseModelExtension.class).getPsseModel(); + String jsonRef = loadJsonReference("IEEE_24_bus.json"); + assertEquals(jsonRef, toJsonString(psseModel)); } private static void changeIEEE24BusNetwork(Network network) { @@ -114,6 +138,29 @@ private static void changeIEEE24BusNetwork(Network network) { tw2t.getTerminal2().disconnect(); } + private static String toJsonString(PssePowerFlowModel rawData) throws JsonProcessingException { + PsseVersion version = fromRevision(rawData.getCaseIdentification().getRev()); + SimpleBeanPropertyFilter filter = new SimpleBeanPropertyFilter() { + @Override + protected boolean include(PropertyWriter writer) { + Revision rev = writer.getAnnotation(Revision.class); + return rev == null || PsseVersioned.isValidVersion(version, rev); + } + }; + FilterProvider filters = new SimpleFilterProvider().addFilter("PsseVersionFilter", filter); + String json = new ObjectMapper().writerWithDefaultPrettyPrinter().with(filters).writeValueAsString(rawData); + return TestUtil.normalizeLineSeparator(json); + } + + private String loadJsonReference(String fileName) { + try { + InputStream is = getClass().getResourceAsStream("/" + fileName); + return TestUtil.normalizeLineSeparator(new String(ByteStreams.toByteArray(is), StandardCharsets.UTF_8)); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + @Test void importExportTest30() throws IOException { Network network = importTest("IEEE_30_bus", "IEEE_30_bus.raw", false); diff --git a/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PsseBus.java b/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PsseBus.java index 7a4715a5e6b..ce5379b0ccd 100644 --- a/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PsseBus.java +++ b/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PsseBus.java @@ -171,4 +171,22 @@ public void setEvlo(double evlo) { checkVersion("evlo"); this.evlo = evlo; } + + public PsseBus copy() { + PsseBus copy = new PsseBus(); + copy.i = this.i; + copy.name = this.name; + copy.baskv = this.baskv; + copy.ide = this.ide; + copy.area = this.area; + copy.zone = this.zone; + copy.owner = this.owner; + copy.vm = this.vm; + copy.va = this.va; + copy.nvhi = this.nvhi; + copy.nvlo = this.nvlo; + copy.evhi = this.evhi; + copy.evlo = this.evlo; + return copy; + } } diff --git a/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PsseFixedShunt.java b/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PsseFixedShunt.java index d8b40dce319..f85dd386c1b 100644 --- a/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PsseFixedShunt.java +++ b/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PsseFixedShunt.java @@ -69,4 +69,14 @@ public double getBl() { public void setBl(double bl) { this.bl = bl; } + + public PsseFixedShunt copy() { + PsseFixedShunt copy = new PsseFixedShunt(); + copy.i = this.i; + copy.id = this.id; + copy.status = this.status; + copy.gl = this.gl; + copy.bl = this.bl; + return copy; + } } diff --git a/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PsseGenerator.java b/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PsseGenerator.java index 67ee97901a6..1db0d463982 100644 --- a/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PsseGenerator.java +++ b/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PsseGenerator.java @@ -275,4 +275,32 @@ public void setBaslod(int baslod) { public PsseOwnership getOwnership() { return ownership; } + + public PsseGenerator copy() { + PsseGenerator copy = new PsseGenerator(); + copy.i = this.i; + copy.id = this.id; + copy.pg = this.pg; + copy.qg = this.qg; + copy.qt = this.qt; + copy.qb = this.qb; + copy.vs = this.vs; + copy.ireg = this.ireg; + copy.mbase = this.mbase; + copy.zr = this.zr; + copy.zx = this.zx; + copy.rt = this.rt; + copy.xt = this.xt; + copy.gtap = this.gtap; + copy.stat = this.stat; + copy.rmpct = this.rmpct; + copy.pt = this.pt; + copy.pb = this.pb; + copy.ownership = this.ownership; + copy.wmod = this.wmod; + copy.wpf = this.wpf; + copy.nreg = this.nreg; + copy.baslod = this.baslod; + return copy; + } } diff --git a/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PsseLoad.java b/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PsseLoad.java index 299745ac105..5e27a9aaa0c 100644 --- a/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PsseLoad.java +++ b/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PsseLoad.java @@ -229,4 +229,28 @@ public void setLoadtype(String loadtype) { checkVersion("loadtype"); this.loadtype = loadtype; } + + public PsseLoad copy() { + PsseLoad copy = new PsseLoad(); + copy.i = this.i; + copy.id = this.id; + copy.status = this.status; + copy.area = this.area; + copy.zone = this.zone; + copy.owner = this.owner; + copy.pl = this.pl; + copy.ql = this.ql; + copy.ip = this.ip; + copy.iq = this.iq; + copy.yp = this.yp; + copy.yq = this.yq; + copy.owner = this.owner; + copy.scale = this.scale; + copy.intrpt = this.intrpt; + copy.dgenp = this.dgenp; + copy.dgenq = this.dgenq; + copy.dgenm = this.dgenm; + copy.loadtype = this.loadtype; + return copy; + } } diff --git a/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PsseNonTransformerBranch.java b/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PsseNonTransformerBranch.java index be9881554a3..b6ec64a9476 100644 --- a/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PsseNonTransformerBranch.java +++ b/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PsseNonTransformerBranch.java @@ -197,4 +197,25 @@ public PsseOwnership getOwnership() { public PsseRates getRates() { return rates; } + + public PsseNonTransformerBranch copy() { + PsseNonTransformerBranch copy = new PsseNonTransformerBranch(); + copy.i = this.i; + copy.j = this.j; + copy.ckt = this.ckt; + copy.r = this.r; + copy.x = this.x; + copy.b = this.b; + copy.rates = this.rates.copy(); + copy.gi = this.gi; + copy.bi = this.bi; + copy.gj = this.gj; + copy.bj = this.bj; + copy.st = this.st; + copy.met = this.met; + copy.len = this.len; + copy.ownership = this.ownership; + copy.name = this.name; + return copy; + } } diff --git a/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PssePowerFlowModel.java b/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PssePowerFlowModel.java index 49bc7cbb275..e1398adf866 100644 --- a/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PssePowerFlowModel.java +++ b/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PssePowerFlowModel.java @@ -220,6 +220,39 @@ public List getInductionMachines() { return Collections.unmodifiableList(inductionMachines); } + public PssePowerFlowModel referenceAndCopyPssePowerFlowModel() { + PssePowerFlowModel newPsseModel = new PssePowerFlowModel(this.getCaseIdentification()); + referencePermanentBlocks(this, newPsseModel); + copyModifiedBlocks(this, newPsseModel); + return newPsseModel; + } + + private static void referencePermanentBlocks(PssePowerFlowModel psseModel, PssePowerFlowModel newPsseModel) { + newPsseModel.addAreas(psseModel.getAreas()); + newPsseModel.addTwoTerminalDcTransmissionLines(psseModel.getTwoTerminalDcTransmissionLines()); + newPsseModel.addVoltageSourceConverterDcTransmissionLines(psseModel.getVoltageSourceConverterDcTransmissionLines()); + newPsseModel.addTransformerImpedanceCorrections(psseModel.getTransformerImpedanceCorrections()); + newPsseModel.addMultiTerminalDcTransmissionLines(psseModel.getMultiTerminalDcTransmissionLines()); + newPsseModel.addLineGrouping(psseModel.getLineGrouping()); + newPsseModel.addZones(psseModel.getZones()); + newPsseModel.addInterareaTransfer(psseModel.getInterareaTransfer()); + newPsseModel.addOwners(psseModel.getOwners()); + newPsseModel.addFacts(psseModel.getFacts()); + newPsseModel.addGneDevice(psseModel.getGneDevice()); + newPsseModel.addInductionMachines(psseModel.getInductionMachines()); + } + + private static void copyModifiedBlocks(PssePowerFlowModel psseModel, PssePowerFlowModel newPsseModel) { + psseModel.getBuses().forEach(psseBus -> newPsseModel.buses.add(psseBus.copy())); + psseModel.getLoads().forEach(psseLoad -> newPsseModel.loads.add(psseLoad.copy())); + + psseModel.getFixedShunts().forEach(psseFixedShunt -> newPsseModel.fixedShunts.add(psseFixedShunt.copy())); + psseModel.getGenerators().forEach(psseGenerator -> newPsseModel.generators.add(psseGenerator.copy())); + psseModel.getNonTransformerBranches().forEach(nonTransformerBranch -> newPsseModel.nonTransformerBranches.add(nonTransformerBranch.copy())); + psseModel.getTransformers().forEach(psseTransformer -> newPsseModel.transformers.add(psseTransformer.copy())); + psseModel.getSwitchedShunts().forEach(psseSwitchedShunt -> newPsseModel.switchedShunts.add(psseSwitchedShunt.copy())); + } + private List modelled(List elements) { for (PsseVersioned v : elements) { v.setModel(this); diff --git a/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PsseRates.java b/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PsseRates.java index d39eed37bd8..cbe3a98ea7b 100644 --- a/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PsseRates.java +++ b/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PsseRates.java @@ -239,4 +239,24 @@ public void setRate12(double rate12) { checkVersion("rate12"); this.rate12 = rate12; } + + public PsseRates copy() { + PsseRates copy = new PsseRates(); + copy.ratea = this.ratea; + copy.rateb = this.rateb; + copy.ratec = this.ratec; + copy.rate1 = this.rate1; + copy.rate2 = this.rate2; + copy.rate3 = this.rate3; + copy.rate4 = this.rate4; + copy.rate5 = this.rate5; + copy.rate6 = this.rate6; + copy.rate7 = this.rate7; + copy.rate8 = this.rate8; + copy.rate9 = this.rate9; + copy.rate10 = this.rate10; + copy.rate11 = this.rate11; + copy.rate12 = this.rate12; + return copy; + } } diff --git a/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PsseSwitchedShunt.java b/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PsseSwitchedShunt.java index c0b7ad5369d..744c6dec157 100644 --- a/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PsseSwitchedShunt.java +++ b/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PsseSwitchedShunt.java @@ -469,4 +469,46 @@ public int getS8() { public void setS8(int s8) { this.s8 = s8; } + + public PsseSwitchedShunt copy() { + PsseSwitchedShunt copy = new PsseSwitchedShunt(); + copy.i = this.i; + copy.modsw = this.modsw; + copy.adjm = this.adjm; + copy.stat = this.stat; + copy.vswhi = this.vswhi; + copy.vswlo = this.vswlo; + copy.swrem = this.swrem; + copy.rmpct = this.rmpct; + copy.rmidnt = this.rmidnt; + copy.binit = this.binit; + copy.n1 = this.n1; + copy.b1 = this.b1; + copy.n2 = this.n2; + copy.b2 = this.b2; + copy.n3 = this.n3; + copy.b3 = this.b3; + copy.n4 = this.n4; + copy.b4 = this.b4; + copy.n5 = this.n5; + copy.b5 = this.b5; + copy.n6 = this.n6; + copy.b6 = this.b6; + copy.n7 = this.n7; + copy.b7 = this.b7; + copy.n8 = this.n8; + copy.b8 = this.b8; + copy.id = this.id; + copy.swreg = this.swreg; + copy.nreg = this.nreg; + copy.s1 = this.s1; + copy.s2 = this.s2; + copy.s3 = this.s3; + copy.s4 = this.s4; + copy.s5 = this.s5; + copy.s6 = this.s6; + copy.s7 = this.s7; + copy.s8 = this.s8; + return copy; + } } diff --git a/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PsseTransformer.java b/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PsseTransformer.java index 6cc42c86ef9..26389ca06b9 100644 --- a/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PsseTransformer.java +++ b/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PsseTransformer.java @@ -365,6 +365,33 @@ public void setImpedances(TransformerImpedances impedances) { this.impedances = impedances; } + public PsseTransformer copy() { + PsseTransformer copy = new PsseTransformer(); + copy.i = this.i; + copy.j = this.j; + copy.k = this.k; + copy.ckt = this.ckt; + copy.cw = this.cw; + copy.cz = this.cz; + copy.cm = this.cm; + copy.mag1 = this.mag1; + copy.mag2 = this.mag2; + copy.nmetr = this.nmetr; + copy.name = this.name; + copy.stat = this.stat; + copy.ownership = this.ownership; + copy.vecgrp = this.vecgrp; + copy.zcod = this.zcod; + copy.impedances = this.impedances.copy(); + copy.winding1 = this.winding1.copy(); + copy.winding1Rates = this.winding1Rates.copy(); + copy.winding2 = this.winding2.copy(); + copy.winding2Rates = this.winding2Rates.copy(); + copy.winding3 = this.winding3.copy(); + copy.winding3Rates = this.winding3Rates.copy(); + return copy; + } + public static class TransformerImpedances { @Parsed(field = {"r12", "r1_2"}) private double r12 = 0; @@ -406,5 +433,21 @@ public static class TransformerImpedances { @NullString(nulls = {"null"}) @Parsed private double anstar = 0; + + public TransformerImpedances copy() { + TransformerImpedances copy = new TransformerImpedances(); + copy.r12 = this.r12; + copy.x12 = this.x12; + copy.sbase12 = this.sbase12; + copy.r23 = this.r23; + copy.x23 = this.x23; + copy.sbase23 = this.sbase23; + copy.r31 = this.r31; + copy.x31 = this.x31; + copy.sbase31 = this.sbase31; + copy.vmstar = this.vmstar; + copy.anstar = this.anstar; + return copy; + } } } diff --git a/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PsseTransformerWinding.java b/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PsseTransformerWinding.java index 77a5f7ffabd..b5d92a38862 100644 --- a/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PsseTransformerWinding.java +++ b/psse/psse-model/src/main/java/com/powsybl/psse/model/pf/PsseTransformerWinding.java @@ -146,4 +146,24 @@ public double getCx() { public double getCnxa() { return cnxa; } + + public PsseTransformerWinding copy() { + PsseTransformerWinding copy = new PsseTransformerWinding(); + copy.windv = this.windv; + copy.nomv = this.nomv; + copy.ang = this.ang; + copy.cod = this.cod; + copy.cont = this.cont; + copy.node = this.node; + copy.rma = this.rma; + copy.rmi = this.rmi; + copy.vma = this.vma; + copy.vmi = this.vmi; + copy.ntp = this.ntp; + copy.tab = this.tab; + copy.cr = this.cr; + copy.cx = this.cx; + copy.cnxa = this.cnxa; + return copy; + } }