private static void addDisonnectedShunt(Terminal.BusBreakerView view, double q, String shuntId, ConnectedPower balanceMainCC, ConnectedPower balanceOtherCC) { if (view.getConnectableBus().isInMainConnectedComponent()) { if (q > 0) { balanceMainCC.disconnectedShuntPositiveVolume += q; } else { balanceMainCC.disconnectedShuntNegativeVolume += q; } balanceMainCC.disconnectedShunts.add(shuntId); } else { if (q > 0) { balanceOtherCC.disconnectedShuntPositiveVolume += q; } else { balanceOtherCC.disconnectedShuntNegativeVolume += q; } balanceOtherCC.disconnectedShunts.add(shuntId); } }
@Override public void dumpDtaFile(Path workingDir, String fileName, Network network, Map<String, Character> parallelIndexes, String eurostagVersion, Map<String, String> iidm2eurostagId, SimulationParameters simulationParameters) { Objects.requireNonNull(workingDir); Objects.requireNonNull(fileName); Objects.requireNonNull(network); Objects.requireNonNull(parallelIndexes); Objects.requireNonNull(eurostagVersion); Objects.requireNonNull(iidm2eurostagId); LOGGER.info("exporting dynamic data for network: {}", network.getId()); //uses the first connected generator that is available in the iidm2eurostag map Generator generator = network.getGeneratorStream() .filter(gen -> (iidm2eurostagId.containsKey(gen.getId())) && (gen.getTerminal().isConnected())) .findFirst() .orElseThrow(() -> new RuntimeException("could not find a suitable generator in network: " + network + ", to be used in: " + fileName)); Bus bus = generator.getTerminal().getBusBreakerView().getConnectableBus(); if ((bus == null) || (!iidm2eurostagId.containsKey(bus.getId()))) { bus = generator.getTerminal().getBusView().getConnectableBus(); if ((bus == null) || (!iidm2eurostagId.containsKey(bus.getId()))) { throw new RuntimeException("suitable node not found"); } } DynamicDatabaseMockUtils mockUtils = new DynamicDatabaseMockUtils(); String mappedGenName = mockUtils.formatString8(iidm2eurostagId.get(generator.getId())); String mappedNodeName = mockUtils.formatString8(iidm2eurostagId.get(bus.getId())); LOGGER.info("generator: iidm {}, eurostag {}", generator.getId(), mappedGenName); LOGGER.info("node: iidm {}, eurostag {}", bus.getId(), mappedNodeName); mockUtils.copyDynamicDataFiles(MINIMAL_DTA_TEMPLATE, workingDir, fileName, ImmutableMap.of("NODENAME", mappedNodeName, "MINIMALI", mappedGenName), MOCK_REG_FILES_PREFIXES); }
private void visitInjection(Injection inj, TerminalContext context) { Terminal t = inj.getTerminal(); context.update(t); if (config.isReplaceMissingValues()) { if (Double.isNaN(context.p)) { context.p = 0f; } if (Double.isNaN(context.q)) { context.q = 0f; } if (Double.isNaN(context.v)) { // use connectable bus voltage, better than nothing... context.v = t.getBusBreakerView().getConnectableBus().getV(); } if (Double.isNaN(context.v)) { context.v = 0f; // TODO is there a better value? } if (Double.isNaN(context.i)) { context.i = 0f; } } valueMap.put(new HistoDbNetworkAttributeId(inj.getId(), HistoDbAttr.P), context.p); valueMap.put(new HistoDbNetworkAttributeId(inj.getId(), HistoDbAttr.Q), context.q); valueMap.put(new HistoDbNetworkAttributeId(inj.getId(), HistoDbAttr.V), context.v); valueMap.put(new HistoDbNetworkAttributeId(inj.getId(), HistoDbAttr.I), context.i); }
Bus loadBus = load.getTerminal().getBusBreakerView().getBus(); if (loadBus == null) { loadBus = load.getTerminal().getBusBreakerView().getConnectableBus();
private static void extractTfo3WData(Network network, NetworkData networkData) { for (ThreeWindingsTransformer tfo : network.getThreeWindingsTransformers()) { networkData.addTfo3WData(new Tfo3WData(tfo.getId(), (tfo.getLeg1().getTerminal().getBusBreakerView().getBus() != null) ? tfo.getLeg1().getTerminal().getBusBreakerView().getBus().getId() : tfo.getLeg1().getTerminal().getBusBreakerView().getConnectableBus().getId(), (tfo.getLeg2().getTerminal().getBusBreakerView().getBus() != null) ? tfo.getLeg2().getTerminal().getBusBreakerView().getBus().getId() : tfo.getLeg2().getTerminal().getBusBreakerView().getConnectableBus().getId(), (tfo.getLeg3().getTerminal().getBusBreakerView().getBus() != null) ? tfo.getLeg3().getTerminal().getBusBreakerView().getBus().getId() : tfo.getLeg3().getTerminal().getBusBreakerView().getConnectableBus().getId(), apparentPower(tfo.getLeg1().getTerminal()), apparentPower(tfo.getLeg2().getTerminal()), apparentPower(tfo.getLeg3().getTerminal()), tfo.getLeg1().getTerminal().getVoltageLevel().getNominalV(), tfo.getLeg1().getTerminal().getVoltageLevel().getNominalV(), tfo.getLeg3().getTerminal().getVoltageLevel().getNominalV(), (tfo.getLeg1().getCurrentLimits() != null) ? tfo.getLeg1().getCurrentLimits().getPermanentLimit() : Float.NaN, (tfo.getLeg2().getCurrentLimits() != null) ? tfo.getLeg2().getCurrentLimits().getPermanentLimit() : Float.NaN, (tfo.getLeg3().getCurrentLimits() != null) ? tfo.getLeg3().getCurrentLimits().getPermanentLimit() : Float.NaN) ); } }
static void addBusOfOtherSideOfOpenBranches(Set<String> buses, Network n, ExportOptions options) { // and also bus at the other side of open branches n.getBranchStream().forEach(branch -> { Terminal t1 = branch.getTerminal1(); Terminal t2 = branch.getTerminal2(); if (options.getTopologyLevel() == TopologyLevel.BUS_BRANCH) { Bus b1 = t1.getBusView().getConnectableBus(); Bus b2 = t2.getBusView().getConnectableBus(); if ((b1 != null && b1.isInMainConnectedComponent()) && b2 != null && !b2.isInMainConnectedComponent()) { buses.add(b2.getId()); } else if (b1 != null && !b1.isInMainConnectedComponent() && b2 != null && b2.isInMainConnectedComponent()) { buses.add(b1.getId()); } } else { Bus b1 = t1.getBusBreakerView().getConnectableBus(); Bus b2 = t2.getBusBreakerView().getConnectableBus(); if (b1.isInMainConnectedComponent() && !b2.isInMainConnectedComponent()) { buses.add(b2.getId()); } else if (!b1.isInMainConnectedComponent() && b2.isInMainConnectedComponent()) { buses.add(b1.getId()); } } }); }
private static void addGenerators(Network network, ConnectedPower balanceMainCC, ConnectedPower balanceOtherCC) { for (Generator g : network.getGenerators()) { Terminal.BusBreakerView view = g.getTerminal().getBusBreakerView(); if (view.getBus() != null) { if (view.getBus().isInMainConnectedComponent()) { balanceMainCC.connectedMaxGeneration += g.getMaxP(); balanceMainCC.connectedGeneration += g.getTargetP(); balanceMainCC.connectedGenerators.add(g.getId()); } else { balanceOtherCC.connectedMaxGeneration += g.getMaxP(); balanceOtherCC.connectedGeneration += g.getTargetP(); balanceOtherCC.connectedGenerators.add(g.getId()); } } else { if (view.getConnectableBus().isInMainConnectedComponent()) { balanceMainCC.disconnectedMaxGeneration += g.getMaxP(); balanceMainCC.disconnectedGeneration += g.getTargetP(); balanceMainCC.disconnectedGenerators.add(g.getId()); } else { balanceOtherCC.disconnectedMaxGeneration += g.getMaxP(); balanceOtherCC.disconnectedGeneration += g.getTargetP(); balanceOtherCC.disconnectedGenerators.add(g.getId()); } } } }
private static void addLoads(Network network, ConnectedPower balanceMainCC, ConnectedPower balanceOtherCC) { for (Load l : network.getLoads()) { Terminal.BusBreakerView view = l.getTerminal().getBusBreakerView(); if (view.getBus() != null) { if (view.getBus().isInMainConnectedComponent()) { balanceMainCC.connectedLoads.add(l.getId()); balanceMainCC.connectedLoadVolume += l.getP0(); } else { balanceOtherCC.connectedLoads.add(l.getId()); balanceOtherCC.connectedLoadVolume += l.getP0(); } } else { if (view.getConnectableBus().isInMainConnectedComponent()) { balanceMainCC.disconnectedLoads.add(l.getId()); balanceMainCC.disconnectedLoadVolume += l.getP0(); } else { balanceOtherCC.disconnectedLoads.add(l.getId()); balanceOtherCC.disconnectedLoadVolume += l.getP0(); } } } }
private static void addDanglingLines(Network network, ConnectedPower balanceMainCC, ConnectedPower balanceOtherCC) { for (DanglingLine dl : network.getDanglingLines()) { Terminal.BusBreakerView view = dl.getTerminal().getBusBreakerView(); if (view.getBus() != null) { if (view.getBus().isInMainConnectedComponent()) { balanceMainCC.connectedLoads.add(dl.getId()); balanceMainCC.connectedLoadVolume += dl.getP0(); } else { balanceOtherCC.connectedLoads.add(dl.getId()); balanceOtherCC.connectedLoadVolume += dl.getP0(); } } else { if (view.getConnectableBus().isInMainConnectedComponent()) { balanceMainCC.disconnectedLoads.add(dl.getId()); balanceMainCC.disconnectedLoadVolume += dl.getP0(); } else { balanceOtherCC.disconnectedLoads.add(dl.getId()); balanceOtherCC.disconnectedLoadVolume += dl.getP0(); } } } }
public static ConnectionInfo getConnectionInfoInBusBreakerView(Terminal t) { Bus bus = t.getBusBreakerView().getBus(); boolean connected; if (bus != null) { connected = true; } else { connected = false; bus = t.getBusBreakerView().getConnectableBus(); if (bus == null) { // otherwise take first bus of the substation at the same voltage // level... Iterator<Bus> itVLB = t.getVoltageLevel().getBusBreakerView().getBuses().iterator(); if (itVLB.hasNext()) { bus = itVLB.next(); } else { throw new PowsyblException("Cannot find a connection bus"); } } } return new ConnectionInfo(bus, connected); }
private static void extractTfo2WData(Network network, NetworkData networkData) { for (TwoWindingsTransformer tfo : network.getTwoWindingsTransformers()) { networkData.addTfo2WData(new Tfo2WData(tfo.getId(), (tfo.getTerminal1().getBusBreakerView().getBus() != null) ? tfo.getTerminal1().getBusBreakerView().getBus().getId() : tfo.getTerminal1().getBusBreakerView().getConnectableBus().getId(), (tfo.getTerminal2().getBusBreakerView().getBus() != null) ? tfo.getTerminal2().getBusBreakerView().getBus().getId() : tfo.getTerminal2().getBusBreakerView().getConnectableBus().getId(), apparentPower(tfo.getTerminal1()), apparentPower(tfo.getTerminal2()), tfo.getTerminal1().getVoltageLevel().getNominalV(), tfo.getTerminal2().getVoltageLevel().getNominalV(), (tfo.getCurrentLimits1() != null) ? tfo.getCurrentLimits1().getPermanentLimit() : Float.NaN, (tfo.getCurrentLimits2() != null) ? tfo.getCurrentLimits2().getPermanentLimit() : Float.NaN, isRegulating(tfo), correntStepPosition(tfo)) ); } }
protected static void writeNodeOrBus(Integer index, Terminal t, NetworkXmlWriterContext context) throws XMLStreamException { TopologyLevel topologyLevel = TopologyLevel.min(t.getVoltageLevel().getTopologyKind(), context.getOptions().getTopologyLevel()); switch (topologyLevel) { case NODE_BREAKER: writeNode(index, t, context); break; case BUS_BREAKER: writeBus(index, t.getBusBreakerView().getBus(), t.getBusBreakerView().getConnectableBus(), context); break; case BUS_BRANCH: writeBus(index, t.getBusView().getBus(), t.getBusView().getConnectableBus(), context); break; default: throw new AssertionError("Unexpected TopologyLevel value: " + topologyLevel); } if (index != null) { context.getWriter().writeAttribute("voltageLevelId" + index, context.getAnonymizer().anonymizeString(t.getVoltageLevel().getId())); } }
private static void extractGeneratorsData(Network network, NetworkData networkData) { for (Generator generator : network.getGenerators()) { networkData.addGeneratorData(new GeneratorData(generator.getId(), (generator.getTerminal().getBusBreakerView().getBus() != null) ? generator.getTerminal().getBusBreakerView().getBus().getId() : generator.getTerminal().getBusBreakerView().getConnectableBus().getId(), generator.getTerminal().getBusBreakerView().getBus() != null, apparentPower(generator.getTerminal()), generator.getTerminal().getP(), generator.getTerminal().getQ(), generator.getRatedS(), generator.getReactiveLimits().getMaxQ(generator.getTargetP()), generator.getReactiveLimits().getMinQ(generator.getTargetP())) // generator.getReactiveLimits().getMaxQ(generator.getTerminal().getP()), // generator.getReactiveLimits().getMinQ(generator.getTerminal().getP())) ); } }
private static void extractLinesData(Network network, NetworkData networkData) { for (Line line : network.getLines()) { if (line.getTerminal1().getVoltageLevel().getNominalV() >= 110) { networkData.addLineData(new LineData(line.getId(), (line.getTerminal1().getBusBreakerView().getBus() != null) ? line.getTerminal1().getBusBreakerView().getBus().getId() : line.getTerminal1().getBusBreakerView().getConnectableBus().getId(), (line.getTerminal2().getBusBreakerView().getBus() != null) ? line.getTerminal2().getBusBreakerView().getBus().getId() : line.getTerminal2().getBusBreakerView().getConnectableBus().getId(), line.getTerminal1().getI(), line.getTerminal2().getI(), (line.getCurrentLimits1() != null) ? line.getCurrentLimits1().getPermanentLimit() : Float.NaN, (line.getCurrentLimits2() != null) ? line.getCurrentLimits2().getPermanentLimit() : Float.NaN) ); } } }
private ConnectBusInfo findBus(Terminal terminal, String context) { ConnectBusInfo busInfo; Bus bus = null; boolean connected = true; bus = terminal.getBusBreakerView().getBus(); if (bus == null) { connected = false; bus = terminal.getBusBreakerView().getConnectableBus(); if (bus == null) { throw new RuntimeException("Cannot find connection bus"); } } busInfo = new ConnectBusInfo(bus, connected); return busInfo; }
private static void extractLoadsData(Network network, NetworkData networkData) { for (Load load : network.getLoads()) { networkData.addLoadData(new LoadData(load.getId(), (load.getTerminal().getBusBreakerView().getBus() != null) ? load.getTerminal().getBusBreakerView().getBus().getId() : load.getTerminal().getBusBreakerView().getConnectableBus().getId(), load.getTerminal().getBusBreakerView().getBus() != null, load.getTerminal().getVoltageLevel().getNominalV(), load.getTerminal().getP(), load.getTerminal().getQ()) ); } }
public boolean test(Connectable<?> connectable) { if (buses == null) { return true; } for (Terminal t : connectable.getTerminals()) { Bus b = options.getTopologyLevel() == TopologyLevel.BUS_BRANCH ? t.getBusView().getConnectableBus() : t.getBusBreakerView().getConnectableBus(); if (b != null && !buses.contains(b.getId())) { return false; } } return true; } }
@Override protected void writeSubElements(Generator g, VoltageLevel vl, NetworkXmlWriterContext context) throws XMLStreamException { if (g.getRegulatingTerminal() != null && !Objects.equals(g.getRegulatingTerminal().getBusBreakerView().getConnectableBus(), g.getTerminal().getBusBreakerView().getConnectableBus())) { writeTerminalRef(g.getRegulatingTerminal(), context, "regulatingTerminal"); } ReactiveLimitsXml.INSTANCE.write(g, context); }
private static void fillNodeOrBus(InjectionAdder adder, Terminal terminal) { if (terminal.getVoltageLevel().getTopologyKind() == TopologyKind.NODE_BREAKER) { adder.setNode(terminal.getNodeBreakerView().getNode()); } else { if (terminal.isConnected()) { adder.setBus(terminal.getBusBreakerView().getBus().getId()); } adder.setConnectableBus(terminal.getBusBreakerView().getConnectableBus().getId()); } }
public static void printGeneratorsSetpointDiff(Network network, Logger logger) { for (Generator g : network.getGenerators()) { double dp = Math.abs(g.getTerminal().getP() + g.getTargetP()); double dq = Math.abs(g.getTerminal().getQ() + g.getTargetQ()); double dv = Math.abs(g.getTerminal().getBusBreakerView().getConnectableBus().getV() - g.getTargetV()); if (dp > 1 || dq > 5 || dv > 0.1) { logger.warn("Generator {}: ({}, {}, {}) ({}, {}, {}) -> ({}, {}, {})", g.getId(), dp, dq, dv, -g.getTargetP(), -g.getTargetQ(), g.getTargetV(), g.getTerminal().getP(), g.getTerminal().getQ(), g.getTerminal().getBusBreakerView().getConnectableBus().getV()); } } }