Skip to content

Commit

Permalink
Thermal clusters lists : cleaning (#1844)
Browse files Browse the repository at this point in the history
This PR follows the PR #1809 (about cleaning common cluster list and
renewable cluster list)
It aims at simplifying thermal cluster lists as much as possible.

**Goal** : 
Having only one list of thermal clusters.
This list would be **private**
Code would interact with this list through an interface. This interface
would contain functions returning **std::views** that would result in
filtering thermal clusters using a certain property of clusters :
enabled / disabled, must-run or not, a combination of these.

**What's done** : 
- [x] Simplifying the `ClusterList<T>::add()` method
- [x] Changing **std::map** `mapping` from class **ThermalClusterList**
into a **std::vector** (named `allClusters_`)
- [x] Removing **PartThermal::clusters** (often reached by
`area.thermal.clusters`)
- [x] Removing **PartThermal::mustrunList** (often reached by
`area.thermal.mustrunList`)
- [x] Removing **PartThermal::list** (often reached by
`area.thermal.list.clusters`)

**Before starting a review, one should know several things** : 
- what the old lists of clusters used to contain : 
    -  **area.thermal.list.mapping** : all clusters
- **area.thermal.mustrunList.clusters** : clusters must-run and enabled
    - **area.thermal.clusters** : enabled clusters
- **area.thermal.list.clusters** : list used to build the optimization
problem (clusters enabled and not must-run). Careful with that list :
when loading clusters from input, this list contains all clusters. Then
it is progressively cleared from disabled and must-run clusters. So its
content depends on where we are in the execution. This list is also used
from the **GUI**. In that case, it always contains all clusters : it is
**not** cleared from specific clusters.
- the list **area.thermal.list.clusters** is the only list used in the
**GUI**, and in that case, it contains all clusters.
- As said previously, all lists of clusters are removed, except
**area.thermal.list.mapping**, turned into a private **std::vector**
(**area.thermal.list.allClusters_**) containing all clusters, and
filtered to access only clusters of interest at any point of the code.
- **cluster indices** : any cluster (thermal / renewable) used to have 2
indices :
- **index** : it turns out to be an index regarding only enabled and not
must-run clusters. So this index never concerns renewable clusters. It
was moved down from parent class **Cluster** to class
**ThermalCluster**.
- **areaWideIndex** : index regarding only enabled clusters. Concerns
both thermal and renewable clusters
- the 2 lists **area.thermal.mustrunList.clusters** and
**area.thermal.list.clusters** are closely related (inter-dependent) to
the **renewable** cluster list, due to a common inheritance. So this
work deeply impacts the **renewable** cluster lists.

---------

Co-authored-by: Vincent Payet <[email protected]>
Co-authored-by: Jason Maréchal <[email protected]>
Co-authored-by: Florian OMNES <[email protected]>
Co-authored-by: payetvin <[email protected]>
  • Loading branch information
5 people authored Feb 22, 2024
1 parent 418f563 commit b181904
Show file tree
Hide file tree
Showing 83 changed files with 696 additions and 1,200 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ on:
- main
- develop
- release/*
pull_request:
- fix/*
- feature/*

jobs:
sonarcloud:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Makefile
src/.vs

src/config.h
src/config/include

# Yuni
src/ext/yuni/src/ProfileBuild.cmake
Expand Down
5 changes: 2 additions & 3 deletions src/libs/antares/InfoCollection/StudyInfoCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ void StudyInfoCollector::enabledThermalClustersCountToFileContent(FileContent& f
auto end = study_.areas.end();
for (auto i = study_.areas.begin(); i != end; ++i)
{
Area& area = *(i->second);
nbEnabledThermalClusters +=
std::ranges::count_if(area.thermal.list, [](const auto& c) { return c->enabled; });
const Area& area = *(i->second);
nbEnabledThermalClusters += area.thermal.list.enabledAndNotMustRunCount();
}

// Adding an item related to number of enabled thermal clusters to the file content
Expand Down
13 changes: 6 additions & 7 deletions src/libs/antares/checks/checkLoadedInputData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void checkMinStablePower(bool tsGenThermal, const Antares::Data::AreaList& areas
}
else
{
areas.each([](Antares::Data::Area& area) { area.thermal.checkAndCorrectAvailability(); });
areas.each([](const auto& area) { area.thermal.checkAndCorrectAvailability(); });
}
}

Expand All @@ -158,16 +158,15 @@ static void checkThermalColumnNumber(const Antares::Data::AreaList& areas,
for (uint areaIndex = 0; areaIndex < areas.size(); ++areaIndex)
{
const auto& area = *(areas.byIndex[areaIndex]);
for (uint clusterIndex = 0; clusterIndex != area.thermal.clusterCount(); ++clusterIndex)
for (auto cluster : area.thermal.list.each_enabled())
{
const auto& cluster = *(area.thermal.clusters[clusterIndex]);
if (cluster.costgeneration == Antares::Data::setManually)
if (cluster->costgeneration == Antares::Data::setManually)
continue;
const uint otherMatrixWidth = (cluster.ecoInput.*matrix).width;
uint tsWidth = cluster.series.timeSeries.width;
const uint otherMatrixWidth = (cluster->ecoInput.*matrix).width;
uint tsWidth = cluster->series.timeSeries.width;
if (otherMatrixWidth != 1 && otherMatrixWidth != tsWidth)
{
logs.warning() << "Area: " << area.name << ". Cluster name: " << cluster.name()
logs.warning() << "Area: " << area.name << ". Cluster name: " << cluster->name()
<< ". " << exception.what();
error = true;
}
Expand Down
3 changes: 1 addition & 2 deletions src/libs/antares/study/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ source_group("study\\part\\common" FILES ${SRC_STUDY_PART_COMMON})

set(SRC_STUDY_PART_THERMAL
include/antares/study/parts/thermal/container.h
include/antares/study/parts/thermal/container.hxx
parts/thermal/container.cpp
include/antares/study/parts/thermal/prepro.h
include/antares/study/parts/thermal/prepro.hxx
Expand Down Expand Up @@ -318,4 +317,4 @@ target_include_directories(study

install(DIRECTORY include/antares
DESTINATION "include"
)
)
3 changes: 1 addition & 2 deletions src/libs/antares/study/area/area.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,8 @@ void Area::resizeAllTimeseriesNumbers(uint nbYears)
bool Area::thermalClustersMinStablePowerValidity(std::vector<YString>& output) const
{
bool noErrorMinStabPow = true;
for (uint l = 0; l != thermal.clusterCount(); ++l)
for (auto cluster : thermal.list.each_enabled())
{
auto& cluster = thermal.clusters[l];
logs.debug() << "cluster : " << cluster->name();
if ((not cluster->checkMinStablePower())
|| (cluster->minStablePower
Expand Down
41 changes: 6 additions & 35 deletions src/libs/antares/study/area/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -769,14 +769,6 @@ static bool AreaListLoadFromFolderSingleArea(Study& study,
StringT& buffer,
const StudyLoadOptions& options)
{
// Progression
options.progressTicks = 0;
options.progressTickCount
= area.thermal.list.size() * (options.loadOnlyNeeded ? 1 : 2) // prepro+series
+ 1 // links
+ 4 // load,solar,wind,hydro
+ 1; // DSM,misc...

// Reset
area.filterSynthesis = filterAll;
area.filterYearByYear = filterAll;
Expand Down Expand Up @@ -815,15 +807,10 @@ static bool AreaListLoadFromFolderSingleArea(Study& study,
MatrixTestForPositiveValues_LimitWidth(buffer.c_str(), &area.miscGen, fhhPSP);
}

++options.progressTicks;
options.pushProgressLogs();

// Links
{
buffer.clear() << study.folderInput << SEP << "links" << SEP << area.id;
ret = AreaLinksLoadFromFolder(study, list, &area, buffer) && ret;
++options.progressTicks;
options.pushProgressLogs();
}

// UI
Expand Down Expand Up @@ -853,9 +840,6 @@ static bool AreaListLoadFromFolderSingleArea(Study& study,
ret = area.load.series.loadFromFile(buffer.c_str(), averageTs)
&& ret;
}

++options.progressTicks;
options.pushProgressLogs();
}

// Solar
Expand All @@ -875,9 +859,6 @@ static bool AreaListLoadFromFolderSingleArea(Study& study,
&& ret;

}

++options.progressTicks;
options.pushProgressLogs();
}

// Hydro
Expand All @@ -898,9 +879,6 @@ static bool AreaListLoadFromFolderSingleArea(Study& study,
buffer.clear() << study.folderInput << SEP << "hydro" << SEP << "series";
ret = area.hydro.series->loadFromFolder(study, area.id, buffer) && ret;
}

++options.progressTicks;
options.pushProgressLogs();
}

// Wind
Expand All @@ -919,17 +897,14 @@ static bool AreaListLoadFromFolderSingleArea(Study& study,
ret = area.wind.series.loadFromFile(buffer.c_str(), averageTs)
&& ret;
}

++options.progressTicks;
options.pushProgressLogs();
}

// Thermal cluster list
{
buffer.clear() << study.folderInput << SEP << "thermal" << SEP << "prepro";
ret = area.thermal.list.loadPreproFromFolder(study, options, buffer) && ret;
ret = area.thermal.list.loadPreproFromFolder(study, buffer) && ret;
buffer.clear() << study.folderInput << SEP << "thermal" << SEP << "series";
ret = area.thermal.list.loadDataSeriesFromFolder(study, options, buffer) && ret;
ret = area.thermal.list.loadDataSeriesFromFolder(study, buffer) && ret;
ret = area.thermal.list.loadEconomicCosts(study, buffer) && ret;

// In adequacy mode, all thermal clusters must be in 'mustrun' mode
Expand All @@ -951,7 +926,7 @@ static bool AreaListLoadFromFolderSingleArea(Study& study,
if (study.header.version >= StudyVersion(8, 1))
{
buffer.clear() << study.folderInput << SEP << "renewables" << SEP << "series";
ret = area.renewable.list.loadDataSeriesFromFolder(study, options, buffer) && ret;
ret = area.renewable.list.loadDataSeriesFromFolder(study, buffer) && ret;
}

// Adequacy patch
Expand Down Expand Up @@ -1096,7 +1071,6 @@ bool AreaList::loadFromFolder(const StudyLoadOptions& options)
Area& area = *(i->second);
buffer.clear() << pStudy.folderInput << thermalPlant << area.id;
ret = area.thermal.list.loadFromFolder(pStudy, buffer.c_str(), &area) && ret;
area.thermal.prepareAreaWideIndexes();
}
}

Expand Down Expand Up @@ -1136,7 +1110,6 @@ bool AreaList::loadFromFolder(const StudyLoadOptions& options)
Area& area = *(i->second);
buffer.clear() << pStudy.folderInput << renewablePlant << area.id;
ret = area.renewable.list.loadFromFolder(buffer.c_str(), &area) && ret;
area.renewable.prepareAreaWideIndexes();
}
}

Expand Down Expand Up @@ -1291,7 +1264,6 @@ void AreaListEnsureDataHydroPrepro(AreaList* l)

void AreaListEnsureDataThermalPrepro(AreaList* l)
{
assert(l && "The area list must not be nullptr");
l->each([&](Data::Area& area) { area.thermal.list.ensureDataPrepro(); });
}

Expand Down Expand Up @@ -1529,8 +1501,7 @@ ThermalCluster* AreaList::findClusterFromINIKey(const AnyString& key)
Area* parentArea = findFromName(parentName);
if (parentArea == nullptr)
return nullptr;
return parentArea->thermal.list.find(id);

return parentArea->thermal.list.findInAll(id);
}

void AreaList::updateNameIDSet() const
Expand Down Expand Up @@ -1569,8 +1540,8 @@ void AreaList::removeWindTimeseries()
void AreaList::removeThermalTimeseries()
{
each([](Data::Area& area) {
area.thermal.list.each(
[](Data::ThermalCluster& cluster) { cluster.series.reset(); });
for (auto c : area.thermal.list.all())
c->series.reset();
});
}

Expand Down
1 change: 0 additions & 1 deletion src/libs/antares/study/area/store-timeseries-numbers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ void storeTimeseriesNumbersForWind(Solver::IResultWriter& writer, const Area& ar
void storeTimeseriesNumbersForThermal(Solver::IResultWriter& writer, const Area& area)
{
area.thermal.list.storeTimeseriesNumbers(writer);
area.thermal.mustrunList.storeTimeseriesNumbers(writer);
}

void storeTimeseriesNumbersForRenewable(Solver::IResultWriter& writer, const Area& area)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ void BindingConstraint::copyWeights(const Study &study,
if (localParent)
{
const ThermalCluster *localTC
= localParent->thermal.list.find(thermalCluster->id());
= localParent->thermal.list.findInAll(thermalCluster->id());
if (localTC)
pClusterWeights[localTC] = weight;
}
Expand Down Expand Up @@ -329,7 +329,7 @@ void BindingConstraint::copyOffsets(const Study &study,
if (localParent)
{
const ThermalCluster *localTC
= localParent->thermal.list.find(thermalCluster->id());
= localParent->thermal.list.findInAll(thermalCluster->id());
if (localTC)
pClusterOffsets[localTC] = offset;
}
Expand Down
6 changes: 3 additions & 3 deletions src/libs/antares/study/cleaner/cleaner-v20.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ static void listOfFilesAnDirectoriesToKeepForArea(PathList& e, PathList& p, cons
buffer.clear() << "input/thermal/clusters/" << id << "/list.ini";
e.add(buffer);

for (const auto& cluster : area->thermal.list)
for (auto cluster : area->thermal.list.all())
{
buffer.clear() << "input/thermal/prepro/" << id << '/' << cluster->id();
p.add(buffer);
Expand Down Expand Up @@ -156,7 +156,7 @@ static void listOfFilesAnDirectoriesToKeepForArea(PathList& e, PathList& p, cons
buffer.clear() << "input/renewables/clusters/" << id << "/list.ini";
e.add(buffer);

for (const auto& cluster : area->renewable.list)
for (const auto cluster : area->renewable.list.all())
{
buffer.clear() << "input/renewables/series/" << id << '/' << cluster->id();
p.add(buffer);
Expand Down Expand Up @@ -345,7 +345,7 @@ bool listOfFilesAnDirectoriesToKeep(StudyCleaningInfos* infos)
// Exclude
listOfFilesAnDirectoriesToKeepForArea(e, p, area, buffer);
// Clear the memory used by the thermal clusters of the area
area->thermal.list.clear();
area->thermal.list.clearAll();

// Interconnections
{
Expand Down
7 changes: 0 additions & 7 deletions src/libs/antares/study/include/antares/study/load-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ class StudyLoadOptions
StudyLoadOptions();
//@}

//! Push a new log entry according to the local progress data
void pushProgressLogs() const;

void checkForceSimulationMode();

public:
Expand Down Expand Up @@ -89,10 +86,6 @@ class StudyLoadOptions

//! Temporary string for passing log message
mutable Yuni::String logMessage;
//! Porgression, tick count
mutable uint progressTickCount;
//! The current number of ticks
mutable uint progressTicks;

//! Display version number and exit
bool displayVersion = false;
Expand Down
Loading

0 comments on commit b181904

Please sign in to comment.