BusExt getConnectableBus(int node) { // check id the node is associated to a bus BusExt connectableBus = getBus(node); if (connectableBus != null) { return connectableBus; } // if not traverse the graph starting from the node (without stopping at open switches) until finding another // node associated to a bus BusExt[] connectableBus2 = new BusExt[1]; graph.traverse(node, (v1, e, v2) -> { connectableBus2[0] = getBus(v2); if (connectableBus2[0] != null) { return TraverseResult.TERMINATE; } return TraverseResult.CONTINUE; }); // if nothing found, just take the first bus if (connectableBus2[0] != null) { Iterator<CalculatedBus> it = getBuses().iterator(); if (!it.hasNext()) { throw new AssertionError("Should not happen"); } return it.next(); } return connectableBus2[0]; } }
if (getBusChecker().isValid(graph, nodes, terminals)) { CalculatedBusImpl bus = new CalculatedBusImpl(busId, NodeBreakerVoltageLevel.this, terminals); id2bus.put(busId, bus);
protected void updateCache(final Predicate<SwitchImpl> terminate) { if (busCache != null) { return; } LOGGER.trace("Update bus topology of voltage level {}", NodeBreakerVoltageLevel.this.id); Map<String, CalculatedBus> id2bus = new LinkedHashMap<>(); CalculatedBus[] node2bus = new CalculatedBus[graph.getMaxVertex()]; boolean[] encountered = new boolean[graph.getMaxVertex()]; Arrays.fill(encountered, false); for (int e : graph.getEdges()) { traverse(graph.getEdgeVertex1(e), encountered, terminate, id2bus, node2bus); traverse(graph.getEdgeVertex2(e), encountered, terminate, id2bus, node2bus); } busCache = new BusCache(node2bus, id2bus); LOGGER.trace("Found buses {}", id2bus.values()); }
@Override public CalculatedBus getBus(String id) { return variants.get().calculatedBusTopology.getBus(id, false); }
@Override public Iterable<Bus> getBuses() { return Collections.unmodifiableCollection(variants.get().calculatedBusTopology.getBuses()); }
Collection<CalculatedBus> getBuses() { updateCache(); return busCache.getBuses(); }
protected void updateCache() { updateCache(Switch::isOpen); }
@Override public BusExt getConnectableBus() { return ((NodeBreakerVoltageLevel) voltageLevel).getCalculatedBusTopology().getConnectableBus(node); }
@Override public Stream<Bus> getBusStream() { return variants.get().calculatedBusTopology.getBuses().stream().map(Function.identity()); }
CalculatedBus getBus(int node) { updateCache(); return busCache.getBus(node); }
@Override public Bus getMergedBus(String busBarId) { NodeTerminal nt = (NodeTerminal) nodeBreakerView.getBusbarSection(busBarId).getTerminal(); int node = nt.getNode(); return variants.get().calculatedBusTopology.getBus(node); } };
CalculatedBus getBus(String id, boolean throwException) { updateCache(); CalculatedBus bus = busCache.getBus(id); if (throwException && bus == null) { throw new PowsyblException("Bus " + id + " not found"); } return bus; }
@Override public void invalidateCache() { variants.get().calculatedBusBreakerTopology.invalidateCache(); variants.get().calculatedBusTopology.invalidateCache(); getNetwork().getConnectedComponentsManager().invalidate(); }
@Override public BusExt getBus() { return ((NodeBreakerVoltageLevel) voltageLevel).getCalculatedBusTopology().getBus(node); }