Skip to content

Commit

Permalink
copy of the imported PSSE model to make the updates and export (deep …
Browse files Browse the repository at this point in the history
…copy) (#2946)

Signed-off-by: José Antonio Marqués <marquesja@aia.es>
  • Loading branch information
marqueslanauja authored May 22, 2024
1 parent fa3b6ca commit 8babc95
Show file tree
Hide file tree
Showing 19 changed files with 378 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/
package com.powsybl.psse.converter;

import java.util.Collections;
import java.util.Objects;

import com.powsybl.iidm.network.Bus;
Expand Down Expand Up @@ -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());
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/
package com.powsybl.psse.converter;

import java.util.Collections;
import java.util.Objects;

import com.powsybl.iidm.network.*;
Expand Down Expand Up @@ -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));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/
package com.powsybl.psse.converter;

import java.util.Collections;
import java.util.Objects;

import org.slf4j.Logger;
Expand Down Expand Up @@ -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));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import static com.powsybl.psse.model.PsseVersion.Major.V35;

import java.util.Collections;
import java.util.Objects;

/**
Expand Down Expand Up @@ -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));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/
package com.powsybl.psse.converter;

import java.util.Collections;
import java.util.Objects;

import com.powsybl.iidm.network.Load;
Expand Down Expand Up @@ -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));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}

Expand All @@ -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));
}
}

Expand Down
Loading

0 comments on commit 8babc95

Please sign in to comment.