From 1711856132060e6f2d21dcc9cd68ca695f4d611c Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Fri, 22 Sep 2023 10:16:53 +0200 Subject: [PATCH 01/40] Power Credits comments and strings changed to Max Power --- docs/reference-guide/03-commands.md | 2 +- docs/reference-guide/04-active_windows.md | 4 ++-- src/libs/antares/study/fwd.h | 2 +- src/libs/antares/study/parameters.cpp | 4 ++-- src/libs/antares/study/parameters.h | 2 +- src/libs/antares/study/parts/hydro/series.cpp | 6 +++--- .../scenario-builder/HydroPowerCreditsTSNumberData.cpp | 2 +- .../scenario-builder/HydroPowerCreditsTSNumberData.h | 2 +- src/libs/antares/study/scenario-builder/rules.h | 2 +- .../aleatoire/alea_tirage_au_sort_chroniques.cpp | 2 +- src/solver/simulation/timeseries-numbers.cpp | 10 +++++----- .../test-sc-builder-file-read-line.cpp | 4 ++-- .../scenario-builder/test-sc-builder-file-save.cpp | 2 +- src/ui/action/handler/antares-study/area/create.cpp | 2 +- .../application/main/build/scenario-builder.cpp | 2 +- .../toolbox/components/datagrid/renderer/column.cpp | 2 +- .../toolbox/components/datagrid/renderer/column.h | 2 +- 17 files changed, 26 insertions(+), 26 deletions(-) diff --git a/docs/reference-guide/03-commands.md b/docs/reference-guide/03-commands.md index 6765f0825a..a0842e2d84 100644 --- a/docs/reference-guide/03-commands.md +++ b/docs/reference-guide/03-commands.md @@ -178,7 +178,7 @@ this command allows to state, for each kind of time-series, whether it should be the available set (be it ready-made or Antares-generated) _**OR**_ should take a user-defined value (in the former case, the default "rand" value should be kept; in the latter, the value should be the reference number of the time-series to use). Multiple simulation profiles can be defined and archived. The default active profile gives the "rand" status for all time-series in all areas (full probabilistic simulation). - Regarding Hydro time-series, the scenario builder gives, in addition to the assignment of a specific number to use for the inflows time-series, the ability to define the initial reservoir level to use for each MC year, also hydro power credits scenario builder is available to support time-series for Maximum Generation and Maximum Pumping because the number of TS's for ROR, Hydro Storage and Minimum Generation can be different than the number of TS's for Maximum Generation and Maximum Pumping. + Regarding Hydro time-series, the scenario builder gives, in addition to the assignment of a specific number to use for the inflows time-series, the ability to define the initial reservoir level to use for each MC year, also hydro max power scenario builder is available to support time-series for Maximum Generation and Maximum Pumping because the number of TS's for ROR, Hydro Storage and Minimum Generation can be different than the number of TS's for Maximum Generation and Maximum Pumping. - **MC Scenario playlist** For each Monte-Carlo year of the simulation defined in the "Simulation" active window, this command allows to state whether a MC year prepared for the simulation should be actually simulated or not. diff --git a/docs/reference-guide/04-active_windows.md b/docs/reference-guide/04-active_windows.md index 2e6e2f66a8..32a2fdf2e1 100644 --- a/docs/reference-guide/04-active_windows.md +++ b/docs/reference-guide/04-active_windows.md @@ -97,10 +97,10 @@ These two parts are detailed hereafter. ### RIGHT PART: Time-series management -For the different kinds of time-series that Antares manages in a non-deterministic way (load, thermal generation, hydro power, hydro power credits, wind power, solar power or renewable depending on the option chosen): +For the different kinds of time-series that Antares manages in a non-deterministic way (load, thermal generation, hydro power, hydro max power, wind power, solar power or renewable depending on the option chosen): 1. **Choice of the kind of time-series to use** -Either « ready-made » or «stochastic » (i.e. Antares-generated), defined by setting the value to either "on" or "off". Exception is hydro power credits that can only be « ready-made ». Note that for Thermal time-series, the cluster-wise parameter may overrule this global parameter (see Thermal window description below). +Either « ready-made » or «stochastic » (i.e. Antares-generated), defined by setting the value to either "on" or "off". Exception is hydro max power that can only be « ready-made ». Note that for Thermal time-series, the cluster-wise parameter may overrule this global parameter (see Thermal window description below). 2. **For stochastic TS only**: - **Number** Number of TS to generate diff --git a/src/libs/antares/study/fwd.h b/src/libs/antares/study/fwd.h index 85a08863a1..5f4e6c1d40 100644 --- a/src/libs/antares/study/fwd.h +++ b/src/libs/antares/study/fwd.h @@ -221,7 +221,7 @@ enum TimeSeries : unsigned int timeSeriesRenewable = 32, //! TimeSeries : Renewable timeSeriesTransmissionCapacities = 64, - //! TimeSeries : Hydro Power Credits + //! TimeSeries : Hydro Max Power timeSeriesHydroPowerCredits = 256, //! The maximum number of time-series that we can encounter diff --git a/src/libs/antares/study/parameters.cpp b/src/libs/antares/study/parameters.cpp index 7f5994db78..2753bffe1b 100644 --- a/src/libs/antares/study/parameters.cpp +++ b/src/libs/antares/study/parameters.cpp @@ -1146,13 +1146,13 @@ void Parameters::fixGenRefreshForHydroPowerCredits() if ((timeSeriesHydroPowerCredits & timeSeriesToGenerate) != 0) { timeSeriesToGenerate &= ~timeSeriesHydroPowerCredits; - logs.error() << "Time-series generation is not available for hydro power credits. It " + logs.error() << "Time-series generation is not available for hydro max power. It " "will be automatically disabled."; } if ((timeSeriesHydroPowerCredits & timeSeriesToRefresh) != 0) { timeSeriesToRefresh &= ~timeSeriesHydroPowerCredits; - logs.error() << "Time-series refresh is not available for hydro power credits. It will " + logs.error() << "Time-series refresh is not available for hydro max power. It will " "be automatically disabled."; } } diff --git a/src/libs/antares/study/parameters.h b/src/libs/antares/study/parameters.h index 5dd10917a0..8a41414f17 100644 --- a/src/libs/antares/study/parameters.h +++ b/src/libs/antares/study/parameters.h @@ -161,7 +161,7 @@ class Parameters final /*! ** \brief Try to detect then fix TS generation/refresh parameters - * for Hydro Power Credits + * for Hydro Max Power */ void fixGenRefreshForHydroPowerCredits(); diff --git a/src/libs/antares/study/parts/hydro/series.cpp b/src/libs/antares/study/parts/hydro/series.cpp index 219af54df2..9334d32e65 100644 --- a/src/libs/antares/study/parts/hydro/series.cpp +++ b/src/libs/antares/study/parts/hydro/series.cpp @@ -221,7 +221,7 @@ bool DataSeriesHydro::LoadHydroPowerCredits(Study& study, const AreaName& areaID { if (countpowercredits == 0) { - logs.error() << "Hydro Power Credits: `" << areaID + logs.error() << "Hydro Max Power: `" << areaID << "`: empty matrix detected. Fixing it with default values"; maxgen.reset(1, HOURS_PER_YEAR); @@ -233,7 +233,7 @@ bool DataSeriesHydro::LoadHydroPowerCredits(Study& study, const AreaName& areaID { if (maxpump.width != 1 && maxgen.width != 1) { - logs.fatal() << "Hydro Power Credits: `" << areaID + logs.fatal() << "Hydro Max Power: `" << areaID << "`: The matrices Maximum Generation and Maximum Pumping must " "have the same number of time-series."; study.gotFatalError = true; @@ -260,7 +260,7 @@ bool DataSeriesHydro::LoadHydroPowerCredits(Study& study, const AreaName& areaID { areaToInvalidate->invalidateJIT = true; logs.info() << " '" << areaID - << "': The hydro power credits data have been normalized to " + << "': The hydro max power data have been normalized to " << countpowercredits << " timeseries"; } else diff --git a/src/libs/antares/study/scenario-builder/HydroPowerCreditsTSNumberData.cpp b/src/libs/antares/study/scenario-builder/HydroPowerCreditsTSNumberData.cpp index 36d9a452f7..ecd71223d5 100644 --- a/src/libs/antares/study/scenario-builder/HydroPowerCreditsTSNumberData.cpp +++ b/src/libs/antares/study/scenario-builder/HydroPowerCreditsTSNumberData.cpp @@ -35,7 +35,7 @@ bool hydroPowerCreditsTSNumberData::apply(Study& study) assert(areaIndex < pTSNumberRules.width); const MatrixType::ColumnType& col = pTSNumberRules[areaIndex]; - logprefix.clear() << "Hydro Power Credits: Area '" << area.name << "': "; + logprefix.clear() << "Hydro Max Power: Area '" << area.name << "': "; ret = ApplyToMatrixPowerCredits(errors, logprefix, *area.hydro.series, col, tsGenCountHydroPowerCredits) && ret; } return ret; diff --git a/src/libs/antares/study/scenario-builder/HydroPowerCreditsTSNumberData.h b/src/libs/antares/study/scenario-builder/HydroPowerCreditsTSNumberData.h index ac30d2b036..d55dc80b7d 100644 --- a/src/libs/antares/study/scenario-builder/HydroPowerCreditsTSNumberData.h +++ b/src/libs/antares/study/scenario-builder/HydroPowerCreditsTSNumberData.h @@ -3,7 +3,7 @@ #include "TSnumberData.h" // ===================== -// Hydro Power Credits... +// Hydro Max Power... // ===================== namespace Antares::Data::ScenarioBuilder diff --git a/src/libs/antares/study/scenario-builder/rules.h b/src/libs/antares/study/scenario-builder/rules.h index 2e2565802b..ccbc6f13a8 100644 --- a/src/libs/antares/study/scenario-builder/rules.h +++ b/src/libs/antares/study/scenario-builder/rules.h @@ -116,7 +116,7 @@ class Rules final : private Yuni::NonCopyable solarTSNumberData solar; //! Hydro hydroTSNumberData hydro; - //! Hydro Power Credits + //! Hydro Max Power hydroPowerCreditsTSNumberData hydroPowerCredits; //! Wind windTSNumberData wind; diff --git a/src/solver/aleatoire/alea_tirage_au_sort_chroniques.cpp b/src/solver/aleatoire/alea_tirage_au_sort_chroniques.cpp index e003d4109c..46bd130822 100644 --- a/src/solver/aleatoire/alea_tirage_au_sort_chroniques.cpp +++ b/src/solver/aleatoire/alea_tirage_au_sort_chroniques.cpp @@ -59,7 +59,7 @@ void ApplyRandomTSnumbers(const Study& study, ptchro.Solar = (data.timeSeries.width != 1) ? (long)data.timeseriesNumbers[0][year] : 0; // zero-based } - // Hydro and Hydro Power Credits + // Hydro and Hydro Max Power { const Data::DataSeriesHydro& data = *area.hydro.series; assert(year < data.timeseriesNumbers.height); diff --git a/src/solver/simulation/timeseries-numbers.cpp b/src/solver/simulation/timeseries-numbers.cpp index a2e78889f4..cc7c616562 100644 --- a/src/solver/simulation/timeseries-numbers.cpp +++ b/src/solver/simulation/timeseries-numbers.cpp @@ -448,7 +448,7 @@ bool checkInterModalConsistencyForArea(Area& area, listNumberTsOverArea.push_back(nbTimeSeries); } - // Hydro Power Credits : Add hydro's power credits number of TS in area ... + // Hydro Max Power : Add hydro's max power number of TS in area ... indexTS = ts_to_tsIndex.at(timeSeriesHydroPowerCredits); if (isTSintermodal[indexTS]) { @@ -566,7 +566,7 @@ void storeTSnumbersForIntraModal(const array& intramo area.hydro.series->timeseriesNumbers[0][year] = intramodal_draws[indexTS]; // ------------- - // Hydro Power Credits ... + // Hydro Max Power ... // ------------- assert(year < area.hydro.series->timeseriesNumbersPowerCredits.height); indexTS = ts_to_tsIndex.at(timeSeriesHydroPowerCredits); @@ -682,7 +682,7 @@ void drawAndStoreTSnumbersForNOTintraModal(const array& i } // ------------- - // Hydro Power Credits... + // Hydro Max Power... // ------------- indexTS = ts_to_tsIndex.at(timeSeriesHydroPowerCredits); @@ -895,7 +895,7 @@ static void fixTSNumbersWhenWidthIsOne(Study& study) // Hydro fixTSNumbersSingleAreaSingleMode( area.hydro.series->timeseriesNumbers, area.hydro.series->count, years); - // Hydro Power Credits + // Hydro Max Power fixTSNumbersSingleAreaSingleMode( area.hydro.series->timeseriesNumbersPowerCredits, area.hydro.series->countpowercredits, years); @@ -980,7 +980,7 @@ bool TimeSeriesNumbers::Generate(Study& study) (bool)(timeSeriesSolar & parameters.timeSeriesToRefresh), false, // TS generation is always disabled for renewables false, // TS generation is always disabled for links transmission capacities - false}; // TS generation is always disabled for hydro power credits + false}; // TS generation is always disabled for hydro max power if (not checkIntraModalConsistency(nbTimeseriesByMode, isTSintramodal, isTSgenerated, study)) return false; diff --git a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp index f5457ea6c5..660c035caa 100644 --- a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp +++ b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp @@ -87,7 +87,7 @@ struct Fixture area_2->hydro.series->count = nbReadyMadeTS; area_3->hydro.series->count = nbReadyMadeTS; - // Hydro Power Credits: set the nb of ready made TS + // Hydro Max Power: set the nb of ready made TS nbReadyMadeTS = 15; area_1->hydro.series->countpowercredits = nbReadyMadeTS; area_2->hydro.series->countpowercredits = nbReadyMadeTS; @@ -239,7 +239,7 @@ BOOST_FIXTURE_TEST_CASE(on_area2_and_on_year_15__solar_TS_number_3_is_chosen__re } // ================= -// Tests on Hydro Power Credits +// Tests on Hydro Max Power // ================= BOOST_FIXTURE_TEST_CASE(on_area3_and_on_year_10__hydro_power_credits_TS_number_6_is_chosen__reading_OK, Fixture) { diff --git a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp index 6cc7154ed8..717ae8bbf3 100644 --- a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp +++ b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp @@ -129,7 +129,7 @@ struct commonFixture area_2->hydro.series->count = nbReadyMadeTS; area_3->hydro.series->count = nbReadyMadeTS; - // Hydro Power Credits : set the nb of ready made TS + // Hydro Max Power : set the nb of ready made TS nbReadyMadeTS = 15; area_1->hydro.series->countpowercredits = nbReadyMadeTS; area_2->hydro.series->countpowercredits = nbReadyMadeTS; diff --git a/src/ui/action/handler/antares-study/area/create.cpp b/src/ui/action/handler/antares-study/area/create.cpp index 381f69dba2..a2c9d5c9fd 100644 --- a/src/ui/action/handler/antares-study/area/create.cpp +++ b/src/ui/action/handler/antares-study/area/create.cpp @@ -285,7 +285,7 @@ void Create::createActionsForAStandardAreaCopy(Context& ctx, bool copyPosition) *tsNode += prepro; *tsNode += new Action::AntaresStudy::Area::AllocationHydro(pOriginalAreaName); - //Hydro Power Credits + //Hydro Max Power *tsNode += new DataTimeseries(Data::timeSeriesHydroPowerCredits, pOriginalAreaName); // Thermal diff --git a/src/ui/simulator/application/main/build/scenario-builder.cpp b/src/ui/simulator/application/main/build/scenario-builder.cpp index 268c21d4f0..7cba11542e 100644 --- a/src/ui/simulator/application/main/build/scenario-builder.cpp +++ b/src/ui/simulator/application/main/build/scenario-builder.cpp @@ -176,7 +176,7 @@ class hydroScBuilderPageMaker final : public simpleScBuilderPageMaker } }; -// Hydro Power Credits ... +// Hydro Max Power ... class hydroPowerCreditsScBuilderPageMaker final : public simpleScBuilderPageMaker { using simpleScBuilderPageMaker::simpleScBuilderPageMaker; diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/column.cpp b/src/ui/simulator/toolbox/components/datagrid/renderer/column.cpp index 7c2565be7e..1651d92a18 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/column.cpp +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/column.cpp @@ -164,7 +164,7 @@ ColumnNTC::ColumnNTC() : Column(timeSeriesTransmissionCapacities, " Links NTC } // ------------------------------- -// Column Hydro Power Credits +// Column Hydro Max Power // ------------------------------- ColumnHydroPowerCredits::ColumnHydroPowerCredits() : Column(timeSeriesHydroPowerCredits, " Hydro-Power-Credits ") { diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/column.h b/src/ui/simulator/toolbox/components/datagrid/renderer/column.h index 1401862d1d..575b63763f 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/column.h +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/column.h @@ -99,7 +99,7 @@ class ColumnNTC final : public Column }; // ------------------------------- -// Column for Hydro Power Credits +// Column for Hydro Max Power // ------------------------------- class ColumnHydroPowerCredits final : public Column { From c63db7578feb1df9b658c80827f5471d67abfdae Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Fri, 22 Sep 2023 14:28:30 +0200 Subject: [PATCH 02/40] Changing name convention --- docs/reference-guide/13-file-format.md | 2 +- src/libs/antares/study/area/area.cpp | 4 +- src/libs/antares/study/area/list.cpp | 2 +- .../study/area/store-timeseries-numbers.cpp | 14 +++--- .../study/area/store-timeseries-numbers.h | 2 +- .../study/area/store-timeseries-numbers.hxx | 4 +- src/libs/antares/study/fwd.h | 2 +- src/libs/antares/study/parameters.cpp | 22 ++++----- src/libs/antares/study/parameters.h | 2 +- src/libs/antares/study/parts/hydro/series.cpp | 4 +- src/libs/antares/study/parts/hydro/series.h | 4 +- .../HydroPowerCreditsTSNumberData.cpp | 8 ++-- .../HydroPowerCreditsTSNumberData.h | 6 +-- .../study/scenario-builder/applyToMatrix.hxx | 12 ++--- .../antares/study/scenario-builder/rules.cpp | 14 +++--- .../antares/study/scenario-builder/rules.h | 4 +- .../alea_tirage_au_sort_chroniques.cpp | 6 +-- src/solver/hydro/management/daily.cpp | 6 +-- src/solver/hydro/management/management.cpp | 10 ++-- src/solver/hydro/management/management.h | 4 +- .../simulation/sim_calcul_economique.cpp | 12 ++--- src/solver/simulation/sim_structure_donnees.h | 2 +- src/solver/simulation/timeseries-numbers.cpp | 46 +++++++++---------- src/solver/variable/economy/max-mrg.cpp | 2 +- .../study/parts/hydro/test-hydro-series.cpp | 8 ++-- .../test-sc-builder-file-read-line.cpp | 4 +- .../test-sc-builder-file-save.cpp | 8 ++-- .../handler/antares-study/area/create.cpp | 2 +- .../handler/antares-study/area/timeseries.cpp | 10 ++-- .../main/build/scenario-builder.cpp | 10 ++-- src/ui/simulator/application/main/main.h | 2 +- .../components/datagrid/renderer/column.cpp | 2 +- .../components/datagrid/renderer/column.h | 6 +-- .../scenario-builder-hydro-renderer.cpp | 16 +++---- .../scenario-builder-hydro-renderer.h | 6 +-- .../datagrid/renderer/ts-management.cpp | 2 +- 36 files changed, 135 insertions(+), 135 deletions(-) diff --git a/docs/reference-guide/13-file-format.md b/docs/reference-guide/13-file-format.md index 5be64dcd62..769b5b69b1 100644 --- a/docs/reference-guide/13-file-format.md +++ b/docs/reference-guide/13-file-format.md @@ -5,7 +5,7 @@ For each area, new files are added **input/hydro/series/<area>/maxgen.txt* Also for each area, new files are added **input/hydro/common/capacity/maxhoursGen_<area>** and **input/hydro/common/capacity/maxhoursPump_<area>**. These files have just one column and 365 rows. For old studies, file **input/hydro/common/capacity/maxpower_<area>** will be deleted after upgrading the study and corresponding data from that file will be copied to already mentioned new files, even if study is upgraded or not. ### Input -Under `Configure/MC Scenario Builder` new section added `Hydro-Power-Credits` +Under `Configure/MC Scenario Builder` new section added `Hydro Max Power` In the existing file **settings/scenariobuilder.dat**, under **<ruleset>** section following properties added: * **hgp,<area>,<year> = <hgp-value>** ## v8.7.0 diff --git a/src/libs/antares/study/area/area.cpp b/src/libs/antares/study/area/area.cpp index 9cc17127aa..fa96644f71 100644 --- a/src/libs/antares/study/area/area.cpp +++ b/src/libs/antares/study/area/area.cpp @@ -280,7 +280,7 @@ void Area::resizeAllTimeseriesNumbers(uint n) solar.series->timeseriesNumbers.clear(); wind.series->timeseriesNumbers.clear(); hydro.series->timeseriesNumbers.clear(); - hydro.series->timeseriesNumbersPowerCredits.clear(); + hydro.series->timeseriesNumbersHydroMaxPower.clear(); for (auto& namedLink : links) { AreaLink* link = namedLink.second; @@ -293,7 +293,7 @@ void Area::resizeAllTimeseriesNumbers(uint n) solar.series->timeseriesNumbers.resize(1, n); wind.series->timeseriesNumbers.resize(1, n); hydro.series->timeseriesNumbers.resize(1, n); - hydro.series->timeseriesNumbersPowerCredits.resize(1, n); + hydro.series->timeseriesNumbersHydroMaxPower.resize(1, n); for (auto& namedLink : links) { AreaLink* link = namedLink.second; diff --git a/src/libs/antares/study/area/list.cpp b/src/libs/antares/study/area/list.cpp index 378d1895ae..7ed6fd260a 100644 --- a/src/libs/antares/study/area/list.cpp +++ b/src/libs/antares/study/area/list.cpp @@ -919,7 +919,7 @@ static bool AreaListLoadFromFolderSingleArea(Study& study, if (area.hydro.series) { buffer.clear() << study.folderInput << SEP << "hydro" << SEP << "series"; - ret = area.hydro.series->LoadHydroPowerCredits(study, area.id, buffer) && ret; + ret = area.hydro.series->LoadMaxPower(study, area.id, buffer) && ret; } buffer.clear() << study.folderInput << SEP << "hydro" << SEP << "common" << SEP diff --git a/src/libs/antares/study/area/store-timeseries-numbers.cpp b/src/libs/antares/study/area/store-timeseries-numbers.cpp index 83cd1d3f9a..b453fb4fc2 100644 --- a/src/libs/antares/study/area/store-timeseries-numbers.cpp +++ b/src/libs/antares/study/area/store-timeseries-numbers.cpp @@ -48,7 +48,7 @@ struct TSNumbersPredicate }; } // anonymous namespace -static void genericStoreTimeseriesNumbers(Solver::IResultWriter::Ptr writer, +static void storeTSnumbers(Solver::IResultWriter::Ptr writer, const Matrix& timeseriesNumbers, const String& id, const String& directory) @@ -69,28 +69,28 @@ static void genericStoreTimeseriesNumbers(Solver::IResultWriter::Ptr writer, void storeTimeseriesNumbersForLoad(Solver::IResultWriter::Ptr writer, const Area& area) { - genericStoreTimeseriesNumbers(writer, area.load.series->timeseriesNumbers, area.id, "load"); + storeTSnumbers(writer, area.load.series->timeseriesNumbers, area.id, "load"); } void storeTimeseriesNumbersForSolar(Solver::IResultWriter::Ptr writer, const Area& area) { - genericStoreTimeseriesNumbers(writer, area.solar.series->timeseriesNumbers, area.id, "solar"); + storeTSnumbers(writer, area.solar.series->timeseriesNumbers, area.id, "solar"); } void storeTimeseriesNumbersForHydro(Solver::IResultWriter::Ptr writer, const Area& area) { - genericStoreTimeseriesNumbers(writer, area.hydro.series->timeseriesNumbers, area.id, "hydro"); + storeTSnumbers(writer, area.hydro.series->timeseriesNumbers, area.id, "hydro"); } -void storeTimeseriesNumbersForHydroPowerCredits(Solver::IResultWriter::Ptr writer, const Area& area) +void storeTimeseriesNumbersForHydroMaxPower(Solver::IResultWriter::Ptr writer, const Area& area) { - genericStoreTimeseriesNumbers(writer, area.hydro.series->timeseriesNumbersPowerCredits, area.id, "power-credits"); + storeTSnumbers(writer, area.hydro.series->timeseriesNumbersHydroMaxPower, area.id, "max-power"); } void storeTimeseriesNumbersForWind(Solver::IResultWriter::Ptr writer, const Area& area) { - genericStoreTimeseriesNumbers(writer, area.wind.series->timeseriesNumbers, area.id, "wind"); + storeTSnumbers(writer, area.wind.series->timeseriesNumbers, area.id, "wind"); } void storeTimeseriesNumbersForThermal(Solver::IResultWriter::Ptr writer, const Area& area) diff --git a/src/libs/antares/study/area/store-timeseries-numbers.h b/src/libs/antares/study/area/store-timeseries-numbers.h index baca1094c9..c5a0d2cb7e 100644 --- a/src/libs/antares/study/area/store-timeseries-numbers.h +++ b/src/libs/antares/study/area/store-timeseries-numbers.h @@ -46,7 +46,7 @@ namespace Antares::Data void storeTimeseriesNumbersForThermal(Solver::IResultWriter::Ptr writer, const Area& area); void storeTimeseriesNumbersForRenewable(Solver::IResultWriter::Ptr writer, const Area& area); void storeTimeseriesNumbersForTransmissionCapacities(Solver::IResultWriter::Ptr writer, const Area& area); - void storeTimeseriesNumbersForHydroPowerCredits(Solver::IResultWriter::Ptr writer, const Area& area); + void storeTimeseriesNumbersForHydroMaxPower(Solver::IResultWriter::Ptr writer, const Area& area); } //Antares::Data diff --git a/src/libs/antares/study/area/store-timeseries-numbers.hxx b/src/libs/antares/study/area/store-timeseries-numbers.hxx index 5bb4454a1f..ea183242f9 100644 --- a/src/libs/antares/study/area/store-timeseries-numbers.hxx +++ b/src/libs/antares/study/area/store-timeseries-numbers.hxx @@ -62,8 +62,8 @@ void singleAreaStoreTimeseriesNumbers(Solver::IResultWriter::Ptr writer, const A case timeSeriesTransmissionCapacities: storeTimeseriesNumbersForTransmissionCapacities(writer, area); break; - case timeSeriesHydroPowerCredits: - storeTimeseriesNumbersForHydroPowerCredits(writer, area); + case timeSeriesHydroMaxPower: + storeTimeseriesNumbersForHydroMaxPower(writer, area); break; case timeSeriesCount: default: diff --git a/src/libs/antares/study/fwd.h b/src/libs/antares/study/fwd.h index 5f4e6c1d40..9afca30e8a 100644 --- a/src/libs/antares/study/fwd.h +++ b/src/libs/antares/study/fwd.h @@ -222,7 +222,7 @@ enum TimeSeries : unsigned int //! TimeSeries : Renewable timeSeriesTransmissionCapacities = 64, //! TimeSeries : Hydro Max Power - timeSeriesHydroPowerCredits = 256, + timeSeriesHydroMaxPower = 256, //! The maximum number of time-series that we can encounter timeSeriesCount = 8, diff --git a/src/libs/antares/study/parameters.cpp b/src/libs/antares/study/parameters.cpp index 2753bffe1b..c255129b3a 100644 --- a/src/libs/antares/study/parameters.cpp +++ b/src/libs/antares/study/parameters.cpp @@ -74,8 +74,8 @@ static bool ConvertCStrToListTimeSeries(const String& value, uint& v) v |= timeSeriesRenewable; else if (word == "ntc") v |= timeSeriesTransmissionCapacities; - else if (word == "power-credits") - v |= timeSeriesHydroPowerCredits; + else if (word == "max-power") + v |= timeSeriesHydroMaxPower; return true; }); return true; @@ -394,11 +394,11 @@ static void ParametersSaveTimeSeries(IniFile::Section* s, const char* name, uint v += ", "; v += "ntc"; } - if (value & timeSeriesHydroPowerCredits) + if (value & timeSeriesHydroMaxPower) { if (!v.empty()) v += ", "; - v += "power-credits"; + v += "max-power"; } s->add(name, v); } @@ -1081,7 +1081,7 @@ bool Parameters::loadFromINI(const IniFile& ini, uint version, const StudyLoadOp fixGenRefreshForNTC(); - fixGenRefreshForHydroPowerCredits(); + fixGenRefreshForHydroMaxPower(); // Specific action before launching a simulation if (options.usedByTheSolver) @@ -1141,17 +1141,17 @@ void Parameters::fixGenRefreshForNTC() } } -void Parameters::fixGenRefreshForHydroPowerCredits() +void Parameters::fixGenRefreshForHydroMaxPower() { - if ((timeSeriesHydroPowerCredits & timeSeriesToGenerate) != 0) + if ((timeSeriesHydroMaxPower & timeSeriesToGenerate) != 0) { - timeSeriesToGenerate &= ~timeSeriesHydroPowerCredits; + timeSeriesToGenerate &= ~timeSeriesHydroMaxPower; logs.error() << "Time-series generation is not available for hydro max power. It " "will be automatically disabled."; } - if ((timeSeriesHydroPowerCredits & timeSeriesToRefresh) != 0) + if ((timeSeriesHydroMaxPower & timeSeriesToRefresh) != 0) { - timeSeriesToRefresh &= ~timeSeriesHydroPowerCredits; + timeSeriesToRefresh &= ~timeSeriesHydroMaxPower; logs.error() << "Time-series refresh is not available for hydro max power. It will " "be automatically disabled."; } @@ -1401,7 +1401,7 @@ void Parameters::prepareForSimulation(const StudyLoadOptions& options) if (interModal == timeSeriesLoad || interModal == timeSeriesSolar || interModal == timeSeriesWind || interModal == timeSeriesHydro - || interModal == timeSeriesThermal || interModal == timeSeriesRenewable || interModal == timeSeriesHydroPowerCredits) + || interModal == timeSeriesThermal || interModal == timeSeriesRenewable || interModal == timeSeriesHydroMaxPower) { // Only one timeseries in interModal correlation, which is the same than nothing interModal = 0; diff --git a/src/libs/antares/study/parameters.h b/src/libs/antares/study/parameters.h index 8a41414f17..0042f224a0 100644 --- a/src/libs/antares/study/parameters.h +++ b/src/libs/antares/study/parameters.h @@ -163,7 +163,7 @@ class Parameters final ** \brief Try to detect then fix TS generation/refresh parameters * for Hydro Max Power */ - void fixGenRefreshForHydroPowerCredits(); + void fixGenRefreshForHydroMaxPower(); /*! ** \brief Get the amount of memory used by the general data diff --git a/src/libs/antares/study/parts/hydro/series.cpp b/src/libs/antares/study/parts/hydro/series.cpp index 9334d32e65..c58d88258c 100644 --- a/src/libs/antares/study/parts/hydro/series.cpp +++ b/src/libs/antares/study/parts/hydro/series.cpp @@ -199,7 +199,7 @@ void DataSeriesHydro::checkMinGenTsNumber(Study& study, const AreaName& areaID) } } -bool DataSeriesHydro::LoadHydroPowerCredits(Study& study, const AreaName& areaID, const AnyString& folder) +bool DataSeriesHydro::LoadMaxPower(Study& study, const AreaName& areaID, const AnyString& folder) { bool ret = true; auto& buffer = study.bufferLoadingTS; @@ -288,7 +288,7 @@ bool DataSeriesHydro::LoadHydroPowerCredits(Study& study, const AreaName& areaID } } - timeseriesNumbersPowerCredits.clear(); + timeseriesNumbersHydroMaxPower.clear(); return ret; } diff --git a/src/libs/antares/study/parts/hydro/series.h b/src/libs/antares/study/parts/hydro/series.h index 499ad64c82..7eed031371 100644 --- a/src/libs/antares/study/parts/hydro/series.h +++ b/src/libs/antares/study/parts/hydro/series.h @@ -167,8 +167,8 @@ class DataSeriesHydro ** \brief Monte-Carlo */ Matrix timeseriesNumbers; - Matrix timeseriesNumbersPowerCredits; - bool LoadHydroPowerCredits(Study& study, const AreaName& areaID, const AnyString& folder); + Matrix timeseriesNumbersHydroMaxPower; + bool LoadMaxPower(Study& study, const AreaName& areaID, const AnyString& folder); }; // class DataSeriesHydro diff --git a/src/libs/antares/study/scenario-builder/HydroPowerCreditsTSNumberData.cpp b/src/libs/antares/study/scenario-builder/HydroPowerCreditsTSNumberData.cpp index ecd71223d5..028be97bf9 100644 --- a/src/libs/antares/study/scenario-builder/HydroPowerCreditsTSNumberData.cpp +++ b/src/libs/antares/study/scenario-builder/HydroPowerCreditsTSNumberData.cpp @@ -9,13 +9,13 @@ namespace Antares::Data::ScenarioBuilder { -uint hydroPowerCreditsTSNumberData::get_tsGenCount(const Study& study) const +uint hydroMaxPowerTSNumberData::get_tsGenCount(const Study& study) const { //This function must be overriden because it is inherited from abstract class return 0; } -bool hydroPowerCreditsTSNumberData::apply(Study& study) +bool hydroMaxPowerTSNumberData::apply(Study& study) { bool ret = true; CString<512, false> logprefix; @@ -25,7 +25,7 @@ bool hydroPowerCreditsTSNumberData::apply(Study& study) // The total number of areas; const uint areaCount = study.areas.size(); - const uint tsGenCountHydroPowerCredits = get_tsGenCount(study); + const uint tsGenCountHydroMaxPower = get_tsGenCount(study); for (uint areaIndex = 0; areaIndex != areaCount; ++areaIndex) { @@ -36,7 +36,7 @@ bool hydroPowerCreditsTSNumberData::apply(Study& study) const MatrixType::ColumnType& col = pTSNumberRules[areaIndex]; logprefix.clear() << "Hydro Max Power: Area '" << area.name << "': "; - ret = ApplyToMatrixPowerCredits(errors, logprefix, *area.hydro.series, col, tsGenCountHydroPowerCredits) && ret; + ret = ApplyToMatrixMaxPower(errors, logprefix, *area.hydro.series, col, tsGenCountHydroMaxPower) && ret; } return ret; } diff --git a/src/libs/antares/study/scenario-builder/HydroPowerCreditsTSNumberData.h b/src/libs/antares/study/scenario-builder/HydroPowerCreditsTSNumberData.h index d55dc80b7d..0cdc741693 100644 --- a/src/libs/antares/study/scenario-builder/HydroPowerCreditsTSNumberData.h +++ b/src/libs/antares/study/scenario-builder/HydroPowerCreditsTSNumberData.h @@ -8,17 +8,17 @@ namespace Antares::Data::ScenarioBuilder { -class hydroPowerCreditsTSNumberData : public TSNumberData +class hydroMaxPowerTSNumberData : public TSNumberData { public: bool apply(Study& study) override; CString<512, false> get_prefix() const override; uint get_tsGenCount(const Study& study) const override; - virtual ~hydroPowerCreditsTSNumberData() = default; + virtual ~hydroMaxPowerTSNumberData() = default; }; -inline CString<512, false> hydroPowerCreditsTSNumberData::get_prefix() const +inline CString<512, false> hydroMaxPowerTSNumberData::get_prefix() const { return "hgp,"; } diff --git a/src/libs/antares/study/scenario-builder/applyToMatrix.hxx b/src/libs/antares/study/scenario-builder/applyToMatrix.hxx index e4fa56a602..4e5496b477 100644 --- a/src/libs/antares/study/scenario-builder/applyToMatrix.hxx +++ b/src/libs/antares/study/scenario-builder/applyToMatrix.hxx @@ -46,7 +46,7 @@ inline bool CheckValidity(uint value, const BindingConst } template -static inline bool CheckValidityHydroPowerCredits(uint value, const D& data, uint tsGenMax) +static inline bool CheckValidityHydroMaxPower(uint value, const D& data, uint tsGenMax) { // TS Generator never used return (!tsGenMax) ? (value < data.countpowercredits) : (value < tsGenMax); @@ -98,7 +98,7 @@ bool ApplyToMatrix(uint& errors, } template -bool ApplyToMatrixPowerCredits(uint& errors, +bool ApplyToMatrixMaxPower(uint& errors, StringT& logprefix, D& data, const TSNumberData::MatrixType::ColumnType& years, uint tsGenMax) @@ -106,10 +106,10 @@ bool ApplyToMatrixPowerCredits(uint& errors, bool ret = true; // In this case, m.height represents the total number of years - const uint nbYears = data.timeseriesNumbersPowerCredits.height; + const uint nbYears = data.timeseriesNumbersHydroMaxPower.height; // The matrix m has only one column - assert(data.timeseriesNumbersPowerCredits.width == 1); - typename Matrix::ColumnType& target = data.timeseriesNumbersPowerCredits[0]; + assert(data.timeseriesNumbersHydroMaxPower.width == 1); + typename Matrix::ColumnType& target = data.timeseriesNumbersHydroMaxPower[0]; for (uint y = 0; y != nbYears; ++y) { @@ -119,7 +119,7 @@ bool ApplyToMatrixPowerCredits(uint& errors, uint tsNum = years[y] - 1; // When the TS-Generators are not used - if (!CheckValidityHydroPowerCredits(tsNum, data, tsGenMax)) + if (!CheckValidityHydroMaxPower(tsNum, data, tsGenMax)) { if (errors <= maxErrors) { diff --git a/src/libs/antares/study/scenario-builder/rules.cpp b/src/libs/antares/study/scenario-builder/rules.cpp index 38a4b4fe95..191e92016b 100644 --- a/src/libs/antares/study/scenario-builder/rules.cpp +++ b/src/libs/antares/study/scenario-builder/rules.cpp @@ -55,8 +55,8 @@ void Rules::saveToINIFile(Yuni::IO::File::Stream& file) const solar.saveToINIFile(study_, file); // hydro hydro.saveToINIFile(study_, file); - // hydroPowerCredits - hydroPowerCredits.saveToINIFile(study_, file); + // hydroMaxPower + hydroMaxPower.saveToINIFile(study_, file); // wind wind.saveToINIFile(study_, file); // Thermal clusters, renewable clusters, links NTS : each area @@ -81,7 +81,7 @@ bool Rules::reset() load.reset(study_); solar.reset(study_); hydro.reset(study_); - hydroPowerCredits.reset(study_); + hydroMaxPower.reset(study_); wind.reset(study_); // Thermal @@ -246,7 +246,7 @@ bool Rules::readHydro(const AreaName::Vector& splitKey, String value, bool updat return true; } -bool Rules::readHydroPowerCredits(const AreaName::Vector& splitKey, String value, bool updaterMode) +bool Rules::readHydroMaxPower(const AreaName::Vector& splitKey, String value, bool updaterMode) { const uint year = splitKey[2].to(); const AreaName& areaname = splitKey[1]; @@ -256,7 +256,7 @@ bool Rules::readHydroPowerCredits(const AreaName::Vector& splitKey, String value return false; uint val = fromStringToTSnumber(value); - hydroPowerCredits.setTSnumber(area->index, year, val); + hydroMaxPower.setTSnumber(area->index, year, val); return true; } @@ -369,7 +369,7 @@ bool Rules::readLine(const AreaName::Vector& splitKey, String value, bool update else if (kind_of_scenario == "h") return readHydro(splitKey, value, updaterMode); else if (kind_of_scenario == "hgp") - return readHydroPowerCredits(splitKey, value, updaterMode); + return readHydroMaxPower(splitKey, value, updaterMode); else if (kind_of_scenario == "s") return readSolar(splitKey, value, updaterMode); else if (kind_of_scenario == "hl") @@ -389,7 +389,7 @@ bool Rules::apply() returned_status = load.apply(study_) && returned_status; returned_status = solar.apply(study_) && returned_status; returned_status = hydro.apply(study_) && returned_status; - returned_status = hydroPowerCredits.apply(study_) && returned_status; + returned_status = hydroMaxPower.apply(study_) && returned_status; returned_status = wind.apply(study_) && returned_status; for (uint i = 0; i != pAreaCount; ++i) { diff --git a/src/libs/antares/study/scenario-builder/rules.h b/src/libs/antares/study/scenario-builder/rules.h index ccbc6f13a8..9e81ddf590 100644 --- a/src/libs/antares/study/scenario-builder/rules.h +++ b/src/libs/antares/study/scenario-builder/rules.h @@ -117,7 +117,7 @@ class Rules final : private Yuni::NonCopyable //! Hydro hydroTSNumberData hydro; //! Hydro Max Power - hydroPowerCreditsTSNumberData hydroPowerCredits; + hydroMaxPowerTSNumberData hydroMaxPower; //! Wind windTSNumberData wind; @@ -141,7 +141,7 @@ class Rules final : private Yuni::NonCopyable bool readLoad(const AreaName::Vector& instrs, String value, bool updaterMode); bool readWind(const AreaName::Vector& instrs, String value, bool updaterMode); bool readHydro(const AreaName::Vector& instrs, String value, bool updaterMode); - bool readHydroPowerCredits(const AreaName::Vector& splitKey, String value, bool updaterMode); + bool readHydroMaxPower(const AreaName::Vector& splitKey, String value, bool updaterMode); bool readSolar(const AreaName::Vector& instrs, String value, bool updaterMode); bool readHydroLevels(const AreaName::Vector& instrs, String value, bool updaterMode); bool readLink(const AreaName::Vector& instrs, String value, bool updaterMode); diff --git a/src/solver/aleatoire/alea_tirage_au_sort_chroniques.cpp b/src/solver/aleatoire/alea_tirage_au_sort_chroniques.cpp index 46bd130822..44873a5e1d 100644 --- a/src/solver/aleatoire/alea_tirage_au_sort_chroniques.cpp +++ b/src/solver/aleatoire/alea_tirage_au_sort_chroniques.cpp @@ -63,12 +63,12 @@ void ApplyRandomTSnumbers(const Study& study, { const Data::DataSeriesHydro& data = *area.hydro.series; assert(year < data.timeseriesNumbers.height); - assert(year < data.timeseriesNumbersPowerCredits.height); + assert(year < data.timeseriesNumbersHydroMaxPower.height); ptchro.Hydraulique = (data.count != 1) ? (long)data.timeseriesNumbers[0][year] : 0; // zero-based - ptchro.HydrauliquePowerCredits + ptchro.HydrauliqueMaxPower = (data.countpowercredits != 1) - ? static_cast(data.timeseriesNumbersPowerCredits[0][year]) + ? static_cast(data.timeseriesNumbersHydroMaxPower[0][year]) : 0; } // Wind diff --git a/src/solver/hydro/management/daily.cpp b/src/solver/hydro/management/daily.cpp index 3c7bae0cd0..aea7af45fc 100644 --- a/src/solver/hydro/management/daily.cpp +++ b/src/solver/hydro/management/daily.cpp @@ -253,10 +253,10 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St auto const& maxPowerHours = area.hydro.maxHoursGen; auto const& maxPower = area.hydro.series->maxgen; - uint tsIndexPowerCredits - = (NumeroChroniquesTireesParPays[numSpace][z]).HydrauliquePowerCredits; + uint tsIndexMaxPower + = (NumeroChroniquesTireesParPays[numSpace][z]).HydrauliqueMaxPower; - auto const& maxP = maxPower[tsIndexPowerCredits < maxPower.width ? tsIndexPowerCredits : 0]; + auto const& maxP = maxPower[tsIndexMaxPower < maxPower.width ? tsIndexMaxPower : 0]; auto const& maxE = maxPowerHours[0]; auto& ventilationResults = ventilationResults_[numSpace][z]; diff --git a/src/solver/hydro/management/management.cpp b/src/solver/hydro/management/management.cpp index cfe510b239..157fbe888b 100644 --- a/src/solver/hydro/management/management.cpp +++ b/src/solver/hydro/management/management.cpp @@ -307,7 +307,7 @@ bool HydroManagement::checkWeeklyMinGeneration(uint tsIndex, Data::Area& area) c } bool HydroManagement::checkHourlyMinMaxGeneration(uint tsIndex, - uint tsIndexPowerCredits, + uint tsIndexMaxPower, Data::Area& area) const { // Hourly minimum generation <= hourly inflows for each hour @@ -315,7 +315,7 @@ bool HydroManagement::checkHourlyMinMaxGeneration(uint tsIndex, auto const& srcmingen = mingenmatrix[tsIndex < mingenmatrix.width ? tsIndex : 0]; auto& maxgenmatrix = area.hydro.series->maxgen; auto const& srcmaxgen - = maxgenmatrix[tsIndexPowerCredits < maxgenmatrix.width ? tsIndexPowerCredits : 0]; + = maxgenmatrix[tsIndexMaxPower < maxgenmatrix.width ? tsIndexMaxPower : 0]; for (uint h = 0; h < HOURS_PER_YEAR; ++h) { @@ -327,7 +327,7 @@ bool HydroManagement::checkHourlyMinMaxGeneration(uint tsIndex, logs.error() << "In area: " << area.name << " [hourly] minimum generation of " << min << " MW in timestep " << h + 1 << " of TS-" << tsIndex + 1 << " is incompatible with the maximum generation of " << max - << " MW in timestep " << h + 1 << " of TS-" << tsIndexPowerCredits + 1 + << " MW in timestep " << h + 1 << " of TS-" << tsIndexMaxPower + 1 << " MW."; return false; } @@ -344,14 +344,14 @@ bool HydroManagement::checkMinGeneration(uint numSpace) uint z = area.index; const auto& ptchro = NumeroChroniquesTireesParPays[numSpace][z]; auto tsIndex = (uint)ptchro.Hydraulique; - auto tsIndexPowerCredits = ptchro.HydrauliquePowerCredits; + auto tsIndexMaxPower = ptchro.HydrauliqueMaxPower; bool useHeuristicTarget = area.hydro.useHeuristicTarget; bool followLoadModulations = area.hydro.followLoadModulations; bool reservoirManagement = area.hydro.reservoirManagement; if (!reservoirManagement) - ret = checkHourlyMinMaxGeneration(tsIndex, tsIndexPowerCredits, area) && ret; + ret = checkHourlyMinMaxGeneration(tsIndex, tsIndexMaxPower, area) && ret; if (!useHeuristicTarget) return; diff --git a/src/solver/hydro/management/management.h b/src/solver/hydro/management/management.h index 7f44b35570..6ba7a28dec 100644 --- a/src/solver/hydro/management/management.h +++ b/src/solver/hydro/management/management.h @@ -88,7 +88,7 @@ struct TmpDataByArea typedef struct { std::vector HydrauliqueModulableQuotidien; /* indice par jour */ - std::vector NiveauxReservoirsDebutJours; //Niveaux (quotidiens) du reservoir de début + std::vector NiveauxReservoirsDebutJours; //Niveaux (quotidiens) du reservoir de d�but //de jour (en cas de gestion des reservoirs). std::vector NiveauxReservoirsFinJours; //Niveaux (quotidiens) du reservoir de fin //de jour (en cas de gestion des reservoirs). @@ -131,7 +131,7 @@ class HydroManagement final //! check Weekly minimum generation is lower than available inflows bool checkWeeklyMinGeneration(uint tsIndex, Data::Area& area) const; //! check Hourly minimum generation is lower than available inflows - bool checkHourlyMinMaxGeneration(uint tsIndex, uint tsIndexPowerCredits, Data::Area& area) const; + bool checkHourlyMinMaxGeneration(uint tsIndex, uint tsIndexMaxPower, Data::Area& area) const; //! check minimum generation is lower than available inflows bool checkMinGeneration(uint numSpace); //! Prepare the net demand for each area diff --git a/src/solver/simulation/sim_calcul_economique.cpp b/src/solver/simulation/sim_calcul_economique.cpp index bc81cbcf53..406d2049c3 100644 --- a/src/solver/simulation/sim_calcul_economique.cpp +++ b/src/solver/simulation/sim_calcul_economique.cpp @@ -564,19 +564,19 @@ void SIM_RenseignementProblemeHebdo(const Study& study, for (uint k = 0; k < nbPays; ++k) { auto& tsIndex = NumeroChroniquesTireesParPays[numSpace][k]; - uint tsIndexPowerCredits = tsIndex.HydrauliquePowerCredits; + uint tsIndexMaxPower = tsIndex.HydrauliqueMaxPower; auto& area = *(study.areas.byIndex[k]); auto& scratchpad = area.scratchpad[numSpace]; auto& ror = area.hydro.series->ror; auto& maxgenmatrix = area.hydro.series->maxgen; auto const& srcmaxgen - = maxgenmatrix[tsIndexPowerCredits < maxgenmatrix.width ? tsIndexPowerCredits : 0]; + = maxgenmatrix[tsIndexMaxPower < maxgenmatrix.width ? tsIndexMaxPower : 0]; auto const& ContrainteDePmaxHydrauliqueHoraire = srcmaxgen[PasDeTempsDebut + hourInWeek]; auto& maxpumpmatrix = area.hydro.series->maxpump; auto const& srcmaxpump - = maxpumpmatrix[tsIndexPowerCredits < maxpumpmatrix.width ? tsIndexPowerCredits + = maxpumpmatrix[tsIndexMaxPower < maxpumpmatrix.width ? tsIndexMaxPower : 0]; auto const& ContrainteDePmaxPompageHoraire = srcmaxpump[PasDeTempsDebut + hourInWeek]; @@ -652,11 +652,11 @@ void SIM_RenseignementProblemeHebdo(const Study& study, uint tsIndex = (NumeroChroniquesTireesParPays[numSpace][k]).Hydraulique; auto& inflowsmatrix = area.hydro.series->storage; auto const& srcinflows = inflowsmatrix[tsIndex < inflowsmatrix.width ? tsIndex : 0]; - uint tsIndexPowerCredits = (NumeroChroniquesTireesParPays[numSpace][k]).HydrauliquePowerCredits; + uint tsIndexMaxPower = (NumeroChroniquesTireesParPays[numSpace][k]).HydrauliqueMaxPower; auto& maxgenmatrix = area.hydro.series->maxgen; - auto const& srcmaxgen = maxgenmatrix[tsIndexPowerCredits < maxgenmatrix.width ? tsIndexPowerCredits : 0]; + auto const& srcmaxgen = maxgenmatrix[tsIndexMaxPower < maxgenmatrix.width ? tsIndexMaxPower : 0]; auto& maxpumpmatrix = area.hydro.series->maxpump; - auto const& srcmaxpump = maxpumpmatrix[tsIndexPowerCredits < maxpumpmatrix.width ? tsIndexPowerCredits : 0]; + auto const& srcmaxpump = maxpumpmatrix[tsIndexMaxPower < maxpumpmatrix.width ? tsIndexMaxPower : 0]; auto& mingenmatrix = area.hydro.series->mingen; auto const& srcmingen = mingenmatrix[tsIndex < mingenmatrix.width ? tsIndex : 0]; for (uint j = 0; j < problem.NombreDePasDeTemps; ++j) diff --git a/src/solver/simulation/sim_structure_donnees.h b/src/solver/simulation/sim_structure_donnees.h index a45fcffdf1..4017f352f1 100644 --- a/src/solver/simulation/sim_structure_donnees.h +++ b/src/solver/simulation/sim_structure_donnees.h @@ -34,7 +34,7 @@ typedef struct std::vector ThermiqueParPalier; std::vector RenouvelableParPalier; int Hydraulique; - unsigned int HydrauliquePowerCredits; + unsigned int HydrauliqueMaxPower; int Eolien; int Consommation; int Solar; diff --git a/src/solver/simulation/timeseries-numbers.cpp b/src/solver/simulation/timeseries-numbers.cpp index cc7c616562..5cc204e99a 100644 --- a/src/solver/simulation/timeseries-numbers.cpp +++ b/src/solver/simulation/timeseries-numbers.cpp @@ -50,7 +50,7 @@ const map ts_to_tsIndex = {{timeSeriesLoad, 0}, {timeSeriesSolar, 4}, {timeSeriesRenewable, 5}, {timeSeriesTransmissionCapacities, 6}, - {timeSeriesHydroPowerCredits, 7}}; + {timeSeriesHydroMaxPower, 7}}; const map ts_to_tsTitle = {{timeSeriesLoad, "load"}, @@ -60,7 +60,7 @@ const map ts_to_tsTitle {timeSeriesSolar, "solar"}, {timeSeriesRenewable, "renewable clusters"}, {timeSeriesTransmissionCapacities, "transmission capacities"}, - {timeSeriesHydroPowerCredits, "power-credits"}}; + {timeSeriesHydroMaxPower, "max-power"}}; void addInterModalTimeSeriesToMessage(const array& isTSintermodal, std::string& interModalTsMsg) @@ -95,7 +95,7 @@ static bool GenerateDeratedMode(Study& study) area.solar.series->timeseriesNumbers.zero(); area.wind.series->timeseriesNumbers.zero(); area.hydro.series->timeseriesNumbers.zero(); - area.hydro.series->timeseriesNumbersPowerCredits.zero(); + area.hydro.series->timeseriesNumbersHydroMaxPower.zero(); for (uint i = 0; i != area.thermal.clusterCount(); ++i) { @@ -160,10 +160,10 @@ class hydroAreaNumberOfTSretriever : public areaNumberOfTSretriever } }; -class hydroPowerCreditsAreaNumberOfTSretriever : public areaNumberOfTSretriever +class hydroMaxPowerAreaNumberOfTSretriever : public areaNumberOfTSretriever { public: - explicit hydroPowerCreditsAreaNumberOfTSretriever(Study& study) : areaNumberOfTSretriever(study) + explicit hydroMaxPowerAreaNumberOfTSretriever(Study& study) : areaNumberOfTSretriever(study) { } std::vector getAreaTimeSeriesNumber(const Area& area) override @@ -176,7 +176,7 @@ class hydroPowerCreditsAreaNumberOfTSretriever : public areaNumberOfTSretriever return 1; } - virtual ~hydroPowerCreditsAreaNumberOfTSretriever() = default; + virtual ~hydroMaxPowerAreaNumberOfTSretriever() = default; }; class windAreaNumberOfTSretriever : public areaNumberOfTSretriever @@ -378,8 +378,8 @@ bool checkIntraModalConsistency(array& nbTimeseriesByMode = make_shared(study); ts_to_numberOfTSretrievers[timeSeriesTransmissionCapacities] = make_shared(study); - ts_to_numberOfTSretrievers[timeSeriesHydroPowerCredits] - = make_shared(study); + ts_to_numberOfTSretrievers[timeSeriesHydroMaxPower] + = make_shared(study); // Loop over TS kind and check intra-modal consistency mapTStoRetriever::iterator it = ts_to_numberOfTSretrievers.begin(); @@ -449,7 +449,7 @@ bool checkInterModalConsistencyForArea(Area& area, } // Hydro Max Power : Add hydro's max power number of TS in area ... - indexTS = ts_to_tsIndex.at(timeSeriesHydroPowerCredits); + indexTS = ts_to_tsIndex.at(timeSeriesHydroMaxPower); if (isTSintermodal[indexTS]) { uint nbTimeSeries = area.hydro.series->countpowercredits; @@ -568,11 +568,11 @@ void storeTSnumbersForIntraModal(const array& intramo // ------------- // Hydro Max Power ... // ------------- - assert(year < area.hydro.series->timeseriesNumbersPowerCredits.height); - indexTS = ts_to_tsIndex.at(timeSeriesHydroPowerCredits); + assert(year < area.hydro.series->timeseriesNumbersHydroMaxPower.height); + indexTS = ts_to_tsIndex.at(timeSeriesHydroMaxPower); if (isTSintramodal[indexTS]) - area.hydro.series->timeseriesNumbersPowerCredits[0][year] = intramodal_draws[indexTS]; + area.hydro.series->timeseriesNumbersHydroMaxPower[0][year] = intramodal_draws[indexTS]; // ------------- // Thermal ... @@ -684,14 +684,14 @@ void drawAndStoreTSnumbersForNOTintraModal(const array& i // ------------- // Hydro Max Power... // ------------- - indexTS = ts_to_tsIndex.at(timeSeriesHydroPowerCredits); + indexTS = ts_to_tsIndex.at(timeSeriesHydroMaxPower); if (!isTSintramodal[indexTS]) { uint nbTimeSeries = area.hydro.series->maxgen.width; if (nbTimeSeries != 1) { - area.hydro.series->timeseriesNumbersPowerCredits[0][year] = static_cast( + area.hydro.series->timeseriesNumbersHydroMaxPower[0][year] = static_cast( (floor(study.runtime->random[seedTimeseriesNumbers].next() * nbTimeSeries))); } } @@ -805,8 +805,8 @@ Matrix* getFirstTSnumberInterModalMatrixFoundInArea( else if (isTSintermodal[ts_to_tsIndex.at(timeSeriesRenewable)] && area.renewable.clusterCount() > 0) tsNumbersMtx = &(area.renewable.clusters[0]->series->timeseriesNumbers); - else if (isTSintermodal[ts_to_tsIndex.at(timeSeriesHydroPowerCredits)]) - tsNumbersMtx = &(area.hydro.series->timeseriesNumbersPowerCredits); + else if (isTSintermodal[ts_to_tsIndex.at(timeSeriesHydroMaxPower)]) + tsNumbersMtx = &(area.hydro.series->timeseriesNumbersHydroMaxPower); } assert(tsNumbersMtx); @@ -839,9 +839,9 @@ void applyMatrixDrawsToInterModalModesInArea(Matrix* tsNumbersMtx, if (isTSintermodal[ts_to_tsIndex.at(timeSeriesHydro)]) area.hydro.series->timeseriesNumbers[0][year] = draw; - assert(year < area.hydro.series->timeseriesNumbersPowerCredits.height); - if (isTSintermodal[ts_to_tsIndex.at(timeSeriesHydroPowerCredits)]) - area.hydro.series->timeseriesNumbersPowerCredits[0][year] = draw; + assert(year < area.hydro.series->timeseriesNumbersHydroMaxPower.height); + if (isTSintermodal[ts_to_tsIndex.at(timeSeriesHydroMaxPower)]) + area.hydro.series->timeseriesNumbersHydroMaxPower[0][year] = draw; if (isTSintermodal[ts_to_tsIndex.at(timeSeriesThermal)]) { @@ -897,7 +897,7 @@ static void fixTSNumbersWhenWidthIsOne(Study& study) area.hydro.series->timeseriesNumbers, area.hydro.series->count, years); // Hydro Max Power fixTSNumbersSingleAreaSingleMode( - area.hydro.series->timeseriesNumbersPowerCredits, area.hydro.series->countpowercredits, years); + area.hydro.series->timeseriesNumbersHydroMaxPower, area.hydro.series->countpowercredits, years); // Thermal std::for_each(area.thermal.clusters.cbegin(), @@ -965,7 +965,7 @@ bool TimeSeriesNumbers::Generate(Study& study) (bool)(timeSeriesRenewable & parameters.intraModal) && parameters.renewableGeneration.isClusters(), (bool)(timeSeriesTransmissionCapacities & parameters.intraModal), - static_cast(timeSeriesHydroPowerCredits & parameters.intraModal)}; + static_cast(timeSeriesHydroMaxPower & parameters.intraModal)}; array nbTimeseriesByMode; @@ -1012,7 +1012,7 @@ bool TimeSeriesNumbers::Generate(Study& study) (bool)(timeSeriesRenewable & parameters.interModal) && parameters.renewableGeneration.isClusters(), false, // links transmission capacities time series cannot be inter-modal - static_cast(timeSeriesHydroPowerCredits & parameters.interModal)}; + static_cast(timeSeriesHydroMaxPower & parameters.interModal)}; if (std::any_of(std::begin(isTSintermodal), std::end(isTSintermodal), [](bool x) { return x; })) { @@ -1051,7 +1051,7 @@ void TimeSeriesNumbers::StoreTimeSeriesNumbersIntoOuput(Data::Study& study) study.storeTimeSeriesNumbers(); study.storeTimeSeriesNumbers(); study.storeTimeSeriesNumbers(); - study.storeTimeSeriesNumbers(); + study.storeTimeSeriesNumbers(); Simulation::BindingConstraintsTimeSeriesNumbersWriter ts_writer(study.resultWriter); ts_writer.write(study.bindingConstraintsGroups); diff --git a/src/solver/variable/economy/max-mrg.cpp b/src/solver/variable/economy/max-mrg.cpp index de0754c887..2101d4f541 100644 --- a/src/solver/variable/economy/max-mrg.cpp +++ b/src/solver/variable/economy/max-mrg.cpp @@ -133,7 +133,7 @@ inline void PrepareMaxMRGFor(const State& state, double* opmrg, uint numSpace) uint loop = 100; // arbitrary - maximum number of iterations // Pmax - uint tsIndex = (NumeroChroniquesTireesParPays[numSpace][index]).HydrauliquePowerCredits; + uint tsIndex = (NumeroChroniquesTireesParPays[numSpace][index]).HydrauliqueMaxPower; auto& maxgenmatrix = area.hydro.series->maxgen; const auto& P = maxgenmatrix[tsIndex < maxgenmatrix.width ? tsIndex : 0]; diff --git a/src/tests/src/libs/antares/study/parts/hydro/test-hydro-series.cpp b/src/tests/src/libs/antares/study/parts/hydro/test-hydro-series.cpp index 2f2772bb1c..b27a029481 100644 --- a/src/tests/src/libs/antares/study/parts/hydro/test-hydro-series.cpp +++ b/src/tests/src/libs/antares/study/parts/hydro/test-hydro-series.cpp @@ -95,7 +95,7 @@ BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_both_matrix_equal_width, Fixt maxpump.reset(3, HOURS_PER_YEAR); buffer.clear() << base_folder << SEP << series_folder; - ret = area_1->hydro.series->LoadHydroPowerCredits(*study, area_1->id, buffer); + ret = area_1->hydro.series->LoadMaxPower(*study, area_1->id, buffer); BOOST_CHECK(ret); } @@ -120,7 +120,7 @@ BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_matrices_different_width_case maxpump.reset(3, HOURS_PER_YEAR); buffer.clear() << base_folder << SEP << series_folder; - ret = area_1->hydro.series->LoadHydroPowerCredits(*study, area_1->id, buffer); + ret = area_1->hydro.series->LoadMaxPower(*study, area_1->id, buffer); BOOST_CHECK(ret); BOOST_CHECK_EQUAL(maxgen.width, 3); } @@ -146,7 +146,7 @@ BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_matrices_different_width_case maxpump.reset(1, HOURS_PER_YEAR); buffer.clear() << base_folder << SEP << series_folder; - ret = area_1->hydro.series->LoadHydroPowerCredits(*study, area_1->id, buffer); + ret = area_1->hydro.series->LoadMaxPower(*study, area_1->id, buffer); BOOST_CHECK(ret); BOOST_CHECK_EQUAL(maxpump.width, 3); } @@ -174,7 +174,7 @@ BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_no_solver, Fixture) maxpump.reset(3, HOURS_PER_YEAR); buffer.clear() << base_folder << SEP << series_folder; - ret = area_No_Solver->hydro.series->LoadHydroPowerCredits( + ret = area_No_Solver->hydro.series->LoadMaxPower( *studyNoSolver, area_No_Solver->id, buffer); BOOST_CHECK(ret); BOOST_CHECK(area_No_Solver->hydro.hydroModulable); diff --git a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp index 660c035caa..c394df9bcd 100644 --- a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp +++ b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp @@ -248,10 +248,10 @@ BOOST_FIXTURE_TEST_CASE(on_area3_and_on_year_10__hydro_power_credits_TS_number_6 AreaName::Vector splitKey = { "hgp", "area 3", yearNumber }; BOOST_CHECK(my_rule.readLine(splitKey, tsNumber, false)); - BOOST_CHECK_EQUAL(my_rule.hydroPowerCredits.get_value(yearNumber.to(), area_3->index), tsNumber.to()); + BOOST_CHECK_EQUAL(my_rule.hydroMaxPower.get_value(yearNumber.to(), area_3->index), tsNumber.to()); BOOST_CHECK(my_rule.apply()); - BOOST_CHECK_EQUAL(area_3->hydro.series->timeseriesNumbersPowerCredits[0][yearNumber.to()], tsNumber.to() - 1); + BOOST_CHECK_EQUAL(area_3->hydro.series->timeseriesNumbersHydroMaxPower[0][yearNumber.to()], tsNumber.to() - 1); } diff --git a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp index 717ae8bbf3..00fab10d89 100644 --- a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp +++ b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp @@ -357,14 +357,14 @@ BOOST_FIXTURE_TEST_CASE( } // ================= -// Tests on Hydro Power Credits +// Tests on Hydro Max Power // ================= BOOST_FIXTURE_TEST_CASE( HYDRO_POWER_CREDITS__TS_number_for_many_areas_and_years__generated_and_ref_sc_buider_files_are_identical, saveFixture) { - my_rule->hydroPowerCredits.setTSnumber(area_2->index, 10, 7); - my_rule->hydroPowerCredits.setTSnumber(area_3->index, 4, 11); - my_rule->hydroPowerCredits.setTSnumber(area_1->index, 11, 3); + my_rule->hydroMaxPower.setTSnumber(area_2->index, 10, 7); + my_rule->hydroMaxPower.setTSnumber(area_3->index, 4, 11); + my_rule->hydroMaxPower.setTSnumber(area_1->index, 11, 3); saveScenarioBuilder(); diff --git a/src/ui/action/handler/antares-study/area/create.cpp b/src/ui/action/handler/antares-study/area/create.cpp index a2c9d5c9fd..781b3435e0 100644 --- a/src/ui/action/handler/antares-study/area/create.cpp +++ b/src/ui/action/handler/antares-study/area/create.cpp @@ -286,7 +286,7 @@ void Create::createActionsForAStandardAreaCopy(Context& ctx, bool copyPosition) *tsNode += new Action::AntaresStudy::Area::AllocationHydro(pOriginalAreaName); //Hydro Max Power - *tsNode += new DataTimeseries(Data::timeSeriesHydroPowerCredits, pOriginalAreaName); + *tsNode += new DataTimeseries(Data::timeSeriesHydroMaxPower, pOriginalAreaName); // Thermal auto* area = ctx.extStudy->areas.findFromName(pOriginalAreaName); diff --git a/src/ui/action/handler/antares-study/area/timeseries.cpp b/src/ui/action/handler/antares-study/area/timeseries.cpp index 632dfb8733..7b5bfe84e1 100644 --- a/src/ui/action/handler/antares-study/area/timeseries.cpp +++ b/src/ui/action/handler/antares-study/area/timeseries.cpp @@ -57,8 +57,8 @@ DataTimeseries::DataTimeseries(Data::TimeSeries ts, const AnyString& areaname) : case Data::timeSeriesThermal: pInfos.caption << "Thermal : Timeseries"; break; - case Data::timeSeriesHydroPowerCredits: - pInfos.caption << "Power-Credits : Timeseries"; + case Data::timeSeriesHydroMaxPower: + pInfos.caption << "Max-Power : Timeseries"; break; default: break; @@ -106,8 +106,8 @@ void DataTimeseries::registerViewsWL(Context& ctx) case Data::timeSeriesThermal: ctx.view["6:Thermal"]["1:TS"] = this; break; - case Data::timeSeriesHydroPowerCredits: - ctx.view["7:Power-Credits"]["1:TS"] = this; + case Data::timeSeriesHydroMaxPower: + ctx.view["7:Max-Power"]["1:TS"] = this; break; default: break; @@ -173,7 +173,7 @@ bool DataTimeseries::performWL(Context& ctx) break; } - case Data::timeSeriesHydroPowerCredits: + case Data::timeSeriesHydroMaxPower: { ctx.area->hydro.series->maxgen = source->hydro.series->maxgen; ctx.area->hydro.series->maxpump = source->hydro.series->maxpump; diff --git a/src/ui/simulator/application/main/build/scenario-builder.cpp b/src/ui/simulator/application/main/build/scenario-builder.cpp index 7cba11542e..0618c51187 100644 --- a/src/ui/simulator/application/main/build/scenario-builder.cpp +++ b/src/ui/simulator/application/main/build/scenario-builder.cpp @@ -177,17 +177,17 @@ class hydroScBuilderPageMaker final : public simpleScBuilderPageMaker }; // Hydro Max Power ... -class hydroPowerCreditsScBuilderPageMaker final : public simpleScBuilderPageMaker +class hydroMaxPowerScBuilderPageMaker final : public simpleScBuilderPageMaker { using simpleScBuilderPageMaker::simpleScBuilderPageMaker; Renderer::ScBuilderRendererBase* getRenderer() override { - return new_check_allocation(); + return new_check_allocation(); } Notebook::Page* addPageToNotebook() override { - return notebook()->add(grid(), wxT("power-credits"), wxT("Hydro-Power-Credits")); + return notebook()->add(grid(), wxT("hydro-max-power"), wxT("Hydro-Max-Power")); } }; @@ -372,9 +372,9 @@ void ApplWnd::createNBScenarioBuilder() hydroScBuilderPageMaker hydroSBpageMaker(scenarioBuilderPanel, pScenarioBuilderNotebook); pageScBuilderHydro = hydroSBpageMaker.createPage(); - hydroPowerCreditsScBuilderPageMaker hydroPowerCreditsSBpageMaker(scenarioBuilderPanel, + hydroMaxPowerScBuilderPageMaker hydroMaxPowerSBpageMaker(scenarioBuilderPanel, pScenarioBuilderNotebook); - pageScBuilderHydroPowerCredits = hydroPowerCreditsSBpageMaker.createPage(); + pageScBuilderHydroMaxPower = hydroMaxPowerSBpageMaker.createPage(); windScBuilderPageMaker windSBpageMaker(scenarioBuilderPanel, pScenarioBuilderNotebook); pageScBuilderWind = windSBpageMaker.createPage(); diff --git a/src/ui/simulator/application/main/main.h b/src/ui/simulator/application/main/main.h index 3541566589..4d7caa3918 100644 --- a/src/ui/simulator/application/main/main.h +++ b/src/ui/simulator/application/main/main.h @@ -699,7 +699,7 @@ class ApplWnd final : public Component::Frame::WxLocalFrame, public Yuni::IEvent Component::Notebook::Page* pageScBuilderLoad; Component::Notebook::Page* pageScBuilderThermal; Component::Notebook::Page* pageScBuilderHydro; - Component::Notebook::Page* pageScBuilderHydroPowerCredits; + Component::Notebook::Page* pageScBuilderHydroMaxPower; Component::Notebook::Page* pageScBuilderWind; Component::Notebook::Page* pageScBuilderSolar; Component::Notebook::Page* pageScBuilderNTC; diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/column.cpp b/src/ui/simulator/toolbox/components/datagrid/renderer/column.cpp index 1651d92a18..1363e9b39b 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/column.cpp +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/column.cpp @@ -166,7 +166,7 @@ ColumnNTC::ColumnNTC() : Column(timeSeriesTransmissionCapacities, " Links NTC // ------------------------------- // Column Hydro Max Power // ------------------------------- -ColumnHydroPowerCredits::ColumnHydroPowerCredits() : Column(timeSeriesHydroPowerCredits, " Hydro-Power-Credits ") +ColumnHydroMaxPower::ColumnHydroMaxPower() : Column(timeSeriesHydroMaxPower, " Hydro-Max-Power ") { cells_ = {new_check_allocation(), new_check_allocation(wxT("On")), diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/column.h b/src/ui/simulator/toolbox/components/datagrid/renderer/column.h index 575b63763f..71b31aa0ec 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/column.h +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/column.h @@ -101,11 +101,11 @@ class ColumnNTC final : public Column // ------------------------------- // Column for Hydro Max Power // ------------------------------- -class ColumnHydroPowerCredits final : public Column +class ColumnHydroMaxPower final : public Column { public: - ColumnHydroPowerCredits(); - ~ColumnHydroPowerCredits() override = default; + ColumnHydroMaxPower(); + ~ColumnHydroMaxPower() override = default; }; } // namespace Renderer diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-hydro-renderer.cpp b/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-hydro-renderer.cpp index d2718e81fa..752ef14eec 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-hydro-renderer.cpp +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-hydro-renderer.cpp @@ -69,31 +69,31 @@ double hydroScBuilderRenderer::cellNumericValue(int x, int y) const return 0.; } -bool hydroPowerCreditsScBuilderRenderer::cellValue(int x, int y, const Yuni::String& value) +bool hydroMaxPowerScBuilderRenderer::cellValue(int x, int y, const Yuni::String& value) { if (!(!study) && !(!pRules) && (uint)x < study->parameters.nbYears) { if ((uint)y < study->areas.size()) { - assert((uint)y < pRules->hydroPowerCredits.width()); - assert((uint)x < pRules->hydroPowerCredits.height()); + assert((uint)y < pRules->hydroMaxPower.width()); + assert((uint)x < pRules->hydroMaxPower.height()); uint val = fromStringToTSnumber(value); - pRules->hydroPowerCredits.set_value(x, y, val); + pRules->hydroMaxPower.set_value(x, y, val); return true; } } return false; } -double hydroPowerCreditsScBuilderRenderer::cellNumericValue(int x, int y) const +double hydroMaxPowerScBuilderRenderer::cellNumericValue(int x, int y) const { if (!(!study) && !(!pRules) && (uint)x < study->parameters.nbYears) { if ((uint)y < study->areas.size()) { - assert((uint)y < pRules->hydroPowerCredits.width()); - assert((uint)x < pRules->hydroPowerCredits.height()); - return pRules->hydroPowerCredits.get_value(x, y); + assert((uint)y < pRules->hydroMaxPower.width()); + assert((uint)x < pRules->hydroMaxPower.height()); + return pRules->hydroMaxPower.get_value(x, y); } } return 0.; diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-hydro-renderer.h b/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-hydro-renderer.h index 44e35a4be8..80ba31ebe6 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-hydro-renderer.h +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-hydro-renderer.h @@ -46,14 +46,14 @@ class hydroScBuilderRenderer : public ScBuilderRendererAreasAsRows double cellNumericValue(int x, int y) const; }; // class hydroScBuilderRenderer -class hydroPowerCreditsScBuilderRenderer : public ScBuilderRendererAreasAsRows +class hydroMaxPowerScBuilderRenderer : public ScBuilderRendererAreasAsRows { public: - hydroPowerCreditsScBuilderRenderer() = default; + hydroMaxPowerScBuilderRenderer() = default; bool cellValue(int x, int y, const Yuni::String& value); double cellNumericValue(int x, int y) const; -}; // class hydroPowerCreditsScBuilderRenderer +}; // class hydroMaxPowerScBuilderRenderer } // namespace Renderer } // namespace Datagrid diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/ts-management.cpp b/src/ui/simulator/toolbox/components/datagrid/renderer/ts-management.cpp index 81bccb8082..69e212256b 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/ts-management.cpp +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/ts-management.cpp @@ -46,7 +46,7 @@ TSmanagement::TSmanagement() : pControl(nullptr) columns_.push_back(new classicColumn(timeSeriesLoad, " Load ")); columns_.push_back(new thermalColumn()); columns_.push_back(new classicColumn(timeSeriesHydro, " Hydro ")); - columns_.push_back(new ColumnHydroPowerCredits()); + columns_.push_back(new ColumnHydroMaxPower()); } void TSmanagement::checkLineNumberInColumns() From be0b0c9bcb60df40cc544201e0a5bb2be852109f Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Fri, 22 Sep 2023 16:27:30 +0200 Subject: [PATCH 03/40] Implicit conversion code smell --- .../aleatoire/alea_tirage_au_sort_chroniques.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/solver/aleatoire/alea_tirage_au_sort_chroniques.cpp b/src/solver/aleatoire/alea_tirage_au_sort_chroniques.cpp index 44873a5e1d..3f2b3ca216 100644 --- a/src/solver/aleatoire/alea_tirage_au_sort_chroniques.cpp +++ b/src/solver/aleatoire/alea_tirage_au_sort_chroniques.cpp @@ -59,17 +59,21 @@ void ApplyRandomTSnumbers(const Study& study, ptchro.Solar = (data.timeSeries.width != 1) ? (long)data.timeseriesNumbers[0][year] : 0; // zero-based } - // Hydro and Hydro Max Power + // Hydro { const Data::DataSeriesHydro& data = *area.hydro.series; assert(year < data.timeseriesNumbers.height); - assert(year < data.timeseriesNumbersHydroMaxPower.height); + ptchro.Hydraulique = (data.count != 1) ? (long)data.timeseriesNumbers[0][year] : 0; // zero-based - ptchro.HydrauliqueMaxPower - = (data.countpowercredits != 1) - ? static_cast(data.timeseriesNumbersHydroMaxPower[0][year]) - : 0; + } + // Hydro Max Power + { + const Data::DataSeriesHydro& data = *area.hydro.series; + assert(year < data.timeseriesNumbersHydroMaxPower.height); + ptchro.HydrauliqueMaxPower = (data.countpowercredits != 1) + ? (data.timeseriesNumbersHydroMaxPower[0][year]) + : 0; // zero-based } // Wind { From 033807c3fb818ccc2aca053c0358a68cc5f92d52 Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Fri, 22 Sep 2023 17:27:09 +0200 Subject: [PATCH 04/40] Files name modification --- src/libs/antares/study/CMakeLists.txt | 4 ++-- ...rCreditsTSNumberData.cpp => HydroMaxPowerTSNumberData.cpp} | 4 ++-- ...PowerCreditsTSNumberData.h => HydroMaxPowerTSNumberData.h} | 0 src/libs/antares/study/scenario-builder/rules.h | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) rename src/libs/antares/study/scenario-builder/{HydroPowerCreditsTSNumberData.cpp => HydroMaxPowerTSNumberData.cpp} (94%) rename src/libs/antares/study/scenario-builder/{HydroPowerCreditsTSNumberData.h => HydroMaxPowerTSNumberData.h} (100%) diff --git a/src/libs/antares/study/CMakeLists.txt b/src/libs/antares/study/CMakeLists.txt index ba979fda64..c2567f083b 100644 --- a/src/libs/antares/study/CMakeLists.txt +++ b/src/libs/antares/study/CMakeLists.txt @@ -23,8 +23,8 @@ set(SRC_STUDY_SCENARIO_BUILDER scenario-builder/ThermalTSNumberData.h scenario-builder/HydroTSNumberData.h scenario-builder/HydroTSNumberData.cpp - scenario-builder/HydroPowerCreditsTSNumberData.h - scenario-builder/HydroPowerCreditsTSNumberData.cpp + scenario-builder/HydroMaxPowerTSNumberData.h + scenario-builder/HydroMaxPowerTSNumberData.cpp scenario-builder/SolarTSNumberData.cpp scenario-builder/solarTSNumberData.h scenario-builder/WindTSNumberData.h diff --git a/src/libs/antares/study/scenario-builder/HydroPowerCreditsTSNumberData.cpp b/src/libs/antares/study/scenario-builder/HydroMaxPowerTSNumberData.cpp similarity index 94% rename from src/libs/antares/study/scenario-builder/HydroPowerCreditsTSNumberData.cpp rename to src/libs/antares/study/scenario-builder/HydroMaxPowerTSNumberData.cpp index 028be97bf9..3bfb7e50d5 100644 --- a/src/libs/antares/study/scenario-builder/HydroPowerCreditsTSNumberData.cpp +++ b/src/libs/antares/study/scenario-builder/HydroMaxPowerTSNumberData.cpp @@ -1,10 +1,10 @@ -#include "HydroPowerCreditsTSNumberData.h" +#include "HydroMaxPowerTSNumberData.h" #include "applyToMatrix.hxx" // ================================ -// Hydro Energy Credits... +// Hydro Max Power... // ================================ namespace Antares::Data::ScenarioBuilder diff --git a/src/libs/antares/study/scenario-builder/HydroPowerCreditsTSNumberData.h b/src/libs/antares/study/scenario-builder/HydroMaxPowerTSNumberData.h similarity index 100% rename from src/libs/antares/study/scenario-builder/HydroPowerCreditsTSNumberData.h rename to src/libs/antares/study/scenario-builder/HydroMaxPowerTSNumberData.h diff --git a/src/libs/antares/study/scenario-builder/rules.h b/src/libs/antares/study/scenario-builder/rules.h index 9e81ddf590..ebfe5e534f 100644 --- a/src/libs/antares/study/scenario-builder/rules.h +++ b/src/libs/antares/study/scenario-builder/rules.h @@ -40,7 +40,7 @@ #include "HydroTSNumberData.h" #include "WindTSNumberData.h" #include "LoadTSNumberData.h" -#include "HydroPowerCreditsTSNumberData.h" +#include "HydroMaxPowerTSNumberData.h" #include #include From cddc46eddf71bb35f900581255183976ebdc7dba Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Sat, 23 Sep 2023 17:24:00 +0200 Subject: [PATCH 05/40] Renaming matrices from PartHydro and DataTransfer classes --- docs/reference-guide/13-file-format.md | 4 +- src/libs/antares/study/area/scratchpad.cpp | 8 ++-- .../antares/study/cleaner/cleaner-v20.cpp | 8 ++-- .../antares/study/parts/hydro/container.cpp | 48 +++++++++---------- .../antares/study/parts/hydro/container.h | 4 +- .../study/parts/hydro/datatransfer.cpp | 40 ++++++++-------- .../antares/study/parts/hydro/datatransfer.h | 2 +- src/solver/hydro/management/daily.cpp | 2 +- .../simulation/sim_calcul_economique.cpp | 10 ++-- .../parts/hydro/test-datatransfer-class.cpp | 22 ++++----- .../renderer/area/hydromonthlypower.cpp | 4 +- 11 files changed, 76 insertions(+), 76 deletions(-) diff --git a/docs/reference-guide/13-file-format.md b/docs/reference-guide/13-file-format.md index 769b5b69b1..c7ae851631 100644 --- a/docs/reference-guide/13-file-format.md +++ b/docs/reference-guide/13-file-format.md @@ -1,9 +1,9 @@ # Study format changes This is a list of all recent changes that came with new Antares Simulator features. The main goal of this document is to lower the costs of changing existing interfaces, both GUI and scripts. ## v8.8.0 -For each area, new files are added **input/hydro/series/<area>/maxgen.txt** and **input/hydro/series/<area>/maxpump.txt**. These files have one or more columns, and 8760 rows. The number of columns in these two files must be the same, if there is more than one column in each file, but if there is just one column for example in maxgen.txt file, maxpump.txt file can have more than one column and vice versa. For old studies, file **input/hydro/common/capacity/maxpower_<area>** will be deleted after upgrading the study and corresponding data from that file will be copied to already mentioned new files, even if study is upgraded or not. In that case maxgen.txt and maxpump.txt files will have just one column and 8760 rows. +For each area, new files are added **input/hydro/series/<area>/maxHourlyGenPower.txt** and **input/hydro/series/<area>/maxHourlyPumpPower.txt**. These files have one or more columns, and 8760 rows. The number of columns in these two files must be the same, if there is more than one column in each file, but if there is just one column for example in maxHourlyGenPower.txt file, maxHourlyPumpPower.txt file can have more than one column and vice versa. For old studies, file **input/hydro/common/capacity/maxpower_<area>** will be deleted after upgrading the study and corresponding data from that file will be copied to already mentioned new files, even if study is upgraded or not. In that case maxHourlyGenPower.txt and maxHourlyPumpPower.txt files will have just one column and 8760 rows. -Also for each area, new files are added **input/hydro/common/capacity/maxhoursGen_<area>** and **input/hydro/common/capacity/maxhoursPump_<area>**. These files have just one column and 365 rows. For old studies, file **input/hydro/common/capacity/maxpower_<area>** will be deleted after upgrading the study and corresponding data from that file will be copied to already mentioned new files, even if study is upgraded or not. +Also for each area, new files are added **input/hydro/common/capacity/maxHourlyGenEnergy_<area>** and **input/hydro/common/capacity/maxHourlyPumpEnergy_<area>**. These files have just one column and 365 rows. For old studies, file **input/hydro/common/capacity/maxpower_<area>** will be deleted after upgrading the study and corresponding data from that file will be copied to already mentioned new files, even if study is upgraded or not. ### Input Under `Configure/MC Scenario Builder` new section added `Hydro Max Power` In the existing file **settings/scenariobuilder.dat**, under **<ruleset>** section following properties added: diff --git a/src/libs/antares/study/area/scratchpad.cpp b/src/libs/antares/study/area/scratchpad.cpp index ed8b7ffbce..1b2a3a24e2 100644 --- a/src/libs/antares/study/area/scratchpad.cpp +++ b/src/libs/antares/study/area/scratchpad.cpp @@ -89,9 +89,9 @@ AreaScratchpad::AreaScratchpad(const StudyRuntimeInfos& rinfos, Area& area) : ts // ... Getting hydro max power auto const& maxPower = area.hydro.series->maxgen; - auto const& maxGenHours = area.hydro.maxHoursGen[0]; + auto const& maxHourlyGenEnergy = area.hydro.maxHourlyGenEnergy[0]; - hydroGenerationPermission = CheckForPositiveEnergy(maxPower, maxGenHours); + hydroGenerationPermission = CheckForPositiveEnergy(maxPower, maxHourlyGenEnergy); // --------------------- // Hydro has inflows @@ -128,10 +128,10 @@ AreaScratchpad::AreaScratchpad(const StudyRuntimeInfos& rinfos, Area& area) : ts // ... Hydro max pumping power and energy auto const& maxPumpingP = area.hydro.series->maxpump; - auto const& maxPumpHours = area.hydro.maxHoursPump[0]; + auto const& maxHourlyPumpEnergy = area.hydro.maxHourlyPumpEnergy[0]; // If pumping energy is nil over the whole year, pumpHasMod is false, true otherwise. - pumpHasMod = CheckForPositiveEnergy(maxPumpingP, maxPumpHours); + pumpHasMod = CheckForPositiveEnergy(maxPumpingP, maxHourlyPumpEnergy); } AreaScratchpad::~AreaScratchpad() = default; diff --git a/src/libs/antares/study/cleaner/cleaner-v20.cpp b/src/libs/antares/study/cleaner/cleaner-v20.cpp index 6b7a5ffc85..87037e1c01 100644 --- a/src/libs/antares/study/cleaner/cleaner-v20.cpp +++ b/src/libs/antares/study/cleaner/cleaner-v20.cpp @@ -89,9 +89,9 @@ static void listOfFilesAnDirectoriesToKeepForArea(PathList& e, PathList& p, cons e.add(buffer); buffer.clear() << "input/hydro/common/capacity/maxpower_" << id << ".txt"; e.add(buffer); - buffer.clear() << "input/hydro/common/capacity/maxhoursGen_" << id << ".txt"; + buffer.clear() << "input/hydro/common/capacity/maxHourlyGenEnergy_" << id << ".txt"; e.add(buffer); - buffer.clear() << "input/hydro/common/capacity/maxhoursPump_" << id << ".txt"; + buffer.clear() << "input/hydro/common/capacity/maxHourlyPumpEnergy_" << id << ".txt"; e.add(buffer); buffer.clear() << "input/hydro/common/capacity/reservoir_" << id << ".txt"; e.add(buffer); @@ -103,9 +103,9 @@ static void listOfFilesAnDirectoriesToKeepForArea(PathList& e, PathList& p, cons e.add(buffer); buffer.clear() << "input/hydro/series/" << id << "/mingen.txt"; e.add(buffer); - buffer.clear() << "input/hydro/series/" << id << "/maxgen.txt"; + buffer.clear() << "input/hydro/series/" << id << "/maxHourlyGenEnergy.txt"; e.add(buffer); - buffer.clear() << "input/hydro/series/" << id << "/maxpump.txt"; + buffer.clear() << "input/hydro/series/" << id << "/maxHourlyPumpEnergy.txt"; e.add(buffer); buffer.clear() << "input/hydro/allocation/" << id << ".ini"; p.add(buffer); diff --git a/src/libs/antares/study/parts/hydro/container.cpp b/src/libs/antares/study/parts/hydro/container.cpp index c7705b0ae0..297a1e944f 100644 --- a/src/libs/antares/study/parts/hydro/container.cpp +++ b/src/libs/antares/study/parts/hydro/container.cpp @@ -92,10 +92,10 @@ void PartHydro::reset() reservoirLevel.fillColumn(average, 0.5); reservoirLevel.fillColumn(maximum, 1.); waterValues.reset(101, DAYS_PER_YEAR, true); - maxHoursGen.reset(1, DAYS_PER_YEAR, true); - maxHoursGen.fillColumn(0, 24.); - maxHoursPump.reset(1, DAYS_PER_YEAR, true); - maxHoursPump.fillColumn(0, 24.); + maxHourlyGenEnergy.reset(1, DAYS_PER_YEAR, true); + maxHourlyGenEnergy.fillColumn(0, 24.); + maxHourlyPumpEnergy.reset(1, DAYS_PER_YEAR, true); + maxHourlyPumpEnergy.fillColumn(0, 24.); creditModulation.reset(101, 2, true); creditModulation.fill(1); // reset of the hydro allocation - however we don't have any information @@ -223,8 +223,8 @@ bool PartHydro::LoadFromFolder(Study& study, const AnyString& folder) } bool errorHours = false; - auto& colGen = area.hydro.maxHoursGen[0]; - auto& colPump = area.hydro.maxHoursPump[0]; + auto& colGen = area.hydro.maxHourlyGenEnergy[0]; + auto& colPump = area.hydro.maxHourlyPumpEnergy[0]; for (int day = 0; day < DAYS_PER_YEAR; day++) { @@ -707,13 +707,13 @@ bool PartHydro::SaveToFolder(const AreaList& areas, const AnyString& folder) sPowerToLevel->add(area.id, true); // max hours gen - buffer.clear() << folder << SEP << "common" << SEP << "capacity" << SEP << "maxhoursGen_" + buffer.clear() << folder << SEP << "common" << SEP << "capacity" << SEP << "maxHourlyGenEnergy_" << area.id << ".txt"; - ret = area.hydro.maxHoursGen.saveToCSVFile(buffer, /*decimal*/ 2) && ret; + ret = area.hydro.maxHourlyGenEnergy.saveToCSVFile(buffer, /*decimal*/ 2) && ret; // max hours pump - buffer.clear() << folder << SEP << "common" << SEP << "capacity" << SEP << "maxhoursPump_" + buffer.clear() << folder << SEP << "common" << SEP << "capacity" << SEP << "maxHourlyPumpEnergy_" << area.id << ".txt"; - ret = area.hydro.maxHoursPump.saveToCSVFile(buffer, /*decimal*/ 2) && ret; + ret = area.hydro.maxHourlyPumpEnergy.saveToCSVFile(buffer, /*decimal*/ 2) && ret; // credit modulations buffer.clear() << folder << SEP << "common" << SEP << "capacity" << SEP << "creditmodulations_" << area.id << ".txt"; @@ -743,8 +743,8 @@ bool PartHydro::forceReload(bool reload) const ret = inflowPattern.forceReload(reload) && ret; ret = reservoirLevel.forceReload(reload) && ret; ret = waterValues.forceReload(reload) && ret; - ret = maxHoursGen.forceReload(reload) && ret; - ret = maxHoursPump.forceReload(reload) && ret; + ret = maxHourlyGenEnergy.forceReload(reload) && ret; + ret = maxHourlyPumpEnergy.forceReload(reload) && ret; if (series) ret = series->forceReload(reload) && ret; @@ -760,8 +760,8 @@ void PartHydro::markAsModified() const reservoirLevel.markAsModified(); waterValues.markAsModified(); creditModulation.markAsModified(); - maxHoursGen.markAsModified(); - maxHoursPump.markAsModified(); + maxHourlyGenEnergy.markAsModified(); + maxHourlyPumpEnergy.markAsModified(); if (series) series->markAsModified(); @@ -816,16 +816,16 @@ void PartHydro::copyFrom(const PartHydro& rhs) // max hours gen { - maxHoursGen = rhs.maxHoursGen; - maxHoursGen.unloadFromMemory(); - rhs.maxHoursGen.unloadFromMemory(); + maxHourlyGenEnergy = rhs.maxHourlyGenEnergy; + maxHourlyGenEnergy.unloadFromMemory(); + rhs.maxHourlyGenEnergy.unloadFromMemory(); } // max hours pump { - maxHoursPump = rhs.maxHoursPump; - maxHoursPump.unloadFromMemory(); - rhs.maxHoursPump.unloadFromMemory(); + maxHourlyPumpEnergy = rhs.maxHourlyPumpEnergy; + maxHourlyPumpEnergy.unloadFromMemory(); + rhs.maxHourlyPumpEnergy.unloadFromMemory(); } } @@ -834,17 +834,17 @@ bool PartHydro::LoadHours(Study& study, Area& area, const AnyString& folder) auto& buffer = study.bufferLoadingTS; bool ret = true; - buffer.clear() << folder << SEP << "common" << SEP << "capacity" << SEP << "maxhoursGen_" + buffer.clear() << folder << SEP << "common" << SEP << "capacity" << SEP << "maxHourlyPumpEnergy_" << area.id << '.' << study.inputExtension; - ret = area.hydro.maxHoursGen.loadFromCSVFile( + ret = area.hydro.maxHourlyGenEnergy.loadFromCSVFile( buffer, 1, DAYS_PER_YEAR, Matrix<>::optFixedSize, &study.dataBuffer) && ret; - buffer.clear() << folder << SEP << "common" << SEP << "capacity" << SEP << "maxhoursPump_" + buffer.clear() << folder << SEP << "common" << SEP << "capacity" << SEP << "maxHourlyPumpEnergy_" << area.id << '.' << study.inputExtension; - ret = area.hydro.maxHoursPump.loadFromCSVFile( + ret = area.hydro.maxHourlyPumpEnergy.loadFromCSVFile( buffer, 1, DAYS_PER_YEAR, Matrix<>::optFixedSize, &study.dataBuffer) && ret; diff --git a/src/libs/antares/study/parts/hydro/container.h b/src/libs/antares/study/parts/hydro/container.h index 9c193cea09..131a7d5895 100644 --- a/src/libs/antares/study/parts/hydro/container.h +++ b/src/libs/antares/study/parts/hydro/container.h @@ -162,8 +162,8 @@ class PartHydro //! Data for time-series DataSeriesHydro* series; - Matrix maxHoursGen; - Matrix maxHoursPump; + Matrix maxHourlyGenEnergy; + Matrix maxHourlyPumpEnergy; }; // class PartHydro diff --git a/src/libs/antares/study/parts/hydro/datatransfer.cpp b/src/libs/antares/study/parts/hydro/datatransfer.cpp index 9fac54de84..8a4ca36ad0 100644 --- a/src/libs/antares/study/parts/hydro/datatransfer.cpp +++ b/src/libs/antares/study/parts/hydro/datatransfer.cpp @@ -38,7 +38,7 @@ namespace Antares::Data DataTransfer::DataTransfer() { - maxPower.reset(4, DAYS_PER_YEAR, true); + dailyMaxPumpAndGen.reset(4, DAYS_PER_YEAR, true); } bool DataTransfer::LoadFromFolder(Study& study, const AnyString& folder, Area& area) @@ -63,7 +63,7 @@ bool DataTransfer::LoadFromFolder(Study& study, const AnyString& folder, Area& a enabledModeIsChanged = true; } - ret = maxPower.loadFromCSVFile( + ret = dailyMaxPumpAndGen.loadFromCSVFile( buffer, 4, DAYS_PER_YEAR, Matrix<>::optFixedSize, &study.dataBuffer) && ret; @@ -72,14 +72,14 @@ bool DataTransfer::LoadFromFolder(Study& study, const AnyString& folder, Area& a } else { - ret = maxPower.loadFromCSVFile( + ret = dailyMaxPumpAndGen.loadFromCSVFile( buffer, 4, DAYS_PER_YEAR, Matrix<>::optFixedSize, &study.dataBuffer) && ret; bool errorPowers = false; for (uint i = 0; i < 4; ++i) { - auto& col = maxPower[i]; + auto& col = dailyMaxPumpAndGen[i]; for (uint day = 0; day < DAYS_PER_YEAR; ++day) { if (!errorPowers && (col[day] < 0 || (i % 2 /*column hours*/ && col[day] > 24))) @@ -100,28 +100,28 @@ bool DataTransfer::AutoTransferHours(Study& study, const AnyString& folder, Area auto& buffer = study.bufferLoadingTS; bool ret = true; - auto& maxHoursGen = area.hydro.maxHoursGen; - auto& maxHoursPump = area.hydro.maxHoursPump; + auto& maxHourlyGenEnergy = area.hydro.maxHourlyGenEnergy; + auto& maxHourlyPumpEnergy = area.hydro.maxHourlyPumpEnergy; - maxHoursGen.reset(1, DAYS_PER_YEAR, true); - maxHoursGen.fillColumn(0, 24.); + maxHourlyGenEnergy.reset(1, DAYS_PER_YEAR, true); + maxHourlyGenEnergy.fillColumn(0, 24.); - maxHoursPump.reset(1, DAYS_PER_YEAR, true); - maxHoursPump.fillColumn(0, 24.); + maxHourlyPumpEnergy.reset(1, DAYS_PER_YEAR, true); + maxHourlyPumpEnergy.fillColumn(0, 24.); for (uint day = 0; day < DAYS_PER_YEAR; ++day) { - maxHoursGen[0][day] = maxPower[genMaxE][day]; - maxHoursPump[0][day] = maxPower[pumpMaxE][day]; + maxHourlyGenEnergy[0][day] = dailyMaxPumpAndGen[genMaxE][day]; + maxHourlyPumpEnergy[0][day] = dailyMaxPumpAndGen[pumpMaxE][day]; } - buffer.clear() << folder << SEP << "common" << SEP << "capacity" << SEP << "maxhoursGen_" + buffer.clear() << folder << SEP << "common" << SEP << "capacity" << SEP << "maxHourlyGenEnergy_" << area.id << ".txt"; - ret = maxHoursGen.saveToCSVFile(buffer, /*decimal*/ 2) && ret; + ret = maxHourlyGenEnergy.saveToCSVFile(buffer, /*decimal*/ 2) && ret; - buffer.clear() << folder << SEP << "common" << SEP << "capacity" << SEP << "maxhoursPump_" + buffer.clear() << folder << SEP << "common" << SEP << "capacity" << SEP << "maxHourlyPumpEnergy_" << area.id << ".txt"; - ret = maxHoursPump.saveToCSVFile(buffer, /*decimal*/ 2) && ret; + ret = maxHourlyPumpEnergy.saveToCSVFile(buffer, /*decimal*/ 2) && ret; return ret; } @@ -133,14 +133,14 @@ bool DataTransfer::SupportForOldStudies(Study& study, const AnyString& folder, A auto& maxgen = area.hydro.series->maxgen; auto& maxpump = area.hydro.series->maxpump; - auto& MaxPowerGen = maxPower[genMaxP]; - auto& MaxPowerPump = maxPower[pumpMaxP]; + auto& dailyMaxGen = dailyMaxPumpAndGen[genMaxP]; + auto& dailyMaxPump = dailyMaxPumpAndGen[pumpMaxP]; maxgen.reset(1, HOURS_PER_YEAR); maxpump.reset(1, HOURS_PER_YEAR); - AutoTransferPower(maxgen, MaxPowerGen); - AutoTransferPower(maxpump, MaxPowerPump); + AutoTransferPower(maxgen, dailyMaxGen); + AutoTransferPower(maxpump, dailyMaxPump); buffer.clear() << folder << SEP << "series" << SEP << area.id << SEP << "maxgen." << study.inputExtension; ret = maxgen.saveToCSVFile(buffer, 1, HOURS_PER_YEAR, &study.dataBuffer) && ret; diff --git a/src/libs/antares/study/parts/hydro/datatransfer.h b/src/libs/antares/study/parts/hydro/datatransfer.h index e2e2307305..fe2820eeab 100644 --- a/src/libs/antares/study/parts/hydro/datatransfer.h +++ b/src/libs/antares/study/parts/hydro/datatransfer.h @@ -54,7 +54,7 @@ class DataTransfer pumpMaxE, }; - Matrix maxPower; + Matrix dailyMaxPumpAndGen; bool LoadFromFolder(Study& study, const AnyString& folder, Area& area); bool AutoTransferHours(Study& study, const AnyString& folder, Area& area); diff --git a/src/solver/hydro/management/daily.cpp b/src/solver/hydro/management/daily.cpp index aea7af45fc..5e6fc31155 100644 --- a/src/solver/hydro/management/daily.cpp +++ b/src/solver/hydro/management/daily.cpp @@ -250,7 +250,7 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St uint dayYear = 0; - auto const& maxPowerHours = area.hydro.maxHoursGen; + auto const& maxPowerHours = area.hydro.maxHourlyGenEnergy; auto const& maxPower = area.hydro.series->maxgen; uint tsIndexMaxPower diff --git a/src/solver/simulation/sim_calcul_economique.cpp b/src/solver/simulation/sim_calcul_economique.cpp index 406d2049c3..b52e0ac5ea 100644 --- a/src/solver/simulation/sim_calcul_economique.cpp +++ b/src/solver/simulation/sim_calcul_economique.cpp @@ -681,7 +681,7 @@ void SIM_RenseignementProblemeHebdo(const Study& study, = 0.; problem.CaracteristiquesHydrauliques[k] .MaxEnergieHydrauParIntervalleOptimise[j] - = meanPower * area.hydro.maxHoursGen[0][day] + = meanPower * area.hydro.maxHourlyGenEnergy[0][day] * problem.CaracteristiquesHydrauliques[k] .WeeklyGeneratingModulation; } @@ -732,7 +732,7 @@ void SIM_RenseignementProblemeHebdo(const Study& study, uint day = study.calendar.hours[PasDeTempsDebut + j * 24].dayYear; auto meanPower = CalculateDailyMeanPower(day, srcmaxgen); - double DGC = meanPower * area.hydro.maxHoursGen[0][day]; + double DGC = meanPower * area.hydro.maxHourlyGenEnergy[0][day]; DGU_tmp[j] = DNT[day] * LUB; DGL_tmp[j] = DNT[day] * LLB; @@ -841,7 +841,7 @@ void SIM_RenseignementProblemeHebdo(const Study& study, problem.CaracteristiquesHydrauliques[k] .MaxEnergiePompageParIntervalleOptimise[j] - = meanPump * area.hydro.maxHoursPump[0][day] + = meanPump * area.hydro.maxHourlyPumpEnergy[0][day] * problem.CaracteristiquesHydrauliques[k] .WeeklyPumpingModulation; } @@ -875,7 +875,7 @@ void SIM_RenseignementProblemeHebdo(const Study& study, auto meanPump = CalculateDailyMeanPower(day, srcmaxpump); double DPC - = meanPump * area.hydro.maxHoursPump[0][day]; + = meanPump * area.hydro.maxHourlyPumpEnergy[0][day]; WPU += DPC; } @@ -887,7 +887,7 @@ void SIM_RenseignementProblemeHebdo(const Study& study, uint day = study.calendar.hours[PasDeTempsDebut + j * 24].dayYear; auto meanPump = CalculateDailyMeanPower(day, srcmaxpump); double DPC - = meanPump * area.hydro.maxHoursPump[0][day]; + = meanPump * area.hydro.maxHourlyPumpEnergy[0][day]; double rc = area.hydro.reservoirCapacity; if (not area.hydro.hardBoundsOnRuleCurves) diff --git a/src/tests/src/libs/antares/study/parts/hydro/test-datatransfer-class.cpp b/src/tests/src/libs/antares/study/parts/hydro/test-datatransfer-class.cpp index 95f3e75c7e..e671120518 100644 --- a/src/tests/src/libs/antares/study/parts/hydro/test-datatransfer-class.cpp +++ b/src/tests/src/libs/antares/study/parts/hydro/test-datatransfer-class.cpp @@ -21,23 +21,23 @@ struct Fixture // Create necessary folders and files for these two areas createFoldersAndFiles(); - auto& gen = datatransfer->maxPower[DataTransfer::genMaxP]; + auto& gen = datatransfer->dailyMaxPumpAndGen[DataTransfer::genMaxP]; InstantiateColumn(gen, 300., DAYS_PER_YEAR); - auto& pump = datatransfer->maxPower[DataTransfer::pumpMaxP]; + auto& pump = datatransfer->dailyMaxPumpAndGen[DataTransfer::pumpMaxP]; InstantiateColumn(pump, 200., DAYS_PER_YEAR); - auto& hoursGen = datatransfer->maxPower[DataTransfer::genMaxE]; + auto& hoursGen = datatransfer->dailyMaxPumpAndGen[DataTransfer::genMaxE]; InstantiateColumn(hoursGen, 20., DAYS_PER_YEAR); - auto& hoursPump = datatransfer->maxPower[DataTransfer::pumpMaxE]; + auto& hoursPump = datatransfer->dailyMaxPumpAndGen[DataTransfer::pumpMaxE]; InstantiateColumn(hoursPump, 14., DAYS_PER_YEAR); my_string buffer; my_string file_name = "maxpower_" + area_2->id + ".txt"; buffer.clear() << base_folder << SEP << hydro_folder << SEP << common_folder << SEP << capacity_folder << SEP << file_name; - datatransfer->maxPower.saveToCSVFile(buffer, 2); + datatransfer->dailyMaxPumpAndGen.saveToCSVFile(buffer, 2); } void createFoldersAndFiles() @@ -88,8 +88,8 @@ struct Fixture my_string series_folder = "series"; my_string common_folder = "common"; my_string capacity_folder = "capacity"; - my_string maxhoursGen = "maxhoursGen_"; - my_string maxhoursPump = "maxhoursPump_"; + my_string maxhoursGen = "maxHourlyGenEnergy_"; + my_string maxhoursPump = "maxHourlyPumpEnergy_"; my_string maxpower = "maxpower_"; my_string maxgentxt = "maxgen.txt"; my_string maxpumptxt = "maxpump.txt"; @@ -126,7 +126,7 @@ BOOST_FIXTURE_TEST_CASE(Testing_load_from_folder_when_retuns_true, Fixture) { my_string buffer; bool ret = false; - datatransfer->maxPower.reset(4, DAYS_PER_YEAR, true); + datatransfer->dailyMaxPumpAndGen.reset(4, DAYS_PER_YEAR, true); buffer.clear() << base_folder << SEP << hydro_folder; ret = datatransfer->LoadFromFolder(*study, buffer, *area_2); @@ -138,14 +138,14 @@ BOOST_FIXTURE_TEST_CASE(Testing_load_from_folder_when_retuns_false, Fixture) my_string buffer; bool ret = false; - auto& hoursGen = datatransfer->maxPower[DataTransfer::genMaxE]; + auto& hoursGen = datatransfer->dailyMaxPumpAndGen[DataTransfer::genMaxE]; InstantiateColumn(hoursGen, 25., DAYS_PER_YEAR); my_string file_name = "maxpower_" + area_2->id + ".txt"; buffer.clear() << base_folder << SEP << hydro_folder << SEP << common_folder << SEP << capacity_folder << SEP << file_name; - datatransfer->maxPower.saveToCSVFile(buffer, 2); - datatransfer->maxPower.reset(4, DAYS_PER_YEAR, true); + datatransfer->dailyMaxPumpAndGen.saveToCSVFile(buffer, 2); + datatransfer->dailyMaxPumpAndGen.reset(4, DAYS_PER_YEAR, true); buffer.clear() << base_folder << SEP << hydro_folder; ret = datatransfer->LoadFromFolder(*study, buffer, *area_2); diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/area/hydromonthlypower.cpp b/src/ui/simulator/toolbox/components/datagrid/renderer/area/hydromonthlypower.cpp index fcfa7a9389..d9519fd94b 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/area/hydromonthlypower.cpp +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/area/hydromonthlypower.cpp @@ -102,9 +102,9 @@ void HydroMonthlyHours::internalAreaChanged(Antares::Data::Area* area) Data::PartHydro* pHydro = (area) ? &(area->hydro) : nullptr; Renderer::ARendererArea::internalAreaChanged(area); if (pHydro && hoursType == HoursType::Generation) - MatrixAncestorType::matrix(&pHydro->maxHoursGen); + MatrixAncestorType::matrix(&pHydro->maxHourlyGenEnergy); else if (pHydro && hoursType == HoursType::Pumping) - MatrixAncestorType::matrix(&pHydro->maxHoursPump); + MatrixAncestorType::matrix(&pHydro->maxHourlyPumpEnergy); else MatrixAncestorType::matrix(nullptr); } From b0e3d0b1f077d03812bda3706310d008f9f33245 Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Sat, 23 Sep 2023 18:33:29 +0200 Subject: [PATCH 06/40] Renaming matrices from DataSeriesHydro class --- src/libs/antares/study/area/list.cpp | 4 +- src/libs/antares/study/area/scratchpad.cpp | 8 +- .../antares/study/cleaner/cleaner-v20.cpp | 4 +- .../antares/study/parts/hydro/container.cpp | 294 +++++++++--------- .../study/parts/hydro/datatransfer.cpp | 20 +- src/libs/antares/study/parts/hydro/series.cpp | 68 ++-- src/libs/antares/study/parts/hydro/series.h | 10 +- src/solver/hydro/management/daily.cpp | 10 +- src/solver/hydro/management/management.cpp | 9 +- .../simulation/sim_calcul_economique.cpp | 36 +-- src/solver/simulation/timeseries-numbers.cpp | 2 +- src/solver/variable/economy/max-mrg.cpp | 4 +- .../parts/hydro/test-datatransfer-class.cpp | 6 +- .../study/parts/hydro/test-hydro-series.cpp | 92 +++--- .../handler/antares-study/area/timeseries.cpp | 8 +- .../datagrid/renderer/area/timeseries.h | 16 +- src/ui/simulator/windows/hydro/series.cpp | 4 +- 17 files changed, 290 insertions(+), 305 deletions(-) diff --git a/src/libs/antares/study/area/list.cpp b/src/libs/antares/study/area/list.cpp index 7ed6fd260a..7413f335e9 100644 --- a/src/libs/antares/study/area/list.cpp +++ b/src/libs/antares/study/area/list.cpp @@ -1639,8 +1639,8 @@ void AreaList::removeHydroTimeseries() area.hydro.series->ror.reset(1, HOURS_PER_YEAR); area.hydro.series->storage.reset(1, DAYS_PER_YEAR); area.hydro.series->mingen.reset(1, HOURS_PER_YEAR); - area.hydro.series->maxgen.reset(1, HOURS_PER_YEAR); - area.hydro.series->maxpump.reset(1, HOURS_PER_YEAR); + area.hydro.series->maxHourlyGenPower.reset(1, HOURS_PER_YEAR); + area.hydro.series->maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); area.hydro.series->count = 1; area.hydro.series->countpowercredits = 1; }); diff --git a/src/libs/antares/study/area/scratchpad.cpp b/src/libs/antares/study/area/scratchpad.cpp index 1b2a3a24e2..405dfd8d48 100644 --- a/src/libs/antares/study/area/scratchpad.cpp +++ b/src/libs/antares/study/area/scratchpad.cpp @@ -88,10 +88,10 @@ AreaScratchpad::AreaScratchpad(const StudyRuntimeInfos& rinfos, Area& area) : ts bool hydroGenerationPermission = false; // ... Getting hydro max power - auto const& maxPower = area.hydro.series->maxgen; + auto const& maxHourlyGenPower = area.hydro.series->maxHourlyGenPower; auto const& maxHourlyGenEnergy = area.hydro.maxHourlyGenEnergy[0]; - hydroGenerationPermission = CheckForPositiveEnergy(maxPower, maxHourlyGenEnergy); + hydroGenerationPermission = CheckForPositiveEnergy(maxHourlyGenPower, maxHourlyGenEnergy); // --------------------- // Hydro has inflows @@ -127,11 +127,11 @@ AreaScratchpad::AreaScratchpad(const StudyRuntimeInfos& rinfos, Area& area) : ts // ... Hydro max power // ... Hydro max pumping power and energy - auto const& maxPumpingP = area.hydro.series->maxpump; + auto const& maxHourlyPumpPower = area.hydro.series->maxHourlyPumpPower; auto const& maxHourlyPumpEnergy = area.hydro.maxHourlyPumpEnergy[0]; // If pumping energy is nil over the whole year, pumpHasMod is false, true otherwise. - pumpHasMod = CheckForPositiveEnergy(maxPumpingP, maxHourlyPumpEnergy); + pumpHasMod = CheckForPositiveEnergy(maxHourlyPumpPower, maxHourlyPumpEnergy); } AreaScratchpad::~AreaScratchpad() = default; diff --git a/src/libs/antares/study/cleaner/cleaner-v20.cpp b/src/libs/antares/study/cleaner/cleaner-v20.cpp index 87037e1c01..8d8b19331b 100644 --- a/src/libs/antares/study/cleaner/cleaner-v20.cpp +++ b/src/libs/antares/study/cleaner/cleaner-v20.cpp @@ -103,9 +103,9 @@ static void listOfFilesAnDirectoriesToKeepForArea(PathList& e, PathList& p, cons e.add(buffer); buffer.clear() << "input/hydro/series/" << id << "/mingen.txt"; e.add(buffer); - buffer.clear() << "input/hydro/series/" << id << "/maxHourlyGenEnergy.txt"; + buffer.clear() << "input/hydro/series/" << id << "/maxHourlyGenPower.txt"; e.add(buffer); - buffer.clear() << "input/hydro/series/" << id << "/maxHourlyPumpEnergy.txt"; + buffer.clear() << "input/hydro/series/" << id << "/maxHourlyPumpPower.txt"; e.add(buffer); buffer.clear() << "input/hydro/allocation/" << id << ".ini"; p.add(buffer); diff --git a/src/libs/antares/study/parts/hydro/container.cpp b/src/libs/antares/study/parts/hydro/container.cpp index 297a1e944f..6ba3c018c0 100644 --- a/src/libs/antares/study/parts/hydro/container.cpp +++ b/src/libs/antares/study/parts/hydro/container.cpp @@ -116,161 +116,145 @@ bool PartHydro::LoadFromFolder(Study& study, const AnyString& folder) bool ret = true; // Initialize all alpha values to 0 - study.areas.each([&](Data::Area& area) { - area.hydro.interDailyBreakdown = 1.; - area.hydro.intraDailyModulation = 24.; - area.hydro.intermonthlyBreakdown = 1.; - area.hydro.reservoirManagement = false; - area.hydro.followLoadModulations = true; - area.hydro.useWaterValue = false; - area.hydro.hardBoundsOnRuleCurves = false; - area.hydro.useHeuristicTarget = true; - area.hydro.useLeeway = false; - area.hydro.powerToLevel = false; - area.hydro.leewayLowerBound = 1.; - area.hydro.leewayUpperBound = 1.; - area.hydro.initializeReservoirLevelDate = 0; - area.hydro.reservoirCapacity = 0.; - area.hydro.pumpingEfficiency = 1.; - - if (study.header.version >= 870) - { - // GUI part patch : - // We need to know, when estimating the RAM required by the solver, if the current area - // is hydro modulable. Therefore, reading the area's daily max power at this stage is - // necessary. - - if (!study.usedByTheSolver) - { - bool enabledModeIsChanged = false; - if (JIT::enabled) - { - JIT::enabled = false; // Allowing to read the area's daily max power - enabledModeIsChanged = true; - } - - ret = area.hydro.LoadHours(study, area, folder); - - if (enabledModeIsChanged) - JIT::enabled = true; // Back to the previous loading mode. - } - else - { - ret = area.hydro.LoadHours(study, area, folder); - } - } - - if (study.header.version < 870) - { - std::shared_ptr datatransfer = std::make_shared(); - - ret = datatransfer->LoadFromFolder(study, folder, area); - ret = datatransfer->AutoTransferHours(study, folder, area); - } - - buffer.clear() << folder << SEP << "common" << SEP << "capacity" << SEP - << "creditmodulations_" << area.id << '.' << study.inputExtension; - ret = area.hydro.creditModulation.loadFromCSVFile( - buffer, 101, 2, Matrix<>::optFixedSize, &study.dataBuffer) - && ret; - - buffer.clear() << folder << SEP << "common" << SEP << "capacity" << SEP << "reservoir_" - << area.id << '.' << study.inputExtension; - ret = area.hydro.reservoirLevel.loadFromCSVFile( - buffer, 3, DAYS_PER_YEAR, Matrix<>::optFixedSize, &study.dataBuffer) - && ret; - - - buffer.clear() << folder << SEP << "common" << SEP << "capacity" << SEP - << "waterValues_" << area.id << '.' << study.inputExtension; - ret = area.hydro.waterValues.loadFromCSVFile( - buffer, 101, DAYS_PER_YEAR, Matrix<>::optFixedSize, &study.dataBuffer) - && ret; - - buffer.clear() << folder << SEP << "common" << SEP << "capacity" << SEP - << "inflowPattern_" << area.id << '.' << study.inputExtension; - ret = area.hydro.inflowPattern.loadFromCSVFile( - buffer, 1, DAYS_PER_YEAR, Matrix<>::optFixedSize, &study.dataBuffer) - && ret; - - if (study.usedByTheSolver) - { - auto& col = area.hydro.inflowPattern[0]; - bool errorInflow = false; - for (int day = 0; day < DAYS_PER_YEAR; day++) - { - if (col[day] < 0 && !errorInflow) - { - logs.error() << area.name << ": invalid inflow value"; - errorInflow = true; - ret = false; - } - } - bool errorLevels = false; - auto& colMin = area.hydro.reservoirLevel[minimum]; - auto& colAvg = area.hydro.reservoirLevel[average]; - auto& colMax = area.hydro.reservoirLevel[maximum]; - for (int day = 0; day < DAYS_PER_YEAR; day++) - { - if (!errorLevels - && (colMin[day] < 0 || colAvg[day] < 0 || colMin[day] > colMax[day] - || colAvg[day] > 100 || colMax[day] > 100)) - { - logs.error() << area.name << ": invalid reservoir level value"; - errorLevels = true; - ret = false; - } - } - - bool errorHours = false; - auto& colGen = area.hydro.maxHourlyGenEnergy[0]; - auto& colPump = area.hydro.maxHourlyPumpEnergy[0]; - - for (int day = 0; day < DAYS_PER_YEAR; day++) - { - if (!errorHours && (colGen[day] < 0 || (colGen[day] > 24))) - { - logs.error() << area.name << ": invalid power or energy value"; - errorHours = true; - ret = false; - } - - if (!errorHours && (colPump[day] < 0 || (colPump[day] > 24))) - { - logs.error() << area.name << ": invalid power or energy value"; - errorHours = true; - ret = false; - } - } - - for (int i = 0; i < 101; i++) - { - if ((area.hydro.creditModulation[i][0] < 0) - || (area.hydro.creditModulation[i][1] < 0)) - { - logs.error() << area.name << ": invalid credit modulation value"; - ret = false; - } - } - } - else - { - /* - Maxgen matrix is not initialized at this moment, so this code will induce - Segmentation fault (core dumped) because maxgen matrix pointing to invalid memory - address. This code block is moved to series.cpp file for hydro. - - Is area hydro modulable ? - - auto& max = area.hydro.series->maxgen; - - if (MatrixTestForAtLeastOnePositiveValue(max)) - { - area.hydro.hydroModulable = true; - } - */ - } - }); + study.areas.each( + [&](Data::Area& area) + { + area.hydro.interDailyBreakdown = 1.; + area.hydro.intraDailyModulation = 24.; + area.hydro.intermonthlyBreakdown = 1.; + area.hydro.reservoirManagement = false; + area.hydro.followLoadModulations = true; + area.hydro.useWaterValue = false; + area.hydro.hardBoundsOnRuleCurves = false; + area.hydro.useHeuristicTarget = true; + area.hydro.useLeeway = false; + area.hydro.powerToLevel = false; + area.hydro.leewayLowerBound = 1.; + area.hydro.leewayUpperBound = 1.; + area.hydro.initializeReservoirLevelDate = 0; + area.hydro.reservoirCapacity = 0.; + area.hydro.pumpingEfficiency = 1.; + + if (study.header.version >= 870) + { + // GUI part patch : + // We need to know, when estimating the RAM required by the solver, if the current + // area is hydro modulable. Therefore, reading the area's daily max power at this + // stage is necessary. + + if (!study.usedByTheSolver) + { + bool enabledModeIsChanged = false; + if (JIT::enabled) + { + JIT::enabled = false; // Allowing to read the area's daily max power + enabledModeIsChanged = true; + } + + ret = area.hydro.LoadHours(study, area, folder); + + if (enabledModeIsChanged) + JIT::enabled = true; // Back to the previous loading mode. + } + else + { + ret = area.hydro.LoadHours(study, area, folder); + } + } + + if (study.header.version < 870) + { + std::shared_ptr datatransfer = std::make_shared(); + + ret = datatransfer->LoadFromFolder(study, folder, area); + ret = datatransfer->AutoTransferHours(study, folder, area); + } + + buffer.clear() << folder << SEP << "common" << SEP << "capacity" << SEP + << "creditmodulations_" << area.id << '.' << study.inputExtension; + ret = area.hydro.creditModulation.loadFromCSVFile( + buffer, 101, 2, Matrix<>::optFixedSize, &study.dataBuffer) + && ret; + + buffer.clear() << folder << SEP << "common" << SEP << "capacity" << SEP << "reservoir_" + << area.id << '.' << study.inputExtension; + ret = area.hydro.reservoirLevel.loadFromCSVFile( + buffer, 3, DAYS_PER_YEAR, Matrix<>::optFixedSize, &study.dataBuffer) + && ret; + + buffer.clear() << folder << SEP << "common" << SEP << "capacity" << SEP << "waterValues_" + << area.id << '.' << study.inputExtension; + ret = area.hydro.waterValues.loadFromCSVFile( + buffer, 101, DAYS_PER_YEAR, Matrix<>::optFixedSize, &study.dataBuffer) + && ret; + + buffer.clear() << folder << SEP << "common" << SEP << "capacity" << SEP + << "inflowPattern_" << area.id << '.' << study.inputExtension; + ret = area.hydro.inflowPattern.loadFromCSVFile( + buffer, 1, DAYS_PER_YEAR, Matrix<>::optFixedSize, &study.dataBuffer) + && ret; + + if (study.usedByTheSolver) + { + auto& col = area.hydro.inflowPattern[0]; + bool errorInflow = false; + for (int day = 0; day < DAYS_PER_YEAR; day++) + { + if (col[day] < 0 && !errorInflow) + { + logs.error() << area.name << ": invalid inflow value"; + errorInflow = true; + ret = false; + } + } + bool errorLevels = false; + auto& colMin = area.hydro.reservoirLevel[minimum]; + auto& colAvg = area.hydro.reservoirLevel[average]; + auto& colMax = area.hydro.reservoirLevel[maximum]; + for (int day = 0; day < DAYS_PER_YEAR; day++) + { + if (!errorLevels + && (colMin[day] < 0 || colAvg[day] < 0 || colMin[day] > colMax[day] + || colAvg[day] > 100 || colMax[day] > 100)) + { + logs.error() << area.name << ": invalid reservoir level value"; + errorLevels = true; + ret = false; + } + } + + bool errorHours = false; + auto& colGen = area.hydro.maxHourlyGenEnergy[0]; + auto& colPump = area.hydro.maxHourlyPumpEnergy[0]; + + for (int day = 0; day < DAYS_PER_YEAR; day++) + { + if (!errorHours && (colGen[day] < 0 || (colGen[day] > 24))) + { + logs.error() << area.name << ": invalid power or energy value"; + errorHours = true; + ret = false; + } + + if (!errorHours && (colPump[day] < 0 || (colPump[day] > 24))) + { + logs.error() << area.name << ": invalid power or energy value"; + errorHours = true; + ret = false; + } + } + + for (int i = 0; i < 101; i++) + { + if ((area.hydro.creditModulation[i][0] < 0) + || (area.hydro.creditModulation[i][1] < 0)) + { + logs.error() << area.name << ": invalid credit modulation value"; + ret = false; + } + } + } + }); IniFile ini; if (not ini.open(buffer.clear() << folder << SEP << "hydro.ini")) diff --git a/src/libs/antares/study/parts/hydro/datatransfer.cpp b/src/libs/antares/study/parts/hydro/datatransfer.cpp index 8a4ca36ad0..2f3ec916c5 100644 --- a/src/libs/antares/study/parts/hydro/datatransfer.cpp +++ b/src/libs/antares/study/parts/hydro/datatransfer.cpp @@ -130,23 +130,23 @@ bool DataTransfer::SupportForOldStudies(Study& study, const AnyString& folder, A { bool ret = true; auto& buffer = study.bufferLoadingTS; - auto& maxgen = area.hydro.series->maxgen; - auto& maxpump = area.hydro.series->maxpump; + auto& maxHourlyGenPower = area.hydro.series->maxHourlyGenPower; + auto& maxHourlyPumpPower = area.hydro.series->maxHourlyPumpPower; auto& dailyMaxGen = dailyMaxPumpAndGen[genMaxP]; auto& dailyMaxPump = dailyMaxPumpAndGen[pumpMaxP]; - maxgen.reset(1, HOURS_PER_YEAR); - maxpump.reset(1, HOURS_PER_YEAR); + maxHourlyGenPower.reset(1, HOURS_PER_YEAR); + maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); - AutoTransferPower(maxgen, dailyMaxGen); - AutoTransferPower(maxpump, dailyMaxPump); + AutoTransferPower(maxHourlyGenPower, dailyMaxGen); + AutoTransferPower(maxHourlyPumpPower, dailyMaxPump); - buffer.clear() << folder << SEP << "series" << SEP << area.id << SEP << "maxgen." << study.inputExtension; - ret = maxgen.saveToCSVFile(buffer, 1, HOURS_PER_YEAR, &study.dataBuffer) && ret; + buffer.clear() << folder << SEP << "series" << SEP << area.id << SEP << "maxHourlyGenPower." << study.inputExtension; + ret = maxHourlyGenPower.saveToCSVFile(buffer, 1, HOURS_PER_YEAR, &study.dataBuffer) && ret; - buffer.clear() << folder << SEP << "series" << SEP << area.id << SEP << "maxpump." << study.inputExtension; - ret = maxpump.saveToCSVFile(buffer, 1, HOURS_PER_YEAR, &study.dataBuffer) && ret; + buffer.clear() << folder << SEP << "series" << SEP << area.id << SEP << "maxHourlyPumpPower." << study.inputExtension; + ret = maxHourlyPumpPower.saveToCSVFile(buffer, 1, HOURS_PER_YEAR, &study.dataBuffer) && ret; return ret; } diff --git a/src/libs/antares/study/parts/hydro/series.cpp b/src/libs/antares/study/parts/hydro/series.cpp index c58d88258c..65d0bf995b 100644 --- a/src/libs/antares/study/parts/hydro/series.cpp +++ b/src/libs/antares/study/parts/hydro/series.cpp @@ -45,11 +45,11 @@ DataSeriesHydro::DataSeriesHydro() : count(0) { // Pmin was introduced in v8.6 // The previous behavior was Pmin=0 - // For compatibility reasons with existing studies, mingen, maxgen and maxpump are set to one + // For compatibility reasons with existing studies, mingen, maxHourlyGenPower and maxHourlyPumpPower are set to one // column of zeros by default mingen.reset(1, HOURS_PER_YEAR); - maxgen.reset(1, HOURS_PER_YEAR); - maxpump.reset(1, HOURS_PER_YEAR); + maxHourlyGenPower.reset(1, HOURS_PER_YEAR); + maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); } bool DataSeriesHydro::saveToFolder(const AreaName& areaID, const AnyString& folder) const @@ -68,10 +68,10 @@ bool DataSeriesHydro::saveToFolder(const AreaName& areaID, const AnyString& fold ret = storage.saveToCSVFile(buffer, 0) && ret; buffer.clear() << folder << SEP << areaID << SEP << "mingen.txt"; ret = mingen.saveToCSVFile(buffer, 0) && ret; - buffer.clear() << folder << SEP << areaID << SEP << "maxgen.txt"; - ret = maxgen.saveToCSVFile(buffer, 0) && ret; - buffer.clear() << folder << SEP << areaID << SEP << "maxpump.txt"; - ret = maxpump.saveToCSVFile(buffer, 0) && ret; + buffer.clear() << folder << SEP << areaID << SEP << "maxHourlyGenPower.txt"; + ret = maxHourlyGenPower.saveToCSVFile(buffer, 0) && ret; + buffer.clear() << folder << SEP << areaID << SEP << "maxHourlyPumpPower.txt"; + ret = maxHourlyPumpPower.saveToCSVFile(buffer, 0) && ret; return ret; } return false; @@ -206,16 +206,16 @@ bool DataSeriesHydro::LoadMaxPower(Study& study, const AreaName& areaID, const A if (study.header.version >= 870) { - buffer.clear() << folder << SEP << areaID << SEP << "maxgen." << study.inputExtension; - ret = maxgen.loadFromCSVFile(buffer, 1, HOURS_PER_YEAR, &study.dataBuffer) && ret; - buffer.clear() << folder << SEP << areaID << SEP << "maxpump." << study.inputExtension; - ret = maxpump.loadFromCSVFile(buffer, 1, HOURS_PER_YEAR, &study.dataBuffer) && ret; + buffer.clear() << folder << SEP << areaID << SEP << "maxHourlyGenPower." << study.inputExtension; + ret = maxHourlyGenPower.loadFromCSVFile(buffer, 1, HOURS_PER_YEAR, &study.dataBuffer) && ret; + buffer.clear() << folder << SEP << areaID << SEP << "maxHourlyPumpPower." << study.inputExtension; + ret = maxHourlyPumpPower.loadFromCSVFile(buffer, 1, HOURS_PER_YEAR, &study.dataBuffer) && ret; } - countpowercredits = maxgen.width; + countpowercredits = maxHourlyGenPower.width; - if (maxpump.width > countpowercredits) - countpowercredits = maxpump.width; + if (maxHourlyPumpPower.width > countpowercredits) + countpowercredits = maxHourlyPumpPower.width; if (study.usedByTheSolver) { @@ -224,14 +224,14 @@ bool DataSeriesHydro::LoadMaxPower(Study& study, const AreaName& areaID, const A logs.error() << "Hydro Max Power: `" << areaID << "`: empty matrix detected. Fixing it with default values"; - maxgen.reset(1, HOURS_PER_YEAR); - maxpump.reset(1, HOURS_PER_YEAR); + maxHourlyGenPower.reset(1, HOURS_PER_YEAR); + maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); } else { - if (countpowercredits > 1 && maxgen.width != maxpump.width) + if (countpowercredits > 1 && maxHourlyGenPower.width != maxHourlyPumpPower.width) { - if (maxpump.width != 1 && maxgen.width != 1) + if (maxHourlyPumpPower.width != 1 && maxHourlyGenPower.width != 1) { logs.fatal() << "Hydro Max Power: `" << areaID << "`: The matrices Maximum Generation and Maximum Pumping must " @@ -240,19 +240,19 @@ bool DataSeriesHydro::LoadMaxPower(Study& study, const AreaName& areaID, const A } else { - if (maxpump.width == 1) + if (maxHourlyPumpPower.width == 1) { - maxpump.resizeWithoutDataLost(countpowercredits, maxpump.height); + maxHourlyPumpPower.resizeWithoutDataLost(countpowercredits, maxHourlyPumpPower.height); for (uint x = 1; x < countpowercredits; ++x) - maxpump.pasteToColumn(x, maxpump[0]); + maxHourlyPumpPower.pasteToColumn(x, maxHourlyPumpPower[0]); } else { - if (maxgen.width == 1) + if (maxHourlyGenPower.width == 1) { - maxgen.resizeWithoutDataLost(countpowercredits, maxgen.height); + maxHourlyGenPower.resizeWithoutDataLost(countpowercredits, maxHourlyGenPower.height); for (uint x = 1; x < countpowercredits; ++x) - maxgen.pasteToColumn(x, maxgen[0]); + maxHourlyGenPower.pasteToColumn(x, maxHourlyGenPower[0]); } } Area* areaToInvalidate = study.areas.find(areaID); @@ -272,8 +272,8 @@ bool DataSeriesHydro::LoadMaxPower(Study& study, const AreaName& areaID, const A if (study.parameters.derated) { - maxgen.averageTimeseries(); - maxpump.averageTimeseries(); + maxHourlyGenPower.averageTimeseries(); + maxHourlyPumpPower.averageTimeseries(); countpowercredits = 1; } } @@ -282,7 +282,7 @@ bool DataSeriesHydro::LoadMaxPower(Study& study, const AreaName& areaID, const A // Is area hydro modulable ? Area* area = study.areas.find(areaID); - if (MatrixTestForAtLeastOnePositiveValue(maxgen)) + if (MatrixTestForAtLeastOnePositiveValue(maxHourlyGenPower)) { area->hydro.hydroModulable = true; } @@ -299,8 +299,8 @@ bool DataSeriesHydro::forceReload(bool reload) const ret = ror.forceReload(reload) && ret; ret = storage.forceReload(reload) && ret; ret = mingen.forceReload(reload) && ret; - ret = maxgen.forceReload(reload) && ret; - ret = maxpump.forceReload(reload) && ret; + ret = maxHourlyGenPower.forceReload(reload) && ret; + ret = maxHourlyPumpPower.forceReload(reload) && ret; return ret; } @@ -309,8 +309,8 @@ void DataSeriesHydro::markAsModified() const ror.markAsModified(); storage.markAsModified(); mingen.markAsModified(); - maxgen.markAsModified(); - maxpump.markAsModified(); + maxHourlyGenPower.markAsModified(); + maxHourlyPumpPower.markAsModified(); } void DataSeriesHydro::reset() @@ -318,8 +318,8 @@ void DataSeriesHydro::reset() ror.reset(1, HOURS_PER_YEAR); storage.reset(1, DAYS_PER_YEAR); mingen.reset(1, HOURS_PER_YEAR); - maxgen.reset(1, HOURS_PER_YEAR); - maxpump.reset(1, HOURS_PER_YEAR); + maxHourlyGenPower.reset(1, HOURS_PER_YEAR); + maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); count = 1; countpowercredits = 1; } @@ -327,7 +327,7 @@ void DataSeriesHydro::reset() uint64_t DataSeriesHydro::memoryUsage() const { return sizeof(double) + ror.memoryUsage() + storage.memoryUsage() + mingen.memoryUsage() - + maxgen.memoryUsage() + maxpump.memoryUsage(); + + maxHourlyGenPower.memoryUsage() + maxHourlyPumpPower.memoryUsage(); } } // namespace Data } // namespace Antares diff --git a/src/libs/antares/study/parts/hydro/series.h b/src/libs/antares/study/parts/hydro/series.h index 7eed031371..944c9495a6 100644 --- a/src/libs/antares/study/parts/hydro/series.h +++ b/src/libs/antares/study/parts/hydro/series.h @@ -134,14 +134,14 @@ class DataSeriesHydro ** ** Merely a matrix of TimeSeriesCount * HOURS_PER_YEAR values */ - Matrix maxgen; + Matrix maxHourlyGenPower; /*! ** \brief Maximum Pumping (MW) ** ** Merely a matrix of TimeSeriesCount * HOURS_PER_YEAR values */ - Matrix maxpump; + Matrix maxHourlyPumpPower; /*! ** \brief The number of time-series @@ -154,11 +154,11 @@ class DataSeriesHydro uint count; /*! - ** \brief The number of time-series for maxgen and maxpump matrices + ** \brief The number of time-series for maxHourlyGenPower and maxHourlyPumpPower matrices ** - ** This value must be the same as the width of the matrices `maxgen` and `maxpump`. + ** This value must be the same as the width of the matrices `maxHourlyGenPower` and `maxHourlyPumpPower`. ** It is only provided for convenience to avoid same strange and ambiguous code - ** (for example using `maxgen.width` and `maxpump.width` in the same routine, it might + ** (for example using `maxHourlyGenPower.width` and `maxHourlyPumpPower.width` in the same routine, it might ** indicate that the two values are not strictly equal) */ uint countpowercredits = 0; diff --git a/src/solver/hydro/management/daily.cpp b/src/solver/hydro/management/daily.cpp index 5e6fc31155..7fd8f9fc8d 100644 --- a/src/solver/hydro/management/daily.cpp +++ b/src/solver/hydro/management/daily.cpp @@ -250,14 +250,14 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St uint dayYear = 0; - auto const& maxPowerHours = area.hydro.maxHourlyGenEnergy; - auto const& maxPower = area.hydro.series->maxgen; + auto const& maxHourlyGenEnergy = area.hydro.maxHourlyGenEnergy; + auto const& maxHourlyGenPower = area.hydro.series->maxHourlyGenPower; uint tsIndexMaxPower = (NumeroChroniquesTireesParPays[numSpace][z]).HydrauliqueMaxPower; - auto const& maxP = maxPower[tsIndexMaxPower < maxPower.width ? tsIndexMaxPower : 0]; - auto const& maxE = maxPowerHours[0]; + auto const& maxP = maxHourlyGenPower[tsIndexMaxPower < maxHourlyGenPower.width ? tsIndexMaxPower : 0]; + auto const& maxE = maxHourlyGenEnergy[0]; auto& ventilationResults = ventilationResults_[numSpace][z]; @@ -281,7 +281,7 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St auto daysPerMonth = calendar_.months[month].days; assert(daysPerMonth <= maxOPP); assert(daysPerMonth <= maxDailyTargetGen); - assert(daysPerMonth + dayYear - 1 < maxPower.height); + assert(daysPerMonth + dayYear - 1 < maxHourlyGenPower.height); for (uint day = 0; day != daysPerMonth; ++day) { diff --git a/src/solver/hydro/management/management.cpp b/src/solver/hydro/management/management.cpp index 157fbe888b..8d4f1d9dcb 100644 --- a/src/solver/hydro/management/management.cpp +++ b/src/solver/hydro/management/management.cpp @@ -313,13 +313,14 @@ bool HydroManagement::checkHourlyMinMaxGeneration(uint tsIndex, // Hourly minimum generation <= hourly inflows for each hour auto& mingenmatrix = area.hydro.series->mingen; auto const& srcmingen = mingenmatrix[tsIndex < mingenmatrix.width ? tsIndex : 0]; - auto& maxgenmatrix = area.hydro.series->maxgen; - auto const& srcmaxgen - = maxgenmatrix[tsIndexMaxPower < maxgenmatrix.width ? tsIndexMaxPower : 0]; + auto& maxHourlyGenPowerMatrix = area.hydro.series->maxHourlyGenPower; + auto const& srcMaxHourlyGenPower + = maxHourlyGenPowerMatrix[tsIndexMaxPower < maxHourlyGenPowerMatrix.width ? tsIndexMaxPower + : 0]; for (uint h = 0; h < HOURS_PER_YEAR; ++h) { - const auto& max = srcmaxgen[h]; + const auto& max = srcMaxHourlyGenPower[h]; const auto& min = srcmingen[h]; if (max < min) diff --git a/src/solver/simulation/sim_calcul_economique.cpp b/src/solver/simulation/sim_calcul_economique.cpp index b52e0ac5ea..87a0d2fbb6 100644 --- a/src/solver/simulation/sim_calcul_economique.cpp +++ b/src/solver/simulation/sim_calcul_economique.cpp @@ -569,16 +569,16 @@ void SIM_RenseignementProblemeHebdo(const Study& study, auto& scratchpad = area.scratchpad[numSpace]; auto& ror = area.hydro.series->ror; - auto& maxgenmatrix = area.hydro.series->maxgen; - auto const& srcmaxgen - = maxgenmatrix[tsIndexMaxPower < maxgenmatrix.width ? tsIndexMaxPower : 0]; - auto const& ContrainteDePmaxHydrauliqueHoraire = srcmaxgen[PasDeTempsDebut + hourInWeek]; - - auto& maxpumpmatrix = area.hydro.series->maxpump; - auto const& srcmaxpump - = maxpumpmatrix[tsIndexMaxPower < maxpumpmatrix.width ? tsIndexMaxPower + auto& maxHourlyGenPowerMatrix = area.hydro.series->maxHourlyGenPower; + auto const& srcMaxHourlyGenPower + = maxHourlyGenPowerMatrix[tsIndexMaxPower < maxHourlyGenPowerMatrix.width ? tsIndexMaxPower : 0]; + auto const& ContrainteDePmaxHydrauliqueHoraire = srcMaxHourlyGenPower[PasDeTempsDebut + hourInWeek]; + + auto& maxHourlyPumpPowerMatrix = area.hydro.series->maxHourlyPumpPower; + auto const& srcMaxHourlyPumpPower + = maxHourlyPumpPowerMatrix[tsIndexMaxPower < maxHourlyPumpPowerMatrix.width ? tsIndexMaxPower : 0]; - auto const& ContrainteDePmaxPompageHoraire = srcmaxpump[PasDeTempsDebut + hourInWeek]; + auto const& ContrainteDePmaxPompageHoraire = srcMaxHourlyPumpPower[PasDeTempsDebut + hourInWeek]; assert(&scratchpad); assert((uint)hourInYear < scratchpad.ts.load.height); @@ -653,10 +653,10 @@ void SIM_RenseignementProblemeHebdo(const Study& study, auto& inflowsmatrix = area.hydro.series->storage; auto const& srcinflows = inflowsmatrix[tsIndex < inflowsmatrix.width ? tsIndex : 0]; uint tsIndexMaxPower = (NumeroChroniquesTireesParPays[numSpace][k]).HydrauliqueMaxPower; - auto& maxgenmatrix = area.hydro.series->maxgen; - auto const& srcmaxgen = maxgenmatrix[tsIndexMaxPower < maxgenmatrix.width ? tsIndexMaxPower : 0]; - auto& maxpumpmatrix = area.hydro.series->maxpump; - auto const& srcmaxpump = maxpumpmatrix[tsIndexMaxPower < maxpumpmatrix.width ? tsIndexMaxPower : 0]; + auto& maxHourlyGenPowerMatrix = area.hydro.series->maxHourlyGenPower; + auto const& srcMaxHourlyGenPower = maxHourlyGenPowerMatrix[tsIndexMaxPower < maxHourlyGenPowerMatrix.width ? tsIndexMaxPower : 0]; + auto& maxHourlyPumpPowerMatrix = area.hydro.series->maxHourlyPumpPower; + auto const& srcMaxHourlyPumpPower = maxHourlyPumpPowerMatrix[tsIndexMaxPower < maxHourlyPumpPowerMatrix.width ? tsIndexMaxPower : 0]; auto& mingenmatrix = area.hydro.series->mingen; auto const& srcmingen = mingenmatrix[tsIndex < mingenmatrix.width ? tsIndex : 0]; for (uint j = 0; j < problem.NombreDePasDeTemps; ++j) @@ -674,7 +674,7 @@ void SIM_RenseignementProblemeHebdo(const Study& study, for (uint j = 0; j < 7; ++j) { uint day = study.calendar.hours[PasDeTempsDebut + j * 24].dayYear; - auto meanPower = CalculateDailyMeanPower(day, srcmaxgen); + auto meanPower = CalculateDailyMeanPower(day, srcMaxHourlyGenPower); problem.CaracteristiquesHydrauliques[k] .MinEnergieHydrauParIntervalleOptimise[j] @@ -730,7 +730,7 @@ void SIM_RenseignementProblemeHebdo(const Study& study, for (uint j = 0; j < 7; ++j) { uint day = study.calendar.hours[PasDeTempsDebut + j * 24].dayYear; - auto meanPower = CalculateDailyMeanPower(day, srcmaxgen); + auto meanPower = CalculateDailyMeanPower(day, srcMaxHourlyGenPower); double DGC = meanPower * area.hydro.maxHourlyGenEnergy[0][day]; @@ -837,7 +837,7 @@ void SIM_RenseignementProblemeHebdo(const Study& study, for (uint j = 0; j < 7; ++j) { uint day = study.calendar.hours[PasDeTempsDebut + j * 24].dayYear; - auto meanPump = CalculateDailyMeanPower(day, srcmaxpump); + auto meanPump = CalculateDailyMeanPower(day, srcMaxHourlyPumpPower); problem.CaracteristiquesHydrauliques[k] .MaxEnergiePompageParIntervalleOptimise[j] @@ -872,7 +872,7 @@ void SIM_RenseignementProblemeHebdo(const Study& study, for (uint j = 0; j < 7; ++j) { uint day = study.calendar.hours[PasDeTempsDebut + j * 24].dayYear; - auto meanPump = CalculateDailyMeanPower(day, srcmaxpump); + auto meanPump = CalculateDailyMeanPower(day, srcMaxHourlyPumpPower); double DPC = meanPump * area.hydro.maxHourlyPumpEnergy[0][day]; @@ -885,7 +885,7 @@ void SIM_RenseignementProblemeHebdo(const Study& study, for (uint j = 0; j < 7; ++j) { uint day = study.calendar.hours[PasDeTempsDebut + j * 24].dayYear; - auto meanPump = CalculateDailyMeanPower(day, srcmaxpump); + auto meanPump = CalculateDailyMeanPower(day, srcMaxHourlyPumpPower); double DPC = meanPump * area.hydro.maxHourlyPumpEnergy[0][day]; double rc = area.hydro.reservoirCapacity; diff --git a/src/solver/simulation/timeseries-numbers.cpp b/src/solver/simulation/timeseries-numbers.cpp index 5cc204e99a..3a965a18d8 100644 --- a/src/solver/simulation/timeseries-numbers.cpp +++ b/src/solver/simulation/timeseries-numbers.cpp @@ -688,7 +688,7 @@ void drawAndStoreTSnumbersForNOTintraModal(const array& i if (!isTSintramodal[indexTS]) { - uint nbTimeSeries = area.hydro.series->maxgen.width; + uint nbTimeSeries = area.hydro.series->maxHourlyGenPower.width; if (nbTimeSeries != 1) { area.hydro.series->timeseriesNumbersHydroMaxPower[0][year] = static_cast( diff --git a/src/solver/variable/economy/max-mrg.cpp b/src/solver/variable/economy/max-mrg.cpp index 2101d4f541..ca9eee4424 100644 --- a/src/solver/variable/economy/max-mrg.cpp +++ b/src/solver/variable/economy/max-mrg.cpp @@ -134,8 +134,8 @@ inline void PrepareMaxMRGFor(const State& state, double* opmrg, uint numSpace) // Pmax uint tsIndex = (NumeroChroniquesTireesParPays[numSpace][index]).HydrauliqueMaxPower; - auto& maxgenmatrix = area.hydro.series->maxgen; - const auto& P = maxgenmatrix[tsIndex < maxgenmatrix.width ? tsIndex : 0]; + auto& maxHourlyGenPowerMatrix = area.hydro.series->maxHourlyGenPower; + const auto& P = maxHourlyGenPowerMatrix[tsIndex < maxHourlyGenPowerMatrix.width ? tsIndex : 0]; do { diff --git a/src/tests/src/libs/antares/study/parts/hydro/test-datatransfer-class.cpp b/src/tests/src/libs/antares/study/parts/hydro/test-datatransfer-class.cpp index e671120518..975de6292b 100644 --- a/src/tests/src/libs/antares/study/parts/hydro/test-datatransfer-class.cpp +++ b/src/tests/src/libs/antares/study/parts/hydro/test-datatransfer-class.cpp @@ -57,7 +57,7 @@ struct Fixture createFolder(buffer, area1_folder); buffer.clear() << base_folder << SEP << hydro_folder << SEP << series_folder << SEP << area1_folder; - // maxgen and maxpump files + // maxHourlyGenPower and maxHourlyPumpPower files createFile(buffer, maxgentxt); createFile(buffer, maxpumptxt); @@ -91,8 +91,8 @@ struct Fixture my_string maxhoursGen = "maxHourlyGenEnergy_"; my_string maxhoursPump = "maxHourlyPumpEnergy_"; my_string maxpower = "maxpower_"; - my_string maxgentxt = "maxgen.txt"; - my_string maxpumptxt = "maxpump.txt"; + my_string maxgentxt = "maxHourlyGenPower.txt"; + my_string maxpumptxt = "maxHourlyPumpPower.txt"; ~Fixture() { diff --git a/src/tests/src/libs/antares/study/parts/hydro/test-hydro-series.cpp b/src/tests/src/libs/antares/study/parts/hydro/test-hydro-series.cpp index b27a029481..3a838fefc1 100644 --- a/src/tests/src/libs/antares/study/parts/hydro/test-hydro-series.cpp +++ b/src/tests/src/libs/antares/study/parts/hydro/test-hydro-series.cpp @@ -46,12 +46,12 @@ struct Fixture createFolder(buffer, area1_folder); createFolder(buffer, area_No_Solver_folder); - // maxgen and maxpump files + // maxHourlyGenPower and maxHourlyPumpPower files buffer.clear() << base_folder << SEP << series_folder << SEP << area1_folder; createFile(buffer, maxgentxt); createFile(buffer, maxpumptxt); - // maxgen and maxpump files + // maxHourlyGenPower and maxHourlyPumpPower files buffer.clear() << base_folder << SEP << series_folder << SEP << area_No_Solver_folder; createFile(buffer, maxgentxt); createFile(buffer, maxpumptxt); @@ -63,8 +63,8 @@ struct Fixture Area* area_No_Solver; my_string base_folder = fs::current_path().string(); my_string series_folder = "series"; - my_string maxgentxt = "maxgen.txt"; - my_string maxpumptxt = "maxpump.txt"; + my_string maxgentxt = "maxHourlyGenPower.txt"; + my_string maxpumptxt = "maxHourlyPumpPower.txt"; ~Fixture() { @@ -77,22 +77,22 @@ BOOST_AUTO_TEST_SUITE(s) BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_both_matrix_equal_width, Fixture) { bool ret = false; - auto& maxgen = area_1->hydro.series->maxgen; - auto& maxpump = area_1->hydro.series->maxpump; - maxgen.reset(3, HOURS_PER_YEAR); - maxpump.reset(3, HOURS_PER_YEAR); + auto& maxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower; + auto& maxHourlyPumpPower = area_1->hydro.series->maxHourlyPumpPower; + maxHourlyGenPower.reset(3, HOURS_PER_YEAR); + maxHourlyPumpPower.reset(3, HOURS_PER_YEAR); - InstantiateMatrix(maxgen, 400., HOURS_PER_YEAR); - InstantiateMatrix(maxpump, 200., HOURS_PER_YEAR); + InstantiateMatrix(maxHourlyGenPower, 400., HOURS_PER_YEAR); + InstantiateMatrix(maxHourlyPumpPower, 200., HOURS_PER_YEAR); my_string buffer; buffer.clear() << base_folder << SEP << series_folder << SEP << area_1->id << SEP << maxgentxt; - maxgen.saveToCSVFile(buffer, 0); + maxHourlyGenPower.saveToCSVFile(buffer, 0); buffer.clear() << base_folder << SEP << series_folder << SEP << area_1->id << SEP << maxpumptxt; - maxpump.saveToCSVFile(buffer, 0); + maxHourlyPumpPower.saveToCSVFile(buffer, 0); - maxgen.reset(3, HOURS_PER_YEAR); - maxpump.reset(3, HOURS_PER_YEAR); + maxHourlyGenPower.reset(3, HOURS_PER_YEAR); + maxHourlyPumpPower.reset(3, HOURS_PER_YEAR); buffer.clear() << base_folder << SEP << series_folder; ret = area_1->hydro.series->LoadMaxPower(*study, area_1->id, buffer); @@ -102,76 +102,76 @@ BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_both_matrix_equal_width, Fixt BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_matrices_different_width_case_1, Fixture) { bool ret = false; - auto& maxgen = area_1->hydro.series->maxgen; - auto& maxpump = area_1->hydro.series->maxpump; - maxgen.reset(1, HOURS_PER_YEAR); - maxpump.reset(3, HOURS_PER_YEAR); + auto& maxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower; + auto& maxHourlyPumpPower = area_1->hydro.series->maxHourlyPumpPower; + maxHourlyGenPower.reset(1, HOURS_PER_YEAR); + maxHourlyPumpPower.reset(3, HOURS_PER_YEAR); - InstantiateMatrix(maxgen, 400., HOURS_PER_YEAR); - InstantiateMatrix(maxpump, 200., HOURS_PER_YEAR); + InstantiateMatrix(maxHourlyGenPower, 400., HOURS_PER_YEAR); + InstantiateMatrix(maxHourlyPumpPower, 200., HOURS_PER_YEAR); my_string buffer; buffer.clear() << base_folder << SEP << series_folder << SEP << area_1->id << SEP << maxgentxt; - maxgen.saveToCSVFile(buffer, 0); + maxHourlyGenPower.saveToCSVFile(buffer, 0); buffer.clear() << base_folder << SEP << series_folder << SEP << area_1->id << SEP << maxpumptxt; - maxpump.saveToCSVFile(buffer, 0); + maxHourlyPumpPower.saveToCSVFile(buffer, 0); - maxgen.reset(1, HOURS_PER_YEAR); - maxpump.reset(3, HOURS_PER_YEAR); + maxHourlyGenPower.reset(1, HOURS_PER_YEAR); + maxHourlyPumpPower.reset(3, HOURS_PER_YEAR); buffer.clear() << base_folder << SEP << series_folder; ret = area_1->hydro.series->LoadMaxPower(*study, area_1->id, buffer); BOOST_CHECK(ret); - BOOST_CHECK_EQUAL(maxgen.width, 3); + BOOST_CHECK_EQUAL(maxHourlyGenPower.width, 3); } BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_matrices_different_width_case_2, Fixture) { bool ret = false; - auto& maxgen = area_1->hydro.series->maxgen; - auto& maxpump = area_1->hydro.series->maxpump; - maxgen.reset(3, HOURS_PER_YEAR); - maxpump.reset(1, HOURS_PER_YEAR); + auto& maxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower; + auto& maxHourlyPumpPower = area_1->hydro.series->maxHourlyPumpPower; + maxHourlyGenPower.reset(3, HOURS_PER_YEAR); + maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); - InstantiateMatrix(maxgen, 400., HOURS_PER_YEAR); - InstantiateMatrix(maxpump, 200., HOURS_PER_YEAR); + InstantiateMatrix(maxHourlyGenPower, 400., HOURS_PER_YEAR); + InstantiateMatrix(maxHourlyPumpPower, 200., HOURS_PER_YEAR); my_string buffer; buffer.clear() << base_folder << SEP << series_folder << SEP << area_1->id << SEP << maxgentxt; - maxgen.saveToCSVFile(buffer, 0); + maxHourlyGenPower.saveToCSVFile(buffer, 0); buffer.clear() << base_folder << SEP << series_folder << SEP << area_1->id << SEP << maxpumptxt; - maxpump.saveToCSVFile(buffer, 0); + maxHourlyPumpPower.saveToCSVFile(buffer, 0); - maxgen.reset(3, HOURS_PER_YEAR); - maxpump.reset(1, HOURS_PER_YEAR); + maxHourlyGenPower.reset(3, HOURS_PER_YEAR); + maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); buffer.clear() << base_folder << SEP << series_folder; ret = area_1->hydro.series->LoadMaxPower(*study, area_1->id, buffer); BOOST_CHECK(ret); - BOOST_CHECK_EQUAL(maxpump.width, 3); + BOOST_CHECK_EQUAL(maxHourlyPumpPower.width, 3); } BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_no_solver, Fixture) { bool ret = false; - auto& maxgen = area_No_Solver->hydro.series->maxgen; - auto& maxpump = area_No_Solver->hydro.series->maxpump; - maxgen.reset(3, HOURS_PER_YEAR); - maxpump.reset(3, HOURS_PER_YEAR); + auto& maxHourlyGenPower = area_No_Solver->hydro.series->maxHourlyGenPower; + auto& maxHourlyPumpPower = area_No_Solver->hydro.series->maxHourlyPumpPower; + maxHourlyGenPower.reset(3, HOURS_PER_YEAR); + maxHourlyPumpPower.reset(3, HOURS_PER_YEAR); - InstantiateMatrix(maxgen, 400., HOURS_PER_YEAR); - InstantiateMatrix(maxpump, 200., HOURS_PER_YEAR); + InstantiateMatrix(maxHourlyGenPower, 400., HOURS_PER_YEAR); + InstantiateMatrix(maxHourlyPumpPower, 200., HOURS_PER_YEAR); my_string buffer; buffer.clear() << base_folder << SEP << series_folder << SEP << area_No_Solver->id << SEP << maxgentxt; - maxgen.saveToCSVFile(buffer, 0); + maxHourlyGenPower.saveToCSVFile(buffer, 0); buffer.clear() << base_folder << SEP << series_folder << SEP << area_No_Solver->id << SEP << maxpumptxt; - maxpump.saveToCSVFile(buffer, 0); + maxHourlyPumpPower.saveToCSVFile(buffer, 0); - maxgen.reset(3, HOURS_PER_YEAR); - maxpump.reset(3, HOURS_PER_YEAR); + maxHourlyGenPower.reset(3, HOURS_PER_YEAR); + maxHourlyPumpPower.reset(3, HOURS_PER_YEAR); buffer.clear() << base_folder << SEP << series_folder; ret = area_No_Solver->hydro.series->LoadMaxPower( diff --git a/src/ui/action/handler/antares-study/area/timeseries.cpp b/src/ui/action/handler/antares-study/area/timeseries.cpp index 7b5bfe84e1..120241d616 100644 --- a/src/ui/action/handler/antares-study/area/timeseries.cpp +++ b/src/ui/action/handler/antares-study/area/timeseries.cpp @@ -175,13 +175,13 @@ bool DataTimeseries::performWL(Context& ctx) } case Data::timeSeriesHydroMaxPower: { - ctx.area->hydro.series->maxgen = source->hydro.series->maxgen; - ctx.area->hydro.series->maxpump = source->hydro.series->maxpump; + ctx.area->hydro.series->maxHourlyGenPower = source->hydro.series->maxHourlyGenPower; + ctx.area->hydro.series->maxHourlyPumpPower = source->hydro.series->maxHourlyPumpPower; ctx.area->hydro.series->countpowercredits = source->hydro.series->countpowercredits; - source->hydro.series->maxgen.unloadFromMemory(); - source->hydro.series->maxpump.unloadFromMemory(); + source->hydro.series->maxHourlyGenPower.unloadFromMemory(); + source->hydro.series->maxHourlyPumpPower.unloadFromMemory(); } case Data::timeSeriesThermal: { diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/area/timeseries.h b/src/ui/simulator/toolbox/components/datagrid/renderer/area/timeseries.h index 95e85b051f..60b83477c0 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/area/timeseries.h +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/area/timeseries.h @@ -332,16 +332,16 @@ class TimeSeriesHydroMinGen final : public ATimeSeries } }; -class TimeSeriesHydroMaxGen final : public ATimeSeries +class TimeSeriesHydroMaxHourlyGenPower final : public ATimeSeries { public: using AncestorType = Renderer::Matrix; - TimeSeriesHydroMaxGen(wxWindow* control, Toolbox::InputSelector::Area* notifier) : + TimeSeriesHydroMaxHourlyGenPower(wxWindow* control, Toolbox::InputSelector::Area* notifier) : ATimeSeries(control, notifier) { } - ~TimeSeriesHydroMaxGen() override + ~TimeSeriesHydroMaxHourlyGenPower() override { destroyBoundEvents(); } @@ -359,21 +359,21 @@ class TimeSeriesHydroMaxGen final : public ATimeSeries private: void internalAreaChanged(Antares::Data::Area* area) override { - matrix((area && CurrentStudyIsValid()) ? &(area->hydro.series->maxgen) : NULL); + matrix((area && CurrentStudyIsValid()) ? &(area->hydro.series->maxHourlyGenPower) : NULL); Renderer::ARendererArea::internalAreaChanged(area); } }; -class TimeSeriesHydroMaxPump final : public ATimeSeries +class TimeSeriesHydroMaxHourlyPumpPower final : public ATimeSeries { public: using AncestorType = Renderer::Matrix; - TimeSeriesHydroMaxPump(wxWindow* control, Toolbox::InputSelector::Area* notifier) : + TimeSeriesHydroMaxHourlyPumpPower(wxWindow* control, Toolbox::InputSelector::Area* notifier) : ATimeSeries(control, notifier) { } - ~TimeSeriesHydroMaxPump() override + ~TimeSeriesHydroMaxHourlyPumpPower() override { destroyBoundEvents(); } @@ -391,7 +391,7 @@ class TimeSeriesHydroMaxPump final : public ATimeSeries private: void internalAreaChanged(Antares::Data::Area* area) override { - matrix((area && CurrentStudyIsValid()) ? &(area->hydro.series->maxpump) : NULL); + matrix((area && CurrentStudyIsValid()) ? &(area->hydro.series->maxHourlyPumpPower) : NULL); Renderer::ARendererArea::internalAreaChanged(area); } }; diff --git a/src/ui/simulator/windows/hydro/series.cpp b/src/ui/simulator/windows/hydro/series.cpp index 1112db0c9a..310fc98d9a 100644 --- a/src/ui/simulator/windows/hydro/series.cpp +++ b/src/ui/simulator/windows/hydro/series.cpp @@ -58,11 +58,11 @@ Series::Series(wxWindow* parent, Toolbox::InputSelector::Area* notifier) : pPageFatal = notebook->add(com, wxT("Minimum Generation")); com = new Component::Datagrid::Component(notebook); - com->renderer(new Component::Datagrid::Renderer::TimeSeriesHydroMaxGen(com, notifier)); + com->renderer(new Component::Datagrid::Renderer::TimeSeriesHydroMaxHourlyGenPower(com, notifier)); pPageFatal = notebook->add(com, wxT("Maximum Generation")); com = new Component::Datagrid::Component(notebook); - com->renderer(new Component::Datagrid::Renderer::TimeSeriesHydroMaxPump(com, notifier)); + com->renderer(new Component::Datagrid::Renderer::TimeSeriesHydroMaxHourlyPumpPower(com, notifier)); pPageFatal = notebook->add(com, wxT("Maximum Pumping")); // Connection to the notifier From 8436eb4eca2761eccfc1bff68d27f06fbe07f9c4 Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Wed, 27 Sep 2023 00:20:16 +0200 Subject: [PATCH 07/40] HydroMaxTSReader class --- docs/reference-guide/13-file-format.md | 2 +- src/libs/antares/study/CMakeLists.txt | 4 +- src/libs/antares/study/area/list.cpp | 15 +- src/libs/antares/study/area/scratchpad.cpp | 8 +- .../antares/study/cleaner/cleaner-v20.cpp | 6 +- .../antares/study/parts/hydro/container.cpp | 117 +++++----- .../antares/study/parts/hydro/container.h | 8 +- .../study/parts/hydro/datatransfer.cpp | 171 -------------- .../parts/hydro/hydromaxtimeseriesreader.cpp | 213 ++++++++++++++++++ ...atransfer.h => hydromaxtimeseriesreader.h} | 40 ++-- src/libs/antares/study/parts/parts.h | 2 +- src/solver/hydro/management/daily.cpp | 4 +- .../simulation/sim_calcul_economique.cpp | 10 +- .../antares/study/parts/hydro/CMakeLists.txt | 18 +- .../study/parts/hydro/help-functions.cpp | 27 +++ .../study/parts/hydro/help-functions.h | 4 +- ...r-class.cpp => test-hydroreader-class.cpp} | 74 ++---- .../handler/antares-study/area/timeseries.cpp | 2 + .../renderer/area/hydromonthlypower.cpp | 4 +- 19 files changed, 381 insertions(+), 348 deletions(-) delete mode 100644 src/libs/antares/study/parts/hydro/datatransfer.cpp create mode 100644 src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.cpp rename src/libs/antares/study/parts/hydro/{datatransfer.h => hydromaxtimeseriesreader.h} (54%) rename src/tests/src/libs/antares/study/parts/hydro/{test-datatransfer-class.cpp => test-hydroreader-class.cpp} (57%) diff --git a/docs/reference-guide/13-file-format.md b/docs/reference-guide/13-file-format.md index c7ae851631..26c5cb3401 100644 --- a/docs/reference-guide/13-file-format.md +++ b/docs/reference-guide/13-file-format.md @@ -3,7 +3,7 @@ This is a list of all recent changes that came with new Antares Simulator featur ## v8.8.0 For each area, new files are added **input/hydro/series/<area>/maxHourlyGenPower.txt** and **input/hydro/series/<area>/maxHourlyPumpPower.txt**. These files have one or more columns, and 8760 rows. The number of columns in these two files must be the same, if there is more than one column in each file, but if there is just one column for example in maxHourlyGenPower.txt file, maxHourlyPumpPower.txt file can have more than one column and vice versa. For old studies, file **input/hydro/common/capacity/maxpower_<area>** will be deleted after upgrading the study and corresponding data from that file will be copied to already mentioned new files, even if study is upgraded or not. In that case maxHourlyGenPower.txt and maxHourlyPumpPower.txt files will have just one column and 8760 rows. -Also for each area, new files are added **input/hydro/common/capacity/maxHourlyGenEnergy_<area>** and **input/hydro/common/capacity/maxHourlyPumpEnergy_<area>**. These files have just one column and 365 rows. For old studies, file **input/hydro/common/capacity/maxpower_<area>** will be deleted after upgrading the study and corresponding data from that file will be copied to already mentioned new files, even if study is upgraded or not. +Also for each area, new files are added **input/hydro/common/capacity/maxDailyGenEnergy_<area>** and **input/hydro/common/capacity/maxDailyPumpEnergy_<area>**. These files have just one column and 365 rows. For old studies, file **input/hydro/common/capacity/maxpower_<area>** will be deleted after upgrading the study and corresponding data from that file will be copied to already mentioned new files, even if study is upgraded or not. ### Input Under `Configure/MC Scenario Builder` new section added `Hydro Max Power` In the existing file **settings/scenariobuilder.dat**, under **<ruleset>** section following properties added: diff --git a/src/libs/antares/study/CMakeLists.txt b/src/libs/antares/study/CMakeLists.txt index c2567f083b..5df50837d4 100644 --- a/src/libs/antares/study/CMakeLists.txt +++ b/src/libs/antares/study/CMakeLists.txt @@ -137,8 +137,8 @@ set(SRC_STUDY_PART_HYDRO parts/hydro/allocation.h parts/hydro/allocation.hxx parts/hydro/allocation.cpp - parts/hydro/datatransfer.h - parts/hydro/datatransfer.cpp + parts/hydro/hydromaxtimeseriesreader.h + parts/hydro/hydromaxtimeseriesreader.cpp ) source_group("study\\part\\hydro" FILES ${SRC_STUDY_PART_HYDRO}) diff --git a/src/libs/antares/study/area/list.cpp b/src/libs/antares/study/area/list.cpp index 7413f335e9..befb62a315 100644 --- a/src/libs/antares/study/area/list.cpp +++ b/src/libs/antares/study/area/list.cpp @@ -909,11 +909,10 @@ static bool AreaListLoadFromFolderSingleArea(Study& study, if (area.hydro.series && study.header.version < 870) { - std::shared_ptr datatransfer = std::make_shared(); buffer.clear() << study.folderInput << SEP << "hydro"; - datatransfer->LoadFromFolder(study, buffer, area); - datatransfer->SupportForOldStudies(study, buffer, area); + HydroMaxTimeSeriesReader reader; + ret = reader(buffer, area) && ret; } if (area.hydro.series) @@ -922,14 +921,10 @@ static bool AreaListLoadFromFolderSingleArea(Study& study, ret = area.hydro.series->LoadMaxPower(study, area.id, buffer) && ret; } - buffer.clear() << study.folderInput << SEP << "hydro" << SEP << "common" << SEP - << "capacity" << SEP << "maxpower_" << area.id << '.' - << study.inputExtension; - - bool exists = IO::File::Exists(buffer); - - if (study.header.version >= 870 && exists) + if (bool exists = IO::File::Exists(buffer); study.header.version >= 870 && exists) { + buffer.clear() << study.folderInput << SEP << "hydro" << SEP << "common" << SEP + << "capacity" << SEP << "maxpower_" << area.id << ".txt"; IO::File::Delete(buffer); } diff --git a/src/libs/antares/study/area/scratchpad.cpp b/src/libs/antares/study/area/scratchpad.cpp index 405dfd8d48..ca794dec3d 100644 --- a/src/libs/antares/study/area/scratchpad.cpp +++ b/src/libs/antares/study/area/scratchpad.cpp @@ -89,9 +89,9 @@ AreaScratchpad::AreaScratchpad(const StudyRuntimeInfos& rinfos, Area& area) : ts // ... Getting hydro max power auto const& maxHourlyGenPower = area.hydro.series->maxHourlyGenPower; - auto const& maxHourlyGenEnergy = area.hydro.maxHourlyGenEnergy[0]; + auto const& maxDailyGenEnergy = area.hydro.maxDailyGenEnergy[0]; - hydroGenerationPermission = CheckForPositiveEnergy(maxHourlyGenPower, maxHourlyGenEnergy); + hydroGenerationPermission = CheckForPositiveEnergy(maxHourlyGenPower, maxDailyGenEnergy); // --------------------- // Hydro has inflows @@ -128,10 +128,10 @@ AreaScratchpad::AreaScratchpad(const StudyRuntimeInfos& rinfos, Area& area) : ts // ... Hydro max pumping power and energy auto const& maxHourlyPumpPower = area.hydro.series->maxHourlyPumpPower; - auto const& maxHourlyPumpEnergy = area.hydro.maxHourlyPumpEnergy[0]; + auto const& maxDailyPumpEnergy = area.hydro.maxDailyPumpEnergy[0]; // If pumping energy is nil over the whole year, pumpHasMod is false, true otherwise. - pumpHasMod = CheckForPositiveEnergy(maxHourlyPumpPower, maxHourlyPumpEnergy); + pumpHasMod = CheckForPositiveEnergy(maxHourlyPumpPower, maxDailyPumpEnergy); } AreaScratchpad::~AreaScratchpad() = default; diff --git a/src/libs/antares/study/cleaner/cleaner-v20.cpp b/src/libs/antares/study/cleaner/cleaner-v20.cpp index 8d8b19331b..240d38aba3 100644 --- a/src/libs/antares/study/cleaner/cleaner-v20.cpp +++ b/src/libs/antares/study/cleaner/cleaner-v20.cpp @@ -87,11 +87,9 @@ static void listOfFilesAnDirectoriesToKeepForArea(PathList& e, PathList& p, cons e.add(buffer); buffer.clear() << "input/hydro/common/capacity/inflowPattern_" << id << ".txt"; e.add(buffer); - buffer.clear() << "input/hydro/common/capacity/maxpower_" << id << ".txt"; + buffer.clear() << "input/hydro/common/capacity/maxDailyGenEnergy_" << id << ".txt"; e.add(buffer); - buffer.clear() << "input/hydro/common/capacity/maxHourlyGenEnergy_" << id << ".txt"; - e.add(buffer); - buffer.clear() << "input/hydro/common/capacity/maxHourlyPumpEnergy_" << id << ".txt"; + buffer.clear() << "input/hydro/common/capacity/maxDailyPumpEnergy_" << id << ".txt"; e.add(buffer); buffer.clear() << "input/hydro/common/capacity/reservoir_" << id << ".txt"; e.add(buffer); diff --git a/src/libs/antares/study/parts/hydro/container.cpp b/src/libs/antares/study/parts/hydro/container.cpp index 6ba3c018c0..020f3c7d95 100644 --- a/src/libs/antares/study/parts/hydro/container.cpp +++ b/src/libs/antares/study/parts/hydro/container.cpp @@ -28,7 +28,7 @@ #include "../../study.h" #include "container.h" #include -#include "datatransfer.h" +#include "hydromaxtimeseriesreader.h" using namespace Antares; using namespace Yuni; @@ -92,10 +92,10 @@ void PartHydro::reset() reservoirLevel.fillColumn(average, 0.5); reservoirLevel.fillColumn(maximum, 1.); waterValues.reset(101, DAYS_PER_YEAR, true); - maxHourlyGenEnergy.reset(1, DAYS_PER_YEAR, true); - maxHourlyGenEnergy.fillColumn(0, 24.); - maxHourlyPumpEnergy.reset(1, DAYS_PER_YEAR, true); - maxHourlyPumpEnergy.fillColumn(0, 24.); + maxDailyGenEnergy.reset(1, DAYS_PER_YEAR, true); + maxDailyGenEnergy.fillColumn(0, 24.); + maxDailyPumpEnergy.reset(1, DAYS_PER_YEAR, true); + maxDailyPumpEnergy.fillColumn(0, 24.); creditModulation.reset(101, 2, true); creditModulation.fill(1); // reset of the hydro allocation - however we don't have any information @@ -151,23 +151,38 @@ bool PartHydro::LoadFromFolder(Study& study, const AnyString& folder) enabledModeIsChanged = true; } - ret = area.hydro.LoadHours(study, area, folder); + ret = area.hydro.LoadDailyMaxEnergy(area, folder); if (enabledModeIsChanged) JIT::enabled = true; // Back to the previous loading mode. } else { - ret = area.hydro.LoadHours(study, area, folder); - } - } + ret = area.hydro.LoadDailyMaxEnergy(area, folder); - if (study.header.version < 870) - { - std::shared_ptr datatransfer = std::make_shared(); + // Check is moved here, because in case of old study + // maxDailyGenEnergy and maxDailyPumpEnergy are not yet initialized. + bool errorHours = false; + auto& colGen = area.hydro.maxDailyGenEnergy[0]; + auto& colPump = area.hydro.maxDailyPumpEnergy[0]; - ret = datatransfer->LoadFromFolder(study, folder, area); - ret = datatransfer->AutoTransferHours(study, folder, area); + for (int day = 0; day < DAYS_PER_YEAR; day++) + { + if (!errorHours && (colGen[day] < 0 || (colGen[day] > 24))) + { + logs.error() << area.name << ": invalid power or energy value"; + errorHours = true; + ret = false; + } + + if (!errorHours && (colPump[day] < 0 || (colPump[day] > 24))) + { + logs.error() << area.name << ": invalid power or energy value"; + errorHours = true; + ret = false; + } + } + } } buffer.clear() << folder << SEP << "common" << SEP << "capacity" << SEP @@ -223,27 +238,6 @@ bool PartHydro::LoadFromFolder(Study& study, const AnyString& folder) } } - bool errorHours = false; - auto& colGen = area.hydro.maxHourlyGenEnergy[0]; - auto& colPump = area.hydro.maxHourlyPumpEnergy[0]; - - for (int day = 0; day < DAYS_PER_YEAR; day++) - { - if (!errorHours && (colGen[day] < 0 || (colGen[day] > 24))) - { - logs.error() << area.name << ": invalid power or energy value"; - errorHours = true; - ret = false; - } - - if (!errorHours && (colPump[day] < 0 || (colPump[day] > 24))) - { - logs.error() << area.name << ": invalid power or energy value"; - errorHours = true; - ret = false; - } - } - for (int i = 0; i < 101; i++) { if ((area.hydro.creditModulation[i][0] < 0) @@ -691,13 +685,13 @@ bool PartHydro::SaveToFolder(const AreaList& areas, const AnyString& folder) sPowerToLevel->add(area.id, true); // max hours gen - buffer.clear() << folder << SEP << "common" << SEP << "capacity" << SEP << "maxHourlyGenEnergy_" + buffer.clear() << folder << SEP << "common" << SEP << "capacity" << SEP << "maxDailyGenEnergy_" << area.id << ".txt"; - ret = area.hydro.maxHourlyGenEnergy.saveToCSVFile(buffer, /*decimal*/ 2) && ret; + ret = area.hydro.maxDailyGenEnergy.saveToCSVFile(buffer, /*decimal*/ 2) && ret; // max hours pump - buffer.clear() << folder << SEP << "common" << SEP << "capacity" << SEP << "maxHourlyPumpEnergy_" + buffer.clear() << folder << SEP << "common" << SEP << "capacity" << SEP << "maxDailyPumpEnergy_" << area.id << ".txt"; - ret = area.hydro.maxHourlyPumpEnergy.saveToCSVFile(buffer, /*decimal*/ 2) && ret; + ret = area.hydro.maxDailyPumpEnergy.saveToCSVFile(buffer, /*decimal*/ 2) && ret; // credit modulations buffer.clear() << folder << SEP << "common" << SEP << "capacity" << SEP << "creditmodulations_" << area.id << ".txt"; @@ -727,8 +721,8 @@ bool PartHydro::forceReload(bool reload) const ret = inflowPattern.forceReload(reload) && ret; ret = reservoirLevel.forceReload(reload) && ret; ret = waterValues.forceReload(reload) && ret; - ret = maxHourlyGenEnergy.forceReload(reload) && ret; - ret = maxHourlyPumpEnergy.forceReload(reload) && ret; + ret = maxDailyGenEnergy.forceReload(reload) && ret; + ret = maxDailyPumpEnergy.forceReload(reload) && ret; if (series) ret = series->forceReload(reload) && ret; @@ -744,8 +738,8 @@ void PartHydro::markAsModified() const reservoirLevel.markAsModified(); waterValues.markAsModified(); creditModulation.markAsModified(); - maxHourlyGenEnergy.markAsModified(); - maxHourlyPumpEnergy.markAsModified(); + maxDailyGenEnergy.markAsModified(); + maxDailyPumpEnergy.markAsModified(); if (series) series->markAsModified(); @@ -798,38 +792,39 @@ void PartHydro::copyFrom(const PartHydro& rhs) pumpingEfficiency = rhs.pumpingEfficiency; } - // max hours gen + // max daily gen { - maxHourlyGenEnergy = rhs.maxHourlyGenEnergy; - maxHourlyGenEnergy.unloadFromMemory(); - rhs.maxHourlyGenEnergy.unloadFromMemory(); + maxDailyGenEnergy = rhs.maxDailyGenEnergy; + maxDailyGenEnergy.unloadFromMemory(); + rhs.maxDailyGenEnergy.unloadFromMemory(); } - // max hours pump + // max daily pump { - maxHourlyPumpEnergy = rhs.maxHourlyPumpEnergy; - maxHourlyPumpEnergy.unloadFromMemory(); - rhs.maxHourlyPumpEnergy.unloadFromMemory(); + maxDailyPumpEnergy = rhs.maxDailyPumpEnergy; + maxDailyPumpEnergy.unloadFromMemory(); + rhs.maxDailyPumpEnergy.unloadFromMemory(); } } -bool PartHydro::LoadHours(Study& study, Area& area, const AnyString& folder) +bool PartHydro::LoadDailyMaxEnergy(Area& area, const AnyString& folder) { - auto& buffer = study.bufferLoadingTS; + YString filePath; + Matrix<>::BufferType fileContent; bool ret = true; - buffer.clear() << folder << SEP << "common" << SEP << "capacity" << SEP << "maxHourlyPumpEnergy_" - << area.id << '.' << study.inputExtension; + filePath.clear() << folder << SEP << "common" << SEP << "capacity" << SEP + << "maxDailyGenEnergy_" << area.id << '.' << "txt"; - ret = area.hydro.maxHourlyGenEnergy.loadFromCSVFile( - buffer, 1, DAYS_PER_YEAR, Matrix<>::optFixedSize, &study.dataBuffer) + ret = area.hydro.maxDailyGenEnergy.loadFromCSVFile( + filePath, 1, DAYS_PER_YEAR, Matrix<>::optFixedSize, &fileContent) && ret; - buffer.clear() << folder << SEP << "common" << SEP << "capacity" << SEP << "maxHourlyPumpEnergy_" - << area.id << '.' << study.inputExtension; + filePath.clear() << folder << SEP << "common" << SEP << "capacity" << SEP + << "maxDailyPumpEnergy_" << area.id << '.' << "txt"; - ret = area.hydro.maxHourlyPumpEnergy.loadFromCSVFile( - buffer, 1, DAYS_PER_YEAR, Matrix<>::optFixedSize, &study.dataBuffer) + ret = area.hydro.maxDailyPumpEnergy.loadFromCSVFile( + filePath, 1, DAYS_PER_YEAR, Matrix<>::optFixedSize, &fileContent) && ret; return ret; diff --git a/src/libs/antares/study/parts/hydro/container.h b/src/libs/antares/study/parts/hydro/container.h index 131a7d5895..72cf0b0f61 100644 --- a/src/libs/antares/study/parts/hydro/container.h +++ b/src/libs/antares/study/parts/hydro/container.h @@ -100,9 +100,9 @@ class PartHydro void markAsModified() const; /*! - ** \brief Load hours data + ** \brief Load daily max energy */ - bool LoadHours(Study& study, Area& area, const AnyString& folder); + bool LoadDailyMaxEnergy(Area& area, const AnyString& folder); public: //! Inter-daily breakdown (previously called Smoothing Factor or alpha) @@ -162,8 +162,8 @@ class PartHydro //! Data for time-series DataSeriesHydro* series; - Matrix maxHourlyGenEnergy; - Matrix maxHourlyPumpEnergy; + Matrix maxDailyGenEnergy; + Matrix maxDailyPumpEnergy; }; // class PartHydro diff --git a/src/libs/antares/study/parts/hydro/datatransfer.cpp b/src/libs/antares/study/parts/hydro/datatransfer.cpp deleted file mode 100644 index 2f3ec916c5..0000000000 --- a/src/libs/antares/study/parts/hydro/datatransfer.cpp +++ /dev/null @@ -1,171 +0,0 @@ -/* -** Copyright 2007-2023 RTE -** Authors: Antares_Simulator Team -** -** This file is part of Antares_Simulator. -** -** Antares_Simulator is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** There are special exceptions to the terms and conditions of the -** license as they are applied to this software. View the full text of -** the exceptions in file COPYING.txt in the directory of this software -** distribution -** -** 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 -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with Antares_Simulator. If not, see . -** -** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions -*/ - -#include "../../study.h" -#include "datatransfer.h" -#include - -using namespace Yuni; - -#define SEP IO::Separator - -namespace Antares::Data -{ - -DataTransfer::DataTransfer() -{ - dailyMaxPumpAndGen.reset(4, DAYS_PER_YEAR, true); -} - -bool DataTransfer::LoadFromFolder(Study& study, const AnyString& folder, Area& area) -{ - auto& buffer = study.bufferLoadingTS; - bool ret = true; - - buffer.clear() << folder << SEP << "common" << SEP << "capacity" << SEP << "maxpower_" - << area.id << '.' << study.inputExtension; - - // GUI part patch : - // We need to know, when estimating the RAM required by the solver, if the current area - // is hydro modulable. Therefore, reading the area's daily max power at this stage is - // necessary. - - if (!study.usedByTheSolver) - { - bool enabledModeIsChanged = false; - if (JIT::enabled) - { - JIT::enabled = false; // Allowing to read the area's daily max power - enabledModeIsChanged = true; - } - - ret = dailyMaxPumpAndGen.loadFromCSVFile( - buffer, 4, DAYS_PER_YEAR, Matrix<>::optFixedSize, &study.dataBuffer) - && ret; - - if (enabledModeIsChanged) - JIT::enabled = true; // Back to the previous loading mode. - } - else - { - ret = dailyMaxPumpAndGen.loadFromCSVFile( - buffer, 4, DAYS_PER_YEAR, Matrix<>::optFixedSize, &study.dataBuffer) - && ret; - - bool errorPowers = false; - for (uint i = 0; i < 4; ++i) - { - auto& col = dailyMaxPumpAndGen[i]; - for (uint day = 0; day < DAYS_PER_YEAR; ++day) - { - if (!errorPowers && (col[day] < 0 || (i % 2 /*column hours*/ && col[day] > 24))) - { - logs.error() << area.name << ": invalid power or energy value"; - errorPowers = true; - ret = false; - } - } - } - } - - return ret; -} - -bool DataTransfer::AutoTransferHours(Study& study, const AnyString& folder, Area& area) -{ - auto& buffer = study.bufferLoadingTS; - bool ret = true; - - auto& maxHourlyGenEnergy = area.hydro.maxHourlyGenEnergy; - auto& maxHourlyPumpEnergy = area.hydro.maxHourlyPumpEnergy; - - maxHourlyGenEnergy.reset(1, DAYS_PER_YEAR, true); - maxHourlyGenEnergy.fillColumn(0, 24.); - - maxHourlyPumpEnergy.reset(1, DAYS_PER_YEAR, true); - maxHourlyPumpEnergy.fillColumn(0, 24.); - - for (uint day = 0; day < DAYS_PER_YEAR; ++day) - { - maxHourlyGenEnergy[0][day] = dailyMaxPumpAndGen[genMaxE][day]; - maxHourlyPumpEnergy[0][day] = dailyMaxPumpAndGen[pumpMaxE][day]; - } - - buffer.clear() << folder << SEP << "common" << SEP << "capacity" << SEP << "maxHourlyGenEnergy_" - << area.id << ".txt"; - ret = maxHourlyGenEnergy.saveToCSVFile(buffer, /*decimal*/ 2) && ret; - - buffer.clear() << folder << SEP << "common" << SEP << "capacity" << SEP << "maxHourlyPumpEnergy_" - << area.id << ".txt"; - ret = maxHourlyPumpEnergy.saveToCSVFile(buffer, /*decimal*/ 2) && ret; - - return ret; -} - -bool DataTransfer::SupportForOldStudies(Study& study, const AnyString& folder, Area& area) -{ - bool ret = true; - auto& buffer = study.bufferLoadingTS; - auto& maxHourlyGenPower = area.hydro.series->maxHourlyGenPower; - auto& maxHourlyPumpPower = area.hydro.series->maxHourlyPumpPower; - - auto& dailyMaxGen = dailyMaxPumpAndGen[genMaxP]; - auto& dailyMaxPump = dailyMaxPumpAndGen[pumpMaxP]; - - maxHourlyGenPower.reset(1, HOURS_PER_YEAR); - maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); - - AutoTransferPower(maxHourlyGenPower, dailyMaxGen); - AutoTransferPower(maxHourlyPumpPower, dailyMaxPump); - - buffer.clear() << folder << SEP << "series" << SEP << area.id << SEP << "maxHourlyGenPower." << study.inputExtension; - ret = maxHourlyGenPower.saveToCSVFile(buffer, 1, HOURS_PER_YEAR, &study.dataBuffer) && ret; - - buffer.clear() << folder << SEP << "series" << SEP << area.id << SEP << "maxHourlyPumpPower." << study.inputExtension; - ret = maxHourlyPumpPower.saveToCSVFile(buffer, 1, HOURS_PER_YEAR, &study.dataBuffer) && ret; - - return ret; -} - -void DataTransfer::AutoTransferPower(Matrix& matrix, - const Matrix::ColumnType& maxP) -{ - uint hours = 0; - uint days = 0; - - while (hours < HOURS_PER_YEAR && days < DAYS_PER_YEAR) - { - for (uint i = 0; i < 24; ++i) - { - matrix[0][hours] = maxP[days]; - ++hours; - } - ++days; - } -} - -} // namespace Antares::Data \ No newline at end of file diff --git a/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.cpp b/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.cpp new file mode 100644 index 0000000000..23e2583312 --- /dev/null +++ b/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.cpp @@ -0,0 +1,213 @@ +/* +** Copyright 2007-2023 RTE +** Authors: Antares_Simulator Team +** +** This file is part of Antares_Simulator. +** +** Antares_Simulator is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** There are special exceptions to the terms and conditions of the +** license as they are applied to this software. View the full text of +** the exceptions in file COPYING.txt in the directory of this software +** distribution +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Antares_Simulator. If not, see . +** +** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions +*/ + +#include "../../study.h" +#include "hydromaxtimeseriesreader.h" +#include + +using namespace Yuni; + +#define SEP IO::Separator + +namespace Antares::Data +{ + +HydroMaxTimeSeriesReader::HydroMaxTimeSeriesReader() +{ + dailyMaxPumpAndGen.reset(4, DAYS_PER_YEAR, true); +} + +bool HydroMaxTimeSeriesReader::LoadDailyMaxPowersAndEnergies(const AnyString& folder, Area& area) +{ + YString filePath; + Matrix<>::BufferType fileContent; + bool ret = true; + + filePath.clear() << folder << SEP << "common" << SEP << "capacity" << SEP << "maxpower_" + << area.id << ".txt"; + + // It is necessary to load maxpower_ txt file, whether loading is called from old GUI + // or from solver. + + bool enabledModeIsChanged = false; + + if (JIT::enabled) + { + JIT::enabled = false; // Allowing to read the area's daily max power and energy + enabledModeIsChanged = true; + } + + ret = dailyMaxPumpAndGen.loadFromCSVFile( + filePath, 4, DAYS_PER_YEAR, Matrix<>::optFixedSize, &fileContent) + && ret; + + if (enabledModeIsChanged) + JIT::enabled = true; // Back to the previous loading mode. + + bool errorPowers = false; + for (uint i = 0; i < 4; ++i) + { + auto& col = dailyMaxPumpAndGen[i]; + for (uint day = 0; day < DAYS_PER_YEAR; ++day) + { + if (!errorPowers && (col[day] < 0 || (i % 2 /*column hours*/ && col[day] > 24))) + { + logs.error() << area.name << ": invalid power or energy value"; + errorPowers = true; + ret = false; + } + } + } + return ret; +} + +bool HydroMaxTimeSeriesReader::SaveDailyMaxEnergy(const AnyString& folder, Area& area) +{ + bool ret = true; + + ret = SaveMaxGenerationEnergy(folder, area) && ret; + ret = SaveMaxPumpingEnergy(folder, area) && ret; + + return ret; +} + +bool HydroMaxTimeSeriesReader::SaveMaxGenerationEnergy(const AnyString& folder, Area& area) +{ + YString filePath; + auto& maxDailyGenEnergy = area.hydro.maxDailyGenEnergy; + bool ret = true; + + maxDailyGenEnergy.reset(1, DAYS_PER_YEAR, true); + maxDailyGenEnergy.fillColumn(0, 24.); + + for (uint day = 0; day < DAYS_PER_YEAR; ++day) + maxDailyGenEnergy[0][day] = dailyMaxPumpAndGen[genMaxE][day]; + + filePath.clear() << folder << SEP << "common" << SEP << "capacity" << SEP + << "maxDailyGenEnergy_" << area.id << ".txt"; + + ret = maxDailyGenEnergy.saveToCSVFile(filePath, 2) && ret; + + return ret; +} + +bool HydroMaxTimeSeriesReader::SaveMaxPumpingEnergy(const AnyString& folder, Area& area) +{ + YString filePath; + auto& maxDailyPumpEnergy = area.hydro.maxDailyPumpEnergy; + bool ret = true; + + maxDailyPumpEnergy.reset(1, DAYS_PER_YEAR, true); + maxDailyPumpEnergy.fillColumn(0, 24.); + + for (uint day = 0; day < DAYS_PER_YEAR; ++day) + maxDailyPumpEnergy[0][day] = dailyMaxPumpAndGen[pumpMaxE][day]; + + filePath.clear() << folder << SEP << "common" << SEP << "capacity" << SEP + << "maxDailyPumpEnergy_" << area.id << ".txt"; + ret = maxDailyPumpEnergy.saveToCSVFile(filePath, 2) && ret; + + return ret; +} + +bool HydroMaxTimeSeriesReader::SaveDailyMaxPowerAsHourly(const AnyString& folder, Area& area) +{ + bool ret = true; + + ret = SaveDailyMaxGenPowerAsHourly(folder, area) && ret; + ret = SaveDailyMaxPumpPowerAsHourly(folder, area) && ret; + + return ret; +} + +bool HydroMaxTimeSeriesReader::SaveDailyMaxGenPowerAsHourly(const AnyString& folder, Area& area) +{ + bool ret = true; + YString filePath; + + auto& maxHourlyGenPower = area.hydro.series->maxHourlyGenPower; + auto& dailyMaxGen = dailyMaxPumpAndGen[genMaxP]; + + maxHourlyGenPower.reset(1, HOURS_PER_YEAR); + + TransferDailyMaxPowerAsHourly(maxHourlyGenPower[0], dailyMaxGen); + + filePath.clear() << folder << SEP << "series" << SEP << area.id << SEP << "maxHourlyGenPower." + << "txt"; + ret = maxHourlyGenPower.saveToCSVFile(filePath, 2) && ret; + + return ret; +} + +bool HydroMaxTimeSeriesReader::SaveDailyMaxPumpPowerAsHourly(const AnyString& folder, Area& area) +{ + bool ret = true; + YString filePath; + + auto& maxHourlyPumpPower = area.hydro.series->maxHourlyPumpPower; + auto& dailyMaxPump = dailyMaxPumpAndGen[pumpMaxP]; + + maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); + + TransferDailyMaxPowerAsHourly(maxHourlyPumpPower[0], dailyMaxPump); + + filePath.clear() << folder << SEP << "series" << SEP << area.id << SEP << "maxHourlyPumpPower." + << "txt"; + ret = maxHourlyPumpPower.saveToCSVFile(filePath, 2) && ret; + + return ret; +} + +bool HydroMaxTimeSeriesReader::operator()(const AnyString& folder, Area& area) +{ + bool ret = true; + + ret = LoadDailyMaxPowersAndEnergies(folder, area) && ret; + ret = SaveDailyMaxEnergy(folder, area) && ret; + ret = SaveDailyMaxPowerAsHourly(folder, area) && ret; + + return ret; +} + +void TransferDailyMaxPowerAsHourly(Matrix::ColumnType& hourlyColumn, + const Matrix::ColumnType& dailyColumn) +{ + uint hours = 0; + uint days = 0; + + while (hours < HOURS_PER_YEAR && days < DAYS_PER_YEAR) + { + for (uint i = 0; i < 24; ++i) + { + hourlyColumn[hours] = dailyColumn[days]; + ++hours; + } + ++days; + } +} + +} // namespace Antares::Data \ No newline at end of file diff --git a/src/libs/antares/study/parts/hydro/datatransfer.h b/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.h similarity index 54% rename from src/libs/antares/study/parts/hydro/datatransfer.h rename to src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.h index fe2820eeab..41dedaf8d5 100644 --- a/src/libs/antares/study/parts/hydro/datatransfer.h +++ b/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.h @@ -25,22 +25,26 @@ ** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions */ -#ifndef __ANTARES_LIBS_STUDY_PARTS_HYDRO_DATA_TRANSFER_H__ -#define __ANTARES_LIBS_STUDY_PARTS_HYDRO_DATA_TRANSFER_H__ +#ifndef __ANTARES_LIBS_STUDY_PARTS_HYDRO_MAX_TIME_SERIES_READER_H__ +#define __ANTARES_LIBS_STUDY_PARTS_HYDRO_MAX_TIME_SERIES_READER_H__ #include "../../../array/antares//array/matrix.h" namespace Antares::Data { /*! -** \brief Hydro for a single area +** This class provides support for old studies, reading from deprecated files, +** fils matrix dailyMaxPumpAndGen and transfers data to the corresponding data class members of +** class PartHydro */ -class DataTransfer +class HydroMaxTimeSeriesReader { - public: + HydroMaxTimeSeriesReader(); + + bool operator()(const AnyString& folder, Area& area); - DataTransfer(); + Matrix dailyMaxPumpAndGen; enum powerDailyE { @@ -54,17 +58,19 @@ class DataTransfer pumpMaxE, }; - Matrix dailyMaxPumpAndGen; - - bool LoadFromFolder(Study& study, const AnyString& folder, Area& area); - bool AutoTransferHours(Study& study, const AnyString& folder, Area& area); - void AutoTransferPower(Matrix& matrix, - const Matrix::ColumnType& maxPower); - bool SupportForOldStudies(Study& study, const AnyString& folder, Area& area); - - +private: + bool LoadDailyMaxPowersAndEnergies(const AnyString& folder, Area& area); + bool SaveDailyMaxEnergy(const AnyString& folder, Area& area); + bool SaveDailyMaxPowerAsHourly(const AnyString& folder, Area& area); + bool SaveMaxGenerationEnergy(const AnyString& folder, Area& area); + bool SaveMaxPumpingEnergy(const AnyString& folder, Area& area); + bool SaveDailyMaxGenPowerAsHourly(const AnyString& folder, Area& area); + bool SaveDailyMaxPumpPowerAsHourly(const AnyString& folder, Area& area); }; -} // Antares::Data +void TransferDailyMaxPowerAsHourly(Matrix::ColumnType& hourlyColumn, + const Matrix::ColumnType& dailyColumn); + +} // namespace Antares::Data -#endif /*__ANTARES_LIBS_STUDY_PARTS_HYDRO_DATA_TRANSFER_H__*/ \ No newline at end of file +#endif /*__ANTARES_LIBS_STUDY_PARTS_HYDRO_MAX_TIME_SERIES_READER_H__*/ \ No newline at end of file diff --git a/src/libs/antares/study/parts/parts.h b/src/libs/antares/study/parts/parts.h index 1dcbdbc39d..01d654821f 100644 --- a/src/libs/antares/study/parts/parts.h +++ b/src/libs/antares/study/parts/parts.h @@ -40,7 +40,7 @@ #include "hydro/prepro.h" #include "hydro/series.h" #include "hydro/container.h" -#include "hydro/datatransfer.h" +#include "hydro/hydromaxtimeseriesreader.h" // Wind #include "wind/prepro.h" diff --git a/src/solver/hydro/management/daily.cpp b/src/solver/hydro/management/daily.cpp index 7fd8f9fc8d..0f69f0b331 100644 --- a/src/solver/hydro/management/daily.cpp +++ b/src/solver/hydro/management/daily.cpp @@ -250,14 +250,14 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St uint dayYear = 0; - auto const& maxHourlyGenEnergy = area.hydro.maxHourlyGenEnergy; + auto const& maxDailyGenEnergy = area.hydro.maxDailyGenEnergy; auto const& maxHourlyGenPower = area.hydro.series->maxHourlyGenPower; uint tsIndexMaxPower = (NumeroChroniquesTireesParPays[numSpace][z]).HydrauliqueMaxPower; auto const& maxP = maxHourlyGenPower[tsIndexMaxPower < maxHourlyGenPower.width ? tsIndexMaxPower : 0]; - auto const& maxE = maxHourlyGenEnergy[0]; + auto const& maxE = maxDailyGenEnergy[0]; auto& ventilationResults = ventilationResults_[numSpace][z]; diff --git a/src/solver/simulation/sim_calcul_economique.cpp b/src/solver/simulation/sim_calcul_economique.cpp index 87a0d2fbb6..fb4dc88c9a 100644 --- a/src/solver/simulation/sim_calcul_economique.cpp +++ b/src/solver/simulation/sim_calcul_economique.cpp @@ -681,7 +681,7 @@ void SIM_RenseignementProblemeHebdo(const Study& study, = 0.; problem.CaracteristiquesHydrauliques[k] .MaxEnergieHydrauParIntervalleOptimise[j] - = meanPower * area.hydro.maxHourlyGenEnergy[0][day] + = meanPower * area.hydro.maxDailyGenEnergy[0][day] * problem.CaracteristiquesHydrauliques[k] .WeeklyGeneratingModulation; } @@ -732,7 +732,7 @@ void SIM_RenseignementProblemeHebdo(const Study& study, uint day = study.calendar.hours[PasDeTempsDebut + j * 24].dayYear; auto meanPower = CalculateDailyMeanPower(day, srcMaxHourlyGenPower); - double DGC = meanPower * area.hydro.maxHourlyGenEnergy[0][day]; + double DGC = meanPower * area.hydro.maxDailyGenEnergy[0][day]; DGU_tmp[j] = DNT[day] * LUB; DGL_tmp[j] = DNT[day] * LLB; @@ -841,7 +841,7 @@ void SIM_RenseignementProblemeHebdo(const Study& study, problem.CaracteristiquesHydrauliques[k] .MaxEnergiePompageParIntervalleOptimise[j] - = meanPump * area.hydro.maxHourlyPumpEnergy[0][day] + = meanPump * area.hydro.maxDailyPumpEnergy[0][day] * problem.CaracteristiquesHydrauliques[k] .WeeklyPumpingModulation; } @@ -875,7 +875,7 @@ void SIM_RenseignementProblemeHebdo(const Study& study, auto meanPump = CalculateDailyMeanPower(day, srcMaxHourlyPumpPower); double DPC - = meanPump * area.hydro.maxHourlyPumpEnergy[0][day]; + = meanPump * area.hydro.maxDailyPumpEnergy[0][day]; WPU += DPC; } @@ -887,7 +887,7 @@ void SIM_RenseignementProblemeHebdo(const Study& study, uint day = study.calendar.hours[PasDeTempsDebut + j * 24].dayYear; auto meanPump = CalculateDailyMeanPower(day, srcMaxHourlyPumpPower); double DPC - = meanPump * area.hydro.maxHourlyPumpEnergy[0][day]; + = meanPump * area.hydro.maxDailyPumpEnergy[0][day]; double rc = area.hydro.reservoirCapacity; if (not area.hydro.hardBoundsOnRuleCurves) diff --git a/src/tests/src/libs/antares/study/parts/hydro/CMakeLists.txt b/src/tests/src/libs/antares/study/parts/hydro/CMakeLists.txt index 41f54f9059..8f32cde1c4 100644 --- a/src/tests/src/libs/antares/study/parts/hydro/CMakeLists.txt +++ b/src/tests/src/libs/antares/study/parts/hydro/CMakeLists.txt @@ -3,21 +3,21 @@ set(src_libs_antares_study "${CMAKE_SOURCE_DIR}/libs/antares/study") set(src_libs_antares "${CMAKE_SOURCE_DIR}/libs/antares") # Hydro data transfer -set(SRC_DATA_TRANSFER - test-datatransfer-class.cpp +set(SRC_HYDRO_READER + test-hydroreader-class.cpp help-functions.h help-functions.cpp) -add_executable(test-hydro-data-transfer ${SRC_DATA_TRANSFER}) +add_executable(test-hydro-reader ${SRC_HYDRO_READER}) -target_include_directories(test-hydro-data-transfer +target_include_directories(test-hydro-reader PRIVATE "${src_libs_antares_study}" "${src_libs_antares_study}/parts/hydro" "${src_libs_antares}/array/antares/array" ) -target_link_libraries(test-hydro-data-transfer +target_link_libraries(test-hydro-reader PRIVATE Boost::unit_test_framework antares-core @@ -28,12 +28,12 @@ target_link_libraries(test-hydro-data-transfer # Linux if(UNIX AND NOT APPLE) - target_link_libraries(test-hydro-data-transfer PRIVATE stdc++fs) + target_link_libraries(test-hydro-reader PRIVATE stdc++fs) endif() -set_target_properties(test-hydro-data-transfer PROPERTIES FOLDER Unit-tests) -add_test(NAME test-hydro-data-transfer COMMAND test-hydro-data-transfer) -set_property(TEST test-hydro-data-transfer PROPERTY LABELS unit) +set_target_properties(test-hydro-reader PROPERTIES FOLDER Unit-tests) +add_test(NAME test-hydro-reader COMMAND test-hydro-reader) +set_property(TEST test-hydro-reader PROPERTY LABELS unit) # Useful variables definitions set(src_libs_antares_study "${CMAKE_SOURCE_DIR}/libs/antares/study") diff --git a/src/tests/src/libs/antares/study/parts/hydro/help-functions.cpp b/src/tests/src/libs/antares/study/parts/hydro/help-functions.cpp index 5d96198a85..4a96fbb0ce 100644 --- a/src/tests/src/libs/antares/study/parts/hydro/help-functions.cpp +++ b/src/tests/src/libs/antares/study/parts/hydro/help-functions.cpp @@ -74,4 +74,31 @@ void removeFolder(my_string& path, my_string& folder_name) << "\n"; } } +} + +bool DailyMaxPowerAsHourlyTransferCheck(Matrix::ColumnType& hourlyColumn, + const Matrix::ColumnType& dailyColumn) +{ + uint hours = 0; + uint days = 0; + bool check = true; + + while (hours < HOURS_PER_YEAR && days < DAYS_PER_YEAR) + { + for (uint i = 0; i < 24; ++i) + { + if (hourlyColumn[hours] != dailyColumn[days]) + { + check = false; + break; + } + ++hours; + } + + if (!check) + break; + + ++days; + } + return check; } \ No newline at end of file diff --git a/src/tests/src/libs/antares/study/parts/hydro/help-functions.h b/src/tests/src/libs/antares/study/parts/hydro/help-functions.h index 6e0e579d49..655a42f312 100644 --- a/src/tests/src/libs/antares/study/parts/hydro/help-functions.h +++ b/src/tests/src/libs/antares/study/parts/hydro/help-functions.h @@ -16,4 +16,6 @@ void createFolder(const my_string& path, const my_string& folder_name); bool createFile(const my_string& folder_path, const my_string& file_name); void InstantiateMatrix(Matrix& matrix, double seed, uint type); void InstantiateColumn(Matrix::ColumnType& col, double seed, uint type); -void removeFolder(my_string& path, my_string& folder_name); \ No newline at end of file +void removeFolder(my_string& path, my_string& folder_name); +bool DailyMaxPowerAsHourlyTransferCheck(Matrix::ColumnType& hourlyColumn, + const Matrix::ColumnType& dailyColumn); \ No newline at end of file diff --git a/src/tests/src/libs/antares/study/parts/hydro/test-datatransfer-class.cpp b/src/tests/src/libs/antares/study/parts/hydro/test-hydroreader-class.cpp similarity index 57% rename from src/tests/src/libs/antares/study/parts/hydro/test-datatransfer-class.cpp rename to src/tests/src/libs/antares/study/parts/hydro/test-hydroreader-class.cpp index 975de6292b..d943e216f8 100644 --- a/src/tests/src/libs/antares/study/parts/hydro/test-datatransfer-class.cpp +++ b/src/tests/src/libs/antares/study/parts/hydro/test-hydroreader-class.cpp @@ -11,7 +11,7 @@ struct Fixture Fixture() { study = make_shared(true); - datatransfer = make_shared(); + reader = make_shared(); study->inputExtension = "txt"; // Add areas area_1 = study->areaAdd("Area1"); @@ -21,23 +21,23 @@ struct Fixture // Create necessary folders and files for these two areas createFoldersAndFiles(); - auto& gen = datatransfer->dailyMaxPumpAndGen[DataTransfer::genMaxP]; + auto& gen = reader->dailyMaxPumpAndGen[HydroMaxTimeSeriesReader::genMaxP]; InstantiateColumn(gen, 300., DAYS_PER_YEAR); - auto& pump = datatransfer->dailyMaxPumpAndGen[DataTransfer::pumpMaxP]; + auto& pump = reader->dailyMaxPumpAndGen[HydroMaxTimeSeriesReader::pumpMaxP]; InstantiateColumn(pump, 200., DAYS_PER_YEAR); - auto& hoursGen = datatransfer->dailyMaxPumpAndGen[DataTransfer::genMaxE]; + auto& hoursGen = reader->dailyMaxPumpAndGen[HydroMaxTimeSeriesReader::genMaxE]; InstantiateColumn(hoursGen, 20., DAYS_PER_YEAR); - auto& hoursPump = datatransfer->dailyMaxPumpAndGen[DataTransfer::pumpMaxE]; + auto& hoursPump = reader->dailyMaxPumpAndGen[HydroMaxTimeSeriesReader::pumpMaxE]; InstantiateColumn(hoursPump, 14., DAYS_PER_YEAR); my_string buffer; - my_string file_name = "maxpower_" + area_2->id + ".txt"; + my_string file_name = "maxpower_" + area_1->id + ".txt"; buffer.clear() << base_folder << SEP << hydro_folder << SEP << common_folder << SEP << capacity_folder << SEP << file_name; - datatransfer->dailyMaxPumpAndGen.saveToCSVFile(buffer, 2); + reader->dailyMaxPumpAndGen.saveToCSVFile(buffer, 2); } void createFoldersAndFiles() @@ -70,9 +70,9 @@ struct Fixture // maxhours files buffer.clear() << base_folder << SEP << hydro_folder << SEP << common_folder << SEP << capacity_folder; - my_string file1_name = maxhoursGen << SEP << area_2->id << SEP << ".txt"; - my_string file2_name = maxhoursPump << SEP << area_2->id << SEP << ".txt"; - my_string file3_name = maxpower << SEP << area_2->id << SEP << ".txt"; + my_string file1_name = maxhoursGen << SEP << area_1->id << SEP << ".txt"; + my_string file2_name = maxhoursPump << SEP << area_1->id << SEP << ".txt"; + my_string file3_name = maxpower << SEP << area_1->id << SEP << ".txt"; createFile(buffer, file1_name); createFile(buffer, file2_name); @@ -80,7 +80,7 @@ struct Fixture } shared_ptr study; - shared_ptr datatransfer; + shared_ptr reader; Area* area_1; Area* area_2; my_string base_folder = fs::current_path().string(); @@ -88,8 +88,8 @@ struct Fixture my_string series_folder = "series"; my_string common_folder = "common"; my_string capacity_folder = "capacity"; - my_string maxhoursGen = "maxHourlyGenEnergy_"; - my_string maxhoursPump = "maxHourlyPumpEnergy_"; + my_string maxhoursGen = "maxDailyGenEnergy_"; + my_string maxhoursPump = "maxDailyPumpEnergy_"; my_string maxpower = "maxpower_"; my_string maxgentxt = "maxHourlyGenPower.txt"; my_string maxpumptxt = "maxHourlyPumpPower.txt"; @@ -106,50 +106,16 @@ BOOST_FIXTURE_TEST_CASE(Testing_support_for_old_studies, Fixture) { my_string buffer; bool ret = false; + auto& colMaxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower[0]; + auto& colMaxHourlyPumpPower = area_1->hydro.series->maxHourlyPumpPower[0]; + auto& gen = reader->dailyMaxPumpAndGen[HydroMaxTimeSeriesReader::genMaxP]; + auto& pump = reader->dailyMaxPumpAndGen[HydroMaxTimeSeriesReader::pumpMaxP]; buffer.clear() << base_folder << SEP << hydro_folder; - ret = datatransfer->SupportForOldStudies(*study, buffer, *area_1); + ret = (*reader)(buffer, *area_1); BOOST_CHECK(ret); -} - -BOOST_FIXTURE_TEST_CASE(Testing_auto_transfer_hours, Fixture) -{ - my_string buffer; - bool ret = false; - - buffer.clear() << base_folder << SEP << hydro_folder; - ret = datatransfer->AutoTransferHours(*study, buffer, *area_2); - BOOST_CHECK(ret); -} - -BOOST_FIXTURE_TEST_CASE(Testing_load_from_folder_when_retuns_true, Fixture) -{ - my_string buffer; - bool ret = false; - datatransfer->dailyMaxPumpAndGen.reset(4, DAYS_PER_YEAR, true); - - buffer.clear() << base_folder << SEP << hydro_folder; - ret = datatransfer->LoadFromFolder(*study, buffer, *area_2); - BOOST_CHECK(ret); -} - -BOOST_FIXTURE_TEST_CASE(Testing_load_from_folder_when_retuns_false, Fixture) -{ - my_string buffer; - bool ret = false; - - auto& hoursGen = datatransfer->dailyMaxPumpAndGen[DataTransfer::genMaxE]; - InstantiateColumn(hoursGen, 25., DAYS_PER_YEAR); - - my_string file_name = "maxpower_" + area_2->id + ".txt"; - buffer.clear() << base_folder << SEP << hydro_folder << SEP << common_folder << SEP - << capacity_folder << SEP << file_name; - datatransfer->dailyMaxPumpAndGen.saveToCSVFile(buffer, 2); - datatransfer->dailyMaxPumpAndGen.reset(4, DAYS_PER_YEAR, true); - - buffer.clear() << base_folder << SEP << hydro_folder; - ret = datatransfer->LoadFromFolder(*study, buffer, *area_2); - BOOST_CHECK(!ret); + BOOST_CHECK(DailyMaxPowerAsHourlyTransferCheck(colMaxHourlyGenPower, gen)); + BOOST_CHECK(DailyMaxPowerAsHourlyTransferCheck(colMaxHourlyPumpPower, pump)); } BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/src/ui/action/handler/antares-study/area/timeseries.cpp b/src/ui/action/handler/antares-study/area/timeseries.cpp index 120241d616..d057b3b6fd 100644 --- a/src/ui/action/handler/antares-study/area/timeseries.cpp +++ b/src/ui/action/handler/antares-study/area/timeseries.cpp @@ -182,6 +182,8 @@ bool DataTimeseries::performWL(Context& ctx) source->hydro.series->maxHourlyGenPower.unloadFromMemory(); source->hydro.series->maxHourlyPumpPower.unloadFromMemory(); + + break; } case Data::timeSeriesThermal: { diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/area/hydromonthlypower.cpp b/src/ui/simulator/toolbox/components/datagrid/renderer/area/hydromonthlypower.cpp index d9519fd94b..39aa340833 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/area/hydromonthlypower.cpp +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/area/hydromonthlypower.cpp @@ -102,9 +102,9 @@ void HydroMonthlyHours::internalAreaChanged(Antares::Data::Area* area) Data::PartHydro* pHydro = (area) ? &(area->hydro) : nullptr; Renderer::ARendererArea::internalAreaChanged(area); if (pHydro && hoursType == HoursType::Generation) - MatrixAncestorType::matrix(&pHydro->maxHourlyGenEnergy); + MatrixAncestorType::matrix(&pHydro->maxDailyGenEnergy); else if (pHydro && hoursType == HoursType::Pumping) - MatrixAncestorType::matrix(&pHydro->maxHourlyPumpEnergy); + MatrixAncestorType::matrix(&pHydro->maxDailyPumpEnergy); else MatrixAncestorType::matrix(nullptr); } From 0f3d12c511a25c72fbf974416ab84894752d09b8 Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Wed, 27 Sep 2023 12:19:41 +0200 Subject: [PATCH 08/40] Refactoring --- src/libs/antares/study/area/list.cpp | 5 +- .../antares/study/parts/hydro/container.cpp | 61 +++++++++++-------- .../antares/study/parts/hydro/container.h | 4 +- .../parts/hydro/hydromaxtimeseriesreader.cpp | 2 +- .../parts/hydro/hydromaxtimeseriesreader.h | 2 +- 5 files changed, 43 insertions(+), 31 deletions(-) diff --git a/src/libs/antares/study/area/list.cpp b/src/libs/antares/study/area/list.cpp index befb62a315..941a9a0352 100644 --- a/src/libs/antares/study/area/list.cpp +++ b/src/libs/antares/study/area/list.cpp @@ -921,10 +921,11 @@ static bool AreaListLoadFromFolderSingleArea(Study& study, ret = area.hydro.series->LoadMaxPower(study, area.id, buffer) && ret; } + buffer.clear() << study.folderInput << SEP << "hydro" << SEP << "common" << SEP + << "capacity" << SEP << "maxpower_" << area.id << ".txt"; + if (bool exists = IO::File::Exists(buffer); study.header.version >= 870 && exists) { - buffer.clear() << study.folderInput << SEP << "hydro" << SEP << "common" << SEP - << "capacity" << SEP << "maxpower_" << area.id << ".txt"; IO::File::Delete(buffer); } diff --git a/src/libs/antares/study/parts/hydro/container.cpp b/src/libs/antares/study/parts/hydro/container.cpp index 020f3c7d95..7bb56dc9fa 100644 --- a/src/libs/antares/study/parts/hydro/container.cpp +++ b/src/libs/antares/study/parts/hydro/container.cpp @@ -151,37 +151,19 @@ bool PartHydro::LoadFromFolder(Study& study, const AnyString& folder) enabledModeIsChanged = true; } - ret = area.hydro.LoadDailyMaxEnergy(area, folder); + ret = area.hydro.LoadDailyMaxEnergy(folder, area.id) && ret; if (enabledModeIsChanged) JIT::enabled = true; // Back to the previous loading mode. } else { - ret = area.hydro.LoadDailyMaxEnergy(area, folder); + ret = area.hydro.LoadDailyMaxEnergy(folder, area.id) && ret; // Check is moved here, because in case of old study // maxDailyGenEnergy and maxDailyPumpEnergy are not yet initialized. - bool errorHours = false; - auto& colGen = area.hydro.maxDailyGenEnergy[0]; - auto& colPump = area.hydro.maxDailyPumpEnergy[0]; - for (int day = 0; day < DAYS_PER_YEAR; day++) - { - if (!errorHours && (colGen[day] < 0 || (colGen[day] > 24))) - { - logs.error() << area.name << ": invalid power or energy value"; - errorHours = true; - ret = false; - } - - if (!errorHours && (colPump[day] < 0 || (colPump[day] > 24))) - { - logs.error() << area.name << ": invalid power or energy value"; - errorHours = true; - ret = false; - } - } + ret = area.hydro.CheckDailyMaxEnergy(area.name) && ret; } } @@ -807,29 +789,56 @@ void PartHydro::copyFrom(const PartHydro& rhs) } } -bool PartHydro::LoadDailyMaxEnergy(Area& area, const AnyString& folder) +bool PartHydro::LoadDailyMaxEnergy(const AnyString& folder, const AnyString& areaid) { YString filePath; Matrix<>::BufferType fileContent; bool ret = true; filePath.clear() << folder << SEP << "common" << SEP << "capacity" << SEP - << "maxDailyGenEnergy_" << area.id << '.' << "txt"; + << "maxDailyGenEnergy_" << areaid << ".txt"; - ret = area.hydro.maxDailyGenEnergy.loadFromCSVFile( + ret = maxDailyGenEnergy.loadFromCSVFile( filePath, 1, DAYS_PER_YEAR, Matrix<>::optFixedSize, &fileContent) && ret; filePath.clear() << folder << SEP << "common" << SEP << "capacity" << SEP - << "maxDailyPumpEnergy_" << area.id << '.' << "txt"; + << "maxDailyPumpEnergy_" << areaid << ".txt"; - ret = area.hydro.maxDailyPumpEnergy.loadFromCSVFile( + ret = maxDailyPumpEnergy.loadFromCSVFile( filePath, 1, DAYS_PER_YEAR, Matrix<>::optFixedSize, &fileContent) && ret; return ret; } +bool PartHydro::CheckDailyMaxEnergy(const AnyString& areaName) +{ + bool ret = true; + bool errorEnergy = false; + auto& colGen = maxDailyGenEnergy[0]; + auto& colPump = maxDailyPumpEnergy[0]; + + for (int day = 0; day < DAYS_PER_YEAR; day++) + { + if (!errorEnergy && (colGen[day] < 0 || (colGen[day] > 24))) + { + logs.error() << areaName << ": invalid maximum generation energy value"; + errorEnergy = true; + ret = false; + } + + if (!errorEnergy && (colPump[day] < 0 || (colPump[day] > 24))) + { + logs.error() << areaName << ": invalid maximum pumping energy value"; + errorEnergy = true; + ret = false; + } + } + + return ret; +} + void getWaterValue(const double& level /* format : in % of reservoir capacity */, const Matrix& waterValues, const uint day, diff --git a/src/libs/antares/study/parts/hydro/container.h b/src/libs/antares/study/parts/hydro/container.h index 72cf0b0f61..26171655e3 100644 --- a/src/libs/antares/study/parts/hydro/container.h +++ b/src/libs/antares/study/parts/hydro/container.h @@ -102,7 +102,9 @@ class PartHydro /*! ** \brief Load daily max energy */ - bool LoadDailyMaxEnergy(Area& area, const AnyString& folder); + bool LoadDailyMaxEnergy(const AnyString& folder, const AnyString& areaid); + + bool CheckDailyMaxEnergy(const AnyString& areaName); public: //! Inter-daily breakdown (previously called Smoothing Factor or alpha) diff --git a/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.cpp b/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.cpp index 23e2583312..6eb5605207 100644 --- a/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.cpp +++ b/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.cpp @@ -41,7 +41,7 @@ HydroMaxTimeSeriesReader::HydroMaxTimeSeriesReader() dailyMaxPumpAndGen.reset(4, DAYS_PER_YEAR, true); } -bool HydroMaxTimeSeriesReader::LoadDailyMaxPowersAndEnergies(const AnyString& folder, Area& area) +bool HydroMaxTimeSeriesReader::LoadDailyMaxPowersAndEnergies(const AnyString& folder, const Area& area) { YString filePath; Matrix<>::BufferType fileContent; diff --git a/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.h b/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.h index 41dedaf8d5..f3e0582d49 100644 --- a/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.h +++ b/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.h @@ -59,7 +59,7 @@ class HydroMaxTimeSeriesReader }; private: - bool LoadDailyMaxPowersAndEnergies(const AnyString& folder, Area& area); + bool LoadDailyMaxPowersAndEnergies(const AnyString& folder, const Area& area); bool SaveDailyMaxEnergy(const AnyString& folder, Area& area); bool SaveDailyMaxPowerAsHourly(const AnyString& folder, Area& area); bool SaveMaxGenerationEnergy(const AnyString& folder, Area& area); From dae8e69d7aa614d0ed1dddfe019dccd0d41b8ea2 Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Thu, 28 Sep 2023 00:52:27 +0200 Subject: [PATCH 09/40] New LoadMaxPower function --- src/libs/antares/study/area/list.cpp | 13 +- .../parts/hydro/hydromaxtimeseriesreader.cpp | 1 + src/libs/antares/study/parts/hydro/series.cpp | 248 +++++++++++------- src/libs/antares/study/parts/hydro/series.h | 40 ++- .../antares/study/parts/hydro/CMakeLists.txt | 3 + .../study/parts/hydro/test-hydro-series.cpp | 156 +++++++---- 6 files changed, 311 insertions(+), 150 deletions(-) diff --git a/src/libs/antares/study/area/list.cpp b/src/libs/antares/study/area/list.cpp index 941a9a0352..3c55028789 100644 --- a/src/libs/antares/study/area/list.cpp +++ b/src/libs/antares/study/area/list.cpp @@ -915,10 +915,19 @@ static bool AreaListLoadFromFolderSingleArea(Study& study, ret = reader(buffer, area) && ret; } - if (area.hydro.series) + if (area.hydro.series && study.header.version >= 870) { buffer.clear() << study.folderInput << SEP << "hydro" << SEP << "series"; - ret = area.hydro.series->LoadMaxPower(study, area.id, buffer) && ret; + ret = area.hydro.series->LoadMaxPower(area.id, buffer) && ret; + + if (study.usedByTheSolver) + { + area.hydro.series->setCountVariable(); + ret = area.hydro.series->postProcessMaxPowerTS(area) && ret; + area.hydro.series->setMaxPowerTSWhenDeratedMode(study); + } + else + area.hydro.series->setHydroModulability(study, area.id); } buffer.clear() << study.folderInput << SEP << "hydro" << SEP << "common" << SEP diff --git a/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.cpp b/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.cpp index 6eb5605207..a3d092e152 100644 --- a/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.cpp +++ b/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.cpp @@ -140,6 +140,7 @@ bool HydroMaxTimeSeriesReader::SaveDailyMaxPowerAsHourly(const AnyString& folder ret = SaveDailyMaxGenPowerAsHourly(folder, area) && ret; ret = SaveDailyMaxPumpPowerAsHourly(folder, area) && ret; + area.hydro.series->setCountVariable(); return ret; } diff --git a/src/libs/antares/study/parts/hydro/series.cpp b/src/libs/antares/study/parts/hydro/series.cpp index 65d0bf995b..17cab13604 100644 --- a/src/libs/antares/study/parts/hydro/series.cpp +++ b/src/libs/antares/study/parts/hydro/series.cpp @@ -199,100 +199,6 @@ void DataSeriesHydro::checkMinGenTsNumber(Study& study, const AreaName& areaID) } } -bool DataSeriesHydro::LoadMaxPower(Study& study, const AreaName& areaID, const AnyString& folder) -{ - bool ret = true; - auto& buffer = study.bufferLoadingTS; - - if (study.header.version >= 870) - { - buffer.clear() << folder << SEP << areaID << SEP << "maxHourlyGenPower." << study.inputExtension; - ret = maxHourlyGenPower.loadFromCSVFile(buffer, 1, HOURS_PER_YEAR, &study.dataBuffer) && ret; - buffer.clear() << folder << SEP << areaID << SEP << "maxHourlyPumpPower." << study.inputExtension; - ret = maxHourlyPumpPower.loadFromCSVFile(buffer, 1, HOURS_PER_YEAR, &study.dataBuffer) && ret; - } - - countpowercredits = maxHourlyGenPower.width; - - if (maxHourlyPumpPower.width > countpowercredits) - countpowercredits = maxHourlyPumpPower.width; - - if (study.usedByTheSolver) - { - if (countpowercredits == 0) - { - logs.error() << "Hydro Max Power: `" << areaID - << "`: empty matrix detected. Fixing it with default values"; - - maxHourlyGenPower.reset(1, HOURS_PER_YEAR); - maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); - } - else - { - if (countpowercredits > 1 && maxHourlyGenPower.width != maxHourlyPumpPower.width) - { - if (maxHourlyPumpPower.width != 1 && maxHourlyGenPower.width != 1) - { - logs.fatal() << "Hydro Max Power: `" << areaID - << "`: The matrices Maximum Generation and Maximum Pumping must " - "have the same number of time-series."; - study.gotFatalError = true; - } - else - { - if (maxHourlyPumpPower.width == 1) - { - maxHourlyPumpPower.resizeWithoutDataLost(countpowercredits, maxHourlyPumpPower.height); - for (uint x = 1; x < countpowercredits; ++x) - maxHourlyPumpPower.pasteToColumn(x, maxHourlyPumpPower[0]); - } - else - { - if (maxHourlyGenPower.width == 1) - { - maxHourlyGenPower.resizeWithoutDataLost(countpowercredits, maxHourlyGenPower.height); - for (uint x = 1; x < countpowercredits; ++x) - maxHourlyGenPower.pasteToColumn(x, maxHourlyGenPower[0]); - } - } - Area* areaToInvalidate = study.areas.find(areaID); - if (areaToInvalidate) - { - areaToInvalidate->invalidateJIT = true; - logs.info() << " '" << areaID - << "': The hydro max power data have been normalized to " - << countpowercredits << " timeseries"; - } - else - logs.error() - << "Impossible to find the area `" << areaID << "` to invalidate it"; - } - } - } - - if (study.parameters.derated) - { - maxHourlyGenPower.averageTimeseries(); - maxHourlyPumpPower.averageTimeseries(); - countpowercredits = 1; - } - } - else - { - // Is area hydro modulable ? - Area* area = study.areas.find(areaID); - - if (MatrixTestForAtLeastOnePositiveValue(maxHourlyGenPower)) - { - area->hydro.hydroModulable = true; - } - } - - timeseriesNumbersHydroMaxPower.clear(); - - return ret; -} - bool DataSeriesHydro::forceReload(bool reload) const { bool ret = true; @@ -329,5 +235,159 @@ uint64_t DataSeriesHydro::memoryUsage() const return sizeof(double) + ror.memoryUsage() + storage.memoryUsage() + mingen.memoryUsage() + maxHourlyGenPower.memoryUsage() + maxHourlyPumpPower.memoryUsage(); } + +bool DataSeriesHydro::LoadMaxPower(const AreaName& areaID, const AnyString& folder) +{ + bool ret = true; + YString filepath; + Matrix<>::BufferType fileContent; + + filepath.clear() << folder << SEP << areaID << SEP << "maxHourlyGenPower" + << ".txt"; + ret = maxHourlyGenPower.loadFromCSVFile(filepath, 1, HOURS_PER_YEAR, &fileContent) && ret; + filepath.clear() << folder << SEP << areaID << SEP << "maxHourlyPumpPower" + << ".txt"; + ret = maxHourlyPumpPower.loadFromCSVFile(filepath, 1, HOURS_PER_YEAR, &fileContent) && ret; + + timeseriesNumbersHydroMaxPower.clear(); + + return ret; +} + +bool DataSeriesHydro::postProcessMaxPowerTS(Area& area) +{ + NbTsComparer nbTSCompare(maxHourlyGenPower.width, maxHourlyPumpPower.width); + TsActions tsActions(maxHourlyGenPower, maxHourlyPumpPower); + // What will happen if one width is 0 and second one is 1 + // This case is not cover even in previous version + if (nbTSCompare.bothZeros()) + { + tsActions.handleBothZeros(area.id); + return false; + } + + if (nbTSCompare.same()) + return true; + + if (nbTSCompare.differentAndGreaterThanOne(countpowercredits)) + { + tsActions.handleBothGreaterThanOne(area.id); + return false; + } + + tsActions.resizeWhenOneTS(area, countpowercredits); + + return true; +} + +void DataSeriesHydro::setHydroModulability(Study& study, const AreaName& areaID) +{ + Area* area = study.areas.find(areaID); + + if (MatrixTestForAtLeastOnePositiveValue(maxHourlyGenPower)) + { + area->hydro.hydroModulable = true; + } +} + +void DataSeriesHydro::setCountVariable() +{ + auto& maxHourlyGenPower_ = maxHourlyGenPower.width; + auto& maxHourlyPumpPower_ = maxHourlyPumpPower.width; + + countpowercredits + = (maxHourlyGenPower_ >= maxHourlyPumpPower_) ? maxHourlyGenPower_ : maxHourlyPumpPower_; +} + +void DataSeriesHydro::setMaxPowerTSWhenDeratedMode(Study& study) +{ + if (study.parameters.derated) + { + maxHourlyGenPower.averageTimeseries(); + maxHourlyPumpPower.averageTimeseries(); + countpowercredits = 1; + } +} + +DataSeriesHydro::NbTsComparer::NbTsComparer(uint32_t nbOfGenPowerTs_, uint32_t nbOfPumpPowerTs_) : + nbOfGenPowerTs(nbOfGenPowerTs_), nbOfPumpPowerTs(nbOfPumpPowerTs_) +{ +} + +bool DataSeriesHydro::NbTsComparer::bothZeros() +{ + return (nbOfGenPowerTs || nbOfPumpPowerTs) ? false : true; +} + +bool DataSeriesHydro::NbTsComparer::same() +{ + return (nbOfGenPowerTs == nbOfPumpPowerTs) ? true : false; +} + +bool DataSeriesHydro::NbTsComparer::differentAndGreaterThanOne(uint countpowercredits_) +{ + return (countpowercredits_ > 1 && (nbOfGenPowerTs != 1) && (nbOfPumpPowerTs != 1)) ? true + : false; +} + +DataSeriesHydro::TsActions::TsActions(Matrix& maxHourlyGenPower_, + Matrix& maxHourlyPumpPower_) : + maxHourlyGenPower(maxHourlyGenPower_), maxHourlyPumpPower(maxHourlyPumpPower_) +{ +} + +void DataSeriesHydro::TsActions::handleBothZeros(const AreaName& areaID) +{ + logs.error() << "Hydro Max Power: `" << areaID + << "`: empty matrix detected. Fixing it with default values"; + + maxHourlyGenPower.reset(1, HOURS_PER_YEAR); + maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); +} + +void DataSeriesHydro::TsActions::handleBothGreaterThanOne(const AreaName& areaID) +{ + logs.fatal() << "Hydro Max Power: `" << areaID + << "`: The matrices Maximum Generation and Maximum Pumping must " + "have the same number of time-series."; + throw Error::ReadingStudy(); +} + +void DataSeriesHydro::TsActions::resizeWhenOneTS(Area& area, uint countpowercredits) +{ + if (maxHourlyGenPower.width == 1) + { + resizeMatrixNoDataLoss(maxHourlyGenPower, countpowercredits); + areaToInvalidate(&area, countpowercredits); + return; + } + + if (maxHourlyPumpPower.width == 1) + { + resizeMatrixNoDataLoss(maxHourlyPumpPower, countpowercredits); + areaToInvalidate(&area, countpowercredits); + return; + } +} + +void DataSeriesHydro::TsActions::areaToInvalidate(Area* area, uint countpowercredits) +{ + if (area) + { + area->invalidateJIT = true; + logs.info() << " '" << area->id << "': The hydro max power data have been normalized to " + << countpowercredits << " timeseries"; + } + else + logs.error() << "Impossible to find the area `" << area->id << "` to invalidate it"; +} + +void resizeMatrixNoDataLoss(Matrix& matrixToResize, uint width) +{ + matrixToResize.resizeWithoutDataLost(width, matrixToResize.height); + for (uint x = 1; x < width; ++x) + matrixToResize.pasteToColumn(x, matrixToResize[0]); +} + } // namespace Data } // namespace Antares diff --git a/src/libs/antares/study/parts/hydro/series.h b/src/libs/antares/study/parts/hydro/series.h index 944c9495a6..fb079c117c 100644 --- a/src/libs/antares/study/parts/hydro/series.h +++ b/src/libs/antares/study/parts/hydro/series.h @@ -29,6 +29,7 @@ #include #include "../../fwd.h" +#include namespace Antares { @@ -168,10 +169,47 @@ class DataSeriesHydro */ Matrix timeseriesNumbers; Matrix timeseriesNumbersHydroMaxPower; - bool LoadMaxPower(Study& study, const AreaName& areaID, const AnyString& folder); + bool LoadMaxPower(const AreaName& areaID, const AnyString& folder); + bool postProcessMaxPowerTS(Area& area); + void setHydroModulability(Study& study, const AreaName& areaID); + void setCountVariable(); + void setMaxPowerTSWhenDeratedMode(Study& study); + + class NbTsComparer + { + public: + NbTsComparer(uint32_t nbOfGenPowerTs_, uint32_t nbOfPumpPowerTs_); + + bool bothZeros(); + bool same(); + bool differentAndGreaterThanOne(uint countpowercredits_); + + private: + uint32_t nbOfGenPowerTs{0}; + uint32_t nbOfPumpPowerTs{0}; + }; + + class TsActions + { + public: + TsActions(Matrix& maxHourlyGenPower_, + Matrix& maxHourlyPumpPower_); + + void handleBothZeros(const AreaName& areaID); + void handleBothGreaterThanOne(const AreaName& areaID); + void resizeWhenOneTS(Area& area, uint countpowercredits); + + private: + Matrix& maxHourlyGenPower; + Matrix& maxHourlyPumpPower; + + void areaToInvalidate(Area* area, uint countpowercredits); + }; }; // class DataSeriesHydro +void resizeMatrixNoDataLoss(Matrix& maxHourlyGenPower, uint width); + } // namespace Data } // namespace Antares diff --git a/src/tests/src/libs/antares/study/parts/hydro/CMakeLists.txt b/src/tests/src/libs/antares/study/parts/hydro/CMakeLists.txt index 8f32cde1c4..19fdde366b 100644 --- a/src/tests/src/libs/antares/study/parts/hydro/CMakeLists.txt +++ b/src/tests/src/libs/antares/study/parts/hydro/CMakeLists.txt @@ -52,6 +52,8 @@ target_include_directories(test-hydro-series "${src_libs_antares_study}" "${src_libs_antares_study}/parts/hydro" "${src_libs_antares}/array/antares/array" + "${src_libs_antares}/array/antares/array" + "${src_libs_antares}/exception/antares/exception" ) target_link_libraries(test-hydro-series @@ -61,6 +63,7 @@ target_link_libraries(test-hydro-series model_antares antares-solver-hydro yuni-static-core + exception ) # Linux diff --git a/src/tests/src/libs/antares/study/parts/hydro/test-hydro-series.cpp b/src/tests/src/libs/antares/study/parts/hydro/test-hydro-series.cpp index 3a838fefc1..5028805553 100644 --- a/src/tests/src/libs/antares/study/parts/hydro/test-hydro-series.cpp +++ b/src/tests/src/libs/antares/study/parts/hydro/test-hydro-series.cpp @@ -5,6 +5,7 @@ #include #include "help-functions.h" #include +#include struct Fixture { @@ -12,15 +13,10 @@ struct Fixture { // Create studies study = make_shared(true); - study->inputExtension = "txt"; - studyNoSolver = make_shared(); - studyNoSolver->inputExtension = "txt"; // Add areas to studies area_1 = study->areaAdd("Area1"); study->areas.rebuildIndexes(); - area_No_Solver = studyNoSolver->areaAdd("AreaNoSolver"); - studyNoSolver->areas.rebuildIndexes(); // Create necessary folders and files for these two areas createFoldersAndFiles(); @@ -28,9 +24,6 @@ struct Fixture // Instantiating neccessary studies parameters study->header.version = 870; study->parameters.derated = false; - - studyNoSolver->header.version = 870; - studyNoSolver->parameters.derated = false; } void createFoldersAndFiles() @@ -41,30 +34,21 @@ struct Fixture // areas folder my_string area1_folder = area_1->id; - my_string area_No_Solver_folder = area_No_Solver->id; buffer.clear() << base_folder << SEP << series_folder; createFolder(buffer, area1_folder); - createFolder(buffer, area_No_Solver_folder); // maxHourlyGenPower and maxHourlyPumpPower files buffer.clear() << base_folder << SEP << series_folder << SEP << area1_folder; - createFile(buffer, maxgentxt); - createFile(buffer, maxpumptxt); - - // maxHourlyGenPower and maxHourlyPumpPower files - buffer.clear() << base_folder << SEP << series_folder << SEP << area_No_Solver_folder; - createFile(buffer, maxgentxt); - createFile(buffer, maxpumptxt); + createFile(buffer, maxHourlyGenPower_file); + createFile(buffer, maxHourlyPumpPower_file); } shared_ptr study; - shared_ptr studyNoSolver; Area* area_1; - Area* area_No_Solver; my_string base_folder = fs::current_path().string(); my_string series_folder = "series"; - my_string maxgentxt = "maxHourlyGenPower.txt"; - my_string maxpumptxt = "maxHourlyPumpPower.txt"; + my_string maxHourlyGenPower_file = "maxHourlyGenPower.txt"; + my_string maxHourlyPumpPower_file = "maxHourlyPumpPower.txt"; ~Fixture() { @@ -74,7 +58,7 @@ struct Fixture BOOST_AUTO_TEST_SUITE(s) -BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_both_matrix_equal_width, Fixture) +BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_matrices_equal_width, Fixture) { bool ret = false; auto& maxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower; @@ -86,98 +70,164 @@ BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_both_matrix_equal_width, Fixt InstantiateMatrix(maxHourlyPumpPower, 200., HOURS_PER_YEAR); my_string buffer; - buffer.clear() << base_folder << SEP << series_folder << SEP << area_1->id << SEP << maxgentxt; + buffer.clear() << base_folder << SEP << series_folder << SEP << area_1->id << SEP << maxHourlyGenPower_file; maxHourlyGenPower.saveToCSVFile(buffer, 0); - buffer.clear() << base_folder << SEP << series_folder << SEP << area_1->id << SEP << maxpumptxt; + buffer.clear() << base_folder << SEP << series_folder << SEP << area_1->id << SEP << maxHourlyPumpPower_file; maxHourlyPumpPower.saveToCSVFile(buffer, 0); maxHourlyGenPower.reset(3, HOURS_PER_YEAR); maxHourlyPumpPower.reset(3, HOURS_PER_YEAR); buffer.clear() << base_folder << SEP << series_folder; - ret = area_1->hydro.series->LoadMaxPower(*study, area_1->id, buffer); + ret = area_1->hydro.series->LoadMaxPower(area_1->id, buffer); + area_1->hydro.series->setCountVariable(); + ret = area_1->hydro.series->postProcessMaxPowerTS(*area_1) && ret; BOOST_CHECK(ret); + BOOST_CHECK_EQUAL(maxHourlyGenPower.width, 3); } -BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_matrices_different_width_case_1, Fixture) +BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_both_matrix_equal_width_and_derated, Fixture) { - bool ret = false; + bool ret = true; + study->parameters.derated = true; auto& maxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower; auto& maxHourlyPumpPower = area_1->hydro.series->maxHourlyPumpPower; - maxHourlyGenPower.reset(1, HOURS_PER_YEAR); + maxHourlyGenPower.reset(3, HOURS_PER_YEAR); maxHourlyPumpPower.reset(3, HOURS_PER_YEAR); InstantiateMatrix(maxHourlyGenPower, 400., HOURS_PER_YEAR); InstantiateMatrix(maxHourlyPumpPower, 200., HOURS_PER_YEAR); my_string buffer; - buffer.clear() << base_folder << SEP << series_folder << SEP << area_1->id << SEP << maxgentxt; + buffer.clear() << base_folder << SEP << series_folder << SEP << area_1->id << SEP << maxHourlyGenPower_file; maxHourlyGenPower.saveToCSVFile(buffer, 0); - buffer.clear() << base_folder << SEP << series_folder << SEP << area_1->id << SEP << maxpumptxt; + buffer.clear() << base_folder << SEP << series_folder << SEP << area_1->id << SEP << maxHourlyPumpPower_file; maxHourlyPumpPower.saveToCSVFile(buffer, 0); - maxHourlyGenPower.reset(1, HOURS_PER_YEAR); + maxHourlyGenPower.reset(3, HOURS_PER_YEAR); maxHourlyPumpPower.reset(3, HOURS_PER_YEAR); buffer.clear() << base_folder << SEP << series_folder; - ret = area_1->hydro.series->LoadMaxPower(*study, area_1->id, buffer); + ret = area_1->hydro.series->LoadMaxPower(area_1->id, buffer) && ret; + ret = area_1->hydro.series->postProcessMaxPowerTS(*area_1) && ret; + area_1->hydro.series->setMaxPowerTSWhenDeratedMode(*study); + BOOST_CHECK_EQUAL(maxHourlyGenPower.width, 1); + BOOST_CHECK_EQUAL(maxHourlyPumpPower.width, 1); BOOST_CHECK(ret); - BOOST_CHECK_EQUAL(maxHourlyGenPower.width, 3); } BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_matrices_different_width_case_2, Fixture) { - bool ret = false; + bool ret = true; auto& maxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower; auto& maxHourlyPumpPower = area_1->hydro.series->maxHourlyPumpPower; maxHourlyGenPower.reset(3, HOURS_PER_YEAR); - maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); + maxHourlyPumpPower.reset(2, HOURS_PER_YEAR); InstantiateMatrix(maxHourlyGenPower, 400., HOURS_PER_YEAR); InstantiateMatrix(maxHourlyPumpPower, 200., HOURS_PER_YEAR); my_string buffer; - buffer.clear() << base_folder << SEP << series_folder << SEP << area_1->id << SEP << maxgentxt; + buffer.clear() << base_folder << SEP << series_folder << SEP << area_1->id << SEP << maxHourlyGenPower_file; maxHourlyGenPower.saveToCSVFile(buffer, 0); - buffer.clear() << base_folder << SEP << series_folder << SEP << area_1->id << SEP << maxpumptxt; + buffer.clear() << base_folder << SEP << series_folder << SEP << area_1->id << SEP << maxHourlyPumpPower_file; maxHourlyPumpPower.saveToCSVFile(buffer, 0); maxHourlyGenPower.reset(3, HOURS_PER_YEAR); - maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); + maxHourlyPumpPower.reset(2, HOURS_PER_YEAR); buffer.clear() << base_folder << SEP << series_folder; - ret = area_1->hydro.series->LoadMaxPower(*study, area_1->id, buffer); + ret = area_1->hydro.series->LoadMaxPower(area_1->id, buffer); + area_1->hydro.series->setCountVariable(); BOOST_CHECK(ret); - BOOST_CHECK_EQUAL(maxHourlyPumpPower.width, 3); + BOOST_CHECK_THROW(area_1->hydro.series->postProcessMaxPowerTS(*area_1), Error::ReadingStudy); } -BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_no_solver, Fixture) +BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_different_width_case_1, Fixture) { - bool ret = false; - auto& maxHourlyGenPower = area_No_Solver->hydro.series->maxHourlyGenPower; - auto& maxHourlyPumpPower = area_No_Solver->hydro.series->maxHourlyPumpPower; - maxHourlyGenPower.reset(3, HOURS_PER_YEAR); + bool ret = true; + auto& maxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower; + auto& maxHourlyPumpPower = area_1->hydro.series->maxHourlyPumpPower; + maxHourlyGenPower.reset(1, HOURS_PER_YEAR); maxHourlyPumpPower.reset(3, HOURS_PER_YEAR); InstantiateMatrix(maxHourlyGenPower, 400., HOURS_PER_YEAR); InstantiateMatrix(maxHourlyPumpPower, 200., HOURS_PER_YEAR); my_string buffer; - buffer.clear() << base_folder << SEP << series_folder << SEP << area_No_Solver->id << SEP - << maxgentxt; + buffer.clear() << base_folder << SEP << series_folder << SEP << area_1->id << SEP << maxHourlyGenPower_file; maxHourlyGenPower.saveToCSVFile(buffer, 0); - buffer.clear() << base_folder << SEP << series_folder << SEP << area_No_Solver->id << SEP - << maxpumptxt; + buffer.clear() << base_folder << SEP << series_folder << SEP << area_1->id << SEP << maxHourlyPumpPower_file; maxHourlyPumpPower.saveToCSVFile(buffer, 0); - maxHourlyGenPower.reset(3, HOURS_PER_YEAR); + maxHourlyGenPower.reset(1, HOURS_PER_YEAR); maxHourlyPumpPower.reset(3, HOURS_PER_YEAR); buffer.clear() << base_folder << SEP << series_folder; - ret = area_No_Solver->hydro.series->LoadMaxPower( - *studyNoSolver, area_No_Solver->id, buffer); + ret = area_1->hydro.series->LoadMaxPower(area_1->id, buffer); + area_1->hydro.series->setCountVariable(); + ret = area_1->hydro.series->postProcessMaxPowerTS(*area_1) && ret; + BOOST_CHECK(ret); + BOOST_CHECK_EQUAL(maxHourlyGenPower.width, maxHourlyPumpPower.width); +} + +BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_different_width_case_2, Fixture) +{ + bool ret = true; + auto& maxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower; + auto& maxHourlyPumpPower = area_1->hydro.series->maxHourlyPumpPower; + maxHourlyGenPower.reset(4, HOURS_PER_YEAR); + maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); + + InstantiateMatrix(maxHourlyGenPower, 400., HOURS_PER_YEAR); + InstantiateMatrix(maxHourlyPumpPower, 200., HOURS_PER_YEAR); + + my_string buffer; + buffer.clear() << base_folder << SEP << series_folder << SEP << area_1->id << SEP << maxHourlyGenPower_file; + maxHourlyGenPower.saveToCSVFile(buffer, 0); + buffer.clear() << base_folder << SEP << series_folder << SEP << area_1->id << SEP << maxHourlyPumpPower_file; + maxHourlyPumpPower.saveToCSVFile(buffer, 0); + + maxHourlyGenPower.reset(4, HOURS_PER_YEAR); + maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); + + buffer.clear() << base_folder << SEP << series_folder; + ret = area_1->hydro.series->LoadMaxPower(area_1->id, buffer); + area_1->hydro.series->setCountVariable(); + ret = area_1->hydro.series->postProcessMaxPowerTS(*area_1) && ret; BOOST_CHECK(ret); - BOOST_CHECK(area_No_Solver->hydro.hydroModulable); + BOOST_CHECK_EQUAL(maxHourlyGenPower.width, maxHourlyPumpPower.width); +} + +BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_both_zeros, Fixture) +{ + bool ret = true; + auto& maxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower; + auto& maxHourlyPumpPower = area_1->hydro.series->maxHourlyPumpPower; + maxHourlyGenPower.reset(4, HOURS_PER_YEAR); + maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); + + InstantiateMatrix(maxHourlyGenPower, 400., HOURS_PER_YEAR); + InstantiateMatrix(maxHourlyPumpPower, 200., HOURS_PER_YEAR); + + my_string buffer; + buffer.clear() << base_folder << SEP << series_folder << SEP << area_1->id << SEP << maxHourlyGenPower_file; + maxHourlyGenPower.saveToCSVFile(buffer, 0); + buffer.clear() << base_folder << SEP << series_folder << SEP << area_1->id << SEP << maxHourlyPumpPower_file; + maxHourlyPumpPower.saveToCSVFile(buffer, 0); + + maxHourlyGenPower.reset(4, HOURS_PER_YEAR); + maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); + + buffer.clear() << base_folder << SEP << series_folder; + ret = area_1->hydro.series->LoadMaxPower(area_1->id, buffer); + area_1->hydro.series->setCountVariable(); + maxHourlyGenPower.width = 0; + maxHourlyPumpPower.width = 0; + ret = area_1->hydro.series->postProcessMaxPowerTS(*area_1) && ret; + BOOST_CHECK(!ret); + BOOST_CHECK_EQUAL(maxHourlyGenPower.width, maxHourlyPumpPower.width); } + BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file From c5e49215d5d259eadb67bbc2c30a8b4f930ab5c1 Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Thu, 28 Sep 2023 02:33:43 +0200 Subject: [PATCH 10/40] bugfix --- src/libs/antares/study/parts/hydro/series.cpp | 32 ++++++++++--------- src/libs/antares/study/parts/hydro/series.h | 16 +++++----- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/libs/antares/study/parts/hydro/series.cpp b/src/libs/antares/study/parts/hydro/series.cpp index 17cab13604..3b8ccdfb16 100644 --- a/src/libs/antares/study/parts/hydro/series.cpp +++ b/src/libs/antares/study/parts/hydro/series.cpp @@ -280,7 +280,7 @@ bool DataSeriesHydro::postProcessMaxPowerTS(Area& area) return true; } -void DataSeriesHydro::setHydroModulability(Study& study, const AreaName& areaID) +void DataSeriesHydro::setHydroModulability(Study& study, const AreaName& areaID) const { Area* area = study.areas.find(areaID); @@ -292,14 +292,14 @@ void DataSeriesHydro::setHydroModulability(Study& study, const AreaName& areaID) void DataSeriesHydro::setCountVariable() { - auto& maxHourlyGenPower_ = maxHourlyGenPower.width; - auto& maxHourlyPumpPower_ = maxHourlyPumpPower.width; + const auto& maxHourlyGenPower_ = maxHourlyGenPower.width; + const auto& maxHourlyPumpPower_ = maxHourlyPumpPower.width; countpowercredits = (maxHourlyGenPower_ >= maxHourlyPumpPower_) ? maxHourlyGenPower_ : maxHourlyPumpPower_; } -void DataSeriesHydro::setMaxPowerTSWhenDeratedMode(Study& study) +void DataSeriesHydro::setMaxPowerTSWhenDeratedMode(const Study& study) { if (study.parameters.derated) { @@ -314,17 +314,17 @@ DataSeriesHydro::NbTsComparer::NbTsComparer(uint32_t nbOfGenPowerTs_, uint32_t n { } -bool DataSeriesHydro::NbTsComparer::bothZeros() +bool DataSeriesHydro::NbTsComparer::bothZeros() const { return (nbOfGenPowerTs || nbOfPumpPowerTs) ? false : true; } -bool DataSeriesHydro::NbTsComparer::same() +bool DataSeriesHydro::NbTsComparer::same() const { return (nbOfGenPowerTs == nbOfPumpPowerTs) ? true : false; } -bool DataSeriesHydro::NbTsComparer::differentAndGreaterThanOne(uint countpowercredits_) +bool DataSeriesHydro::NbTsComparer::differentAndGreaterThanOne(uint countpowercredits_) const { return (countpowercredits_ > 1 && (nbOfGenPowerTs != 1) && (nbOfPumpPowerTs != 1)) ? true : false; @@ -345,7 +345,7 @@ void DataSeriesHydro::TsActions::handleBothZeros(const AreaName& areaID) maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); } -void DataSeriesHydro::TsActions::handleBothGreaterThanOne(const AreaName& areaID) +[[noreturn]] void DataSeriesHydro::TsActions::handleBothGreaterThanOne(const AreaName& areaID) const { logs.fatal() << "Hydro Max Power: `" << areaID << "`: The matrices Maximum Generation and Maximum Pumping must " @@ -353,24 +353,26 @@ void DataSeriesHydro::TsActions::handleBothGreaterThanOne(const AreaName& areaID throw Error::ReadingStudy(); } -void DataSeriesHydro::TsActions::resizeWhenOneTS(Area& area, uint countpowercredits) +void DataSeriesHydro::TsActions::resizeWhenOneTS(Area& area, uint countpowercredits_) { if (maxHourlyGenPower.width == 1) { - resizeMatrixNoDataLoss(maxHourlyGenPower, countpowercredits); - areaToInvalidate(&area, countpowercredits); + resizeMatrixNoDataLoss(maxHourlyGenPower, countpowercredits_); + areaToInvalidate(&area, area.id, countpowercredits_); return; } if (maxHourlyPumpPower.width == 1) { - resizeMatrixNoDataLoss(maxHourlyPumpPower, countpowercredits); - areaToInvalidate(&area, countpowercredits); + resizeMatrixNoDataLoss(maxHourlyPumpPower, countpowercredits_); + areaToInvalidate(&area, area.id, countpowercredits_); return; } } -void DataSeriesHydro::TsActions::areaToInvalidate(Area* area, uint countpowercredits) +void DataSeriesHydro::TsActions::areaToInvalidate(Area* area, + const AreaName& areaID, + uint countpowercredits) const { if (area) { @@ -379,7 +381,7 @@ void DataSeriesHydro::TsActions::areaToInvalidate(Area* area, uint countpowercre << countpowercredits << " timeseries"; } else - logs.error() << "Impossible to find the area `" << area->id << "` to invalidate it"; + logs.error() << "Impossible to find the area `" << areaID << "` to invalidate it"; } void resizeMatrixNoDataLoss(Matrix& matrixToResize, uint width) diff --git a/src/libs/antares/study/parts/hydro/series.h b/src/libs/antares/study/parts/hydro/series.h index fb079c117c..de03c526d2 100644 --- a/src/libs/antares/study/parts/hydro/series.h +++ b/src/libs/antares/study/parts/hydro/series.h @@ -171,18 +171,18 @@ class DataSeriesHydro Matrix timeseriesNumbersHydroMaxPower; bool LoadMaxPower(const AreaName& areaID, const AnyString& folder); bool postProcessMaxPowerTS(Area& area); - void setHydroModulability(Study& study, const AreaName& areaID); + void setHydroModulability(Study& study, const AreaName& areaID) const; void setCountVariable(); - void setMaxPowerTSWhenDeratedMode(Study& study); + void setMaxPowerTSWhenDeratedMode(const Study& study); class NbTsComparer { public: NbTsComparer(uint32_t nbOfGenPowerTs_, uint32_t nbOfPumpPowerTs_); - bool bothZeros(); - bool same(); - bool differentAndGreaterThanOne(uint countpowercredits_); + bool bothZeros() const; + bool same() const; + bool differentAndGreaterThanOne(uint countpowercredits_) const; private: uint32_t nbOfGenPowerTs{0}; @@ -196,14 +196,14 @@ class DataSeriesHydro Matrix& maxHourlyPumpPower_); void handleBothZeros(const AreaName& areaID); - void handleBothGreaterThanOne(const AreaName& areaID); - void resizeWhenOneTS(Area& area, uint countpowercredits); + [[noreturn]] void handleBothGreaterThanOne(const AreaName& areaID) const; + void resizeWhenOneTS(Area& area, uint countpowercredits_); private: Matrix& maxHourlyGenPower; Matrix& maxHourlyPumpPower; - void areaToInvalidate(Area* area, uint countpowercredits); + void areaToInvalidate(Area* area, const AreaName& areaID, uint countpowercredits_) const; }; }; // class DataSeriesHydro From 318df7a3fe899e56c29217a127a0a52e5036d5d8 Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Thu, 28 Sep 2023 09:18:57 +0200 Subject: [PATCH 11/40] Excluding unnecessary data from tests and bugfix --- src/libs/antares/study/parts/hydro/series.cpp | 3 --- .../parts/hydro/test-hydroreader-class.cpp | 17 ++++++++--------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/libs/antares/study/parts/hydro/series.cpp b/src/libs/antares/study/parts/hydro/series.cpp index 3b8ccdfb16..053fa2d54b 100644 --- a/src/libs/antares/study/parts/hydro/series.cpp +++ b/src/libs/antares/study/parts/hydro/series.cpp @@ -270,10 +270,7 @@ bool DataSeriesHydro::postProcessMaxPowerTS(Area& area) return true; if (nbTSCompare.differentAndGreaterThanOne(countpowercredits)) - { tsActions.handleBothGreaterThanOne(area.id); - return false; - } tsActions.resizeWhenOneTS(area, countpowercredits); diff --git a/src/tests/src/libs/antares/study/parts/hydro/test-hydroreader-class.cpp b/src/tests/src/libs/antares/study/parts/hydro/test-hydroreader-class.cpp index d943e216f8..3f780d4cf0 100644 --- a/src/tests/src/libs/antares/study/parts/hydro/test-hydroreader-class.cpp +++ b/src/tests/src/libs/antares/study/parts/hydro/test-hydroreader-class.cpp @@ -12,7 +12,6 @@ struct Fixture { study = make_shared(true); reader = make_shared(); - study->inputExtension = "txt"; // Add areas area_1 = study->areaAdd("Area1"); area_2 = study->areaAdd("Area2"); @@ -58,8 +57,8 @@ struct Fixture buffer.clear() << base_folder << SEP << hydro_folder << SEP << series_folder << SEP << area1_folder; // maxHourlyGenPower and maxHourlyPumpPower files - createFile(buffer, maxgentxt); - createFile(buffer, maxpumptxt); + createFile(buffer, maxHourlyGenPower); + createFile(buffer, maxHourlyPumpPower); // common and capacity folders buffer.clear() << base_folder << SEP << hydro_folder; @@ -70,8 +69,8 @@ struct Fixture // maxhours files buffer.clear() << base_folder << SEP << hydro_folder << SEP << common_folder << SEP << capacity_folder; - my_string file1_name = maxhoursGen << SEP << area_1->id << SEP << ".txt"; - my_string file2_name = maxhoursPump << SEP << area_1->id << SEP << ".txt"; + my_string file1_name = maxDailyGenEnergy_ << SEP << area_1->id << SEP << ".txt"; + my_string file2_name = maxDailyPumpEnergy_ << SEP << area_1->id << SEP << ".txt"; my_string file3_name = maxpower << SEP << area_1->id << SEP << ".txt"; createFile(buffer, file1_name); @@ -88,11 +87,11 @@ struct Fixture my_string series_folder = "series"; my_string common_folder = "common"; my_string capacity_folder = "capacity"; - my_string maxhoursGen = "maxDailyGenEnergy_"; - my_string maxhoursPump = "maxDailyPumpEnergy_"; + my_string maxDailyGenEnergy_ = "maxDailyGenEnergy_"; + my_string maxDailyPumpEnergy_ = "maxDailyPumpEnergy_"; my_string maxpower = "maxpower_"; - my_string maxgentxt = "maxHourlyGenPower.txt"; - my_string maxpumptxt = "maxHourlyPumpPower.txt"; + my_string maxHourlyGenPower = "maxHourlyGenPower.txt"; + my_string maxHourlyPumpPower = "maxHourlyPumpPower.txt"; ~Fixture() { From 2b1587228c8857e1d1cdd74dfc1e13f1f5ce7047 Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Thu, 28 Sep 2023 09:23:40 +0200 Subject: [PATCH 12/40] Code smell --- src/libs/antares/study/parts/hydro/series.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/antares/study/parts/hydro/series.cpp b/src/libs/antares/study/parts/hydro/series.cpp index 053fa2d54b..eb48df7b00 100644 --- a/src/libs/antares/study/parts/hydro/series.cpp +++ b/src/libs/antares/study/parts/hydro/series.cpp @@ -369,13 +369,13 @@ void DataSeriesHydro::TsActions::resizeWhenOneTS(Area& area, uint countpowercred void DataSeriesHydro::TsActions::areaToInvalidate(Area* area, const AreaName& areaID, - uint countpowercredits) const + uint countpowercredits_) const { if (area) { area->invalidateJIT = true; logs.info() << " '" << area->id << "': The hydro max power data have been normalized to " - << countpowercredits << " timeseries"; + << countpowercredits_ << " timeseries"; } else logs.error() << "Impossible to find the area `" << areaID << "` to invalidate it"; From 48d02cee0e13a6c77a93beae3ecd6cdbb7afdff9 Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Thu, 28 Sep 2023 21:19:19 +0200 Subject: [PATCH 13/40] Daily mean maximum generation/pumping matrices --- src/libs/antares/constants.h | 2 + src/libs/antares/study/area/scratchpad.cpp | 78 ++++++++++++------- src/libs/antares/study/area/scratchpad.h | 36 +++++++-- .../parts/hydro/hydromaxtimeseriesreader.cpp | 2 +- src/solver/hydro/management/daily.cpp | 23 +++--- src/solver/hydro/management/management.h | 2 +- .../simulation/sim_calcul_economique.cpp | 32 ++++---- 7 files changed, 110 insertions(+), 65 deletions(-) diff --git a/src/libs/antares/constants.h b/src/libs/antares/constants.h index f82f0372de..aed585153b 100644 --- a/src/libs/antares/constants.h +++ b/src/libs/antares/constants.h @@ -42,6 +42,8 @@ /*! Hours per year */ #define HOURS_PER_YEAR 8760 +#define HOURS_PER_DAY 24 + namespace Antares::Constants { extern const std::array daysPerMonth; diff --git a/src/libs/antares/study/area/scratchpad.cpp b/src/libs/antares/study/area/scratchpad.cpp index ca794dec3d..0f553e6701 100644 --- a/src/libs/antares/study/area/scratchpad.cpp +++ b/src/libs/antares/study/area/scratchpad.cpp @@ -32,9 +32,7 @@ using namespace Yuni; -namespace Antares -{ -namespace Data +namespace Antares::Data { AreaScratchpad::TimeseriesData::TimeseriesData(Area& area) : load(area.load.series->timeSeries), solar(area.solar.series->timeSeries), wind(area.wind.series->timeSeries) @@ -56,7 +54,7 @@ AreaScratchpad::AreaScratchpad(const StudyRuntimeInfos& rinfos, Area& area) : ts originalMustrunSum[h] = std::numeric_limits::quiet_NaN(); } - // Fatal hors hydro + // Fatal hors hydro { double sum; uint w; @@ -77,6 +75,18 @@ AreaScratchpad::AreaScratchpad(const StudyRuntimeInfos& rinfos, Area& area) : ts } } + // Hourly maximum generation/pumping power matrices and their number of TS's (width of matrices) + auto const& maxHourlyGenPower = area.hydro.series->maxHourlyGenPower; + auto const& maxHourlyPumpPower = area.hydro.series->maxHourlyPumpPower; + uint nbOfMaxPowerTimeSeries = area.hydro.series->countpowercredits; + + // Setting width and height of daily mean maximum generation/pumping power matrices + meanMaxDailyGenPower.reset(nbOfMaxPowerTimeSeries, DAYS_PER_YEAR); + meanMaxDailyPumpPower.reset(nbOfMaxPowerTimeSeries, DAYS_PER_YEAR); + + // Instantiate daily mean maximum generation/pumping power matrices + CalculateMeanDailyMaxPowerMatrices(maxHourlyGenPower, maxHourlyPumpPower, nbOfMaxPowerTimeSeries); + // =============== // hydroHasMod // =============== @@ -85,10 +95,9 @@ AreaScratchpad::AreaScratchpad(const StudyRuntimeInfos& rinfos, Area& area) : ts // Hydro generation permission // ------------------------------ // Useful whether we use a heuristic target or not - bool hydroGenerationPermission = false; + bool hydroGenerationPermission = false; - // ... Getting hydro max power - auto const& maxHourlyGenPower = area.hydro.series->maxHourlyGenPower; + // ... Getting hydro max energy auto const& maxDailyGenEnergy = area.hydro.maxDailyGenEnergy[0]; hydroGenerationPermission = CheckForPositiveEnergy(maxHourlyGenPower, maxDailyGenEnergy); @@ -120,47 +129,64 @@ AreaScratchpad::AreaScratchpad(const StudyRuntimeInfos& rinfos, Area& area) : ts // -------------------------- hydroHasMod = hydroHasInflows || hydroGenerationPermission; - // =============== // Pumping // =============== - // ... Hydro max power - // ... Hydro max pumping power and energy - auto const& maxHourlyPumpPower = area.hydro.series->maxHourlyPumpPower; - auto const& maxDailyPumpEnergy = area.hydro.maxDailyPumpEnergy[0]; + // Hydro max pumping energy + auto const& maxDailyPumpEnergy = area.hydro.maxDailyPumpEnergy[0]; - // If pumping energy is nil over the whole year, pumpHasMod is false, true otherwise. + // If pumping energy is nil over the whole year, pumpHasMod is false, true otherwise. pumpHasMod = CheckForPositiveEnergy(maxHourlyPumpPower, maxDailyPumpEnergy); } AreaScratchpad::~AreaScratchpad() = default; -bool AreaScratchpad::CheckForPositiveEnergy(const Matrix& matrix, - const Matrix::ColumnType& hours) +void AreaScratchpad::CalculateMeanDailyMaxPowerMatrices(const Matrix& hourlyMaxGenMatrix, + const Matrix& hourlyMaxPumpMatrix, + uint nbOfMaxPowerTimeSeries) { - double value = 0.; + for (uint nbOfTimeSeries = 0; nbOfTimeSeries < nbOfMaxPowerTimeSeries; ++nbOfTimeSeries) + { + auto& hourlyMaxGenColumn = hourlyMaxGenMatrix[nbOfTimeSeries]; + auto& hourlyMaxPumpColumn = hourlyMaxPumpMatrix[nbOfTimeSeries]; + auto& MeanMaxDailyGenPowerColumn = meanMaxDailyGenPower[nbOfTimeSeries]; + auto& MeanMaxDailyPumpPowerColumn = meanMaxDailyPumpPower[nbOfTimeSeries]; - for (uint width = 0; width < matrix.width; ++width) + CalculateDailyMeanPower(hourlyMaxGenColumn, MeanMaxDailyGenPowerColumn); + CalculateDailyMeanPower(hourlyMaxPumpColumn, MeanMaxDailyPumpPowerColumn); + } +} + +bool CheckForPositiveEnergy(const Matrix& power, + const Matrix::ColumnType& energy) +{ + for (uint tsNumber = 0; tsNumber < power.width; ++tsNumber) { - for (uint d = 0; d < DAYS_PER_YEAR; ++d) + double yearlyMaxGenEnergy = 0; + + for (uint day = 0; day < DAYS_PER_YEAR; ++day) { - value += CalculateDailyMeanPower(d, matrix[width]) * hours[d]; + yearlyMaxGenEnergy += power[tsNumber][day] * energy[day]; - if (value > 0.) + if (yearlyMaxGenEnergy > 0.) return true; } - - value = 0.; } return false; } -double CalculateDailyMeanPower(uint dYear, const Matrix::ColumnType& maxPower) +void CalculateDailyMeanPower(const Matrix::ColumnType& hourlyColumn, + Matrix::ColumnType& dailyColumn) { - return std::accumulate(maxPower + dYear * 24, maxPower + dYear * 24 + 24, 0) / 24.; + for (uint day = 0; day < DAYS_PER_YEAR; ++day) + { + dailyColumn[day] = std::accumulate(hourlyColumn + day * HOURS_PER_DAY, + hourlyColumn + day * HOURS_PER_DAY + HOURS_PER_DAY, + 0) + / HOURS_PER_DAY; + } } -} // namespace Data -} // namespace Antares +} // namespace Antares::Data diff --git a/src/libs/antares/study/area/scratchpad.h b/src/libs/antares/study/area/scratchpad.h index 0fd3c946d8..76cbd046c5 100644 --- a/src/libs/antares/study/area/scratchpad.h +++ b/src/libs/antares/study/area/scratchpad.h @@ -36,9 +36,7 @@ #include #include -namespace Antares -{ -namespace Data +namespace Antares::Data { /*! ** \brief Scratchpad for temporary data performed by the solver @@ -99,14 +97,36 @@ class AreaScratchpad final */ double dispatchableGenerationMargin[168]; + /*! + ** \brief Daily mean maximum power matrices + ** + ** These matrices will be calculated based on maximum + ** hourly generation/pumping matrices + */ + Matrix meanMaxDailyGenPower; + Matrix meanMaxDailyPumpPower; + private: - bool CheckForPositiveEnergy(const Matrix& matrix, - const Matrix::ColumnType& hours); + /*! + ** \brief Caluclation of daily mean maximum power matrices + ** + ** Calculates daily mean maximum generation/pumping power + ** power matrices meanMaxDailyGenPower/meanMaxDailyPumpPower + */ + void CalculateMeanDailyMaxPowerMatrices(const Matrix& hourlyMaxGenMatrix, + const Matrix& hourlyMaxPumpMatrix, + uint nbOfMaxPowerTimeSeries); + }; // class AreaScratchpad -double CalculateDailyMeanPower(uint dYear, const Matrix::ColumnType& maxPower); +// Calculates daily mean maximum generation/pumping power for one column/time-serie +void CalculateDailyMeanPower(const Matrix::ColumnType& hourlyColumn, + Matrix::ColumnType& dailyColumn); + +// Return true if maximum generated energy just in one day and for every TS is grated than 0 +bool CheckForPositiveEnergy(const Matrix& matrix, + const Matrix::ColumnType& hours); -} // namespace Data -} // namespace Antares +} // namespace Antares::Data #endif // __ANTARES_LIBS_STUDY_AREA_SCRATCHPAD_H__ diff --git a/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.cpp b/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.cpp index a3d092e152..ae82ab8ab3 100644 --- a/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.cpp +++ b/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.cpp @@ -202,7 +202,7 @@ void TransferDailyMaxPowerAsHourly(Matrix::ColumnType& hourlyCo while (hours < HOURS_PER_YEAR && days < DAYS_PER_YEAR) { - for (uint i = 0; i < 24; ++i) + for (uint i = 0; i < HOURS_PER_DAY; ++i) { hourlyColumn[hours] = dailyColumn[days]; ++hours; diff --git a/src/solver/hydro/management/daily.cpp b/src/solver/hydro/management/daily.cpp index 0f69f0b331..9d14af6a81 100644 --- a/src/solver/hydro/management/daily.cpp +++ b/src/solver/hydro/management/daily.cpp @@ -193,7 +193,7 @@ struct DebugData double niveauDeb = ventilationResults.NiveauxReservoirsDebutJours[day]; double niveauFin = ventilationResults.NiveauxReservoirsFinJours[day]; double apports = srcinflows[day] / reservoirCapacity; - double turbMax = Antares::Data::CalculateDailyMeanPower(day, maxP) * maxE[day] / reservoirCapacity; + double turbMax = maxP[day] * maxE[day] / reservoirCapacity; double turbCible = dailyTargetGen[day] / reservoirCapacity; double turbCibleUpdated = dailyTargetGen[day] / reservoirCapacity + previousMonthWaste[realmonth] / daysPerMonth; @@ -240,6 +240,10 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St auto& data = tmpDataByArea_[numSpace][z]; + auto& scratchpad = area.scratchpad[numSpace]; + + auto& meanMaxDailyGenPower = scratchpad.meanMaxDailyGenPower; + int initReservoirLvlMonth = area.hydro.initializeReservoirLevelDate; double reservoirCapacity = area.hydro.reservoirCapacity; @@ -251,12 +255,10 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St uint dayYear = 0; auto const& maxDailyGenEnergy = area.hydro.maxDailyGenEnergy; - auto const& maxHourlyGenPower = area.hydro.series->maxHourlyGenPower; - uint tsIndexMaxPower - = (NumeroChroniquesTireesParPays[numSpace][z]).HydrauliqueMaxPower; + uint tsIndexMaxPower = (NumeroChroniquesTireesParPays[numSpace][z]).HydrauliqueMaxPower; - auto const& maxP = maxHourlyGenPower[tsIndexMaxPower < maxHourlyGenPower.width ? tsIndexMaxPower : 0]; + auto const& maxP = meanMaxDailyGenPower[tsIndexMaxPower]; auto const& maxE = maxDailyGenEnergy[0]; auto& ventilationResults = ventilationResults_[numSpace][z]; @@ -281,17 +283,16 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St auto daysPerMonth = calendar_.months[month].days; assert(daysPerMonth <= maxOPP); assert(daysPerMonth <= maxDailyTargetGen); - assert(daysPerMonth + dayYear - 1 < maxHourlyGenPower.height); + assert(daysPerMonth + dayYear - 1 < meanMaxDailyGenPower.height); for (uint day = 0; day != daysPerMonth; ++day) { auto dYear = day + dayYear; assert(day < 32); assert(dYear < 366); - auto meanPower = Antares::Data::CalculateDailyMeanPower(dYear, maxP); if (debugData) - debugData->OPP[dYear] = meanPower * maxE[dYear]; + debugData->OPP[dYear] = maxP[dYear] * maxE[dYear]; } dayYear += daysPerMonth; @@ -400,8 +401,7 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St uint dayMonth = 0; for (uint day = firstDay; day != endDay; ++day) { - auto meanPower = Antares::Data::CalculateDailyMeanPower(day, maxP); - problem.TurbineMax[dayMonth] = meanPower * maxE[day]; + problem.TurbineMax[dayMonth] = maxP[day] * maxE[day]; problem.TurbineMin[dayMonth] = data.dailyMinGen[day]; problem.TurbineCible[dayMonth] = dailyTargetGen[day]; dayMonth++; @@ -478,8 +478,7 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St uint dayMonth = 0; for (uint day = firstDay; day != endDay; ++day) { - auto meanPower = Antares::Data::CalculateDailyMeanPower(day, maxP); - problem.TurbineMax[dayMonth] = meanPower * maxE[day] / reservoirCapacity; + problem.TurbineMax[dayMonth] = maxP[day] * maxE[day] / reservoirCapacity; problem.TurbineMin[dayMonth] = data.dailyMinGen[day] / reservoirCapacity; problem.TurbineCible[dayMonth] diff --git a/src/solver/hydro/management/management.h b/src/solver/hydro/management/management.h index 6ba7a28dec..b301fddb66 100644 --- a/src/solver/hydro/management/management.h +++ b/src/solver/hydro/management/management.h @@ -88,7 +88,7 @@ struct TmpDataByArea typedef struct { std::vector HydrauliqueModulableQuotidien; /* indice par jour */ - std::vector NiveauxReservoirsDebutJours; //Niveaux (quotidiens) du reservoir de d�but + std::vector NiveauxReservoirsDebutJours; //Niveaux (quotidiens) du reservoir de début //de jour (en cas de gestion des reservoirs). std::vector NiveauxReservoirsFinJours; //Niveaux (quotidiens) du reservoir de fin //de jour (en cas de gestion des reservoirs). diff --git a/src/solver/simulation/sim_calcul_economique.cpp b/src/solver/simulation/sim_calcul_economique.cpp index fb4dc88c9a..570fbae159 100644 --- a/src/solver/simulation/sim_calcul_economique.cpp +++ b/src/solver/simulation/sim_calcul_economique.cpp @@ -559,7 +559,8 @@ void SIM_RenseignementProblemeHebdo(const Study& study, ntc.ValeurDeLoopFlowOrigineVersExtremite[k] = lnk.parameters[fhlLoopFlow][hourInYear]; } } - preparerBindingConstraint(problem, numSpace, PasDeTempsDebut, study.bindingConstraints, weekFirstDay, hourInWeek); + preparerBindingConstraint( + problem, numSpace, PasDeTempsDebut, study.bindingConstraints, weekFirstDay, hourInWeek); for (uint k = 0; k < nbPays; ++k) { @@ -653,10 +654,9 @@ void SIM_RenseignementProblemeHebdo(const Study& study, auto& inflowsmatrix = area.hydro.series->storage; auto const& srcinflows = inflowsmatrix[tsIndex < inflowsmatrix.width ? tsIndex : 0]; uint tsIndexMaxPower = (NumeroChroniquesTireesParPays[numSpace][k]).HydrauliqueMaxPower; - auto& maxHourlyGenPowerMatrix = area.hydro.series->maxHourlyGenPower; - auto const& srcMaxHourlyGenPower = maxHourlyGenPowerMatrix[tsIndexMaxPower < maxHourlyGenPowerMatrix.width ? tsIndexMaxPower : 0]; - auto& maxHourlyPumpPowerMatrix = area.hydro.series->maxHourlyPumpPower; - auto const& srcMaxHourlyPumpPower = maxHourlyPumpPowerMatrix[tsIndexMaxPower < maxHourlyPumpPowerMatrix.width ? tsIndexMaxPower : 0]; + auto& scratchpad = area.scratchpad[numSpace]; + auto& dailyMeanMaxGenPower = scratchpad.meanMaxDailyGenPower[tsIndexMaxPower]; + auto& dailyMeanMaxPumpPower = scratchpad.meanMaxDailyPumpPower[tsIndexMaxPower]; auto& mingenmatrix = area.hydro.series->mingen; auto const& srcmingen = mingenmatrix[tsIndex < mingenmatrix.width ? tsIndex : 0]; for (uint j = 0; j < problem.NombreDePasDeTemps; ++j) @@ -674,14 +674,13 @@ void SIM_RenseignementProblemeHebdo(const Study& study, for (uint j = 0; j < 7; ++j) { uint day = study.calendar.hours[PasDeTempsDebut + j * 24].dayYear; - auto meanPower = CalculateDailyMeanPower(day, srcMaxHourlyGenPower); problem.CaracteristiquesHydrauliques[k] .MinEnergieHydrauParIntervalleOptimise[j] = 0.; problem.CaracteristiquesHydrauliques[k] .MaxEnergieHydrauParIntervalleOptimise[j] - = meanPower * area.hydro.maxDailyGenEnergy[0][day] + = dailyMeanMaxGenPower[day] * area.hydro.maxDailyGenEnergy[0][day] * problem.CaracteristiquesHydrauliques[k] .WeeklyGeneratingModulation; } @@ -730,9 +729,9 @@ void SIM_RenseignementProblemeHebdo(const Study& study, for (uint j = 0; j < 7; ++j) { uint day = study.calendar.hours[PasDeTempsDebut + j * 24].dayYear; - auto meanPower = CalculateDailyMeanPower(day, srcMaxHourlyGenPower); - double DGC = meanPower * area.hydro.maxDailyGenEnergy[0][day]; + double DGC + = dailyMeanMaxGenPower[day] * area.hydro.maxDailyGenEnergy[0][day]; DGU_tmp[j] = DNT[day] * LUB; DGL_tmp[j] = DNT[day] * LLB; @@ -837,11 +836,11 @@ void SIM_RenseignementProblemeHebdo(const Study& study, for (uint j = 0; j < 7; ++j) { uint day = study.calendar.hours[PasDeTempsDebut + j * 24].dayYear; - auto meanPump = CalculateDailyMeanPower(day, srcMaxHourlyPumpPower); problem.CaracteristiquesHydrauliques[k] .MaxEnergiePompageParIntervalleOptimise[j] - = meanPump * area.hydro.maxDailyPumpEnergy[0][day] + = dailyMeanMaxPumpPower[day] + * area.hydro.maxDailyPumpEnergy[0][day] * problem.CaracteristiquesHydrauliques[k] .WeeklyPumpingModulation; } @@ -872,10 +871,9 @@ void SIM_RenseignementProblemeHebdo(const Study& study, for (uint j = 0; j < 7; ++j) { uint day = study.calendar.hours[PasDeTempsDebut + j * 24].dayYear; - auto meanPump = CalculateDailyMeanPower(day, srcMaxHourlyPumpPower); - double DPC - = meanPump * area.hydro.maxDailyPumpEnergy[0][day]; + double DPC = dailyMeanMaxPumpPower[day] + * area.hydro.maxDailyPumpEnergy[0][day]; WPU += DPC; } @@ -885,9 +883,9 @@ void SIM_RenseignementProblemeHebdo(const Study& study, for (uint j = 0; j < 7; ++j) { uint day = study.calendar.hours[PasDeTempsDebut + j * 24].dayYear; - auto meanPump = CalculateDailyMeanPower(day, srcMaxHourlyPumpPower); - double DPC - = meanPump * area.hydro.maxDailyPumpEnergy[0][day]; + + double DPC = dailyMeanMaxPumpPower[day] + * area.hydro.maxDailyPumpEnergy[0][day]; double rc = area.hydro.reservoirCapacity; if (not area.hydro.hardBoundsOnRuleCurves) From 13a238c5f0cdac213c20ca9bb6a72e72b070f669 Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Thu, 28 Sep 2023 23:17:04 +0200 Subject: [PATCH 14/40] Check Power Bounds --- src/solver/hydro/management/management.cpp | 74 +++++++++++++--------- src/solver/hydro/management/management.h | 4 +- 2 files changed, 48 insertions(+), 30 deletions(-) diff --git a/src/solver/hydro/management/management.cpp b/src/solver/hydro/management/management.cpp index 8d4f1d9dcb..17f4a498a5 100644 --- a/src/solver/hydro/management/management.cpp +++ b/src/solver/hydro/management/management.cpp @@ -306,35 +306,48 @@ bool HydroManagement::checkWeeklyMinGeneration(uint tsIndex, Data::Area& area) c return true; } -bool HydroManagement::checkHourlyMinMaxGeneration(uint tsIndex, - uint tsIndexMaxPower, - Data::Area& area) const +bool HydroManagement::checkGenerationPowerConsistency(uint numSpace) const { - // Hourly minimum generation <= hourly inflows for each hour - auto& mingenmatrix = area.hydro.series->mingen; - auto const& srcmingen = mingenmatrix[tsIndex < mingenmatrix.width ? tsIndex : 0]; - auto& maxHourlyGenPowerMatrix = area.hydro.series->maxHourlyGenPower; - auto const& srcMaxHourlyGenPower - = maxHourlyGenPowerMatrix[tsIndexMaxPower < maxHourlyGenPowerMatrix.width ? tsIndexMaxPower - : 0]; + bool ret = true; - for (uint h = 0; h < HOURS_PER_YEAR; ++h) - { - const auto& max = srcMaxHourlyGenPower[h]; - const auto& min = srcmingen[h]; + areas_.each( + [this, &numSpace, &ret](Data::Area& area) -> decltype(ret) + { + uint z = area.index; + const auto& ptchro = NumeroChroniquesTireesParPays[numSpace][z]; + auto tsIndex = (uint)ptchro.Hydraulique; + auto tsIndexMaxPower = ptchro.HydrauliqueMaxPower; - if (max < min) - { - logs.error() << "In area: " << area.name << " [hourly] minimum generation of " << min - << " MW in timestep " << h + 1 << " of TS-" << tsIndex + 1 - << " is incompatible with the maximum generation of " << max - << " MW in timestep " << h + 1 << " of TS-" << tsIndexMaxPower + 1 - << " MW."; - return false; - } - } + // Hourly minimum generation <= hourly inflows for each hour + auto& mingenmatrix = area.hydro.series->mingen; + auto const& srcmingen = mingenmatrix[tsIndex < mingenmatrix.width ? tsIndex : 0]; + auto& maxHourlyGenPowerMatrix = area.hydro.series->maxHourlyGenPower; + auto const& srcMaxHourlyGenPower + = maxHourlyGenPowerMatrix[tsIndexMaxPower < maxHourlyGenPowerMatrix.width + ? tsIndexMaxPower + : 0]; - return true; + for (uint h = 0; h < HOURS_PER_YEAR; ++h) + { + const auto& max = srcMaxHourlyGenPower[h]; + const auto& min = srcmingen[h]; + + if (max < min) + { // Maybe we should put and day in which exception happens? + // Now use can only see in which hour this error log + logs.error() << "In area: " << area.name << " [hourly] minimum generation of " + << min << " MW in timestep " << h + 1 << " of TS-" << tsIndex + 1 + << " is incompatible with the maximum generation of " << max + << " MW in timestep " << h + 1 << " of TS-" << tsIndexMaxPower + 1 + << " MW."; + ret = false; + return ret; + } + } + return ret; + }); + + return ret; } bool HydroManagement::checkMinGeneration(uint numSpace) @@ -351,9 +364,6 @@ bool HydroManagement::checkMinGeneration(uint numSpace) bool followLoadModulations = area.hydro.followLoadModulations; bool reservoirManagement = area.hydro.reservoirManagement; - if (!reservoirManagement) - ret = checkHourlyMinMaxGeneration(tsIndex, tsIndexMaxPower, area) && ret; - if (!useHeuristicTarget) return; @@ -514,6 +524,12 @@ double HydroManagement::randomReservoirLevel(double min, double avg, double max) return x * max + (1. - x) * min; } +bool HydroManagement::checksOnGenerationPowerBounds(uint numSpace) +{ + return (checkMinGeneration(numSpace) && checkGenerationPowerConsistency(numSpace)) ? true + : false; +} + void HydroManagement::makeVentilation(double* randomReservoirLevel, Solver::Variable::State& state, uint y, @@ -523,7 +539,7 @@ void HydroManagement::makeVentilation(double* randomReservoirLevel, prepareInflowsScaling(numSpace); minGenerationScaling(numSpace); - if (!checkMinGeneration(numSpace)) + if (!checksOnGenerationPowerBounds(numSpace)) { throw FatalError("hydro management: invalid minimum generation"); } diff --git a/src/solver/hydro/management/management.h b/src/solver/hydro/management/management.h index b301fddb66..2ff0b75fdb 100644 --- a/src/solver/hydro/management/management.h +++ b/src/solver/hydro/management/management.h @@ -131,9 +131,11 @@ class HydroManagement final //! check Weekly minimum generation is lower than available inflows bool checkWeeklyMinGeneration(uint tsIndex, Data::Area& area) const; //! check Hourly minimum generation is lower than available inflows - bool checkHourlyMinMaxGeneration(uint tsIndex, uint tsIndexMaxPower, Data::Area& area) const; + bool checkGenerationPowerConsistency(uint numSpace) const; //! check minimum generation is lower than available inflows bool checkMinGeneration(uint numSpace); + //! return false if checkGenerationPowerConsistency or checkMinGeneration returns false + bool checksOnGenerationPowerBounds(uint numSpace); //! Prepare the net demand for each area template void prepareNetDemand(uint numSpace); From 191476538ba322ac28d5f14641e36bf830f5799d Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Thu, 28 Sep 2023 23:20:26 +0200 Subject: [PATCH 15/40] Rewrite comment --- src/solver/hydro/management/management.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/solver/hydro/management/management.cpp b/src/solver/hydro/management/management.cpp index 17f4a498a5..c7759f5cf5 100644 --- a/src/solver/hydro/management/management.cpp +++ b/src/solver/hydro/management/management.cpp @@ -334,7 +334,7 @@ bool HydroManagement::checkGenerationPowerConsistency(uint numSpace) const if (max < min) { // Maybe we should put and day in which exception happens? - // Now use can only see in which hour this error log + // Now user can only see in hourly resolution when an exception occur. logs.error() << "In area: " << area.name << " [hourly] minimum generation of " << min << " MW in timestep " << h + 1 << " of TS-" << tsIndex + 1 << " is incompatible with the maximum generation of " << max From 61881ee4f52610c96a140d04b060b4fef57e8ad5 Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Fri, 29 Sep 2023 00:16:31 +0200 Subject: [PATCH 16/40] Name convention --- src/libs/antares/study/area/list.cpp | 2 +- src/libs/antares/study/area/scratchpad.cpp | 2 +- src/libs/antares/study/parts/hydro/series.cpp | 28 +++++++++---------- src/libs/antares/study/parts/hydro/series.h | 8 +++--- .../study/scenario-builder/applyToMatrix.hxx | 2 +- .../alea_tirage_au_sort_chroniques.cpp | 2 +- src/solver/simulation/timeseries-numbers.cpp | 6 ++-- .../test-sc-builder-file-read-line.cpp | 6 ++-- .../test-sc-builder-file-save.cpp | 6 ++-- .../handler/antares-study/area/timeseries.cpp | 2 +- 10 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/libs/antares/study/area/list.cpp b/src/libs/antares/study/area/list.cpp index 3c55028789..1572de9317 100644 --- a/src/libs/antares/study/area/list.cpp +++ b/src/libs/antares/study/area/list.cpp @@ -1647,7 +1647,7 @@ void AreaList::removeHydroTimeseries() area.hydro.series->maxHourlyGenPower.reset(1, HOURS_PER_YEAR); area.hydro.series->maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); area.hydro.series->count = 1; - area.hydro.series->countpowercredits = 1; + area.hydro.series->nbTimeSeriesSup = 1; }); } diff --git a/src/libs/antares/study/area/scratchpad.cpp b/src/libs/antares/study/area/scratchpad.cpp index 0f553e6701..9b32e83396 100644 --- a/src/libs/antares/study/area/scratchpad.cpp +++ b/src/libs/antares/study/area/scratchpad.cpp @@ -78,7 +78,7 @@ AreaScratchpad::AreaScratchpad(const StudyRuntimeInfos& rinfos, Area& area) : ts // Hourly maximum generation/pumping power matrices and their number of TS's (width of matrices) auto const& maxHourlyGenPower = area.hydro.series->maxHourlyGenPower; auto const& maxHourlyPumpPower = area.hydro.series->maxHourlyPumpPower; - uint nbOfMaxPowerTimeSeries = area.hydro.series->countpowercredits; + uint nbOfMaxPowerTimeSeries = area.hydro.series->nbTimeSeriesSup; // Setting width and height of daily mean maximum generation/pumping power matrices meanMaxDailyGenPower.reset(nbOfMaxPowerTimeSeries, DAYS_PER_YEAR); diff --git a/src/libs/antares/study/parts/hydro/series.cpp b/src/libs/antares/study/parts/hydro/series.cpp index eb48df7b00..3c3c7cddab 100644 --- a/src/libs/antares/study/parts/hydro/series.cpp +++ b/src/libs/antares/study/parts/hydro/series.cpp @@ -227,7 +227,7 @@ void DataSeriesHydro::reset() maxHourlyGenPower.reset(1, HOURS_PER_YEAR); maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); count = 1; - countpowercredits = 1; + nbTimeSeriesSup = 1; } uint64_t DataSeriesHydro::memoryUsage() const @@ -269,10 +269,10 @@ bool DataSeriesHydro::postProcessMaxPowerTS(Area& area) if (nbTSCompare.same()) return true; - if (nbTSCompare.differentAndGreaterThanOne(countpowercredits)) + if (nbTSCompare.differentAndGreaterThanOne(nbTimeSeriesSup)) tsActions.handleBothGreaterThanOne(area.id); - tsActions.resizeWhenOneTS(area, countpowercredits); + tsActions.resizeWhenOneTS(area, nbTimeSeriesSup); return true; } @@ -292,7 +292,7 @@ void DataSeriesHydro::setCountVariable() const auto& maxHourlyGenPower_ = maxHourlyGenPower.width; const auto& maxHourlyPumpPower_ = maxHourlyPumpPower.width; - countpowercredits + nbTimeSeriesSup = (maxHourlyGenPower_ >= maxHourlyPumpPower_) ? maxHourlyGenPower_ : maxHourlyPumpPower_; } @@ -302,7 +302,7 @@ void DataSeriesHydro::setMaxPowerTSWhenDeratedMode(const Study& study) { maxHourlyGenPower.averageTimeseries(); maxHourlyPumpPower.averageTimeseries(); - countpowercredits = 1; + nbTimeSeriesSup = 1; } } @@ -321,9 +321,9 @@ bool DataSeriesHydro::NbTsComparer::same() const return (nbOfGenPowerTs == nbOfPumpPowerTs) ? true : false; } -bool DataSeriesHydro::NbTsComparer::differentAndGreaterThanOne(uint countpowercredits_) const +bool DataSeriesHydro::NbTsComparer::differentAndGreaterThanOne(uint nbTimeSeriesSup_) const { - return (countpowercredits_ > 1 && (nbOfGenPowerTs != 1) && (nbOfPumpPowerTs != 1)) ? true + return (nbTimeSeriesSup_ > 1 && (nbOfGenPowerTs != 1) && (nbOfPumpPowerTs != 1)) ? true : false; } @@ -350,32 +350,32 @@ void DataSeriesHydro::TsActions::handleBothZeros(const AreaName& areaID) throw Error::ReadingStudy(); } -void DataSeriesHydro::TsActions::resizeWhenOneTS(Area& area, uint countpowercredits_) +void DataSeriesHydro::TsActions::resizeWhenOneTS(Area& area, uint nbTimeSeriesSup_) { if (maxHourlyGenPower.width == 1) { - resizeMatrixNoDataLoss(maxHourlyGenPower, countpowercredits_); - areaToInvalidate(&area, area.id, countpowercredits_); + resizeMatrixNoDataLoss(maxHourlyGenPower, nbTimeSeriesSup_); + areaToInvalidate(&area, area.id, nbTimeSeriesSup_); return; } if (maxHourlyPumpPower.width == 1) { - resizeMatrixNoDataLoss(maxHourlyPumpPower, countpowercredits_); - areaToInvalidate(&area, area.id, countpowercredits_); + resizeMatrixNoDataLoss(maxHourlyPumpPower, nbTimeSeriesSup_); + areaToInvalidate(&area, area.id, nbTimeSeriesSup_); return; } } void DataSeriesHydro::TsActions::areaToInvalidate(Area* area, const AreaName& areaID, - uint countpowercredits_) const + uint nbTimeSeriesSup_) const { if (area) { area->invalidateJIT = true; logs.info() << " '" << area->id << "': The hydro max power data have been normalized to " - << countpowercredits_ << " timeseries"; + << nbTimeSeriesSup_ << " timeseries"; } else logs.error() << "Impossible to find the area `" << areaID << "` to invalidate it"; diff --git a/src/libs/antares/study/parts/hydro/series.h b/src/libs/antares/study/parts/hydro/series.h index de03c526d2..387a95ca67 100644 --- a/src/libs/antares/study/parts/hydro/series.h +++ b/src/libs/antares/study/parts/hydro/series.h @@ -162,7 +162,7 @@ class DataSeriesHydro ** (for example using `maxHourlyGenPower.width` and `maxHourlyPumpPower.width` in the same routine, it might ** indicate that the two values are not strictly equal) */ - uint countpowercredits = 0; + uint nbTimeSeriesSup = 0; /*! ** \brief Monte-Carlo @@ -182,7 +182,7 @@ class DataSeriesHydro bool bothZeros() const; bool same() const; - bool differentAndGreaterThanOne(uint countpowercredits_) const; + bool differentAndGreaterThanOne(uint nbTimeSeriesSup_) const; private: uint32_t nbOfGenPowerTs{0}; @@ -197,13 +197,13 @@ class DataSeriesHydro void handleBothZeros(const AreaName& areaID); [[noreturn]] void handleBothGreaterThanOne(const AreaName& areaID) const; - void resizeWhenOneTS(Area& area, uint countpowercredits_); + void resizeWhenOneTS(Area& area, uint nbTimeSeriesSup_); private: Matrix& maxHourlyGenPower; Matrix& maxHourlyPumpPower; - void areaToInvalidate(Area* area, const AreaName& areaID, uint countpowercredits_) const; + void areaToInvalidate(Area* area, const AreaName& areaID, uint nbTimeSeriesSup_) const; }; }; // class DataSeriesHydro diff --git a/src/libs/antares/study/scenario-builder/applyToMatrix.hxx b/src/libs/antares/study/scenario-builder/applyToMatrix.hxx index 4e5496b477..c85a4d3d65 100644 --- a/src/libs/antares/study/scenario-builder/applyToMatrix.hxx +++ b/src/libs/antares/study/scenario-builder/applyToMatrix.hxx @@ -49,7 +49,7 @@ template static inline bool CheckValidityHydroMaxPower(uint value, const D& data, uint tsGenMax) { // TS Generator never used - return (!tsGenMax) ? (value < data.countpowercredits) : (value < tsGenMax); + return (!tsGenMax) ? (value < data.nbTimeSeriesSup) : (value < tsGenMax); } template diff --git a/src/solver/aleatoire/alea_tirage_au_sort_chroniques.cpp b/src/solver/aleatoire/alea_tirage_au_sort_chroniques.cpp index 3f2b3ca216..0e851ebd9b 100644 --- a/src/solver/aleatoire/alea_tirage_au_sort_chroniques.cpp +++ b/src/solver/aleatoire/alea_tirage_au_sort_chroniques.cpp @@ -71,7 +71,7 @@ void ApplyRandomTSnumbers(const Study& study, { const Data::DataSeriesHydro& data = *area.hydro.series; assert(year < data.timeseriesNumbersHydroMaxPower.height); - ptchro.HydrauliqueMaxPower = (data.countpowercredits != 1) + ptchro.HydrauliqueMaxPower = (data.nbTimeSeriesSup != 1) ? (data.timeseriesNumbersHydroMaxPower[0][year]) : 0; // zero-based } diff --git a/src/solver/simulation/timeseries-numbers.cpp b/src/solver/simulation/timeseries-numbers.cpp index 3a965a18d8..23ce912430 100644 --- a/src/solver/simulation/timeseries-numbers.cpp +++ b/src/solver/simulation/timeseries-numbers.cpp @@ -168,7 +168,7 @@ class hydroMaxPowerAreaNumberOfTSretriever : public areaNumberOfTSretriever } std::vector getAreaTimeSeriesNumber(const Area& area) override { - std::vector to_return = {area.hydro.series->countpowercredits}; + std::vector to_return = {area.hydro.series->nbTimeSeriesSup}; return to_return; } uint getGeneratedTimeSeriesNumber() override @@ -452,7 +452,7 @@ bool checkInterModalConsistencyForArea(Area& area, indexTS = ts_to_tsIndex.at(timeSeriesHydroMaxPower); if (isTSintermodal[indexTS]) { - uint nbTimeSeries = area.hydro.series->countpowercredits; + uint nbTimeSeries = area.hydro.series->nbTimeSeriesSup; listNumberTsOverArea.push_back(nbTimeSeries); } @@ -897,7 +897,7 @@ static void fixTSNumbersWhenWidthIsOne(Study& study) area.hydro.series->timeseriesNumbers, area.hydro.series->count, years); // Hydro Max Power fixTSNumbersSingleAreaSingleMode( - area.hydro.series->timeseriesNumbersHydroMaxPower, area.hydro.series->countpowercredits, years); + area.hydro.series->timeseriesNumbersHydroMaxPower, area.hydro.series->nbTimeSeriesSup, years); // Thermal std::for_each(area.thermal.clusters.cbegin(), diff --git a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp index c394df9bcd..71281e1f6a 100644 --- a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp +++ b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp @@ -89,9 +89,9 @@ struct Fixture // Hydro Max Power: set the nb of ready made TS nbReadyMadeTS = 15; - area_1->hydro.series->countpowercredits = nbReadyMadeTS; - area_2->hydro.series->countpowercredits = nbReadyMadeTS; - area_3->hydro.series->countpowercredits = nbReadyMadeTS; + area_1->hydro.series->nbTimeSeriesSup = nbReadyMadeTS; + area_2->hydro.series->nbTimeSeriesSup = nbReadyMadeTS; + area_3->hydro.series->nbTimeSeriesSup = nbReadyMadeTS; // Links link_12 = AreaAddLinkBetweenAreas(area_1, area_2, false); diff --git a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp index 00fab10d89..d5089555da 100644 --- a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp +++ b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp @@ -131,9 +131,9 @@ struct commonFixture // Hydro Max Power : set the nb of ready made TS nbReadyMadeTS = 15; - area_1->hydro.series->countpowercredits = nbReadyMadeTS; - area_2->hydro.series->countpowercredits = nbReadyMadeTS; - area_3->hydro.series->countpowercredits = nbReadyMadeTS; + area_1->hydro.series->nbTimeSeriesSup = nbReadyMadeTS; + area_2->hydro.series->nbTimeSeriesSup = nbReadyMadeTS; + area_3->hydro.series->nbTimeSeriesSup = nbReadyMadeTS; // Links link_12 = AreaAddLinkBetweenAreas(area_1, area_2, false); diff --git a/src/ui/action/handler/antares-study/area/timeseries.cpp b/src/ui/action/handler/antares-study/area/timeseries.cpp index d057b3b6fd..3ca94f2eac 100644 --- a/src/ui/action/handler/antares-study/area/timeseries.cpp +++ b/src/ui/action/handler/antares-study/area/timeseries.cpp @@ -178,7 +178,7 @@ bool DataTimeseries::performWL(Context& ctx) ctx.area->hydro.series->maxHourlyGenPower = source->hydro.series->maxHourlyGenPower; ctx.area->hydro.series->maxHourlyPumpPower = source->hydro.series->maxHourlyPumpPower; - ctx.area->hydro.series->countpowercredits = source->hydro.series->countpowercredits; + ctx.area->hydro.series->nbTimeSeriesSup = source->hydro.series->nbTimeSeriesSup; source->hydro.series->maxHourlyGenPower.unloadFromMemory(); source->hydro.series->maxHourlyPumpPower.unloadFromMemory(); From 57fdb440a52e1a52515d42464e00e705f580ea4b Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Fri, 29 Sep 2023 00:35:33 +0200 Subject: [PATCH 17/40] Code smells --- src/solver/hydro/management/management.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/solver/hydro/management/management.cpp b/src/solver/hydro/management/management.cpp index c7759f5cf5..85ff4cbe12 100644 --- a/src/solver/hydro/management/management.cpp +++ b/src/solver/hydro/management/management.cpp @@ -311,7 +311,7 @@ bool HydroManagement::checkGenerationPowerConsistency(uint numSpace) const bool ret = true; areas_.each( - [this, &numSpace, &ret](Data::Area& area) -> decltype(ret) + [&numSpace, &ret](Data::Area& area) -> decltype(ret) { uint z = area.index; const auto& ptchro = NumeroChroniquesTireesParPays[numSpace][z]; @@ -358,7 +358,6 @@ bool HydroManagement::checkMinGeneration(uint numSpace) uint z = area.index; const auto& ptchro = NumeroChroniquesTireesParPays[numSpace][z]; auto tsIndex = (uint)ptchro.Hydraulique; - auto tsIndexMaxPower = ptchro.HydrauliqueMaxPower; bool useHeuristicTarget = area.hydro.useHeuristicTarget; bool followLoadModulations = area.hydro.followLoadModulations; From f0bf47be4a5b6cdb6f9eb08b20735e773a07ce0e Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Fri, 29 Sep 2023 11:36:53 +0200 Subject: [PATCH 18/40] Comments and function name changed --- src/libs/antares/study/area/list.cpp | 2 +- .../parts/hydro/hydromaxtimeseriesreader.cpp | 2 +- .../parts/hydro/hydromaxtimeseriesreader.h | 21 ++++++++++++-- src/libs/antares/study/parts/hydro/series.cpp | 2 +- src/libs/antares/study/parts/hydro/series.h | 29 ++++++++++++++++++- .../study/parts/hydro/test-hydro-series.cpp | 10 +++---- 6 files changed, 55 insertions(+), 11 deletions(-) diff --git a/src/libs/antares/study/area/list.cpp b/src/libs/antares/study/area/list.cpp index 1572de9317..0987ac2720 100644 --- a/src/libs/antares/study/area/list.cpp +++ b/src/libs/antares/study/area/list.cpp @@ -922,7 +922,7 @@ static bool AreaListLoadFromFolderSingleArea(Study& study, if (study.usedByTheSolver) { - area.hydro.series->setCountVariable(); + area.hydro.series->setNbTimeSeriesSup(); ret = area.hydro.series->postProcessMaxPowerTS(area) && ret; area.hydro.series->setMaxPowerTSWhenDeratedMode(study); } diff --git a/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.cpp b/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.cpp index ae82ab8ab3..84af75d815 100644 --- a/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.cpp +++ b/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.cpp @@ -140,7 +140,7 @@ bool HydroMaxTimeSeriesReader::SaveDailyMaxPowerAsHourly(const AnyString& folder ret = SaveDailyMaxGenPowerAsHourly(folder, area) && ret; ret = SaveDailyMaxPumpPowerAsHourly(folder, area) && ret; - area.hydro.series->setCountVariable(); + area.hydro.series->setNbTimeSeriesSup(); return ret; } diff --git a/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.h b/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.h index f3e0582d49..adbfbef460 100644 --- a/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.h +++ b/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.h @@ -35,7 +35,7 @@ namespace Antares::Data /*! ** This class provides support for old studies, reading from deprecated files, ** fils matrix dailyMaxPumpAndGen and transfers data to the corresponding data class members of -** class PartHydro +** class PartHydro. Just version below 8.7 will use this class to be compatible with current implemetation. */ class HydroMaxTimeSeriesReader { @@ -59,11 +59,28 @@ class HydroMaxTimeSeriesReader }; private: + /** + * \brief Loading deprecated files + * This function provides reading from deprecated files + * which contains daily maximum generation/pumping power data. + */ bool LoadDailyMaxPowersAndEnergies(const AnyString& folder, const Area& area); + + /** + * \brief Save energy functions + * These functions provides instantiation of necessary matrices for + * computation and saving matrices data to the newly created files. + */ bool SaveDailyMaxEnergy(const AnyString& folder, Area& area); - bool SaveDailyMaxPowerAsHourly(const AnyString& folder, Area& area); bool SaveMaxGenerationEnergy(const AnyString& folder, Area& area); bool SaveMaxPumpingEnergy(const AnyString& folder, Area& area); + + /** + * \brief Save power functions + * These functions provides instantiation of necessary matrices for + * computation and saving matrices data to the newly created files. + */ + bool SaveDailyMaxPowerAsHourly(const AnyString& folder, Area& area); bool SaveDailyMaxGenPowerAsHourly(const AnyString& folder, Area& area); bool SaveDailyMaxPumpPowerAsHourly(const AnyString& folder, Area& area); }; diff --git a/src/libs/antares/study/parts/hydro/series.cpp b/src/libs/antares/study/parts/hydro/series.cpp index 3c3c7cddab..10c808cd78 100644 --- a/src/libs/antares/study/parts/hydro/series.cpp +++ b/src/libs/antares/study/parts/hydro/series.cpp @@ -287,7 +287,7 @@ void DataSeriesHydro::setHydroModulability(Study& study, const AreaName& areaID) } } -void DataSeriesHydro::setCountVariable() +void DataSeriesHydro::setNbTimeSeriesSup() { const auto& maxHourlyGenPower_ = maxHourlyGenPower.width; const auto& maxHourlyPumpPower_ = maxHourlyPumpPower.width; diff --git a/src/libs/antares/study/parts/hydro/series.h b/src/libs/antares/study/parts/hydro/series.h index 387a95ca67..0a44bb5da3 100644 --- a/src/libs/antares/study/parts/hydro/series.h +++ b/src/libs/antares/study/parts/hydro/series.h @@ -169,12 +169,35 @@ class DataSeriesHydro */ Matrix timeseriesNumbers; Matrix timeseriesNumbersHydroMaxPower; + + /** + * \brief Loading hydro maximum generation and pumping TS's + */ bool LoadMaxPower(const AreaName& areaID, const AnyString& folder); + + /** + * \brief Post processing numbers of TS's + * Checking whether or not TS's numbers are different + * and taking proper action based on corresponding check + */ bool postProcessMaxPowerTS(Area& area); + void setHydroModulability(Study& study, const AreaName& areaID) const; - void setCountVariable(); + + /** + * \brief Setting TS's number of maximum generation and pumping matrices + */ + void setNbTimeSeriesSup(); + + /** + * \brief Setting TS's when derated mode is on + */ void setMaxPowerTSWhenDeratedMode(const Study& study); + /** + * This class provides comparing two integers + * that represents width of two corresponding matrices. + */ class NbTsComparer { public: @@ -189,6 +212,10 @@ class DataSeriesHydro uint32_t nbOfPumpPowerTs{0}; }; + /** + * This class provides actions based on the return + * values of the NbTsComparer class member functions + */ class TsActions { public: diff --git a/src/tests/src/libs/antares/study/parts/hydro/test-hydro-series.cpp b/src/tests/src/libs/antares/study/parts/hydro/test-hydro-series.cpp index 5028805553..45a73e96c9 100644 --- a/src/tests/src/libs/antares/study/parts/hydro/test-hydro-series.cpp +++ b/src/tests/src/libs/antares/study/parts/hydro/test-hydro-series.cpp @@ -80,7 +80,7 @@ BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_matrices_equal_width, Fixture buffer.clear() << base_folder << SEP << series_folder; ret = area_1->hydro.series->LoadMaxPower(area_1->id, buffer); - area_1->hydro.series->setCountVariable(); + area_1->hydro.series->setNbTimeSeriesSup(); ret = area_1->hydro.series->postProcessMaxPowerTS(*area_1) && ret; BOOST_CHECK(ret); BOOST_CHECK_EQUAL(maxHourlyGenPower.width, 3); @@ -138,7 +138,7 @@ BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_matrices_different_width_case buffer.clear() << base_folder << SEP << series_folder; ret = area_1->hydro.series->LoadMaxPower(area_1->id, buffer); - area_1->hydro.series->setCountVariable(); + area_1->hydro.series->setNbTimeSeriesSup(); BOOST_CHECK(ret); BOOST_CHECK_THROW(area_1->hydro.series->postProcessMaxPowerTS(*area_1), Error::ReadingStudy); } @@ -165,7 +165,7 @@ BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_different_width_case_1, Fixtu buffer.clear() << base_folder << SEP << series_folder; ret = area_1->hydro.series->LoadMaxPower(area_1->id, buffer); - area_1->hydro.series->setCountVariable(); + area_1->hydro.series->setNbTimeSeriesSup(); ret = area_1->hydro.series->postProcessMaxPowerTS(*area_1) && ret; BOOST_CHECK(ret); BOOST_CHECK_EQUAL(maxHourlyGenPower.width, maxHourlyPumpPower.width); @@ -193,7 +193,7 @@ BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_different_width_case_2, Fixtu buffer.clear() << base_folder << SEP << series_folder; ret = area_1->hydro.series->LoadMaxPower(area_1->id, buffer); - area_1->hydro.series->setCountVariable(); + area_1->hydro.series->setNbTimeSeriesSup(); ret = area_1->hydro.series->postProcessMaxPowerTS(*area_1) && ret; BOOST_CHECK(ret); BOOST_CHECK_EQUAL(maxHourlyGenPower.width, maxHourlyPumpPower.width); @@ -221,7 +221,7 @@ BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_both_zeros, Fixture) buffer.clear() << base_folder << SEP << series_folder; ret = area_1->hydro.series->LoadMaxPower(area_1->id, buffer); - area_1->hydro.series->setCountVariable(); + area_1->hydro.series->setNbTimeSeriesSup(); maxHourlyGenPower.width = 0; maxHourlyPumpPower.width = 0; ret = area_1->hydro.series->postProcessMaxPowerTS(*area_1) && ret; From b35642049f3e0236f186bbc805a5864c1197e317 Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Fri, 29 Sep 2023 14:48:28 +0200 Subject: [PATCH 19/40] Lambda function refactor --- src/solver/hydro/management/management.cpp | 25 +++++++--------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/solver/hydro/management/management.cpp b/src/solver/hydro/management/management.cpp index 85ff4cbe12..690979704d 100644 --- a/src/solver/hydro/management/management.cpp +++ b/src/solver/hydro/management/management.cpp @@ -314,32 +314,23 @@ bool HydroManagement::checkGenerationPowerConsistency(uint numSpace) const [&numSpace, &ret](Data::Area& area) -> decltype(ret) { uint z = area.index; - const auto& ptchro = NumeroChroniquesTireesParPays[numSpace][z]; - auto tsIndex = (uint)ptchro.Hydraulique; - auto tsIndexMaxPower = ptchro.HydrauliqueMaxPower; + auto tsIndex = (uint)NumeroChroniquesTireesParPays[numSpace][z].Hydraulique; + auto tsIndexMaxPower = NumeroChroniquesTireesParPays[numSpace][z].HydrauliqueMaxPower; - // Hourly minimum generation <= hourly inflows for each hour - auto& mingenmatrix = area.hydro.series->mingen; - auto const& srcmingen = mingenmatrix[tsIndex < mingenmatrix.width ? tsIndex : 0]; - auto& maxHourlyGenPowerMatrix = area.hydro.series->maxHourlyGenPower; - auto const& srcMaxHourlyGenPower - = maxHourlyGenPowerMatrix[tsIndexMaxPower < maxHourlyGenPowerMatrix.width - ? tsIndexMaxPower - : 0]; + auto const& srcmingen = area.hydro.series->mingen; + auto const& srcmaxgen = area.hydro.series->maxHourlyGenPower; for (uint h = 0; h < HOURS_PER_YEAR; ++h) { - const auto& max = srcMaxHourlyGenPower[h]; - const auto& min = srcmingen[h]; + const auto& min = srcmingen[tsIndex < srcmingen.width ? tsIndex : 0][h]; + const auto& max = srcmaxgen[tsIndexMaxPower < srcmaxgen.width ? tsIndexMaxPower : 0][h]; if (max < min) - { // Maybe we should put and day in which exception happens? - // Now user can only see in hourly resolution when an exception occur. + { logs.error() << "In area: " << area.name << " [hourly] minimum generation of " << min << " MW in timestep " << h + 1 << " of TS-" << tsIndex + 1 << " is incompatible with the maximum generation of " << max - << " MW in timestep " << h + 1 << " of TS-" << tsIndexMaxPower + 1 - << " MW."; + << " MW in timestep " << h + 1 << " of TS-" << tsIndexMaxPower + 1 << " MW."; ret = false; return ret; } From 069565f23888e93c4084975d1d8171a910b7183b Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Fri, 29 Sep 2023 15:44:38 +0200 Subject: [PATCH 20/40] Get and Set functions --- src/libs/antares/study/area/list.cpp | 2 +- src/libs/antares/study/area/scratchpad.cpp | 2 +- src/libs/antares/study/parts/hydro/series.cpp | 10 ++++++++++ src/libs/antares/study/parts/hydro/series.h | 12 ++++++++++++ .../antares/study/scenario-builder/applyToMatrix.hxx | 2 +- .../aleatoire/alea_tirage_au_sort_chroniques.cpp | 2 +- src/solver/simulation/timeseries-numbers.cpp | 6 +++--- .../test-sc-builder-file-read-line.cpp | 6 +++--- .../scenario-builder/test-sc-builder-file-save.cpp | 6 +++--- .../action/handler/antares-study/area/timeseries.cpp | 2 +- 10 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/libs/antares/study/area/list.cpp b/src/libs/antares/study/area/list.cpp index 0987ac2720..076b23a3aa 100644 --- a/src/libs/antares/study/area/list.cpp +++ b/src/libs/antares/study/area/list.cpp @@ -1647,7 +1647,7 @@ void AreaList::removeHydroTimeseries() area.hydro.series->maxHourlyGenPower.reset(1, HOURS_PER_YEAR); area.hydro.series->maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); area.hydro.series->count = 1; - area.hydro.series->nbTimeSeriesSup = 1; + area.hydro.series->setNbTimeSeriesSup(1); }); } diff --git a/src/libs/antares/study/area/scratchpad.cpp b/src/libs/antares/study/area/scratchpad.cpp index 9b32e83396..747f4d078c 100644 --- a/src/libs/antares/study/area/scratchpad.cpp +++ b/src/libs/antares/study/area/scratchpad.cpp @@ -78,7 +78,7 @@ AreaScratchpad::AreaScratchpad(const StudyRuntimeInfos& rinfos, Area& area) : ts // Hourly maximum generation/pumping power matrices and their number of TS's (width of matrices) auto const& maxHourlyGenPower = area.hydro.series->maxHourlyGenPower; auto const& maxHourlyPumpPower = area.hydro.series->maxHourlyPumpPower; - uint nbOfMaxPowerTimeSeries = area.hydro.series->nbTimeSeriesSup; + uint nbOfMaxPowerTimeSeries = area.hydro.series->getNbTimeSeriesSup(); // Setting width and height of daily mean maximum generation/pumping power matrices meanMaxDailyGenPower.reset(nbOfMaxPowerTimeSeries, DAYS_PER_YEAR); diff --git a/src/libs/antares/study/parts/hydro/series.cpp b/src/libs/antares/study/parts/hydro/series.cpp index 10c808cd78..8b32997160 100644 --- a/src/libs/antares/study/parts/hydro/series.cpp +++ b/src/libs/antares/study/parts/hydro/series.cpp @@ -287,6 +287,16 @@ void DataSeriesHydro::setHydroModulability(Study& study, const AreaName& areaID) } } +void DataSeriesHydro::setNbTimeSeriesSup(uint nbTimeSeriesSup_) +{ + nbTimeSeriesSup = nbTimeSeriesSup_; +} + +uint DataSeriesHydro::getNbTimeSeriesSup() const +{ + return nbTimeSeriesSup; +} + void DataSeriesHydro::setNbTimeSeriesSup() { const auto& maxHourlyGenPower_ = maxHourlyGenPower.width; diff --git a/src/libs/antares/study/parts/hydro/series.h b/src/libs/antares/study/parts/hydro/series.h index 0a44bb5da3..d170b3ac7f 100644 --- a/src/libs/antares/study/parts/hydro/series.h +++ b/src/libs/antares/study/parts/hydro/series.h @@ -154,6 +154,7 @@ class DataSeriesHydro */ uint count; +private: /*! ** \brief The number of time-series for maxHourlyGenPower and maxHourlyPumpPower matrices ** @@ -164,6 +165,7 @@ class DataSeriesHydro */ uint nbTimeSeriesSup = 0; +public: /*! ** \brief Monte-Carlo */ @@ -184,11 +186,21 @@ class DataSeriesHydro void setHydroModulability(Study& study, const AreaName& areaID) const; + /** + * \brief Setting TS's number of maximum generation and pumping matrices + */ + void setNbTimeSeriesSup(uint nbTimeSeriesSup_); + /** * \brief Setting TS's number of maximum generation and pumping matrices */ void setNbTimeSeriesSup(); + /** + * \brief Get function for TS's number of maximum generation and pumping matrices + */ + uint getNbTimeSeriesSup() const; + /** * \brief Setting TS's when derated mode is on */ diff --git a/src/libs/antares/study/scenario-builder/applyToMatrix.hxx b/src/libs/antares/study/scenario-builder/applyToMatrix.hxx index c85a4d3d65..ade5b939b3 100644 --- a/src/libs/antares/study/scenario-builder/applyToMatrix.hxx +++ b/src/libs/antares/study/scenario-builder/applyToMatrix.hxx @@ -49,7 +49,7 @@ template static inline bool CheckValidityHydroMaxPower(uint value, const D& data, uint tsGenMax) { // TS Generator never used - return (!tsGenMax) ? (value < data.nbTimeSeriesSup) : (value < tsGenMax); + return (!tsGenMax) ? (value < data.getNbTimeSeriesSup()) : (value < tsGenMax); } template diff --git a/src/solver/aleatoire/alea_tirage_au_sort_chroniques.cpp b/src/solver/aleatoire/alea_tirage_au_sort_chroniques.cpp index 0e851ebd9b..75c93f15d9 100644 --- a/src/solver/aleatoire/alea_tirage_au_sort_chroniques.cpp +++ b/src/solver/aleatoire/alea_tirage_au_sort_chroniques.cpp @@ -71,7 +71,7 @@ void ApplyRandomTSnumbers(const Study& study, { const Data::DataSeriesHydro& data = *area.hydro.series; assert(year < data.timeseriesNumbersHydroMaxPower.height); - ptchro.HydrauliqueMaxPower = (data.nbTimeSeriesSup != 1) + ptchro.HydrauliqueMaxPower = (data.getNbTimeSeriesSup() != 1) ? (data.timeseriesNumbersHydroMaxPower[0][year]) : 0; // zero-based } diff --git a/src/solver/simulation/timeseries-numbers.cpp b/src/solver/simulation/timeseries-numbers.cpp index 23ce912430..26ab49a11a 100644 --- a/src/solver/simulation/timeseries-numbers.cpp +++ b/src/solver/simulation/timeseries-numbers.cpp @@ -168,7 +168,7 @@ class hydroMaxPowerAreaNumberOfTSretriever : public areaNumberOfTSretriever } std::vector getAreaTimeSeriesNumber(const Area& area) override { - std::vector to_return = {area.hydro.series->nbTimeSeriesSup}; + std::vector to_return = {area.hydro.series->getNbTimeSeriesSup()}; return to_return; } uint getGeneratedTimeSeriesNumber() override @@ -452,7 +452,7 @@ bool checkInterModalConsistencyForArea(Area& area, indexTS = ts_to_tsIndex.at(timeSeriesHydroMaxPower); if (isTSintermodal[indexTS]) { - uint nbTimeSeries = area.hydro.series->nbTimeSeriesSup; + uint nbTimeSeries = area.hydro.series->getNbTimeSeriesSup(); listNumberTsOverArea.push_back(nbTimeSeries); } @@ -897,7 +897,7 @@ static void fixTSNumbersWhenWidthIsOne(Study& study) area.hydro.series->timeseriesNumbers, area.hydro.series->count, years); // Hydro Max Power fixTSNumbersSingleAreaSingleMode( - area.hydro.series->timeseriesNumbersHydroMaxPower, area.hydro.series->nbTimeSeriesSup, years); + area.hydro.series->timeseriesNumbersHydroMaxPower, area.hydro.series->getNbTimeSeriesSup(), years); // Thermal std::for_each(area.thermal.clusters.cbegin(), diff --git a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp index 71281e1f6a..38b0ab6102 100644 --- a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp +++ b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp @@ -89,9 +89,9 @@ struct Fixture // Hydro Max Power: set the nb of ready made TS nbReadyMadeTS = 15; - area_1->hydro.series->nbTimeSeriesSup = nbReadyMadeTS; - area_2->hydro.series->nbTimeSeriesSup = nbReadyMadeTS; - area_3->hydro.series->nbTimeSeriesSup = nbReadyMadeTS; + area_1->hydro.series->setNbTimeSeriesSup(nbReadyMadeTS); + area_2->hydro.series->setNbTimeSeriesSup(nbReadyMadeTS); + area_3->hydro.series->setNbTimeSeriesSup(nbReadyMadeTS); // Links link_12 = AreaAddLinkBetweenAreas(area_1, area_2, false); diff --git a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp index d5089555da..97df58e4a1 100644 --- a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp +++ b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp @@ -131,9 +131,9 @@ struct commonFixture // Hydro Max Power : set the nb of ready made TS nbReadyMadeTS = 15; - area_1->hydro.series->nbTimeSeriesSup = nbReadyMadeTS; - area_2->hydro.series->nbTimeSeriesSup = nbReadyMadeTS; - area_3->hydro.series->nbTimeSeriesSup = nbReadyMadeTS; + area_1->hydro.series->setNbTimeSeriesSup(nbReadyMadeTS); + area_2->hydro.series->setNbTimeSeriesSup(nbReadyMadeTS); + area_3->hydro.series->setNbTimeSeriesSup(nbReadyMadeTS); // Links link_12 = AreaAddLinkBetweenAreas(area_1, area_2, false); diff --git a/src/ui/action/handler/antares-study/area/timeseries.cpp b/src/ui/action/handler/antares-study/area/timeseries.cpp index 3ca94f2eac..9b0788a25b 100644 --- a/src/ui/action/handler/antares-study/area/timeseries.cpp +++ b/src/ui/action/handler/antares-study/area/timeseries.cpp @@ -178,7 +178,7 @@ bool DataTimeseries::performWL(Context& ctx) ctx.area->hydro.series->maxHourlyGenPower = source->hydro.series->maxHourlyGenPower; ctx.area->hydro.series->maxHourlyPumpPower = source->hydro.series->maxHourlyPumpPower; - ctx.area->hydro.series->nbTimeSeriesSup = source->hydro.series->nbTimeSeriesSup; + ctx.area->hydro.series->setNbTimeSeriesSup(source->hydro.series->getNbTimeSeriesSup()); source->hydro.series->maxHourlyGenPower.unloadFromMemory(); source->hydro.series->maxHourlyPumpPower.unloadFromMemory(); From dbb2407f9a12ba0ed6a7d908a31127b298deec93 Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Fri, 29 Sep 2023 18:38:41 +0200 Subject: [PATCH 21/40] Small refactoring --- .../parts/hydro/hydromaxtimeseriesreader.cpp | 6 ++--- src/libs/antares/study/parts/hydro/series.h | 24 ++++++++++--------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.cpp b/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.cpp index 84af75d815..fcb8ceddae 100644 --- a/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.cpp +++ b/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.cpp @@ -104,8 +104,7 @@ bool HydroMaxTimeSeriesReader::SaveMaxGenerationEnergy(const AnyString& folder, maxDailyGenEnergy.reset(1, DAYS_PER_YEAR, true); maxDailyGenEnergy.fillColumn(0, 24.); - for (uint day = 0; day < DAYS_PER_YEAR; ++day) - maxDailyGenEnergy[0][day] = dailyMaxPumpAndGen[genMaxE][day]; + maxDailyGenEnergy.pasteToColumn(0, dailyMaxPumpAndGen[genMaxE]); filePath.clear() << folder << SEP << "common" << SEP << "capacity" << SEP << "maxDailyGenEnergy_" << area.id << ".txt"; @@ -124,8 +123,7 @@ bool HydroMaxTimeSeriesReader::SaveMaxPumpingEnergy(const AnyString& folder, Are maxDailyPumpEnergy.reset(1, DAYS_PER_YEAR, true); maxDailyPumpEnergy.fillColumn(0, 24.); - for (uint day = 0; day < DAYS_PER_YEAR; ++day) - maxDailyPumpEnergy[0][day] = dailyMaxPumpAndGen[pumpMaxE][day]; + maxDailyPumpEnergy.pasteToColumn(0, dailyMaxPumpAndGen[pumpMaxE]); filePath.clear() << folder << SEP << "common" << SEP << "capacity" << SEP << "maxDailyPumpEnergy_" << area.id << ".txt"; diff --git a/src/libs/antares/study/parts/hydro/series.h b/src/libs/antares/study/parts/hydro/series.h index d170b3ac7f..14ffeba7d1 100644 --- a/src/libs/antares/study/parts/hydro/series.h +++ b/src/libs/antares/study/parts/hydro/series.h @@ -154,17 +154,6 @@ class DataSeriesHydro */ uint count; -private: - /*! - ** \brief The number of time-series for maxHourlyGenPower and maxHourlyPumpPower matrices - ** - ** This value must be the same as the width of the matrices `maxHourlyGenPower` and `maxHourlyPumpPower`. - ** It is only provided for convenience to avoid same strange and ambiguous code - ** (for example using `maxHourlyGenPower.width` and `maxHourlyPumpPower.width` in the same routine, it might - ** indicate that the two values are not strictly equal) - */ - uint nbTimeSeriesSup = 0; - public: /*! ** \brief Monte-Carlo @@ -206,6 +195,19 @@ class DataSeriesHydro */ void setMaxPowerTSWhenDeratedMode(const Study& study); +private: + /*! + ** \brief The number of time-series for maxHourlyGenPower and maxHourlyPumpPower matrices + ** + ** This value must be the same as the width of the matrices `maxHourlyGenPower` and + *`maxHourlyPumpPower`. + ** It is only provided for convenience to avoid same strange and ambiguous code + ** (for example using `maxHourlyGenPower.width` and `maxHourlyPumpPower.width` in the same + *routine, it might + ** indicate that the two values are not strictly equal) + */ + uint nbTimeSeriesSup = 0; + /** * This class provides comparing two integers * that represents width of two corresponding matrices. From 0981477e355fae5d57ce71766724aaed0d235e4a Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Tue, 3 Oct 2023 20:47:58 +0200 Subject: [PATCH 22/40] Name convention --- src/solver/aleatoire/alea_tirage_au_sort_chroniques.cpp | 2 +- src/solver/hydro/management/daily.cpp | 2 +- src/solver/hydro/management/management.cpp | 2 +- src/solver/simulation/sim_calcul_economique.cpp | 4 ++-- src/solver/simulation/sim_structure_donnees.h | 2 +- src/solver/variable/economy/max-mrg.cpp | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/solver/aleatoire/alea_tirage_au_sort_chroniques.cpp b/src/solver/aleatoire/alea_tirage_au_sort_chroniques.cpp index 75c93f15d9..2783c84e33 100644 --- a/src/solver/aleatoire/alea_tirage_au_sort_chroniques.cpp +++ b/src/solver/aleatoire/alea_tirage_au_sort_chroniques.cpp @@ -71,7 +71,7 @@ void ApplyRandomTSnumbers(const Study& study, { const Data::DataSeriesHydro& data = *area.hydro.series; assert(year < data.timeseriesNumbersHydroMaxPower.height); - ptchro.HydrauliqueMaxPower = (data.getNbTimeSeriesSup() != 1) + ptchro.HydroMaxPower = (data.getNbTimeSeriesSup() != 1) ? (data.timeseriesNumbersHydroMaxPower[0][year]) : 0; // zero-based } diff --git a/src/solver/hydro/management/daily.cpp b/src/solver/hydro/management/daily.cpp index 9d14af6a81..8f5969169f 100644 --- a/src/solver/hydro/management/daily.cpp +++ b/src/solver/hydro/management/daily.cpp @@ -256,7 +256,7 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St auto const& maxDailyGenEnergy = area.hydro.maxDailyGenEnergy; - uint tsIndexMaxPower = (NumeroChroniquesTireesParPays[numSpace][z]).HydrauliqueMaxPower; + uint tsIndexMaxPower = (NumeroChroniquesTireesParPays[numSpace][z]).HydroMaxPower; auto const& maxP = meanMaxDailyGenPower[tsIndexMaxPower]; auto const& maxE = maxDailyGenEnergy[0]; diff --git a/src/solver/hydro/management/management.cpp b/src/solver/hydro/management/management.cpp index 690979704d..1baa1985a2 100644 --- a/src/solver/hydro/management/management.cpp +++ b/src/solver/hydro/management/management.cpp @@ -315,7 +315,7 @@ bool HydroManagement::checkGenerationPowerConsistency(uint numSpace) const { uint z = area.index; auto tsIndex = (uint)NumeroChroniquesTireesParPays[numSpace][z].Hydraulique; - auto tsIndexMaxPower = NumeroChroniquesTireesParPays[numSpace][z].HydrauliqueMaxPower; + auto tsIndexMaxPower = NumeroChroniquesTireesParPays[numSpace][z].HydroMaxPower; auto const& srcmingen = area.hydro.series->mingen; auto const& srcmaxgen = area.hydro.series->maxHourlyGenPower; diff --git a/src/solver/simulation/sim_calcul_economique.cpp b/src/solver/simulation/sim_calcul_economique.cpp index 570fbae159..d17fd4950b 100644 --- a/src/solver/simulation/sim_calcul_economique.cpp +++ b/src/solver/simulation/sim_calcul_economique.cpp @@ -565,7 +565,7 @@ void SIM_RenseignementProblemeHebdo(const Study& study, for (uint k = 0; k < nbPays; ++k) { auto& tsIndex = NumeroChroniquesTireesParPays[numSpace][k]; - uint tsIndexMaxPower = tsIndex.HydrauliqueMaxPower; + uint tsIndexMaxPower = tsIndex.HydroMaxPower; auto& area = *(study.areas.byIndex[k]); auto& scratchpad = area.scratchpad[numSpace]; auto& ror = area.hydro.series->ror; @@ -653,7 +653,7 @@ void SIM_RenseignementProblemeHebdo(const Study& study, uint tsIndex = (NumeroChroniquesTireesParPays[numSpace][k]).Hydraulique; auto& inflowsmatrix = area.hydro.series->storage; auto const& srcinflows = inflowsmatrix[tsIndex < inflowsmatrix.width ? tsIndex : 0]; - uint tsIndexMaxPower = (NumeroChroniquesTireesParPays[numSpace][k]).HydrauliqueMaxPower; + uint tsIndexMaxPower = (NumeroChroniquesTireesParPays[numSpace][k]).HydroMaxPower; auto& scratchpad = area.scratchpad[numSpace]; auto& dailyMeanMaxGenPower = scratchpad.meanMaxDailyGenPower[tsIndexMaxPower]; auto& dailyMeanMaxPumpPower = scratchpad.meanMaxDailyPumpPower[tsIndexMaxPower]; diff --git a/src/solver/simulation/sim_structure_donnees.h b/src/solver/simulation/sim_structure_donnees.h index 4017f352f1..725890b24a 100644 --- a/src/solver/simulation/sim_structure_donnees.h +++ b/src/solver/simulation/sim_structure_donnees.h @@ -34,7 +34,7 @@ typedef struct std::vector ThermiqueParPalier; std::vector RenouvelableParPalier; int Hydraulique; - unsigned int HydrauliqueMaxPower; + unsigned int HydroMaxPower; int Eolien; int Consommation; int Solar; diff --git a/src/solver/variable/economy/max-mrg.cpp b/src/solver/variable/economy/max-mrg.cpp index ca9eee4424..a1eb79b92f 100644 --- a/src/solver/variable/economy/max-mrg.cpp +++ b/src/solver/variable/economy/max-mrg.cpp @@ -133,7 +133,7 @@ inline void PrepareMaxMRGFor(const State& state, double* opmrg, uint numSpace) uint loop = 100; // arbitrary - maximum number of iterations // Pmax - uint tsIndex = (NumeroChroniquesTireesParPays[numSpace][index]).HydrauliqueMaxPower; + uint tsIndex = (NumeroChroniquesTireesParPays[numSpace][index]).HydroMaxPower; auto& maxHourlyGenPowerMatrix = area.hydro.series->maxHourlyGenPower; const auto& P = maxHourlyGenPowerMatrix[tsIndex < maxHourlyGenPowerMatrix.width ? tsIndex : 0]; From e5bb73adc1720c1783c4db56f4c57c4324de2b84 Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Tue, 3 Oct 2023 21:23:06 +0200 Subject: [PATCH 23/40] Ternary operator check index excluded --- src/solver/simulation/sim_calcul_economique.cpp | 13 ++++++------- src/solver/variable/economy/max-mrg.cpp | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/solver/simulation/sim_calcul_economique.cpp b/src/solver/simulation/sim_calcul_economique.cpp index d17fd4950b..40bcd41846 100644 --- a/src/solver/simulation/sim_calcul_economique.cpp +++ b/src/solver/simulation/sim_calcul_economique.cpp @@ -571,15 +571,14 @@ void SIM_RenseignementProblemeHebdo(const Study& study, auto& ror = area.hydro.series->ror; auto& maxHourlyGenPowerMatrix = area.hydro.series->maxHourlyGenPower; - auto const& srcMaxHourlyGenPower - = maxHourlyGenPowerMatrix[tsIndexMaxPower < maxHourlyGenPowerMatrix.width ? tsIndexMaxPower : 0]; - auto const& ContrainteDePmaxHydrauliqueHoraire = srcMaxHourlyGenPower[PasDeTempsDebut + hourInWeek]; + auto const& maxHourlyGenPowerTS + = maxHourlyGenPowerMatrix[tsIndexMaxPower]; + auto const& ContrainteDePmaxHydrauliqueHoraire = maxHourlyGenPowerTS[PasDeTempsDebut + hourInWeek]; auto& maxHourlyPumpPowerMatrix = area.hydro.series->maxHourlyPumpPower; - auto const& srcMaxHourlyPumpPower - = maxHourlyPumpPowerMatrix[tsIndexMaxPower < maxHourlyPumpPowerMatrix.width ? tsIndexMaxPower - : 0]; - auto const& ContrainteDePmaxPompageHoraire = srcMaxHourlyPumpPower[PasDeTempsDebut + hourInWeek]; + auto const& maxHourlyPumpPowerTS + = maxHourlyPumpPowerMatrix[tsIndexMaxPower]; + auto const& ContrainteDePmaxPompageHoraire = maxHourlyPumpPowerTS[PasDeTempsDebut + hourInWeek]; assert(&scratchpad); assert((uint)hourInYear < scratchpad.ts.load.height); diff --git a/src/solver/variable/economy/max-mrg.cpp b/src/solver/variable/economy/max-mrg.cpp index a1eb79b92f..f522e52259 100644 --- a/src/solver/variable/economy/max-mrg.cpp +++ b/src/solver/variable/economy/max-mrg.cpp @@ -135,7 +135,7 @@ inline void PrepareMaxMRGFor(const State& state, double* opmrg, uint numSpace) // Pmax uint tsIndex = (NumeroChroniquesTireesParPays[numSpace][index]).HydroMaxPower; auto& maxHourlyGenPowerMatrix = area.hydro.series->maxHourlyGenPower; - const auto& P = maxHourlyGenPowerMatrix[tsIndex < maxHourlyGenPowerMatrix.width ? tsIndex : 0]; + const auto& P = maxHourlyGenPowerMatrix[tsIndex]; do { From 69a339e2825db59fdb861f52550349c67c2502a8 Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Tue, 3 Oct 2023 22:57:28 +0200 Subject: [PATCH 24/40] Clang Format undone --- src/solver/simulation/sim_calcul_economique.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/solver/simulation/sim_calcul_economique.cpp b/src/solver/simulation/sim_calcul_economique.cpp index 40bcd41846..beb1696131 100644 --- a/src/solver/simulation/sim_calcul_economique.cpp +++ b/src/solver/simulation/sim_calcul_economique.cpp @@ -624,10 +624,8 @@ void SIM_RenseignementProblemeHebdo(const Study& study, if (problem.CaracteristiquesHydrauliques[k].PresenceDHydrauliqueModulable > 0) { - problem.CaracteristiquesHydrauliques[k] - .ContrainteDePmaxHydrauliqueHoraire[hourInWeek] + problem.CaracteristiquesHydrauliques[k].ContrainteDePmaxHydrauliqueHoraire[hourInWeek] = ContrainteDePmaxHydrauliqueHoraire - * problem.CaracteristiquesHydrauliques[k].WeeklyGeneratingModulation; } From 3aeef1c21fae8a53830afcca6579f0ae580294a3 Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Wed, 4 Oct 2023 00:07:41 +0200 Subject: [PATCH 25/40] Function argument names --- src/libs/antares/study/area/scratchpad.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/antares/study/area/scratchpad.h b/src/libs/antares/study/area/scratchpad.h index 76cbd046c5..f019ad7c75 100644 --- a/src/libs/antares/study/area/scratchpad.h +++ b/src/libs/antares/study/area/scratchpad.h @@ -124,8 +124,8 @@ void CalculateDailyMeanPower(const Matrix::ColumnType& hourlyColumn, Matrix::ColumnType& dailyColumn); // Return true if maximum generated energy just in one day and for every TS is grated than 0 -bool CheckForPositiveEnergy(const Matrix& matrix, - const Matrix::ColumnType& hours); +bool CheckForPositiveEnergy(const Matrix& power, + const Matrix::ColumnType& energy); } // namespace Antares::Data From 37095523e4a94e08b0ba79524ef33f79ea4f761d Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Sat, 7 Oct 2023 11:27:57 +0200 Subject: [PATCH 26/40] Possible Bug? --- src/libs/antares/study/area/list.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/libs/antares/study/area/list.cpp b/src/libs/antares/study/area/list.cpp index 076b23a3aa..3c7b5d4efb 100644 --- a/src/libs/antares/study/area/list.cpp +++ b/src/libs/antares/study/area/list.cpp @@ -1644,10 +1644,7 @@ void AreaList::removeHydroTimeseries() area.hydro.series->ror.reset(1, HOURS_PER_YEAR); area.hydro.series->storage.reset(1, DAYS_PER_YEAR); area.hydro.series->mingen.reset(1, HOURS_PER_YEAR); - area.hydro.series->maxHourlyGenPower.reset(1, HOURS_PER_YEAR); - area.hydro.series->maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); area.hydro.series->count = 1; - area.hydro.series->setNbTimeSeriesSup(1); }); } From 6254c41c70a7a38b6eecec420cdeaa786d841196 Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Sun, 8 Oct 2023 11:24:27 +0200 Subject: [PATCH 27/40] Refactoring lambda function --- src/solver/hydro/management/management.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/solver/hydro/management/management.cpp b/src/solver/hydro/management/management.cpp index 1baa1985a2..9c77ac274a 100644 --- a/src/solver/hydro/management/management.cpp +++ b/src/solver/hydro/management/management.cpp @@ -311,7 +311,7 @@ bool HydroManagement::checkGenerationPowerConsistency(uint numSpace) const bool ret = true; areas_.each( - [&numSpace, &ret](Data::Area& area) -> decltype(ret) + [&numSpace, &ret](Data::Area& area) { uint z = area.index; auto tsIndex = (uint)NumeroChroniquesTireesParPays[numSpace][z].Hydraulique; @@ -332,10 +332,9 @@ bool HydroManagement::checkGenerationPowerConsistency(uint numSpace) const << " is incompatible with the maximum generation of " << max << " MW in timestep " << h + 1 << " of TS-" << tsIndexMaxPower + 1 << " MW."; ret = false; - return ret; + return; } } - return ret; }); return ret; From fe533f4ed17fd92bf22a170681fbee172089a979 Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Thu, 12 Oct 2023 22:14:33 +0200 Subject: [PATCH 28/40] Refactoring Unit tests --- .../study/parts/hydro/help-functions.cpp | 74 ++-- .../study/parts/hydro/help-functions.h | 12 +- .../study/parts/hydro/test-hydro-series.cpp | 338 ++++++++++-------- .../parts/hydro/test-hydroreader-class.cpp | 97 +++-- 4 files changed, 285 insertions(+), 236 deletions(-) diff --git a/src/tests/src/libs/antares/study/parts/hydro/help-functions.cpp b/src/tests/src/libs/antares/study/parts/hydro/help-functions.cpp index 4a96fbb0ce..231904c175 100644 --- a/src/tests/src/libs/antares/study/parts/hydro/help-functions.cpp +++ b/src/tests/src/libs/antares/study/parts/hydro/help-functions.cpp @@ -1,12 +1,20 @@ #include "help-functions.h" -void createFolder(const my_string& path, const my_string& folder_name) +void createFolder(const stringT& path, const stringT& folder_name) { fs::path folder_path = fs::path(path.c_str()) / folder_name.c_str(); - fs::create_directory(folder_path); + + try + { + fs::create_directory(folder_path); + } + catch (const fs::filesystem_error& e) + { + std::cerr << "Exception deleting folder '" + folder_name + "': " + e.what() + "\n"; + } } -bool createFile(const my_string& folder_path, const my_string& file_name) +void createFile(const stringT& folder_path, const stringT& file_name) { // Construct the full path to the file fs::path path = fs::path(folder_path.c_str()) / file_name.c_str(); @@ -14,17 +22,24 @@ bool createFile(const my_string& folder_path, const my_string& file_name) // Create an output file stream std::ofstream outputFile(path); - if (outputFile.is_open()) + try { - // File was successfully created and is open - outputFile << "This is a sample content." << std::endl; - outputFile.close(); - return true; + if (outputFile.is_open()) + { + // File was successfully created and is open + outputFile << "This is a sample content." << std::endl; + outputFile.close(); + std::cout << "File " + file_name + " is created in " + folder_path + "\n"; + } + else + { + // Failed to create or open the file + throw std::runtime_error("Failed to create file\n"); + } } - else + catch(const std::exception& e) { - // Failed to create or open the file - return false; + std::cerr << "Error: " << e.what() << "\n"; } } @@ -57,7 +72,7 @@ void InstantiateColumn(Matrix::ColumnType& col, double seed, uint type) } } -void removeFolder(my_string& path, my_string& folder_name) +void removeFolder(stringT& path, stringT& folder_name) { fs::path folder_path = fs::path(path.c_str()) / folder_name.c_str(); if (fs::exists(folder_path)) @@ -65,40 +80,13 @@ void removeFolder(my_string& path, my_string& folder_name) try { fs::remove_all(folder_path); - std::cout << "Folder '" << folder_name << "' at '" << folder_path - << "' deleted.\n"; + std::cout << "Folder '" + folder_name + "' at '" + folder_path.string() + + "' deleted.\n"; } catch (const fs::filesystem_error& e) { - std::cerr << "Exception deleting folder '" << folder_name << "': " << e.what() - << "\n"; + std::cerr << "Exception deleting folder '" + folder_name + "': " + e.what() + + "\n"; } } -} - -bool DailyMaxPowerAsHourlyTransferCheck(Matrix::ColumnType& hourlyColumn, - const Matrix::ColumnType& dailyColumn) -{ - uint hours = 0; - uint days = 0; - bool check = true; - - while (hours < HOURS_PER_YEAR && days < DAYS_PER_YEAR) - { - for (uint i = 0; i < 24; ++i) - { - if (hourlyColumn[hours] != dailyColumn[days]) - { - check = false; - break; - } - ++hours; - } - - if (!check) - break; - - ++days; - } - return check; } \ No newline at end of file diff --git a/src/tests/src/libs/antares/study/parts/hydro/help-functions.h b/src/tests/src/libs/antares/study/parts/hydro/help-functions.h index 655a42f312..5bf9b1e5dc 100644 --- a/src/tests/src/libs/antares/study/parts/hydro/help-functions.h +++ b/src/tests/src/libs/antares/study/parts/hydro/help-functions.h @@ -5,17 +5,13 @@ #include #include -#define SEP Yuni::IO::Separator - using namespace Antares::Data; -using my_string = Yuni::CString<256, false>; +using stringT = std::string; using namespace std; namespace fs = std::filesystem; -void createFolder(const my_string& path, const my_string& folder_name); -bool createFile(const my_string& folder_path, const my_string& file_name); +void createFolder(const stringT& path, const stringT& folder_name); +void createFile(const stringT& folder_path, const stringT& file_name); void InstantiateMatrix(Matrix& matrix, double seed, uint type); void InstantiateColumn(Matrix::ColumnType& col, double seed, uint type); -void removeFolder(my_string& path, my_string& folder_name); -bool DailyMaxPowerAsHourlyTransferCheck(Matrix::ColumnType& hourlyColumn, - const Matrix::ColumnType& dailyColumn); \ No newline at end of file +void removeFolder(stringT& path, stringT& folder_name); \ No newline at end of file diff --git a/src/tests/src/libs/antares/study/parts/hydro/test-hydro-series.cpp b/src/tests/src/libs/antares/study/parts/hydro/test-hydro-series.cpp index 45a73e96c9..e6c8dae982 100644 --- a/src/tests/src/libs/antares/study/parts/hydro/test-hydro-series.cpp +++ b/src/tests/src/libs/antares/study/parts/hydro/test-hydro-series.cpp @@ -7,6 +7,8 @@ #include #include +#define SEP "/" + struct Fixture { Fixture() @@ -29,26 +31,28 @@ struct Fixture void createFoldersAndFiles() { // series folder - my_string buffer; + stringT buffer; createFolder(base_folder, series_folder); // areas folder - my_string area1_folder = area_1->id; - buffer.clear() << base_folder << SEP << series_folder; + stringT area1_folder = "Area1"; + buffer.clear(); + buffer = base_folder + SEP + series_folder; createFolder(buffer, area1_folder); // maxHourlyGenPower and maxHourlyPumpPower files - buffer.clear() << base_folder << SEP << series_folder << SEP << area1_folder; + buffer.clear(); + buffer = base_folder + SEP + series_folder + SEP + area1_folder; createFile(buffer, maxHourlyGenPower_file); createFile(buffer, maxHourlyPumpPower_file); } shared_ptr study; Area* area_1; - my_string base_folder = fs::current_path().string(); - my_string series_folder = "series"; - my_string maxHourlyGenPower_file = "maxHourlyGenPower.txt"; - my_string maxHourlyPumpPower_file = "maxHourlyPumpPower.txt"; + stringT base_folder = fs::current_path().string(); + stringT series_folder = "series"; + stringT maxHourlyGenPower_file = "maxHourlyGenPower.txt"; + stringT maxHourlyPumpPower_file = "maxHourlyPumpPower.txt"; ~Fixture() { @@ -69,165 +73,189 @@ BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_matrices_equal_width, Fixture InstantiateMatrix(maxHourlyGenPower, 400., HOURS_PER_YEAR); InstantiateMatrix(maxHourlyPumpPower, 200., HOURS_PER_YEAR); - my_string buffer; - buffer.clear() << base_folder << SEP << series_folder << SEP << area_1->id << SEP << maxHourlyGenPower_file; - maxHourlyGenPower.saveToCSVFile(buffer, 0); - buffer.clear() << base_folder << SEP << series_folder << SEP << area_1->id << SEP << maxHourlyPumpPower_file; - maxHourlyPumpPower.saveToCSVFile(buffer, 0); + stringT buffer; - maxHourlyGenPower.reset(3, HOURS_PER_YEAR); - maxHourlyPumpPower.reset(3, HOURS_PER_YEAR); + buffer.clear(); + buffer = base_folder + SEP + series_folder + SEP + "Area1" + SEP + maxHourlyGenPower_file; + Yuni::CString<256, false> temp1(buffer); + ret = maxHourlyGenPower.saveToCSVFile(temp1, 0) && ret; - buffer.clear() << base_folder << SEP << series_folder; - ret = area_1->hydro.series->LoadMaxPower(area_1->id, buffer); - area_1->hydro.series->setNbTimeSeriesSup(); - ret = area_1->hydro.series->postProcessMaxPowerTS(*area_1) && ret; - BOOST_CHECK(ret); - BOOST_CHECK_EQUAL(maxHourlyGenPower.width, 3); -} + buffer.clear(); + buffer = base_folder + SEP + series_folder + SEP + "Area1" + SEP + maxHourlyPumpPower_file; -BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_both_matrix_equal_width_and_derated, Fixture) -{ - bool ret = true; - study->parameters.derated = true; - auto& maxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower; - auto& maxHourlyPumpPower = area_1->hydro.series->maxHourlyPumpPower; - maxHourlyGenPower.reset(3, HOURS_PER_YEAR); - maxHourlyPumpPower.reset(3, HOURS_PER_YEAR); - - InstantiateMatrix(maxHourlyGenPower, 400., HOURS_PER_YEAR); - InstantiateMatrix(maxHourlyPumpPower, 200., HOURS_PER_YEAR); - - my_string buffer; - buffer.clear() << base_folder << SEP << series_folder << SEP << area_1->id << SEP << maxHourlyGenPower_file; - maxHourlyGenPower.saveToCSVFile(buffer, 0); - buffer.clear() << base_folder << SEP << series_folder << SEP << area_1->id << SEP << maxHourlyPumpPower_file; - maxHourlyPumpPower.saveToCSVFile(buffer, 0); + Yuni::CString<256, false> temp2(buffer); + ret = maxHourlyPumpPower.saveToCSVFile(temp2, 0) && ret; maxHourlyGenPower.reset(3, HOURS_PER_YEAR); maxHourlyPumpPower.reset(3, HOURS_PER_YEAR); - buffer.clear() << base_folder << SEP << series_folder; - ret = area_1->hydro.series->LoadMaxPower(area_1->id, buffer) && ret; - ret = area_1->hydro.series->postProcessMaxPowerTS(*area_1) && ret; - area_1->hydro.series->setMaxPowerTSWhenDeratedMode(*study); - BOOST_CHECK_EQUAL(maxHourlyGenPower.width, 1); - BOOST_CHECK_EQUAL(maxHourlyPumpPower.width, 1); - BOOST_CHECK(ret); -} - -BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_matrices_different_width_case_2, Fixture) -{ - bool ret = true; - auto& maxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower; - auto& maxHourlyPumpPower = area_1->hydro.series->maxHourlyPumpPower; - maxHourlyGenPower.reset(3, HOURS_PER_YEAR); - maxHourlyPumpPower.reset(2, HOURS_PER_YEAR); - - InstantiateMatrix(maxHourlyGenPower, 400., HOURS_PER_YEAR); - InstantiateMatrix(maxHourlyPumpPower, 200., HOURS_PER_YEAR); - - my_string buffer; - buffer.clear() << base_folder << SEP << series_folder << SEP << area_1->id << SEP << maxHourlyGenPower_file; - maxHourlyGenPower.saveToCSVFile(buffer, 0); - buffer.clear() << base_folder << SEP << series_folder << SEP << area_1->id << SEP << maxHourlyPumpPower_file; - maxHourlyPumpPower.saveToCSVFile(buffer, 0); - - maxHourlyGenPower.reset(3, HOURS_PER_YEAR); - maxHourlyPumpPower.reset(2, HOURS_PER_YEAR); - - buffer.clear() << base_folder << SEP << series_folder; - ret = area_1->hydro.series->LoadMaxPower(area_1->id, buffer); - area_1->hydro.series->setNbTimeSeriesSup(); - BOOST_CHECK(ret); - BOOST_CHECK_THROW(area_1->hydro.series->postProcessMaxPowerTS(*area_1), Error::ReadingStudy); -} - -BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_different_width_case_1, Fixture) -{ - bool ret = true; - auto& maxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower; - auto& maxHourlyPumpPower = area_1->hydro.series->maxHourlyPumpPower; - maxHourlyGenPower.reset(1, HOURS_PER_YEAR); - maxHourlyPumpPower.reset(3, HOURS_PER_YEAR); - - InstantiateMatrix(maxHourlyGenPower, 400., HOURS_PER_YEAR); - InstantiateMatrix(maxHourlyPumpPower, 200., HOURS_PER_YEAR); - - my_string buffer; - buffer.clear() << base_folder << SEP << series_folder << SEP << area_1->id << SEP << maxHourlyGenPower_file; - maxHourlyGenPower.saveToCSVFile(buffer, 0); - buffer.clear() << base_folder << SEP << series_folder << SEP << area_1->id << SEP << maxHourlyPumpPower_file; - maxHourlyPumpPower.saveToCSVFile(buffer, 0); - - maxHourlyGenPower.reset(1, HOURS_PER_YEAR); - maxHourlyPumpPower.reset(3, HOURS_PER_YEAR); - - buffer.clear() << base_folder << SEP << series_folder; - ret = area_1->hydro.series->LoadMaxPower(area_1->id, buffer); + buffer.clear(); + buffer = base_folder + SEP + series_folder; + Yuni::CString<256, false> temp3(buffer); + ret = area_1->hydro.series->LoadMaxPower(area_1->id, temp3) && ret; area_1->hydro.series->setNbTimeSeriesSup(); ret = area_1->hydro.series->postProcessMaxPowerTS(*area_1) && ret; BOOST_CHECK(ret); - BOOST_CHECK_EQUAL(maxHourlyGenPower.width, maxHourlyPumpPower.width); -} - -BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_different_width_case_2, Fixture) -{ - bool ret = true; - auto& maxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower; - auto& maxHourlyPumpPower = area_1->hydro.series->maxHourlyPumpPower; - maxHourlyGenPower.reset(4, HOURS_PER_YEAR); - maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); - - InstantiateMatrix(maxHourlyGenPower, 400., HOURS_PER_YEAR); - InstantiateMatrix(maxHourlyPumpPower, 200., HOURS_PER_YEAR); - - my_string buffer; - buffer.clear() << base_folder << SEP << series_folder << SEP << area_1->id << SEP << maxHourlyGenPower_file; - maxHourlyGenPower.saveToCSVFile(buffer, 0); - buffer.clear() << base_folder << SEP << series_folder << SEP << area_1->id << SEP << maxHourlyPumpPower_file; - maxHourlyPumpPower.saveToCSVFile(buffer, 0); - - maxHourlyGenPower.reset(4, HOURS_PER_YEAR); - maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); - - buffer.clear() << base_folder << SEP << series_folder; - ret = area_1->hydro.series->LoadMaxPower(area_1->id, buffer); - area_1->hydro.series->setNbTimeSeriesSup(); - ret = area_1->hydro.series->postProcessMaxPowerTS(*area_1) && ret; - BOOST_CHECK(ret); - BOOST_CHECK_EQUAL(maxHourlyGenPower.width, maxHourlyPumpPower.width); + BOOST_CHECK_EQUAL(maxHourlyGenPower.width, 3); } -BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_both_zeros, Fixture) -{ - bool ret = true; - auto& maxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower; - auto& maxHourlyPumpPower = area_1->hydro.series->maxHourlyPumpPower; - maxHourlyGenPower.reset(4, HOURS_PER_YEAR); - maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); - - InstantiateMatrix(maxHourlyGenPower, 400., HOURS_PER_YEAR); - InstantiateMatrix(maxHourlyPumpPower, 200., HOURS_PER_YEAR); - - my_string buffer; - buffer.clear() << base_folder << SEP << series_folder << SEP << area_1->id << SEP << maxHourlyGenPower_file; - maxHourlyGenPower.saveToCSVFile(buffer, 0); - buffer.clear() << base_folder << SEP << series_folder << SEP << area_1->id << SEP << maxHourlyPumpPower_file; - maxHourlyPumpPower.saveToCSVFile(buffer, 0); - - maxHourlyGenPower.reset(4, HOURS_PER_YEAR); - maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); - - buffer.clear() << base_folder << SEP << series_folder; - ret = area_1->hydro.series->LoadMaxPower(area_1->id, buffer); - area_1->hydro.series->setNbTimeSeriesSup(); - maxHourlyGenPower.width = 0; - maxHourlyPumpPower.width = 0; - ret = area_1->hydro.series->postProcessMaxPowerTS(*area_1) && ret; - BOOST_CHECK(!ret); - BOOST_CHECK_EQUAL(maxHourlyGenPower.width, maxHourlyPumpPower.width); -} +// BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_both_matrix_equal_width_and_derated, Fixture) +// { +// bool ret = true; +// study->parameters.derated = true; +// auto& maxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower; +// auto& maxHourlyPumpPower = area_1->hydro.series->maxHourlyPumpPower; +// maxHourlyGenPower.reset(3, HOURS_PER_YEAR); +// maxHourlyPumpPower.reset(3, HOURS_PER_YEAR); + +// InstantiateMatrix(maxHourlyGenPower, 400., HOURS_PER_YEAR); +// InstantiateMatrix(maxHourlyPumpPower, 200., HOURS_PER_YEAR); + +// stringT buffer; +// buffer.clear(); +// buffer = base_folder + SEP + series_folder + SEP + area_1->id + SEP + maxHourlyGenPower_file; +// maxHourlyGenPower.saveToCSVFile(buffer, 0); +// buffer.clear(); +// buffer = base_folder + SEP + series_folder + SEP + area_1->id + SEP + maxHourlyPumpPower_file; +// maxHourlyPumpPower.saveToCSVFile(buffer, 0); + +// maxHourlyGenPower.reset(3, HOURS_PER_YEAR); +// maxHourlyPumpPower.reset(3, HOURS_PER_YEAR); + +// buffer.clear(); +// buffer = base_folder + SEP + series_folder; +// ret = area_1->hydro.series->LoadMaxPower(area_1->id, buffer) && ret; +// ret = area_1->hydro.series->postProcessMaxPowerTS(*area_1) && ret; +// area_1->hydro.series->setMaxPowerTSWhenDeratedMode(*study); +// BOOST_CHECK_EQUAL(maxHourlyGenPower.width, 1); +// BOOST_CHECK_EQUAL(maxHourlyPumpPower.width, 1); +// BOOST_CHECK(ret); +// } + +// BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_matrices_different_width_case_2, Fixture) +// { +// bool ret = true; +// auto& maxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower; +// auto& maxHourlyPumpPower = area_1->hydro.series->maxHourlyPumpPower; +// maxHourlyGenPower.reset(3, HOURS_PER_YEAR); +// maxHourlyPumpPower.reset(2, HOURS_PER_YEAR); + +// InstantiateMatrix(maxHourlyGenPower, 400., HOURS_PER_YEAR); +// InstantiateMatrix(maxHourlyPumpPower, 200., HOURS_PER_YEAR); + +// stringT buffer; +// buffer.clear(); +// buffer = base_folder + SEP + series_folder + SEP + area_1->id + SEP + maxHourlyGenPower_file; +// maxHourlyGenPower.saveToCSVFile(buffer, 0); +// buffer.clear(); +// buffer = base_folder + SEP + series_folder + SEP + area_1->id + SEP + maxHourlyPumpPower_file; +// maxHourlyPumpPower.saveToCSVFile(buffer, 0); + +// maxHourlyGenPower.reset(3, HOURS_PER_YEAR); +// maxHourlyPumpPower.reset(2, HOURS_PER_YEAR); + +// buffer.clear(); +// buffer = base_folder + SEP + series_folder; +// ret = area_1->hydro.series->LoadMaxPower(area_1->id, buffer); +// area_1->hydro.series->setNbTimeSeriesSup(); +// BOOST_CHECK(ret); +// BOOST_CHECK_THROW(area_1->hydro.series->postProcessMaxPowerTS(*area_1), Error::ReadingStudy); +// } + +// BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_different_width_case_1, Fixture) +// { +// bool ret = true; +// auto& maxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower; +// auto& maxHourlyPumpPower = area_1->hydro.series->maxHourlyPumpPower; +// maxHourlyGenPower.reset(1, HOURS_PER_YEAR); +// maxHourlyPumpPower.reset(3, HOURS_PER_YEAR); + +// InstantiateMatrix(maxHourlyGenPower, 400., HOURS_PER_YEAR); +// InstantiateMatrix(maxHourlyPumpPower, 200., HOURS_PER_YEAR); + +// stringT buffer; +// buffer.clear(); +// buffer = base_folder + SEP + series_folder + SEP + area_1->id + SEP + maxHourlyGenPower_file; +// maxHourlyGenPower.saveToCSVFile(buffer, 0); +// buffer.clear(); +// buffer = base_folder + SEP + series_folder + SEP + area_1->id + SEP + maxHourlyPumpPower_file; +// maxHourlyPumpPower.saveToCSVFile(buffer, 0); + +// maxHourlyGenPower.reset(1, HOURS_PER_YEAR); +// maxHourlyPumpPower.reset(3, HOURS_PER_YEAR); + +// buffer.clear(); +// buffer = base_folder + SEP + series_folder; +// ret = area_1->hydro.series->LoadMaxPower(area_1->id, buffer); +// area_1->hydro.series->setNbTimeSeriesSup(); +// ret = area_1->hydro.series->postProcessMaxPowerTS(*area_1) && ret; +// BOOST_CHECK(ret); +// BOOST_CHECK_EQUAL(maxHourlyGenPower.width, maxHourlyPumpPower.width); +// } + +// BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_different_width_case_2, Fixture) +// { +// bool ret = true; +// auto& maxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower; +// auto& maxHourlyPumpPower = area_1->hydro.series->maxHourlyPumpPower; +// maxHourlyGenPower.reset(4, HOURS_PER_YEAR); +// maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); + +// InstantiateMatrix(maxHourlyGenPower, 400., HOURS_PER_YEAR); +// InstantiateMatrix(maxHourlyPumpPower, 200., HOURS_PER_YEAR); + +// stringT buffer; +// buffer.clear(); +// buffer = base_folder + SEP + series_folder + SEP + area_1->id + SEP + maxHourlyGenPower_file; +// maxHourlyGenPower.saveToCSVFile(buffer, 0); +// buffer.clear(); +// buffer = base_folder + SEP + series_folder + SEP + area_1->id + SEP + maxHourlyPumpPower_file; +// maxHourlyPumpPower.saveToCSVFile(buffer, 0); + +// maxHourlyGenPower.reset(4, HOURS_PER_YEAR); +// maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); + +// buffer.clear(); +// buffer = base_folder + SEP + series_folder; +// ret = area_1->hydro.series->LoadMaxPower(area_1->id, buffer); +// area_1->hydro.series->setNbTimeSeriesSup(); +// ret = area_1->hydro.series->postProcessMaxPowerTS(*area_1) && ret; +// BOOST_CHECK(ret); +// BOOST_CHECK_EQUAL(maxHourlyGenPower.width, maxHourlyPumpPower.width); +// } + +// BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_both_zeros, Fixture) +// { +// bool ret = true; +// auto& maxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower; +// auto& maxHourlyPumpPower = area_1->hydro.series->maxHourlyPumpPower; +// maxHourlyGenPower.reset(4, HOURS_PER_YEAR); +// maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); + +// InstantiateMatrix(maxHourlyGenPower, 400., HOURS_PER_YEAR); +// InstantiateMatrix(maxHourlyPumpPower, 200., HOURS_PER_YEAR); + +// stringT buffer; +// buffer.clear(); +// buffer = base_folder + SEP + series_folder + SEP + area_1->id + SEP + maxHourlyGenPower_file; +// maxHourlyGenPower.saveToCSVFile(buffer, 0); +// buffer.clear(); +// buffer = base_folder + SEP + series_folder + SEP + area_1->id + SEP + maxHourlyPumpPower_file; +// maxHourlyPumpPower.saveToCSVFile(buffer, 0); + +// maxHourlyGenPower.reset(4, HOURS_PER_YEAR); +// maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); + +// buffer.clear(); +// buffer = base_folder + SEP + series_folder; +// ret = area_1->hydro.series->LoadMaxPower(area_1->id, buffer); +// area_1->hydro.series->setNbTimeSeriesSup(); +// maxHourlyGenPower.width = 0; +// maxHourlyPumpPower.width = 0; +// ret = area_1->hydro.series->postProcessMaxPowerTS(*area_1) && ret; +// BOOST_CHECK(!ret); +// BOOST_CHECK_EQUAL(maxHourlyGenPower.width, maxHourlyPumpPower.width); +// } BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/src/tests/src/libs/antares/study/parts/hydro/test-hydroreader-class.cpp b/src/tests/src/libs/antares/study/parts/hydro/test-hydroreader-class.cpp index 3f780d4cf0..e254070eb4 100644 --- a/src/tests/src/libs/antares/study/parts/hydro/test-hydroreader-class.cpp +++ b/src/tests/src/libs/antares/study/parts/hydro/test-hydroreader-class.cpp @@ -5,6 +5,34 @@ #include #include "help-functions.h" #include +#define SEP "/" + +bool DailyMaxPowerAsHourlyTransferCheck(Matrix::ColumnType& hourlyColumn, + const Matrix::ColumnType& dailyColumn) +{ + uint hours = 0; + uint days = 0; + bool check = true; + + while (hours < HOURS_PER_YEAR && days < DAYS_PER_YEAR) + { + for (uint i = 0; i < 24; ++i) + { + if (hourlyColumn[hours] != dailyColumn[days]) + { + check = false; + break; + } + ++hours; + } + + if (!check) + break; + + ++days; + } + return check; +} struct Fixture { @@ -32,46 +60,54 @@ struct Fixture auto& hoursPump = reader->dailyMaxPumpAndGen[HydroMaxTimeSeriesReader::pumpMaxE]; InstantiateColumn(hoursPump, 14., DAYS_PER_YEAR); - my_string buffer; - my_string file_name = "maxpower_" + area_1->id + ".txt"; - buffer.clear() << base_folder << SEP << hydro_folder << SEP << common_folder << SEP - << capacity_folder << SEP << file_name; - reader->dailyMaxPumpAndGen.saveToCSVFile(buffer, 2); + stringT buffer; + stringT file_name = std::string("maxpower_Area1.txt"); + buffer.clear(); + buffer = base_folder + SEP + hydro_folder + SEP + common_folder + SEP + + capacity_folder + SEP + file_name; + Yuni::CString<256, false> temp(buffer); + reader->dailyMaxPumpAndGen.saveToCSVFile(temp, 2); } void createFoldersAndFiles() { - my_string buffer; + stringT buffer; + buffer.clear(); // hydro folder createFolder(base_folder, hydro_folder); // series folder - buffer.clear() << base_folder << SEP << hydro_folder; + buffer = base_folder + SEP + hydro_folder; createFolder(buffer, series_folder); // area1 folder - my_string area1_folder = area_1->id; - buffer.clear() << base_folder << SEP << hydro_folder << SEP << series_folder; + stringT area1_folder = "Area1"; + buffer.clear(); + buffer = base_folder + SEP + hydro_folder + SEP + series_folder; createFolder(buffer, area1_folder); - buffer.clear() << base_folder << SEP << hydro_folder << SEP << series_folder << SEP - << area1_folder; + buffer.clear(); + buffer = base_folder + SEP + hydro_folder + SEP + series_folder + SEP + + area1_folder; // maxHourlyGenPower and maxHourlyPumpPower files createFile(buffer, maxHourlyGenPower); createFile(buffer, maxHourlyPumpPower); // common and capacity folders - buffer.clear() << base_folder << SEP << hydro_folder; + buffer.clear(); + buffer = base_folder + SEP + hydro_folder; createFolder(buffer, common_folder); - buffer.clear() << base_folder << SEP << hydro_folder << SEP << common_folder; + buffer.clear(); + buffer = base_folder + SEP + hydro_folder + SEP + common_folder; createFolder(buffer, capacity_folder); // maxhours files - buffer.clear() << base_folder << SEP << hydro_folder << SEP << common_folder << SEP - << capacity_folder; - my_string file1_name = maxDailyGenEnergy_ << SEP << area_1->id << SEP << ".txt"; - my_string file2_name = maxDailyPumpEnergy_ << SEP << area_1->id << SEP << ".txt"; - my_string file3_name = maxpower << SEP << area_1->id << SEP << ".txt"; + buffer.clear(); + buffer = base_folder + SEP + hydro_folder + SEP + common_folder + SEP + + capacity_folder; + stringT file1_name = maxDailyGenEnergy_ + SEP + "Area1" + SEP + ".txt"; + stringT file2_name = maxDailyPumpEnergy_ + SEP + "Area1" + SEP + ".txt"; + stringT file3_name = maxpower + SEP + "Area1" + SEP + ".txt"; createFile(buffer, file1_name); createFile(buffer, file2_name); @@ -82,16 +118,16 @@ struct Fixture shared_ptr reader; Area* area_1; Area* area_2; - my_string base_folder = fs::current_path().string(); - my_string hydro_folder = "hydro"; - my_string series_folder = "series"; - my_string common_folder = "common"; - my_string capacity_folder = "capacity"; - my_string maxDailyGenEnergy_ = "maxDailyGenEnergy_"; - my_string maxDailyPumpEnergy_ = "maxDailyPumpEnergy_"; - my_string maxpower = "maxpower_"; - my_string maxHourlyGenPower = "maxHourlyGenPower.txt"; - my_string maxHourlyPumpPower = "maxHourlyPumpPower.txt"; + stringT base_folder = fs::current_path().string(); + stringT hydro_folder = "hydro"; + stringT series_folder = "series"; + stringT common_folder = "common"; + stringT capacity_folder = "capacity"; + stringT maxDailyGenEnergy_ = "maxDailyGenEnergy_"; + stringT maxDailyPumpEnergy_ = "maxDailyPumpEnergy_"; + stringT maxpower = "maxpower_"; + stringT maxHourlyGenPower = "maxHourlyGenPower.txt"; + stringT maxHourlyPumpPower = "maxHourlyPumpPower.txt"; ~Fixture() { @@ -103,14 +139,15 @@ BOOST_AUTO_TEST_SUITE(s) BOOST_FIXTURE_TEST_CASE(Testing_support_for_old_studies, Fixture) { - my_string buffer; + stringT buffer; bool ret = false; auto& colMaxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower[0]; auto& colMaxHourlyPumpPower = area_1->hydro.series->maxHourlyPumpPower[0]; auto& gen = reader->dailyMaxPumpAndGen[HydroMaxTimeSeriesReader::genMaxP]; auto& pump = reader->dailyMaxPumpAndGen[HydroMaxTimeSeriesReader::pumpMaxP]; - buffer.clear() << base_folder << SEP << hydro_folder; + buffer.clear(); + buffer = base_folder + SEP + hydro_folder; ret = (*reader)(buffer, *area_1); BOOST_CHECK(ret); BOOST_CHECK(DailyMaxPowerAsHourlyTransferCheck(colMaxHourlyGenPower, gen)); From fa060d6c74f6f6b3b8eb10514bd32287412b1e8e Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Fri, 13 Oct 2023 13:52:22 +0200 Subject: [PATCH 29/40] Refactoring unit tests --- .../antares/study/parts/hydro/CMakeLists.txt | 4 +- .../study/parts/hydro/help-functions.cpp | 9 +- .../study/parts/hydro/test-hydro-series.cpp | 329 ++++++++---------- .../parts/hydro/test-hydroreader-class.cpp | 29 +- 4 files changed, 173 insertions(+), 198 deletions(-) diff --git a/src/tests/src/libs/antares/study/parts/hydro/CMakeLists.txt b/src/tests/src/libs/antares/study/parts/hydro/CMakeLists.txt index 19fdde366b..bacda9ebe6 100644 --- a/src/tests/src/libs/antares/study/parts/hydro/CMakeLists.txt +++ b/src/tests/src/libs/antares/study/parts/hydro/CMakeLists.txt @@ -31,7 +31,7 @@ if(UNIX AND NOT APPLE) target_link_libraries(test-hydro-reader PRIVATE stdc++fs) endif() -set_target_properties(test-hydro-reader PROPERTIES FOLDER Unit-tests) +set_target_properties(test-hydro-reader PROPERTIES FOLDER Unit-tests/hydro) add_test(NAME test-hydro-reader COMMAND test-hydro-reader) set_property(TEST test-hydro-reader PROPERTY LABELS unit) @@ -71,6 +71,6 @@ if(UNIX AND NOT APPLE) target_link_libraries(test-hydro-series PRIVATE stdc++fs) endif() -set_target_properties(test-hydro-series PROPERTIES FOLDER Unit-tests) +set_target_properties(test-hydro-series PROPERTIES FOLDER Unit-tests/hydro) add_test(NAME test-hydro-series COMMAND test-hydro-series) set_property(TEST test-hydro-series PROPERTY LABELS unit) \ No newline at end of file diff --git a/src/tests/src/libs/antares/study/parts/hydro/help-functions.cpp b/src/tests/src/libs/antares/study/parts/hydro/help-functions.cpp index 231904c175..20e5204579 100644 --- a/src/tests/src/libs/antares/study/parts/hydro/help-functions.cpp +++ b/src/tests/src/libs/antares/study/parts/hydro/help-functions.cpp @@ -10,7 +10,7 @@ void createFolder(const stringT& path, const stringT& folder_name) } catch (const fs::filesystem_error& e) { - std::cerr << "Exception deleting folder '" + folder_name + "': " + e.what() + "\n"; + std::cerr << "Exception creating folder '" + folder_name + "': " + e.what() + "\n"; } } @@ -34,12 +34,13 @@ void createFile(const stringT& folder_path, const stringT& file_name) else { // Failed to create or open the file - throw std::runtime_error("Failed to create file\n"); + std::error_code ec = std::make_error_code(std::errc::io_error); + throw fs::filesystem_error("Failed to create the file.", ec); } } - catch(const std::exception& e) + catch (const fs::filesystem_error& e) { - std::cerr << "Error: " << e.what() << "\n"; + std::cerr << "Error creating file: " << file_name << "/" << e.what() << "\n"; } } diff --git a/src/tests/src/libs/antares/study/parts/hydro/test-hydro-series.cpp b/src/tests/src/libs/antares/study/parts/hydro/test-hydro-series.cpp index e6c8dae982..266a89bb26 100644 --- a/src/tests/src/libs/antares/study/parts/hydro/test-hydro-series.cpp +++ b/src/tests/src/libs/antares/study/parts/hydro/test-hydro-series.cpp @@ -26,6 +26,17 @@ struct Fixture // Instantiating neccessary studies parameters study->header.version = 870; study->parameters.derated = false; + + // Setting necessary paths + pathToMaxHourlyGenPower_file.clear(); + pathToMaxHourlyGenPower_file = base_folder + SEP + series_folder + SEP + area_1->id.c_str() + SEP + maxHourlyGenPower_file; + + pathToMaxHourlyPumpPower_file.clear(); + pathToMaxHourlyPumpPower_file = base_folder + SEP + series_folder + SEP + area_1->id.c_str() + SEP + maxHourlyPumpPower_file; + + pathToSeriesFolder.clear(); + pathToSeriesFolder = base_folder + SEP + series_folder; + } void createFoldersAndFiles() @@ -34,8 +45,8 @@ struct Fixture stringT buffer; createFolder(base_folder, series_folder); - // areas folder - stringT area1_folder = "Area1"; + // area folder + stringT area1_folder = area_1->id.c_str(); buffer.clear(); buffer = base_folder + SEP + series_folder; createFolder(buffer, area1_folder); @@ -49,10 +60,13 @@ struct Fixture shared_ptr study; Area* area_1; - stringT base_folder = fs::current_path().string(); + stringT base_folder = fs::temp_directory_path().string(); stringT series_folder = "series"; stringT maxHourlyGenPower_file = "maxHourlyGenPower.txt"; stringT maxHourlyPumpPower_file = "maxHourlyPumpPower.txt"; + stringT pathToMaxHourlyGenPower_file; + stringT pathToMaxHourlyPumpPower_file; + stringT pathToSeriesFolder; ~Fixture() { @@ -64,7 +78,8 @@ BOOST_AUTO_TEST_SUITE(s) BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_matrices_equal_width, Fixture) { - bool ret = false; + bool ret = true; + auto& maxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower; auto& maxHourlyPumpPower = area_1->hydro.series->maxHourlyPumpPower; maxHourlyGenPower.reset(3, HOURS_PER_YEAR); @@ -73,189 +88,153 @@ BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_matrices_equal_width, Fixture InstantiateMatrix(maxHourlyGenPower, 400., HOURS_PER_YEAR); InstantiateMatrix(maxHourlyPumpPower, 200., HOURS_PER_YEAR); - stringT buffer; + ret = maxHourlyGenPower.saveToCSVFile(pathToMaxHourlyGenPower_file, 0) && ret; + ret = maxHourlyPumpPower.saveToCSVFile(pathToMaxHourlyPumpPower_file, 0) && ret; + + maxHourlyGenPower.reset(3, HOURS_PER_YEAR); + maxHourlyPumpPower.reset(3, HOURS_PER_YEAR); - buffer.clear(); - buffer = base_folder + SEP + series_folder + SEP + "Area1" + SEP + maxHourlyGenPower_file; - Yuni::CString<256, false> temp1(buffer); - ret = maxHourlyGenPower.saveToCSVFile(temp1, 0) && ret; + ret = area_1->hydro.series->LoadMaxPower(area_1->id, pathToSeriesFolder) && ret; + area_1->hydro.series->setNbTimeSeriesSup(); + ret = area_1->hydro.series->postProcessMaxPowerTS(*area_1) && ret; - buffer.clear(); - buffer = base_folder + SEP + series_folder + SEP + "Area1" + SEP + maxHourlyPumpPower_file; + BOOST_CHECK(ret); + BOOST_CHECK_EQUAL(maxHourlyGenPower.width, 3); +} + +BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_both_matrix_equal_width_and_derated, Fixture) +{ + bool ret = true; + study->parameters.derated = true; + + auto& maxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower; + auto& maxHourlyPumpPower = area_1->hydro.series->maxHourlyPumpPower; + maxHourlyGenPower.reset(3, HOURS_PER_YEAR); + maxHourlyPumpPower.reset(3, HOURS_PER_YEAR); + + InstantiateMatrix(maxHourlyGenPower, 400., HOURS_PER_YEAR); + InstantiateMatrix(maxHourlyPumpPower, 200., HOURS_PER_YEAR); - Yuni::CString<256, false> temp2(buffer); - ret = maxHourlyPumpPower.saveToCSVFile(temp2, 0) && ret; + ret = maxHourlyGenPower.saveToCSVFile(pathToMaxHourlyGenPower_file, 0) && ret; + ret = maxHourlyPumpPower.saveToCSVFile(pathToMaxHourlyPumpPower_file, 0) && ret; maxHourlyGenPower.reset(3, HOURS_PER_YEAR); maxHourlyPumpPower.reset(3, HOURS_PER_YEAR); - buffer.clear(); - buffer = base_folder + SEP + series_folder; - Yuni::CString<256, false> temp3(buffer); - ret = area_1->hydro.series->LoadMaxPower(area_1->id, temp3) && ret; + ret = area_1->hydro.series->LoadMaxPower(area_1->id, pathToSeriesFolder) && ret; + ret = area_1->hydro.series->postProcessMaxPowerTS(*area_1) && ret; + area_1->hydro.series->setMaxPowerTSWhenDeratedMode(*study); + + BOOST_CHECK_EQUAL(maxHourlyGenPower.width, 1); + BOOST_CHECK_EQUAL(maxHourlyPumpPower.width, 1); + BOOST_CHECK(ret); +} + +BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_matrices_different_width_case_2, Fixture) +{ + bool ret = true; + + auto& maxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower; + auto& maxHourlyPumpPower = area_1->hydro.series->maxHourlyPumpPower; + maxHourlyGenPower.reset(3, HOURS_PER_YEAR); + maxHourlyPumpPower.reset(2, HOURS_PER_YEAR); + + InstantiateMatrix(maxHourlyGenPower, 400., HOURS_PER_YEAR); + InstantiateMatrix(maxHourlyPumpPower, 200., HOURS_PER_YEAR); + + ret = maxHourlyGenPower.saveToCSVFile(pathToMaxHourlyGenPower_file, 0) && ret; + ret = maxHourlyPumpPower.saveToCSVFile(pathToMaxHourlyPumpPower_file, 0) && ret; + + maxHourlyGenPower.reset(3, HOURS_PER_YEAR); + maxHourlyPumpPower.reset(2, HOURS_PER_YEAR); + + ret = area_1->hydro.series->LoadMaxPower(area_1->id, pathToSeriesFolder) && ret; + area_1->hydro.series->setNbTimeSeriesSup(); + + BOOST_CHECK(ret); + BOOST_CHECK_THROW(area_1->hydro.series->postProcessMaxPowerTS(*area_1), Error::ReadingStudy); +} + +BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_different_width_case_1, Fixture) +{ + bool ret = true; + + auto& maxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower; + auto& maxHourlyPumpPower = area_1->hydro.series->maxHourlyPumpPower; + maxHourlyGenPower.reset(1, HOURS_PER_YEAR); + maxHourlyPumpPower.reset(3, HOURS_PER_YEAR); + + InstantiateMatrix(maxHourlyGenPower, 400., HOURS_PER_YEAR); + InstantiateMatrix(maxHourlyPumpPower, 200., HOURS_PER_YEAR); + + ret = maxHourlyGenPower.saveToCSVFile(pathToMaxHourlyGenPower_file, 0) && ret; + ret = maxHourlyPumpPower.saveToCSVFile(pathToMaxHourlyPumpPower_file, 0) && ret; + + maxHourlyGenPower.reset(1, HOURS_PER_YEAR); + maxHourlyPumpPower.reset(3, HOURS_PER_YEAR); + + ret = area_1->hydro.series->LoadMaxPower(area_1->id, pathToSeriesFolder) && ret; area_1->hydro.series->setNbTimeSeriesSup(); ret = area_1->hydro.series->postProcessMaxPowerTS(*area_1) && ret; + + BOOST_CHECK(ret); - BOOST_CHECK_EQUAL(maxHourlyGenPower.width, 3); + BOOST_CHECK_EQUAL(maxHourlyGenPower.width, maxHourlyPumpPower.width); } -// BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_both_matrix_equal_width_and_derated, Fixture) -// { -// bool ret = true; -// study->parameters.derated = true; -// auto& maxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower; -// auto& maxHourlyPumpPower = area_1->hydro.series->maxHourlyPumpPower; -// maxHourlyGenPower.reset(3, HOURS_PER_YEAR); -// maxHourlyPumpPower.reset(3, HOURS_PER_YEAR); - -// InstantiateMatrix(maxHourlyGenPower, 400., HOURS_PER_YEAR); -// InstantiateMatrix(maxHourlyPumpPower, 200., HOURS_PER_YEAR); - -// stringT buffer; -// buffer.clear(); -// buffer = base_folder + SEP + series_folder + SEP + area_1->id + SEP + maxHourlyGenPower_file; -// maxHourlyGenPower.saveToCSVFile(buffer, 0); -// buffer.clear(); -// buffer = base_folder + SEP + series_folder + SEP + area_1->id + SEP + maxHourlyPumpPower_file; -// maxHourlyPumpPower.saveToCSVFile(buffer, 0); - -// maxHourlyGenPower.reset(3, HOURS_PER_YEAR); -// maxHourlyPumpPower.reset(3, HOURS_PER_YEAR); - -// buffer.clear(); -// buffer = base_folder + SEP + series_folder; -// ret = area_1->hydro.series->LoadMaxPower(area_1->id, buffer) && ret; -// ret = area_1->hydro.series->postProcessMaxPowerTS(*area_1) && ret; -// area_1->hydro.series->setMaxPowerTSWhenDeratedMode(*study); -// BOOST_CHECK_EQUAL(maxHourlyGenPower.width, 1); -// BOOST_CHECK_EQUAL(maxHourlyPumpPower.width, 1); -// BOOST_CHECK(ret); -// } - -// BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_matrices_different_width_case_2, Fixture) -// { -// bool ret = true; -// auto& maxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower; -// auto& maxHourlyPumpPower = area_1->hydro.series->maxHourlyPumpPower; -// maxHourlyGenPower.reset(3, HOURS_PER_YEAR); -// maxHourlyPumpPower.reset(2, HOURS_PER_YEAR); - -// InstantiateMatrix(maxHourlyGenPower, 400., HOURS_PER_YEAR); -// InstantiateMatrix(maxHourlyPumpPower, 200., HOURS_PER_YEAR); - -// stringT buffer; -// buffer.clear(); -// buffer = base_folder + SEP + series_folder + SEP + area_1->id + SEP + maxHourlyGenPower_file; -// maxHourlyGenPower.saveToCSVFile(buffer, 0); -// buffer.clear(); -// buffer = base_folder + SEP + series_folder + SEP + area_1->id + SEP + maxHourlyPumpPower_file; -// maxHourlyPumpPower.saveToCSVFile(buffer, 0); - -// maxHourlyGenPower.reset(3, HOURS_PER_YEAR); -// maxHourlyPumpPower.reset(2, HOURS_PER_YEAR); - -// buffer.clear(); -// buffer = base_folder + SEP + series_folder; -// ret = area_1->hydro.series->LoadMaxPower(area_1->id, buffer); -// area_1->hydro.series->setNbTimeSeriesSup(); -// BOOST_CHECK(ret); -// BOOST_CHECK_THROW(area_1->hydro.series->postProcessMaxPowerTS(*area_1), Error::ReadingStudy); -// } - -// BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_different_width_case_1, Fixture) -// { -// bool ret = true; -// auto& maxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower; -// auto& maxHourlyPumpPower = area_1->hydro.series->maxHourlyPumpPower; -// maxHourlyGenPower.reset(1, HOURS_PER_YEAR); -// maxHourlyPumpPower.reset(3, HOURS_PER_YEAR); - -// InstantiateMatrix(maxHourlyGenPower, 400., HOURS_PER_YEAR); -// InstantiateMatrix(maxHourlyPumpPower, 200., HOURS_PER_YEAR); - -// stringT buffer; -// buffer.clear(); -// buffer = base_folder + SEP + series_folder + SEP + area_1->id + SEP + maxHourlyGenPower_file; -// maxHourlyGenPower.saveToCSVFile(buffer, 0); -// buffer.clear(); -// buffer = base_folder + SEP + series_folder + SEP + area_1->id + SEP + maxHourlyPumpPower_file; -// maxHourlyPumpPower.saveToCSVFile(buffer, 0); - -// maxHourlyGenPower.reset(1, HOURS_PER_YEAR); -// maxHourlyPumpPower.reset(3, HOURS_PER_YEAR); - -// buffer.clear(); -// buffer = base_folder + SEP + series_folder; -// ret = area_1->hydro.series->LoadMaxPower(area_1->id, buffer); -// area_1->hydro.series->setNbTimeSeriesSup(); -// ret = area_1->hydro.series->postProcessMaxPowerTS(*area_1) && ret; -// BOOST_CHECK(ret); -// BOOST_CHECK_EQUAL(maxHourlyGenPower.width, maxHourlyPumpPower.width); -// } - -// BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_different_width_case_2, Fixture) -// { -// bool ret = true; -// auto& maxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower; -// auto& maxHourlyPumpPower = area_1->hydro.series->maxHourlyPumpPower; -// maxHourlyGenPower.reset(4, HOURS_PER_YEAR); -// maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); - -// InstantiateMatrix(maxHourlyGenPower, 400., HOURS_PER_YEAR); -// InstantiateMatrix(maxHourlyPumpPower, 200., HOURS_PER_YEAR); - -// stringT buffer; -// buffer.clear(); -// buffer = base_folder + SEP + series_folder + SEP + area_1->id + SEP + maxHourlyGenPower_file; -// maxHourlyGenPower.saveToCSVFile(buffer, 0); -// buffer.clear(); -// buffer = base_folder + SEP + series_folder + SEP + area_1->id + SEP + maxHourlyPumpPower_file; -// maxHourlyPumpPower.saveToCSVFile(buffer, 0); - -// maxHourlyGenPower.reset(4, HOURS_PER_YEAR); -// maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); - -// buffer.clear(); -// buffer = base_folder + SEP + series_folder; -// ret = area_1->hydro.series->LoadMaxPower(area_1->id, buffer); -// area_1->hydro.series->setNbTimeSeriesSup(); -// ret = area_1->hydro.series->postProcessMaxPowerTS(*area_1) && ret; -// BOOST_CHECK(ret); -// BOOST_CHECK_EQUAL(maxHourlyGenPower.width, maxHourlyPumpPower.width); -// } - -// BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_both_zeros, Fixture) -// { -// bool ret = true; -// auto& maxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower; -// auto& maxHourlyPumpPower = area_1->hydro.series->maxHourlyPumpPower; -// maxHourlyGenPower.reset(4, HOURS_PER_YEAR); -// maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); - -// InstantiateMatrix(maxHourlyGenPower, 400., HOURS_PER_YEAR); -// InstantiateMatrix(maxHourlyPumpPower, 200., HOURS_PER_YEAR); - -// stringT buffer; -// buffer.clear(); -// buffer = base_folder + SEP + series_folder + SEP + area_1->id + SEP + maxHourlyGenPower_file; -// maxHourlyGenPower.saveToCSVFile(buffer, 0); -// buffer.clear(); -// buffer = base_folder + SEP + series_folder + SEP + area_1->id + SEP + maxHourlyPumpPower_file; -// maxHourlyPumpPower.saveToCSVFile(buffer, 0); - -// maxHourlyGenPower.reset(4, HOURS_PER_YEAR); -// maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); - -// buffer.clear(); -// buffer = base_folder + SEP + series_folder; -// ret = area_1->hydro.series->LoadMaxPower(area_1->id, buffer); -// area_1->hydro.series->setNbTimeSeriesSup(); -// maxHourlyGenPower.width = 0; -// maxHourlyPumpPower.width = 0; -// ret = area_1->hydro.series->postProcessMaxPowerTS(*area_1) && ret; -// BOOST_CHECK(!ret); -// BOOST_CHECK_EQUAL(maxHourlyGenPower.width, maxHourlyPumpPower.width); -// } +BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_different_width_case_2, Fixture) +{ + bool ret = true; + + auto& maxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower; + auto& maxHourlyPumpPower = area_1->hydro.series->maxHourlyPumpPower; + maxHourlyGenPower.reset(4, HOURS_PER_YEAR); + maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); + + InstantiateMatrix(maxHourlyGenPower, 400., HOURS_PER_YEAR); + InstantiateMatrix(maxHourlyPumpPower, 200., HOURS_PER_YEAR); + + ret = maxHourlyGenPower.saveToCSVFile(pathToMaxHourlyGenPower_file, 0) && ret; + ret = maxHourlyPumpPower.saveToCSVFile(pathToMaxHourlyPumpPower_file, 0) && ret; + + maxHourlyGenPower.reset(4, HOURS_PER_YEAR); + maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); + + ret = area_1->hydro.series->LoadMaxPower(area_1->id, pathToSeriesFolder) && ret; + area_1->hydro.series->setNbTimeSeriesSup(); + ret = area_1->hydro.series->postProcessMaxPowerTS(*area_1) && ret; + + BOOST_CHECK(ret); + BOOST_CHECK_EQUAL(maxHourlyGenPower.width, maxHourlyPumpPower.width); +} + +BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_both_zeros, Fixture) +{ + bool ret = true; + + auto& maxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower; + auto& maxHourlyPumpPower = area_1->hydro.series->maxHourlyPumpPower; + maxHourlyGenPower.reset(4, HOURS_PER_YEAR); + maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); + + InstantiateMatrix(maxHourlyGenPower, 400., HOURS_PER_YEAR); + InstantiateMatrix(maxHourlyPumpPower, 200., HOURS_PER_YEAR); + + ret = maxHourlyGenPower.saveToCSVFile(pathToMaxHourlyGenPower_file, 0) && ret; + ret = maxHourlyPumpPower.saveToCSVFile(pathToMaxHourlyPumpPower_file, 0) && ret; + + maxHourlyGenPower.reset(4, HOURS_PER_YEAR); + maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); + + ret = area_1->hydro.series->LoadMaxPower(area_1->id, pathToSeriesFolder) && ret; + area_1->hydro.series->setNbTimeSeriesSup(); + maxHourlyGenPower.width = 0; + maxHourlyPumpPower.width = 0; + ret = area_1->hydro.series->postProcessMaxPowerTS(*area_1) && ret; + + BOOST_CHECK(!ret); + BOOST_CHECK_EQUAL(maxHourlyGenPower.width, maxHourlyPumpPower.width); +} BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/src/tests/src/libs/antares/study/parts/hydro/test-hydroreader-class.cpp b/src/tests/src/libs/antares/study/parts/hydro/test-hydroreader-class.cpp index e254070eb4..6d98f693ce 100644 --- a/src/tests/src/libs/antares/study/parts/hydro/test-hydroreader-class.cpp +++ b/src/tests/src/libs/antares/study/parts/hydro/test-hydroreader-class.cpp @@ -42,7 +42,6 @@ struct Fixture reader = make_shared(); // Add areas area_1 = study->areaAdd("Area1"); - area_2 = study->areaAdd("Area2"); study->areas.rebuildIndexes(); // Create necessary folders and files for these two areas @@ -61,10 +60,9 @@ struct Fixture InstantiateColumn(hoursPump, 14., DAYS_PER_YEAR); stringT buffer; - stringT file_name = std::string("maxpower_Area1.txt"); buffer.clear(); buffer = base_folder + SEP + hydro_folder + SEP + common_folder + SEP - + capacity_folder + SEP + file_name; + + capacity_folder + SEP + maxpower + area_1->id.c_str() + ".txt"; Yuni::CString<256, false> temp(buffer); reader->dailyMaxPumpAndGen.saveToCSVFile(temp, 2); } @@ -82,7 +80,7 @@ struct Fixture createFolder(buffer, series_folder); // area1 folder - stringT area1_folder = "Area1"; + stringT area1_folder = area_1->id.c_str(); buffer.clear(); buffer = base_folder + SEP + hydro_folder + SEP + series_folder; createFolder(buffer, area1_folder); @@ -102,16 +100,13 @@ struct Fixture createFolder(buffer, capacity_folder); // maxhours files + stringT maxpowerArea1 = maxpower + area1_folder + ".txt"; buffer.clear(); - buffer = base_folder + SEP + hydro_folder + SEP + common_folder + SEP - + capacity_folder; - stringT file1_name = maxDailyGenEnergy_ + SEP + "Area1" + SEP + ".txt"; - stringT file2_name = maxDailyPumpEnergy_ + SEP + "Area1" + SEP + ".txt"; - stringT file3_name = maxpower + SEP + "Area1" + SEP + ".txt"; - - createFile(buffer, file1_name); - createFile(buffer, file2_name); - createFile(buffer, file3_name); + buffer = base_folder + SEP + hydro_folder + SEP + common_folder + SEP + capacity_folder; + + createFile(buffer, maxDailyGenEnergy_); + createFile(buffer, maxDailyPumpEnergy_); + createFile(buffer, maxpowerArea1); } shared_ptr study; @@ -123,8 +118,8 @@ struct Fixture stringT series_folder = "series"; stringT common_folder = "common"; stringT capacity_folder = "capacity"; - stringT maxDailyGenEnergy_ = "maxDailyGenEnergy_"; - stringT maxDailyPumpEnergy_ = "maxDailyPumpEnergy_"; + stringT maxDailyGenEnergy_ = "maxDailyGenEnergy_area1.txt"; + stringT maxDailyPumpEnergy_ = "maxDailyPumpEnergy_area1.txt"; stringT maxpower = "maxpower_"; stringT maxHourlyGenPower = "maxHourlyGenPower.txt"; stringT maxHourlyPumpPower = "maxHourlyPumpPower.txt"; @@ -140,7 +135,7 @@ BOOST_AUTO_TEST_SUITE(s) BOOST_FIXTURE_TEST_CASE(Testing_support_for_old_studies, Fixture) { stringT buffer; - bool ret = false; + bool ret = true; auto& colMaxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower[0]; auto& colMaxHourlyPumpPower = area_1->hydro.series->maxHourlyPumpPower[0]; auto& gen = reader->dailyMaxPumpAndGen[HydroMaxTimeSeriesReader::genMaxP]; @@ -148,7 +143,7 @@ BOOST_FIXTURE_TEST_CASE(Testing_support_for_old_studies, Fixture) buffer.clear(); buffer = base_folder + SEP + hydro_folder; - ret = (*reader)(buffer, *area_1); + ret = (*reader)(buffer, *area_1) && ret; BOOST_CHECK(ret); BOOST_CHECK(DailyMaxPowerAsHourlyTransferCheck(colMaxHourlyGenPower, gen)); BOOST_CHECK(DailyMaxPowerAsHourlyTransferCheck(colMaxHourlyPumpPower, pump)); From bd0280e88b93a25d243968973c8ebf116c9e49f0 Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Fri, 13 Oct 2023 15:13:24 +0200 Subject: [PATCH 30/40] Unit tests --- .../antares/study/parts/hydro/CMakeLists.txt | 42 ++++----- .../study/parts/hydro/help-functions.cpp | 93 ------------------- .../study/parts/hydro/help-functions.h | 17 ---- .../study/parts/hydro/test-hydro-series.cpp | 52 +++++++---- .../parts/hydro/test-hydroreader-class.cpp | 36 ++++--- src/tests/src/utils/utils.cpp | 62 +++++++++++++ src/tests/src/utils/utils.h | 9 ++ 7 files changed, 142 insertions(+), 169 deletions(-) delete mode 100644 src/tests/src/libs/antares/study/parts/hydro/help-functions.cpp delete mode 100644 src/tests/src/libs/antares/study/parts/hydro/help-functions.h diff --git a/src/tests/src/libs/antares/study/parts/hydro/CMakeLists.txt b/src/tests/src/libs/antares/study/parts/hydro/CMakeLists.txt index bacda9ebe6..3f8db81a57 100644 --- a/src/tests/src/libs/antares/study/parts/hydro/CMakeLists.txt +++ b/src/tests/src/libs/antares/study/parts/hydro/CMakeLists.txt @@ -1,29 +1,27 @@ # Useful variables definitions set(src_libs_antares_study "${CMAKE_SOURCE_DIR}/libs/antares/study") set(src_libs_antares "${CMAKE_SOURCE_DIR}/libs/antares") +set(src_test_utilis "${CMAKE_SOURCE_DIR}/tests/src/utlis") -# Hydro data transfer + +# Hydro data reader set(SRC_HYDRO_READER - test-hydroreader-class.cpp - help-functions.h - help-functions.cpp) + test-hydroreader-class.cpp) add_executable(test-hydro-reader ${SRC_HYDRO_READER}) target_include_directories(test-hydro-reader PRIVATE "${src_libs_antares_study}" - "${src_libs_antares_study}/parts/hydro" "${src_libs_antares}/array/antares/array" + "${src_test_utilis}" ) target_link_libraries(test-hydro-reader PRIVATE Boost::unit_test_framework - antares-core - model_antares - antares-solver-hydro - yuni-static-core + Antares::study + test_utils_unit ) # Linux @@ -32,38 +30,30 @@ if(UNIX AND NOT APPLE) endif() set_target_properties(test-hydro-reader PROPERTIES FOLDER Unit-tests/hydro) -add_test(NAME test-hydro-reader COMMAND test-hydro-reader) -set_property(TEST test-hydro-reader PROPERTY LABELS unit) +add_test(NAME hydro-reader COMMAND test-hydro-reader) +set_property(TEST hydro-reader PROPERTY LABELS unit) -# Useful variables definitions -set(src_libs_antares_study "${CMAKE_SOURCE_DIR}/libs/antares/study") -set(src_libs_antares "${CMAKE_SOURCE_DIR}/libs/antares") # Hydro series set(SRC_HYDRO_SERIES - test-hydro-series.cpp - help-functions.h - help-functions.cpp) + test-hydro-series.cpp) add_executable(test-hydro-series ${SRC_HYDRO_SERIES}) target_include_directories(test-hydro-series PRIVATE "${src_libs_antares_study}" - "${src_libs_antares_study}/parts/hydro" - "${src_libs_antares}/array/antares/array" "${src_libs_antares}/array/antares/array" "${src_libs_antares}/exception/antares/exception" + "${src_test_utilis}" ) target_link_libraries(test-hydro-series PRIVATE Boost::unit_test_framework - antares-core - model_antares - antares-solver-hydro - yuni-static-core - exception + Antares::study + Antares::exception + test_utils_unit ) # Linux @@ -72,5 +62,5 @@ if(UNIX AND NOT APPLE) endif() set_target_properties(test-hydro-series PROPERTIES FOLDER Unit-tests/hydro) -add_test(NAME test-hydro-series COMMAND test-hydro-series) -set_property(TEST test-hydro-series PROPERTY LABELS unit) \ No newline at end of file +add_test(NAME hydro-series COMMAND test-hydro-series) +set_property(TEST hydro-series PROPERTY LABELS unit) \ No newline at end of file diff --git a/src/tests/src/libs/antares/study/parts/hydro/help-functions.cpp b/src/tests/src/libs/antares/study/parts/hydro/help-functions.cpp deleted file mode 100644 index 20e5204579..0000000000 --- a/src/tests/src/libs/antares/study/parts/hydro/help-functions.cpp +++ /dev/null @@ -1,93 +0,0 @@ -#include "help-functions.h" - -void createFolder(const stringT& path, const stringT& folder_name) -{ - fs::path folder_path = fs::path(path.c_str()) / folder_name.c_str(); - - try - { - fs::create_directory(folder_path); - } - catch (const fs::filesystem_error& e) - { - std::cerr << "Exception creating folder '" + folder_name + "': " + e.what() + "\n"; - } -} - -void createFile(const stringT& folder_path, const stringT& file_name) -{ - // Construct the full path to the file - fs::path path = fs::path(folder_path.c_str()) / file_name.c_str(); - - // Create an output file stream - std::ofstream outputFile(path); - - try - { - if (outputFile.is_open()) - { - // File was successfully created and is open - outputFile << "This is a sample content." << std::endl; - outputFile.close(); - std::cout << "File " + file_name + " is created in " + folder_path + "\n"; - } - else - { - // Failed to create or open the file - std::error_code ec = std::make_error_code(std::errc::io_error); - throw fs::filesystem_error("Failed to create the file.", ec); - } - } - catch (const fs::filesystem_error& e) - { - std::cerr << "Error creating file: " << file_name << "/" << e.what() << "\n"; - } -} - -void InstantiateMatrix(Matrix& matrix, double seed, uint type) -{ - for (uint i = 0; i < matrix.width; i++) - { - for (uint hours = 0; hours < type; hours++) - { - if (hours != 0 && hours != type - 1) - matrix[i][hours] = seed; - else if (hours == 0) - matrix[i][hours] = seed + 1; - else if (hours == type - 1) - matrix[i][hours] = seed + 2; - } - } -} - -void InstantiateColumn(Matrix::ColumnType& col, double seed, uint type) -{ - for (uint days = 0; days < type; days++) - { - if (days != 0 && days != type - 1) - col[days] = seed; - else if (days == 0) - col[days] = seed + 1; - else if (days == type - 1) - col[days] = seed + 2; - } -} - -void removeFolder(stringT& path, stringT& folder_name) -{ - fs::path folder_path = fs::path(path.c_str()) / folder_name.c_str(); - if (fs::exists(folder_path)) - { - try - { - fs::remove_all(folder_path); - std::cout << "Folder '" + folder_name + "' at '" + folder_path.string() - + "' deleted.\n"; - } - catch (const fs::filesystem_error& e) - { - std::cerr << "Exception deleting folder '" + folder_name + "': " + e.what() - + "\n"; - } - } -} \ No newline at end of file diff --git a/src/tests/src/libs/antares/study/parts/hydro/help-functions.h b/src/tests/src/libs/antares/study/parts/hydro/help-functions.h deleted file mode 100644 index 5bf9b1e5dc..0000000000 --- a/src/tests/src/libs/antares/study/parts/hydro/help-functions.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -using namespace Antares::Data; -using stringT = std::string; -using namespace std; -namespace fs = std::filesystem; - -void createFolder(const stringT& path, const stringT& folder_name); -void createFile(const stringT& folder_path, const stringT& file_name); -void InstantiateMatrix(Matrix& matrix, double seed, uint type); -void InstantiateColumn(Matrix::ColumnType& col, double seed, uint type); -void removeFolder(stringT& path, stringT& folder_name); \ No newline at end of file diff --git a/src/tests/src/libs/antares/study/parts/hydro/test-hydro-series.cpp b/src/tests/src/libs/antares/study/parts/hydro/test-hydro-series.cpp index 266a89bb26..89a65be523 100644 --- a/src/tests/src/libs/antares/study/parts/hydro/test-hydro-series.cpp +++ b/src/tests/src/libs/antares/study/parts/hydro/test-hydro-series.cpp @@ -3,18 +3,31 @@ #define WIN32_LEAN_AND_MEAN #include -#include "help-functions.h" #include #include +#include +#include #define SEP "/" +using namespace Antares::Data; +namespace fs = std::filesystem; + +void fillTimeSeriesWithSpecialEnds(Matrix& timeSeries, double value) +{ + for (uint ts = 0; ts < timeSeries.width; ts++) + { + timeSeries[ts][0] = value + 1; + timeSeries[ts][timeSeries.height - 1] = value + 2; + } +} + struct Fixture { Fixture() { // Create studies - study = make_shared(true); + study = std::make_shared(true); // Add areas to studies area_1 = study->areaAdd("Area1"); @@ -29,14 +42,15 @@ struct Fixture // Setting necessary paths pathToMaxHourlyGenPower_file.clear(); - pathToMaxHourlyGenPower_file = base_folder + SEP + series_folder + SEP + area_1->id.c_str() + SEP + maxHourlyGenPower_file; + pathToMaxHourlyGenPower_file = base_folder + SEP + series_folder + SEP + area_1->id.c_str() + + SEP + maxHourlyGenPower_file; pathToMaxHourlyPumpPower_file.clear(); - pathToMaxHourlyPumpPower_file = base_folder + SEP + series_folder + SEP + area_1->id.c_str() + SEP + maxHourlyPumpPower_file; + pathToMaxHourlyPumpPower_file = base_folder + SEP + series_folder + SEP + area_1->id.c_str() + + SEP + maxHourlyPumpPower_file; pathToSeriesFolder.clear(); pathToSeriesFolder = base_folder + SEP + series_folder; - } void createFoldersAndFiles() @@ -58,7 +72,7 @@ struct Fixture createFile(buffer, maxHourlyPumpPower_file); } - shared_ptr study; + std::shared_ptr study; Area* area_1; stringT base_folder = fs::temp_directory_path().string(); stringT series_folder = "series"; @@ -85,8 +99,8 @@ BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_matrices_equal_width, Fixture maxHourlyGenPower.reset(3, HOURS_PER_YEAR); maxHourlyPumpPower.reset(3, HOURS_PER_YEAR); - InstantiateMatrix(maxHourlyGenPower, 400., HOURS_PER_YEAR); - InstantiateMatrix(maxHourlyPumpPower, 200., HOURS_PER_YEAR); + fillTimeSeriesWithSpecialEnds(maxHourlyGenPower, 400.); + fillTimeSeriesWithSpecialEnds(maxHourlyPumpPower, 200.); ret = maxHourlyGenPower.saveToCSVFile(pathToMaxHourlyGenPower_file, 0) && ret; ret = maxHourlyPumpPower.saveToCSVFile(pathToMaxHourlyPumpPower_file, 0) && ret; @@ -112,8 +126,8 @@ BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_both_matrix_equal_width_and_d maxHourlyGenPower.reset(3, HOURS_PER_YEAR); maxHourlyPumpPower.reset(3, HOURS_PER_YEAR); - InstantiateMatrix(maxHourlyGenPower, 400., HOURS_PER_YEAR); - InstantiateMatrix(maxHourlyPumpPower, 200., HOURS_PER_YEAR); + fillTimeSeriesWithSpecialEnds(maxHourlyGenPower, 400.); + fillTimeSeriesWithSpecialEnds(maxHourlyPumpPower, 200.); ret = maxHourlyGenPower.saveToCSVFile(pathToMaxHourlyGenPower_file, 0) && ret; ret = maxHourlyPumpPower.saveToCSVFile(pathToMaxHourlyPumpPower_file, 0) && ret; @@ -139,8 +153,8 @@ BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_matrices_different_width_case maxHourlyGenPower.reset(3, HOURS_PER_YEAR); maxHourlyPumpPower.reset(2, HOURS_PER_YEAR); - InstantiateMatrix(maxHourlyGenPower, 400., HOURS_PER_YEAR); - InstantiateMatrix(maxHourlyPumpPower, 200., HOURS_PER_YEAR); + fillTimeSeriesWithSpecialEnds(maxHourlyGenPower, 400.); + fillTimeSeriesWithSpecialEnds(maxHourlyPumpPower, 200.); ret = maxHourlyGenPower.saveToCSVFile(pathToMaxHourlyGenPower_file, 0) && ret; ret = maxHourlyPumpPower.saveToCSVFile(pathToMaxHourlyPumpPower_file, 0) && ret; @@ -164,8 +178,8 @@ BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_different_width_case_1, Fixtu maxHourlyGenPower.reset(1, HOURS_PER_YEAR); maxHourlyPumpPower.reset(3, HOURS_PER_YEAR); - InstantiateMatrix(maxHourlyGenPower, 400., HOURS_PER_YEAR); - InstantiateMatrix(maxHourlyPumpPower, 200., HOURS_PER_YEAR); + fillTimeSeriesWithSpecialEnds(maxHourlyGenPower, 400.); + fillTimeSeriesWithSpecialEnds(maxHourlyPumpPower, 200.); ret = maxHourlyGenPower.saveToCSVFile(pathToMaxHourlyGenPower_file, 0) && ret; ret = maxHourlyPumpPower.saveToCSVFile(pathToMaxHourlyPumpPower_file, 0) && ret; @@ -177,7 +191,6 @@ BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_different_width_case_1, Fixtu area_1->hydro.series->setNbTimeSeriesSup(); ret = area_1->hydro.series->postProcessMaxPowerTS(*area_1) && ret; - BOOST_CHECK(ret); BOOST_CHECK_EQUAL(maxHourlyGenPower.width, maxHourlyPumpPower.width); } @@ -191,8 +204,8 @@ BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_different_width_case_2, Fixtu maxHourlyGenPower.reset(4, HOURS_PER_YEAR); maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); - InstantiateMatrix(maxHourlyGenPower, 400., HOURS_PER_YEAR); - InstantiateMatrix(maxHourlyPumpPower, 200., HOURS_PER_YEAR); + fillTimeSeriesWithSpecialEnds(maxHourlyGenPower, 400.); + fillTimeSeriesWithSpecialEnds(maxHourlyPumpPower, 200.); ret = maxHourlyGenPower.saveToCSVFile(pathToMaxHourlyGenPower_file, 0) && ret; ret = maxHourlyPumpPower.saveToCSVFile(pathToMaxHourlyPumpPower_file, 0) && ret; @@ -217,8 +230,8 @@ BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_both_zeros, Fixture) maxHourlyGenPower.reset(4, HOURS_PER_YEAR); maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); - InstantiateMatrix(maxHourlyGenPower, 400., HOURS_PER_YEAR); - InstantiateMatrix(maxHourlyPumpPower, 200., HOURS_PER_YEAR); + fillTimeSeriesWithSpecialEnds(maxHourlyGenPower, 400.); + fillTimeSeriesWithSpecialEnds(maxHourlyPumpPower, 200.); ret = maxHourlyGenPower.saveToCSVFile(pathToMaxHourlyGenPower_file, 0) && ret; ret = maxHourlyPumpPower.saveToCSVFile(pathToMaxHourlyPumpPower_file, 0) && ret; @@ -236,5 +249,4 @@ BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_both_zeros, Fixture) BOOST_CHECK_EQUAL(maxHourlyGenPower.width, maxHourlyPumpPower.width); } - BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/src/tests/src/libs/antares/study/parts/hydro/test-hydroreader-class.cpp b/src/tests/src/libs/antares/study/parts/hydro/test-hydroreader-class.cpp index 6d98f693ce..851f2765fc 100644 --- a/src/tests/src/libs/antares/study/parts/hydro/test-hydroreader-class.cpp +++ b/src/tests/src/libs/antares/study/parts/hydro/test-hydroreader-class.cpp @@ -3,10 +3,15 @@ #define WIN32_LEAN_AND_MEAN #include -#include "help-functions.h" #include +#include +#include + #define SEP "/" +using namespace Antares::Data; +namespace fs = std::filesystem; + bool DailyMaxPowerAsHourlyTransferCheck(Matrix::ColumnType& hourlyColumn, const Matrix::ColumnType& dailyColumn) { @@ -34,12 +39,18 @@ bool DailyMaxPowerAsHourlyTransferCheck(Matrix::ColumnType& hou return check; } +void fillColumnWithSpecialEnds(Matrix::ColumnType& col, double value, uint heigth) +{ + col[0] = value + 1; + col[heigth - 1] = value + 2; +} + struct Fixture { Fixture() { - study = make_shared(true); - reader = make_shared(); + study = std::make_shared(true); + reader = std::make_shared(); // Add areas area_1 = study->areaAdd("Area1"); study->areas.rebuildIndexes(); @@ -48,21 +59,21 @@ struct Fixture createFoldersAndFiles(); auto& gen = reader->dailyMaxPumpAndGen[HydroMaxTimeSeriesReader::genMaxP]; - InstantiateColumn(gen, 300., DAYS_PER_YEAR); + fillColumnWithSpecialEnds(gen, 300., DAYS_PER_YEAR); auto& pump = reader->dailyMaxPumpAndGen[HydroMaxTimeSeriesReader::pumpMaxP]; - InstantiateColumn(pump, 200., DAYS_PER_YEAR); + fillColumnWithSpecialEnds(pump, 200., DAYS_PER_YEAR); auto& hoursGen = reader->dailyMaxPumpAndGen[HydroMaxTimeSeriesReader::genMaxE]; - InstantiateColumn(hoursGen, 20., DAYS_PER_YEAR); + fillColumnWithSpecialEnds(hoursGen, 20., DAYS_PER_YEAR); auto& hoursPump = reader->dailyMaxPumpAndGen[HydroMaxTimeSeriesReader::pumpMaxE]; - InstantiateColumn(hoursPump, 14., DAYS_PER_YEAR); + fillColumnWithSpecialEnds(hoursPump, 14., DAYS_PER_YEAR); stringT buffer; buffer.clear(); - buffer = base_folder + SEP + hydro_folder + SEP + common_folder + SEP - + capacity_folder + SEP + maxpower + area_1->id.c_str() + ".txt"; + buffer = base_folder + SEP + hydro_folder + SEP + common_folder + SEP + capacity_folder + + SEP + maxpower + area_1->id.c_str() + ".txt"; Yuni::CString<256, false> temp(buffer); reader->dailyMaxPumpAndGen.saveToCSVFile(temp, 2); } @@ -85,8 +96,7 @@ struct Fixture buffer = base_folder + SEP + hydro_folder + SEP + series_folder; createFolder(buffer, area1_folder); buffer.clear(); - buffer = base_folder + SEP + hydro_folder + SEP + series_folder + SEP - + area1_folder; + buffer = base_folder + SEP + hydro_folder + SEP + series_folder + SEP + area1_folder; // maxHourlyGenPower and maxHourlyPumpPower files createFile(buffer, maxHourlyGenPower); createFile(buffer, maxHourlyPumpPower); @@ -109,8 +119,8 @@ struct Fixture createFile(buffer, maxpowerArea1); } - shared_ptr study; - shared_ptr reader; + std::shared_ptr study; + std::shared_ptr reader; Area* area_1; Area* area_2; stringT base_folder = fs::current_path().string(); diff --git a/src/tests/src/utils/utils.cpp b/src/tests/src/utils/utils.cpp index 4fd0fe735e..9e2d5d1852 100644 --- a/src/tests/src/utils/utils.cpp +++ b/src/tests/src/utils/utils.cpp @@ -9,3 +9,65 @@ fs::path generateAndCreateDirName(const std::string& dirName) fs::create_directories(working_dir); return working_dir; } + +void createFolder(const stringT& path, const stringT& folder_name) +{ + fs::path folder_path = fs::path(path.c_str()) / folder_name.c_str(); + + try + { + fs::create_directory(folder_path); + } + catch (const fs::filesystem_error& e) + { + std::cerr << "Exception creating folder '" + folder_name + "': " + e.what() + "\n"; + } +} + +void createFile(const stringT& folder_path, const stringT& file_name) +{ + // Construct the full path to the file + fs::path path = fs::path(folder_path.c_str()) / file_name.c_str(); + + // Create an output file stream + std::ofstream outputFile(path); + + try + { + if (outputFile.is_open()) + { + // File was successfully created and is open + outputFile << "This is a sample content." << std::endl; + outputFile.close(); + std::cout << "File " + file_name + " is created in " + folder_path + "\n"; + } + else + { + // Failed to create or open the file + std::error_code ec = std::make_error_code(std::errc::io_error); + throw fs::filesystem_error("Failed to create the file.", ec); + } + } + catch (const fs::filesystem_error& e) + { + std::cerr << "Error creating file: " << file_name << "/" << e.what() << "\n"; + } +} + +void removeFolder(stringT& path, stringT& folder_name) +{ + fs::path folder_path = fs::path(path.c_str()) / folder_name.c_str(); + if (fs::exists(folder_path)) + { + try + { + fs::remove_all(folder_path); + std::cout << "Folder '" + folder_name + "' at '" + folder_path.string() + + "' deleted.\n"; + } + catch (const fs::filesystem_error& e) + { + std::cerr << "Exception deleting folder '" + folder_name + "': " + e.what() + "\n"; + } + } +} \ No newline at end of file diff --git a/src/tests/src/utils/utils.h b/src/tests/src/utils/utils.h index 9c7e70367f..ccc5289c62 100644 --- a/src/tests/src/utils/utils.h +++ b/src/tests/src/utils/utils.h @@ -1,8 +1,17 @@ #pragma once #include +#include +#include +#include + +using stringT = std::string; // The following macro is used due to linking issues with #define CREATE_TMP_DIR_BASED_ON_TEST_NAME() generateAndCreateDirName(boost::unit_test::framework::current_test_case().p_name); std::filesystem::path generateAndCreateDirName(const std::string&); + +void createFolder(const stringT& path, const stringT& folder_name); +void createFile(const stringT& folder_path, const stringT& file_name); +void removeFolder(stringT& path, stringT& folder_name); From fbf2e96d7a1406e059ccef0e973e0b63346bf18c Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Fri, 13 Oct 2023 16:01:52 +0200 Subject: [PATCH 31/40] Typo and renaming --- src/libs/antares/study/parts/hydro/series.cpp | 34 +++++++++---------- src/libs/antares/study/parts/hydro/series.h | 10 +++--- .../antares/study/parts/hydro/CMakeLists.txt | 6 ++-- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/libs/antares/study/parts/hydro/series.cpp b/src/libs/antares/study/parts/hydro/series.cpp index 8b32997160..f7caacc076 100644 --- a/src/libs/antares/study/parts/hydro/series.cpp +++ b/src/libs/antares/study/parts/hydro/series.cpp @@ -227,7 +227,7 @@ void DataSeriesHydro::reset() maxHourlyGenPower.reset(1, HOURS_PER_YEAR); maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); count = 1; - nbTimeSeriesSup = 1; + nbTimeSeriesSup_ = 1; } uint64_t DataSeriesHydro::memoryUsage() const @@ -269,10 +269,10 @@ bool DataSeriesHydro::postProcessMaxPowerTS(Area& area) if (nbTSCompare.same()) return true; - if (nbTSCompare.differentAndGreaterThanOne(nbTimeSeriesSup)) + if (nbTSCompare.differentAndGreaterThanOne(nbTimeSeriesSup_)) tsActions.handleBothGreaterThanOne(area.id); - tsActions.resizeWhenOneTS(area, nbTimeSeriesSup); + tsActions.resizeWhenOneTS(area, nbTimeSeriesSup_); return true; } @@ -287,14 +287,14 @@ void DataSeriesHydro::setHydroModulability(Study& study, const AreaName& areaID) } } -void DataSeriesHydro::setNbTimeSeriesSup(uint nbTimeSeriesSup_) +void DataSeriesHydro::setNbTimeSeriesSup(uint nbTimeSeriesSup) { - nbTimeSeriesSup = nbTimeSeriesSup_; + nbTimeSeriesSup = nbTimeSeriesSup; } uint DataSeriesHydro::getNbTimeSeriesSup() const { - return nbTimeSeriesSup; + return nbTimeSeriesSup_; } void DataSeriesHydro::setNbTimeSeriesSup() @@ -302,7 +302,7 @@ void DataSeriesHydro::setNbTimeSeriesSup() const auto& maxHourlyGenPower_ = maxHourlyGenPower.width; const auto& maxHourlyPumpPower_ = maxHourlyPumpPower.width; - nbTimeSeriesSup + nbTimeSeriesSup_ = (maxHourlyGenPower_ >= maxHourlyPumpPower_) ? maxHourlyGenPower_ : maxHourlyPumpPower_; } @@ -312,7 +312,7 @@ void DataSeriesHydro::setMaxPowerTSWhenDeratedMode(const Study& study) { maxHourlyGenPower.averageTimeseries(); maxHourlyPumpPower.averageTimeseries(); - nbTimeSeriesSup = 1; + nbTimeSeriesSup_ = 1; } } @@ -331,9 +331,9 @@ bool DataSeriesHydro::NbTsComparer::same() const return (nbOfGenPowerTs == nbOfPumpPowerTs) ? true : false; } -bool DataSeriesHydro::NbTsComparer::differentAndGreaterThanOne(uint nbTimeSeriesSup_) const +bool DataSeriesHydro::NbTsComparer::differentAndGreaterThanOne(uint nbTimeSeriesSup) const { - return (nbTimeSeriesSup_ > 1 && (nbOfGenPowerTs != 1) && (nbOfPumpPowerTs != 1)) ? true + return (nbTimeSeriesSup > 1 && (nbOfGenPowerTs != 1) && (nbOfPumpPowerTs != 1)) ? true : false; } @@ -360,32 +360,32 @@ void DataSeriesHydro::TsActions::handleBothZeros(const AreaName& areaID) throw Error::ReadingStudy(); } -void DataSeriesHydro::TsActions::resizeWhenOneTS(Area& area, uint nbTimeSeriesSup_) +void DataSeriesHydro::TsActions::resizeWhenOneTS(Area& area, uint nbTimeSeriesSup) { if (maxHourlyGenPower.width == 1) { - resizeMatrixNoDataLoss(maxHourlyGenPower, nbTimeSeriesSup_); - areaToInvalidate(&area, area.id, nbTimeSeriesSup_); + resizeMatrixNoDataLoss(maxHourlyGenPower, nbTimeSeriesSup); + areaToInvalidate(&area, area.id, nbTimeSeriesSup); return; } if (maxHourlyPumpPower.width == 1) { - resizeMatrixNoDataLoss(maxHourlyPumpPower, nbTimeSeriesSup_); - areaToInvalidate(&area, area.id, nbTimeSeriesSup_); + resizeMatrixNoDataLoss(maxHourlyPumpPower, nbTimeSeriesSup); + areaToInvalidate(&area, area.id, nbTimeSeriesSup); return; } } void DataSeriesHydro::TsActions::areaToInvalidate(Area* area, const AreaName& areaID, - uint nbTimeSeriesSup_) const + uint nbTimeSeriesSup) const { if (area) { area->invalidateJIT = true; logs.info() << " '" << area->id << "': The hydro max power data have been normalized to " - << nbTimeSeriesSup_ << " timeseries"; + << nbTimeSeriesSup << " timeseries"; } else logs.error() << "Impossible to find the area `" << areaID << "` to invalidate it"; diff --git a/src/libs/antares/study/parts/hydro/series.h b/src/libs/antares/study/parts/hydro/series.h index 14ffeba7d1..de999c1dc3 100644 --- a/src/libs/antares/study/parts/hydro/series.h +++ b/src/libs/antares/study/parts/hydro/series.h @@ -178,7 +178,7 @@ class DataSeriesHydro /** * \brief Setting TS's number of maximum generation and pumping matrices */ - void setNbTimeSeriesSup(uint nbTimeSeriesSup_); + void setNbTimeSeriesSup(uint nbTimeSeriesSup); /** * \brief Setting TS's number of maximum generation and pumping matrices @@ -206,7 +206,7 @@ class DataSeriesHydro *routine, it might ** indicate that the two values are not strictly equal) */ - uint nbTimeSeriesSup = 0; + uint nbTimeSeriesSup_ = 0; /** * This class provides comparing two integers @@ -219,7 +219,7 @@ class DataSeriesHydro bool bothZeros() const; bool same() const; - bool differentAndGreaterThanOne(uint nbTimeSeriesSup_) const; + bool differentAndGreaterThanOne(uint nbTimeSeriesSup) const; private: uint32_t nbOfGenPowerTs{0}; @@ -238,13 +238,13 @@ class DataSeriesHydro void handleBothZeros(const AreaName& areaID); [[noreturn]] void handleBothGreaterThanOne(const AreaName& areaID) const; - void resizeWhenOneTS(Area& area, uint nbTimeSeriesSup_); + void resizeWhenOneTS(Area& area, uint nbTimeSeriesSup); private: Matrix& maxHourlyGenPower; Matrix& maxHourlyPumpPower; - void areaToInvalidate(Area* area, const AreaName& areaID, uint nbTimeSeriesSup_) const; + void areaToInvalidate(Area* area, const AreaName& areaID, uint nbTimeSeriesSup) const; }; }; // class DataSeriesHydro diff --git a/src/tests/src/libs/antares/study/parts/hydro/CMakeLists.txt b/src/tests/src/libs/antares/study/parts/hydro/CMakeLists.txt index 3f8db81a57..d113d66e8b 100644 --- a/src/tests/src/libs/antares/study/parts/hydro/CMakeLists.txt +++ b/src/tests/src/libs/antares/study/parts/hydro/CMakeLists.txt @@ -1,7 +1,7 @@ # Useful variables definitions set(src_libs_antares_study "${CMAKE_SOURCE_DIR}/libs/antares/study") set(src_libs_antares "${CMAKE_SOURCE_DIR}/libs/antares") -set(src_test_utilis "${CMAKE_SOURCE_DIR}/tests/src/utlis") +set(src_test_utils "${CMAKE_SOURCE_DIR}/tests/src/utils") # Hydro data reader @@ -14,7 +14,7 @@ target_include_directories(test-hydro-reader PRIVATE "${src_libs_antares_study}" "${src_libs_antares}/array/antares/array" - "${src_test_utilis}" + "${src_test_utils}" ) target_link_libraries(test-hydro-reader @@ -45,7 +45,7 @@ target_include_directories(test-hydro-series "${src_libs_antares_study}" "${src_libs_antares}/array/antares/array" "${src_libs_antares}/exception/antares/exception" - "${src_test_utilis}" + "${src_test_utils}" ) target_link_libraries(test-hydro-series From 33b5c5e18230199fc3716585b87464fa58840557 Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Fri, 13 Oct 2023 17:03:17 +0200 Subject: [PATCH 32/40] Unit test fix and renaming --- src/libs/antares/study/parts/hydro/series.cpp | 30 +++++++++---------- src/libs/antares/study/parts/hydro/series.h | 16 +++++----- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/libs/antares/study/parts/hydro/series.cpp b/src/libs/antares/study/parts/hydro/series.cpp index f7caacc076..6fa07744eb 100644 --- a/src/libs/antares/study/parts/hydro/series.cpp +++ b/src/libs/antares/study/parts/hydro/series.cpp @@ -289,7 +289,7 @@ void DataSeriesHydro::setHydroModulability(Study& study, const AreaName& areaID) void DataSeriesHydro::setNbTimeSeriesSup(uint nbTimeSeriesSup) { - nbTimeSeriesSup = nbTimeSeriesSup; + nbTimeSeriesSup_ = nbTimeSeriesSup; } uint DataSeriesHydro::getNbTimeSeriesSup() const @@ -316,30 +316,30 @@ void DataSeriesHydro::setMaxPowerTSWhenDeratedMode(const Study& study) } } -DataSeriesHydro::NbTsComparer::NbTsComparer(uint32_t nbOfGenPowerTs_, uint32_t nbOfPumpPowerTs_) : - nbOfGenPowerTs(nbOfGenPowerTs_), nbOfPumpPowerTs(nbOfPumpPowerTs_) +DataSeriesHydro::NbTsComparer::NbTsComparer(uint32_t nbOfGenPowerTs, uint32_t nbOfPumpPowerTs) : + nbOfGenPowerTs_(nbOfGenPowerTs), nbOfPumpPowerTs_(nbOfPumpPowerTs) { } bool DataSeriesHydro::NbTsComparer::bothZeros() const { - return (nbOfGenPowerTs || nbOfPumpPowerTs) ? false : true; + return (nbOfGenPowerTs_ || nbOfPumpPowerTs_) ? false : true; } bool DataSeriesHydro::NbTsComparer::same() const { - return (nbOfGenPowerTs == nbOfPumpPowerTs) ? true : false; + return (nbOfGenPowerTs_ == nbOfPumpPowerTs_) ? true : false; } bool DataSeriesHydro::NbTsComparer::differentAndGreaterThanOne(uint nbTimeSeriesSup) const { - return (nbTimeSeriesSup > 1 && (nbOfGenPowerTs != 1) && (nbOfPumpPowerTs != 1)) ? true + return (nbTimeSeriesSup > 1 && (nbOfGenPowerTs_ != 1) && (nbOfPumpPowerTs_ != 1)) ? true : false; } -DataSeriesHydro::TsActions::TsActions(Matrix& maxHourlyGenPower_, - Matrix& maxHourlyPumpPower_) : - maxHourlyGenPower(maxHourlyGenPower_), maxHourlyPumpPower(maxHourlyPumpPower_) +DataSeriesHydro::TsActions::TsActions(Matrix& maxHourlyGenPower, + Matrix& maxHourlyPumpPower) : + maxHourlyGenPower_(maxHourlyGenPower), maxHourlyPumpPower_(maxHourlyPumpPower) { } @@ -348,8 +348,8 @@ void DataSeriesHydro::TsActions::handleBothZeros(const AreaName& areaID) logs.error() << "Hydro Max Power: `" << areaID << "`: empty matrix detected. Fixing it with default values"; - maxHourlyGenPower.reset(1, HOURS_PER_YEAR); - maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); + maxHourlyGenPower_.reset(1, HOURS_PER_YEAR); + maxHourlyPumpPower_.reset(1, HOURS_PER_YEAR); } [[noreturn]] void DataSeriesHydro::TsActions::handleBothGreaterThanOne(const AreaName& areaID) const @@ -362,16 +362,16 @@ void DataSeriesHydro::TsActions::handleBothZeros(const AreaName& areaID) void DataSeriesHydro::TsActions::resizeWhenOneTS(Area& area, uint nbTimeSeriesSup) { - if (maxHourlyGenPower.width == 1) + if (maxHourlyGenPower_.width == 1) { - resizeMatrixNoDataLoss(maxHourlyGenPower, nbTimeSeriesSup); + resizeMatrixNoDataLoss(maxHourlyGenPower_, nbTimeSeriesSup); areaToInvalidate(&area, area.id, nbTimeSeriesSup); return; } - if (maxHourlyPumpPower.width == 1) + if (maxHourlyPumpPower_.width == 1) { - resizeMatrixNoDataLoss(maxHourlyPumpPower, nbTimeSeriesSup); + resizeMatrixNoDataLoss(maxHourlyPumpPower_, nbTimeSeriesSup); areaToInvalidate(&area, area.id, nbTimeSeriesSup); return; } diff --git a/src/libs/antares/study/parts/hydro/series.h b/src/libs/antares/study/parts/hydro/series.h index de999c1dc3..d3dd7b50b9 100644 --- a/src/libs/antares/study/parts/hydro/series.h +++ b/src/libs/antares/study/parts/hydro/series.h @@ -215,15 +215,15 @@ class DataSeriesHydro class NbTsComparer { public: - NbTsComparer(uint32_t nbOfGenPowerTs_, uint32_t nbOfPumpPowerTs_); + NbTsComparer(uint32_t nbOfGenPowerTs, uint32_t nbOfPumpPowerTs); bool bothZeros() const; bool same() const; bool differentAndGreaterThanOne(uint nbTimeSeriesSup) const; private: - uint32_t nbOfGenPowerTs{0}; - uint32_t nbOfPumpPowerTs{0}; + uint32_t nbOfGenPowerTs_{0}; + uint32_t nbOfPumpPowerTs_{0}; }; /** @@ -233,23 +233,23 @@ class DataSeriesHydro class TsActions { public: - TsActions(Matrix& maxHourlyGenPower_, - Matrix& maxHourlyPumpPower_); + TsActions(Matrix& maxHourlyGenPower, + Matrix& maxHourlyPumpPower); void handleBothZeros(const AreaName& areaID); [[noreturn]] void handleBothGreaterThanOne(const AreaName& areaID) const; void resizeWhenOneTS(Area& area, uint nbTimeSeriesSup); private: - Matrix& maxHourlyGenPower; - Matrix& maxHourlyPumpPower; + Matrix& maxHourlyGenPower_; + Matrix& maxHourlyPumpPower_; void areaToInvalidate(Area* area, const AreaName& areaID, uint nbTimeSeriesSup) const; }; }; // class DataSeriesHydro -void resizeMatrixNoDataLoss(Matrix& maxHourlyGenPower, uint width); +void resizeMatrixNoDataLoss(Matrix& matrixToResize, uint width); } // namespace Data } // namespace Antares From adbece2194b50356d28d5f9e5c844970b7dee1ef Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Fri, 13 Oct 2023 17:29:16 +0200 Subject: [PATCH 33/40] hydro reader unit tests refactoring --- .../parts/hydro/test-hydroreader-class.cpp | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/tests/src/libs/antares/study/parts/hydro/test-hydroreader-class.cpp b/src/tests/src/libs/antares/study/parts/hydro/test-hydroreader-class.cpp index 851f2765fc..bf25aa63f2 100644 --- a/src/tests/src/libs/antares/study/parts/hydro/test-hydroreader-class.cpp +++ b/src/tests/src/libs/antares/study/parts/hydro/test-hydroreader-class.cpp @@ -74,8 +74,7 @@ struct Fixture buffer.clear(); buffer = base_folder + SEP + hydro_folder + SEP + common_folder + SEP + capacity_folder + SEP + maxpower + area_1->id.c_str() + ".txt"; - Yuni::CString<256, false> temp(buffer); - reader->dailyMaxPumpAndGen.saveToCSVFile(temp, 2); + reader->dailyMaxPumpAndGen.saveToCSVFile(buffer, 2); } void createFoldersAndFiles() @@ -91,12 +90,12 @@ struct Fixture createFolder(buffer, series_folder); // area1 folder - stringT area1_folder = area_1->id.c_str(); + stringT area1_ID = area_1->id.c_str(); buffer.clear(); buffer = base_folder + SEP + hydro_folder + SEP + series_folder; - createFolder(buffer, area1_folder); + createFolder(buffer, area1_ID); buffer.clear(); - buffer = base_folder + SEP + hydro_folder + SEP + series_folder + SEP + area1_folder; + buffer = base_folder + SEP + hydro_folder + SEP + series_folder + SEP + area1_ID; // maxHourlyGenPower and maxHourlyPumpPower files createFile(buffer, maxHourlyGenPower); createFile(buffer, maxHourlyPumpPower); @@ -109,14 +108,20 @@ struct Fixture buffer = base_folder + SEP + hydro_folder + SEP + common_folder; createFolder(buffer, capacity_folder); - // maxhours files - stringT maxpowerArea1 = maxpower + area1_folder + ".txt"; buffer.clear(); buffer = base_folder + SEP + hydro_folder + SEP + common_folder + SEP + capacity_folder; - createFile(buffer, maxDailyGenEnergy_); - createFile(buffer, maxDailyPumpEnergy_); + // max daily energy and power file + stringT maxpowerArea1 = maxpower + area1_ID + ".txt"; + createFile(buffer, maxpowerArea1); + + // max daily energy files + stringT maxDailyGenEnergy_Area1 = maxDailyGenEnergy_ + area1_ID + ".txt"; + stringT maxDailyPumpEnergy_Area1 = maxDailyPumpEnergy_ + area1_ID + ".txt"; + + createFile(buffer, maxDailyGenEnergy_Area1); + createFile(buffer, maxDailyPumpEnergy_Area1); } std::shared_ptr study; @@ -128,8 +133,8 @@ struct Fixture stringT series_folder = "series"; stringT common_folder = "common"; stringT capacity_folder = "capacity"; - stringT maxDailyGenEnergy_ = "maxDailyGenEnergy_area1.txt"; - stringT maxDailyPumpEnergy_ = "maxDailyPumpEnergy_area1.txt"; + stringT maxDailyGenEnergy_ = "maxDailyGenEnergy_"; + stringT maxDailyPumpEnergy_ = "maxDailyPumpEnergy_"; stringT maxpower = "maxpower_"; stringT maxHourlyGenPower = "maxHourlyGenPower.txt"; stringT maxHourlyPumpPower = "maxHourlyPumpPower.txt"; From e907fb0593239a05d801e0f1ebf650ecf0243c4a Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Sat, 14 Oct 2023 19:05:33 +0200 Subject: [PATCH 34/40] Refactoring unit tests help functions --- .../parts/hydro/test-hydroreader-class.cpp | 66 ++++++++++++------- 1 file changed, 42 insertions(+), 24 deletions(-) diff --git a/src/tests/src/libs/antares/study/parts/hydro/test-hydroreader-class.cpp b/src/tests/src/libs/antares/study/parts/hydro/test-hydroreader-class.cpp index bf25aa63f2..ed123ab24a 100644 --- a/src/tests/src/libs/antares/study/parts/hydro/test-hydroreader-class.cpp +++ b/src/tests/src/libs/antares/study/parts/hydro/test-hydroreader-class.cpp @@ -12,31 +12,35 @@ using namespace Antares::Data; namespace fs = std::filesystem; -bool DailyMaxPowerAsHourlyTransferCheck(Matrix::ColumnType& hourlyColumn, +bool equalDailyMaxPowerAsHourlyTs(const Matrix::ColumnType& hourlyColumn, const Matrix::ColumnType& dailyColumn) { - uint hours = 0; - uint days = 0; - bool check = true; + uint hour = 0; + uint day = 0; - while (hours < HOURS_PER_YEAR && days < DAYS_PER_YEAR) + while (hour < HOURS_PER_YEAR && day < DAYS_PER_YEAR) { - for (uint i = 0; i < 24; ++i) + for (uint i = 0; i < HOURS_PER_DAY; ++i) { - if (hourlyColumn[hours] != dailyColumn[days]) - { - check = false; - break; - } - ++hours; + if (hourlyColumn[hour] != dailyColumn[day]) + return false; + ++hour; } + ++day; + } - if (!check) - break; + return true; +} - ++days; +bool equalDailyMaxEnergyTs(const Matrix::ColumnType& col1, const Matrix::ColumnType& col2) +{ + for (uint h = 0; h < DAYS_PER_YEAR; ++h) + { + if (col1[h] != col2[h]) + return false; } - return check; + + return true; } void fillColumnWithSpecialEnds(Matrix::ColumnType& col, double value, uint heigth) @@ -75,6 +79,12 @@ struct Fixture buffer = base_folder + SEP + hydro_folder + SEP + common_folder + SEP + capacity_folder + SEP + maxpower + area_1->id.c_str() + ".txt"; reader->dailyMaxPumpAndGen.saveToCSVFile(buffer, 2); + + // Reset columns + reader->dailyMaxPumpAndGen.fillColumn(HydroMaxTimeSeriesReader::genMaxP, 0.); + reader->dailyMaxPumpAndGen.fillColumn(HydroMaxTimeSeriesReader::pumpMaxP, 0.); + reader->dailyMaxPumpAndGen.fillColumn(HydroMaxTimeSeriesReader::genMaxE, 24.); + reader->dailyMaxPumpAndGen.fillColumn(HydroMaxTimeSeriesReader::pumpMaxE, 24.); } void createFoldersAndFiles() @@ -127,8 +137,7 @@ struct Fixture std::shared_ptr study; std::shared_ptr reader; Area* area_1; - Area* area_2; - stringT base_folder = fs::current_path().string(); + stringT base_folder = fs::temp_directory_path().string(); stringT hydro_folder = "hydro"; stringT series_folder = "series"; stringT common_folder = "common"; @@ -151,17 +160,26 @@ BOOST_FIXTURE_TEST_CASE(Testing_support_for_old_studies, Fixture) { stringT buffer; bool ret = true; - auto& colMaxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower[0]; - auto& colMaxHourlyPumpPower = area_1->hydro.series->maxHourlyPumpPower[0]; - auto& gen = reader->dailyMaxPumpAndGen[HydroMaxTimeSeriesReader::genMaxP]; - auto& pump = reader->dailyMaxPumpAndGen[HydroMaxTimeSeriesReader::pumpMaxP]; + + auto& genP = area_1->hydro.series->maxHourlyGenPower[0]; + auto& pumpP = area_1->hydro.series->maxHourlyPumpPower[0]; + auto& genE = area_1->hydro.maxDailyGenEnergy[0]; + auto& pumpE = area_1->hydro.maxDailyPumpEnergy[0]; + + auto& genPReader = reader->dailyMaxPumpAndGen[HydroMaxTimeSeriesReader::genMaxP]; + auto& pumpPReader = reader->dailyMaxPumpAndGen[HydroMaxTimeSeriesReader::pumpMaxP]; + auto& genEReader = reader->dailyMaxPumpAndGen[HydroMaxTimeSeriesReader::genMaxE]; + auto& pumpEReader = reader->dailyMaxPumpAndGen[HydroMaxTimeSeriesReader::pumpMaxE]; buffer.clear(); buffer = base_folder + SEP + hydro_folder; ret = (*reader)(buffer, *area_1) && ret; + BOOST_CHECK(ret); - BOOST_CHECK(DailyMaxPowerAsHourlyTransferCheck(colMaxHourlyGenPower, gen)); - BOOST_CHECK(DailyMaxPowerAsHourlyTransferCheck(colMaxHourlyPumpPower, pump)); + BOOST_CHECK(equalDailyMaxPowerAsHourlyTs(genP, genPReader)); + BOOST_CHECK(equalDailyMaxPowerAsHourlyTs(pumpP, pumpPReader)); + BOOST_CHECK(equalDailyMaxEnergyTs(genE, genEReader)); + BOOST_CHECK(equalDailyMaxEnergyTs(pumpE, pumpEReader)); } BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file From 5da63e3add150acf2c778a8fd0c092e4bc973ed8 Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Mon, 16 Oct 2023 11:50:32 +0200 Subject: [PATCH 35/40] Excluding saving new files before upgrade --- src/libs/antares/constants.h | 2 +- src/libs/antares/study/area/list.cpp | 2 +- .../parts/hydro/hydromaxtimeseriesreader.cpp | 164 +++++++----------- .../parts/hydro/hydromaxtimeseriesreader.h | 48 ++--- .../parts/hydro/test-hydroreader-class.cpp | 21 ++- 5 files changed, 106 insertions(+), 131 deletions(-) diff --git a/src/libs/antares/constants.h b/src/libs/antares/constants.h index aed585153b..61372b62bc 100644 --- a/src/libs/antares/constants.h +++ b/src/libs/antares/constants.h @@ -42,7 +42,7 @@ /*! Hours per year */ #define HOURS_PER_YEAR 8760 -#define HOURS_PER_DAY 24 +#define HOURS_PER_DAY 24U namespace Antares::Constants { diff --git a/src/libs/antares/study/area/list.cpp b/src/libs/antares/study/area/list.cpp index 3c7b5d4efb..5c24b39fa1 100644 --- a/src/libs/antares/study/area/list.cpp +++ b/src/libs/antares/study/area/list.cpp @@ -912,7 +912,7 @@ static bool AreaListLoadFromFolderSingleArea(Study& study, buffer.clear() << study.folderInput << SEP << "hydro"; HydroMaxTimeSeriesReader reader; - ret = reader(buffer, area) && ret; + ret = reader(buffer, area, study.usedByTheSolver) && ret; } if (area.hydro.series && study.header.version >= 870) diff --git a/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.cpp b/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.cpp index fcb8ceddae..96f91d262d 100644 --- a/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.cpp +++ b/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.cpp @@ -38,10 +38,12 @@ namespace Antares::Data HydroMaxTimeSeriesReader::HydroMaxTimeSeriesReader() { - dailyMaxPumpAndGen.reset(4, DAYS_PER_YEAR, true); + dailyMaxPumpAndGen.reset(4U, DAYS_PER_YEAR, true); } -bool HydroMaxTimeSeriesReader::LoadDailyMaxPowersAndEnergies(const AnyString& folder, const Area& area) +bool HydroMaxTimeSeriesReader::loadDailyMaxPowersAndEnergies(const AnyString& folder, + const Area& area, + bool usedBySolver) { YString filePath; Matrix<>::BufferType fileContent; @@ -53,159 +55,125 @@ bool HydroMaxTimeSeriesReader::LoadDailyMaxPowersAndEnergies(const AnyString& fo // It is necessary to load maxpower_ txt file, whether loading is called from old GUI // or from solver. - bool enabledModeIsChanged = false; - - if (JIT::enabled) + if (!usedBySolver) { - JIT::enabled = false; // Allowing to read the area's daily max power and energy - enabledModeIsChanged = true; - } + bool enabledModeIsChanged = false; - ret = dailyMaxPumpAndGen.loadFromCSVFile( - filePath, 4, DAYS_PER_YEAR, Matrix<>::optFixedSize, &fileContent) - && ret; + if (JIT::enabled) + { + JIT::enabled = false; // Allowing to read the area's daily max power and energy + enabledModeIsChanged = true; + } - if (enabledModeIsChanged) - JIT::enabled = true; // Back to the previous loading mode. + ret = dailyMaxPumpAndGen.loadFromCSVFile( + filePath, 4U, DAYS_PER_YEAR, Matrix<>::optFixedSize, &fileContent) + && ret; - bool errorPowers = false; - for (uint i = 0; i < 4; ++i) + if (enabledModeIsChanged) + JIT::enabled = true; // Back to the previous loading mode. + } + else { - auto& col = dailyMaxPumpAndGen[i]; - for (uint day = 0; day < DAYS_PER_YEAR; ++day) + ret = dailyMaxPumpAndGen.loadFromCSVFile( + filePath, 4U, DAYS_PER_YEAR, Matrix<>::optFixedSize, &fileContent) + && ret; + + bool errorPowers = false; + for (uint i = 0; i < 4U; ++i) { - if (!errorPowers && (col[day] < 0 || (i % 2 /*column hours*/ && col[day] > 24))) + auto& col = dailyMaxPumpAndGen[i]; + for (uint day = 0; day < DAYS_PER_YEAR; ++day) { - logs.error() << area.name << ": invalid power or energy value"; - errorPowers = true; - ret = false; + if (!errorPowers && (col[day] < 0. || (i % 2U /*column hours*/ && col[day] > 24.))) + { + logs.error() << area.name << ": invalid power or energy value"; + errorPowers = true; + ret = false; + } } } } return ret; } -bool HydroMaxTimeSeriesReader::SaveDailyMaxEnergy(const AnyString& folder, Area& area) +void HydroMaxTimeSeriesReader::copyDailyMaxEnergy(Area& area) const { - bool ret = true; - - ret = SaveMaxGenerationEnergy(folder, area) && ret; - ret = SaveMaxPumpingEnergy(folder, area) && ret; - - return ret; + copyDailyMaxGenerationEnergy(area); + copyDailyMaxPumpingEnergy(area); } -bool HydroMaxTimeSeriesReader::SaveMaxGenerationEnergy(const AnyString& folder, Area& area) +void HydroMaxTimeSeriesReader::copyDailyMaxGenerationEnergy(Area& area) const { - YString filePath; auto& maxDailyGenEnergy = area.hydro.maxDailyGenEnergy; - bool ret = true; - - maxDailyGenEnergy.reset(1, DAYS_PER_YEAR, true); - maxDailyGenEnergy.fillColumn(0, 24.); - - maxDailyGenEnergy.pasteToColumn(0, dailyMaxPumpAndGen[genMaxE]); - - filePath.clear() << folder << SEP << "common" << SEP << "capacity" << SEP - << "maxDailyGenEnergy_" << area.id << ".txt"; + const auto& dailyMaxGenE = dailyMaxPumpAndGen[genMaxE]; - ret = maxDailyGenEnergy.saveToCSVFile(filePath, 2) && ret; + maxDailyGenEnergy.reset(1U, DAYS_PER_YEAR, true); - return ret; + maxDailyGenEnergy.pasteToColumn(0, dailyMaxGenE); } -bool HydroMaxTimeSeriesReader::SaveMaxPumpingEnergy(const AnyString& folder, Area& area) +void HydroMaxTimeSeriesReader::copyDailyMaxPumpingEnergy(Area& area) const { - YString filePath; auto& maxDailyPumpEnergy = area.hydro.maxDailyPumpEnergy; - bool ret = true; - - maxDailyPumpEnergy.reset(1, DAYS_PER_YEAR, true); - maxDailyPumpEnergy.fillColumn(0, 24.); + const auto& dailyMaxPumpE = dailyMaxPumpAndGen[pumpMaxE]; - maxDailyPumpEnergy.pasteToColumn(0, dailyMaxPumpAndGen[pumpMaxE]); + maxDailyPumpEnergy.reset(1U, DAYS_PER_YEAR, true); - filePath.clear() << folder << SEP << "common" << SEP << "capacity" << SEP - << "maxDailyPumpEnergy_" << area.id << ".txt"; - ret = maxDailyPumpEnergy.saveToCSVFile(filePath, 2) && ret; - - return ret; + maxDailyPumpEnergy.pasteToColumn(0, dailyMaxPumpE); } -bool HydroMaxTimeSeriesReader::SaveDailyMaxPowerAsHourly(const AnyString& folder, Area& area) +void HydroMaxTimeSeriesReader::copyDailyMaxPowerAsHourly(Area& area) const { - bool ret = true; - - ret = SaveDailyMaxGenPowerAsHourly(folder, area) && ret; - ret = SaveDailyMaxPumpPowerAsHourly(folder, area) && ret; + copyDailyMaxGenPowerAsHourly(area); + copyDailyMaxPumpPowerAsHourly(area); area.hydro.series->setNbTimeSeriesSup(); - - return ret; } -bool HydroMaxTimeSeriesReader::SaveDailyMaxGenPowerAsHourly(const AnyString& folder, Area& area) +void HydroMaxTimeSeriesReader::copyDailyMaxGenPowerAsHourly(Area& area) const { - bool ret = true; - YString filePath; - auto& maxHourlyGenPower = area.hydro.series->maxHourlyGenPower; - auto& dailyMaxGen = dailyMaxPumpAndGen[genMaxP]; + const auto& dailyMaxGenP = dailyMaxPumpAndGen[genMaxP]; - maxHourlyGenPower.reset(1, HOURS_PER_YEAR); + maxHourlyGenPower.reset(1U, HOURS_PER_YEAR); - TransferDailyMaxPowerAsHourly(maxHourlyGenPower[0], dailyMaxGen); - - filePath.clear() << folder << SEP << "series" << SEP << area.id << SEP << "maxHourlyGenPower." - << "txt"; - ret = maxHourlyGenPower.saveToCSVFile(filePath, 2) && ret; - - return ret; + copyDailyTsAsHourly(maxHourlyGenPower[0], dailyMaxGenP); } -bool HydroMaxTimeSeriesReader::SaveDailyMaxPumpPowerAsHourly(const AnyString& folder, Area& area) +void HydroMaxTimeSeriesReader::copyDailyMaxPumpPowerAsHourly(Area& area) const { - bool ret = true; - YString filePath; - auto& maxHourlyPumpPower = area.hydro.series->maxHourlyPumpPower; - auto& dailyMaxPump = dailyMaxPumpAndGen[pumpMaxP]; - - maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); + const auto& dailyMaxPumpP = dailyMaxPumpAndGen[pumpMaxP]; - TransferDailyMaxPowerAsHourly(maxHourlyPumpPower[0], dailyMaxPump); + maxHourlyPumpPower.reset(1U, HOURS_PER_YEAR); - filePath.clear() << folder << SEP << "series" << SEP << area.id << SEP << "maxHourlyPumpPower." - << "txt"; - ret = maxHourlyPumpPower.saveToCSVFile(filePath, 2) && ret; - - return ret; + copyDailyTsAsHourly(maxHourlyPumpPower[0], dailyMaxPumpP); } -bool HydroMaxTimeSeriesReader::operator()(const AnyString& folder, Area& area) +bool HydroMaxTimeSeriesReader::operator()(const AnyString& folder, Area& area, bool usedBySolver) { bool ret = true; - ret = LoadDailyMaxPowersAndEnergies(folder, area) && ret; - ret = SaveDailyMaxEnergy(folder, area) && ret; - ret = SaveDailyMaxPowerAsHourly(folder, area) && ret; + ret = loadDailyMaxPowersAndEnergies(folder, area, usedBySolver) && ret; + copyDailyMaxEnergy(area); + copyDailyMaxPowerAsHourly(area); return ret; } -void TransferDailyMaxPowerAsHourly(Matrix::ColumnType& hourlyColumn, - const Matrix::ColumnType& dailyColumn) +void copyDailyTsAsHourly(Matrix::ColumnType& hourlyColumn, + const Matrix::ColumnType& dailyColumn) { - uint hours = 0; - uint days = 0; + uint hour = 0; + uint day = 0; - while (hours < HOURS_PER_YEAR && days < DAYS_PER_YEAR) + while (hour < HOURS_PER_YEAR && day < DAYS_PER_YEAR) { for (uint i = 0; i < HOURS_PER_DAY; ++i) { - hourlyColumn[hours] = dailyColumn[days]; - ++hours; + hourlyColumn[hour] = dailyColumn[day]; + ++hour; } - ++days; + ++day; } } diff --git a/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.h b/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.h index adbfbef460..fe526d033c 100644 --- a/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.h +++ b/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.h @@ -34,15 +34,16 @@ namespace Antares::Data { /*! ** This class provides support for old studies, reading from deprecated files, -** fils matrix dailyMaxPumpAndGen and transfers data to the corresponding data class members of -** class PartHydro. Just version below 8.7 will use this class to be compatible with current implemetation. +** fils matrix dailyMaxPumpAndGen and transfers data to the corresponding data +** class members of class PartHydro. Just versions below 8.7 will use instance +** of this class to be compatible with current implementation. */ class HydroMaxTimeSeriesReader { public: HydroMaxTimeSeriesReader(); - bool operator()(const AnyString& folder, Area& area); + bool operator()(const AnyString& folder, Area& area, bool usedBySolver); Matrix dailyMaxPumpAndGen; @@ -61,32 +62,39 @@ class HydroMaxTimeSeriesReader private: /** * \brief Loading deprecated files - * This function provides reading from deprecated files - * which contains daily maximum generation/pumping power data. + * This function provides reading from deprecated files which + * contains daily maximum generation/pumping power and energy data. */ - bool LoadDailyMaxPowersAndEnergies(const AnyString& folder, const Area& area); + bool loadDailyMaxPowersAndEnergies(const AnyString& folder, + const Area& area, + bool usedBySolver); /** - * \brief Save energy functions - * These functions provides instantiation of necessary matrices for - * computation and saving matrices data to the newly created files. + * \brief Copy energy functions + * These functions provides coping of energy data loaded + * from deprecated file. */ - bool SaveDailyMaxEnergy(const AnyString& folder, Area& area); - bool SaveMaxGenerationEnergy(const AnyString& folder, Area& area); - bool SaveMaxPumpingEnergy(const AnyString& folder, Area& area); + void copyDailyMaxEnergy(Area& area) const; + void copyDailyMaxGenerationEnergy(Area& area) const; + void copyDailyMaxPumpingEnergy(Area& area) const; /** - * \brief Save power functions - * These functions provides instantiation of necessary matrices for - * computation and saving matrices data to the newly created files. + * \brief Copy power functions + * These functions provides coping of power data loaded + * from deprecated file. */ - bool SaveDailyMaxPowerAsHourly(const AnyString& folder, Area& area); - bool SaveDailyMaxGenPowerAsHourly(const AnyString& folder, Area& area); - bool SaveDailyMaxPumpPowerAsHourly(const AnyString& folder, Area& area); + void copyDailyMaxPowerAsHourly(Area& area) const; + void copyDailyMaxGenPowerAsHourly(Area& area) const; + void copyDailyMaxPumpPowerAsHourly(Area& area) const; }; -void TransferDailyMaxPowerAsHourly(Matrix::ColumnType& hourlyColumn, - const Matrix::ColumnType& dailyColumn); +/** + * \brief Copy raw data + * This function provides coping raw data from daily resolution + * column and pasting data into hourly resolution column. + */ +void copyDailyTsAsHourly(Matrix::ColumnType& hourlyColumn, + const Matrix::ColumnType& dailyColumn); } // namespace Antares::Data diff --git a/src/tests/src/libs/antares/study/parts/hydro/test-hydroreader-class.cpp b/src/tests/src/libs/antares/study/parts/hydro/test-hydroreader-class.cpp index ed123ab24a..75132e2e07 100644 --- a/src/tests/src/libs/antares/study/parts/hydro/test-hydroreader-class.cpp +++ b/src/tests/src/libs/antares/study/parts/hydro/test-hydroreader-class.cpp @@ -90,6 +90,11 @@ struct Fixture void createFoldersAndFiles() { stringT buffer; + stringT area1_ID = area_1->id.c_str(); + stringT maxpowerArea1 = maxpower + area1_ID + ".txt"; + stringT maxDailyGenEnergy_Area1 = maxDailyGenEnergy_ + area1_ID + ".txt"; + stringT maxDailyPumpEnergy_Area1 = maxDailyPumpEnergy_ + area1_ID + ".txt"; + buffer.clear(); // hydro folder @@ -100,17 +105,17 @@ struct Fixture createFolder(buffer, series_folder); // area1 folder - stringT area1_ID = area_1->id.c_str(); buffer.clear(); buffer = base_folder + SEP + hydro_folder + SEP + series_folder; createFolder(buffer, area1_ID); buffer.clear(); buffer = base_folder + SEP + hydro_folder + SEP + series_folder + SEP + area1_ID; - // maxHourlyGenPower and maxHourlyPumpPower files + + // maxHourlyGenPower and maxHourlyPumpPower files createFile(buffer, maxHourlyGenPower); createFile(buffer, maxHourlyPumpPower); - // common and capacity folders + // common and capacity folders buffer.clear(); buffer = base_folder + SEP + hydro_folder; createFolder(buffer, common_folder); @@ -118,18 +123,12 @@ struct Fixture buffer = base_folder + SEP + hydro_folder + SEP + common_folder; createFolder(buffer, capacity_folder); + // max daily energy and power file buffer.clear(); buffer = base_folder + SEP + hydro_folder + SEP + common_folder + SEP + capacity_folder; - - // max daily energy and power file - stringT maxpowerArea1 = maxpower + area1_ID + ".txt"; - createFile(buffer, maxpowerArea1); // max daily energy files - stringT maxDailyGenEnergy_Area1 = maxDailyGenEnergy_ + area1_ID + ".txt"; - stringT maxDailyPumpEnergy_Area1 = maxDailyPumpEnergy_ + area1_ID + ".txt"; - createFile(buffer, maxDailyGenEnergy_Area1); createFile(buffer, maxDailyPumpEnergy_Area1); } @@ -173,7 +172,7 @@ BOOST_FIXTURE_TEST_CASE(Testing_support_for_old_studies, Fixture) buffer.clear(); buffer = base_folder + SEP + hydro_folder; - ret = (*reader)(buffer, *area_1) && ret; + ret = (*reader)(buffer, *area_1, study->usedByTheSolver) && ret; BOOST_CHECK(ret); BOOST_CHECK(equalDailyMaxPowerAsHourlyTs(genP, genPReader)); From d642df753079d2bb66d9f358e2858e9c7aa30955 Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Mon, 16 Oct 2023 14:38:33 +0200 Subject: [PATCH 36/40] Renameing files --- .../src/libs/antares/study/constraint/test_constraint.cpp | 2 +- src/tests/src/libs/antares/study/constraint/test_group.cpp | 2 +- .../libs/antares/study/parts/hydro/test-hydro-series.cpp | 2 +- .../antares/study/parts/hydro/test-hydroreader-class.cpp | 2 +- .../src/solver/simulation/test-store-timeseries-number.cpp | 2 +- src/tests/src/solver/simulation/test-time_series.cpp | 2 +- src/tests/src/utils/CMakeLists.txt | 4 ++-- src/tests/src/utils/{utils.cpp => files-system.cpp} | 6 +++--- src/tests/src/utils/{utils.h => files-system.h} | 0 9 files changed, 11 insertions(+), 11 deletions(-) rename src/tests/src/utils/{utils.cpp => files-system.cpp} (92%) rename src/tests/src/utils/{utils.h => files-system.h} (100%) diff --git a/src/tests/src/libs/antares/study/constraint/test_constraint.cpp b/src/tests/src/libs/antares/study/constraint/test_constraint.cpp index a671d7857c..91aedabf1b 100644 --- a/src/tests/src/libs/antares/study/constraint/test_constraint.cpp +++ b/src/tests/src/libs/antares/study/constraint/test_constraint.cpp @@ -13,7 +13,7 @@ #include "antares/study/area/area.h" #include #include -#include "utils.h" +#include using namespace Antares::Data; namespace fs = std::filesystem; diff --git a/src/tests/src/libs/antares/study/constraint/test_group.cpp b/src/tests/src/libs/antares/study/constraint/test_group.cpp index c53f3c855d..c7f4faef7d 100644 --- a/src/tests/src/libs/antares/study/constraint/test_group.cpp +++ b/src/tests/src/libs/antares/study/constraint/test_group.cpp @@ -9,7 +9,7 @@ #include #include #include "antares/study/study.h" -#include "utils.h" +#include using namespace Antares::Data; namespace fs = std::filesystem; diff --git a/src/tests/src/libs/antares/study/parts/hydro/test-hydro-series.cpp b/src/tests/src/libs/antares/study/parts/hydro/test-hydro-series.cpp index 89a65be523..ca1e7f6d7d 100644 --- a/src/tests/src/libs/antares/study/parts/hydro/test-hydro-series.cpp +++ b/src/tests/src/libs/antares/study/parts/hydro/test-hydro-series.cpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include #define SEP "/" diff --git a/src/tests/src/libs/antares/study/parts/hydro/test-hydroreader-class.cpp b/src/tests/src/libs/antares/study/parts/hydro/test-hydroreader-class.cpp index 75132e2e07..c581528e8b 100644 --- a/src/tests/src/libs/antares/study/parts/hydro/test-hydroreader-class.cpp +++ b/src/tests/src/libs/antares/study/parts/hydro/test-hydroreader-class.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #define SEP "/" diff --git a/src/tests/src/solver/simulation/test-store-timeseries-number.cpp b/src/tests/src/solver/simulation/test-store-timeseries-number.cpp index 940a8b28fa..889f390b47 100644 --- a/src/tests/src/solver/simulation/test-store-timeseries-number.cpp +++ b/src/tests/src/solver/simulation/test-store-timeseries-number.cpp @@ -11,7 +11,7 @@ #include #include "timeseries-numbers.h" #include "BindingConstraintsTimeSeriesNumbersWriter.h" -#include "utils.h" +#include #include #include #include diff --git a/src/tests/src/solver/simulation/test-time_series.cpp b/src/tests/src/solver/simulation/test-time_series.cpp index 00357c5299..897ab37ee1 100644 --- a/src/tests/src/solver/simulation/test-time_series.cpp +++ b/src/tests/src/solver/simulation/test-time_series.cpp @@ -9,7 +9,7 @@ #include #include #include -#include "utils.h" +#include using namespace Antares::Solver; using namespace Antares::Data; diff --git a/src/tests/src/utils/CMakeLists.txt b/src/tests/src/utils/CMakeLists.txt index bc7f9bc1d7..5e4781ad96 100644 --- a/src/tests/src/utils/CMakeLists.txt +++ b/src/tests/src/utils/CMakeLists.txt @@ -1,6 +1,6 @@ add_library(test_utils_unit - utils.cpp - utils.h + files-system.cpp + files-system.h ) target_include_directories( diff --git a/src/tests/src/utils/utils.cpp b/src/tests/src/utils/files-system.cpp similarity index 92% rename from src/tests/src/utils/utils.cpp rename to src/tests/src/utils/files-system.cpp index 9e2d5d1852..32eebb9dcb 100644 --- a/src/tests/src/utils/utils.cpp +++ b/src/tests/src/utils/files-system.cpp @@ -1,4 +1,4 @@ -#include "utils.h" +#include "files-system.h" namespace fs = std::filesystem; @@ -62,8 +62,8 @@ void removeFolder(stringT& path, stringT& folder_name) try { fs::remove_all(folder_path); - std::cout << "Folder '" + folder_name + "' at '" + folder_path.string() - + "' deleted.\n"; + std::cout << "Folder " + folder_name + " at " + folder_path.string() + + " deleted.\n"; } catch (const fs::filesystem_error& e) { diff --git a/src/tests/src/utils/utils.h b/src/tests/src/utils/files-system.h similarity index 100% rename from src/tests/src/utils/utils.h rename to src/tests/src/utils/files-system.h From 481c7a1fca47bd199ba13e5d35f68d5531223571 Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Mon, 16 Oct 2023 14:43:12 +0200 Subject: [PATCH 37/40] Get function instead of class data member --- src/solver/simulation/timeseries-numbers.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/solver/simulation/timeseries-numbers.cpp b/src/solver/simulation/timeseries-numbers.cpp index 26ab49a11a..3008f57d09 100644 --- a/src/solver/simulation/timeseries-numbers.cpp +++ b/src/solver/simulation/timeseries-numbers.cpp @@ -688,7 +688,7 @@ void drawAndStoreTSnumbersForNOTintraModal(const array& i if (!isTSintramodal[indexTS]) { - uint nbTimeSeries = area.hydro.series->maxHourlyGenPower.width; + uint nbTimeSeries = area.hydro.series->getNbTimeSeriesSup(); if (nbTimeSeries != 1) { area.hydro.series->timeseriesNumbersHydroMaxPower[0][year] = static_cast( From ee5b88c1d25c5e85dd0dbd2f2ebe11bc14d4645f Mon Sep 17 00:00:00 2001 From: guilpier-code <62292552+guilpier-code@users.noreply.github.com> Date: Thu, 26 Oct 2023 20:23:06 +0200 Subject: [PATCH 38/40] Refactor hydro max power TS consistency (#1707) * Refactor max power TS checks : several things (see commit message) This commit is large, it should be shorter, but the long compilation time forces to gather the devs in one piece. - Remove the exception raising, not necessary : the gotFatalError (set to true) will trigger an exception anyway. - class NbTsComparer : is generalized to any time series pair : + to isolate it from business context + to have a chance to re-use it in another context - Move both classes NbTsComparer and TsActions outside class DataSeriesHydro, for same reasons as above - Rename TsActions::handleBothGreaterThanOne (unclear) into something more meaningful - Consequences of previous changes in tests * Refactor max power TS checks : several things (see commit message) TsActions::areaToInvalidate : - Remove areaToInvalidate from class TsActions (it has nothing to do in here) and make it a free function - Extract areaToInvalidate calls from TsActions::resizeWhenOneTS, as calling it here not related to TsActions * Refactor max power TS checks : simplify TsActions::resizeWhenOneTS * Refactor max power TS checks : remove a useless argument to free function invalidateArea * Refactor max power TS checks : changing invalidateArea's signature and content In this context, pointer area (as argument) is necessarily not null, because it is used way before we come to this point. So : - We make area a reference - We stop testing the area address (we known it's not null) - We remove the dead code (when area address is null) * Refactor max power TS checks : several things (see commit message) - Move class NumberComparison to separate source files - Remove return type to function postProcessMaxPowerTS : no more boolean returned, but void. Returning boolean is for loading tasks, here we check and possibly change already loaded data. We adapt tests, as a consequence - Removing class TsActions, not useful - * Refactor max power TS checks : add forgotten files + renaming * Refactor max power TS checks : remove case where both TS matrices (pump + gen) have null width, impossible * Refactor max power TS checks : just removing useless comments * Refactor max power TS checks : a bot of cleaning * Refactor max power TS checks : internalize count of generation time series (ror, storage, mingen) We should not be able to change a TS count without resizing the TS. This was allowed when because this count was a public data member. So we make it a private data member, and change it only when resizing the associated data. * Refactor max power TS checks : renaming * Refactor max power TS checks : renaming * Refactor max power TS checks : adapt CI Window workflow to new runner (about python) * Refactor max power TS checks : define and use of function EqualizeTSsize(...) * Refactor max power TS checks : rearrange DataSeriesHydro::loadFromFolder, but no major change * Refactor max power TS checks : remove the case where TS (ror, storage, mingen) have a zero size. Impossible case. * Refactor max power TS checks : fix bugs on function EqualizeTSsize * Refactor max power TS checks : use maxPowerTScount() whenever possible * Refactor max power TS checks : removing the setter for max power TS number * Refactor max power TS checks : fix a bug due to removing the setter for max power TS number * Refactor max power TS checks : gather loading and equalizing hydro mingen TS * Refactor max power TS checks : split load of ROR, STORAGE and MINGEN * Refactor max power TS checks : loading Max Power TS : using a generic loading function * Refactor max power TS checks : fix a bug on loading inflows (height ont correct) * Refactor max power TS checks : correction after (small) merge * Refactor max power TS checks : fixing bug on loading inflows was wrong. Fixing it for real now. * Refactor max power TS checks : remove useless checkMinGenTsNumber * Refactor max power TS checks : cleaning on the very ugly setHydroModulability (too many args, body too big) * Refactor max power TS checks : correct derated mode for hydro * Refactor max power TS checks : some more corrections due to review * Refactor max power TS checks : some more corrections after review * Refactor max power TS checks : fixing errors introduced by earlier corrections * Refactor max power TS checks : more corrections after review * Refactor max power TS checks : more corrections due to tight review :-) * Fixing sonar bug * Code smells * Use init-statement inside the if statement for hydroSeries ptr * More code smells --------- Co-authored-by: NikolaIlic --- .github/workflows/windows-vcpkg.yml | 4 +- src/libs/antares/study/CMakeLists.txt | 2 + src/libs/antares/study/area/list.cpp | 53 ++- src/libs/antares/study/area/scratchpad.cpp | 2 +- .../parts/hydro/hydromaxtimeseriesreader.cpp | 46 +- .../parts/hydro/hydromaxtimeseriesreader.h | 18 - .../study/parts/hydro/pair-of-integers.cpp | 25 ++ .../study/parts/hydro/pair-of-integers.h | 18 + src/libs/antares/study/parts/hydro/series.cpp | 416 ++++++++---------- src/libs/antares/study/parts/hydro/series.h | 145 ++---- .../study/scenario-builder/applyToMatrix.hxx | 4 +- .../alea_tirage_au_sort_chroniques.cpp | 4 +- src/solver/simulation/timeseries-numbers.cpp | 14 +- src/solver/ts-generator/hydro.cpp | 6 +- .../test_unfeasible_problem.py | 1 - .../study/parts/hydro/test-hydro-series.cpp | 50 ++- .../test-sc-builder-file-read-line.cpp | 12 +- .../test-sc-builder-file-save.cpp | 15 +- .../handler/antares-study/area/timeseries.cpp | 20 +- 19 files changed, 359 insertions(+), 496 deletions(-) create mode 100644 src/libs/antares/study/parts/hydro/pair-of-integers.cpp create mode 100644 src/libs/antares/study/parts/hydro/pair-of-integers.h diff --git a/.github/workflows/windows-vcpkg.yml b/.github/workflows/windows-vcpkg.yml index 3a9bc71d65..e54c221cdb 100644 --- a/.github/workflows/windows-vcpkg.yml +++ b/.github/workflows/windows-vcpkg.yml @@ -85,11 +85,11 @@ jobs: ortools-url: ${{env.ORTOOLS_URL}} ortools-dir: ${{env.ORTOOLS_DIR}} - - name: Setup Python 3.11 + - name: Setup Python 3.12 uses: actions/setup-python@v4 with: architecture: 'x64' - python-version: '3.11' + python-version: '3.12' - name: Install pip dependencies if necessary run: pip install -r src/tests/examples/requirements.txt diff --git a/src/libs/antares/study/CMakeLists.txt b/src/libs/antares/study/CMakeLists.txt index 5df50837d4..be95d2762b 100644 --- a/src/libs/antares/study/CMakeLists.txt +++ b/src/libs/antares/study/CMakeLists.txt @@ -139,6 +139,8 @@ set(SRC_STUDY_PART_HYDRO parts/hydro/allocation.cpp parts/hydro/hydromaxtimeseriesreader.h parts/hydro/hydromaxtimeseriesreader.cpp + parts/hydro/pair-of-integers.h + parts/hydro/pair-of-integers.cpp ) source_group("study\\part\\hydro" FILES ${SRC_STUDY_PART_HYDRO}) diff --git a/src/libs/antares/study/area/list.cpp b/src/libs/antares/study/area/list.cpp index 5c24b39fa1..dd1519eea4 100644 --- a/src/libs/antares/study/area/list.cpp +++ b/src/libs/antares/study/area/list.cpp @@ -901,33 +901,41 @@ static bool AreaListLoadFromFolderSingleArea(Study& study, buffer.clear() << study.folderInput << SEP << "hydro" << SEP << "prepro"; ret = area.hydro.prepro->loadFromFolder(study, area.id, buffer.c_str()) && ret; } - if (area.hydro.series && (!options.loadOnlyNeeded || !area.hydro.prepro)) // Series - { - buffer.clear() << study.folderInput << SEP << "hydro" << SEP << "series"; - ret = area.hydro.series->loadFromFolder(study, area.id, buffer) && ret; - } - if (area.hydro.series && study.header.version < 870) + if (auto* hydroSeries = area.hydro.series; hydroSeries) { - buffer.clear() << study.folderInput << SEP << "hydro"; + if (!options.loadOnlyNeeded || !area.hydro.prepro) // Series + { + buffer.clear() << study.folderInput << SEP << "hydro" << SEP << "series"; + ret = hydroSeries->loadGenerationTS(area.id, buffer, study.header.version) && ret; - HydroMaxTimeSeriesReader reader; - ret = reader(buffer, area, study.usedByTheSolver) && ret; - } + hydroSeries->EqualizeGenerationTSsizes( + area, study.usedByTheSolver, study.gotFatalError); + } - if (area.hydro.series && study.header.version >= 870) - { - buffer.clear() << study.folderInput << SEP << "hydro" << SEP << "series"; - ret = area.hydro.series->LoadMaxPower(area.id, buffer) && ret; + if (study.header.version < 870) + { + buffer.clear() << study.folderInput << SEP << "hydro"; - if (study.usedByTheSolver) + HydroMaxTimeSeriesReader reader; + ret = reader(buffer, area, study.usedByTheSolver) && ret; + } + + if (study.header.version >= 870) { - area.hydro.series->setNbTimeSeriesSup(); - ret = area.hydro.series->postProcessMaxPowerTS(area) && ret; - area.hydro.series->setMaxPowerTSWhenDeratedMode(study); + buffer.clear() << study.folderInput << SEP << "hydro" << SEP << "series"; + ret = hydroSeries->LoadMaxPower(area.id, buffer) && ret; + + if (study.usedByTheSolver) + { + hydroSeries->EqualizeMaxPowerTSsizes(area, study.gotFatalError); + } + else + hydroSeries->setHydroModulability(area); } - else - area.hydro.series->setHydroModulability(study, area.id); + + hydroSeries->resizeTSinDeratedMode( + study.parameters.derated, study.header.version, study.usedByTheSolver); } buffer.clear() << study.folderInput << SEP << "hydro" << SEP << "common" << SEP @@ -1641,10 +1649,7 @@ void AreaList::removeLoadTimeseries() void AreaList::removeHydroTimeseries() { each([&](Data::Area& area) { - area.hydro.series->ror.reset(1, HOURS_PER_YEAR); - area.hydro.series->storage.reset(1, DAYS_PER_YEAR); - area.hydro.series->mingen.reset(1, HOURS_PER_YEAR); - area.hydro.series->count = 1; + area.hydro.series->reset(); }); } diff --git a/src/libs/antares/study/area/scratchpad.cpp b/src/libs/antares/study/area/scratchpad.cpp index 747f4d078c..5c1dd5e806 100644 --- a/src/libs/antares/study/area/scratchpad.cpp +++ b/src/libs/antares/study/area/scratchpad.cpp @@ -78,7 +78,7 @@ AreaScratchpad::AreaScratchpad(const StudyRuntimeInfos& rinfos, Area& area) : ts // Hourly maximum generation/pumping power matrices and their number of TS's (width of matrices) auto const& maxHourlyGenPower = area.hydro.series->maxHourlyGenPower; auto const& maxHourlyPumpPower = area.hydro.series->maxHourlyPumpPower; - uint nbOfMaxPowerTimeSeries = area.hydro.series->getNbTimeSeriesSup(); + uint nbOfMaxPowerTimeSeries = area.hydro.series->maxPowerTScount(); // Setting width and height of daily mean maximum generation/pumping power matrices meanMaxDailyGenPower.reset(nbOfMaxPowerTimeSeries, DAYS_PER_YEAR); diff --git a/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.cpp b/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.cpp index 96f91d262d..ab2c60f6ae 100644 --- a/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.cpp +++ b/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.cpp @@ -122,59 +122,15 @@ void HydroMaxTimeSeriesReader::copyDailyMaxPumpingEnergy(Area& area) const maxDailyPumpEnergy.pasteToColumn(0, dailyMaxPumpE); } -void HydroMaxTimeSeriesReader::copyDailyMaxPowerAsHourly(Area& area) const -{ - copyDailyMaxGenPowerAsHourly(area); - copyDailyMaxPumpPowerAsHourly(area); - area.hydro.series->setNbTimeSeriesSup(); -} - -void HydroMaxTimeSeriesReader::copyDailyMaxGenPowerAsHourly(Area& area) const -{ - auto& maxHourlyGenPower = area.hydro.series->maxHourlyGenPower; - const auto& dailyMaxGenP = dailyMaxPumpAndGen[genMaxP]; - - maxHourlyGenPower.reset(1U, HOURS_PER_YEAR); - - copyDailyTsAsHourly(maxHourlyGenPower[0], dailyMaxGenP); -} - -void HydroMaxTimeSeriesReader::copyDailyMaxPumpPowerAsHourly(Area& area) const -{ - auto& maxHourlyPumpPower = area.hydro.series->maxHourlyPumpPower; - const auto& dailyMaxPumpP = dailyMaxPumpAndGen[pumpMaxP]; - - maxHourlyPumpPower.reset(1U, HOURS_PER_YEAR); - - copyDailyTsAsHourly(maxHourlyPumpPower[0], dailyMaxPumpP); -} - bool HydroMaxTimeSeriesReader::operator()(const AnyString& folder, Area& area, bool usedBySolver) { bool ret = true; ret = loadDailyMaxPowersAndEnergies(folder, area, usedBySolver) && ret; copyDailyMaxEnergy(area); - copyDailyMaxPowerAsHourly(area); + area.hydro.series->buildMaxPowerFromDailyTS(dailyMaxPumpAndGen[genMaxP], dailyMaxPumpAndGen[pumpMaxP]); return ret; } -void copyDailyTsAsHourly(Matrix::ColumnType& hourlyColumn, - const Matrix::ColumnType& dailyColumn) -{ - uint hour = 0; - uint day = 0; - - while (hour < HOURS_PER_YEAR && day < DAYS_PER_YEAR) - { - for (uint i = 0; i < HOURS_PER_DAY; ++i) - { - hourlyColumn[hour] = dailyColumn[day]; - ++hour; - } - ++day; - } -} - } // namespace Antares::Data \ No newline at end of file diff --git a/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.h b/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.h index fe526d033c..fefb4ef239 100644 --- a/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.h +++ b/src/libs/antares/study/parts/hydro/hydromaxtimeseriesreader.h @@ -77,25 +77,7 @@ class HydroMaxTimeSeriesReader void copyDailyMaxEnergy(Area& area) const; void copyDailyMaxGenerationEnergy(Area& area) const; void copyDailyMaxPumpingEnergy(Area& area) const; - - /** - * \brief Copy power functions - * These functions provides coping of power data loaded - * from deprecated file. - */ - void copyDailyMaxPowerAsHourly(Area& area) const; - void copyDailyMaxGenPowerAsHourly(Area& area) const; - void copyDailyMaxPumpPowerAsHourly(Area& area) const; }; - -/** - * \brief Copy raw data - * This function provides coping raw data from daily resolution - * column and pasting data into hourly resolution column. - */ -void copyDailyTsAsHourly(Matrix::ColumnType& hourlyColumn, - const Matrix::ColumnType& dailyColumn); - } // namespace Antares::Data #endif /*__ANTARES_LIBS_STUDY_PARTS_HYDRO_MAX_TIME_SERIES_READER_H__*/ \ No newline at end of file diff --git a/src/libs/antares/study/parts/hydro/pair-of-integers.cpp b/src/libs/antares/study/parts/hydro/pair-of-integers.cpp new file mode 100644 index 0000000000..1332469837 --- /dev/null +++ b/src/libs/antares/study/parts/hydro/pair-of-integers.cpp @@ -0,0 +1,25 @@ +#include "pair-of-integers.h" +#include + + +PairOfIntegers::PairOfIntegers(unsigned int numberOfTS_1, unsigned int numberOfTS_2) + : numberOfTS_1_(numberOfTS_1), numberOfTS_2_(numberOfTS_2) +{ + numberOfTSsup_ = std::max(numberOfTS_1_, numberOfTS_2_); + numberOfTSinf_ = std::min(numberOfTS_1_, numberOfTS_2_); +} + +bool PairOfIntegers::bothZero() const +{ + return numberOfTSsup_ == 0; +} + +bool PairOfIntegers::same() const +{ + return (numberOfTS_1_ == numberOfTS_2_) ? true : false; +} + +bool PairOfIntegers::bothGreaterThanOne() const +{ + return (numberOfTSinf_ > 1); +} \ No newline at end of file diff --git a/src/libs/antares/study/parts/hydro/pair-of-integers.h b/src/libs/antares/study/parts/hydro/pair-of-integers.h new file mode 100644 index 0000000000..3c3ca0e839 --- /dev/null +++ b/src/libs/antares/study/parts/hydro/pair-of-integers.h @@ -0,0 +1,18 @@ +#pragma once + +class PairOfIntegers +{ +public: + PairOfIntegers(unsigned int numberOfTS_1, unsigned int numberOfTS_2); + + bool bothZero() const; + bool same() const; + bool bothGreaterThanOne() const; + unsigned int sup() const { return numberOfTSsup_; } + +private: + unsigned int numberOfTS_1_; + unsigned int numberOfTS_2_; + unsigned int numberOfTSsup_{ 0 }; + unsigned int numberOfTSinf_{ 0 }; +}; diff --git a/src/libs/antares/study/parts/hydro/series.cpp b/src/libs/antares/study/parts/hydro/series.cpp index 6fa07744eb..181aea472f 100644 --- a/src/libs/antares/study/parts/hydro/series.cpp +++ b/src/libs/antares/study/parts/hydro/series.cpp @@ -32,6 +32,8 @@ #include #include #include "../../study.h" +#include "pair-of-integers.h" +#include using namespace Yuni; @@ -41,7 +43,7 @@ namespace Antares { namespace Data { -DataSeriesHydro::DataSeriesHydro() : count(0) +DataSeriesHydro::DataSeriesHydro() { // Pmin was introduced in v8.6 // The previous behavior was Pmin=0 @@ -52,6 +54,69 @@ DataSeriesHydro::DataSeriesHydro() : count(0) maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); } +unsigned int EqualizeTSsize(Matrix& TScollection1, + Matrix& TScollection2, + bool& fatalError, + const std::string& fatalErrorMsg, + Area& area, + unsigned int height1 = HOURS_PER_YEAR, + unsigned int height2 = HOURS_PER_YEAR) +{ + PairOfIntegers pairOfTSsizes(TScollection1.width, TScollection2.width); + + if (pairOfTSsizes.bothZero()) + { + TScollection1.reset(1, height1); + TScollection2.reset(1, height2); + return 1; + } + + if (pairOfTSsizes.same()) + return pairOfTSsizes.sup(); + + if (pairOfTSsizes.bothGreaterThanOne()) + { + logs.fatal() << fatalErrorMsg; + fatalError = true; + return 0; + } + + // At this point, one TS collection size is > 1 and the other is of size 1. + + // This following instruction to force reloading all area's TS when saving the study (GUI) + area.invalidateJIT = true; + + if (TScollection1.width == 1) + resizeMatrixNoDataLoss(TScollection1, pairOfTSsizes.sup()); + if (TScollection2.width == 1) + resizeMatrixNoDataLoss(TScollection2, pairOfTSsizes.sup()); + + return pairOfTSsizes.sup(); +} + +void DataSeriesHydro::copyGenerationTS(const DataSeriesHydro& source) +{ + ror = source.ror; + storage = source.storage; + mingen = source.mingen; + + generationTScount_ = source.generationTScount_; + + source.ror.unloadFromMemory(); + source.storage.unloadFromMemory(); + source.mingen.unloadFromMemory(); +} +void DataSeriesHydro::copyMaxPowerTS(const DataSeriesHydro& source) +{ + maxHourlyGenPower = source.maxHourlyGenPower; + maxHourlyPumpPower = source.maxHourlyPumpPower; + + maxPowerTScount_ = source.maxPowerTScount_; + + source.maxHourlyGenPower.unloadFromMemory(); + source.maxHourlyPumpPower.unloadFromMemory(); +} + bool DataSeriesHydro::saveToFolder(const AreaName& areaID, const AnyString& folder) const { String buffer; @@ -77,128 +142,100 @@ bool DataSeriesHydro::saveToFolder(const AreaName& areaID, const AnyString& fold return false; } -bool DataSeriesHydro::loadFromFolder(Study& study, const AreaName& areaID, const AnyString& folder) + +bool loadTSfromFile(Matrix& ts, + const AreaName& areaID, + const AnyString& folder, + const std::string& filename, + unsigned int height) { - bool ret = true; - auto& buffer = study.bufferLoadingTS; + YString filePath; + Matrix<>::BufferType fileContent; + filePath.clear() << folder << SEP << areaID << SEP << filename; + return ts.loadFromCSVFile(filePath, 1, height, &fileContent); +} - buffer.clear() << folder << SEP << areaID << SEP << "ror." << study.inputExtension; +bool DataSeriesHydro::loadGenerationTS(const AreaName& areaID, const AnyString& folder, unsigned int studyVersion) +{ + timeseriesNumbers.clear(); - ret = ror.loadFromCSVFile(buffer, 1, HOURS_PER_YEAR, &study.dataBuffer) && ret; + bool ret = loadTSfromFile(ror, areaID, folder, "ror.txt", HOURS_PER_YEAR); + ret = loadTSfromFile(storage, areaID, folder, "mod.txt", DAYS_PER_YEAR) && ret; + if (studyVersion >= 860) + ret = loadTSfromFile(mingen, areaID, folder, "mingen.txt", HOURS_PER_YEAR) && ret; + return ret; +} - buffer.clear() << folder << SEP << areaID << SEP << "mod." << study.inputExtension; - ret = storage.loadFromCSVFile(buffer, 1, DAYS_PER_YEAR, &study.dataBuffer) && ret; +void DataSeriesHydro::EqualizeGenerationTSsizes(Area& area, bool usedByTheSolver, bool& fatalError) +{ + if (!usedByTheSolver) // From GUI, no need to equalize TS collections sizes + return; - // The number of time-series - count = storage.width; + // Equalize ROR and INFLOWS time series sizes + // ------------------------------------------ + std::string fatalErrorMsg = "Hydro : area `" + area.id.to() + "` : "; + fatalErrorMsg += "ROR and INFLOWS must have the same number of time series."; - if (ror.width > count) - count = ror.width; + generationTScount_ = EqualizeTSsize(ror, storage, fatalError, fatalErrorMsg, area, HOURS_PER_YEAR, DAYS_PER_YEAR); - if (study.header.version >= 860) - { - buffer.clear() << folder << SEP << areaID << SEP << "mingen." << study.inputExtension; - ret = mingen.loadFromCSVFile(buffer, 1, HOURS_PER_YEAR, &study.dataBuffer) && ret; - } + logs.info() << " '" << area.id << "': ROR and INFLOWS time series were both set to : " << generationTScount_; - if (study.usedByTheSolver) - { - if (0 == count) - { - logs.error() << "Hydro: `" << areaID - << "`: empty matrix detected. Fixing it with default values"; - ror.reset(1, HOURS_PER_YEAR); - storage.reset(1, DAYS_PER_YEAR); - mingen.reset(1, HOURS_PER_YEAR); - } - else - { - if (count > 1 && storage.width != ror.width) - { - if (ror.width != 1 && storage.width != 1) - { - logs.fatal() << "Hydro: `" << areaID - << "`: The matrices ROR (run-of-the-river) and hydro-storage must " - "have the same number of time-series."; - study.gotFatalError = true; - } - else - { - if (ror.width == 1) - { - ror.resizeWithoutDataLost(count, ror.height); - for (uint x = 1; x < count; ++x) - ror.pasteToColumn(x, ror[0]); - } - else - { - if (storage.width == 1) - { - storage.resizeWithoutDataLost(count, storage.height); - for (uint x = 1; x < count; ++x) - storage.pasteToColumn(x, storage[0]); - } - } - Area* areaToInvalidate = study.areas.find(areaID); - if (areaToInvalidate) - { - areaToInvalidate->invalidateJIT = true; - logs.info() - << " '" << areaID << "': The hydro data have been normalized to " - << count << " timeseries"; - } - else - logs.error() - << "Impossible to find the area `" << areaID << "` to invalidate it"; - } - } - checkMinGenTsNumber(study, areaID); - } + // Equalize ROR and MINGEN time series sizes + // ----------------------------------------- + fatalErrorMsg = "Hydro : area `" + area.id.to() + "` : "; + fatalErrorMsg += "ROR and MINGEN must have the same number of time series."; - if (study.parameters.derated) - { - ror.averageTimeseries(); - storage.averageTimeseries(); - mingen.averageTimeseries(); - count = 1; - } - } + generationTScount_ = EqualizeTSsize(ror, mingen, fatalError, fatalErrorMsg, area); - timeseriesNumbers.clear(); + logs.info() << " '" << area.id << "': ROR and MINGEN time series were both set to : " << generationTScount_; +} + +bool DataSeriesHydro::LoadMaxPower(const AreaName& areaID, const AnyString& folder) +{ + bool ret = true; + YString filepath; + Matrix<>::BufferType fileContent; + + filepath.clear() << folder << SEP << areaID << SEP << "maxHourlyGenPower.txt"; + ret = maxHourlyGenPower.loadFromCSVFile(filepath, 1, HOURS_PER_YEAR, &fileContent) && ret; + + filepath.clear() << folder << SEP << areaID << SEP << "maxHourlyPumpPower.txt"; + ret = maxHourlyPumpPower.loadFromCSVFile(filepath, 1, HOURS_PER_YEAR, &fileContent) && ret; + + timeseriesNumbersHydroMaxPower.clear(); return ret; } -void DataSeriesHydro::checkMinGenTsNumber(Study& study, const AreaName& areaID) +void ConvertDailyTSintoHourlyTS(const Matrix::ColumnType& dailyColumn, + Matrix::ColumnType& hourlyColumn) { - if (mingen.width != storage.width) + uint hour = 0; + uint day = 0; + + while (hour < HOURS_PER_YEAR && day < DAYS_PER_YEAR) { - if (mingen.width > 1) - { - logs.fatal() << "Hydro: `" << areaID - << "`: The matrices Minimum Generation must " - "has the same number of time-series as ROR and hydro-storage."; - study.gotFatalError = true; - } - else + for (uint i = 0; i < HOURS_PER_DAY; ++i) { - mingen.resizeWithoutDataLost(count, mingen.height); - for (uint x = 1; x < count; ++x) - mingen.pasteToColumn(x, mingen[0]); - Area* areaToInvalidate = study.areas.find(areaID); - if (areaToInvalidate) - { - areaToInvalidate->invalidateJIT = true; - logs.info() << " '" << areaID - << "': The hydro minimum generation data have been normalized to " - << count << " timeseries"; - } - else - logs.error() << "Impossible to find the area `" << areaID << "` to invalidate it"; + hourlyColumn[hour] = dailyColumn[day]; + ++hour; } + ++day; } } +void DataSeriesHydro::buildMaxPowerFromDailyTS(const Matrix::ColumnType& DailyMaxGenPower, + const Matrix::ColumnType& DailyMaxPumpPower) +{ + maxPowerTScount_ = 1; + + maxHourlyGenPower.reset(maxPowerTScount_, HOURS_PER_YEAR); + maxHourlyPumpPower.reset(maxPowerTScount_, HOURS_PER_YEAR); + + ConvertDailyTSintoHourlyTS(DailyMaxGenPower, maxHourlyGenPower[0]); + ConvertDailyTSintoHourlyTS(DailyMaxPumpPower, maxHourlyPumpPower[0]); +} + bool DataSeriesHydro::forceReload(bool reload) const { bool ret = true; @@ -224,173 +261,88 @@ void DataSeriesHydro::reset() ror.reset(1, HOURS_PER_YEAR); storage.reset(1, DAYS_PER_YEAR); mingen.reset(1, HOURS_PER_YEAR); + generationTScount_ = 1; + maxHourlyGenPower.reset(1, HOURS_PER_YEAR); maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); - count = 1; - nbTimeSeriesSup_ = 1; -} - -uint64_t DataSeriesHydro::memoryUsage() const -{ - return sizeof(double) + ror.memoryUsage() + storage.memoryUsage() + mingen.memoryUsage() - + maxHourlyGenPower.memoryUsage() + maxHourlyPumpPower.memoryUsage(); + maxPowerTScount_ = 1; } -bool DataSeriesHydro::LoadMaxPower(const AreaName& areaID, const AnyString& folder) +void DataSeriesHydro::resizeRORandSTORAGE(unsigned int width) { - bool ret = true; - YString filepath; - Matrix<>::BufferType fileContent; - - filepath.clear() << folder << SEP << areaID << SEP << "maxHourlyGenPower" - << ".txt"; - ret = maxHourlyGenPower.loadFromCSVFile(filepath, 1, HOURS_PER_YEAR, &fileContent) && ret; - filepath.clear() << folder << SEP << areaID << SEP << "maxHourlyPumpPower" - << ".txt"; - ret = maxHourlyPumpPower.loadFromCSVFile(filepath, 1, HOURS_PER_YEAR, &fileContent) && ret; - - timeseriesNumbersHydroMaxPower.clear(); - - return ret; + ror.resize(width, HOURS_PER_YEAR); + storage.resize(width, DAYS_PER_YEAR); + generationTScount_ = width; } -bool DataSeriesHydro::postProcessMaxPowerTS(Area& area) +void DataSeriesHydro::resizeGenerationTS(unsigned int w, unsigned int h) { - NbTsComparer nbTSCompare(maxHourlyGenPower.width, maxHourlyPumpPower.width); - TsActions tsActions(maxHourlyGenPower, maxHourlyPumpPower); - // What will happen if one width is 0 and second one is 1 - // This case is not cover even in previous version - if (nbTSCompare.bothZeros()) - { - tsActions.handleBothZeros(area.id); - return false; - } - - if (nbTSCompare.same()) - return true; - - if (nbTSCompare.differentAndGreaterThanOne(nbTimeSeriesSup_)) - tsActions.handleBothGreaterThanOne(area.id); - - tsActions.resizeWhenOneTS(area, nbTimeSeriesSup_); - - return true; + ror.resize(w, h); + storage.resize(w, std::min((unsigned int)DAYS_PER_YEAR, h)); + mingen.resize(w, h); + generationTScount_ = w; } -void DataSeriesHydro::setHydroModulability(Study& study, const AreaName& areaID) const +void DataSeriesHydro::resizeMaxPowerTS(unsigned int w, unsigned int h) { - Area* area = study.areas.find(areaID); - - if (MatrixTestForAtLeastOnePositiveValue(maxHourlyGenPower)) - { - area->hydro.hydroModulable = true; - } + maxHourlyGenPower.reset(w, h); + maxHourlyPumpPower.reset(w, h); + maxPowerTScount_ = w; } -void DataSeriesHydro::setNbTimeSeriesSup(uint nbTimeSeriesSup) +uint64_t DataSeriesHydro::memoryUsage() const { - nbTimeSeriesSup_ = nbTimeSeriesSup; + return sizeof(double) + ror.memoryUsage() + storage.memoryUsage() + mingen.memoryUsage() + + maxHourlyGenPower.memoryUsage() + maxHourlyPumpPower.memoryUsage(); } -uint DataSeriesHydro::getNbTimeSeriesSup() const +void DataSeriesHydro::EqualizeMaxPowerTSsizes(Area& area, bool& fatalError) { - return nbTimeSeriesSup_; -} + std::string fatalErrorMsg = "Hydro Max Power: " + area.id.to() + " : "; + fatalErrorMsg += "generation and pumping must have the same number of TS."; -void DataSeriesHydro::setNbTimeSeriesSup() -{ - const auto& maxHourlyGenPower_ = maxHourlyGenPower.width; - const auto& maxHourlyPumpPower_ = maxHourlyPumpPower.width; + maxPowerTScount_ = EqualizeTSsize(maxHourlyGenPower, maxHourlyPumpPower, fatalError, fatalErrorMsg, area); - nbTimeSeriesSup_ - = (maxHourlyGenPower_ >= maxHourlyPumpPower_) ? maxHourlyGenPower_ : maxHourlyPumpPower_; + logs.info() << " '" << area.id << "': The number of hydro max power (generation and pumping) " + << "TS were both set to : " << maxPowerTScount_; } -void DataSeriesHydro::setMaxPowerTSWhenDeratedMode(const Study& study) +void DataSeriesHydro::setHydroModulability(Area& area) const { - if (study.parameters.derated) + if (MatrixTestForAtLeastOnePositiveValue(maxHourlyGenPower)) { - maxHourlyGenPower.averageTimeseries(); - maxHourlyPumpPower.averageTimeseries(); - nbTimeSeriesSup_ = 1; + area.hydro.hydroModulable = true; } } -DataSeriesHydro::NbTsComparer::NbTsComparer(uint32_t nbOfGenPowerTs, uint32_t nbOfPumpPowerTs) : - nbOfGenPowerTs_(nbOfGenPowerTs), nbOfPumpPowerTs_(nbOfPumpPowerTs) -{ -} - -bool DataSeriesHydro::NbTsComparer::bothZeros() const -{ - return (nbOfGenPowerTs_ || nbOfPumpPowerTs_) ? false : true; -} - -bool DataSeriesHydro::NbTsComparer::same() const -{ - return (nbOfGenPowerTs_ == nbOfPumpPowerTs_) ? true : false; -} - -bool DataSeriesHydro::NbTsComparer::differentAndGreaterThanOne(uint nbTimeSeriesSup) const -{ - return (nbTimeSeriesSup > 1 && (nbOfGenPowerTs_ != 1) && (nbOfPumpPowerTs_ != 1)) ? true - : false; -} - -DataSeriesHydro::TsActions::TsActions(Matrix& maxHourlyGenPower, - Matrix& maxHourlyPumpPower) : - maxHourlyGenPower_(maxHourlyGenPower), maxHourlyPumpPower_(maxHourlyPumpPower) +uint DataSeriesHydro::maxPowerTScount() const { + return maxPowerTScount_; } -void DataSeriesHydro::TsActions::handleBothZeros(const AreaName& areaID) +void DataSeriesHydro::resizeTSinDeratedMode(bool derated, + unsigned int studyVersion, + bool usedBySolver) { - logs.error() << "Hydro Max Power: `" << areaID - << "`: empty matrix detected. Fixing it with default values"; - - maxHourlyGenPower_.reset(1, HOURS_PER_YEAR); - maxHourlyPumpPower_.reset(1, HOURS_PER_YEAR); -} - -[[noreturn]] void DataSeriesHydro::TsActions::handleBothGreaterThanOne(const AreaName& areaID) const -{ - logs.fatal() << "Hydro Max Power: `" << areaID - << "`: The matrices Maximum Generation and Maximum Pumping must " - "have the same number of time-series."; - throw Error::ReadingStudy(); -} - -void DataSeriesHydro::TsActions::resizeWhenOneTS(Area& area, uint nbTimeSeriesSup) -{ - if (maxHourlyGenPower_.width == 1) - { - resizeMatrixNoDataLoss(maxHourlyGenPower_, nbTimeSeriesSup); - areaToInvalidate(&area, area.id, nbTimeSeriesSup); + if (!(derated && usedBySolver)) return; - } - if (maxHourlyPumpPower_.width == 1) - { - resizeMatrixNoDataLoss(maxHourlyPumpPower_, nbTimeSeriesSup); - areaToInvalidate(&area, area.id, nbTimeSeriesSup); - return; - } -} + ror.averageTimeseries(); + storage.averageTimeseries(); + if (studyVersion >= 860) + mingen.averageTimeseries(); + generationTScount_ = 1; -void DataSeriesHydro::TsActions::areaToInvalidate(Area* area, - const AreaName& areaID, - uint nbTimeSeriesSup) const -{ - if (area) + if (studyVersion >= 870) { - area->invalidateJIT = true; - logs.info() << " '" << area->id << "': The hydro max power data have been normalized to " - << nbTimeSeriesSup << " timeseries"; + maxHourlyGenPower.averageTimeseries(); + maxHourlyPumpPower.averageTimeseries(); + maxPowerTScount_ = 1; } - else - logs.error() << "Impossible to find the area `" << areaID << "` to invalidate it"; } +// TODO : this function should not be here, as it applies to +// any time series, not just hydro TS. void resizeMatrixNoDataLoss(Matrix& matrixToResize, uint width) { matrixToResize.resizeWithoutDataLost(width, matrixToResize.height); diff --git a/src/libs/antares/study/parts/hydro/series.h b/src/libs/antares/study/parts/hydro/series.h index d3dd7b50b9..b55b105708 100644 --- a/src/libs/antares/study/parts/hydro/series.h +++ b/src/libs/antares/study/parts/hydro/series.h @@ -31,10 +31,12 @@ #include "../../fwd.h" #include + namespace Antares { namespace Data { + /*! ** \brief Data series (Hydro) */ @@ -49,6 +51,9 @@ class DataSeriesHydro DataSeriesHydro(); //@} + void copyGenerationTS(const DataSeriesHydro& source); + void copyMaxPowerTS(const DataSeriesHydro& source); + //! \name Data //@{ /*! @@ -56,6 +61,10 @@ class DataSeriesHydro */ void reset(); + void resizeRORandSTORAGE(unsigned int width); + void resizeGenerationTS(unsigned int w, unsigned int h); + void resizeMaxPowerTS(unsigned int w, unsigned int h); + /*! ** \brief Load all data not already loaded ** @@ -66,16 +75,17 @@ class DataSeriesHydro void markAsModified() const; //@} - //! \name Save / Load - //@{ - /*! - ** \brief Load data series for hydro from a folder - ** - ** \param d The data series for hydro - ** \param folder The source folder - ** \return A non-zero value if the operation succeeded, 0 otherwise - */ - bool loadFromFolder(Study& s, const AreaName& areaID, const AnyString& folder); + void EqualizeGenerationTSsizes(Area& area, bool usedByTheSolver, bool& fatalError); + + // Loading hydro time series collection + // Returned boolean : reading from file failed + bool loadGenerationTS(const AreaName& areaID, const AnyString& folder, unsigned int studyVersion); + + // Loading hydro max generation and mqx pumping TS's + bool LoadMaxPower(const AreaName& areaID, const AnyString& folder); + + void buildMaxPowerFromDailyTS(const Matrix::ColumnType& DailyMaxGenPower, + const Matrix::ColumnType& DailyMaxPumpPower); /*! ** \brief Save data series for hydro into a folder (`input/hydro/series`) @@ -101,11 +111,6 @@ class DataSeriesHydro //@} - /*! - ** \brief Check TS number for Minimum Generation and logs error if necessary - */ - void checkMinGenTsNumber(Study& s, const AreaName& areaID); - public: /*! ** \brief Run-of-the-river - ROR (MW) @@ -144,108 +149,34 @@ class DataSeriesHydro */ Matrix maxHourlyPumpPower; - /*! - ** \brief The number of time-series - ** - ** This value must be the same as the width of the matrices `mod` and `fatal`. - ** It is only provided for convenience to avoid same strange and ambiguous code - ** (for example using `fatal.width` and `mod.width` in the same routine, it might - ** indicate that the two values are not strictly equal) - */ - uint count; + unsigned int TScount() const { return generationTScount_; }; public: - /*! - ** \brief Monte-Carlo - */ Matrix timeseriesNumbers; Matrix timeseriesNumbersHydroMaxPower; - /** - * \brief Loading hydro maximum generation and pumping TS's - */ - bool LoadMaxPower(const AreaName& areaID, const AnyString& folder); - - /** - * \brief Post processing numbers of TS's - * Checking whether or not TS's numbers are different - * and taking proper action based on corresponding check - */ - bool postProcessMaxPowerTS(Area& area); - - void setHydroModulability(Study& study, const AreaName& areaID) const; - - /** - * \brief Setting TS's number of maximum generation and pumping matrices - */ - void setNbTimeSeriesSup(uint nbTimeSeriesSup); + // Equalizing max generation and max pumping numbers of TS's + void EqualizeMaxPowerTSsizes(Area& area, bool& fatalError); - /** - * \brief Setting TS's number of maximum generation and pumping matrices - */ - void setNbTimeSeriesSup(); + void setHydroModulability(Area& area) const; - /** - * \brief Get function for TS's number of maximum generation and pumping matrices - */ - uint getNbTimeSeriesSup() const; + // Get max power (generatoin and pumping) number of TS + uint maxPowerTScount() const; - /** - * \brief Setting TS's when derated mode is on - */ - void setMaxPowerTSWhenDeratedMode(const Study& study); + // Setting TS's when derated mode is on + void resizeTSinDeratedMode(bool derated, unsigned int studyVersion, bool useBySolver); private: - /*! - ** \brief The number of time-series for maxHourlyGenPower and maxHourlyPumpPower matrices - ** - ** This value must be the same as the width of the matrices `maxHourlyGenPower` and - *`maxHourlyPumpPower`. - ** It is only provided for convenience to avoid same strange and ambiguous code - ** (for example using `maxHourlyGenPower.width` and `maxHourlyPumpPower.width` in the same - *routine, it might - ** indicate that the two values are not strictly equal) - */ - uint nbTimeSeriesSup_ = 0; - - /** - * This class provides comparing two integers - * that represents width of two corresponding matrices. - */ - class NbTsComparer - { - public: - NbTsComparer(uint32_t nbOfGenPowerTs, uint32_t nbOfPumpPowerTs); - - bool bothZeros() const; - bool same() const; - bool differentAndGreaterThanOne(uint nbTimeSeriesSup) const; - - private: - uint32_t nbOfGenPowerTs_{0}; - uint32_t nbOfPumpPowerTs_{0}; - }; - - /** - * This class provides actions based on the return - * values of the NbTsComparer class member functions - */ - class TsActions - { - public: - TsActions(Matrix& maxHourlyGenPower, - Matrix& maxHourlyPumpPower); - - void handleBothZeros(const AreaName& areaID); - [[noreturn]] void handleBothGreaterThanOne(const AreaName& areaID) const; - void resizeWhenOneTS(Area& area, uint nbTimeSeriesSup); - - private: - Matrix& maxHourlyGenPower_; - Matrix& maxHourlyPumpPower_; - - void areaToInvalidate(Area* area, const AreaName& areaID, uint nbTimeSeriesSup) const; - }; + + // The number of time-series about generation (ror, inflows (=storage), mingen) + // They all should have the same number of columns (width), as they each year receives a common + // TS number for all three. + uint generationTScount_ = 0; + + // The number of time-series about max power (maxHourlyGenPower and maxHourlyPumpPower) + // They both should have the same number of columns (width), as they each year receives a common + // TS number for all three. + uint maxPowerTScount_ = 0; }; // class DataSeriesHydro diff --git a/src/libs/antares/study/scenario-builder/applyToMatrix.hxx b/src/libs/antares/study/scenario-builder/applyToMatrix.hxx index ade5b939b3..ac79bd9716 100644 --- a/src/libs/antares/study/scenario-builder/applyToMatrix.hxx +++ b/src/libs/antares/study/scenario-builder/applyToMatrix.hxx @@ -25,7 +25,7 @@ inline bool CheckValidity(uint value, uint tsGenMax) { // When the TS-Generators are not used - return (!tsGenMax) ? (value < data.count) : (value < tsGenMax); + return (!tsGenMax) ? (value < data.TScount()) : (value < tsGenMax); } template<> @@ -49,7 +49,7 @@ template static inline bool CheckValidityHydroMaxPower(uint value, const D& data, uint tsGenMax) { // TS Generator never used - return (!tsGenMax) ? (value < data.getNbTimeSeriesSup()) : (value < tsGenMax); + return (!tsGenMax) ? (value < data.maxPowerTScount()) : (value < tsGenMax); } template diff --git a/src/solver/aleatoire/alea_tirage_au_sort_chroniques.cpp b/src/solver/aleatoire/alea_tirage_au_sort_chroniques.cpp index 2783c84e33..287631518e 100644 --- a/src/solver/aleatoire/alea_tirage_au_sort_chroniques.cpp +++ b/src/solver/aleatoire/alea_tirage_au_sort_chroniques.cpp @@ -65,13 +65,13 @@ void ApplyRandomTSnumbers(const Study& study, assert(year < data.timeseriesNumbers.height); ptchro.Hydraulique - = (data.count != 1) ? (long)data.timeseriesNumbers[0][year] : 0; // zero-based + = (data.TScount() != 1) ? (long)data.timeseriesNumbers[0][year] : 0; // zero-based } // Hydro Max Power { const Data::DataSeriesHydro& data = *area.hydro.series; assert(year < data.timeseriesNumbersHydroMaxPower.height); - ptchro.HydroMaxPower = (data.getNbTimeSeriesSup() != 1) + ptchro.HydroMaxPower = (data.maxPowerTScount() != 1) ? (data.timeseriesNumbersHydroMaxPower[0][year]) : 0; // zero-based } diff --git a/src/solver/simulation/timeseries-numbers.cpp b/src/solver/simulation/timeseries-numbers.cpp index 3008f57d09..17cf9055e5 100644 --- a/src/solver/simulation/timeseries-numbers.cpp +++ b/src/solver/simulation/timeseries-numbers.cpp @@ -151,7 +151,7 @@ class hydroAreaNumberOfTSretriever : public areaNumberOfTSretriever } std::vector getAreaTimeSeriesNumber(const Area& area) { - std::vector to_return = {area.hydro.series->count}; + std::vector to_return = {area.hydro.series->TScount()}; return to_return; } uint getGeneratedTimeSeriesNumber() @@ -168,7 +168,7 @@ class hydroMaxPowerAreaNumberOfTSretriever : public areaNumberOfTSretriever } std::vector getAreaTimeSeriesNumber(const Area& area) override { - std::vector to_return = {area.hydro.series->getNbTimeSeriesSup()}; + std::vector to_return = {area.hydro.series->maxPowerTScount()}; return to_return; } uint getGeneratedTimeSeriesNumber() override @@ -444,7 +444,7 @@ bool checkInterModalConsistencyForArea(Area& area, if (isTSintermodal[indexTS]) { uint nbTimeSeries - = isTSgenerated[indexTS] ? parameters.nbTimeSeriesHydro : area.hydro.series->count; + = isTSgenerated[indexTS] ? parameters.nbTimeSeriesHydro : area.hydro.series->TScount(); listNumberTsOverArea.push_back(nbTimeSeries); } @@ -452,7 +452,7 @@ bool checkInterModalConsistencyForArea(Area& area, indexTS = ts_to_tsIndex.at(timeSeriesHydroMaxPower); if (isTSintermodal[indexTS]) { - uint nbTimeSeries = area.hydro.series->getNbTimeSeriesSup(); + uint nbTimeSeries = area.hydro.series->maxPowerTScount(); listNumberTsOverArea.push_back(nbTimeSeries); } @@ -688,7 +688,7 @@ void drawAndStoreTSnumbersForNOTintraModal(const array& i if (!isTSintramodal[indexTS]) { - uint nbTimeSeries = area.hydro.series->getNbTimeSeriesSup(); + uint nbTimeSeries = area.hydro.series->maxPowerTScount(); if (nbTimeSeries != 1) { area.hydro.series->timeseriesNumbersHydroMaxPower[0][year] = static_cast( @@ -894,10 +894,10 @@ static void fixTSNumbersWhenWidthIsOne(Study& study) area.wind.series->timeseriesNumbers, area.wind.series->timeSeries.width, years); // Hydro fixTSNumbersSingleAreaSingleMode( - area.hydro.series->timeseriesNumbers, area.hydro.series->count, years); + area.hydro.series->timeseriesNumbers, area.hydro.series->TScount(), years); // Hydro Max Power fixTSNumbersSingleAreaSingleMode( - area.hydro.series->timeseriesNumbersHydroMaxPower, area.hydro.series->getNbTimeSeriesSup(), years); + area.hydro.series->timeseriesNumbersHydroMaxPower, area.hydro.series->maxPowerTScount(), years); // Thermal std::for_each(area.thermal.clusters.cbegin(), diff --git a/src/solver/ts-generator/hydro.cpp b/src/solver/ts-generator/hydro.cpp index cb458bb4ad..1dfea0dfdc 100644 --- a/src/solver/ts-generator/hydro.cpp +++ b/src/solver/ts-generator/hydro.cpp @@ -50,11 +50,7 @@ namespace TSGenerator static void PreproHydroInitMatrices(Data::Study& study, uint tsCount) { study.areas.each([&](Data::Area& area) { - auto& hydroseries = *(area.hydro.series); - - hydroseries.ror.resize(tsCount, HOURS_PER_YEAR); - hydroseries.storage.resize(tsCount, DAYS_PER_YEAR); - hydroseries.count = tsCount; + area.hydro.series->resizeRORandSTORAGE(tsCount); }); } diff --git a/src/tests/run-study-tests/test_unfeasible_problem.py b/src/tests/run-study-tests/test_unfeasible_problem.py index 7ef0212061..4047907b21 100644 --- a/src/tests/run-study-tests/test_unfeasible_problem.py +++ b/src/tests/run-study-tests/test_unfeasible_problem.py @@ -65,4 +65,3 @@ def test_unfeasible_problem_01__warning_dry(study_path, check_runner): checks_on_weeks=warnings_on_weeks, simulation=check_runner.get_simulation())) check_runner.run(checks) - diff --git a/src/tests/src/libs/antares/study/parts/hydro/test-hydro-series.cpp b/src/tests/src/libs/antares/study/parts/hydro/test-hydro-series.cpp index ca1e7f6d7d..750cdf707d 100644 --- a/src/tests/src/libs/antares/study/parts/hydro/test-hydro-series.cpp +++ b/src/tests/src/libs/antares/study/parts/hydro/test-hydro-series.cpp @@ -93,6 +93,7 @@ BOOST_AUTO_TEST_SUITE(s) BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_matrices_equal_width, Fixture) { bool ret = true; + bool fatalError = false; auto& maxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower; auto& maxHourlyPumpPower = area_1->hydro.series->maxHourlyPumpPower; @@ -109,17 +110,21 @@ BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_matrices_equal_width, Fixture maxHourlyPumpPower.reset(3, HOURS_PER_YEAR); ret = area_1->hydro.series->LoadMaxPower(area_1->id, pathToSeriesFolder) && ret; - area_1->hydro.series->setNbTimeSeriesSup(); - ret = area_1->hydro.series->postProcessMaxPowerTS(*area_1) && ret; - BOOST_CHECK(ret); + + area_1->hydro.series->EqualizeMaxPowerTSsizes(*area_1, fatalError); + + BOOST_CHECK(!fatalError); BOOST_CHECK_EQUAL(maxHourlyGenPower.width, 3); } BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_both_matrix_equal_width_and_derated, Fixture) { bool ret = true; + bool fatalError = false; study->parameters.derated = true; + unsigned int studyVersion = 870; + bool usedBySolver = true; auto& maxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower; auto& maxHourlyPumpPower = area_1->hydro.series->maxHourlyPumpPower; @@ -136,17 +141,20 @@ BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_both_matrix_equal_width_and_d maxHourlyPumpPower.reset(3, HOURS_PER_YEAR); ret = area_1->hydro.series->LoadMaxPower(area_1->id, pathToSeriesFolder) && ret; - ret = area_1->hydro.series->postProcessMaxPowerTS(*area_1) && ret; - area_1->hydro.series->setMaxPowerTSWhenDeratedMode(*study); + BOOST_CHECK(ret); + + area_1->hydro.series->EqualizeMaxPowerTSsizes(*area_1, fatalError); + area_1->hydro.series->resizeTSinDeratedMode(study->parameters.derated, studyVersion, usedBySolver); BOOST_CHECK_EQUAL(maxHourlyGenPower.width, 1); BOOST_CHECK_EQUAL(maxHourlyPumpPower.width, 1); - BOOST_CHECK(ret); + BOOST_CHECK(!fatalError); } BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_matrices_different_width_case_2, Fixture) { bool ret = true; + bool fatalError = false; auto& maxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower; auto& maxHourlyPumpPower = area_1->hydro.series->maxHourlyPumpPower; @@ -163,15 +171,16 @@ BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_matrices_different_width_case maxHourlyPumpPower.reset(2, HOURS_PER_YEAR); ret = area_1->hydro.series->LoadMaxPower(area_1->id, pathToSeriesFolder) && ret; - area_1->hydro.series->setNbTimeSeriesSup(); - BOOST_CHECK(ret); - BOOST_CHECK_THROW(area_1->hydro.series->postProcessMaxPowerTS(*area_1), Error::ReadingStudy); + + area_1->hydro.series->EqualizeMaxPowerTSsizes(*area_1, fatalError); + BOOST_CHECK(fatalError); } BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_different_width_case_1, Fixture) { bool ret = true; + bool fatalError = false; auto& maxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower; auto& maxHourlyPumpPower = area_1->hydro.series->maxHourlyPumpPower; @@ -188,16 +197,18 @@ BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_different_width_case_1, Fixtu maxHourlyPumpPower.reset(3, HOURS_PER_YEAR); ret = area_1->hydro.series->LoadMaxPower(area_1->id, pathToSeriesFolder) && ret; - area_1->hydro.series->setNbTimeSeriesSup(); - ret = area_1->hydro.series->postProcessMaxPowerTS(*area_1) && ret; - BOOST_CHECK(ret); + + area_1->hydro.series->EqualizeMaxPowerTSsizes(*area_1, fatalError); + + BOOST_CHECK(!fatalError); BOOST_CHECK_EQUAL(maxHourlyGenPower.width, maxHourlyPumpPower.width); } BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_different_width_case_2, Fixture) { bool ret = true; + bool fatalError = false; auto& maxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower; auto& maxHourlyPumpPower = area_1->hydro.series->maxHourlyPumpPower; @@ -214,16 +225,18 @@ BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_different_width_case_2, Fixtu maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); ret = area_1->hydro.series->LoadMaxPower(area_1->id, pathToSeriesFolder) && ret; - area_1->hydro.series->setNbTimeSeriesSup(); - ret = area_1->hydro.series->postProcessMaxPowerTS(*area_1) && ret; - BOOST_CHECK(ret); + + area_1->hydro.series->EqualizeMaxPowerTSsizes(*area_1, fatalError); + + BOOST_CHECK(!fatalError); BOOST_CHECK_EQUAL(maxHourlyGenPower.width, maxHourlyPumpPower.width); } BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_both_zeros, Fixture) { bool ret = true; + bool fatalError = false; auto& maxHourlyGenPower = area_1->hydro.series->maxHourlyGenPower; auto& maxHourlyPumpPower = area_1->hydro.series->maxHourlyPumpPower; @@ -240,12 +253,13 @@ BOOST_FIXTURE_TEST_CASE(Testing_load_power_credits_both_zeros, Fixture) maxHourlyPumpPower.reset(1, HOURS_PER_YEAR); ret = area_1->hydro.series->LoadMaxPower(area_1->id, pathToSeriesFolder) && ret; - area_1->hydro.series->setNbTimeSeriesSup(); + BOOST_CHECK(ret); + maxHourlyGenPower.width = 0; maxHourlyPumpPower.width = 0; - ret = area_1->hydro.series->postProcessMaxPowerTS(*area_1) && ret; + area_1->hydro.series->EqualizeMaxPowerTSsizes(*area_1, fatalError); - BOOST_CHECK(!ret); + BOOST_CHECK(!fatalError); BOOST_CHECK_EQUAL(maxHourlyGenPower.width, maxHourlyPumpPower.width); } diff --git a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp index 38b0ab6102..d098cf3ca0 100644 --- a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp +++ b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp @@ -83,15 +83,15 @@ struct Fixture // Hydro : set the nb of ready made TS nbReadyMadeTS = 12; - area_1->hydro.series->count = nbReadyMadeTS; - area_2->hydro.series->count = nbReadyMadeTS; - area_3->hydro.series->count = nbReadyMadeTS; + area_1->hydro.series->resizeGenerationTS(nbReadyMadeTS, 1); + area_2->hydro.series->resizeGenerationTS(nbReadyMadeTS, 1); + area_3->hydro.series->resizeGenerationTS(nbReadyMadeTS, 1); // Hydro Max Power: set the nb of ready made TS nbReadyMadeTS = 15; - area_1->hydro.series->setNbTimeSeriesSup(nbReadyMadeTS); - area_2->hydro.series->setNbTimeSeriesSup(nbReadyMadeTS); - area_3->hydro.series->setNbTimeSeriesSup(nbReadyMadeTS); + area_1->hydro.series->resizeMaxPowerTS(nbReadyMadeTS, 1); + area_2->hydro.series->resizeMaxPowerTS(nbReadyMadeTS, 1); + area_3->hydro.series->resizeMaxPowerTS(nbReadyMadeTS, 1); // Links link_12 = AreaAddLinkBetweenAreas(area_1, area_2, false); diff --git a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp index 97df58e4a1..b2e26dd653 100644 --- a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp +++ b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp @@ -96,8 +96,7 @@ struct commonFixture study = std::make_shared(); // Set study parameters study->parameters.nbYears = 20; - study->parameters.timeSeriesToGenerate - = 0; // No generated time-series, only ready made time-series + study->parameters.timeSeriesToGenerate = 0; // No generated time-series, only ready made time-series // Add areas area_1 = study->areaAdd("Area 1"); @@ -125,15 +124,15 @@ struct commonFixture // Hydro : set the nb of ready made TS nbReadyMadeTS = 12; - area_1->hydro.series->count = nbReadyMadeTS; - area_2->hydro.series->count = nbReadyMadeTS; - area_3->hydro.series->count = nbReadyMadeTS; + area_1->hydro.series->resizeGenerationTS(nbReadyMadeTS, 1); + area_2->hydro.series->resizeGenerationTS(nbReadyMadeTS, 1); + area_3->hydro.series->resizeGenerationTS(nbReadyMadeTS, 1); // Hydro Max Power : set the nb of ready made TS nbReadyMadeTS = 15; - area_1->hydro.series->setNbTimeSeriesSup(nbReadyMadeTS); - area_2->hydro.series->setNbTimeSeriesSup(nbReadyMadeTS); - area_3->hydro.series->setNbTimeSeriesSup(nbReadyMadeTS); + area_1->hydro.series->resizeMaxPowerTS(nbReadyMadeTS, 1); + area_2->hydro.series->resizeMaxPowerTS(nbReadyMadeTS, 1); + area_3->hydro.series->resizeMaxPowerTS(nbReadyMadeTS, 1); // Links link_12 = AreaAddLinkBetweenAreas(area_1, area_2, false); diff --git a/src/ui/action/handler/antares-study/area/timeseries.cpp b/src/ui/action/handler/antares-study/area/timeseries.cpp index 9b0788a25b..a43bdc9577 100644 --- a/src/ui/action/handler/antares-study/area/timeseries.cpp +++ b/src/ui/action/handler/antares-study/area/timeseries.cpp @@ -161,28 +161,12 @@ bool DataTimeseries::performWL(Context& ctx) } case Data::timeSeriesHydro: { - ctx.area->hydro.series->ror = source->hydro.series->ror; - ctx.area->hydro.series->storage = source->hydro.series->storage; - ctx.area->hydro.series->mingen = source->hydro.series->mingen; - - ctx.area->hydro.series->count = source->hydro.series->count; - - source->hydro.series->ror.unloadFromMemory(); - source->hydro.series->storage.unloadFromMemory(); - source->hydro.series->mingen.unloadFromMemory(); - + ctx.area->hydro.series->copyGenerationTS(*source->hydro.series); break; } case Data::timeSeriesHydroMaxPower: { - ctx.area->hydro.series->maxHourlyGenPower = source->hydro.series->maxHourlyGenPower; - ctx.area->hydro.series->maxHourlyPumpPower = source->hydro.series->maxHourlyPumpPower; - - ctx.area->hydro.series->setNbTimeSeriesSup(source->hydro.series->getNbTimeSeriesSup()); - - source->hydro.series->maxHourlyGenPower.unloadFromMemory(); - source->hydro.series->maxHourlyPumpPower.unloadFromMemory(); - + ctx.area->hydro.series->copyMaxPowerTS(*source->hydro.series); break; } case Data::timeSeriesThermal: From 9e92840c5d8346d549e182ca7753e2bc0a681d1a Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Thu, 26 Oct 2023 20:25:11 +0200 Subject: [PATCH 39/40] Bugfix --- src/libs/antares/study/area/scratchpad.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/antares/study/area/scratchpad.cpp b/src/libs/antares/study/area/scratchpad.cpp index 5c1dd5e806..4233293ad4 100644 --- a/src/libs/antares/study/area/scratchpad.cpp +++ b/src/libs/antares/study/area/scratchpad.cpp @@ -185,7 +185,7 @@ void CalculateDailyMeanPower(const Matrix::ColumnType& hourlyColumn, dailyColumn[day] = std::accumulate(hourlyColumn + day * HOURS_PER_DAY, hourlyColumn + day * HOURS_PER_DAY + HOURS_PER_DAY, 0) - / HOURS_PER_DAY; + / 24.; } } From 65046a15503f21e8a9cc4cc634e1982ef632881f Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Thu, 26 Oct 2023 21:17:26 +0200 Subject: [PATCH 40/40] Code smells --- src/libs/antares/study/parts/hydro/series.cpp | 5 +++++ src/libs/antares/study/parts/hydro/series.h | 9 ++++----- src/solver/hydro/management/management.cpp | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/libs/antares/study/parts/hydro/series.cpp b/src/libs/antares/study/parts/hydro/series.cpp index 181aea472f..c94957f91d 100644 --- a/src/libs/antares/study/parts/hydro/series.cpp +++ b/src/libs/antares/study/parts/hydro/series.cpp @@ -315,6 +315,11 @@ void DataSeriesHydro::setHydroModulability(Area& area) const } } +uint DataSeriesHydro::TScount() const +{ + return generationTScount_; +} + uint DataSeriesHydro::maxPowerTScount() const { return maxPowerTScount_; diff --git a/src/libs/antares/study/parts/hydro/series.h b/src/libs/antares/study/parts/hydro/series.h index b55b105708..04ffa79550 100644 --- a/src/libs/antares/study/parts/hydro/series.h +++ b/src/libs/antares/study/parts/hydro/series.h @@ -111,7 +111,6 @@ class DataSeriesHydro //@} -public: /*! ** \brief Run-of-the-river - ROR (MW) ** @@ -149,9 +148,7 @@ class DataSeriesHydro */ Matrix maxHourlyPumpPower; - unsigned int TScount() const { return generationTScount_; }; - -public: + // TS's number matrices for Generation and Maximum Power Matrix timeseriesNumbers; Matrix timeseriesNumbersHydroMaxPower; @@ -160,7 +157,9 @@ class DataSeriesHydro void setHydroModulability(Area& area) const; - // Get max power (generatoin and pumping) number of TS + // Getters for generation (ror, storage and mingen) and + // max power (generation and pumping) number of TS + uint TScount() const; uint maxPowerTScount() const; // Setting TS's when derated mode is on diff --git a/src/solver/hydro/management/management.cpp b/src/solver/hydro/management/management.cpp index 9c77ac274a..b2a69f12b8 100644 --- a/src/solver/hydro/management/management.cpp +++ b/src/solver/hydro/management/management.cpp @@ -311,7 +311,7 @@ bool HydroManagement::checkGenerationPowerConsistency(uint numSpace) const bool ret = true; areas_.each( - [&numSpace, &ret](Data::Area& area) + [&numSpace, &ret](const Data::Area& area) { uint z = area.index; auto tsIndex = (uint)NumeroChroniquesTireesParPays[numSpace][z].Hydraulique;