From d8a8749d0823a4498a87deac19e52d3b06855cba Mon Sep 17 00:00:00 2001 From: Florian OMNES <26088210+flomnes@users.noreply.github.com> Date: Mon, 22 Jan 2024 17:09:07 +0100 Subject: [PATCH 1/4] Start CR23 in-memory tests --- .../end-to-end/simple_study/simple-study.cpp | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/tests/end-to-end/simple_study/simple-study.cpp b/src/tests/end-to-end/simple_study/simple-study.cpp index a36c3fe6ab..670057d411 100644 --- a/src/tests/end-to-end/simple_study/simple-study.cpp +++ b/src/tests/end-to-end/simple_study/simple-study.cpp @@ -247,3 +247,39 @@ BOOST_AUTO_TEST_CASE(error_on_wrong_hydro_data) BOOST_CHECK_THROW(simulation->run(), Antares::FatalError); } BOOST_AUTO_TEST_SUITE_END() + + +BOOST_AUTO_TEST_SUITE(hydro_hourly_max_power) +BOOST_AUTO_TEST_CASE(basic) +{ + StudyBuilder builder; + builder.simulationBetweenDays(0, 7); + builder.setNumberMCyears(1); + Area& area = *builder.addAreaToStudy("A"); + + area.thermal.unsuppliedEnergyCost = 1; + + PartHydro& hydro = area.hydro; + TimeSeriesConfigurer genP(hydro.series->maxHourlyGenPower.timeSeries); + genP.setColumnCount(1) + .fillColumnWith(0, 12); + + // 10000MW hourly load + loadInArea = 24000.0; + TimeSeriesConfigurer loadTSconfig(area.load.series.timeSeries); + loadTSconfig.setColumnCount(1) + .fillColumnWith(0, loadInArea); + + + hydro.reservoirCapacity = 1e6; + hydro.reservoirManagement = true; // TODO check + + TimeSeriesConfigurer inflowsTS(hydro.series->storage.timeSeries); + inflowsTS.setColumnCount(1) + .fillColumnWith(0, 1000); + + auto simulation = builder.simulation; + simulation->create(); + simulation->run(); +} +BOOST_AUTO_TEST_SUITE_END() From f0a31ee2a205d013d7e57a03a0197ab735180f88 Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Wed, 24 Jan 2024 10:36:49 +0100 Subject: [PATCH 2/4] Adding simple hydro study --- .../end-to-end/simple_study/simple-study.cpp | 74 +++++++++++-------- src/tests/end-to-end/utils/utils.cpp | 12 ++- src/tests/end-to-end/utils/utils.h | 3 +- 3 files changed, 56 insertions(+), 33 deletions(-) diff --git a/src/tests/end-to-end/simple_study/simple-study.cpp b/src/tests/end-to-end/simple_study/simple-study.cpp index 670057d411..bee2f960f9 100644 --- a/src/tests/end-to-end/simple_study/simple-study.cpp +++ b/src/tests/end-to-end/simple_study/simple-study.cpp @@ -46,6 +46,43 @@ StudyFixture::StudyFixture() .setUnitCount(1); }; +struct HydroMaxPowerStudy : public StudyBuilder +{ + using StudyBuilder::StudyBuilder; + HydroMaxPowerStudy(); + + // Data members + Area* area = nullptr; + PartHydro* hydro = nullptr; + double loadInArea = 24000.; + TimeSeriesConfigurer loadTSconfig; +}; + +HydroMaxPowerStudy::HydroMaxPowerStudy() +{ + simulationBetweenDays(0, 14); + setNumberMCyears(1); + + area = addAreaToStudy("Area"); + area->thermal.unsuppliedEnergyCost = 1; + + TimeSeriesConfigurer loadTSconfig(area->load.series.timeSeries); + loadTSconfig.setColumnCount(1).fillColumnWith(0, loadInArea); + + hydro = &area->hydro; + + TimeSeriesConfigurer genP(hydro->series->maxHourlyGenPower.timeSeries); + genP.setColumnCount(1).fillColumnWith(0, 100.); + + TimeSeriesConfigurer hydroStorage(hydro->series->storage.timeSeries); + hydroStorage.setColumnCount(1, DAYS_PER_YEAR).fillColumnWith(0, 2400.); + + TimeSeriesConfigurer genE(hydro->dailyNbHoursAtGenPmax); + genE.setColumnCount(1, DAYS_PER_YEAR).fillColumnWith(0, 24); + + hydro->reservoirCapacity = 1e6; + hydro->reservoirManagement = true; +}; BOOST_FIXTURE_TEST_SUITE(ONE_AREA__ONE_THERMAL_CLUSTER, StudyFixture) @@ -248,38 +285,17 @@ BOOST_AUTO_TEST_CASE(error_on_wrong_hydro_data) } BOOST_AUTO_TEST_SUITE_END() +BOOST_FIXTURE_TEST_SUITE(HYDRO_MAX_POWER, HydroMaxPowerStudy) -BOOST_AUTO_TEST_SUITE(hydro_hourly_max_power) BOOST_AUTO_TEST_CASE(basic) { - StudyBuilder builder; - builder.simulationBetweenDays(0, 7); - builder.setNumberMCyears(1); - Area& area = *builder.addAreaToStudy("A"); - - area.thermal.unsuppliedEnergyCost = 1; - - PartHydro& hydro = area.hydro; - TimeSeriesConfigurer genP(hydro.series->maxHourlyGenPower.timeSeries); - genP.setColumnCount(1) - .fillColumnWith(0, 12); - - // 10000MW hourly load - loadInArea = 24000.0; - TimeSeriesConfigurer loadTSconfig(area.load.series.timeSeries); - loadTSconfig.setColumnCount(1) - .fillColumnWith(0, loadInArea); - - - hydro.reservoirCapacity = 1e6; - hydro.reservoirManagement = true; // TODO check - - TimeSeriesConfigurer inflowsTS(hydro.series->storage.timeSeries); - inflowsTS.setColumnCount(1) - .fillColumnWith(0, 1000); - - auto simulation = builder.simulation; simulation->create(); simulation->run(); + + OutputRetriever output(simulation->rawSimu()); + + BOOST_TEST(output.hydroStorage(area).hour(0) == hydro->series->maxHourlyGenPower.timeSeries[0][0], tt::tolerance(0.001)); + BOOST_TEST(output.overallCost(area).hour(0) == (loadInArea - output.hydroStorage(area).hour(0)) * area->thermal.unsuppliedEnergyCost, tt::tolerance(0.001)); } -BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/src/tests/end-to-end/utils/utils.cpp b/src/tests/end-to-end/utils/utils.cpp index 70920b7ca3..10370c9623 100644 --- a/src/tests/end-to-end/utils/utils.cpp +++ b/src/tests/end-to-end/utils/utils.cpp @@ -39,10 +39,10 @@ void addScratchpadToEachArea(Study& study) } } } - -TimeSeriesConfigurer& TimeSeriesConfigurer::setColumnCount(unsigned int columnCount) +// Name should be changed to setTSSize +TimeSeriesConfigurer& TimeSeriesConfigurer::setColumnCount(unsigned int columnCount, unsigned rowCount) { - ts_->resize(columnCount, HOURS_PER_YEAR); + ts_->resize(columnCount, rowCount); return *this; } @@ -102,6 +102,12 @@ averageResults OutputRetriever::load(Area* area) return averageResults(result->avgdata); } +averageResults OutputRetriever::hydroStorage(Area* area) +{ + auto result = retrieveAreaResults(area); + return averageResults(result->avgdata); +} + averageResults OutputRetriever::flow(AreaLink* link) { // There is a problem here : diff --git a/src/tests/end-to-end/utils/utils.h b/src/tests/end-to-end/utils/utils.h index 15c7ae065f..ac695f5282 100644 --- a/src/tests/end-to-end/utils/utils.h +++ b/src/tests/end-to-end/utils/utils.h @@ -20,7 +20,7 @@ class TimeSeriesConfigurer public: TimeSeriesConfigurer() = default; TimeSeriesConfigurer(Matrix<>& matrix) : ts_(&matrix) {} - TimeSeriesConfigurer& setColumnCount(unsigned int columnCount); + TimeSeriesConfigurer& setColumnCount(unsigned int columnCount, unsigned rowCount = HOURS_PER_YEAR); TimeSeriesConfigurer& fillColumnWith(unsigned int column, double value); private: Matrix<>* ts_ = nullptr; @@ -70,6 +70,7 @@ class OutputRetriever OutputRetriever(ISimulation& simulation) : simulation_(simulation) {} averageResults overallCost(Area* area); averageResults load(Area* area); + averageResults hydroStorage(Area* area); averageResults flow(AreaLink* link); averageResults thermalGeneration(ThermalCluster* cluster); averageResults thermalNbUnitsON(ThermalCluster* cluster); From b98ad45b5394672cb786a2e080a51ded1d53ad24 Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Wed, 24 Jan 2024 11:55:28 +0100 Subject: [PATCH 3/4] Removing unnecessary struct members --- src/tests/end-to-end/simple_study/simple-study.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/tests/end-to-end/simple_study/simple-study.cpp b/src/tests/end-to-end/simple_study/simple-study.cpp index bee2f960f9..48af0dc4c0 100644 --- a/src/tests/end-to-end/simple_study/simple-study.cpp +++ b/src/tests/end-to-end/simple_study/simple-study.cpp @@ -55,7 +55,6 @@ struct HydroMaxPowerStudy : public StudyBuilder Area* area = nullptr; PartHydro* hydro = nullptr; double loadInArea = 24000.; - TimeSeriesConfigurer loadTSconfig; }; HydroMaxPowerStudy::HydroMaxPowerStudy() From 9e0eedb96a274ee43128f90c3111657879f37d3e Mon Sep 17 00:00:00 2001 From: NikolaIlic Date: Thu, 25 Jan 2024 11:49:18 +0100 Subject: [PATCH 4/4] Scenario Builder Test --- src/libs/antares/study/parts/hydro/series.h | 1 + .../end-to-end/simple_study/simple-study.cpp | 34 ++++++++++++++++++- src/tests/end-to-end/utils/utils.h | 1 + 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/libs/antares/study/parts/hydro/series.h b/src/libs/antares/study/parts/hydro/series.h index 97b984a244..9d09140878 100644 --- a/src/libs/antares/study/parts/hydro/series.h +++ b/src/libs/antares/study/parts/hydro/series.h @@ -163,6 +163,7 @@ class DataSeriesHydro // max power (generation and pumping) number of TS uint TScount() const; uint maxPowerTScount() const; + void setMaxPowerTScount(uint count) { maxPowerTScount_ = count;} // Setting TS's when derated mode is on void resizeTSinDeratedMode(bool derated, unsigned int studyVersion, bool useBySolver); diff --git a/src/tests/end-to-end/simple_study/simple-study.cpp b/src/tests/end-to-end/simple_study/simple-study.cpp index de28b49451..55c9f8b0c4 100644 --- a/src/tests/end-to-end/simple_study/simple-study.cpp +++ b/src/tests/end-to-end/simple_study/simple-study.cpp @@ -347,6 +347,38 @@ BOOST_AUTO_TEST_CASE(basic) BOOST_TEST(output.overallCost(area).hour(0) == (loadInArea - output.hydroStorage(area).hour(0)) * area->thermal.unsuppliedEnergyCost, tt::tolerance(0.001)); } -BOOST_AUTO_TEST_SUITE_END() +BOOST_AUTO_TEST_CASE(scenario_builder) +{ + hydro->series->setMaxPowerTScount(3U); + setNumberMCyears(3); + + giveWeightToYear(4.f, 0); + giveWeightToYear(3.f, 1); + giveWeightToYear(2.f, 2); + float weightSum = study->parameters.getYearsWeightSum(); + TimeSeriesConfigurer genP(hydro->series->maxHourlyGenPower.timeSeries); + TimeSeriesConfigurer genE(hydro->series->maxHourlyPumpPower.timeSeries); + genP.setColumnCount(3).fillColumnWith(0, 100.).fillColumnWith(1, 200.).fillColumnWith(2, 300.); + genE.setColumnCount(3).fillColumnWith(0, 0.).fillColumnWith(1, 0.).fillColumnWith(2, 0.); + + ScenarioBuilderRule scenarioBuilderRule(*study); + scenarioBuilderRule.hydroMaxPower().setTSnumber(area->index, 0, 3); + scenarioBuilderRule.hydroMaxPower().setTSnumber(area->index, 1, 2); + scenarioBuilderRule.hydroMaxPower().setTSnumber(area->index, 2, 1); + + simulation->create(); + simulation->run(); + + OutputRetriever output(simulation->rawSimu()); + + double averageLoad = (4 * 300. + 3. * 200. + 2. * 100.) / weightSum; + + BOOST_TEST(hydro->series->maxHourlyGenPower.timeseriesNumbers[0][0] == 2U); + BOOST_TEST(hydro->series->maxHourlyGenPower.timeseriesNumbers[0][1] == 1U); + BOOST_TEST(hydro->series->maxHourlyGenPower.timeseriesNumbers[0][2] == 0); + BOOST_TEST(output.overallCost(area).hour(0) == loadInArea - averageLoad * area->thermal.unsuppliedEnergyCost, tt::tolerance(0.1)); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/src/tests/end-to-end/utils/utils.h b/src/tests/end-to-end/utils/utils.h index 5ad8594b4e..ef320fe2ad 100644 --- a/src/tests/end-to-end/utils/utils.h +++ b/src/tests/end-to-end/utils/utils.h @@ -121,6 +121,7 @@ class ScenarioBuilderRule public: ScenarioBuilderRule(Study& study); loadTSNumberData& load() { return rules_->load; } + hydroMaxPowerTSNumberData& hydroMaxPower() { return rules_->hydroMaxPower; } BindingConstraintsTSNumberData& bcGroup() { return rules_->binding_constraints; } private: