From 82d297d5c85e7b74b0155eb4d963720783505830 Mon Sep 17 00:00:00 2001 From: Ayoub LABIDI Date: Wed, 8 Nov 2023 15:17:56 +0100 Subject: [PATCH] Fix sectionCount and maxSectionCount application Signed-off-by: Ayoub LABIDI --- .../ShuntCompensatorModification.java | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/gridsuite/modification/server/modifications/ShuntCompensatorModification.java b/src/main/java/org/gridsuite/modification/server/modifications/ShuntCompensatorModification.java index 1ddc1a04d..d2f2f840f 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/ShuntCompensatorModification.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/ShuntCompensatorModification.java @@ -70,23 +70,39 @@ public void apply(Network network, Reporter subReporter) { } } - private void applyModificationOnLinearModel(Reporter subReporter, ShuntCompensator shuntCompensator, VoltageLevel voltageLevel) { - List reports = new ArrayList<>(); - ShuntCompensatorLinearModel model = shuntCompensator.getModel(ShuntCompensatorLinearModel.class); - var shuntCompensatorType = model.getBPerSection() > 0 ? ShuntCompensatorType.CAPACITOR : ShuntCompensatorType.REACTOR; - var maximumSectionCount = shuntCompensator.getMaximumSectionCount(); - + private void modifyMaximumSectionCount(List reports, ShuntCompensator shuntCompensator, ShuntCompensatorLinearModel model) { if (modificationInfos.getMaximumSectionCount() != null) { - maximumSectionCount = modificationInfos.getMaximumSectionCount().getValue(); + var maximumSectionCount = modificationInfos.getMaximumSectionCount().getValue(); if (modificationInfos.getMaxSusceptance() == null && modificationInfos.getMaxQAtNominalV() == null) { model.setBPerSection(model.getBPerSection() * shuntCompensator.getMaximumSectionCount() / maximumSectionCount); } - reports.add(ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport(model::setMaximumSectionCount, shuntCompensator::getSectionCount, modificationInfos.getMaximumSectionCount(), "Maximum section count")); + reports.add(ModificationUtils.getInstance().buildModificationReport(shuntCompensator.getMaximumSectionCount(), maximumSectionCount, "Maximum section count")); + model.setMaximumSectionCount(maximumSectionCount); } + } + private void modifySectionCount(List reports, ShuntCompensator shuntCompensator) { if (modificationInfos.getSectionCount() != null) { reports.add(ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport(shuntCompensator::setSectionCount, shuntCompensator::getSectionCount, modificationInfos.getSectionCount(), "Section count")); } + } + + private void applyModificationOnLinearModel(Reporter subReporter, ShuntCompensator shuntCompensator, VoltageLevel voltageLevel) { + List reports = new ArrayList<>(); + ShuntCompensatorLinearModel model = shuntCompensator.getModel(ShuntCompensatorLinearModel.class); + var shuntCompensatorType = model.getBPerSection() > 0 ? ShuntCompensatorType.CAPACITOR : ShuntCompensatorType.REACTOR; + + // due to cross validation between maximum section count and section count, we need to modify section count first + // when maximum section count old value is greater than the new one + if (modificationInfos.getMaximumSectionCount() != null && modificationInfos.getMaximumSectionCount().getValue() < shuntCompensator.getMaximumSectionCount()) { + modifySectionCount(reports, shuntCompensator); + modifyMaximumSectionCount(reports, shuntCompensator, model); + } else { + modifyMaximumSectionCount(reports, shuntCompensator, model); + modifySectionCount(reports, shuntCompensator); + } + + var maximumSectionCount = modificationInfos.getMaximumSectionCount() != null ? modificationInfos.getMaximumSectionCount().getValue() : shuntCompensator.getMaximumSectionCount(); if (modificationInfos.getShuntCompensatorType() != null) { reports.add(ModificationUtils.getInstance().buildModificationReport(shuntCompensatorType, modificationInfos.getShuntCompensatorType().getValue(), "Type"));