-
Notifications
You must be signed in to change notification settings - Fork 0
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
Share code for network modifications #524
Conversation
Signed-off-by: Mathieu DEHARBE <[email protected]>
Signed-off-by: Mathieu DEHARBE <[email protected]>
Signed-off-by: Mathieu DEHARBE <[email protected]>
Signed-off-by: Mathieu DEHARBE <[email protected]>
Signed-off-by: Mathieu DEHARBE <[email protected]>
Signed-off-by: Mathieu DEHARBE <[email protected]>
…ions' into share-code-for-network-modifications
Signed-off-by: Mathieu DEHARBE <[email protected]>
Signed-off-by: Mathieu DEHARBE <[email protected]>
Signed-off-by: Mathieu DEHARBE <[email protected]>
Signed-off-by: Mathieu DEHARBE <[email protected]>
Signed-off-by: Mathieu DEHARBE <[email protected]>
Signed-off-by: Mathieu DEHARBE <[email protected]>
Signed-off-by: Mathieu DEHARBE <[email protected]>
Signed-off-by: Mathieu DEHARBE <[email protected]>
Signed-off-by: Mathieu DEHARBE <[email protected]>
Signed-off-by: Mathieu DEHARBE <[email protected]>
Signed-off-by: Mathieu DEHARBE <[email protected]>
Signed-off-by: Mathieu DEHARBE <[email protected]>
Signed-off-by: Mathieu DEHARBE <[email protected]>
@@ -36,14 +43,28 @@ public static Double getReferenceValue(Battery battery, String batteryField) { | |||
|
|||
public static void setNewValue(Battery battery, String batteryField, Double newValue) { | |||
BatteryField field = BatteryField.valueOf(batteryField); | |||
final AttributeModification<Double> modif = new AttributeModification<>(newValue, OperationType.SET); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doubleAttributeModification ? or attributeModification
use variable name more descriptive
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is attributeModif
enough ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I renamed it to the whole attributeModification.
case ACTIVE_POWER_SET_POINT -> { | ||
ModificationUtils.getInstance().checkActivePowerZeroOrBetweenMinAndMaxActivePower( | ||
modif, null, null, battery.getMinP(), | ||
battery.getMaxP(), battery.getTargetP(), MODIFY_GENERATOR_ERROR, "Battery '" + battery.getId() + "' : " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MODIFY_BATTERY_ERROR
ActivePowerControlAdder<Battery> activePowerControlAdder = battery.newExtension(ActivePowerControlAdder.class); | ||
ModificationUtils.getInstance().modifyActivePowerControlAttributes( | ||
activePowerControl, activePowerControlAdder, null, | ||
new AttributeModification<>(newValue.floatValue(), OperationType.SET), null, null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check for null before converting it to a float
you can use optional to handle null safely like
Optional.ofNullable(newValue) .map(Double::floatValue) ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added @NotNull
to the Double newValue
parameter.
import org.gridsuite.modification.server.dto.OperationType; | ||
import org.gridsuite.modification.server.modifications.ModificationUtils; | ||
|
||
import static org.gridsuite.modification.server.NetworkModificationException.Type.MODIFY_GENERATOR_ERROR; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Battery exception type !
GeneratorField field = GeneratorField.valueOf(generatorField); | ||
final AttributeModification<Double> attrModif = new AttributeModification<>(newValue, OperationType.SET); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And same as well.
case PHASE_LOW_TAP_POSITION -> phaseTapChanger.setLowTapPosition(newValue.intValue()); | ||
case PHASE_TAP_POSITION -> phaseTapChanger.setTapPosition(newValue.intValue()); | ||
case PHASE_TARGET_DEADBAND -> phaseTapChanger.setTargetDeadband(newValue); | ||
case R -> modifyBranchFields(transformer, attrModif, null, null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modifyAttributeR ? or modifyR ?
same remarq for X attribute
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure why but those field got put together and called branch specific fields in the function modifyCharacteristics
. They also have a BranchModificationInfos
object joining them. So I kept them together.
But ok let's separate them. We'll see.
ReportNode subReporterSetpoints) { | ||
List<ReportNode> reports = new ArrayList<>(); | ||
if (activePowerControl != null) { | ||
modifyExistingActivePowerControl(activePowerControl, participateInfo, droopInfo, reports); | ||
} else { | ||
createNewActivePowerControl(activePowerControlAdder, participateInfo, droopInfo, reports); | ||
} | ||
if (subReportNode == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the end of the function is all about reports. But this is not clear, I reversed it. Let me know if this is ok.
AttributeModification<Double> ipMax, | ||
ReportNode subReportNode, | ||
VoltageLevel voltageLevel) { | ||
if (ipMin == null && ipMax == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have to report this case ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so : in the case of a regular network modification most value are null (which means not modified). So this case is simply ignored. In the case of modification by formula, null fields are detected much sooner.
.buildModificationReport(oldIpMaxToReport, newIpMaxToReport, "High short circuit current limit")); | ||
} else if (oldIpMax != null) { | ||
identifiableShortCircuitAdder.withIpMax(oldIpMax); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to optimize and refacto this code I suggest something like
private void updateShortCircuitLimits(ValueWrapper ipMin, ValueWrapper ipMax, Double oldIpMin, Double oldIpMax, IdentifiableShortCircuitAdder identifiableShortCircuitAdder, List<ModificationReport> reports) {
updateShortCircuitLimit(ipMin, oldIpMin, "Low short circuit current limit", identifiableShortCircuitAdder::withIpMin, reports);
updateShortCircuitLimit(ipMax, oldIpMax, "High short circuit current limit", identifiableShortCircuitAdder::withIpMax, reports);
}
private void updateShortCircuitLimit(ValueWrapper newValueWrapper, Double oldValue, String limitDescription,
Consumer<Double> setterMethod, List<ModificationReport> reports) {
Double newValue = (newValueWrapper != null) ? newValueWrapper.getValue() : null;
if (newValue != null) {
setterMethod.accept(newValue);
Double oldValueToReport = convertToKiloAmps(oldValue);
Double newValueToReport = convertToKiloAmps(newValue);
reports.add(ModificationUtils.getInstance().buildModificationReport(oldValueToReport, newValueToReport, limitDescription));
} else if (oldValue != null) {
setterMethod.accept(oldValue);
}
}
private Double convertToKiloAmps(Double value) {
return (value != null) ? value * 0.001 : null;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks nice. I tried to integrate it but it broke the unit tests, I don't know why. So I just kept convertToKiloAmps
.
double oldMagnetizingConductanceToReport = transformer.getG() * Math.pow(10, 6); | ||
double newMagnetizingConductanceToReport = modifG.getValue() * Math.pow(10, 6); | ||
insertReportNode(reportNode, ModificationUtils.getInstance().buildModificationReportWithIndentation(oldMagnetizingConductanceToReport, | ||
newMagnetizingConductanceToReport, "Magnetizing conductance", 1)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Constants for Keys
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like this ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
little comments
twoWindingsTransformer.setRatedU1(twoWindingsTransformerModificationInfos.getRatedU1().getValue()); | ||
} | ||
|
||
public static void modifyBranchFields(TwoWindingsTransformer twt, AttributeModification<Double> modifR, AttributeModification<Double> modifX, ReportNode reportNode) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change name and maybe separate in two methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one for R and one for X
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha you agree with Ghazwa. Done.
...java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerModification.java
Show resolved
Hide resolved
...java/org/gridsuite/modification/server/modifications/GeneratorByFormulaModificationTest.java
Show resolved
Hide resolved
Signed-off-by: Mathieu DEHARBE <[email protected]>
…ion-server into share-code-for-network-modifications Signed-off-by: Mathieu DEHARBE <[email protected]> # Conflicts: # src/main/java/org/gridsuite/modification/server/modifications/GeneratorModification.java # src/main/java/org/gridsuite/modification/server/modifications/ModificationUtils.java # src/main/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerModification.java
Signed-off-by: Mathieu DEHARBE <[email protected]>
…ions' into share-code-for-network-modifications
Signed-off-by: Mathieu DEHARBE <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I renamed it to the whole attributeModification
.
Many merge conflicts are solved in the last commits.
@@ -36,14 +43,28 @@ public static Double getReferenceValue(Battery battery, String batteryField) { | |||
|
|||
public static void setNewValue(Battery battery, String batteryField, Double newValue) { | |||
BatteryField field = BatteryField.valueOf(batteryField); | |||
final AttributeModification<Double> modif = new AttributeModification<>(newValue, OperationType.SET); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is attributeModif
enough ?
ActivePowerControlAdder<Battery> activePowerControlAdder = battery.newExtension(ActivePowerControlAdder.class); | ||
ModificationUtils.getInstance().modifyActivePowerControlAttributes( | ||
activePowerControl, activePowerControlAdder, null, | ||
new AttributeModification<>(newValue.floatValue(), OperationType.SET), null, null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added @NotNull
to the Double newValue
parameter.
GeneratorField field = GeneratorField.valueOf(generatorField); | ||
final AttributeModification<Double> attrModif = new AttributeModification<>(newValue, OperationType.SET); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And same as well.
@@ -28,8 +33,8 @@ public static Double getReferenceValue(Load load, String loadField) { | |||
public static void setNewValue(Load load, String loadField, Double newValue) { | |||
LoadField field = LoadField.valueOf(loadField); | |||
switch (field) { | |||
case ACTIVE_POWER -> load.setP0(newValue); | |||
case REACTIVE_POWER -> load.setQ0(newValue); | |||
case ACTIVE_POWER -> modifyP0(load, new AttributeModification<>(newValue, OperationType.SET), null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But P0 is an attribute. Therefore attribute
is implicit ?
case ACTIVE_POWER -> load.setP0(newValue); | ||
case REACTIVE_POWER -> load.setQ0(newValue); | ||
case ACTIVE_POWER -> modifyP0(load, new AttributeModification<>(newValue, OperationType.SET), null); | ||
case REACTIVE_POWER -> modifyQ0(load, new AttributeModification<>(newValue, OperationType.SET), null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same remark.
twoWindingsTransformer.setRatedU1(twoWindingsTransformerModificationInfos.getRatedU1().getValue()); | ||
} | ||
|
||
public static void modifyBranchFields(TwoWindingsTransformer twt, AttributeModification<Double> modifR, AttributeModification<Double> modifX, ReportNode reportNode) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha you agree with Ghazwa. Done.
...java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerModification.java
Show resolved
Hide resolved
AttributeModification<Double> ipMax, | ||
ReportNode subReportNode, | ||
VoltageLevel voltageLevel) { | ||
if (ipMin == null && ipMax == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so : in the case of a regular network modification most value are null (which means not modified). So this case is simply ignored. In the case of modification by formula, null fields are detected much sooner.
.buildModificationReport(oldIpMaxToReport, newIpMaxToReport, "High short circuit current limit")); | ||
} else if (oldIpMax != null) { | ||
identifiableShortCircuitAdder.withIpMax(oldIpMax); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks nice. I tried to integrate it but it broke the unit tests, I don't know why. So I just kept convertToKiloAmps
.
...java/org/gridsuite/modification/server/modifications/GeneratorByFormulaModificationTest.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few more comments and it is good for me
@@ -61,86 +66,42 @@ public static Double getReferenceValue(Generator generator, String generatorFiel | |||
}; | |||
} | |||
|
|||
public static void setNewValue(Generator generator, String generatorField, Double newValue) { | |||
public static void setNewValue(Generator generator, String generatorField, @NotNull Double newValue) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should it be better to set a primitive type (double), it forces to be not null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not. Done.
} | ||
} | ||
report(formulaSubReporter, formulaReports); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are you sure ? the second
report(formulaSubReporter, formulaReports);
is in another if loop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, pretty sure.
Previously if none of your equipment had been modified those reports were not displayed even if it was because of a problem in the network or the formula.
I think it is much better to have the details. This way the user can display the TRACE in the logs if he wants to, and see what really happened.
ReportNode reportReactivePower = null; | ||
if (modifTargetQ != null) { | ||
if (modifTargetQ.getOp() == OperationType.SET) { | ||
reportReactivePower = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport(generator::setTargetQ, generator::getTargetQ, modifTargetQ, "Reactive power"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should it be specified that it is target reactive power or setpoint ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was simply refactoring that part but I think that you are right. Ok renamed.
Signed-off-by: Mathieu DEHARBE <[email protected]>
Quality Gate passedIssues Measures |
…s by formula (#524) Signed-off-by: Mathieu DEHARBE <[email protected]>
No description provided.