diff --git a/src/solver/variable/CMakeLists.txt b/src/solver/variable/CMakeLists.txt index eeb6ab9bc5c..44228fcb15f 100644 --- a/src/solver/variable/CMakeLists.txt +++ b/src/solver/variable/CMakeLists.txt @@ -77,6 +77,7 @@ set(SRC_VARIABLE_ECONOMY include/antares/solver/variable/economy/all.h include/antares/solver/variable/economy/economy_base.h include/antares/solver/variable/economy/links.h + include/antares/solver/variable/economy/economy_base.h # Variables for Economy include/antares/solver/variable/economy/max-mrg-utils.h @@ -99,8 +100,6 @@ set(SRC_VARIABLE_ECONOMY include/antares/solver/variable/economy/STStorageWithdrawalByCluster.h 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/priceCSR.h include/antares/solver/variable/economy/domesticUnsuppliedEnergy.h include/antares/solver/variable/economy/localMatchingRuleViolations.h @@ -124,6 +123,7 @@ set(SRC_VARIABLE_ECONOMY include/antares/solver/variable/economy/nearPriceCap.h include/antares/solver/variable/economy/avail-dispatchable-generation.h include/antares/solver/variable/economy/dispatchable-generation-margin.h + include/antares/solver/variable/economy/unsupliedEnergy.h # Links include/antares/solver/variable/economy/links/flowLinear.h diff --git a/src/solver/variable/include/antares/solver/variable/economy/all.h b/src/solver/variable/include/antares/solver/variable/economy/all.h index e63f4758ec5..c97febf5bd8 100644 --- a/src/solver/variable/include/antares/solver/variable/economy/all.h +++ b/src/solver/variable/include/antares/solver/variable/economy/all.h @@ -78,7 +78,6 @@ #include "spilledEnergy.h" #include "thermalAirPollutantEmissions.h" #include "unsupliedEnergy.h" -#include "unsupliedEnergyCsr.h" #include "waterValue.h" namespace Antares::Solver::Variable::Economy diff --git a/src/solver/variable/include/antares/solver/variable/economy/economy_base.h b/src/solver/variable/include/antares/solver/variable/economy/economy_base.h index b75a9fd4745..248bedf6958 100644 --- a/src/solver/variable/include/antares/solver/variable/economy/economy_base.h +++ b/src/solver/variable/include/antares/solver/variable/economy/economy_base.h @@ -223,7 +223,7 @@ class Economy_Base { if (Traits::checkCondition(state)) { - pValuesForTheCurrentYear[numSpace][state.hourInTheYear] = Traits::value(); + pValuesForTheCurrentYear[numSpace][state.hourInTheYear] = Traits::value(state); } // Next variable diff --git a/src/solver/variable/include/antares/solver/variable/economy/lold.h b/src/solver/variable/include/antares/solver/variable/economy/lold.h index 52bd7ca7ac9..94e1bbe4bcc 100644 --- a/src/solver/variable/include/antares/solver/variable/economy/lold.h +++ b/src/solver/variable/include/antares/solver/variable/economy/lold.h @@ -20,6 +20,7 @@ */ #pragma once +#include "economy_base.h" #include "lold_base.h" namespace Antares::Solver::Variable::Economy diff --git a/src/solver/variable/include/antares/solver/variable/economy/lold_base.h b/src/solver/variable/include/antares/solver/variable/economy/lold_base.h index 6b53397df9f..643c01ee6b1 100644 --- a/src/solver/variable/include/antares/solver/variable/economy/lold_base.h +++ b/src/solver/variable/include/antares/solver/variable/economy/lold_base.h @@ -21,8 +21,6 @@ #pragma once -#include "economy_base.h" - namespace Antares::Solver::Variable::Economy { @@ -44,7 +42,7 @@ struct LOLD_Base_Traits static constexpr uint8_t spatialAggregate = Category::spatialAggregateSumThen1IfPositive; - static double value() + static double value(const State&) { return 1.; } diff --git a/src/solver/variable/include/antares/solver/variable/economy/lolp_base.h b/src/solver/variable/include/antares/solver/variable/economy/lolp_base.h index bd7dd107fe6..aa56d476eff 100644 --- a/src/solver/variable/include/antares/solver/variable/economy/lolp_base.h +++ b/src/solver/variable/include/antares/solver/variable/economy/lolp_base.h @@ -21,8 +21,6 @@ #pragma once -#include "economy_base.h" - namespace Antares::Solver::Variable::Economy { @@ -39,7 +37,7 @@ struct LOLP_Base_Traits static constexpr uint8_t spatialAggregate = Category::spatialAggregateOr; - static double value() + static double value(const State&) { return 100.; } diff --git a/src/solver/variable/include/antares/solver/variable/economy/unsupliedEnergy.h b/src/solver/variable/include/antares/solver/variable/economy/unsupliedEnergy.h index 0df3c3ab551..db3bbe48f2f 100644 --- a/src/solver/variable/include/antares/solver/variable/economy/unsupliedEnergy.h +++ b/src/solver/variable/include/antares/solver/variable/economy/unsupliedEnergy.h @@ -18,247 +18,97 @@ * You should have received a copy of the Mozilla Public Licence 2.0 * along with Antares_Simulator. If not, see . */ -#ifndef __SOLVER_VARIABLE_ECONOMY_UnsupliedEnergy_H__ -#define __SOLVER_VARIABLE_ECONOMY_UnsupliedEnergy_H__ -#include "antares/solver/variable/variable.h" +#pragma once +#include "antares/solver/variable/categories.h" +#include "antares/solver/variable/state.h" +#include "antares/solver/variable/storage/intermediate.h" +#include "antares/solver/variable/storage/results.h" namespace Antares::Solver::Variable::Economy { -struct VCardUnsupliedEnergy + +struct UnsuppliedEnergyTrait { - //! Caption static std::string Caption() { return "UNSP. ENRG"; } - //! Unit static std::string Unit() { return "MWh"; } - //! The short description of the variable static std::string Description() { return "Unsuplied Energy (demand that cannot be satisfied)"; } - //! The expecte results typedef Results>>>> ResultsType; - - //! The VCard to look for for calculating spatial aggregates - typedef VCardUnsupliedEnergy VCardForSpatialAggregate; - - //! Data Level - static constexpr uint8_t categoryDataLevel = Category::DataLevel::area; - //! File level (provided by the type of the results) - static constexpr uint8_t categoryFileLevel = ResultsType::categoryFile - & (Category::FileLevel::id - | Category::FileLevel::va); - //! Precision (views) - static constexpr uint8_t precision = Category::all; - //! Indentation (GUI) - static constexpr uint8_t nodeDepthForGUI = +0; - //! Decimal precision static constexpr uint8_t decimal = 0; - //! Number of columns used by the variable (One ResultsType per column) - static constexpr int columnCount = 1; - //! The Spatial aggregation static constexpr uint8_t spatialAggregate = Category::spatialAggregateSum; - static constexpr uint8_t spatialAggregateMode = Category::spatialAggregateEachYear; - static constexpr uint8_t spatialAggregatePostProcessing = 0; - //! Intermediate values - static constexpr uint8_t hasIntermediateValues = 1; - //! Can this variable be non applicable (0 : no, 1 : yes) - static constexpr uint8_t isPossiblyNonApplicable = 0; - - typedef IntermediateValues IntermediateValuesBaseType; - typedef std::vector IntermediateValuesType; - - using IntermediateValuesTypeForSpatialAg = std::unique_ptr; - -}; // class VCard - -/*! -** \brief C02 Average value of the overrall UnsupliedEnergy emissions expected from all -** the thermal dispatchable clusters -*/ -template -class UnsupliedEnergy - : public Variable::IVariable, NextT, VCardUnsupliedEnergy> -{ -public: - //! Type of the next static variable - typedef NextT NextType; - //! VCard - typedef VCardUnsupliedEnergy VCardType; - //! Ancestor - typedef Variable::IVariable, NextT, VCardType> AncestorType; - - //! List of expected results - typedef typename VCardType::ResultsType ResultsType; - - typedef VariableAccessor VariableAccessorType; - - enum - { - //! How many items have we got - count = 1 + NextT::count, - }; - - template - struct Statistics - { - enum - { - count = ((VCardType::categoryDataLevel & CDataLevel - && VCardType::categoryFileLevel & CFile) - ? (NextType::template Statistics::count - + VCardType::columnCount * ResultsType::count) - : NextType::template Statistics::count), - }; - }; - -public: - void initializeFromStudy(Data::Study& study) - { - pNbYearsParallel = study.maxNbYearsInParallel; - - // Intermediate values - InitializeResultsFromStudy(AncestorType::pResults, study); - - pValuesForTheCurrentYear.resize(pNbYearsParallel); - for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++) - { - pValuesForTheCurrentYear[numSpace].initializeFromStudy(study); - } - - // Next - NextType::initializeFromStudy(study); - } - - template - static void InitializeResultsFromStudy(R& results, Data::Study& study) - { - VariableAccessorType::InitializeAndReset(results, study); - } - - void initializeFromArea(Data::Study* study, Data::Area* area) - { - // Next - NextType::initializeFromArea(study, area); - } - - void initializeFromLink(Data::Study* study, Data::AreaLink* link) - { - // Next - NextType::initializeFromAreaLink(study, link); - } - - void simulationBegin() - { - for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++) - { - pValuesForTheCurrentYear[numSpace].reset(); - } - // Next - NextType::simulationBegin(); - } - void simulationEnd() + static void yearBeginLogic(unsigned, IntermediateValues& iv, Data::Area*, unsigned) { - NextType::simulationEnd(); + iv.reset(); } - void yearBegin(unsigned int year, unsigned int numSpace) + static void setValue(const State& state, IntermediateValues& iv, unsigned) { - // Reset the values for the current year - pValuesForTheCurrentYear[numSpace].reset(); - - // Next variable - NextType::yearBegin(year, numSpace); + iv[state.hourInTheYear] = state.hourlyResults + ->ValeursHorairesDeDefaillancePositive[state.hourInTheWeek]; } - void yearEndBuild(State& state, unsigned int year, unsigned int numSpace) + static void computeStats(IntermediateValues& iv) { - // Next variable - NextType::yearEndBuild(state, year, numSpace); + iv.computeStatisticsForTheCurrentYear(); } - void yearEnd(unsigned int year, unsigned int numSpace) + static bool checkCondition(const State&) { - // Compute all statistics for the current year (daily,weekly,monthly) - pValuesForTheCurrentYear[numSpace].computeStatisticsForTheCurrentYear(); - - // Next variable - NextType::yearEnd(year, numSpace); + return true; } - void computeSummary(unsigned int year, unsigned int numSpace) + static double value(const State& state) { - // Merge all those values with the global results - AncestorType::pResults.merge(year, pValuesForTheCurrentYear[numSpace]); - - // Next variable - NextType::computeSummary(year, numSpace); + return state.hourlyResults->ValeursHorairesDeDefaillancePositive[state.hourInTheWeek]; } +}; - void hourBegin(unsigned int hourInTheYear) +struct UnsuppliedEnergyCSRTrait: UnsuppliedEnergyTrait +{ + static std::string Caption() { - // Next variable - NextType::hourBegin(hourInTheYear); + return "UNSP. ENRG CSR"; } - void hourForEachArea(State& state, unsigned int numSpace) + static std::string Description() { - // Total UnsupliedEnergy emissions - pValuesForTheCurrentYear[numSpace][state.hourInTheYear] = - // Current Hydro Storage generation - state.hourlyResults->ValeursHorairesDeDefaillancePositive[state.hourInTheWeek]; - - // Next variable - NextType::hourForEachArea(state, numSpace); + return "Unsuplied Energy after CSR (demand that cannot be satisfied)"; } - Antares::Memory::Stored::ConstReturnType retrieveRawHourlyValuesForCurrentYear( - unsigned int, - unsigned int numSpace) const + static void setValue(const State& state, IntermediateValues& iv, unsigned) { - return pValuesForTheCurrentYear[numSpace].hour; + iv[state.hourInTheYear] = state.hourlyResults + ->ValeursHorairesDeDefaillancePositiveCSR[state.hourInTheWeek]; } - void localBuildAnnualSurveyReport(SurveyResults& results, - int fileLevel, - int precision, - unsigned int numSpace) const + static double value(const State& state) { - // Initializing external pointer on current variable non applicable status - results.isCurrentVarNA = AncestorType::isNonApplicable; - - if (AncestorType::isPrinted[0]) - { - // Write the data for the current year - results.variableCaption = VCardType::Caption(); - results.variableUnit = VCardType::Unit(); - pValuesForTheCurrentYear[numSpace] - .template buildAnnualSurveyReport(results, fileLevel, precision); - } + return state.hourlyResults->ValeursHorairesDeDefaillancePositiveCSR[state.hourInTheWeek]; } +}; -private: - //! Intermediate values for each year - typename VCardType::IntermediateValuesType pValuesForTheCurrentYear; - unsigned int pNbYearsParallel; +template +using UnsupliedEnergy = Economy_Base; -}; // class UnsupliedEnergy +template +using UnsupliedEnergyCSR = Economy_Base; } // namespace Antares::Solver::Variable::Economy - -#endif // __SOLVER_VARIABLE_ECONOMY_UnsupliedEnergy_H__ diff --git a/src/solver/variable/include/antares/solver/variable/economy/unsupliedEnergyCsr.h b/src/solver/variable/include/antares/solver/variable/economy/unsupliedEnergyCsr.h deleted file mode 100644 index 65b407018c0..00000000000 --- a/src/solver/variable/include/antares/solver/variable/economy/unsupliedEnergyCsr.h +++ /dev/null @@ -1,252 +0,0 @@ -/* - * Copyright 2007-2025, 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 . - */ -#pragma once - -#include "antares/solver/variable/variable.h" - -namespace Antares::Solver::Variable::Economy -{ -struct VCardUnsupliedEnergyCSR -{ - //! Caption - static std::string Caption() - { - return "UNSP. ENRG CSR"; - } - - //! Unit - static std::string Unit() - { - return "MWh"; - } - - //! The short description of the variable - static std::string Description() - { - return "Unsuplied Energy after CSR (demand that cannot be satisfied)"; - } - - //! The expecte results - typedef Results>>>> - ResultsType; - - //! The VCard to look for for calculating spatial aggregates - typedef VCardUnsupliedEnergyCSR VCardForSpatialAggregate; - static constexpr uint8_t categoryDataLevel = Category::DataLevel::area; - //! File level (provided by the type of the results) - static constexpr uint8_t categoryFileLevel = ResultsType::categoryFile - & (Category::FileLevel::id - | Category::FileLevel::va); - //! Precision (views) - static constexpr uint8_t precision = Category::all; - //! Indentation (GUI) - static constexpr uint8_t nodeDepthForGUI = +0; - //! Decimal precision - static constexpr uint8_t decimal = 0; - //! Number of columns used by the variable (One ResultsType per column) - static constexpr int columnCount = 1; - //! The Spatial aggregation - static constexpr uint8_t spatialAggregate = Category::spatialAggregateSum; - static constexpr uint8_t spatialAggregateMode = Category::spatialAggregateEachYear; - static constexpr uint8_t spatialAggregatePostProcessing = 0; - //! Intermediate values - static constexpr uint8_t hasIntermediateValues = 1; - //! Can this variable be non applicable (0 : no, 1 : yes) - static constexpr uint8_t isPossiblyNonApplicable = 0; - - typedef IntermediateValues IntermediateValuesBaseType; - typedef std::vector IntermediateValuesType; - - using IntermediateValuesTypeForSpatialAg = std::unique_ptr; - -}; // class VCard - -template -class UnsupliedEnergyCSR - : public Variable::IVariable, NextT, VCardUnsupliedEnergyCSR> -{ -public: - //! Type of the next static variable - typedef NextT NextType; - //! VCard - typedef VCardUnsupliedEnergyCSR VCardType; - //! Ancestor - typedef Variable::IVariable, NextT, VCardType> AncestorType; - - //! List of expected results - typedef typename VCardType::ResultsType ResultsType; - - typedef VariableAccessor VariableAccessorType; - - enum - { - //! How many items have we got - count = 1 + NextT::count, - }; - - template - struct Statistics - { - enum - { - count = ((VCardType::categoryDataLevel & CDataLevel - && VCardType::categoryFileLevel & CFile) - ? (NextType::template Statistics::count - + VCardType::columnCount * ResultsType::count) - : NextType::template Statistics::count), - }; - }; - -public: - void initializeFromStudy(Data::Study& study) - { - pNbYearsParallel = study.maxNbYearsInParallel; - - // Intermediate values - InitializeResultsFromStudy(AncestorType::pResults, study); - - pValuesForTheCurrentYear.resize(pNbYearsParallel); - for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++) - { - pValuesForTheCurrentYear[numSpace].initializeFromStudy(study); - } - - // Next - NextType::initializeFromStudy(study); - } - - template - static void InitializeResultsFromStudy(R& results, Data::Study& study) - { - VariableAccessorType::InitializeAndReset(results, study); - } - - void initializeFromArea(Data::Study* study, Data::Area* area) - { - // Next - NextType::initializeFromArea(study, area); - } - - void initializeFromLink(Data::Study* study, Data::AreaLink* link) - { - // Next - NextType::initializeFromAreaLink(study, link); - } - - void simulationBegin() - { - for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++) - { - pValuesForTheCurrentYear[numSpace].reset(); - } - // Next - NextType::simulationBegin(); - } - - void simulationEnd() - { - NextType::simulationEnd(); - } - - void yearBegin(unsigned int year, unsigned int numSpace) - { - // Reset the values for the current year - pValuesForTheCurrentYear[numSpace].reset(); - - // Next variable - NextType::yearBegin(year, numSpace); - } - - void yearEndBuild(State& state, unsigned int year, unsigned int numSpace) - { - // Next variable - NextType::yearEndBuild(state, year, numSpace); - } - - void yearEnd(unsigned int year, unsigned int numSpace) - { - // Compute all statistics for the current year (daily,weekly,monthly) - pValuesForTheCurrentYear[numSpace].computeStatisticsForTheCurrentYear(); - - // Next variable - NextType::yearEnd(year, numSpace); - } - - void computeSummary(unsigned int year, unsigned int numSpace) - { - // Merge all those values with the global results - AncestorType::pResults.merge(year, pValuesForTheCurrentYear[numSpace]); - - // Next variable - NextType::computeSummary(year, numSpace); - } - - void hourBegin(unsigned int hourInTheYear) - { - // Next variable - NextType::hourBegin(hourInTheYear); - } - - void hourForEachArea(State& state, unsigned int numSpace) - { - pValuesForTheCurrentYear[numSpace][state.hourInTheYear] - = state.hourlyResults->ValeursHorairesDeDefaillancePositiveCSR[state.hourInTheWeek]; - // Next variable - NextType::hourForEachArea(state, numSpace); - } - - Antares::Memory::Stored::ConstReturnType retrieveRawHourlyValuesForCurrentYear( - unsigned int, - unsigned int numSpace) const - { - return pValuesForTheCurrentYear[numSpace].hour; - } - - void localBuildAnnualSurveyReport(SurveyResults& results, - int fileLevel, - int precision, - unsigned int numSpace) const - { - // Initializing external pointer on current variable non applicable status - results.isCurrentVarNA = AncestorType::isNonApplicable; - - if (AncestorType::isPrinted[0]) - { - // Write the data for the current year - results.variableCaption = VCardType::Caption(); - results.variableUnit = VCardType::Unit(); - pValuesForTheCurrentYear[numSpace] - .template buildAnnualSurveyReport(results, fileLevel, precision); - } - } - -private: - //! Intermediate values for each year - typename VCardType::IntermediateValuesType pValuesForTheCurrentYear; - unsigned int pNbYearsParallel; - -}; // class UnsupliedEnergyCSR - -} // namespace Antares::Solver::Variable::Economy