diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/builders/AbstractEquipmentModelBuilder.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/builders/AbstractEquipmentModelBuilder.java index 54435c474..18fe04d67 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/builders/AbstractEquipmentModelBuilder.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/builders/AbstractEquipmentModelBuilder.java @@ -13,6 +13,7 @@ import com.powsybl.iidm.network.Network; import java.util.Objects; +import java.util.function.Predicate; /** * @author Laurent Issertial {@literal } @@ -23,6 +24,7 @@ public abstract class AbstractEquipmentModelBuilder, R protected String parameterSetId; protected final ModelConfig modelConfig; protected final BuilderEquipment builderEquipment; + private Predicate equipmentPredicates = eq -> Objects.equals(network, eq.getNetwork()); protected AbstractEquipmentModelBuilder(Network network, ModelConfig modelConfig, IdentifiableType equipmentType, ReportNode reportNode) { super(network, reportNode); @@ -72,7 +74,11 @@ protected void checkData() { protected abstract T findEquipment(String staticId); protected boolean checkEquipment(T equipment) { - return Objects.equals(network, equipment.getNetwork()); + return equipmentPredicates.test(equipment); + } + + protected void addEquipmentPredicate(Predicate predicate) { + equipmentPredicates = equipmentPredicates.and(predicate); } public T getEquipment() { diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/hvdc/HvdcVscBuilder.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/hvdc/HvdcVscBuilder.java index 33d34382e..bbc361573 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/hvdc/HvdcVscBuilder.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/hvdc/HvdcVscBuilder.java @@ -12,12 +12,10 @@ import com.powsybl.dynawaltz.builders.ModelConfigsHandler; import com.powsybl.dynawaltz.builders.ModelConfigs; import com.powsybl.dynawaltz.builders.BuilderReports; -import com.powsybl.iidm.network.HvdcConverterStation; -import com.powsybl.iidm.network.HvdcLine; -import com.powsybl.iidm.network.IdentifiableType; -import com.powsybl.iidm.network.Network; +import com.powsybl.iidm.network.*; import java.util.Set; +import java.util.function.Predicate; /** * @author Laurent Issertial {@literal } @@ -26,6 +24,7 @@ public class HvdcVscBuilder extends AbstractHvdcBuilder { private static final String CATEGORY = "hvdcVsc"; private static final ModelConfigs MODEL_CONFIGS = ModelConfigsHandler.getInstance().getModelConfigs(CATEGORY); + private static final Predicate IS_VSC = eq -> HvdcConverterStation.HvdcType.VSC == eq.getConverterStation1().getHvdcType(); public static HvdcVscBuilder of(Network network) { return of(network, ReportNode.NO_OP); @@ -54,6 +53,7 @@ public static Set getSupportedLibs() { protected HvdcVscBuilder(Network network, ModelConfig modelConfig, ReportNode reportNode) { super(network, modelConfig, "VSC " + IdentifiableType.HVDC_LINE, reportNode); + addEquipmentPredicate(IS_VSC); } @Override @@ -71,7 +71,7 @@ public HvdcVsc build() { @Override protected HvdcLine findEquipment(String staticId) { HvdcLine line = network.getHvdcLine(staticId); - return HvdcConverterStation.HvdcType.VSC == line.getConverterStation1().getHvdcType() ? line : null; + return line != null && IS_VSC.test(line) ? line : null; } @Override diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/loads/AbstractLoadModelBuilder.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/loads/AbstractLoadModelBuilder.java index 057442dd9..bf7ff2695 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/loads/AbstractLoadModelBuilder.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/loads/AbstractLoadModelBuilder.java @@ -14,18 +14,23 @@ import com.powsybl.iidm.network.Load; import com.powsybl.iidm.network.Network; +import java.util.function.Predicate; + /** * @author Laurent Issertial {@literal } */ public abstract class AbstractLoadModelBuilder> extends AbstractEquipmentModelBuilder { + private static final Predicate IS_NOT_FICTITIOUS = eq -> !eq.isFictitious(); + protected AbstractLoadModelBuilder(Network network, ModelConfig modelConfig, ReportNode reportNode) { super(network, modelConfig, IdentifiableType.LOAD, reportNode); + addEquipmentPredicate(IS_NOT_FICTITIOUS); } @Override protected Load findEquipment(String staticId) { - return network.getLoad(staticId); + Load load = network.getLoad(staticId); + return load != null && IS_NOT_FICTITIOUS.test(load) ? load : null; } - } diff --git a/dynawaltz/src/test/java/com/powsybl/dynawaltz/models/HvdcTest.java b/dynawaltz/src/test/java/com/powsybl/dynawaltz/models/HvdcTest.java index d5a49dbe9..ce94b9aa9 100644 --- a/dynawaltz/src/test/java/com/powsybl/dynawaltz/models/HvdcTest.java +++ b/dynawaltz/src/test/java/com/powsybl/dynawaltz/models/HvdcTest.java @@ -18,6 +18,7 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; /** * @author Laurent Issertial {@literal } @@ -58,4 +59,14 @@ void testDanglingConnectedStation() { assertEquals(1, hvdcVscDangling.getConnectedStations().size()); assertEquals(line.getConverterStation1(), hvdcVscDangling.getConnectedStations().get(0)); } + + @Test + void vscDynamicModelOnLCC() { + Network network = HvdcTestNetwork.createLcc(); + assertNull(HvdcVscBuilder.of(network) + .dynamicModelId("hvdc") + .staticId("L") + .parameterSetId("HVDC") + .build()); + } } diff --git a/dynawaltz/src/test/java/com/powsybl/dynawaltz/models/LoadTest.java b/dynawaltz/src/test/java/com/powsybl/dynawaltz/models/LoadTest.java new file mode 100644 index 000000000..0db1eab23 --- /dev/null +++ b/dynawaltz/src/test/java/com/powsybl/dynawaltz/models/LoadTest.java @@ -0,0 +1,39 @@ +/** + * Copyright (c) 2023, 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.dynawaltz.models; + +import com.powsybl.dynawaltz.models.loads.BaseLoadBuilder; +import com.powsybl.iidm.network.Network; +import com.powsybl.iidm.network.test.NoEquipmentNetworkFactory; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertNull; + +/** + * @author Laurent Issertial {@literal } + */ +class LoadTest { + + @Test + void loadFictitious() { + Network network = NoEquipmentNetworkFactory.create(); + network.getVoltageLevel("vl1").newLoad() + .setId("LOAD") + .setBus("busA") + .setConnectableBus("busA") + .setFictitious(true) + .setP0(600.0) + .setQ0(200.0) + .add(); + assertNull(BaseLoadBuilder.of(network) + .dynamicModelId("load") + .staticId("L") + .parameterSetId("LAB") + .build()); + } +}