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

Builder list setter #330

Merged
merged 6 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -40,6 +40,7 @@ class DynaWaltzDynamicModelGroovyExtension implements DynamicModelGroovyExtensio
builderConfigs.stream().flatMap { it -> it.libs}.toList() as List<String>
}


@Override
void load(Binding binding, Consumer<DynamicModel> consumer, Reporter reporter) {
builderConfigs.forEach {conf ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,8 @@ 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/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 value '[LOAD, 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' list is empty
Model ZAB cannot be instantiated
"""),
Expand All @@ -275,8 +274,9 @@ private static Stream<Arguments> provideWarningsModel() {
+ DSL tests
+ Groovy Dynamic Models Supplier
+ DSL model builder for TapChangerBlockingAutomaton
'uMeasurements' field value 'GEN' not found for equipment type(s) LOAD/TWO_WINDINGS_TRANSFORMER
'transformers' list is empty
'transformers' field value 'GEN' not found for equipment type(s) TWO_WINDINGS_TRANSFORMER/LOAD, id will be used as pure dynamic model id
'uMeasurements' field value 'GEN' not found for equipment type(s) BUS/BUSBAR_SECTION
'uMeasurements' list is empty
Model ZAB cannot be instantiated
"""),
Arguments.of("/warnings/hvdcVscWrongStaticType.groovy", HvdcTestNetwork.createLcc(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@

package dynamicModels

List[] measurements = [["OldId", "NGEN", "NHV1"], ["NHV1", "OldId"], ["NHV2"]]

TapChangerBlockingAutomaton {
dynamicModelId "ZAB"
parameterSetId "ZAB"
uMeasurements ["OldId", "NGEN", "NHV1"], ["NHV1", "OldId"], ["NHV2"]
uMeasurements measurements
transformers "NGEN_NHV1", "NHV2_NLOAD", "LOAD"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

package dynamicModels

def measurements = ["S1VL2_BBS1", "OldId", "S3VL1_BBS"]

TapChangerBlockingAutomaton {
dynamicModelId "ZAB"
parameterSetId "ZAB"
uMeasurements "S1VL2_BBS1", "OldId", "S3VL1_BBS"
uMeasurements measurements
transformers "TWT", "LD1"
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
* 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 "NGEN"
uMeasurements "GEN"
transformers "GEN"
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* SPDX-License-Identifier: MPL-2.0
*/

package warnings

List[] measurementPoints = [["LOAD", "Wrong_ID"], ["NGEN_NHV1"]]

TapChangerBlockingAutomaton {
dynamicModelId "ZAB"
parameterSetId "ZAB"
uMeasurements ["LOAD", "Wrong_ID"], ["NGEN_NHV1"]
uMeasurements measurementPoints
transformers "NGEN_NHV1", "NHV2_NLOAD", "LOAD"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/**
* Copyright (c) 2024, 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.builders;

import com.powsybl.commons.reporter.Reporter;
import com.powsybl.iidm.network.Identifiable;
import com.powsybl.iidm.network.IdentifiableType;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;

/**
* @author Laurent Issertial {@literal <laurent.issertial at rte-france.com>}
*/
public class BuilderEquipmentsList<T extends Identifiable<?>> {

private final String equipmentType;
private final String fieldName;
// when set to true equipment ids not found in the network are seen as dynamic ids for automatons and reported as such
private final boolean missingIdsHasDynamicIds;
Lisrte marked this conversation as resolved.
Show resolved Hide resolved
protected List<String> missingEquipmentIds = new ArrayList<>();
protected final List<T> equipments = new ArrayList<>();

public BuilderEquipmentsList(IdentifiableType identifiableType, String fieldName) {
this(identifiableType.toString(), fieldName, false);
}

public BuilderEquipmentsList(String equipmentType, String fieldName) {
this(equipmentType, fieldName, false);
}

public BuilderEquipmentsList(String equipmentType, String fieldName, boolean missingIdsHasDynamicIds) {
this.equipmentType = equipmentType;
this.fieldName = fieldName;
this.missingIdsHasDynamicIds = missingIdsHasDynamicIds;
}

public void addEquipments(String[] staticIds, Function<String, T> equipmentsSupplier) {
addEquipments(() -> Arrays.stream(staticIds).iterator(), equipmentsSupplier);
}

public void addEquipments(Iterable<String> staticIds, Function<String, T> equipmentsSupplier) {
staticIds.forEach(id -> {
T equipment = equipmentsSupplier.apply(id);
if (equipment != null) {
equipments.add(equipment);
} else {
missingEquipmentIds.add(id);
}
});
}

public boolean checkEquipmentData(Reporter reporter) {
boolean emptyList = equipments.isEmpty();
if (missingEquipmentIds.isEmpty() && emptyList) {
Reporters.reportFieldNotSet(reporter, fieldName);
return false;
} else if (!missingIdsHasDynamicIds) {
missingEquipmentIds.forEach(missingId ->
Reporters.reportStaticIdUnknown(reporter, fieldName, missingId, equipmentType));
if (emptyList) {
Reporters.reportEmptyList(reporter, fieldName);
}
return !emptyList;
} else {
missingEquipmentIds.forEach(missingId ->
Reporters.reportUnknownStaticIdHandling(reporter, fieldName, missingId, equipmentType));
return true;
}
}

public List<T> getEquipments() {
return equipments;
}

public List<String> getMissingEquipmentIds() {
return missingEquipmentIds;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright (c) 2024, 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.builders;

import com.powsybl.iidm.network.Identifiable;

import java.util.Collection;
import java.util.Objects;
import java.util.function.Function;

/**
* @author Laurent Issertial {@literal <laurent.issertial at rte-france.com>}
*/
public class BuilderIdListEquipmentList<T extends Identifiable<?>> extends BuilderEquipmentsList<T> {

public BuilderIdListEquipmentList(String equipmentType, String fieldName) {
super(equipmentType, fieldName);
}

public void addEquipments(Collection<String>[] staticIdsArray, Function<String, T> equipmentSupplier) {
for (Collection<String> staticIds : staticIdsArray) {
addEquipment(staticIds, equipmentSupplier);
}
}

private void addEquipment(Collection<String> staticIds, Function<String, T> equipmentSupplier) {
staticIds.stream()
.map(equipmentSupplier)
.filter(Objects::nonNull)
.findFirst()
.ifPresentOrElse(equipments::add,
() -> missingEquipmentIds.add(staticIds.toString()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
package com.powsybl.dynawaltz.builders;

import com.powsybl.iidm.network.Identifiable;
import com.powsybl.iidm.network.IdentifiableType;
import com.powsybl.iidm.network.Network;

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

public static final String MEASUREMENT_POINT_TYPE = IdentifiableType.BUS + "/" + IdentifiableType.BUSBAR_SECTION;

private BuildersUtil() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static void reportFieldNotSet(Reporter reporter, String fieldName) {

public static void reportStaticIdUnknown(Reporter reporter, String fieldName, String staticId, String equipmentType) {
reporter.report(Report.builder()
.withKey("staticIdUnknown")
.withKey("unknownStaticIdToDynamic")
.withDefaultMessage("'${fieldName}' field value '${staticId}' not found for equipment type(s) ${equipmentType}")
.withValue("equipmentType", equipmentType)
.withValue(FIELD_NAME, fieldName)
Expand All @@ -92,6 +92,16 @@ public static void reportDifferentNetwork(Reporter reporter, String fieldName, S
.build());
}

public static void reportUnknownStaticIdHandling(Reporter reporter, String fieldName, String staticId, String equipmentType) {
reporter.report(Report.builder()
.withKey("staticIdUnknown")
.withDefaultMessage("'${fieldName}' field value '${staticId}' not found for equipment type(s) ${equipmentType}, id will be used as pure dynamic model id")
.withValue("equipmentType", equipmentType)
.withValue(FIELD_NAME, fieldName).withValue("staticId", staticId)
.withSeverity(TypedValue.INFO_SEVERITY)
.build());
}

public static void reportCrossThreshold(Reporter reporter, String fieldName, double fieldValue, String threshold) {
reporter.report(Report.builder()
.withKey("crossThreshold")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import com.powsybl.dynawaltz.models.transformers.TapChangerModel;
import com.powsybl.iidm.network.Identifiable;
import com.powsybl.iidm.network.IdentifiableType;
import com.powsybl.iidm.network.Load;
import com.powsybl.iidm.network.TwoWindingsTransformer;

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
Expand All @@ -33,19 +31,17 @@ public class TapChangerBlockingAutomaton extends AbstractPureDynamicBlackBoxMode
private static final Set<IdentifiableType> COMPATIBLE_EQUIPMENTS = EnumSet.of(IdentifiableType.LOAD, IdentifiableType.TWO_WINDINGS_TRANSFORMER);
private static final int MAX_MEASUREMENTS = 5;

private final List<TwoWindingsTransformer> transformers;
private final List<Load> loadsWithTransformer;
private final List<Identifiable<?>> tapChangerEquipments;
private final List<String> tapChangerAutomatonIds;
private final List<Identifiable<?>> uMeasurements;
private boolean isConnected = true;

protected TapChangerBlockingAutomaton(String dynamicModelId, String parameterSetId, List<TwoWindingsTransformer> transformers, List<Load> loadsWithTransformer, List<String> tapChangerAutomatonIds, List<Identifiable<?>> uMeasurements, String lib) {
protected TapChangerBlockingAutomaton(String dynamicModelId, String parameterSetId, List<Identifiable<?>> tapChangerEquipments, List<String> tapChangerAutomatonIds, List<Identifiable<?>> uMeasurements, String lib) {
super(dynamicModelId, parameterSetId, lib);
this.transformers = Objects.requireNonNull(transformers);
this.loadsWithTransformer = Objects.requireNonNull(loadsWithTransformer);
this.tapChangerEquipments = Objects.requireNonNull(tapChangerEquipments);
this.tapChangerAutomatonIds = Objects.requireNonNull(tapChangerAutomatonIds);
this.uMeasurements = Objects.requireNonNull(uMeasurements);
if (transformers.isEmpty() && loadsWithTransformer.isEmpty() && tapChangerAutomatonIds.isEmpty()) {
if (tapChangerEquipments.isEmpty() && tapChangerAutomatonIds.isEmpty()) {
throw new PowsyblException("No Tap changers to monitor");
}
if (uMeasurements.isEmpty()) {
Expand All @@ -72,13 +68,9 @@ public String getLib() {

@Override
public void createMacroConnections(MacroConnectionsAdder adder) {
for (TwoWindingsTransformer transformer : transformers) {
adder.createMacroConnections(this, transformer, TapChangerModel.class, this::getVarConnectionsWith);
}
int skippedTapChangers = 0;
for (Load load : loadsWithTransformer) {
boolean isSkipped = adder.createMacroConnectionsOrSkip(this, load, TapChangerModel.class, this::getVarConnectionsWith);
if (isSkipped) {
for (Identifiable<?> tc : tapChangerEquipments) {
if (adder.createMacroConnectionsOrSkip(this, tc, TapChangerModel.class, this::getVarConnectionsWith)) {
skippedTapChangers++;
}
}
Expand All @@ -87,7 +79,7 @@ public void createMacroConnections(MacroConnectionsAdder adder) {
skippedTapChangers++;
}
}
if (!transformers.isEmpty() || skippedTapChangers < (loadsWithTransformer.size() + tapChangerAutomatonIds.size())) {
if (skippedTapChangers < (tapChangerEquipments.size() + tapChangerAutomatonIds.size())) {
int i = 1;
for (Identifiable<?> measurement : uMeasurements) {
adder.createMacroConnections(this, measurement, ActionConnectionPoint.class, this::getVarConnectionsWith, MeasurementPointSuffix.of(i));
Expand All @@ -104,7 +96,6 @@ private List<VarConnection> getVarConnectionsWith(TapChangerModel connected) {
}

private List<VarConnection> getVarConnectionsWith(ActionConnectionPoint connected, String suffix) {

return connected.getUImpinVarName()
.map(uImpinVarName -> List.of(new VarConnection("tapChangerBlocking_UMonitored" + suffix, uImpinVarName)))
.orElse(Collections.emptyList());
Expand Down
Loading
Loading