Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Dupuy <[email protected]>
  • Loading branch information
flo-dup committed Dec 13, 2023
1 parent 96c0f0f commit 6d9975b
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,14 @@ public DynaWaltzContext(Network network, String workingVariantId, List<BlackBoxM

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

// Late init on ContextDependentEvents
this.eventModels.stream()
.filter(ContextDependentEvent.class::isInstance)
.map(ContextDependentEvent.class::cast)
.forEach(e -> e.setEquipmentHasDynamicModel(this));

this.curves = Objects.requireNonNull(curves);
this.parameters = Objects.requireNonNull(parameters);
this.dynaWaltzParameters = Objects.requireNonNull(dynaWaltzParameters);
Expand Down Expand Up @@ -201,15 +206,6 @@ protected static Predicate<BlackBoxModel> distinctByDynamicId(Reporter reporter)
};
}

protected Function<BlackBoxModel, BlackBoxModel> setLateInitEventField() {
return blackBoxModel -> {
if (blackBoxModel instanceof ContextDependentEvent event) {
event.setEquipmentHasDynamicModel(this);
}
return blackBoxModel;
};
}

public boolean hasDynamicModel(Identifiable<?> equipment) {
return staticIdBlackBoxModelMap.containsKey(equipment.getId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public final class DefaultEquipmentConnectionPoint implements EquipmentConnectio
private DefaultEquipmentConnectionPoint() {
}

public static DefaultEquipmentConnectionPoint getDefaultModel(String staticId) {
public static DefaultEquipmentConnectionPoint getDefaultModel() {
return INSTANCE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public enum DefaultModelConfiguration {
new DefaultModelFactory<>(DefaultActionConnectionPoint::new)),
EQUIPMENT_CONNECTION_POINT(IdentifiableType.BUS,
EquipmentConnectionPoint.class,
DefaultEquipmentConnectionPoint::getDefaultModel),
staticId -> DefaultEquipmentConnectionPoint.getDefaultModel()),
GENERATOR(IdentifiableType.GENERATOR,
GeneratorModel.class,
new DefaultModelFactory<>(DefaultGenerator::new)),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* 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.defaultmodels;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ default double getWeightGen(DynaWaltzParameters dynaWaltzParameters) {

String getStaticId();

Bus getConnectesBus();
Bus getConnectableBus();
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void createMacroConnections(MacroConnectionsAdder adder) throws PowsyblEx
for (FrequencySynchronizedModel eq : synchronizedEquipments) {
adder.createMacroConnections(this, eq, getVarConnectionsWith(eq), MacroConnectAttribute.ofIndex1(index));
// If a bus with a dynamic model is found SetPoint is used in place of OmegaRef, thus at this point we don't have to handle dynamic model buses
BusOfFrequencySynchronizedModel busOf = new DefaultBusOfFrequencySynchronized(eq.getConnectesBus().getId(), eq.getStaticId());
BusOfFrequencySynchronizedModel busOf = new DefaultBusOfFrequencySynchronized(eq.getConnectableBus().getId(), eq.getStaticId());
adder.createMacroConnections(this, busOf, getVarConnectionsWithBus(busOf), MacroConnectAttribute.ofIndex1(index));
index++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public List<VarMapping> getVarsMapping() {
}

@Override
public Bus getConnectesBus() {
public Bus getConnectableBus() {
return BusUtils.getConnectableBus(equipment);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public String getOmegaRefPuVarName() {
}

@Override
public Bus getConnectesBus() {
public Bus getConnectableBus() {
return BusUtils.getConnectableBus(equipment);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public String getRunningVarName() {
}

@Override
public Bus getConnectesBus() {
public Bus getConnectableBus() {
return BusUtils.getConnectableBus(equipment);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public final T getValue() {
}

public final void setValue(T value) {
if (this.value != null) {
throw new PowsyblException("Field has already been initialized");
}
this.value = Objects.requireNonNull(value);
}
}

0 comments on commit 6d9975b

Please sign in to comment.