Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent dynamic model instanciation from fictitious loads #343

Merged
merged 2 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.powsybl.iidm.network.Network;

import java.util.Objects;
import java.util.function.Predicate;

/**
* @author Laurent Issertial {@literal <laurent.issertial at rte-france.com>}
Expand All @@ -23,6 +24,7 @@ public abstract class AbstractEquipmentModelBuilder<T extends Identifiable<?>, R
protected String parameterSetId;
protected final ModelConfig modelConfig;
protected final BuilderEquipment<T> builderEquipment;
private Predicate<T> equipmentPredicates = eq -> Objects.equals(network, eq.getNetwork());

protected AbstractEquipmentModelBuilder(Network network, ModelConfig modelConfig, IdentifiableType equipmentType, ReportNode reportNode) {
super(network, reportNode);
Expand Down Expand Up @@ -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);
Lisrte marked this conversation as resolved.
Show resolved Hide resolved
}

protected void addEquipmentPredicate(Predicate<T> predicate) {
equipmentPredicates = equipmentPredicates.and(predicate);
}

public T getEquipment() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <laurent.issertial at rte-france.com>}
Expand All @@ -26,6 +24,7 @@ public class HvdcVscBuilder extends AbstractHvdcBuilder<HvdcVscBuilder> {

private static final String CATEGORY = "hvdcVsc";
private static final ModelConfigs MODEL_CONFIGS = ModelConfigsHandler.getInstance().getModelConfigs(CATEGORY);
private static final Predicate<HvdcLine> IS_VSC = eq -> HvdcConverterStation.HvdcType.VSC == eq.getConverterStation1().getHvdcType();

public static HvdcVscBuilder of(Network network) {
return of(network, ReportNode.NO_OP);
Expand Down Expand Up @@ -54,6 +53,7 @@ public static Set<String> getSupportedLibs() {

protected HvdcVscBuilder(Network network, ModelConfig modelConfig, ReportNode reportNode) {
super(network, modelConfig, "VSC " + IdentifiableType.HVDC_LINE, reportNode);
addEquipmentPredicate(IS_VSC);
}

@Override
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <laurent.issertial at rte-france.com>}
*/
public abstract class AbstractLoadModelBuilder<R extends AbstractEquipmentModelBuilder<Load, R>> extends AbstractEquipmentModelBuilder<Load, R> {

private static final Predicate<Load> 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;
}

}
11 changes: 11 additions & 0 deletions dynawaltz/src/test/java/com/powsybl/dynawaltz/models/HvdcTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <laurent.issertial at rte-france.com>}
Expand Down Expand Up @@ -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());
}
}
39 changes: 39 additions & 0 deletions dynawaltz/src/test/java/com/powsybl/dynawaltz/models/LoadTest.java
Original file line number Diff line number Diff line change
@@ -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 <laurent.issertial at rte-france.com>}
*/
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());
}
}
Loading