Skip to content

Commit

Permalink
Check if StandardBus connect with DynamicModel or throw exception
Browse files Browse the repository at this point in the history
Signed-off-by: lisrte <laurent.issertial@rte-france.com>
  • Loading branch information
Lisrte committed Mar 3, 2023
1 parent 0efd8a4 commit 44610c4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public Collection<MacroConnector> getEventMacroConnectors() {
}

public boolean isWithoutBlackBoxDynamicModel(String staticId) {
return getInputBlackBoxDynamicModelStream().noneMatch(d -> staticId.equals(d.getStaticId().orElseThrow()));
return !staticIdBlackBoxModelMap.containsKey(staticId);
}

private Stream<BlackBoxModel> getInputBlackBoxDynamicModelStream() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,15 @@
import com.powsybl.commons.PowsyblException;
import com.powsybl.dynawaltz.DynaWaltzContext;
import com.powsybl.dynawaltz.models.AbstractBlackBoxModel;
import com.powsybl.dynawaltz.models.VarConnection;
import com.powsybl.dynawaltz.models.generators.GeneratorModel;
import com.powsybl.iidm.network.Bus;
import com.powsybl.iidm.network.Identifiable;
import org.apache.commons.lang3.tuple.Pair;

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* @author Dimitri Baudrier <dimitri.baudrier at rte-france.com>
Expand Down Expand Up @@ -51,27 +48,27 @@ public List<Pair<String, String>> getMacroConnectToAttributes() {
return attributesConnectTo;
}

public List<VarConnection> getVarConnectionsWithGenerator(GeneratorModel connected) {
return Arrays.asList(
new VarConnection(getTerminalVarName(), connected.getTerminalVarName()),
new VarConnection(getSwitchOffSignalVarName(), connected.getSwitchOffSignalNodeVarName())
);
}

/**
* Creates connections only with generators without a dynamic model
*/
@Override
public void createMacroConnections(DynaWaltzContext context) {
// Buses with a dynamical model can only connect to equipment with a dynamic model
String staticId = getStaticId().orElse(null);
Bus bus = context.getNetwork().getBusBreakerView().getBus(staticId);
if (bus == null) {
throw new PowsyblException("Bus static id unknown: " + staticId);
}
List<String> staticIds = bus.getGeneratorStream().map(Identifiable::getId).filter(context::isWithoutBlackBoxDynamicModel).collect(Collectors.toList());
if (!staticIds.isEmpty()) {
createMacroConnectionsWithIndex1(staticIds, GeneratorModel.class, false, this::getVarConnectionsWithGenerator, context);
}
checkLinkedDynamicModels(bus.getGeneratorStream(), "generator", context);
checkLinkedDynamicModels(bus.getLineStream(), "line", context);
checkLinkedDynamicModels(bus.getLoadStream(), "load", context);
}

private <T extends Identifiable<T>> void checkLinkedDynamicModels(Stream<T> stream, String equipmentName, DynaWaltzContext context) {
stream.map(Identifiable::getId)
.filter(context::isWithoutBlackBoxDynamicModel)
.findAny()
.ifPresent(id -> {
throw new PowsyblException(String.format("The %s %s linked to the standard bus %s does not possess a dynamic model",
equipmentName, id, getStaticId().orElse(null)));
});
}

@Override
Expand Down

0 comments on commit 44610c4

Please sign in to comment.