Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In-memory tests for CR23 #1894

Merged
merged 5 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/libs/antares/study/parts/hydro/series.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
82 changes: 82 additions & 0 deletions src/tests/end-to-end/simple_study/simple-study.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,42 @@ StudyFixture::StudyFixture()
.setUnitCount(1);
};

struct HydroMaxPowerStudy : public StudyBuilder
{
using StudyBuilder::StudyBuilder;
HydroMaxPowerStudy();

// Data members
Area* area = nullptr;
PartHydro* hydro = nullptr;
double loadInArea = 24000.;
};

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)

Expand Down Expand Up @@ -298,5 +334,51 @@ BOOST_AUTO_TEST_CASE(sts_initial_level)
}
BOOST_AUTO_TEST_SUITE_END()

BOOST_FIXTURE_TEST_SUITE(HYDRO_MAX_POWER, HydroMaxPowerStudy)

BOOST_AUTO_TEST_CASE(basic)
{
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_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()

12 changes: 9 additions & 3 deletions src/tests/end-to-end/utils/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -110,6 +110,12 @@ averageResults OutputRetriever::load(Area* area)
return averageResults(result->avgdata);
}

averageResults OutputRetriever::hydroStorage(Area* area)
{
auto result = retrieveAreaResults<Variable::Economy::VCardHydroStorage>(area);
return averageResults(result->avgdata);
}

averageResults OutputRetriever::flow(AreaLink* link)
{
// There is a problem here :
Expand Down
4 changes: 3 additions & 1 deletion src/tests/end-to-end/utils/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -71,6 +71,7 @@ class OutputRetriever
averageResults overallCost(Area* area);
averageResults STSLevel_PSP_Open(Area* area);
averageResults load(Area* area);
averageResults hydroStorage(Area* area);
averageResults flow(AreaLink* link);
averageResults thermalGeneration(ThermalCluster* cluster);
averageResults thermalNbUnitsON(ThermalCluster* cluster);
Expand Down Expand Up @@ -120,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:
Expand Down
Loading