Skip to content

Commit

Permalink
merge develop
Browse files Browse the repository at this point in the history
  • Loading branch information
payetvin committed Jun 28, 2024
2 parents 2c80605 + a00b90a commit 0fc7481
Show file tree
Hide file tree
Showing 43 changed files with 1,477 additions and 881 deletions.
135 changes: 19 additions & 116 deletions src/libs/antares/study/area/links.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@

#include <filesystem>
#include <limits>

#include <boost/algorithm/string/case_conv.hpp>

#include <yuni/yuni.h>
#include <array>

#include <antares/exception/LoadingError.hpp>
#include <antares/logs/logs.h>
Expand Down Expand Up @@ -137,58 +134,6 @@ bool AreaLink::linkLoadTimeSeries_for_version_820_and_later(const AnyString& fol
return success;
}

// This function is "lazy", it only loads files if they exist
// and set a `valid` flag
bool AreaLink::loadTSGenTimeSeries(const fs::path& folder)
{
const std::string idprepro = std::string(from->id) + "/" + std::string(with->id);
tsGeneration.prepro =
std::make_unique<Data::PreproAvailability>(idprepro, tsGeneration.unitCount);

bool anyFileWasLoaded = false;

// file name without suffix, .txt for general infos and mod_direct/indirect.txt
fs::path preproFile = folder / "prepro" / with->id.c_str();

// Prepro
fs::path filepath = preproFile;
filepath += ".txt";
if (fs::exists(filepath))
{
anyFileWasLoaded = true;
tsGeneration.valid = tsGeneration.prepro->data.loadFromCSVFile(
filepath.string(),
Antares::Data::PreproAvailability::preproAvailabilityMax,
DAYS_PER_YEAR)
&& tsGeneration.prepro->validate();
}

// Modulation
filepath = preproFile;
filepath += "_mod_direct.txt";
if (fs::exists(filepath))
{
anyFileWasLoaded = true;
tsGeneration.valid &= tsGeneration.modulationCapacityDirect
.loadFromCSVFile(filepath.string(), 1, HOURS_PER_YEAR);
}

filepath = preproFile;
filepath += "_mod_indirect.txt";
if (fs::exists(filepath))
{
anyFileWasLoaded = true;
tsGeneration.valid &= tsGeneration.modulationCapacityIndirect
.loadFromCSVFile(filepath.string(), 1, HOURS_PER_YEAR);
}

if (anyFileWasLoaded)
{
return tsGeneration.valid;
}
return true;
}

bool AreaLink::isLinkPhysical() const
{
// All link types are physical, except arVirt
Expand Down Expand Up @@ -360,7 +305,16 @@ AreaLink* AreaAddLinkBetweenAreas(Area* area, Area* with, bool warning)

namespace // anonymous
{
bool handleKey(Data::AreaLink& link, const String& key, const String& value)

bool isPropertyUsedForLinkTSgeneration(const std::string& key)
{
std::array<std::string, 7> listKeys
= {"unitcount", "nominalcapacity", "law.planned", "law.forced",
"volatility.planned", "volatility.forced", "force-no-generation"};
return std::find(listKeys.begin(), listKeys.end(), key) != listKeys.end();
}

bool AreaLinksInternalLoadFromProperty(AreaLink& link, const String& key, const String& value)
{
if (key == "hurdles-cost")
{
Expand Down Expand Up @@ -503,55 +457,9 @@ bool handleKey(Data::AreaLink& link, const String& key, const String& value)
link.filterYearByYear = stringIntoDatePrecision(value);
return true;
}
return false;
}

bool handleTSGenKey(Data::LinkTsGeneration& out,
const std::string& key,
const String& value)
{

if (key == "unitcount")
{
return value.to<uint>(out.unitCount);
}

if (key == "nominalcapacity")
{
return value.to<double>(out.nominalCapacity);
}

if (key == "law.planned")
{
return value.to(out.plannedLaw);
}

if (key == "law.forced")
{
return value.to(out.forcedLaw);
}

if (key == "volatility.planned")
{
return value.to(out.plannedVolatility);
}

if (key == "volatility.forced")
{
return value.to(out.forcedVolatility);
}

if (key == "force-no-generation")
{
return value.to<bool>(out.forceNoGeneration);
}

return false;
}

bool AreaLinksInternalLoadFromProperty(AreaLink& link, const String& key, const String& value)
{
return handleKey(link, key, value) || handleTSGenKey(link.tsGeneration, key, value);
// Properties used by TS generator only.
// We just skip them (otherwise : reading error)
return isPropertyUsedForLinkTSgeneration(key.to<std::string>());
}

[[noreturn]] void logLinkDataCheckError(const AreaLink& link, const String& msg, int hour)
Expand All @@ -572,7 +480,7 @@ bool AreaLinksInternalLoadFromProperty(AreaLink& link, const String& key, const
}
} // anonymous namespace

bool AreaLinksLoadFromFolder(Study& study, AreaList* l, Area* area, const fs::path& folder, bool loadTSGen)
bool AreaLinksLoadFromFolder(Study& study, AreaList* areaList, Area* area, const fs::path& folder)
{
// Assert
assert(area);
Expand All @@ -594,16 +502,16 @@ bool AreaLinksLoadFromFolder(Study& study, AreaList* l, Area* area, const fs::pa
for (auto* s = ini.firstSection; s; s = s->next)
{
// Getting the name of the area
std::string buffer = transformNameIntoID(s->name);
const std::string targetAreaName = transformNameIntoID(s->name);

// Trying to find it
Area* linkedWith = AreaListLFind(l, buffer.c_str());
if (!linkedWith)
Area* targetArea = AreaListLFind(areaList, targetAreaName.c_str());
if (!targetArea)
{
logs.error() << '`' << s->name << "`: Impossible to find the area";
continue;
}
AreaLink* lnk = AreaAddLinkBetweenAreas(area, linkedWith);
AreaLink* lnk = AreaAddLinkBetweenAreas(area, targetArea);
if (!lnk)
{
logs.error() << "Impossible to create a link between two areas";
Expand Down Expand Up @@ -698,11 +606,6 @@ bool AreaLinksLoadFromFolder(Study& study, AreaList* l, Area* area, const fs::pa
}
}

if (loadTSGen)
{
ret = link.loadTSGenTimeSeries(folder) && ret;
}

// From the solver only
if (study.usedByTheSolver)
{
Expand Down
2 changes: 1 addition & 1 deletion src/libs/antares/study/area/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ static bool AreaListLoadFromFolderSingleArea(Study& study,
// Links
{
fs::path folder = fs::path(study.folderInput.c_str()) / "links" / area.id.c_str();
ret = AreaLinksLoadFromFolder(study, list, &area, folder, options.linksLoadTSGen) && ret;
ret = AreaLinksLoadFromFolder(study, list, &area, folder) && ret;
}

// UI
Expand Down
2 changes: 1 addition & 1 deletion src/libs/antares/study/cleaner/cleaner-v20.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ bool listOfFilesAnDirectoriesToKeep(StudyCleaningInfos* infos)
logs.verbosityLevel = Logs::Verbosity::Warning::level;
// load all links
buffer.clear() << infos->folder << "/input/links/" << area->id;
if (not AreaLinksLoadFromFolder(*study, arealist, area, buffer.c_str(), false))
if (not AreaLinksLoadFromFolder(*study, arealist, area, buffer.c_str()))
{
delete arealist;
delete study;
Expand Down
4 changes: 0 additions & 4 deletions src/libs/antares/study/fwd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ const char* SeedToCString(SeedIndex seed)
return "Noise on virtual Hydro costs";
case seedHydroManagement:
return "Initial reservoir levels";
case seedTsGenLinks:
return "Links time-series generation";
case seedMax:
return "";
}
Expand Down Expand Up @@ -87,8 +85,6 @@ const char* SeedToID(SeedIndex seed)
return "seed-hydro-costs";
case seedHydroManagement:
return "seed-initial-reservoir-levels";
case seedTsGenLinks:
return "seed-tsgen-links";
case seedMax:
return "";
}
Expand Down
3 changes: 1 addition & 2 deletions src/libs/antares/study/include/antares/study/area/area.h
Original file line number Diff line number Diff line change
Expand Up @@ -727,8 +727,7 @@ AreaLink* AreaAddLinkBetweenAreas(Area* area, Area* with, bool warning = true);
bool AreaLinksLoadFromFolder(Study& s,
AreaList* l,
Area* area,
const std::filesystem::path& folder,
bool loadTSGen);
const std::filesystem::path& folder);

/*!
** \brief Save interconnections of a given area into a folder (`input/areas/[area]/ntc`)
Expand Down
5 changes: 0 additions & 5 deletions src/libs/antares/study/include/antares/study/area/links.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ class AreaLink final: public Yuni::NonCopyable<AreaLink>

bool loadTimeSeries(const StudyVersion& version, const AnyString& folder);

bool loadTSGenTimeSeries(const std::filesystem::path& folder);

void storeTimeseriesNumbers(Solver::IResultWriter& writer) const;

//! \name Area
Expand Down Expand Up @@ -208,9 +206,6 @@ class AreaLink final: public Yuni::NonCopyable<AreaLink>
int linkWidth;

friend struct CompareLinkName;

LinkTsGeneration tsGeneration;

}; // class AreaLink

struct CompareLinkName final
Expand Down
2 changes: 0 additions & 2 deletions src/libs/antares/study/include/antares/study/fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,6 @@ enum SeedIndex
seedHydroCosts,
//! Seed - Hydro management
seedHydroManagement,
//! The seed for links
seedTsGenLinks,
//! The number of seeds
seedMax,
};
Expand Down
3 changes: 0 additions & 3 deletions src/libs/antares/study/include/antares/study/load-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ class StudyLoadOptions
//! Force the year-by-year flag
bool forceYearByYear;

//! Load data associated to link TS generation
bool linksLoadTSGen = false;

//! Force the derated mode
bool forceDerated;

Expand Down
2 changes: 0 additions & 2 deletions src/libs/antares/study/include/antares/study/parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,6 @@ class Parameters final
uint nbTimeSeriesThermal;
//! Nb of timeSeries : Solar
uint nbTimeSeriesSolar;
//! Nb of timeSeries : Links
uint nbLinkTStoGenerate = 1;
//@}

//! \name Time-series refresh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,60 @@

namespace Antares::Data
{

//! The maximum number of days in a year
constexpr size_t dayYearCount = 366;

struct DailyDemand
{
//! Net demand, for each day of the year, for each area
double DLN = 0.;
//! Daily local effective load
double DLE = 0.;
};

struct MonthlyGenerationTargetData
{
//! Monthly local effective demand
double MLE = 0.;
//! Monthly optimal generation
double MOG = 0.;
//! Monthly optimal level
double MOL = 0.;
//! Monthly target generations
double MTG = 0.;
};

//! Hydro Management Data for a given area
struct TimeDependantHydroManagementData
{
std::array<DailyDemand, dayYearCount> daily{0};
std::array<MonthlyGenerationTargetData, 12> monthly{0};
};

//! Area Hydro Management Data for a given year
struct AreaDependantHydroManagementData
{
//! inflows
std::array<double, 12> inflows{};
//! monthly minimal generation
std::array<double, 12> mingens{};

//! daily minimal generation
std::array<double, dayYearCount> dailyMinGen{};

// Data for minGen<->inflows preChecks
//! monthly total mingen
std::array<double, 12> totalMonthMingen{};
//! monthly total inflows
std::array<double, 12> totalMonthInflows{};
//! yearly total mingen
double totalYearMingen = 0;
//! yearly total inflows
double totalYearInflows = 0;

}; // struct AreaDependantHydroManagementData

/*!
** \brief Hydro for a single area
*/
Expand Down Expand Up @@ -165,6 +219,7 @@ class PartHydro
// which contains other time.
Matrix<double, double> dailyNbHoursAtGenPmax;
Matrix<double, double> dailyNbHoursAtPumpPmax;
std::unordered_map<uint, AreaDependantHydroManagementData> managementData;

std::vector<std::optional<double>> deltaBetweenFinalAndInitialLevels;

Expand Down
13 changes: 7 additions & 6 deletions src/libs/antares/study/parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,9 @@ static bool SGDIntLoadFamily_General(Parameters& d,
}
if (key == "nbtimeserieslinks")
{
return value.to<uint>(d.nbLinkTStoGenerate);
// This data is among solver data, but is useless while running a simulation
// Only by TS generator. We skip it here (otherwise, we get a reading error).
return true;
}
// Interval values
if (key == "refreshintervalload")
Expand Down Expand Up @@ -1026,10 +1028,6 @@ static bool SGDIntLoadFamily_SeedsMersenneTwister(Parameters& d,
{
return value.to<uint>(d.seed[seedTsGenSolar]);
}
if (key == "seed_links")
{
return value.to<uint>(d.seed[seedTsGenLinks]);
}
if (key == "seed_timeseriesnumbers")
{
return value.to<uint>(d.seed[seedTimeseriesNumbers]);
Expand All @@ -1046,6 +1044,10 @@ static bool SGDIntLoadFamily_SeedsMersenneTwister(Parameters& d,
return value.to<uint>(d.seed[sd]);
}
}
if (key == "seed-tsgen-links")
{
return true; // Useless for solver, belongs to TS generator
}
}
}
return false;
Expand Down Expand Up @@ -1766,7 +1768,6 @@ void Parameters::saveToINI(IniFile& ini) const
section->add("nbTimeSeriesWind", nbTimeSeriesWind);
section->add("nbTimeSeriesThermal", nbTimeSeriesThermal);
section->add("nbTimeSeriesSolar", nbTimeSeriesSolar);
section->add("nbtimeserieslinks", nbLinkTStoGenerate);

// Refresh
ParametersSaveTimeSeries(section, "refreshTimeSeries", timeSeriesToRefresh);
Expand Down
Loading

0 comments on commit 0fc7481

Please sign in to comment.