Skip to content

Commit

Permalink
Merge branch 'main' into add-by-filter-deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinebhs authored Dec 13, 2023
2 parents a603a6b + 54c724a commit 96565d0
Show file tree
Hide file tree
Showing 6 changed files with 440 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,26 @@ public void apply(Network network, Reporter subReporter) {
.filter(distinctByKey(FilterInfos::getId))
.collect(Collectors.toMap(FilterInfos::getId, FilterInfos::getName));

Map<UUID, FilterEquipments> exportFilters = ModificationUtils.getInstance().getUuidFilterEquipmentsMap(filterService, network, subReporter, filters, scalingInfos);
if (exportFilters == null) {
return;
Map<UUID, FilterEquipments> exportFilters = ModificationUtils.getUuidFilterEquipmentsMap(filterService, network, subReporter, filters, scalingInfos.getErrorType());
if (exportFilters != null) {
Map<UUID, FilterEquipments> filtersWithWrongEquipmentIds = ModificationUtils.getUuidFilterWrongEquipmentsIdsMap(subReporter, exportFilters, filters);

// apply variations
scalingInfos.getVariations().forEach(variation -> {
List<IdentifiableAttributes> identifiableAttributes = ModificationUtils.getIdentifiableAttributes(exportFilters, filtersWithWrongEquipmentIds, variation.getFilters(), subReporter);

if (CollectionUtils.isEmpty(identifiableAttributes)) {
String filterNames = variation.getFilters().stream().map(FilterInfos::getName).collect(Collectors.joining(", "));
createReport(subReporter,
"allFiltersWrong",
String.format("All of the following variation's filters have equipments with wrong id : %s", filterNames),
TypedValue.WARN_SEVERITY);
} else {
applyVariation(network, subReporter, identifiableAttributes, variation);
}
});
createReport(subReporter, "scalingCreated", "new scaling created", TypedValue.INFO_SEVERITY);
}
Map<UUID, FilterEquipments> filtersWithWrongEquipmentIds = ModificationUtils.getInstance().getUuidFilterWrongEquipmentsIdsMap(subReporter, exportFilters, filters);

// apply variations
scalingInfos.getVariations().forEach(variation -> {
List<IdentifiableAttributes> identifiableAttributes = ModificationUtils.getIdentifiableAttributes(exportFilters, filtersWithWrongEquipmentIds, variation.getFilters(), subReporter);

if (CollectionUtils.isEmpty(identifiableAttributes)) {
String filterNames = variation.getFilters().stream().map(FilterInfos::getName).collect(Collectors.joining(", "));
createReport(subReporter,
"allFiltersWrong",
String.format("All of the following variation's filters have equipments with wrong id : %s", filterNames),
TypedValue.WARN_SEVERITY);
} else {
applyVariation(network, subReporter, identifiableAttributes, variation);
}
});
createReport(subReporter, "scalingCreated", "new scaling created", TypedValue.INFO_SEVERITY);
}

private void applyVariation(Network network,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void apply(Network network, Reporter subReporter) {
.filter(distinctByKey(FilterInfos::getId))
.collect(Collectors.toMap(FilterInfos::getId, FilterInfos::getName));

Map<UUID, FilterEquipments> exportFilters = ModificationUtils.getInstance().getUuidFilterEquipmentsMap(filterService, network, subReporter, filters, modificationInfos);
Map<UUID, FilterEquipments> exportFilters = ModificationUtils.getUuidFilterEquipmentsMap(filterService, network, subReporter, filters, modificationInfos.getErrorType());

if (exportFilters != null) {
long equipmentCount = exportFilters.values()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ private static double computeTotalDemand(Component component, double lossCoeffic
return totalLoad * (1. + lossCoefficient / 100.);
}

private static double computeTotalActiveBatteryTargetP(Component component) {
Objects.requireNonNull(component);
return component.getBusStream().flatMap(Bus::getBatteryStream)
.filter(battery -> battery.getTerminal().isConnected())
.mapToDouble(Battery::getTargetP)
.sum();
}

private static double computeTotalAmountFixedSupply(Network network, Component component, List<String> generatorsWithFixedSupply, Reporter reporter) {
double totalAmountFixedSupply = 0.;
List<Generator> generatorsWithoutSetpointList = new ArrayList<>();
Expand Down Expand Up @@ -306,7 +314,7 @@ public void endReport(List<Generator> 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(), IS_PLURAL, updatedGenerators.size() > 1 ? "s" : ""), TypedValue.INFO_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));
Map.of(GENERATOR, g.getId(), "newValue", round(g.getTargetP())), TypedValue.TRACE_SEVERITY));

// report unchanged generators
int nbUnchangedGenerators = adjustableGenerators.size() - updatedGenerators.size();
Expand Down Expand Up @@ -493,26 +501,30 @@ public void apply(Network network, Reporter subReporter) {
// get total value of connected loads in the connected component
double totalDemand = computeTotalDemand(component, generationDispatchInfos.getLossCoefficient());
report(powerToDispatchReporter, Integer.toString(componentNum), "TotalDemand", "The total demand is : ${totalDemand} MW",
Map.of("totalDemand", totalDemand), TypedValue.INFO_SEVERITY);
Map.of("totalDemand", round(totalDemand)), TypedValue.INFO_SEVERITY);

// get total supply value for generators with fixed supply
double totalAmountFixedSupply = computeTotalAmountFixedSupply(network, component, generatorsWithFixedSupply, powerToDispatchReporter);
report(powerToDispatchReporter, Integer.toString(componentNum), "TotalAmountFixedSupply", "The total amount of fixed supply is : ${totalAmountFixedSupply} MW",
Map.of("totalAmountFixedSupply", totalAmountFixedSupply), TypedValue.INFO_SEVERITY);
Map.of("totalAmountFixedSupply", round(totalAmountFixedSupply)), TypedValue.INFO_SEVERITY);

// compute hvdc balance to other synchronous components
double hvdcBalance = computeHvdcBalance(component);
report(powerToDispatchReporter, Integer.toString(componentNum), "TotalOutwardHvdcFlow", "The HVDC balance is : ${hvdcBalance} MW",
Map.of("hvdcBalance", hvdcBalance), TypedValue.INFO_SEVERITY);
Map.of("hvdcBalance", round(hvdcBalance)), TypedValue.INFO_SEVERITY);

double totalAmountSupplyToBeDispatched = totalDemand - totalAmountFixedSupply - hvdcBalance;
double activeBatteryTotalTargetP = computeTotalActiveBatteryTargetP(component);
report(powerToDispatchReporter, Integer.toString(componentNum), "TotalActiveBatteryTargetP", "The battery balance is : ${batteryBalance} MW",
Map.of("batteryBalance", round(activeBatteryTotalTargetP)), TypedValue.INFO_SEVERITY);

double totalAmountSupplyToBeDispatched = totalDemand - totalAmountFixedSupply - hvdcBalance - activeBatteryTotalTargetP;
if (totalAmountSupplyToBeDispatched < 0.) {
report(powerToDispatchReporter, Integer.toString(componentNum), "TotalAmountFixedSupplyExceedsTotalDemand", "The total amount of fixed supply exceeds the total demand",
Map.of(), TypedValue.WARN_SEVERITY);
continue;
} else {
report(powerToDispatchReporter, Integer.toString(componentNum), "TotalAmountSupplyToBeDispatched", "The total amount of supply to be dispatched is : ${totalAmountSupplyToBeDispatched} MW",
Map.of("totalAmountSupplyToBeDispatched", totalAmountSupplyToBeDispatched), TypedValue.INFO_SEVERITY);
Map.of("totalAmountSupplyToBeDispatched", round(totalAmountSupplyToBeDispatched)), TypedValue.INFO_SEVERITY);
}

// get adjustable generators in the component
Expand Down Expand Up @@ -552,18 +564,18 @@ public void apply(Network network, Reporter subReporter) {
Map<EnergySource, Double> activePowerSumByEnergySource = getActivePowerSumByEnergySource(generators);
report(resultReporter, Integer.toString(componentNum), "SumGeneratorActivePower" + region, "Sum of generator active power setpoints in ${region} region: ${sum} MW (NUCLEAR: ${nuclearSum} MW, THERMAL: ${thermalSum} MW, HYDRO: ${hydroSum} MW, WIND AND SOLAR: ${windAndSolarSum} MW, OTHER: ${otherSum} MW).",
Map.of("region", region,
"sum", activePowerSumByEnergySource.values().stream().reduce(0d, Double::sum),
"nuclearSum", activePowerSumByEnergySource.getOrDefault(EnergySource.NUCLEAR, 0d),
"thermalSum", activePowerSumByEnergySource.getOrDefault(EnergySource.THERMAL, 0d),
"hydroSum", activePowerSumByEnergySource.getOrDefault(EnergySource.HYDRO, 0d),
"windAndSolarSum", activePowerSumByEnergySource.getOrDefault(EnergySource.WIND, 0d) + activePowerSumByEnergySource.getOrDefault(EnergySource.SOLAR, 0d),
"otherSum", activePowerSumByEnergySource.getOrDefault(EnergySource.OTHER, 0d)
"sum", round(activePowerSumByEnergySource.values().stream().reduce(0d, Double::sum)),
"nuclearSum", round(activePowerSumByEnergySource.getOrDefault(EnergySource.NUCLEAR, 0d)),
"thermalSum", round(activePowerSumByEnergySource.getOrDefault(EnergySource.THERMAL, 0d)),
"hydroSum", round(activePowerSumByEnergySource.getOrDefault(EnergySource.HYDRO, 0d)),
"windAndSolarSum", round(activePowerSumByEnergySource.getOrDefault(EnergySource.WIND, 0d) + activePowerSumByEnergySource.getOrDefault(EnergySource.SOLAR, 0d)),
"otherSum", round(activePowerSumByEnergySource.getOrDefault(EnergySource.OTHER, 0d))
), TypedValue.INFO_SEVERITY);
});
} else {
double remainingPowerImbalance = totalAmountSupplyToBeDispatched - realized;
report(resultReporter, Integer.toString(componentNum), "SupplyDemandBalanceCouldNotBeMet", "The supply-demand balance could not be met : the remaining power imbalance is ${remainingPower} MW",
Map.of("remainingPower", remainingPowerImbalance), TypedValue.WARN_SEVERITY);
Map.of("remainingPower", round(remainingPowerImbalance)), TypedValue.WARN_SEVERITY);
}
}
}
Expand Down Expand Up @@ -616,4 +628,7 @@ private Map<EnergySource, Double> getActivePowerSumByEnergySource(List<Generator
return generators.stream().collect(Collectors.toMap(Generator::getEnergySource, Generator::getTargetP, Double::sum));
}

private static double round(double value) {
return Math.round(value * 10) / 10.;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1045,19 +1045,18 @@ public static List<IdentifiableAttributes> getIdentifiableAttributes(Map<UUID, F
.flatMap(f -> exportFilters.get(f.getId())
.getIdentifiableAttributes()
.stream())
.filter(distinctByKey(IdentifiableAttributes::getId))
.toList();
}

@Nullable
public Map<UUID, FilterEquipments> getUuidFilterEquipmentsMap(FilterService filterService, Network network, Reporter subReporter, Map<UUID, String> filters, ModificationInfos modificationInfos) {
public static Map<UUID, FilterEquipments> getUuidFilterEquipmentsMap(FilterService filterService, Network network, Reporter subReporter, Map<UUID, String> filters, NetworkModificationException.Type errorType) {
Map<UUID, FilterEquipments> exportFilters = filterService.getUuidFilterEquipmentsMap(network, filters);

boolean isValidFilter = ModificationUtils.getInstance().isValidFilter(subReporter, modificationInfos.getErrorType(), exportFilters);
boolean isValidFilter = ModificationUtils.getInstance().isValidFilter(subReporter, errorType, exportFilters);
return isValidFilter ? exportFilters : null;
}

public Map<UUID, FilterEquipments> getUuidFilterWrongEquipmentsIdsMap(Reporter subReporter, Map<UUID, FilterEquipments> exportFilters, Map<UUID, String> filters) {
public static Map<UUID, FilterEquipments> getUuidFilterWrongEquipmentsIdsMap(Reporter subReporter, Map<UUID, FilterEquipments> exportFilters, Map<UUID, String> filters) {
// collect all filters with wrong equipments ids
Map<UUID, FilterEquipments> filterWithWrongEquipmentsIds = exportFilters.entrySet().stream()
.filter(e -> !CollectionUtils.isEmpty(e.getValue().getNotFoundEquipments()))
Expand Down
Loading

0 comments on commit 96565d0

Please sign in to comment.