Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Copyright (c) 2022, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.iidm.modification.topology;
import com.powsybl.commons.PowsyblException;
import com.powsybl.commons.report.ReportNode;
import com.powsybl.computation.ComputationManager;
import com.powsybl.iidm.modification.AbstractNetworkModification;
import com.powsybl.iidm.modification.NetworkModificationImpact;
import com.powsybl.iidm.network.*;
import com.powsybl.math.graph.TraverseResult;
import org.jgrapht.Graph;
import org.jgrapht.alg.util.Pair;
import org.jgrapht.graph.Pseudograph;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
import static com.powsybl.iidm.modification.util.ModificationReports.*;
/**
* This modification removes the whole feeder bay related to a given feeder connectable.
* This means that it removes all the dangling switches and internal connections which remain once the connectable is removed.
* Note that determining the bay which corresponds to a connectable needs some computation and graph traversals.
* @author Florian Dupuy {@literal }
*/
public class RemoveFeederBay extends AbstractNetworkModification {
private static final Logger LOGGER = LoggerFactory.getLogger(RemoveFeederBay.class);
private final String connectableId;
/**
* Constructor
* @param connectableId non-null id of the connectable whose feeder bay will be removed (busbar section are not accepted)
*/
public RemoveFeederBay(String connectableId) {
this.connectableId = Objects.requireNonNull(connectableId);
}
@Override
public String getName() {
return "RemoveFeederBay";
}
@Override
public void apply(Network network, NamingStrategy namingStrategy, boolean throwException, ComputationManager computationManager, ReportNode reportNode) {
Connectable> connectable = network.getConnectable(connectableId);
if (!checkConnectable(throwException, reportNode, connectable)) {
return;
}
for (Terminal t : connectable.getTerminals()) {
if (t.getVoltageLevel().getTopologyKind() == TopologyKind.NODE_BREAKER) {
Graph graph = createGraphFromTerminal(t);
int node = t.getNodeBreakerView().getNode();
cleanTopology(t.getVoltageLevel().getNodeBreakerView(), graph, node, reportNode);
}
}
connectable.remove();
removedConnectableReport(reportNode, connectableId);
LOGGER.info("Connectable {} removed", connectableId);
}
@Override
public NetworkModificationImpact hasImpactOnNetwork(Network network) {
impact = DEFAULT_IMPACT;
Connectable> connectable = network.getConnectable(connectableId);
if (connectable == null || connectable instanceof BusbarSection) {
impact = NetworkModificationImpact.CANNOT_BE_APPLIED;
}
return impact;
}
private Graph createGraphFromTerminal(Terminal terminal) {
Graph graph = new Pseudograph<>(Object.class);
int node = terminal.getNodeBreakerView().getNode();
VoltageLevel.NodeBreakerView vlNbv = terminal.getVoltageLevel().getNodeBreakerView();
graph.addVertex(node);
vlNbv.traverse(node, (node1, sw, node2) -> {
TraverseResult result = vlNbv.getOptionalTerminal(node2)
.map(Terminal::getConnectable)
.filter(BusbarSection.class::isInstance)
.map(c -> TraverseResult.TERMINATE_PATH)
.orElse(TraverseResult.CONTINUE);
graph.addVertex(node2);
graph.addEdge(node1, node2, sw != null ? sw : Pair.of(node1, node2));
return result;
});
return graph;
}
/**
* Starting from the given node, traverse the graph and remove all the switches and/or internal connections until a
* fork node is encountered, for which special care is needed to clean the topology.
*/
private void cleanTopology(VoltageLevel.NodeBreakerView nbv, Graph graph, int node, ReportNode reportNode) {
Set