From ff40ec22dbee53aa73883d60fb5ba1cfdd947546 Mon Sep 17 00:00:00 2001 From: payetvin <113102157+payetvin@users.noreply.github.com> Date: Mon, 1 Jul 2024 16:25:47 +0200 Subject: [PATCH] Harmonize time constants (#2203) close #2188 --------- Co-authored-by: Florian OMNES --- src/libs/antares/date/date.cpp | 29 ++-- .../include/antares/antares/constants.h | 5 +- src/libs/antares/study/area/scratchpad.cpp | 3 +- src/solver/hydro/management/daily.cpp | 30 ++-- src/solver/hydro/management/monthly.cpp | 36 ++--- .../antares/solver/simulation/solver.hxx | 1 - src/solver/ts-generator/hydro.cpp | 12 +- src/solver/variable/CMakeLists.txt | 3 +- .../antares/solver/variable/categories.h | 59 +------- .../antares/solver/variable/constants.h | 134 ------------------ .../solver/variable/economy/STSbyGroup.h | 2 +- .../economy/STStorageCashFlowByCluster.h | 2 +- .../economy/STStorageInjectionByCluster.h | 2 +- .../economy/STStorageLevelsByCluster.h | 2 +- .../economy/STStorageWithdrawalByCluster.h | 2 +- .../economy/links/congestionProbability.h | 8 +- .../economy/productionByDispatchablePlant.h | 14 +- .../economy/productionByRenewablePlant.h | 2 +- .../include/antares/solver/variable/info.h | 30 ++-- .../include/antares/solver/variable/print.h | 102 +++++++++++-- .../include/antares/solver/variable/state.h | 22 ++- .../antares/solver/variable/storage/average.h | 16 +-- .../solver/variable/storage/averagedata.h | 8 +- .../solver/variable/storage/intermediate.h | 6 +- .../solver/variable/storage/intermediate.hxx | 14 +- .../solver/variable/storage/minmax-data.h | 8 +- .../antares/solver/variable/storage/minmax.h | 38 ++--- .../antares/solver/variable/storage/raw.h | 14 +- .../antares/solver/variable/storage/rawdata.h | 6 +- .../solver/variable/storage/stdDeviation.h | 43 +++--- .../antares/solver/variable/variable.h | 1 - src/solver/variable/state.cpp | 23 ++- src/solver/variable/storage/averagedata.cpp | 18 +-- src/solver/variable/storage/intermediate.cpp | 32 ++--- src/solver/variable/storage/rawdata.cpp | 18 +-- .../variable/surveyresults/surveyresults.cpp | 11 +- 36 files changed, 330 insertions(+), 426 deletions(-) delete mode 100644 src/solver/variable/include/antares/solver/variable/constants.h diff --git a/src/libs/antares/date/date.cpp b/src/libs/antares/date/date.cpp index 1d309201a2..acec182242 100644 --- a/src/libs/antares/date/date.cpp +++ b/src/libs/antares/date/date.cpp @@ -21,6 +21,8 @@ #include +#include + #include #include #include @@ -32,7 +34,7 @@ using namespace Yuni; namespace Antares::Date { -static const uint StandardDaysPerMonths[12] = { +static const uint StandardDaysPerMonths[MONTHS_PER_YEAR] = { 31, // january 28, // february 31, // march @@ -137,12 +139,13 @@ bool StringToMonth(MonthName& out, AnyString text) return false; } text.trim(); - CString<12, false> t = text; - t.toLower(); + std::string t = text; + boost::algorithm::to_lower(t); + /* t.toLower(); */ if (t.size() == 3) { - for (uint m = 0; m != 12; ++m) + for (uint m = 0; m != MONTHS_PER_YEAR; ++m) { if (monthShortLowerNames[m] == t) { @@ -153,7 +156,7 @@ bool StringToMonth(MonthName& out, AnyString text) } else { - for (uint m = 0; m != 12; ++m) + for (uint m = 0; m != MONTHS_PER_YEAR; ++m) { if (monthNamesLower[m] == t) { @@ -168,22 +171,22 @@ bool StringToMonth(MonthName& out, AnyString text) const char* MonthToString(int m, int offset) { - return monthNames[(m - offset) % 12]; + return monthNames[(m - offset) % MONTHS_PER_YEAR]; } const char* MonthToLowerString(int m, int offset) { - return monthNamesLower[(m - offset) % 12]; + return monthNamesLower[(m - offset) % MONTHS_PER_YEAR]; } const char* MonthToShortString(int m, int offset) { - return monthShortNames[(m - offset) % 12]; + return monthShortNames[(m - offset) % MONTHS_PER_YEAR]; } const char* MonthToUpperShortString(int m, int offset) { - return monthShortUpperNames[(m - offset) % 12]; + return monthShortUpperNames[(m - offset) % MONTHS_PER_YEAR]; } const char* WeekdayToString(int m) @@ -424,7 +427,7 @@ bool Calendar::saveToCSVFile(const AnyString& filename) const line.clear() << "hour begin\thour end\tdays\tday uear begin\tday year end\tfirst weekday"; report.months.push_back(line); - for (uint m = 0; m != 12; ++m) + for (uint m = 0; m != MONTHS_PER_YEAR; ++m) { auto& month = months[m]; line.clear(); @@ -494,10 +497,10 @@ void Calendar::reset() (void)::memset(months, '\0', sizeof(months)); // Reset months relationship - for (uint m = 0; m != 12 + 1; ++m) + for (uint m = 0; m != MONTHS_PER_YEAR + 1; ++m) { - uint realmonth = (m + (uint)settings_.firstMonth) % 12; - if (m < 12) + uint realmonth = (m + (uint)settings_.firstMonth) % MONTHS_PER_YEAR; + if (m < MONTHS_PER_YEAR) { mapping.months[realmonth] = m; } diff --git a/src/libs/antares/include/antares/antares/constants.h b/src/libs/antares/include/antares/antares/constants.h index d2bb24bacd..c29e81c1ef 100644 --- a/src/libs/antares/include/antares/antares/constants.h +++ b/src/libs/antares/include/antares/antares/constants.h @@ -51,12 +51,15 @@ #include const unsigned int HOURS_PER_DAY = 24; + +const unsigned int MONTHS_PER_YEAR = 12; +const unsigned int WEEKS_PER_YEAR = 53; const unsigned int DAYS_PER_YEAR = 365; const unsigned int HOURS_PER_YEAR = 8760; namespace Antares::Constants { -extern const std::array daysPerMonth; +extern const std::array daysPerMonth; extern const unsigned int nbHoursInAWeek; } // namespace Antares::Constants diff --git a/src/libs/antares/study/area/scratchpad.cpp b/src/libs/antares/study/area/scratchpad.cpp index a08d6b01c3..d0a1637a1d 100644 --- a/src/libs/antares/study/area/scratchpad.cpp +++ b/src/libs/antares/study/area/scratchpad.cpp @@ -66,7 +66,6 @@ AreaScratchpad::AreaScratchpad(const StudyRuntimeInfos& rinfos, Area& area): { // alias to the simulation mode auto mode = rinfos.mode; - uint nbMonthsPerYear = 12; for (uint i = 0; i != 168; ++i) { @@ -168,7 +167,7 @@ AreaScratchpad::AreaScratchpad(const StudyRuntimeInfos& rinfos, Area& area): auto& colPowerOverWater = m[PreproHydro::powerOverWater]; auto& colMaxEnergy = m[PreproHydro::maximumEnergy]; - for (uint month = 0; month < nbMonthsPerYear; ++month) + for (uint month = 0; month < MONTHS_PER_YEAR; ++month) { valueCol += colMaxEnergy[month] * (1. - colPowerOverWater[month]); } diff --git a/src/solver/hydro/management/daily.cpp b/src/solver/hydro/management/daily.cpp index 64072a5097..254ab2b1b2 100644 --- a/src/solver/hydro/management/daily.cpp +++ b/src/solver/hydro/management/daily.cpp @@ -86,11 +86,11 @@ struct DebugData std::array OVF{0}; std::array DEV{0}; std::array VIO{0}; - std::array deviationMax{0}; - std::array violationMax{0}; - std::array WASTE{0}; - std::array CoutTotal{0}; - std::array previousMonthWaste{0}; + std::array deviationMax{0}; + std::array violationMax{0}; + std::array WASTE{0}; + std::array CoutTotal{0}; + std::array previousMonthWaste{0}; Solver::IResultWriter& pWriter; const Antares::Data::AreaDependantHydroManagementData& data; @@ -163,9 +163,9 @@ struct DebugData << ".txt"; buffer << "\tNiveau init : " << hydro_specific.monthly[initReservoirLvlMonth].MOL << "\n"; - for (uint month = 0; month != 12; ++month) + for (uint month = 0; month != MONTHS_PER_YEAR; ++month) { - uint realmonth = (initReservoirLvlMonth + month) % 12; + uint realmonth = (initReservoirLvlMonth + month) % MONTHS_PER_YEAR; uint simulationMonth = calendar.mapping.months[realmonth]; auto daysPerMonth = calendar.months[simulationMonth].days; @@ -272,7 +272,7 @@ inline void HydroManagement::prepareDailyOptimalGenerations( hydro_specific); } - for (uint month = 0; month != 12; ++month) + for (uint month = 0; month != MONTHS_PER_YEAR; ++month) { auto daysPerMonth = calendar_.months[month].days; assert(daysPerMonth <= maxOPP); @@ -298,7 +298,7 @@ inline void HydroManagement::prepareDailyOptimalGenerations( || (area.hydro.useHeuristicTarget && !area.hydro.followLoadModulations)) { dayYear = 0; - for (uint month = 0; month != 12; ++month) + for (uint month = 0; month != MONTHS_PER_YEAR; ++month) { auto daysPerMonth = calendar_.months[month].days; for (uint day = 0; day != daysPerMonth; ++day) @@ -313,7 +313,7 @@ inline void HydroManagement::prepareDailyOptimalGenerations( else { dayYear = 0; - for (uint month = 0; month != 12; ++month) + for (uint month = 0; month != MONTHS_PER_YEAR; ++month) { uint realmonth = calendar_.months[month].realmonth; auto daysPerMonth = calendar_.months[month].days; @@ -371,7 +371,7 @@ inline void HydroManagement::prepareDailyOptimalGenerations( if (debugData) { dayYear = 0; - for (uint month = 0; month != 12; ++month) + for (uint month = 0; month != MONTHS_PER_YEAR; ++month) { auto daysPerMonth = calendar_.months[month].days; @@ -386,9 +386,9 @@ inline void HydroManagement::prepareDailyOptimalGenerations( if (not area.hydro.reservoirManagement) { - for (uint month = 0; month != 12; ++month) + for (uint month = 0; month != MONTHS_PER_YEAR; ++month) { - uint realmonth = (initReservoirLvlMonth + month) % 12; + uint realmonth = (initReservoirLvlMonth + month) % MONTHS_PER_YEAR; uint simulationMonth = calendar_.mapping.months[realmonth]; auto daysPerMonth = calendar_.months[simulationMonth].days; @@ -453,9 +453,9 @@ inline void HydroManagement::prepareDailyOptimalGenerations( Hydro_problem_costs h2o2_optim_costs(parameters_); - for (uint month = 0; month != 12; ++month) + for (uint month = 0; month != MONTHS_PER_YEAR; ++month) { - uint realmonth = (initReservoirLvlMonth + month) % 12; + uint realmonth = (initReservoirLvlMonth + month) % MONTHS_PER_YEAR; uint simulationMonth = calendar_.mapping.months[realmonth]; auto daysPerMonth = calendar_.months[simulationMonth].days; diff --git a/src/solver/hydro/management/monthly.cpp b/src/solver/hydro/management/monthly.cpp index 684ac4db16..04f2c7b107 100644 --- a/src/solver/hydro/management/monthly.cpp +++ b/src/solver/hydro/management/monthly.cpp @@ -59,9 +59,9 @@ static void CheckHydroAllocationProblem(Data::Area& area, { logs.warning() << area.id << ": lvi = " << lvi; logs.warning() << area.id << ": cost = " << problem.CoutDepassementVolume; - for (uint month = 0; month != 12; ++month) + for (uint month = 0; month != MONTHS_PER_YEAR; ++month) { - uint realmonth = (initLevelMonth + month) % 12; + uint realmonth = (initLevelMonth + month) % MONTHS_PER_YEAR; logs.warning() << "month: " << ((realmonth < 10) ? "0" : "") << realmonth << ", turb.max: " << problem.TurbineMax[realmonth] << ", turb.cible: " << problem.TurbineCible[realmonth] @@ -72,9 +72,9 @@ static void CheckHydroAllocationProblem(Data::Area& area, logs.info(); problem.Volume[initLevelMonth] = lvi; - for (uint month = 0; month != 12; ++month) + for (uint month = 0; month != MONTHS_PER_YEAR; ++month) { - uint realmonth = (initLevelMonth + month) % 12; + uint realmonth = (initLevelMonth + month) % MONTHS_PER_YEAR; logs.warning() << "month: " << ((realmonth < 10) ? "0" : "") << realmonth << ", turbine: " << problem.Turbine[realmonth] << ", volume: " << problem.Volume[realmonth]; @@ -89,14 +89,14 @@ double HydroManagement::prepareMonthlyTargetGenerations( { double total = 0; - for (uint realmonth = 0; realmonth != 12; ++realmonth) + for (uint realmonth = 0; realmonth != MONTHS_PER_YEAR; ++realmonth) { total += data.inflows[realmonth]; } if (not area.hydro.followLoadModulations) { - for (uint realmonth = 0; realmonth != 12; ++realmonth) + for (uint realmonth = 0; realmonth != MONTHS_PER_YEAR; ++realmonth) { hydro_specific.monthly[realmonth].MTG = data.inflows[realmonth]; } @@ -106,7 +106,7 @@ double HydroManagement::prepareMonthlyTargetGenerations( double monthlyMaxDemand = -std::numeric_limits::infinity(); - for (uint realmonth = 0; realmonth != 12; ++realmonth) + for (uint realmonth = 0; realmonth != MONTHS_PER_YEAR; ++realmonth) { if (hydro_specific.monthly[realmonth].MLE > monthlyMaxDemand) { @@ -117,7 +117,7 @@ double HydroManagement::prepareMonthlyTargetGenerations( if (!Utils::isZero(monthlyMaxDemand)) { double coeff = 0.; - for (uint realmonth = 0; realmonth != 12; ++realmonth) + for (uint realmonth = 0; realmonth != MONTHS_PER_YEAR; ++realmonth) { assert(hydro_specific.monthly[realmonth].MLE / monthlyMaxDemand >= 0.); coeff += std::pow(hydro_specific.monthly[realmonth].MLE / monthlyMaxDemand, @@ -129,7 +129,7 @@ double HydroManagement::prepareMonthlyTargetGenerations( coeff = total / coeff; } - for (uint realmonth = 0; realmonth != 12; ++realmonth) + for (uint realmonth = 0; realmonth != MONTHS_PER_YEAR; ++realmonth) { assert(hydro_specific.monthly[realmonth].MLE / monthlyMaxDemand >= 0.); hydro_specific.monthly[realmonth].MTG = coeff @@ -142,7 +142,7 @@ double HydroManagement::prepareMonthlyTargetGenerations( { double coeff = total / 12.; - for (uint realmonth = 0; realmonth != 12; ++realmonth) + for (uint realmonth = 0; realmonth != MONTHS_PER_YEAR; ++realmonth) { hydro_specific.monthly[realmonth].MTG = coeff; } @@ -187,9 +187,9 @@ void HydroManagement::prepareMonthlyOptimalGenerations(double* random_reservoir_ problem.CoutViolMaxDuVolumeMin = 1e5; problem.VolumeInitial = lvi; - for (unsigned month = 0; month != 12; ++month) + for (unsigned month = 0; month != MONTHS_PER_YEAR; ++month) { - uint realmonth = (initReservoirLvlMonth + month) % 12; + uint realmonth = (initReservoirLvlMonth + month) % MONTHS_PER_YEAR; uint simulationMonth = calendar_.mapping.months[realmonth]; uint firstDay = calendar_.months[simulationMonth].daysYear.first; @@ -212,9 +212,9 @@ void HydroManagement::prepareMonthlyOptimalGenerations(double* random_reservoir_ CheckHydroAllocationProblem(area, problem, initReservoirLvlMonth, lvi); } - for (uint month = 0; month != 12; ++month) + for (uint month = 0; month != MONTHS_PER_YEAR; ++month) { - uint realmonth = (initReservoirLvlMonth + month) % 12; + uint realmonth = (initReservoirLvlMonth + month) % MONTHS_PER_YEAR; hydro_specific.monthly[realmonth].MOG = problem.Turbine[month] * area.hydro.reservoirCapacity; @@ -248,7 +248,7 @@ void HydroManagement::prepareMonthlyOptimalGenerations(double* random_reservoir_ { auto& reservoirLevel = area.hydro.reservoirLevel[Data::PartHydro::average]; - for (uint realmonth = 0; realmonth != 12; ++realmonth) + for (uint realmonth = 0; realmonth != MONTHS_PER_YEAR; ++realmonth) { hydro_specific.monthly[realmonth].MOG = data.inflows[realmonth]; hydro_specific.monthly[realmonth].MOL = reservoirLevel[realmonth]; @@ -256,7 +256,7 @@ void HydroManagement::prepareMonthlyOptimalGenerations(double* random_reservoir_ } #ifndef NDEBUG - for (uint realmonth = 0; realmonth != 12; ++realmonth) + for (uint realmonth = 0; realmonth != MONTHS_PER_YEAR; ++realmonth) { assert(!std::isnan(hydro_specific.monthly[realmonth].MOG) && "nan value detected for MOG"); @@ -292,9 +292,9 @@ void HydroManagement::prepareMonthlyOptimalGenerations(double* random_reservoir_ buffer << '\t' << "\tInflows" << '\t' << "\tTarget Gen." << "\tTurbined" << "\tLevels" << '\t' << "\tLvl min" << '\t' << "\tLvl max\n"; - for (uint month = 0; month != 12; ++month) + for (uint month = 0; month != MONTHS_PER_YEAR; ++month) { - uint realmonth = (initReservoirLvlMonth + month) % 12; + uint realmonth = (initReservoirLvlMonth + month) % MONTHS_PER_YEAR; uint simulationMonth = calendar_.mapping.months[realmonth]; diff --git a/src/solver/simulation/include/antares/solver/simulation/solver.hxx b/src/solver/simulation/include/antares/solver/simulation/solver.hxx index cd4ddfc0a9..21e0aeb7a1 100644 --- a/src/solver/simulation/include/antares/solver/simulation/solver.hxx +++ b/src/solver/simulation/include/antares/solver/simulation/solver.hxx @@ -36,7 +36,6 @@ #include "antares/solver/simulation/opt_time_writer.h" #include "antares/solver/simulation/timeseries-numbers.h" #include "antares/solver/ts-generator/generator.h" -#include "antares/solver/variable/constants.h" #include "antares/solver/variable/print.h" namespace Antares::Solver::Simulation diff --git a/src/solver/ts-generator/hydro.cpp b/src/solver/ts-generator/hydro.cpp index 29d0a29f42..2d31f08b22 100644 --- a/src/solver/ts-generator/hydro.cpp +++ b/src/solver/ts-generator/hydro.cpp @@ -66,7 +66,7 @@ bool GenerateHydroTimeSeries(Data::Study& study, uint currentYear, Solver::IResu auto& studyRTI = *(study.runtime); auto& calendar = study.calendar; - uint DIM = 12 * study.areas.size(); + uint DIM = MONTHS_PER_YEAR * study.areas.size(); uint DEM = DIM / 2; Matrix CHSKY; @@ -95,7 +95,7 @@ bool GenerateHydroTimeSeries(Data::Study& study, uint currentYear, Solver::IResu for (uint i = 0; i < DIM; i++) { - uint areaIndexI = i / 12; + uint areaIndexI = i / MONTHS_PER_YEAR; auto* prepro = study.areas.byIndex[areaIndexI]->hydro.prepro; auto& corre = CORRE[i]; @@ -104,10 +104,10 @@ bool GenerateHydroTimeSeries(Data::Study& study, uint currentYear, Solver::IResu for (uint j = 0; j < DIM; j++) { - uint areaIndexJ = j / 12; + uint areaIndexJ = j / MONTHS_PER_YEAR; auto* preproJ = study.areas.byIndex[areaIndexJ]->hydro.prepro; - x = std::abs(((int)(i % 12) - (int)(j % 12)) / 2.); + x = std::abs(((int)(i % MONTHS_PER_YEAR) - (int)(j % MONTHS_PER_YEAR)) / 2.); corre[j] = annualCorrAreaI[areaIndexJ] * pow(prepro->intermonthlyCorrelation * preproJ->intermonthlyCorrelation, x); @@ -167,7 +167,7 @@ bool GenerateHydroTimeSeries(Data::Study& study, uint currentYear, Solver::IResu } for (uint i = 0; i < DIM; ++i) { - auto& area = *(study.areas.byIndex[i / 12]); + auto& area = *(study.areas.byIndex[i / MONTHS_PER_YEAR]); auto& prepro = *area.hydro.prepro; auto& series = *area.hydro.series; auto ror = series.ror[l]; @@ -178,7 +178,7 @@ bool GenerateHydroTimeSeries(Data::Study& study, uint currentYear, Solver::IResu auto& colMaxEnergy = prepro.data[Data::PreproHydro::maximumEnergy]; auto& colPOW = prepro.data[Data::PreproHydro::powerOverWater]; - uint month = i % 12; + uint month = i % MONTHS_PER_YEAR; uint realmonth = calendar.months[month].realmonth; assert(l < series.ror.timeSeries.width); diff --git a/src/solver/variable/CMakeLists.txt b/src/solver/variable/CMakeLists.txt index 58009ba7b4..11ed4b5c9d 100644 --- a/src/solver/variable/CMakeLists.txt +++ b/src/solver/variable/CMakeLists.txt @@ -16,7 +16,6 @@ set(SRC_VARIABLE include/antares/solver/variable/setofareas.hxx include/antares/solver/variable/bindConstraints.h include/antares/solver/variable/bindConstraints.hxx - include/antares/solver/variable/constants.h include/antares/solver/variable/categories.h include/antares/solver/variable/surveyresults.h include/antares/solver/variable/surveyresults/reportbuilder.hxx @@ -183,4 +182,4 @@ target_link_libraries(antares-solver-variable-info install(DIRECTORY include/antares DESTINATION "include" -) \ No newline at end of file +) diff --git a/src/solver/variable/include/antares/solver/variable/categories.h b/src/solver/variable/include/antares/solver/variable/categories.h index d14b457e76..3c2df86b22 100644 --- a/src/solver/variable/include/antares/solver/variable/categories.h +++ b/src/solver/variable/include/antares/solver/variable/categories.h @@ -21,15 +21,9 @@ #ifndef __SOLVER_VARIABLE_CATEGORIES_H__ #define __SOLVER_VARIABLE_CATEGORIES_H__ -#include "constants.h" +#include -namespace Antares -{ -namespace Solver -{ -namespace Variable -{ -namespace Category +namespace Antares::Solver::Variable::Category { namespace DataLevel { @@ -266,53 +260,6 @@ inline void PrecisionLevelToStream(StreamT& out, int precisionLevel) } } -template -struct MaxRowCount -{ - enum - { - value = 0 - }; -}; - -template<> -struct MaxRowCount -{ - enum - { - value = maxHoursInAYear - }; -}; - -template<> -struct MaxRowCount -{ - enum - { - value = maxDaysInAYear - }; -}; - -template<> -struct MaxRowCount -{ - enum - { - value = maxWeeksInAYear - }; -}; - -template<> -struct MaxRowCount -{ - enum - { - value = maxMonths - }; -}; -} // namespace Category -} // namespace Variable -} // namespace Solver -} // namespace Antares +} // namespace Antares::Solver::Variable::Category #endif // __SOLVER_VARIABLE_CATEGORIES_H__ diff --git a/src/solver/variable/include/antares/solver/variable/constants.h b/src/solver/variable/include/antares/solver/variable/constants.h deleted file mode 100644 index cea6298346..0000000000 --- a/src/solver/variable/include/antares/solver/variable/constants.h +++ /dev/null @@ -1,134 +0,0 @@ -/* -** 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 . -*/ -#ifndef __SOLVER_VARIABLE_CONSTANT_H__ -#define __SOLVER_VARIABLE_CONSTANT_H__ - -namespace Antares -{ -namespace Solver -{ -namespace Variable -{ -constexpr unsigned int maxHoursInAYear = 8785; -constexpr unsigned int maxDaysInAYear = 7 * 53 + 1; // 366, -constexpr unsigned int maxWeeksInAYear = 53; -constexpr unsigned int maxHoursInADay = 24; -constexpr unsigned int maxMonths = 12; -constexpr unsigned int maxDaysInAWeek = 7; -constexpr unsigned int maxHoursInAWeek = 24 * 7; // 168 - -template -struct PrecisionToPrintfFormat -{ - static const char* Value() - { - return "%.6f"; - } -}; - -template<> -struct PrecisionToPrintfFormat<0> -{ - static const char* Value() - { - return "%.0f"; - } -}; - -template<> -struct PrecisionToPrintfFormat<1> -{ - static const char* Value() - { - return "%.1f"; - } -}; - -template<> -struct PrecisionToPrintfFormat<2> -{ - static const char* Value() - { - return "%.2f"; - } -}; - -template<> -struct PrecisionToPrintfFormat<3> -{ - static const char* Value() - { - return "%.3f"; - } -}; - -template<> -struct PrecisionToPrintfFormat<4> -{ - static const char* Value() - { - return "%.4f"; - } -}; - -template<> -struct PrecisionToPrintfFormat<5> -{ - static const char* Value() - { - return "%.5f"; - } -}; - -template -static inline void AssignPrecisionToPrintfFormat(StringT& out, uint precision) -{ - switch (precision) - { - case 0: - out.assign("%.0f", 4); - break; - case 1: - out.assign("%.1f", 4); - break; - case 2: - out.assign("%.2f", 4); - break; - case 3: - out.assign("%.3f", 4); - break; - case 4: - out.assign("%.4f", 4); - break; - case 5: - out.assign("%.5f", 4); - break; - default: - out.assign("%.6f", 4); - break; - } -} - -} // namespace Variable -} // namespace Solver -} // namespace Antares - -#endif // __SOLVER_VARIABLE_CONSTANT_H__ diff --git a/src/solver/variable/include/antares/solver/variable/economy/STSbyGroup.h b/src/solver/variable/include/antares/solver/variable/economy/STSbyGroup.h index 70adaea52a..4e3ad6ee7c 100644 --- a/src/solver/variable/include/antares/solver/variable/economy/STSbyGroup.h +++ b/src/solver/variable/include/antares/solver/variable/economy/STSbyGroup.h @@ -341,7 +341,7 @@ class STSbyGroup: public Variable::IVariable, NextT, VCardSTSb { uint64_t r = (sizeof(IntermediateValues) * nbColumns_ + IntermediateValues::MemoryUsage()) * pNbYearsParallel; - r += sizeof(double) * nbColumns_ * maxHoursInAYear * pNbYearsParallel; + r += sizeof(double) * nbColumns_ * HOURS_PER_YEAR * pNbYearsParallel; r += AncestorType::memoryUsage(); return r; } diff --git a/src/solver/variable/include/antares/solver/variable/economy/STStorageCashFlowByCluster.h b/src/solver/variable/include/antares/solver/variable/economy/STStorageCashFlowByCluster.h index db6beb4c95..eb2eaa48b9 100644 --- a/src/solver/variable/include/antares/solver/variable/economy/STStorageCashFlowByCluster.h +++ b/src/solver/variable/include/antares/solver/variable/economy/STStorageCashFlowByCluster.h @@ -263,7 +263,7 @@ class STstorageCashFlowByCluster: public Variable::IVariableareaWideIndex] .hour[i]; state.thermalClusterPMinOfTheClusterForYear[i] += pminOfTheClusterForYear - [numSpace][(state.thermalCluster->areaWideIndex * maxHoursInAYear) + i]; + [numSpace][(state.thermalCluster->areaWideIndex * HOURS_PER_YEAR) + i]; } // Next variable @@ -322,8 +322,8 @@ class ProductionByDispatchablePlant pValuesForTheCurrentYear[numSpace][cluster->areaWideIndex].hour[state.hourInTheYear] += thermal[area->index].thermalClustersProductions[cluster->areaWideIndex]; - pminOfTheClusterForYear[numSpace][(cluster->areaWideIndex * maxHoursInAYear) - + state.hourInTheYear] + pminOfTheClusterForYear[numSpace] + [(cluster->areaWideIndex * HOURS_PER_YEAR) + state.hourInTheYear] = thermal[area->index].PMinOfClusters[cluster->areaWideIndex]; } @@ -348,7 +348,7 @@ class ProductionByDispatchablePlant { uint64_t r = (sizeof(IntermediateValues) * pSize + IntermediateValues::MemoryUsage()) * pNbYearsParallel; - r += sizeof(double) * pSize * maxHoursInAYear * pNbYearsParallel; + r += sizeof(double) * pSize * HOURS_PER_YEAR * pNbYearsParallel; r += AncestorType::memoryUsage(); return r; } diff --git a/src/solver/variable/include/antares/solver/variable/economy/productionByRenewablePlant.h b/src/solver/variable/include/antares/solver/variable/economy/productionByRenewablePlant.h index 8da6244e49..82ce7b3dcf 100644 --- a/src/solver/variable/include/antares/solver/variable/economy/productionByRenewablePlant.h +++ b/src/solver/variable/include/antares/solver/variable/economy/productionByRenewablePlant.h @@ -312,7 +312,7 @@ class ProductionByRenewablePlant: public Variable::IVariable::ReturnType array = intermediateValues[i].hour; - for (uint y = 0; y != maxHoursInAYear; ++y) + for (uint y = 0; y != HOURS_PER_YEAR; ++y) { array[y] *= v; } @@ -88,7 +88,7 @@ struct VariableAccessor for (uint i = 0; i != ColumnCountT; ++i) { Antares::Memory::Stored::ReturnType array = intermediateValues[i].hour; - for (uint y = 0; y != maxHoursInAYear; ++y) + for (uint y = 0; y != HOURS_PER_YEAR; ++y) { array[y] = std::abs(array[y]) > 0. ? 1. : 0.; } @@ -101,7 +101,7 @@ struct VariableAccessor for (uint i = 0; i != ColumnCountT; ++i) { Antares::Memory::Stored::ReturnType array = intermediateValues[i].hour; - for (uint y = 0; y != maxHoursInAYear; ++y) + for (uint y = 0; y != HOURS_PER_YEAR; ++y) { array[y] = std::abs(array[y]) > 0. ? 100. : 0.; } @@ -247,7 +247,7 @@ struct VariableAccessor = var.retrieveRawHourlyValuesForCurrentYear(i, numSpace); assert(src != NULL); - for (uint h = 0; h != maxHoursInAYear; ++h) + for (uint h = 0; h != HOURS_PER_YEAR; ++h) { out[i].hour[h] += src[h]; } @@ -263,7 +263,7 @@ struct VariableAccessor = var.retrieveRawHourlyValuesForCurrentYear(i, numSpace); assert(src != NULL); - for (uint h = 0; h != maxHoursInAYear; ++h) + for (uint h = 0; h != HOURS_PER_YEAR; ++h) { if (out[i].hour[h] < src[h]) { @@ -289,7 +289,7 @@ struct VariableAccessor for (typename Type::const_iterator i = intermediateValues.begin(); i != end; ++i) { array = (*i).hour; - for (uint y = 0; y != maxHoursInAYear; ++y) + for (uint y = 0; y != HOURS_PER_YEAR; ++y) { array[y] *= v; } @@ -304,7 +304,7 @@ struct VariableAccessor for (typename Type::const_iterator i = intermediateValues.begin(); i != end; ++i) { array = (*i).hour; - for (uint y = 0; y != maxHoursInAYear; ++y) + for (uint y = 0; y != HOURS_PER_YEAR; ++y) { array[y] = std::abs(array[y]) > 0. ? 1. : 0.; } @@ -319,7 +319,7 @@ struct VariableAccessor for (typename Type::const_iterator i = intermediateValues.begin(); i != end; ++i) { array = (*i).hour; - for (uint y = 0; y != maxHoursInAYear; ++y) + for (uint y = 0; y != HOURS_PER_YEAR; ++y) { array[y] = std::abs(array[y]) > 0. ? 100. : 0.; } @@ -516,7 +516,7 @@ struct VariableAccessor = var.retrieveRawHourlyValuesForCurrentYear(i, numSpace); assert(src != NULL); - for (uint h = 0; h != maxHoursInAYear; ++h) + for (uint h = 0; h != HOURS_PER_YEAR; ++h) { out[i].hour[h] += src[h]; } @@ -532,7 +532,7 @@ struct VariableAccessor = var.retrieveRawHourlyValuesForCurrentYear(i, numSpace); assert(src != NULL); - for (uint h = 0; h != maxHoursInAYear; ++h) + for (uint h = 0; h != HOURS_PER_YEAR; ++h) { if (out[i].hour[h] < src[h]) { @@ -553,7 +553,7 @@ struct VariableAccessor static void MultiplyHourlyResultsBy(U& intermediateValues, const double v) { assert(!std::isnan(v)); - for (uint y = 0; y != maxHoursInAYear; ++y) + for (uint y = 0; y != HOURS_PER_YEAR; ++y) { intermediateValues.hour[y] *= v; } @@ -562,7 +562,7 @@ struct VariableAccessor template static void SetTo1IfPositive(U& intermediateValues) { - for (uint y = 0; y != maxHoursInAYear; ++y) + for (uint y = 0; y != HOURS_PER_YEAR; ++y) { intermediateValues.hour[y] = std::abs(intermediateValues.hour[y]) > 0. ? 1. : 0.; } @@ -571,7 +571,7 @@ struct VariableAccessor template static void Or(U& intermediateValues) { - for (uint y = 0; y != maxHoursInAYear; ++y) + for (uint y = 0; y != HOURS_PER_YEAR; ++y) { intermediateValues.hour[y] = std::abs(intermediateValues.hour[y]) > 0. ? 100. : 0.; } @@ -683,7 +683,7 @@ struct VariableAccessor = var.retrieveRawHourlyValuesForCurrentYear(-1, numSpace); assert(src != NULL); - for (uint h = 0; h != maxHoursInAYear; ++h) + for (uint h = 0; h != HOURS_PER_YEAR; ++h) { out.hour[h] += src[h]; } @@ -696,7 +696,7 @@ struct VariableAccessor = var.retrieveRawHourlyValuesForCurrentYear(-1, numSpace); assert(src != NULL); - for (uint h = 0; h != maxHoursInAYear; ++h) + for (uint h = 0; h != HOURS_PER_YEAR; ++h) { if (out.hour[h] < src[h]) { diff --git a/src/solver/variable/include/antares/solver/variable/print.h b/src/solver/variable/include/antares/solver/variable/print.h index 9f398ab86b..5ac4b0617a 100644 --- a/src/solver/variable/include/antares/solver/variable/print.h +++ b/src/solver/variable/include/antares/solver/variable/print.h @@ -23,11 +23,7 @@ #include -namespace Antares -{ -namespace Solver -{ -namespace Variable +namespace Antares::Solver::Variable { class PrintInfosStdCout final { @@ -86,8 +82,98 @@ class PrintInfosStdCout final Yuni::String pBuffer; }; -} // namespace Variable -} // namespace Solver -} // namespace Antares +template +struct PrecisionToPrintfFormat +{ + static const char* Value() + { + return "%.6f"; + } +}; + +template<> +struct PrecisionToPrintfFormat<0> +{ + static const char* Value() + { + return "%.0f"; + } +}; + +template<> +struct PrecisionToPrintfFormat<1> +{ + static const char* Value() + { + return "%.1f"; + } +}; + +template<> +struct PrecisionToPrintfFormat<2> +{ + static const char* Value() + { + return "%.2f"; + } +}; + +template<> +struct PrecisionToPrintfFormat<3> +{ + static const char* Value() + { + return "%.3f"; + } +}; + +template<> +struct PrecisionToPrintfFormat<4> +{ + static const char* Value() + { + return "%.4f"; + } +}; + +template<> +struct PrecisionToPrintfFormat<5> +{ + static const char* Value() + { + return "%.5f"; + } +}; + +template +static inline void AssignPrecisionToPrintfFormat(StringT& out, uint precision) +{ + switch (precision) + { + case 0: + out.assign("%.0f", 4); + break; + case 1: + out.assign("%.1f", 4); + break; + case 2: + out.assign("%.2f", 4); + break; + case 3: + out.assign("%.3f", 4); + break; + case 4: + out.assign("%.4f", 4); + break; + case 5: + out.assign("%.5f", 4); + break; + default: + out.assign("%.6f", 4); + break; + } +} + +} // namespace Antares::Solver::Variable #endif // __SOLVER_VARIABLE_PRINT_H__ diff --git a/src/solver/variable/include/antares/solver/variable/state.h b/src/solver/variable/include/antares/solver/variable/state.h index 597b692d9e..eb3edda98c 100644 --- a/src/solver/variable/include/antares/solver/variable/state.h +++ b/src/solver/variable/include/antares/solver/variable/state.h @@ -32,8 +32,6 @@ #include "antares/solver/simulation/sim_structure_donnees.h" #include "antares/solver/simulation/sim_structure_probleme_economique.h" -#include "constants.h" - namespace Antares::Solver::Variable { class ThermalState @@ -115,14 +113,14 @@ class State void yearEndBuildThermalClusterCalculateStartupCosts( const uint& maxDurationON, - const std::array& ON_min, - const std::array& ON_opt, + const std::array& ON_min, + const std::array& ON_opt, const Data::ThermalCluster* currentCluster); - std::array computeEconomicallyOptimalNbClustersONforEachHour( + std::array computeEconomicallyOptimalNbClustersONforEachHour( const uint& maxDurationON, - const std::array& ON_min, - const std::array& ON_max) const; + const std::array& ON_min, + const std::array& ON_max) const; /*! ** \brief Smooth the thermal units run after resolutions @@ -182,17 +180,17 @@ class State VALEURS_DE_NTC_ET_RESISTANCES ntc; //! Thermal production for the current thermal cluster for the whole year - double thermalClusterProductionForYear[Variable::maxHoursInAYear]; + double thermalClusterProductionForYear[HOURS_PER_YEAR]; //! Number of unit dispatched for all clusters for the whole year for ucHeruistic (fast) or //! ucMILP (accurate) - uint thermalClusterDispatchedUnitsCountForYear[Variable::maxHoursInAYear]; + uint thermalClusterDispatchedUnitsCountForYear[HOURS_PER_YEAR]; //! Thermal operating cost for the current thermal cluster for the whole year - double thermalClusterOperatingCostForYear[Variable::maxHoursInAYear]; + double thermalClusterOperatingCostForYear[HOURS_PER_YEAR]; //! Thermal NP Cost for the current thermal cluster for the whole year - double thermalClusterNonProportionalCostForYear[Variable::maxHoursInAYear]; + double thermalClusterNonProportionalCostForYear[HOURS_PER_YEAR]; //! Minimum power of the cluster for the whole year - double thermalClusterPMinOfTheClusterForYear[Variable::maxHoursInAYear]; + double thermalClusterPMinOfTheClusterForYear[HOURS_PER_YEAR]; double renewableClusterProduction; diff --git a/src/solver/variable/include/antares/solver/variable/storage/average.h b/src/solver/variable/include/antares/solver/variable/storage/average.h index 0597d121b8..380915e284 100644 --- a/src/solver/variable/include/antares/solver/variable/storage/average.h +++ b/src/solver/variable/include/antares/solver/variable/storage/average.h @@ -100,20 +100,20 @@ struct Average: public NextT switch (precision) { case Category::hourly: - InternalExportValues(report, - Memory::RawPointer( - avgdata.hourly)); + InternalExportValues(report, + Memory::RawPointer( + avgdata.hourly)); break; case Category::daily: - InternalExportValues(report, - avgdata.daily); + InternalExportValues(report, avgdata.daily); break; case Category::weekly: - InternalExportValues(report, - avgdata.weekly); + InternalExportValues(report, + avgdata.weekly); break; case Category::monthly: - InternalExportValues(report, avgdata.monthly); + InternalExportValues(report, + avgdata.monthly); break; case Category::annual: InternalExportValues<1, VCardT, Category::annual>(report, avgdata.year); diff --git a/src/solver/variable/include/antares/solver/variable/storage/averagedata.h b/src/solver/variable/include/antares/solver/variable/storage/averagedata.h index 22de3ff8c8..0ed11ae239 100644 --- a/src/solver/variable/include/antares/solver/variable/storage/averagedata.h +++ b/src/solver/variable/include/antares/solver/variable/storage/averagedata.h @@ -54,13 +54,13 @@ class AverageData uint64_t dynamicMemoryUsage() const { - return sizeof(double) * maxHoursInAYear + sizeof(double) * nbYearsCapacity; + return sizeof(double) * HOURS_PER_YEAR + sizeof(double) * nbYearsCapacity; } public: - double monthly[maxMonths]; - double weekly[maxWeeksInAYear]; - double daily[maxDaysInAYear]; + double monthly[MONTHS_PER_YEAR]; + double weekly[WEEKS_PER_YEAR]; + double daily[DAYS_PER_YEAR]; Antares::Memory::Stored::Type hourly; double* year; unsigned int nbYearsCapacity; diff --git a/src/solver/variable/include/antares/solver/variable/storage/intermediate.h b/src/solver/variable/include/antares/solver/variable/storage/intermediate.h index 44f54918ad..e7c1757c62 100644 --- a/src/solver/variable/include/antares/solver/variable/storage/intermediate.h +++ b/src/solver/variable/include/antares/solver/variable/storage/intermediate.h @@ -133,11 +133,11 @@ class IntermediateValues final Antares::Data::StudyRuntimeInfos* pRuntimeInfo; //! Values for each month - Type month[maxMonths]; + Type month[MONTHS_PER_YEAR]; //! Values for each week - Type week[maxWeeksInAYear]; + Type week[WEEKS_PER_YEAR]; //! Values for each day in the year - Type day[maxDaysInAYear]; + Type day[DAYS_PER_YEAR]; //! Values for each hour in the year mutable Antares::Memory::Stored::Type hour; //! Year diff --git a/src/solver/variable/include/antares/solver/variable/storage/intermediate.hxx b/src/solver/variable/include/antares/solver/variable/storage/intermediate.hxx index 132b2caba5..9dd74a235a 100644 --- a/src/solver/variable/include/antares/solver/variable/storage/intermediate.hxx +++ b/src/solver/variable/include/antares/solver/variable/storage/intermediate.hxx @@ -21,6 +21,8 @@ #ifndef __SOLVER_VARIABLE_STORAGE_INTERMEDIATE_HXX__ #define __SOLVER_VARIABLE_STORAGE_INTERMEDIATE_HXX__ +#include + namespace Antares { namespace Solver @@ -34,7 +36,7 @@ inline IntermediateValues::~IntermediateValues() inline void IntermediateValues::reset() { - Antares::Memory::Zero(maxHoursInAYear, hour); + Antares::Memory::Zero(HOURS_PER_YEAR, hour); memset(month, 0, sizeof(month)); memset(week, 0, sizeof(week)); memset(day, 0, sizeof(day)); @@ -53,7 +55,7 @@ inline const IntermediateValues::Type& IntermediateValues::operator[]( inline uint64_t IntermediateValues::MemoryUsage() { - return +sizeof(Type) * maxHoursInAYear; + return +sizeof(Type) * HOURS_PER_YEAR; } template @@ -66,16 +68,16 @@ inline void IntermediateValues::buildAnnualSurveyReport(SurveyResults& report, switch (precision) { case Category::hourly: - internalExportAnnualValues(report, hour, false); + internalExportAnnualValues(report, hour, false); break; case Category::daily: - internalExportAnnualValues(report, day, false); + internalExportAnnualValues(report, day, false); break; case Category::weekly: - internalExportAnnualValues(report, week, false); + internalExportAnnualValues(report, week, false); break; case Category::monthly: - internalExportAnnualValues(report, month, false); + internalExportAnnualValues(report, month, false); break; case Category::annual: internalExportAnnualValues<1, VCardT>(report, &year, true); diff --git a/src/solver/variable/include/antares/solver/variable/storage/minmax-data.h b/src/solver/variable/include/antares/solver/variable/storage/minmax-data.h index 156f53fec2..27bc3e89b4 100644 --- a/src/solver/variable/include/antares/solver/variable/storage/minmax-data.h +++ b/src/solver/variable/include/antares/solver/variable/storage/minmax-data.h @@ -46,10 +46,10 @@ class MinMaxData void mergeSup(uint year, const IntermediateValues& rhs); std::vector annual{1}; - std::vector monthly{maxMonths}; - std::vector weekly{maxWeeksInAYear}; - std::vector daily{maxDaysInAYear}; - std::vector hourly{maxHoursInAYear}; + std::vector monthly{MONTHS_PER_YEAR}; + std::vector weekly{WEEKS_PER_YEAR}; + std::vector daily{DAYS_PER_YEAR}; + std::vector hourly{HOURS_PER_YEAR}; }; // class MinMaxData diff --git a/src/solver/variable/include/antares/solver/variable/storage/minmax.h b/src/solver/variable/include/antares/solver/variable/storage/minmax.h index 7866d1a271..6095863374 100644 --- a/src/solver/variable/include/antares/solver/variable/storage/minmax.h +++ b/src/solver/variable/include/antares/solver/variable/storage/minmax.h @@ -83,23 +83,25 @@ struct MinMaxBase: public NextT switch (precision) { case Category::hourly: - InternalExportIndices(report, - Memory::RawPointer( - minmax.hourly.data()), - fileLevel); + InternalExportIndices(report, + Memory::RawPointer( + minmax.hourly.data()), + fileLevel); break; case Category::daily: - InternalExportIndices(report, - minmax.daily.data(), - fileLevel); + InternalExportIndices(report, + minmax.daily.data(), + fileLevel); break; case Category::weekly: - InternalExportIndices(report, - minmax.weekly.data(), - fileLevel); + InternalExportIndices(report, + minmax.weekly.data(), + fileLevel); break; case Category::monthly: - InternalExportIndices(report, minmax.monthly.data(), fileLevel); + InternalExportIndices(report, + minmax.monthly.data(), + fileLevel); break; case Category::annual: InternalExportIndices<1, VCardT>(report, minmax.annual.data(), fileLevel); @@ -111,18 +113,18 @@ struct MinMaxBase: public NextT switch (precision) { case Category::hourly: - InternalExportValues(report, - Memory::RawPointer( - minmax.hourly.data())); + InternalExportValues(report, + Memory::RawPointer( + minmax.hourly.data())); break; case Category::daily: - InternalExportValues(report, minmax.daily.data()); + InternalExportValues(report, minmax.daily.data()); break; case Category::weekly: - InternalExportValues(report, minmax.weekly.data()); + InternalExportValues(report, minmax.weekly.data()); break; case Category::monthly: - InternalExportValues(report, minmax.monthly.data()); + InternalExportValues(report, minmax.monthly.data()); break; case Category::annual: InternalExportValues<1, VCardT>(report, minmax.annual.data()); @@ -143,7 +145,7 @@ struct MinMaxBase: public NextT uint64_t memoryUsage() const { - return sizeof(double) * maxHoursInAYear + NextType::memoryUsage(); + return sizeof(double) * HOURS_PER_YEAR + NextType::memoryUsage(); } template class DecoratorT> diff --git a/src/solver/variable/include/antares/solver/variable/storage/raw.h b/src/solver/variable/include/antares/solver/variable/storage/raw.h index be1c3d9699..e71356953f 100644 --- a/src/solver/variable/include/antares/solver/variable/storage/raw.h +++ b/src/solver/variable/include/antares/solver/variable/storage/raw.h @@ -104,20 +104,20 @@ struct Raw: public NextT switch (precision) { case Category::hourly: - InternalExportValues( + InternalExportValues( report, ::Antares::Memory::RawPointer(rawdata.hourly)); break; case Category::daily: - InternalExportValues(report, - rawdata.daily); + InternalExportValues(report, rawdata.daily); break; case Category::weekly: - InternalExportValues(report, - rawdata.weekly); + InternalExportValues(report, + rawdata.weekly); break; case Category::monthly: - InternalExportValues(report, rawdata.monthly); + InternalExportValues(report, + rawdata.monthly); break; case Category::annual: InternalExportValues(report, rawdata.year); @@ -161,7 +161,7 @@ struct Raw: public NextT uint64_t memoryUsage() const { - return +sizeof(double) * maxHoursInAYear + NextType::memoryUsage(); + return +sizeof(double) * HOURS_PER_YEAR + NextType::memoryUsage(); } template class DecoratorT> diff --git a/src/solver/variable/include/antares/solver/variable/storage/rawdata.h b/src/solver/variable/include/antares/solver/variable/storage/rawdata.h index c559dd57dc..6a2c118c05 100644 --- a/src/solver/variable/include/antares/solver/variable/storage/rawdata.h +++ b/src/solver/variable/include/antares/solver/variable/storage/rawdata.h @@ -56,9 +56,9 @@ class RawData void merge(unsigned int year, const IntermediateValues& rhs); public: - double monthly[maxMonths]; - double weekly[maxWeeksInAYear]; - double daily[maxDaysInAYear]; + double monthly[MONTHS_PER_YEAR]; + double weekly[WEEKS_PER_YEAR]; + double daily[DAYS_PER_YEAR]; Antares::Memory::Stored::Type hourly; double* year; mutable double allYears; diff --git a/src/solver/variable/include/antares/solver/variable/storage/stdDeviation.h b/src/solver/variable/include/antares/solver/variable/storage/stdDeviation.h index a80ac39fdc..44159d9cba 100644 --- a/src/solver/variable/include/antares/solver/variable/storage/stdDeviation.h +++ b/src/solver/variable/include/antares/solver/variable/storage/stdDeviation.h @@ -77,7 +77,7 @@ struct StdDeviation: public NextT protected: void initializeFromStudy(Antares::Data::Study& study) { - Antares::Memory::Allocate(stdDeviationHourly, maxHoursInAYear); + Antares::Memory::Allocate(stdDeviationHourly, HOURS_PER_YEAR); // Next NextType::initializeFromStudy(study); @@ -88,10 +88,10 @@ struct StdDeviation: public NextT void reset() { // Reset - (void)::memset(stdDeviationMonthly, 0, sizeof(double) * maxMonths); - (void)::memset(stdDeviationWeekly, 0, sizeof(double) * maxWeeksInAYear); - (void)::memset(stdDeviationDaily, 0, sizeof(double) * maxDaysInAYear); - Antares::Memory::Zero(maxHoursInAYear, stdDeviationHourly); + (void)::memset(stdDeviationMonthly, 0, sizeof(double) * MONTHS_PER_YEAR); + (void)::memset(stdDeviationWeekly, 0, sizeof(double) * WEEKS_PER_YEAR); + (void)::memset(stdDeviationDaily, 0, sizeof(double) * DAYS_PER_YEAR); + Antares::Memory::Zero(HOURS_PER_YEAR, stdDeviationHourly); stdDeviationYear = 0.; // Next NextType::reset(); @@ -104,22 +104,22 @@ struct StdDeviation: public NextT unsigned int i; // StdDeviation value for each hour throughout all years - for (i = 0; i != maxHoursInAYear; ++i) + for (i = 0; i != HOURS_PER_YEAR; ++i) { stdDeviationHourly[i] += rhs.hour[i] * rhs.hour[i] * pRatio; } // StdDeviation value for each day throughout all years - for (i = 0; i != maxDaysInAYear; ++i) + for (i = 0; i != DAYS_PER_YEAR; ++i) { stdDeviationDaily[i] += rhs.day[i] * rhs.day[i] * pRatio; } // StdDeviation value for each week throughout all years - for (i = 0; i != maxWeeksInAYear; ++i) + for (i = 0; i != WEEKS_PER_YEAR; ++i) { stdDeviationWeekly[i] += rhs.week[i] * rhs.week[i] * pRatio; } // StdDeviation value for each month throughout all years - for (i = 0; i != maxMonths; ++i) + for (i = 0; i != MONTHS_PER_YEAR; ++i) { stdDeviationMonthly[i] += rhs.month[i] * rhs.month[i] * pRatio; } @@ -142,26 +142,27 @@ struct StdDeviation: public NextT switch (precision) { case Category::hourly: - InternalExportValues( + InternalExportValues( report, results, Memory::RawPointer(stdDeviationHourly)); break; case Category::daily: - InternalExportValues(report, - results, - stdDeviationDaily); + InternalExportValues(report, + results, + stdDeviationDaily); break; case Category::weekly: - InternalExportValues( + InternalExportValues( report, results, stdDeviationWeekly); break; case Category::monthly: - InternalExportValues(report, - results, - stdDeviationMonthly); + InternalExportValues( + report, + results, + stdDeviationMonthly); break; case Category::annual: InternalExportValues(report, @@ -180,7 +181,7 @@ struct StdDeviation: public NextT uint64_t memoryUsage() const { - return sizeof(double) * maxHoursInAYear + NextType::memoryUsage(); + return sizeof(double) * HOURS_PER_YEAR + NextType::memoryUsage(); } template class DecoratorT> @@ -194,9 +195,9 @@ struct StdDeviation: public NextT } public: - double stdDeviationMonthly[maxMonths]; - double stdDeviationWeekly[maxWeeksInAYear]; - double stdDeviationDaily[maxDaysInAYear]; + double stdDeviationMonthly[MONTHS_PER_YEAR]; + double stdDeviationWeekly[WEEKS_PER_YEAR]; + double stdDeviationDaily[DAYS_PER_YEAR]; Antares::Memory::Stored::Type stdDeviationHourly; double stdDeviationYear; diff --git a/src/solver/variable/include/antares/solver/variable/variable.h b/src/solver/variable/include/antares/solver/variable/variable.h index 536af9107f..279ba9da3d 100644 --- a/src/solver/variable/include/antares/solver/variable/variable.h +++ b/src/solver/variable/include/antares/solver/variable/variable.h @@ -30,7 +30,6 @@ #include #include "categories.h" -#include "constants.h" #include "container.h" #include "endoflist.h" #include "info.h" diff --git a/src/solver/variable/state.cpp b/src/solver/variable/state.cpp index 9318e49f21..ca8d5b2677 100644 --- a/src/solver/variable/state.cpp +++ b/src/solver/variable/state.cpp @@ -234,20 +234,20 @@ void State::yearEndBuildFromThermalClusterIndex(const uint clusterAreaWideIndex) uint endHourForCurrentYear = startHourForCurrentYear + study.runtime->rangeLimits.hour[Data::rangeCount]; - assert(endHourForCurrentYear <= Variable::maxHoursInAYear); + assert(endHourForCurrentYear <= HOURS_PER_YEAR); // Nombre minimal de groupes en fonctionnement à l'heure h (determiné par Peff et Pnom) - std::array ON_min; + std::array ON_min; // Nombre maximal de groupes en fonctionnement à l'heure h (determine par Peff et Pmin) - std::array ON_max; + std::array ON_max; // Nombre de groupes économiquement optimal en fonctionnement à l'heure h - std::array ON_opt{}; + std::array ON_opt{}; // Get cluster properties Data::ThermalCluster* currentCluster = area->thermal.list.enabledClusterAt(clusterAreaWideIndex) .get(); - assert(endHourForCurrentYear <= Variable::maxHoursInAYear); + assert(endHourForCurrentYear <= HOURS_PER_YEAR); assert(endHourForCurrentYear <= currentCluster->series.timeSeries.height); assert(currentCluster); @@ -373,8 +373,8 @@ void State::yearEndBuildFromThermalClusterIndex(const uint clusterAreaWideIndex) void State::yearEndBuildThermalClusterCalculateStartupCosts( const uint& maxDurationON, - const std::array& ON_min, - const std::array& ON_opt, + const std::array& ON_min, + const std::array& ON_opt, const Data::ThermalCluster* currentCluster) { uint startHourForCurrentYear = study.runtime->rangeLimits.hour[Data::rangeBegin]; @@ -422,18 +422,17 @@ void State::yearEndBuildThermalClusterCalculateStartupCosts( } } -std::array -State::computeEconomicallyOptimalNbClustersONforEachHour( +std::array State::computeEconomicallyOptimalNbClustersONforEachHour( const uint& maxDurationON, - const std::array& ON_min, - const std::array& ON_max) const + const std::array& ON_min, + const std::array& ON_max) const { uint startHourForCurrentYear = study.runtime->rangeLimits.hour[Data::rangeBegin]; uint endHourForCurrentYear = startHourForCurrentYear + study.runtime->rangeLimits.hour[Data::rangeCount]; // Nombre de groupes économiquement optimal en fonctionnement à l'heure h - std::array ON_opt; + std::array ON_opt; uint nivmax; // valeur maximale de ON_opt[h] , progressivement réactualisée à la baisse uint nivmin; // valeur minimale de ON_opt[h] , progressivement réactualisée à la hausse diff --git a/src/solver/variable/storage/averagedata.cpp b/src/solver/variable/storage/averagedata.cpp index aceaf26dcc..4a88945bb6 100644 --- a/src/solver/variable/storage/averagedata.cpp +++ b/src/solver/variable/storage/averagedata.cpp @@ -45,16 +45,16 @@ AverageData::~AverageData() void AverageData::reset() { - Antares::Memory::Zero(maxHoursInAYear, hourly); - (void)::memset(monthly, 0, sizeof(double) * maxMonths); - (void)::memset(weekly, 0, sizeof(double) * maxWeeksInAYear); - (void)::memset(daily, 0, sizeof(double) * maxDaysInAYear); + Antares::Memory::Zero(HOURS_PER_YEAR, hourly); + (void)::memset(monthly, 0, sizeof(double) * MONTHS_PER_YEAR); + (void)::memset(weekly, 0, sizeof(double) * WEEKS_PER_YEAR); + (void)::memset(daily, 0, sizeof(double) * DAYS_PER_YEAR); (void)::memset(year, 0, sizeof(double) * nbYearsCapacity); } void AverageData::initializeFromStudy(Data::Study& study) { - Antares::Memory::Allocate(hourly, maxHoursInAYear); + Antares::Memory::Allocate(hourly, HOURS_PER_YEAR); nbYearsCapacity = study.runtime->rangeLimits.year[Data::rangeEnd] + 1; year = new double[nbYearsCapacity]; @@ -70,22 +70,22 @@ void AverageData::merge(unsigned int y, const IntermediateValues& rhs) double ratio = (double)yearsWeight[y] / (double)yearsWeightSum; // Average value for each hour throughout all years - for (i = 0; i != maxHoursInAYear; ++i) + for (i = 0; i != HOURS_PER_YEAR; ++i) { hourly[i] += rhs.hour[i] * ratio; } // Average value for each day throughout all years - for (i = 0; i != maxDaysInAYear; ++i) + for (i = 0; i != DAYS_PER_YEAR; ++i) { daily[i] += rhs.day[i] * ratio; } // Average value for each week throughout all years - for (i = 0; i != maxWeeksInAYear; ++i) + for (i = 0; i != WEEKS_PER_YEAR; ++i) { weekly[i] += rhs.week[i] * ratio; } // Average value for each month throughout all years - for (i = 0; i != maxMonths; ++i) + for (i = 0; i != MONTHS_PER_YEAR; ++i) { monthly[i] += rhs.month[i] * ratio; } diff --git a/src/solver/variable/storage/intermediate.cpp b/src/solver/variable/storage/intermediate.cpp index 5fb15cc2f4..4799085aaf 100644 --- a/src/solver/variable/storage/intermediate.cpp +++ b/src/solver/variable/storage/intermediate.cpp @@ -35,11 +35,11 @@ IntermediateValues::IntermediateValues(): calendar(nullptr), year(0.) { - Antares::Memory::Allocate(hour, maxHoursInAYear); - Antares::Memory::Zero(maxHoursInAYear, hour); - (void)::memset(month, 0, sizeof(Type) * maxMonths); - (void)::memset(week, 0, sizeof(Type) * maxWeeksInAYear); - (void)::memset(day, 0, sizeof(Type) * maxDaysInAYear); + Antares::Memory::Allocate(hour, HOURS_PER_YEAR); + Antares::Memory::Zero(HOURS_PER_YEAR, hour); + (void)::memset(month, 0, sizeof(Type) * MONTHS_PER_YEAR); + (void)::memset(week, 0, sizeof(Type) * WEEKS_PER_YEAR); + (void)::memset(day, 0, sizeof(Type) * DAYS_PER_YEAR); } void IntermediateValues::initializeFromStudy(Data::Study& study) @@ -87,9 +87,9 @@ void IntermediateValues::computeStatisticsForTheCurrentYear() { double d = 0.; // One day - for (j = 0; j != maxHoursInADay; ++j) + for (j = 0; j != HOURS_PER_DAY; ++j) { - assert(indx < maxHoursInAYear); + assert(indx < HOURS_PER_YEAR); d += hour[indx]; ++indx; } @@ -98,7 +98,7 @@ void IntermediateValues::computeStatisticsForTheCurrentYear() } // weeks - for (i = 0; i != maxWeeksInAYear; ++i) + for (i = 0; i != WEEKS_PER_YEAR; ++i) { week[i] = 0.; } @@ -142,9 +142,9 @@ void IntermediateValues::computeStatisticsOrForTheCurrentYear() { day[i] = 0.; // One day - for (j = 0; j != maxHoursInADay; ++j) + for (j = 0; j != HOURS_PER_DAY; ++j) { - assert(indx < maxHoursInAYear); + assert(indx < HOURS_PER_YEAR); if (hour[indx] > 0.) { day[i] = 100.; @@ -154,7 +154,7 @@ void IntermediateValues::computeStatisticsOrForTheCurrentYear() } // weeks - for (i = 0; i != maxWeeksInAYear; ++i) + for (i = 0; i != WEEKS_PER_YEAR; ++i) { week[i] = 0.; } @@ -220,19 +220,19 @@ void IntermediateValues::computeDailyAveragesForCurrentYear() { // Compute sum of hourly values on the current day of year day_sum = 0.; - for (uint h = 0; h != maxHoursInADay; ++h) + for (uint h = 0; h != HOURS_PER_DAY; ++h) { day_sum += hour[indx]; ++indx; } - day[d] = day_sum / maxHoursInADay; + day[d] = day_sum / HOURS_PER_DAY; } } void IntermediateValues::computeWeeklyAveragesForCurrentYear() { // Re-initialization (a previous MC year could have left non-nil values) - for (int w = 0; w != maxWeeksInAYear; ++w) + for (int w = 0; w != WEEKS_PER_YEAR; ++w) { week[w] = 0.; } @@ -303,7 +303,7 @@ void IntermediateValues::computeProbabilitiesForTheCurrentYear() { d = 0.; // One day - for (j = 0; j != maxHoursInADay; ++j) + for (j = 0; j != HOURS_PER_DAY; ++j) { if (hour[indx] > 0.) { @@ -324,7 +324,7 @@ void IntermediateValues::computeProbabilitiesForTheCurrentYear() } // weeks - for (i = 0; i != maxWeeksInAYear; ++i) + for (i = 0; i != WEEKS_PER_YEAR; ++i) { week[i] = 0.; } diff --git a/src/solver/variable/storage/rawdata.cpp b/src/solver/variable/storage/rawdata.cpp index 117d117bb2..4baf8531bd 100644 --- a/src/solver/variable/storage/rawdata.cpp +++ b/src/solver/variable/storage/rawdata.cpp @@ -42,7 +42,7 @@ RawData::~RawData() void RawData::initializeFromStudy(const Data::Study& study) { - Antares::Memory::Allocate(hourly, maxHoursInAYear); + Antares::Memory::Allocate(hourly, HOURS_PER_YEAR); nbYearsCapacity = study.runtime->rangeLimits.year[Data::rangeEnd] + 1; year = new double[nbYearsCapacity]; } @@ -50,10 +50,10 @@ void RawData::initializeFromStudy(const Data::Study& study) void RawData::reset() { // Reset - Antares::Memory::Zero(maxHoursInAYear, hourly); - (void)::memset(monthly, 0, sizeof(double) * maxMonths); - (void)::memset(weekly, 0, sizeof(double) * maxWeeksInAYear); - (void)::memset(daily, 0, sizeof(double) * maxDaysInAYear); + Antares::Memory::Zero(HOURS_PER_YEAR, hourly); + (void)::memset(monthly, 0, sizeof(double) * MONTHS_PER_YEAR); + (void)::memset(weekly, 0, sizeof(double) * WEEKS_PER_YEAR); + (void)::memset(daily, 0, sizeof(double) * DAYS_PER_YEAR); (void)::memset(year, 0, sizeof(double) * nbYearsCapacity); } @@ -61,22 +61,22 @@ void RawData::merge(unsigned int y, const IntermediateValues& rhs) { unsigned int i; // StdDeviation value for each hour throughout all years - for (i = 0; i != maxHoursInAYear; ++i) + for (i = 0; i != HOURS_PER_YEAR; ++i) { hourly[i] += rhs.hour[i]; } // StdDeviation value for each day throughout all years - for (i = 0; i != maxDaysInAYear; ++i) + for (i = 0; i != DAYS_PER_YEAR; ++i) { daily[i] += rhs.day[i]; } // StdDeviation value for each week throughout all years - for (i = 0; i != maxWeeksInAYear; ++i) + for (i = 0; i != WEEKS_PER_YEAR; ++i) { weekly[i] += rhs.week[i]; } // StdDeviation value for each month throughout all years - for (i = 0; i != maxMonths; ++i) + for (i = 0; i != MONTHS_PER_YEAR; ++i) { monthly[i] += rhs.month[i]; } diff --git a/src/solver/variable/surveyresults/surveyresults.cpp b/src/solver/variable/surveyresults/surveyresults.cpp index 0402fb6c15..bb763a1b80 100644 --- a/src/solver/variable/surveyresults/surveyresults.cpp +++ b/src/solver/variable/surveyresults/surveyresults.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -533,8 +534,8 @@ SurveyResults::SurveyResults(const Data::Study& s, const String& o, IResultWrite values = new ValueType[maxVariables]; for (uint i = 0; i != maxVariables; ++i) { - values[i] = new double[maxHoursInAYear]; - memset(values[i], 0, sizeof(double) * maxHoursInAYear); + values[i] = new double[HOURS_PER_YEAR]; + memset(values[i], 0, sizeof(double) * HOURS_PER_YEAR); } // captions @@ -638,7 +639,7 @@ void SurveyResults::exportDigestAllYears(std::string& buffer) for (auto j = data.rowCaptions.begin(); j != end; ++j, ++y) { // asserts - assert(y < maxHoursInAYear); + assert(y < HOURS_PER_YEAR); buffer.append("\t").append(j->c_str()); @@ -646,7 +647,7 @@ void SurveyResults::exportDigestAllYears(std::string& buffer) for (uint i = 0; i != data.columnIndex; ++i) { assert(i < maxVariables && "i greater can not be greater than maxVariables"); - assert(y < maxHoursInAYear && "y can not be greater than maxHoursInAYear"); + assert(y < HOURS_PER_YEAR && "y can not be greater than HOURS_PER_YEAR"); if (digestNonApplicableStatus[y][i]) { @@ -791,7 +792,7 @@ void SurveyResults::saveToFile(int dataLevel, int fileLevel, int precisionLevel) for (uint y = heightBegin; y < heightEnd; ++y) { // Asserts - assert(y < maxHoursInAYear); + assert(y < HOURS_PER_YEAR); // Index writeDateToFileDescriptor(y + 1, precisionLevel);