Skip to content

Commit

Permalink
Bus id list (#318)
Browse files Browse the repository at this point in the history
- For automaton action point use id list instead of single id
- Id can be bus or busbar section

Signed-off-by: lisrte <[email protected]>
  • Loading branch information
Lisrte authored Dec 13, 2023
1 parent 0b8c46d commit ffa7475
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@ import java.util.function.Predicate
*/
class DslFilteredEquipment<T extends Identifiable> extends DslEquipment<T> {

private final Predicate<IdentifiableType> typePredicate
protected final Predicate<IdentifiableType> typePredicate

DslFilteredEquipment(String equipmentType, Predicate<IdentifiableType> typePredicate) {
super(equipmentType)
this.typePredicate = typePredicate
}

DslFilteredEquipment(String equipmentType, String fieldName, Predicate<IdentifiableType> typePredicate) {
super(equipmentType, fieldName)
this.typePredicate = typePredicate
}

@Override
void addEquipment(String equipmentId, Function<String, T> equipmentSupplier) {
staticId = equipmentId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@ import com.powsybl.dynamicsimulation.groovy.DynamicModelGroovyExtension
import com.powsybl.dynawaltz.dsl.AbstractPureDynamicGroovyExtension
import com.powsybl.dynawaltz.dsl.Reporters
import com.powsybl.dynawaltz.dsl.builders.AbstractPureDynamicModelBuilder
import com.powsybl.dynawaltz.dsl.builders.BuildersUtil
import com.powsybl.dynawaltz.models.automatons.TapChangerBlockingAutomaton
import com.powsybl.iidm.network.Bus
import com.powsybl.iidm.network.Identifiable
import com.powsybl.iidm.network.IdentifiableType
import com.powsybl.iidm.network.Load
import com.powsybl.iidm.network.Network
import com.powsybl.iidm.network.TwoWindingsTransformer
import com.powsybl.iidm.network.*

/**
* @author Laurent Issertial {@literal <laurent.issertial at rte-france.com>}
Expand All @@ -43,7 +39,7 @@ class TapChangerBlockingAutomatonGroovyExtension extends AbstractPureDynamicGroo

List<Load> loads = []
List<TwoWindingsTransformer> transformers = []
List<Bus> uMeasurements = []
List<Identifiable> uMeasurements = []
List<String> tapChangerAutomatonIds = []

TCBAutomatonBuilder(Network network, String lib, Reporter reporter) {
Expand Down Expand Up @@ -77,12 +73,27 @@ class TapChangerBlockingAutomatonGroovyExtension extends AbstractPureDynamicGroo
}

void uMeasurements(String[] staticIds) {
uMeasurements = staticIds.collect {
def bus = network.busBreakerView.getBus(it)
if (!bus) {
Reporters.reportStaticIdUnknown(reporter, "uMeasurements", it, IdentifiableType.BUS.toString())
for (staticId in staticIds) {
def measurementPoint = network.getIdentifiable(staticId)
if (!measurementPoint || !BuildersUtil.isActionConnectionPoint(measurementPoint.type)) {
Reporters.reportStaticIdUnknown(reporter, "uMeasurements", staticId, "BUS/BUSBAR_SECTION")
} else {
uMeasurements << measurementPoint
}
}
}

void uMeasurements(List<String>[] staticIdsArray) {
for (staticIds in staticIdsArray) {
for (staticId in staticIds) {
def measurementPoint = network.getIdentifiable(staticId)
if (!measurementPoint || !BuildersUtil.isActionConnectionPoint(measurementPoint.type)) {
Reporters.reportStaticIdUnknown(reporter, "uMeasurements", staticId, "BUS/BUSBAR_SECTION")
} else {
uMeasurements << measurementPoint
break
}
}
bus
}
}

Expand All @@ -91,12 +102,6 @@ class TapChangerBlockingAutomatonGroovyExtension extends AbstractPureDynamicGroo
if (!uMeasurements) {
Reporters.reportFieldNotSet(reporter, "uMeasurements")
isInstantiable = false
} else {
uMeasurements -= null
if (!uMeasurements) {
Reporters.reportEmptyList(reporter, "uMeasurements")
isInstantiable = false
}
}
if(!loads && !transformers && !tapChangerAutomatonIds) {
Reporters.reportEmptyList(reporter, "transformers")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* 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.dsl.builders


import com.powsybl.iidm.network.IdentifiableType

/**
* @author Laurent Issertial {@literal <laurent.issertial at rte-france.com>}
*/
final class BuildersUtil {

private BuildersUtil() {
}

private static final EnumSet<IdentifiableType> ACTION_CONNECTION_POINTS = EnumSet.of(IdentifiableType.BUS, IdentifiableType.BUSBAR_SECTION)

static boolean isActionConnectionPoint(IdentifiableType type) {
return ACTION_CONNECTION_POINTS.contains(type)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.powsybl.dynawaltz.models.generators.WeccGen;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
import com.powsybl.iidm.network.test.FourSubstationsNodeBreakerFactory;
import com.powsybl.iidm.network.test.HvdcTestNetwork;
import com.powsybl.iidm.network.test.SvcTestCaseFactory;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -138,7 +139,8 @@ private static Stream<Arguments> provideAutomatonModelData() {
Arguments.of("/dynamicModels/currentLimit.groovy", CurrentLimitAutomaton.class, EurostagTutorialExample1Factory.create(), "AM_NHV1_NHV2_1", "CLA", "CurrentLimitAutomaton"),
Arguments.of("/dynamicModels/currentLimitTwoLevels.groovy", CurrentLimitTwoLevelsAutomaton.class, EurostagTutorialExample1Factory.create(), "AM_NHV1_NHV2_1", "CLA", "CurrentLimitAutomatonTwoLevels"),
Arguments.of("/dynamicModels/tapChanger.groovy", TapChangerAutomaton.class, EurostagTutorialExample1Factory.create(), "TC", "tc", "TapChangerAutomaton"),
Arguments.of("/dynamicModels/tapChangerBlocking.groovy", TapChangerBlockingAutomaton.class, EurostagTutorialExample1Factory.create(), "ZAB", "ZAB", "TapChangerBlockingAutomaton1"),
Arguments.of("/dynamicModels/tapChangerBlockingBusBar.groovy", TapChangerBlockingAutomaton.class, FourSubstationsNodeBreakerFactory.create(), "ZAB", "ZAB", "TapChangerBlockingAutomaton2"),
Arguments.of("/dynamicModels/tapChangerBlocking.groovy", TapChangerBlockingAutomaton.class, EurostagTutorialExample1Factory.create(), "ZAB", "ZAB", "TapChangerBlockingAutomaton3"),
Arguments.of("/dynamicModels/phaseShifterI.groovy", PhaseShifterIAutomaton.class, EurostagTutorialExample1Factory.create(), "PS_NGEN_NHV1", "ps", "PhaseShifterI"),
Arguments.of("/dynamicModels/phaseShifterP.groovy", PhaseShifterPAutomaton.class, EurostagTutorialExample1Factory.create(), "PS_NGEN_NHV1", "ps", "PhaseShifterP"),
Arguments.of("/dynamicModels/underVoltage.groovy", UnderVoltageAutomaton.class, EurostagTutorialExample1Factory.create(), "UV_GEN", "uv", "UnderVoltageAutomaton")
Expand Down Expand Up @@ -251,8 +253,20 @@ private static Stream<Arguments> provideWarningsModel() {
+ DSL tests
+ Groovy Dynamic Models Supplier
+ DSL model builder for TapChangerBlockingAutomaton
'uMeasurements' field value 'LOAD' not found for equipment type(s) BUS
'uMeasurements' list is empty
'uMeasurements' field value 'LOAD' not found for equipment type(s) BUS/BUSBAR_SECTION
'uMeasurements' field value 'Wrong_ID' not found for equipment type(s) BUS/BUSBAR_SECTION
'uMeasurements' field is not set
Model ZAB cannot be instantiated
"""),
Arguments.of("/warnings/tapChangerMissingBusList.groovy", EurostagTutorialExample1Factory.create(),
"""
+ DSL tests
+ Groovy Dynamic Models Supplier
+ DSL model builder for TapChangerBlockingAutomaton
'uMeasurements' field value 'LOAD' not found for equipment type(s) BUS/BUSBAR_SECTION
'uMeasurements' field value 'Wrong_ID' not found for equipment type(s) BUS/BUSBAR_SECTION
'uMeasurements' field value 'NGEN_NHV1' not found for equipment type(s) BUS/BUSBAR_SECTION
'uMeasurements' field is not set
Model ZAB cannot be instantiated
"""),
Arguments.of("/warnings/tapChangerCompatible.groovy", EurostagTutorialExample1Factory.create(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@

package dynamicModels


TapChangerBlockingAutomaton {
dynamicModelId "ZAB"
parameterSetId "ZAB"
uMeasurements "NGEN"
uMeasurements ["OldId", "NGEN", "NHV1"], ["NHV1", "OldId"], ["NHV2"]
transformers "NGEN_NHV1", "NHV2_NLOAD", "LOAD"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* 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 dynamicModels


TapChangerBlockingAutomaton {
dynamicModelId "ZAB"
parameterSetId "ZAB"
uMeasurements "S1VL2_BBS1", "OldId", "S3VL1_BBS"
transformers "TWT", "LD1"
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ package warnings
TapChangerBlockingAutomaton {
dynamicModelId "ZAB"
parameterSetId "ZAB"
uMeasurements "LOAD"
uMeasurements "LOAD", "Wrong_ID"
transformers "NGEN_NHV1", "NHV2_NLOAD", "LOAD"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* 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 warnings


TapChangerBlockingAutomaton {
dynamicModelId "ZAB"
parameterSetId "ZAB"
uMeasurements ["LOAD", "Wrong_ID"], ["NGEN_NHV1"]
transformers "NGEN_NHV1", "NHV2_NLOAD", "LOAD"
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import com.powsybl.dynawaltz.models.buses.ActionConnectionPoint;
import com.powsybl.dynawaltz.models.macroconnections.MacroConnectionsAdder;
import com.powsybl.dynawaltz.models.transformers.TapChangerModel;
import com.powsybl.iidm.network.Bus;
import com.powsybl.iidm.network.Identifiable;
import com.powsybl.iidm.network.IdentifiableType;
import com.powsybl.iidm.network.Load;
import com.powsybl.iidm.network.TwoWindingsTransformer;
Expand All @@ -36,10 +36,10 @@ public class TapChangerBlockingAutomaton extends AbstractPureDynamicBlackBoxMode
private final List<TwoWindingsTransformer> transformers;
private final List<Load> loadsWithTransformer;
private final List<String> tapChangerAutomatonIds;
private final List<Bus> uMeasurements;
private final List<Identifiable<?>> uMeasurements;
private boolean isConnected = true;

public TapChangerBlockingAutomaton(String dynamicModelId, String parameterSetId, List<TwoWindingsTransformer> transformers, List<Load> loadsWithTransformer, List<String> tapChangerAutomatonIds, List<Bus> uMeasurements) {
public TapChangerBlockingAutomaton(String dynamicModelId, String parameterSetId, List<TwoWindingsTransformer> transformers, List<Load> loadsWithTransformer, List<String> tapChangerAutomatonIds, List<Identifiable<?>> uMeasurements) {
super(dynamicModelId, parameterSetId);
this.transformers = Objects.requireNonNull(transformers);
this.loadsWithTransformer = Objects.requireNonNull(loadsWithTransformer);
Expand All @@ -56,11 +56,11 @@ public TapChangerBlockingAutomaton(String dynamicModelId, String parameterSetId,
}
}

public TapChangerBlockingAutomaton(String dynamicModelId, String parameterSetId, List<TwoWindingsTransformer> transformers, List<Load> loadsWithTransformer, List<Bus> uMeasurements) {
public TapChangerBlockingAutomaton(String dynamicModelId, String parameterSetId, List<TwoWindingsTransformer> transformers, List<Load> loadsWithTransformer, List<Identifiable<?>> uMeasurements) {
this(dynamicModelId, parameterSetId, transformers, loadsWithTransformer, Collections.emptyList(), uMeasurements);
}

public TapChangerBlockingAutomaton(String dynamicModelId, String parameterSetId, List<TwoWindingsTransformer> transformers, List<Bus> uMeasurements) {
public TapChangerBlockingAutomaton(String dynamicModelId, String parameterSetId, List<TwoWindingsTransformer> transformers, List<Identifiable<?>> uMeasurements) {
this(dynamicModelId, parameterSetId, transformers, Collections.emptyList(), Collections.emptyList(), uMeasurements);
}

Expand Down Expand Up @@ -97,8 +97,8 @@ public void createMacroConnections(MacroConnectionsAdder adder) {
}
if (!transformers.isEmpty() || skippedTapChangers < (loadsWithTransformer.size() + tapChangerAutomatonIds.size())) {
int i = 1;
for (Bus bus : uMeasurements) {
adder.createMacroConnections(this, bus, ActionConnectionPoint.class, this::getVarConnectionsWith, MeasurementPointSuffix.of(i));
for (Identifiable<?> measurement : uMeasurements) {
adder.createMacroConnections(this, measurement, ActionConnectionPoint.class, this::getVarConnectionsWith, MeasurementPointSuffix.of(i));
i++;
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
*/
public enum DefaultModelConfiguration {

ACTION_CONNECTION_POINT_BBS(IdentifiableType.BUSBAR_SECTION,
ActionConnectionPoint.class,
new DefaultModelFactory<>(DefaultActionConnectionPoint::new)),
ACTION_CONNECTION_POINT(IdentifiableType.BUS,
ActionConnectionPoint.class,
new DefaultModelFactory<>(DefaultActionConnectionPoint::new)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;

import static java.util.stream.Collectors.groupingBy;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.powsybl.dynawaltz.models.loads.LoadTwoTransformersTapChangers;
import com.powsybl.dynawaltz.models.transformers.TransformerFixedRatio;
import com.powsybl.iidm.network.Bus;
import com.powsybl.iidm.network.Identifiable;
import com.powsybl.iidm.network.TwoWindingsTransformer;
import com.powsybl.iidm.network.VoltageLevel;
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
Expand Down Expand Up @@ -61,9 +62,9 @@ void writeModel() throws SAXException, IOException, XMLStreamException {
@Test
void testMonitoredEquipmentsLimit() {

List<Bus> buses = List.of(network.getBusBreakerView().getBus("NHV1"));
List<Identifiable<?>> buses = List.of(network.getBusBreakerView().getBus("NHV1"));
List<TwoWindingsTransformer> transformers = List.of(network.getTwoWindingsTransformer("NGEN_NHV1"));
List<Bus> tooManyBuses = List.of(network.getBusBreakerView().getBus("NHV1"),
List<Identifiable<?>> tooManyBuses = List.of(network.getBusBreakerView().getBus("NHV1"),
network.getBusBreakerView().getBus("NHV1"),
network.getBusBreakerView().getBus("NHV1"),
network.getBusBreakerView().getBus("NHV1"),
Expand Down

0 comments on commit ffa7475

Please sign in to comment.