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..03fb6f0d2 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) + .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)); @@ -295,16 +294,17 @@ public void onUpdate(Identifiable identifiable, String attribute, String variant public void endReport(List adjustableGenerators) { 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)); int nbUnchangedGenerators = adjustableGenerators.size() - updatedGenerators.size(); if (nbUnchangedGenerators > 0) { 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 -> !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)); } } } @@ -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) + ); } }