Skip to content

Commit

Permalink
Adequacy patch CSR - revamp output variables [ANT-1932] (#2306)
Browse files Browse the repository at this point in the history
### Variables
- Remove Spilled CSR
- Add DTG MRG CSR
- Add UNSP. ENRG CSR

### Input parameters
Remove flag "recompute-dtg-mrg"

Make code mode testable by using functions.
---------

Co-authored-by: Vincent Payet <[email protected]>
  • Loading branch information
flomnes and payetvin authored Sep 4, 2024
1 parent 69a8b12 commit fcb5254
Show file tree
Hide file tree
Showing 15 changed files with 262 additions and 113 deletions.
5 changes: 4 additions & 1 deletion docs/user-guide/04-migration-guides.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ with XXX in
#### Short term storage: efficiency for withdrawal
In input/st-storage/area/list.ini add property: `efficiencywithdrawal` [double] in range 0-1

### Output
- Remove column SPIL ENRG CSR (adequacy patch)
- Add DTG MRG CSR and UNSP ENRG CSR variables

## v9.1.0
### Input
#### Hydro Maximum Generation/Pumping Power
Expand Down Expand Up @@ -198,7 +202,6 @@ In file **settings/generaldata.ini**, in section `adequacy patch`, add propertie
* `price-taking-order` [string] can take values `DENS` (default value) and `Load`.
* `include-hurdle-cost-csr` [bool]. Default value = `false`
* `check-csr-cost-function` [bool]. Default value = `false`
* `recompute-dtg-mrg` [bool]. Default value = `false`
* `threshold-initiate-curtailment-sharing-rule` [double]. Default value = `0.0`
* `threshold-display-local-matching-rule-violations` [double]. Default value = `0.0`
* `threshold-csr-variable-bounds-relaxation` [int]. Default value = `3`
Expand Down
7 changes: 4 additions & 3 deletions docs/user-guide/solver/03-outputs.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,13 @@ The area files that belong to the "values" class display fields corresponding to
| SPIL. ENRG | Spilled energy (energy produced that cannot be used and has to be wasted) |
| LOLD | Loss of load duration: adequacy indicator (length of shortfalls) |
| LOLP | Loss of Load probability: adequacy indicator (probability of at least one hour of shortfall within the considered period, without normalization by the duration of the considered period) |
| AVL. DTG | Available dispatchable thermal generation (sum of av. power over all plants) |
| DTG. MRG | Disp. Ther. Gen. (AVL DTG – sum of all dispatched thermal generation) |
| AVL DTG | Available dispatchable thermal generation (sum of av. power over all plants) |
| DTG MRG | Disp. Ther. Gen. (AVL DTG – sum of all dispatched thermal generation) |
| MAX. MRG | Maximum margin: operational margin obtained if the hydro storage energy of the week were used to maximise margins instead of minimizing costs |
| DENS | Domestic Energy Not Supplied: the difference between the local production capabilities of an area and its local load[^adqp] |
| LMR. VIOL | Local Matching Rule Violation after the Antares Simulation as defined by the adequacy patch[^adqp] |
| SPIL. ENRG. CSR | Spilled Energy after the Curtailment Sharing Rule step of the dequacy patch[^adqp] |
| UNSP. ENRG. CSR | Unsupplied enery after CSR (demand that cannot be satisfied)[^adqp] |
| DTG MRG CSR | DTG MRG after CSR[^adqp] |
| <Short-term storage group\>_injection | Injection of energy from the area into each short-term storage group |
| <Short-term storage group\>_withdrawal | Withdrawal of energy from each short-term storage group into the area |
| <Short-term storage group\>_level | Average level of each short-term storage group |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ class CurtailmentSharing
//! Check CSR cost function prior & after CSR optimization
bool checkCsrCostFunction;

bool recomputeDTGMRG = false;

bool updateFromKeyValue(const Yuni::String& key, const Yuni::String& value);
void addProperties(IniFile::Section* section) const;

Expand Down
9 changes: 1 addition & 8 deletions src/libs/antares/study/parameters/adq-patch-params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ void CurtailmentSharing::reset()
priceTakingOrder = AdqPatchPTO::isDens;
includeHurdleCost = false;
checkCsrCostFunction = false;
recomputeDTGMRG = false;
resetThresholds();
}

Expand Down Expand Up @@ -107,11 +106,6 @@ bool CurtailmentSharing::updateFromKeyValue(const Yuni::String& key, const Yuni:
{
return value.to<bool>(checkCsrCostFunction);
}
if (key == "recompute-dtg-mrg")
{
return value.to<bool>(recomputeDTGMRG);
}

// Thresholds
if (key == "threshold-initiate-curtailment-sharing-rule")
{
Expand Down Expand Up @@ -147,7 +141,6 @@ void CurtailmentSharing::addProperties(IniFile::Section* section) const
section->add("price-taking-order", PriceTakingOrderToString(priceTakingOrder));
section->add("include-hurdle-cost-csr", includeHurdleCost);
section->add("check-csr-cost-function", checkCsrCostFunction);
section->add("recompute-dtg-mrg", recomputeDTGMRG);

// Thresholds
section->add("threshold-initiate-curtailment-sharing-rule", thresholdRun);
Expand All @@ -170,7 +163,7 @@ void AdqPatchParams::addExcludedVariables(std::vector<std::string>& out) const
{
out.emplace_back("DENS");
out.emplace_back("LMR VIOL.");
out.emplace_back("SPIL. ENRG. CSR");
out.emplace_back("UNSP. ENRG CSR");
out.emplace_back("DTG MRG CSR");
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/solver/optimisation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ set(RTESOLVER_OPT
post_process_commands.cpp
include/antares/solver/optimisation/adequacy_patch_csr/hourly_csr_problem.h
include/antares/solver/optimisation/adequacy_patch_csr/adq_patch_post_process_list.h
include/antares/solver/optimisation/adequacy_patch_csr/post_processing.h
adequacy_patch_csr/adq_patch_post_process_list.cpp
adequacy_patch_csr/post_processing.cpp
include/antares/solver/optimisation/adequacy_patch_csr/adq_patch_curtailment_sharing.h
adequacy_patch_csr/adq_patch_curtailment_sharing.cpp
adequacy_patch_csr/solve_problem.cpp
Expand Down
62 changes: 62 additions & 0 deletions src/solver/optimisation/adequacy_patch_csr/post_processing.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
** Copyright 2007-2024, RTE (https://www.rte-france.com)
** See AUTHORS.txt
** SPDX-License-Identifier: MPL-2.0
** This file is part of Antares-Simulator,
** Adequacy and Performance assessment for interconnected energy networks.
**
** Antares_Simulator is free software: you can redistribute it and/or modify
** it under the terms of the Mozilla Public Licence 2.0 as published by
** the Mozilla Foundation, either version 2 of the License, or
** (at your option) any later version.
**
** Antares_Simulator is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** Mozilla Public Licence 2.0 for more details.
**
** You should have received a copy of the Mozilla Public Licence 2.0
** along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
*/
#include "antares/solver/optimisation/adequacy_patch_csr/post_processing.h"

#include <cmath>

namespace Antares::Data::AdequacyPatch
{
double recomputeDTG_MRG(bool triggered, double dtgMrg, double ens)
{
if (triggered)
{
return std::max(0.0, dtgMrg - ens);
}
else
{
return dtgMrg;
}
}

double recomputeENS_MRG(bool triggered, double dtgMrg, double ens)
{
if (triggered)
{
return std::max(0.0, ens - dtgMrg);
}
else
{
return ens;
}
}

double recomputeMRGPrice(double ensCsr, double originalCost, double unsuppliedEnergyCost)
{
if (ensCsr > 0.5)
{
return -unsuppliedEnergyCost;
}
else
{
return originalCost;
}
}
} // namespace Antares::Data::AdequacyPatch
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void HourlyCSRProblem::setBoundsOnSpilledEnergy()
.ValeursHorairesDeDefaillanceNegative[triggeredHour];

double* AdresseDuResultat = &(problemeHebdo_->ResultatsHoraires[area]
.ValeursHorairesSpilledEnergyAfterCSR[triggeredHour]);
.ValeursHorairesDeDefaillanceNegative[triggeredHour]);

problemeAResoudre_.AdresseOuPlacerLaValeurDesVariablesOptimisees[var]
= AdresseDuResultat;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
** Copyright 2007-2024, RTE (https://www.rte-france.com)
** See AUTHORS.txt
** SPDX-License-Identifier: MPL-2.0
** This file is part of Antares-Simulator,
** Adequacy and Performance assessment for interconnected energy networks.
**
** Antares_Simulator is free software: you can redistribute it and/or modify
** it under the terms of the Mozilla Public Licence 2.0 as published by
** the Mozilla Foundation, either version 2 of the License, or
** (at your option) any later version.
**
** Antares_Simulator is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** Mozilla Public Licence 2.0 for more details.
**
** You should have received a copy of the Mozilla Public Licence 2.0
** along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
*/

#pragma once

namespace Antares::Data::AdequacyPatch
{
double recomputeDTG_MRG(bool triggered, double dtgMrg, double ens);
double recomputeENS_MRG(bool triggered, double dtgMrg, double ens);
double recomputeMRGPrice(double ensCsr, double originalCost, double unsuppliedEnergyCost);
} // namespace Antares::Data::AdequacyPatch
45 changes: 16 additions & 29 deletions src/solver/optimisation/post_process_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "antares/solver/optimisation/post_process_commands.h"

#include "antares/solver/optimisation/adequacy_patch_csr/adq_patch_curtailment_sharing.h"
#include "antares/solver/optimisation/adequacy_patch_csr/post_processing.h"
#include "antares/solver/simulation/adequacy_patch_runtime_data.h"
#include "antares/solver/simulation/common-eco-adq.h"

Expand Down Expand Up @@ -147,32 +148,23 @@ void DTGmarginForAdqPatchPostProcessCmd::execute(const optRuntimeData&)

for (uint hour = 0; hour < nbHoursInWeek; hour++)
{
// define access to the required variables
auto& hourlyResults = problemeHebdo_->ResultatsHoraires[Area];
const auto& scratchpad = area_list_[Area]->scratchpad[thread_number_];
double dtgMrg = scratchpad.dispatchableGenerationMargin[hour];
const double dtgMrg = scratchpad.dispatchableGenerationMargin[hour];
const double ens = hourlyResults.ValeursHorairesDeDefaillancePositive[hour];
const bool triggered = problemeHebdo_->adequacyPatchRuntimeData
->wasCSRTriggeredAtAreaHour(Area, hour);
hourlyResults.ValeursHorairesDtgMrgCsr[hour] = recomputeDTG_MRG(triggered, dtgMrg, ens);
hourlyResults.ValeursHorairesDeDefaillancePositiveCSR[hour] = recomputeENS_MRG(
triggered,
dtgMrg,
ens);

auto& hourlyResults = problemeHebdo_->ResultatsHoraires[Area];
double& dtgMrgCsr = hourlyResults.ValeursHorairesDtgMrgCsr[hour];
double& ens = hourlyResults.ValeursHorairesDeDefaillancePositive[hour];
double& mrgCost = hourlyResults.CoutsMarginauxHoraires[hour];
// calculate DTG MRG CSR and adjust ENS if neccessary
if (problemeHebdo_->adequacyPatchRuntimeData->wasCSRTriggeredAtAreaHour(Area, hour))
{
if (adqPatchParams_.curtailmentSharing.recomputeDTGMRG)
{
dtgMrgCsr = std::max(0.0, dtgMrg - ens);
ens = std::max(0.0, ens - dtgMrg);
}
// set MRG PRICE to value of unsupplied energy cost, if LOLD=1.0 (ENS>0.5)
if (ens > 0.5)
{
mrgCost = -area_list_[Area]->thermal.unsuppliedEnergyCost;
}
}
else
{
dtgMrgCsr = dtgMrg;
}
const double unsuppliedEnergyCost = area_list_[Area]->thermal.unsuppliedEnergyCost;
hourlyResults.CoutsMarginauxHoraires[hour] = recomputeMRGPrice(
hourlyResults.ValeursHorairesDtgMrgCsr[hour],
hourlyResults.CoutsMarginauxHoraires[hour],
unsuppliedEnergyCost);
}
}
}
Expand Down Expand Up @@ -272,11 +264,6 @@ double CurtailmentSharingPostProcessCmd::calculateDensNewAndTotalLmrViolation()
problemeHebdo_->ResultatsHoraires[Area].ValeursHorairesDENS[hour] = std::max(
0.0,
densNew);
;
// copy spilled Energy values into spilled Energy values after CSR
problemeHebdo_->ResultatsHoraires[Area].ValeursHorairesSpilledEnergyAfterCSR[hour]
= problemeHebdo_->ResultatsHoraires[Area]
.ValeursHorairesDeDefaillanceNegative[hour];
// check LMR violations
totalLmrViolation += LmrViolationAreaHour(
problemeHebdo_,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,10 @@ struct PRODUCTION_THERMIQUE_OPTIMALE
struct RESULTATS_HORAIRES
{
std::vector<double> ValeursHorairesDeDefaillancePositive;
std::vector<double> ValeursHorairesDeDefaillancePositiveCSR;
std::vector<double> ValeursHorairesDENS; // adq patch domestic unsupplied energy
std::vector<int> ValeursHorairesLmrViolations; // adq patch lmr violations
std::vector<double> ValeursHorairesSpilledEnergyAfterCSR; // adq patch spillage after CSR
std::vector<double> ValeursHorairesDtgMrgCsr; // adq patch DTG MRG after CSR
std::vector<double> ValeursHorairesDtgMrgCsr; // adq patch DTG MRG after CSR

std::vector<double> ValeursHorairesDeDefaillanceNegative;

Expand Down
4 changes: 2 additions & 2 deletions src/solver/simulation/sim_alloc_probleme_hebdo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,12 +365,12 @@ void SIM_AllocateAreas(PROBLEME_HEBDO& problem,

problem.ResultatsHoraires[k].ValeursHorairesDeDefaillancePositive.assign(NombreDePasDeTemps,
0.);
problem.ResultatsHoraires[k]
.ValeursHorairesDeDefaillancePositiveCSR.assign(NombreDePasDeTemps, 0.);
problem.ResultatsHoraires[k].ValeursHorairesDENS.assign(NombreDePasDeTemps,
0.); // adq patch
problem.ResultatsHoraires[k].ValeursHorairesLmrViolations.assign(NombreDePasDeTemps,
0); // adq patch
problem.ResultatsHoraires[k].ValeursHorairesSpilledEnergyAfterCSR.assign(NombreDePasDeTemps,
0.); // adq patch
problem.ResultatsHoraires[k].ValeursHorairesDtgMrgCsr.assign(NombreDePasDeTemps,
0.); // adq patch

Expand Down
2 changes: 1 addition & 1 deletion src/solver/variable/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ set(SRC_VARIABLE_ECONOMY
include/antares/solver/variable/economy/STStorageLevelsByCluster.h
include/antares/solver/variable/economy/STStorageCashFlowByCluster.h
include/antares/solver/variable/economy/unsupliedEnergy.h
include/antares/solver/variable/economy/unsupliedEnergyCsr.h
include/antares/solver/variable/economy/domesticUnsuppliedEnergy.h
include/antares/solver/variable/economy/localMatchingRuleViolations.h
include/antares/solver/variable/economy/spilledEnergyAfterCSR.h
include/antares/solver/variable/economy/dtgMarginAfterCsr.h
include/antares/solver/variable/economy/spilledEnergy.h
include/antares/solver/variable/economy/dispatchableGeneration.h
Expand Down
Loading

0 comments on commit fcb5254

Please sign in to comment.