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

Refactor time series #1677

Merged
merged 43 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
032aa92
[DEV] Add classes TimeSeriesNumbers TimeSeries
payetvin Oct 4, 2023
ca77e5c
[DEV] Add classes to cpp
payetvin Oct 4, 2023
49782d9
[DEV] getTSNumber
payetvin Oct 4, 2023
e83b6bd
[DEV] getCoeff getColumn
payetvin Oct 4, 2023
d61970d
[FIX] Windows CI
payetvin Oct 5, 2023
ba47967
[DEV] Use matrix<> instead of vector
payetvin Oct 5, 2023
7031cea
[DEV] Add timeSeriesLoadFromFolder
payetvin Oct 5, 2023
c242069
[DEV]
payetvin Oct 5, 2023
1d20d99
[DEV] Wind compiling
payetvin Oct 5, 2023
18cf5fc
[DEV] remove old wind series files
payetvin Oct 5, 2023
cb3f385
[FIX] crash
payetvin Oct 5, 2023
78cd79f
[FIX] getSeriesIndex
payetvin Oct 5, 2023
4be03ca
[DEV] load series
payetvin Oct 6, 2023
8a76389
[DEV] remove load series files
payetvin Oct 6, 2023
3227753
[FIX] compile
payetvin Oct 6, 2023
1c79002
[DEV] Comments
payetvin Oct 6, 2023
a0fc02c
[DEV] revert reset()
payetvin Oct 6, 2023
fb1caae
[DEV] solar series
payetvin Oct 6, 2023
cc65e53
[DEV] remove solar series files
payetvin Oct 6, 2023
aeae022
[FIX] Tests crashes
payetvin Oct 9, 2023
83a04ea
[DEV] Add static member emptyColumn
payetvin Oct 9, 2023
1c91c83
[DEV] remove useless if
payetvin Oct 9, 2023
ab6deaf
Use generic class for load series (#1686)
payetvin Oct 9, 2023
4cafa88
Merge branch 'feature/series' of https://github.com/AntaresSimulatorT…
payetvin Oct 9, 2023
70a5cf9
Merge branch 'feature/series-solar' into feature/series
payetvin Oct 9, 2023
0fa4190
[DEV] Comments
payetvin Oct 9, 2023
01d0616
[DEV] using TScoefficients
payetvin Oct 9, 2023
77d2df4
Refactor thermal & renewable series (#1693)
payetvin Oct 16, 2023
9067974
[DEV] Comments and use series.reset()
payetvin Oct 16, 2023
356ef42
Refactor hydro series (#1705)
payetvin Oct 19, 2023
c052f8f
[MERGE] Develop + conflicts in management and utils
payetvin Oct 19, 2023
e10fadd
[FIX] Compile
payetvin Oct 20, 2023
2977a2d
[FIX] Code smells
payetvin Oct 20, 2023
a8be478
[FIX] Code smells
payetvin Oct 23, 2023
6acd647
[DEV] valueAtTimeStep uses year hour now
payetvin Oct 23, 2023
d645ab8
Unit tests for timeseries (#1713)
payetvin Oct 24, 2023
7dc7570
[DEV] Fix include path
payetvin Oct 25, 2023
3fc1ad0
Merge branch 'feature/series' of https://github.com/AntaresSimulatorT…
payetvin Oct 25, 2023
d28a611
[DEV] move folder series
payetvin Oct 26, 2023
b350143
[DEV] Use timestep instead of hour
payetvin Oct 26, 2023
170b603
[FIX] several comments for class series
payetvin Oct 26, 2023
c1ebd28
[FIX] more comments
payetvin Oct 26, 2023
d93a67b
[FIX] try fix windows CI
payetvin Oct 26, 2023
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
9 changes: 0 additions & 9 deletions src/libs/antares/study/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,6 @@ source_group("study\\part\\short-term-storage" FILES ${SRC_STUDY_PART_SHORT_TERM
set(SRC_STUDY_PART_WIND
parts/wind/container.h
parts/wind/container.cpp
parts/wind/series.h
parts/wind/series.hxx
parts/wind/series.cpp
parts/wind/prepro.h
parts/wind/prepro.hxx
parts/wind/prepro.cpp
Expand Down Expand Up @@ -202,19 +199,13 @@ set(SRC_STUDY
# Load
parts/load/container.h
parts/load/container.cpp
parts/load/series.h
parts/load/series.hxx
parts/load/series.cpp
parts/load/prepro.cpp
parts/load/prepro.h
parts/load/prepro.hxx

# Solar
parts/solar/container.h
parts/solar/container.cpp
parts/solar/series.h
parts/solar/series.hxx
parts/solar/series.cpp
parts/solar/prepro.cpp
parts/solar/prepro.h
parts/solar/prepro.hxx
Expand Down
21 changes: 6 additions & 15 deletions src/libs/antares/study/area/area.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,6 @@ void Area::createMissingData()

void Area::createMissingTimeSeries()
{
if (!load.series)
load.series = new DataSeriesLoad();
if (!solar.series)
solar.series = new DataSeriesSolar();
if (!wind.series)
wind.series = new DataSeriesWind();
if (!hydro.series)
hydro.series = new DataSeriesHydro();
thermal.list.ensureDataTimeSeries();
Expand Down Expand Up @@ -269,16 +263,13 @@ void Area::resizeAllTimeseriesNumbers(uint n)
assert(n < 200000); // arbitrary number

// asserts
assert(load.series and "load.series must not be nullptr !");
assert(solar.series and "solar.series must not be nullptr !");
assert(wind.series and "wind.series must not be nullptr !");
assert(hydro.series and "series must not be nullptr !");

if (!n)
{
load.series->timeseriesNumbers.clear();
solar.series->timeseriesNumbers.clear();
wind.series->timeseriesNumbers.clear();
load.series.timeseriesNumbers.clear();
solar.series.timeseriesNumbers.clear();
wind.series.timeseriesNumbers.clear();
hydro.series->timeseriesNumbers.clear();
for (auto& namedLink : links)
{
Expand All @@ -288,9 +279,9 @@ void Area::resizeAllTimeseriesNumbers(uint n)
}
else
{
load.series->timeseriesNumbers.resize(1, n);
solar.series->timeseriesNumbers.resize(1, n);
wind.series->timeseriesNumbers.resize(1, n);
load.series.timeseriesNumbers.resize(1, n);
solar.series.timeseriesNumbers.resize(1, n);
wind.series.timeseriesNumbers.resize(1, n);
hydro.series->timeseriesNumbers.resize(1, n);
for (auto& namedLink : links)
{
Expand Down
15 changes: 0 additions & 15 deletions src/libs/antares/study/area/area.h
Original file line number Diff line number Diff line change
Expand Up @@ -795,31 +795,16 @@ AreaLink* AreaListAddLink(AreaList* l, const char area[], const char with[], boo

void AreaListClearAllLinks(AreaList* l);

/*!
** \brief Ensure data for load time-series are initialized
*/
void AreaListEnsureDataLoadTimeSeries(AreaList* l);

/*!
** \brief Ensure data for load prepro are initialized
*/
void AreaListEnsureDataLoadPrepro(AreaList* l);

/*!
** \brief Ensure data for load time-series are initialized
*/
void AreaListEnsureDataSolarTimeSeries(AreaList* l);

/*!
** \brief Ensure data for solar prepro are initialized
*/
void AreaListEnsureDataSolarPrepro(AreaList* l);

/*!
** \brief Ensure data for wind time-series are initialized
*/
void AreaListEnsureDataWindTimeSeries(AreaList* l);

/*!
** \brief Ensure data for wind prepro are initialized
*/
Expand Down
76 changes: 16 additions & 60 deletions src/libs/antares/study/area/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,8 @@ static bool AreaListSaveToFolderSingleArea(const Area& area, Clob& buffer, const
<< area.id;
ret = area.load.prepro->saveToFolder(buffer) && ret;
}
if (area.load.series) // Series
{
buffer.clear() << folder << SEP << "input" << SEP << "load" << SEP << "series";
ret = DataSeriesLoadSaveToFolder(area.load.series, area.id, buffer.c_str()) && ret;
}
buffer.clear() << folder << SEP << "input" << SEP << "load" << SEP << "series";
area.load.series.timeSeriesSaveToFolder(area.id, buffer.c_str(), "load_") && ret;
}

// Solar
Expand All @@ -230,11 +227,8 @@ static bool AreaListSaveToFolderSingleArea(const Area& area, Clob& buffer, const
<< area.id;
ret = area.solar.prepro->saveToFolder(buffer) && ret;
}
if (area.solar.series) // Series
{
buffer.clear() << folder << SEP << "input" << SEP << "solar" << SEP << "series";
ret = DataSeriesSolarSaveToFolder(area.solar.series, area.id, buffer.c_str()) && ret;
}
buffer.clear() << folder << SEP << "input" << SEP << "solar" << SEP << "series";
ret = area.solar.series.timeSeriesSaveToFolder(area.id, buffer.c_str(), "solar_") && ret;
}

// Hydro
Expand Down Expand Up @@ -263,11 +257,9 @@ static bool AreaListSaveToFolderSingleArea(const Area& area, Clob& buffer, const
<< area.id;
ret = area.wind.prepro->saveToFolder(buffer) && ret;
}
if (area.wind.series) // Series
{
buffer.clear() << folder << SEP << "input" << SEP << "wind" << SEP << "series";
ret = DataSeriesWindSaveToFolder(area.wind.series, area.id, buffer.c_str()) && ret;
}

buffer.clear() << folder << SEP << "input" << SEP << "wind" << SEP << "series";
ret = area.wind.series.timeSeriesSaveToFolder(area.id, buffer.c_str(), "wind_") && ret;
}

// Thermal cluster list
Expand Down Expand Up @@ -857,10 +849,10 @@ static bool AreaListLoadFromFolderSingleArea(Study& study,
<< area.id;
ret = area.load.prepro->loadFromFolder(buffer) && ret;
}
if (area.load.series && (!options.loadOnlyNeeded || !area.load.prepro)) // Series
if (!options.loadOnlyNeeded || !area.load.prepro) // Series
{
buffer.clear() << study.folderInput << SEP << "load" << SEP << "series";
ret = DataSeriesLoadLoadFromFolder(study, area.load.series, area.id, buffer.c_str())
ret = area.load.series.timeSeriesLoadFromFolder(study, area.id, buffer.c_str(), "load_")
&& ret;
}

Expand All @@ -877,10 +869,10 @@ static bool AreaListLoadFromFolderSingleArea(Study& study,
<< area.id;
ret = area.solar.prepro->loadFromFolder(buffer) && ret;
}
if (area.solar.series && (!options.loadOnlyNeeded || !area.solar.prepro)) // Series
if (!options.loadOnlyNeeded || !area.solar.prepro) // Series
{
buffer.clear() << study.folderInput << SEP << "solar" << SEP << "series";
ret = DataSeriesSolarLoadFromFolder(study, area.solar.series, area.id, buffer.c_str())
ret = area.solar.series.timeSeriesLoadFromFolder(study, area.id, buffer.c_str(), "solar_")
&& ret;
}

Expand Down Expand Up @@ -920,10 +912,10 @@ static bool AreaListLoadFromFolderSingleArea(Study& study,
<< area.id;
ret = area.wind.prepro->loadFromFolder(buffer) && ret;
}
if (area.wind.series && (!options.loadOnlyNeeded || !area.wind.prepro)) // Series
if (!options.loadOnlyNeeded || !area.wind.prepro) // Series
{
buffer.clear() << study.folderInput << SEP << "wind" << SEP << "series";
ret = DataSeriesWindLoadFromFolder(study, area.wind.series, area.id, buffer.c_str())
ret = area.wind.series.timeSeriesLoadFromFolder(study, area.id, buffer.c_str(), "wind_")
&& ret;
}

Expand Down Expand Up @@ -1036,9 +1028,6 @@ static bool AreaListLoadFromFolderSingleArea(Study& study,

void AreaList::ensureDataIsInitialized(Parameters& params, bool loadOnlyNeeded)
{
AreaListEnsureDataLoadTimeSeries(this);
AreaListEnsureDataSolarTimeSeries(this);
AreaListEnsureDataWindTimeSeries(this);
AreaListEnsureDataHydroTimeSeries(this);
AreaListEnsureDataThermalTimeSeries(this);
AreaListEnsureDataRenewableTimeSeries(this);
Expand Down Expand Up @@ -1246,17 +1235,6 @@ Area* AreaListFindPtr(AreaList* l, const Area* ptr)
return nullptr;
}

void AreaListEnsureDataLoadTimeSeries(AreaList* l)
{
/* Asserts */
assert(l);

l->each([&](Data::Area& area) {
if (!area.load.series)
area.load.series = new DataSeriesLoad();
});
}

void AreaListEnsureDataLoadPrepro(AreaList* l)
{
/* Asserts */
Expand All @@ -1268,17 +1246,6 @@ void AreaListEnsureDataLoadPrepro(AreaList* l)
});
}

void AreaListEnsureDataSolarTimeSeries(AreaList* l)
{
/* Asserts */
assert(l);

l->each([&](Data::Area& area) {
if (!area.solar.series)
area.solar.series = new DataSeriesSolar();
});
}

void AreaListEnsureDataSolarPrepro(AreaList* l)
{
/* Asserts */
Expand All @@ -1290,17 +1257,6 @@ void AreaListEnsureDataSolarPrepro(AreaList* l)
});
}

void AreaListEnsureDataWindTimeSeries(AreaList* l)
{
/* Asserts */
assert(l);

l->each([&](Data::Area& area) {
if (!area.wind.series)
area.wind.series = new DataSeriesWind();
});
}

void AreaListEnsureDataWindPrepro(AreaList* l)
{
/* Asserts */
Expand Down Expand Up @@ -1604,7 +1560,7 @@ void AreaList::updateNameIDSet() const

void AreaList::removeLoadTimeseries()
{
each([&](Data::Area& area) { area.load.series->timeSeries.reset(1, HOURS_PER_YEAR); });
each([&](Data::Area& area) { area.load.series.timeSeries.reset(1, HOURS_PER_YEAR); });
}

void AreaList::removeHydroTimeseries()
Expand All @@ -1619,12 +1575,12 @@ void AreaList::removeHydroTimeseries()

void AreaList::removeSolarTimeseries()
{
each([&](Data::Area& area) { area.solar.series->timeSeries.reset(1, HOURS_PER_YEAR); });
each([&](Data::Area& area) { area.solar.series.timeSeries.reset(1, HOURS_PER_YEAR); });
}

void AreaList::removeWindTimeseries()
{
each([&](Data::Area& area) { area.wind.series->timeSeries.reset(1, HOURS_PER_YEAR); });
each([&](Data::Area& area) { area.wind.series.timeSeries.reset(1, HOURS_PER_YEAR); });
}

void AreaList::removeThermalTimeseries()
Expand Down
6 changes: 3 additions & 3 deletions src/libs/antares/study/area/store-timeseries-numbers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ static void genericStoreTimeseriesNumbers(Solver::IResultWriter& writer,

void storeTimeseriesNumbersForLoad(Solver::IResultWriter& writer, const Area& area)
{
genericStoreTimeseriesNumbers(writer, area.load.series->timeseriesNumbers, area.id, "load");
genericStoreTimeseriesNumbers(writer, area.load.series.timeseriesNumbers, area.id, "load");
}

void storeTimeseriesNumbersForSolar(Solver::IResultWriter& writer, const Area& area)
{
genericStoreTimeseriesNumbers(writer, area.solar.series->timeseriesNumbers, area.id, "solar");
genericStoreTimeseriesNumbers(writer, area.solar.series.timeseriesNumbers, area.id, "solar");
}

void storeTimeseriesNumbersForHydro(Solver::IResultWriter& writer, const Area& area)
Expand All @@ -84,7 +84,7 @@ void storeTimeseriesNumbersForHydro(Solver::IResultWriter& writer, const Area& a

void storeTimeseriesNumbersForWind(Solver::IResultWriter& writer, const Area& area)
{
genericStoreTimeseriesNumbers(writer, area.wind.series->timeseriesNumbers, area.id, "wind");
genericStoreTimeseriesNumbers(writer, area.wind.series.timeseriesNumbers, area.id, "wind");
}

void storeTimeseriesNumbersForThermal(Solver::IResultWriter& writer, const Area& area)
Expand Down
72 changes: 72 additions & 0 deletions src/libs/antares/study/parts/common/series.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,78 @@ using namespace Yuni;

namespace Antares::Data
{

const double TimeSeries::emptyColumn[] = {0};

int TimeSeries::timeSeriesLoadFromFolder(Study& s,
const AreaName& areaID,
const std::string& folder,
const std::string& prefix)
{
String& buffer = s.bufferLoadingTS;

int ret = 1;
buffer.clear() << folder << SEP << prefix << areaID << '.' << s.inputExtension;
ret = timeSeries.loadFromCSVFile(buffer, 1, HOURS_PER_YEAR, &s.dataBuffer) && ret;

if (s.usedByTheSolver && s.parameters.derated)
timeSeries.averageTimeseries();

timeseriesNumbers.clear();

return ret;
}

int TimeSeries::timeSeriesSaveToFolder(const AreaName& areaID, const std::string& folder,
const std::string& prefix) const
{
Clob buffer;
buffer.clear() << folder << SEP << prefix << areaID << ".txt";
return timeSeries.saveToCSVFile(buffer, 0);
}

void TimeSeries::reset()
{
timeSeries.reset(1, HOURS_PER_YEAR);
}

double TimeSeries::getCoefficient(uint32_t year, uint32_t hourInYear) const
{
if (timeSeries.width == 0)
return 0;
return timeSeries[getSeriesIndex(year)][hourInYear];
}

const double* TimeSeries::getColumn(uint32_t year) const
{
if (timeSeries.width == 0)
return emptyColumn;
return timeSeries[getSeriesIndex(year)];
}

uint32_t TimeSeries::getSeriesIndex(uint32_t year) const
{
if (timeSeries.width == 1)
return 0;
else
return timeseriesNumbers[0][year];
}

bool TimeSeries::forceReload(bool reload) const
{
return timeSeries.forceReload(reload);
}

void TimeSeries::markAsModified() const
{
timeSeries.markAsModified();
}

uint64_t TimeSeries::memoryUsage() const
{
return timeSeries.memoryUsage();
}

bool DataSeriesCommon::forceReload(bool reload) const
{
return timeSeries.forceReload(reload);
Expand Down
Loading