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

Share code for network modifications #524

Merged
merged 30 commits into from
Sep 26, 2024
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ad6f6f3
draft
Mathieu-Deharbe Aug 28, 2024
3b27dfb
draft refacto check and apply functions
Mathieu-Deharbe Aug 29, 2024
1986a26
indent and correct TU
Mathieu-Deharbe Aug 29, 2024
dffe039
finish GeneratorField + correction in GeneratorModification
Mathieu-Deharbe Aug 29, 2024
3c1c0fa
shunt compensator MAXIMUM_SECTION_COUNT
Mathieu-Deharbe Sep 2, 2024
21cc44e
Merge branch 'main' into share-code-for-network-modifications
Mathieu-Deharbe Sep 2, 2024
f4a62eb
shunt compensator
Mathieu-Deharbe Sep 2, 2024
bccd1cb
Merge remote-tracking branch 'origin/share-code-for-network-modificat…
Mathieu-Deharbe Sep 2, 2024
52a7eeb
VoltageLevelFields
Mathieu-Deharbe Sep 2, 2024
4dcf358
reduce modifyVoltageLevelShortCircuit code complexity
Mathieu-Deharbe Sep 2, 2024
2ce33ed
always send formulaReports
Mathieu-Deharbe Sep 3, 2024
c3bbff8
refacto BatteryField
Mathieu-Deharbe Sep 3, 2024
fe01d83
refacto GeneratorField
Mathieu-Deharbe Sep 3, 2024
3337dd9
refacto VoltageLevelField
Mathieu-Deharbe Sep 3, 2024
c37e5a0
correct tests
Mathieu-Deharbe Sep 3, 2024
a8ae013
correct tests
Mathieu-Deharbe Sep 3, 2024
906613b
modifyBranchValues
Mathieu-Deharbe Sep 4, 2024
6f7a6ae
finish TwoWindingsTransformerField
Mathieu-Deharbe Sep 4, 2024
6e29fdc
reduce cognitive complexity
Mathieu-Deharbe Sep 4, 2024
d249d45
small refect on BatteryField
Mathieu-Deharbe Sep 4, 2024
90b6b5c
ultimate cleaning
Mathieu-Deharbe Sep 4, 2024
e758123
corections post review
Mathieu-Deharbe Sep 17, 2024
0a92daf
Merge branch 'main' of https://github.com/gridsuite/network-modificat…
Mathieu-Deharbe Sep 18, 2024
5c7f145
Merge branch 'main' into share-code-for-network-modifications
Mathieu-Deharbe Sep 18, 2024
68e970a
revert to correct unit tests
Mathieu-Deharbe Sep 18, 2024
04495ce
Merge remote-tracking branch 'origin/share-code-for-network-modificat…
Mathieu-Deharbe Sep 18, 2024
55de855
clean imports
Mathieu-Deharbe Sep 18, 2024
c9ce267
Merge branch 'main' into share-code-for-network-modifications
basseche Sep 18, 2024
6b35eec
Merge branch 'main' into share-code-for-network-modifications
Mathieu-Deharbe Sep 23, 2024
1bf83ed
post review
Mathieu-Deharbe Sep 25, 2024
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
Prev Previous commit
Next Next commit
draft refacto check and apply functions
Signed-off-by: Mathieu DEHARBE <mathieu.deharbe@rte-france.com>
  • Loading branch information
Mathieu-Deharbe committed Aug 29, 2024
commit 3b27dfb8d6ac9c603c061cf9279effc06bc32dca
Original file line number Diff line number Diff line change
@@ -14,6 +14,8 @@
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Battery exception type !


/**
* @author Seddik Yengui <Seddik.yengui at rte-france.com>
*/
@@ -40,26 +42,22 @@ public static Double getReferenceValue(Battery battery, String batteryField) {
public static void setNewValue(Battery battery, String batteryField, Double newValue) {
BatteryField field = BatteryField.valueOf(batteryField);
switch (field) {
case MINIMUM_ACTIVE_POWER ->
ModificationUtils.getInstance().applyElementaryModifications(
battery::setMinP,
battery::getMinP,
new AttributeModification<>(newValue, OperationType.SET));
case MAXIMUM_ACTIVE_POWER ->
ModificationUtils.getInstance().applyElementaryModifications(
battery::setMaxP,
battery::getMaxP,
new AttributeModification<>(newValue, OperationType.SET));
case ACTIVE_POWER_SET_POINT ->
ModificationUtils.getInstance().applyElementaryModifications(
battery::setTargetP,
battery::getTargetP,
new AttributeModification<>(newValue, OperationType.SET));
case REACTIVE_POWER_SET_POINT ->
ModificationUtils.getInstance().applyElementaryModifications(
battery::setTargetQ,
battery::getTargetQ,
new AttributeModification<>(newValue, OperationType.SET));
case MINIMUM_ACTIVE_POWER -> battery.setMinP(newValue);
case MAXIMUM_ACTIVE_POWER -> battery.setMaxP(newValue);
case ACTIVE_POWER_SET_POINT -> {
ModificationUtils.getInstance().checkActivePowerZeroOrBetweenMinAndMaxActivePower(
new AttributeModification<>(newValue, OperationType.SET),
null,
null,
battery.getMinP(),
battery.getMaxP(),
battery.getTargetP(),
MODIFY_GENERATOR_ERROR,
"Battery '" + battery.getId() + "' : "
);
battery.setTargetP(newValue);
}
case REACTIVE_POWER_SET_POINT -> battery.setTargetQ(newValue);
case DROOP -> {
ActivePowerControl<Battery> activePowerControl = battery.getExtension(ActivePowerControl.class);
ActivePowerControlAdder<Battery> activePowerControlAdder = battery.newExtension(ActivePowerControlAdder.class);
@@ -68,16 +66,7 @@ public static void setNewValue(Battery battery, String batteryField, Double newV
activePowerControlAdder,
null,
new AttributeModification<>(newValue.floatValue(), OperationType.SET),
null,
null);
/* Correction basique juste au cas où je ne fais pas le méga refacto :
if (battery.getExtension(ActivePowerControl.class) != null) {
battery.getExtension(ActivePowerControl.class).setDroop(newValue);
} else {
battery.newExtension(ActivePowerControlAdder.class)
.withDroop(newValue)
.add();
}*/
}
}
}
Original file line number Diff line number Diff line change
@@ -15,7 +15,12 @@
import com.powsybl.iidm.network.extensions.GeneratorShortCircuit;
import com.powsybl.iidm.network.extensions.GeneratorShortCircuitAdder;
import com.powsybl.iidm.network.extensions.GeneratorStartup;
import com.powsybl.iidm.network.extensions.GeneratorStartupAdder;
import org.gridsuite.modification.server.dto.AttributeModification;
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;
import static org.gridsuite.modification.server.modifications.GeneratorModification.modifyGeneratorStartUpAttributes;

/**
* @author Seddik Yengui <Seddik.yengui at rte-france.com>
@@ -63,80 +68,72 @@ public static Double getReferenceValue(Generator generator, String generatorFiel

public static void setNewValue(Generator generator, String generatorField, Double newValue) {
if (!Double.isNaN(newValue)) {
GeneratorStartup generatorStartup = generator.getExtension(GeneratorStartup.class);
GeneratorShortCircuit generatorShortCircuit = generator.getExtension(GeneratorShortCircuit.class);
GeneratorField field = GeneratorField.valueOf(generatorField);
switch (field) {
case MAXIMUM_ACTIVE_POWER -> generator.setMaxP(newValue);
case MINIMUM_ACTIVE_POWER -> generator.setMinP(newValue);
case ACTIVE_POWER_SET_POINT -> generator.setTargetP(newValue);
case ACTIVE_POWER_SET_POINT -> {
ModificationUtils.getInstance().checkActivePowerZeroOrBetweenMinAndMaxActivePower(
new AttributeModification<>(newValue, OperationType.SET),
null,
null,
generator.getMinP(),
generator.getMaxP(),
generator.getTargetP(),
MODIFY_GENERATOR_ERROR,
"Generator '" + generator.getId() + "' : "
);
generator.setTargetP(newValue);
}
case RATED_NOMINAL_POWER -> generator.setRatedS(newValue);
case REACTIVE_POWER_SET_POINT -> generator.setTargetQ(newValue);
case VOLTAGE_SET_POINT -> generator.setTargetV(newValue);
case PLANNED_ACTIVE_POWER_SET_POINT -> {
if (generatorStartup == null) {
generator.newExtension(GeneratorStartupAdder.class)
.withPlannedActivePowerSetpoint(newValue)
.add();
} else {
generator.newExtension(GeneratorStartupAdder.class)
.withMarginalCost(generatorStartup.getMarginalCost())
.withPlannedActivePowerSetpoint(newValue)
.withPlannedOutageRate(generatorStartup.getPlannedOutageRate())
.withForcedOutageRate(generatorStartup.getForcedOutageRate())
.add();
}
}
case MARGINAL_COST -> {
if (generatorStartup == null) {
generator.newExtension(GeneratorStartupAdder.class)
.withMarginalCost(newValue)
.add();
} else {
generator.newExtension(GeneratorStartupAdder.class)
.withMarginalCost(newValue)
.withPlannedActivePowerSetpoint(generatorStartup.getPlannedActivePowerSetpoint())
.withPlannedOutageRate(generatorStartup.getPlannedOutageRate())
.withForcedOutageRate(generatorStartup.getForcedOutageRate())
.add();
}
}
case PLANNED_OUTAGE_RATE -> {
if (generatorStartup == null) {
generator.newExtension(GeneratorStartupAdder.class)
.withPlannedOutageRate(newValue)
.add();
} else {
generator.newExtension(GeneratorStartupAdder.class)
.withMarginalCost(generatorStartup.getMarginalCost())
.withPlannedActivePowerSetpoint(generatorStartup.getPlannedActivePowerSetpoint())
.withPlannedOutageRate(newValue)
.withForcedOutageRate(generatorStartup.getForcedOutageRate())
.add();
}
}
case FORCED_OUTAGE_RATE -> {
if (generatorStartup == null) {
generator.newExtension(GeneratorStartupAdder.class)
.withForcedOutageRate(newValue)
.add();
} else {
generator.newExtension(GeneratorStartupAdder.class)
.withMarginalCost(generatorStartup.getMarginalCost())
.withPlannedActivePowerSetpoint(generatorStartup.getPlannedActivePowerSetpoint())
.withPlannedOutageRate(generatorStartup.getForcedOutageRate())
.withForcedOutageRate(newValue)
.add();
}
}
case PLANNED_ACTIVE_POWER_SET_POINT ->
modifyGeneratorStartUpAttributes(
new AttributeModification<>(newValue, OperationType.SET),
null,
null,
null,
generator,
null,
null);
case MARGINAL_COST ->
modifyGeneratorStartUpAttributes(
null,
new AttributeModification<>(newValue, OperationType.SET),
null,
null,
generator,
null,
null);
case PLANNED_OUTAGE_RATE ->
modifyGeneratorStartUpAttributes(
null,
null,
new AttributeModification<>(newValue, OperationType.SET),
null,
generator,
null,
null);
case FORCED_OUTAGE_RATE ->
modifyGeneratorStartUpAttributes(
null,
null,
null,
new AttributeModification<>(newValue, OperationType.SET),
generator,
null,
null);
case DROOP -> {
if (generator.getExtension(ActivePowerControl.class) != null) {
generator.getExtension(ActivePowerControl.class).setDroop(newValue);
} else {
generator.newExtension(ActivePowerControlAdder.class)
.withDroop(newValue)
.add();
}
ActivePowerControl<Generator> activePowerControl = generator.getExtension(ActivePowerControl.class);
ActivePowerControlAdder<Generator> activePowerControlAdder = generator.newExtension(ActivePowerControlAdder.class);
ModificationUtils.getInstance().modifyActivePowerControlAttributes(
activePowerControl,
activePowerControlAdder,
null,
new AttributeModification<>(newValue.floatValue(), OperationType.SET),
null);
}
case TRANSIENT_REACTANCE -> generator.newExtension(GeneratorShortCircuitAdder.class)
.withDirectTransX(newValue)
Original file line number Diff line number Diff line change
@@ -172,7 +172,7 @@ private ReportNode modifyBatteryActivePowerControlAttributes(BatteryModification
Battery battery, ReportNode subReportNode, ReportNode subReportNodeSetpoints) {
ActivePowerControl<Battery> activePowerControl = battery.getExtension(ActivePowerControl.class);
ActivePowerControlAdder<Battery> activePowerControlAdder = battery.newExtension(ActivePowerControlAdder.class);
return ModificationUtils.getInstance().modifyActivePowerControlAttributes(activePowerControl, activePowerControlAdder, modificationInfos.getParticipate(), modificationInfos.getDroop(), subReportNode, subReportNodeSetpoints);
return ModificationUtils.getInstance().modifyActivePowerControlAttributesAndLog(activePowerControl, activePowerControlAdder, modificationInfos.getParticipate(), modificationInfos.getDroop(), subReportNode, subReportNodeSetpoints);
}

private ReportNode modifyBatteryConnectivityAttributes(BatteryModificationInfos modificationInfos,
Original file line number Diff line number Diff line change
@@ -287,7 +287,7 @@ private void applyFormula(Identifiable<?> identifiable,
.withUntypedValue(KEY_VALUE, newValue)
.withSeverity(TypedValue.TRACE_SEVERITY)
.build());
} catch (Exception e) {
} catch (Exception e) { // ATTENTION : ce catch attrape bien mes throw mais sans utiliser les messages donc c'est un peu gâché; En faire un spécifique pour les NetworkModificationException ?
notEditableEquipments.add(identifiable.getId());
equipmentNotModifiedCount += 1;
reports.add(ReportNode.newRootReportNode()
Loading
Loading