From 75566ee2a23095fb5b2899691fb351326e920643 Mon Sep 17 00:00:00 2001 From: David BRAQUART Date: Mon, 25 Sep 2023 13:08:16 +0200 Subject: [PATCH] review remarks Signed-off-by: David BRAQUART --- .../modifications/GenerationDispatch.java | 63 +++++++++---------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/src/main/java/org/gridsuite/modification/server/modifications/GenerationDispatch.java b/src/main/java/org/gridsuite/modification/server/modifications/GenerationDispatch.java index abb52b5ee..d55a9aef6 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/GenerationDispatch.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/GenerationDispatch.java @@ -155,15 +155,9 @@ private static Map> getGeneratorsByMarginalCost(List generator.setTargetP(0.)); // get generators with marginal cost - List generatorsWithMarginalCost = generators.stream().filter(generator -> { - Double marginalCost = getGeneratorMarginalCost(generator); - if (marginalCost == null) { - report(reporter, reporterSuffixKey, "MissingMarginalCostForGenerator", "The generator ${generator} does not have a marginal cost", - Map.of(GENERATOR, generator.getId()), TypedValue.TRACE_SEVERITY); - } - return marginalCost != null; - }).collect(Collectors.toList()); - + List generatorsWithMarginalCost = generators.stream() + .filter(generator -> getGeneratorMarginalCost(generator) != null) + .collect(Collectors.toList()); int nbNoCost = generators.size() - generatorsWithMarginalCost.size(); if (nbNoCost > 0) { report(reporter, reporterSuffixKey, "NbGeneratorsWithNoCost", "${nbNoCost} generator${isPlural} been discarded from generation dispatch because of missing marginal cost. Their active power set point has been set to 0", @@ -171,6 +165,11 @@ private static Map> getGeneratorsByMarginalCost(List 1 ? "s have" : " has"), TypedValue.WARN_SEVERITY); } + generators.stream() + .filter(generator -> getGeneratorMarginalCost(generator) == null) + .forEach(g -> report(reporter, reporterSuffixKey, "MissingMarginalCostForGenerator", "The generator ${generator} does not have a marginal cost", + Map.of(GENERATOR, g.getId()), TypedValue.TRACE_SEVERITY) + ); // build map of generators by marginal cost generatorsWithMarginalCost.sort(Comparator.comparing(GenerationDispatch::getGeneratorMarginalCost)); @@ -274,7 +273,7 @@ private static List computeAdjustableGenerators(Network network, Comp private static class GeneratorTargetPListener extends DefaultNetworkListener { private final Reporter reporter; private final String suffixKey; - private final List updatedGenerators = new ArrayList<>(); + private final List updatedGenerators = new ArrayList<>(); GeneratorTargetPListener(Reporter reporter, String suffixKey) { this.reporter = reporter; @@ -283,28 +282,29 @@ private static class GeneratorTargetPListener extends DefaultNetworkListener { @Override public void onUpdate(Identifiable identifiable, String attribute, String variantId, Object oldValue, Object newValue) { - if (identifiable.getType() == IdentifiableType.GENERATOR && - attribute.equals("targetP") && - Double.compare((double) oldValue, (double) newValue) != 0) { - report(reporter, suffixKey, "GeneratorSetTargetP", "The active power set point of generator ${generator} has been set to ${newValue} MW", - Map.of(GENERATOR, identifiable.getId(), "newValue", newValue), TypedValue.TRACE_SEVERITY); - updatedGenerators.add(identifiable.getId()); + if (identifiable.getType() == IdentifiableType.GENERATOR && attribute.equals("targetP") && Double.compare((double) oldValue, (double) newValue) != 0) { + updatedGenerators.add((Generator) identifiable); } } public void endReport(List adjustableGenerators) { + // report updated generators report(reporter, suffixKey, "TotalGeneratorSetTargetP", "The active power set points of ${nbUpdatedGenerator} generator${isPlural} have been updated as a result of generation dispatch", Map.of("nbUpdatedGenerator", updatedGenerators.size(), "isPlural", updatedGenerators.size() > 1 ? "s" : ""), TypedValue.INFO_SEVERITY); - // what are unchanged generators ? - adjustableGenerators.stream() - .filter(g -> !updatedGenerators.contains(g.getId())) - .forEach(g -> report(reporter, suffixKey, "GeneratorUnchangedTargetP", "Generator ${generator} has not been selected by the merit order algorithm. Its active power set point has been set to 0", - Map.of(GENERATOR, g.getId()), TypedValue.TRACE_SEVERITY)); + updatedGenerators.forEach(g -> report(reporter, suffixKey, "GeneratorSetTargetP", "The active power set point of generator ${generator} has been set to ${newValue} MW", + Map.of(GENERATOR, g.getId(), "newValue", g.getTargetP()), TypedValue.TRACE_SEVERITY)); + + // report unchanged generators int nbUnchangedGenerators = adjustableGenerators.size() - updatedGenerators.size(); if (nbUnchangedGenerators > 0) { + List updatedGeneratorsIds = updatedGenerators.stream().map(Identifiable::getId).toList(); report(reporter, suffixKey, "TotalGeneratorUnchangedTargetP", "${nbUnchangedGenerator} eligible generator${isPlural} not been selected by the merit order algorithm. Their active power set point has been set to 0", Map.of("nbUnchangedGenerator", nbUnchangedGenerators, "isPlural", nbUnchangedGenerators > 1 ? "s have" : " has"), TypedValue.INFO_SEVERITY); + adjustableGenerators.stream() + .filter(g -> !updatedGeneratorsIds.contains(g.getId())) + .forEach(g -> report(reporter, suffixKey, "GeneratorUnchangedTargetP", "Generator ${generator} has not been selected by the merit order algorithm. Its active power set point has been set to 0", + Map.of(GENERATOR, g.getId()), TypedValue.TRACE_SEVERITY)); } } } @@ -414,21 +414,20 @@ private double reduceGeneratorMaxPValue(Generator generator, return Math.max(generator.getMinP(), res * (1. - genFrequencyReserve / 100.)); } - private void reportDisconnectedGenerators(List disconnectedGenerators, int componentNum, Reporter reporter) { - AtomicInteger disconnectedGeneratorCounter = new AtomicInteger(0); - disconnectedGenerators.stream() + private void reportDisconnectedGenerators(List globalDisconnectedGenerators, int componentNum, Reporter reporter) { + List componentDisconnectedGenerators = globalDisconnectedGenerators.stream() .filter(g -> g.getTerminal().getBusView() != null && g.getTerminal().getBusView().getConnectableBus() != null && g.getTerminal().getBusView().getConnectableBus().getSynchronousComponent().getNum() == componentNum) - .forEach(g -> { - report(reporter, Integer.toString(componentNum), "DisconnectedGenerator", "Generator ${generator} has been discarded from generation dispatch because it is disconnected. Its active power set point remains unchanged", - Map.of(GENERATOR, g.getId()), TypedValue.TRACE_SEVERITY); - disconnectedGeneratorCounter.getAndIncrement(); - }); - if (disconnectedGeneratorCounter.get() > 0) { + .toList(); + if (!componentDisconnectedGenerators.isEmpty()) { report(reporter, Integer.toString(componentNum), "TotalDisconnectedGenerator", "${nbDisconnectedGenerator} generator${isPlural} been discarded from generation dispatch because their are disconnected. Their active power set point remains unchanged", - Map.of("nbDisconnectedGenerator", disconnectedGeneratorCounter.get(), - "isPlural", disconnectedGeneratorCounter.get() > 1 ? "s have" : " has"), + Map.of("nbDisconnectedGenerator", componentDisconnectedGenerators.size(), + "isPlural", componentDisconnectedGenerators.size() > 1 ? "s have" : " has"), TypedValue.INFO_SEVERITY); + componentDisconnectedGenerators.forEach(g -> + report(reporter, Integer.toString(componentNum), "DisconnectedGenerator", "Generator ${generator} has been discarded from generation dispatch because it is disconnected. Its active power set point remains unchanged", + Map.of(GENERATOR, g.getId()), TypedValue.TRACE_SEVERITY) + ); } }