Skip to content

Commit

Permalink
Add reporter to MacroConnectionsAdder
Browse files Browse the repository at this point in the history
Signed-off-by: lisrte <[email protected]>
  • Loading branch information
Lisrte committed Nov 24, 2023
1 parent 108678b commit f35843b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public class DynaWaltzContext {
private static final String MODEL_ID_EXCEPTION = "The model identified by the static id %s does not match the expected model (%s)";
private static final String MODEL_ID_LOG = "The model identified by the static id {} does not match the expected model ({})";

private final Reporter reporter;
private final Network network;
private final String workingVariantId;
private final DynamicSimulationParameters parameters;
Expand All @@ -72,20 +71,20 @@ public DynaWaltzContext(Network network, String workingVariantId, List<BlackBoxM
public DynaWaltzContext(Network network, String workingVariantId, List<BlackBoxModel> dynamicModels, List<BlackBoxModel> eventModels,
List<Curve> curves, DynamicSimulationParameters parameters, DynaWaltzParameters dynaWaltzParameters, Reporter reporter) {

this.reporter = DynawaltzReports.createDynaWaltzContextReporter(reporter);
Reporter contextReporter = DynawaltzReports.createDynaWaltzContextReporter(reporter);
this.network = Objects.requireNonNull(network);
this.workingVariantId = Objects.requireNonNull(workingVariantId);

this.dynamicModels = Objects.requireNonNull(dynamicModels).stream()
.filter(distinctByDynamicId(reporter).and(distinctByStaticId(reporter)))
.filter(distinctByDynamicId(contextReporter).and(distinctByStaticId(contextReporter)))
.toList();
this.staticIdBlackBoxModelMap = getInputBlackBoxDynamicModelStream()
.filter(EquipmentBlackBoxModel.class::isInstance)
.map(EquipmentBlackBoxModel.class::cast)
.collect(Collectors.toMap(EquipmentBlackBoxModel::getStaticId, Function.identity()));

this.eventModels = Objects.requireNonNull(eventModels).stream()
.filter(distinctByDynamicId())
.filter(distinctByDynamicId(contextReporter))
.map(setLateInitEventField())
.toList();

Expand All @@ -96,7 +95,8 @@ public DynaWaltzContext(Network network, String workingVariantId, List<BlackBoxM
this.macroConnectionsAdder = new MacroConnectionsAdder(this::getDynamicModel,
this::getPureDynamicModel,
macroConnectList::add,
macroConnectorsMap::computeIfAbsent);
macroConnectorsMap::computeIfAbsent,
contextReporter);

for (BlackBoxModel bbm : getBlackBoxDynamicModelStream().toList()) {
macroStaticReferences.computeIfAbsent(bbm.getName(), k -> new MacroStaticReference(k, bbm.getVarsMapping()));
Expand Down Expand Up @@ -261,8 +261,4 @@ public List<ParametersSet> getDynamicModelsParameters() {
public String getSimulationParFile() {
return getNetwork().getId() + ".par";
}

public Reporter getReporter() {
return reporter;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void createMacroConnections(MacroConnectionsAdder adder) {
boolean isSkipped = adder.createMacroConnectionsOrSkip(this, load, LoadWithTransformers.class, this::getVarConnectionsWith);
if (isSkipped) {
connection = ConnectionState.NOT_CONNECTED;
DynawaltzReports.reportEmptyTapChanger(context.getReporter(), getDynamicModelId());
DynawaltzReports.reportEmptyTapChanger(adder.getReporter(), getDynamicModelId());
} else {
connection = ConnectionState.CONNECTED;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void createMacroConnections(MacroConnectionsAdder adder) {
}
} else {
isConnected = false;
DynawaltzReports.reportEmptyTapChangerBlockingAutomaton(context.getReporter(), getDynamicModelId());
DynawaltzReports.reportEmptyTapChangerBlockingAutomaton(adder.getReporter(), getDynamicModelId());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
package com.powsybl.dynawaltz.models.macroconnections;

import com.powsybl.commons.reporter.Reporter;
import com.powsybl.dynawaltz.models.BlackBoxModel;
import com.powsybl.dynawaltz.models.Model;
import com.powsybl.dynawaltz.models.Side;
Expand All @@ -22,7 +23,10 @@

import java.util.Arrays;
import java.util.List;
import java.util.function.*;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand All @@ -41,17 +45,19 @@ public interface PureDynamicModelGetter {
<T extends Model> T getPureDynamicModel(String dynamicId, Class<T> connectableClass, boolean throwException);
}

private final Reporter reporter;
private final DynamicModelGetter dynamicModelGetter;
private final PureDynamicModelGetter pureDynamicModelGetter;
private Consumer<MacroConnect> macroConnectAdder;
private BiConsumer<String, Function<String, MacroConnector>> macroConnectorAdder;

public MacroConnectionsAdder(DynamicModelGetter dynamicModelGetter, PureDynamicModelGetter pureDynamicModelGetter,
Consumer<MacroConnect> macroConnectAdder, BiConsumer<String, Function<String, MacroConnector>> macroConnectorAdder) {
public MacroConnectionsAdder(DynamicModelGetter dynamicModelGetter, PureDynamicModelGetter pureDynamicModelGetter, Consumer<MacroConnect> macroConnectAdder,
BiConsumer<String, Function<String, MacroConnector>> macroConnectorAdder, Reporter reporter) {
this.dynamicModelGetter = dynamicModelGetter;
this.pureDynamicModelGetter = pureDynamicModelGetter;
this.macroConnectAdder = macroConnectAdder;
this.macroConnectorAdder = macroConnectorAdder;
this.reporter = reporter;
}

/**
Expand Down Expand Up @@ -224,4 +230,8 @@ public void setMacroConnectAdder(Consumer<MacroConnect> macroConnectAdder) {
public void setMacroConnectorAdder(BiConsumer<String, Function<String, MacroConnector>> macroConnectorAdder) {
this.macroConnectorAdder = macroConnectorAdder;
}

public Reporter getReporter() {
return reporter;
}
}

0 comments on commit f35843b

Please sign in to comment.