Skip to content

Commit

Permalink
Clean thermal lists : simplifying added(...) function (common list cl…
Browse files Browse the repository at this point in the history
…ass) and consequences
  • Loading branch information
guilpier-code committed Dec 22, 2023
1 parent fbf0ade commit ee1e5f5
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 38 deletions.
10 changes: 2 additions & 8 deletions src/libs/antares/study/parts/common/cluster_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,12 @@ void ClusterList<ClusterT>::rebuildIndex()
}

template<class ClusterT>
typename ClusterList<ClusterT>::SharedPtr ClusterList<ClusterT>::add(
const ClusterList<ClusterT>::SharedPtr newcluster)
void ClusterList<ClusterT>::add(const SharedPtr newcluster)
{
if (!newcluster)
return nullptr;

if (exists(newcluster->id()))
return newcluster;

return;
clusters.push_back(newcluster);
rebuildIndex();
return newcluster;
}

template<class ClusterT>
Expand Down
2 changes: 1 addition & 1 deletion src/libs/antares/study/parts/common/cluster_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ClusterList
** \param t The cluster to add
** \return True if the cluster has been added, false otherwise
*/
SharedPtr add(const SharedPtr clusters);
void add(const SharedPtr clusters);

/*!
** \brief Try to find a cluster from its id (const)
Expand Down
8 changes: 1 addition & 7 deletions src/libs/antares/study/parts/renewable/cluster_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,7 @@ bool RenewableClusterList::loadFromFolder(const AnyString& folder, Area* area)
cluster->integrityCheck();

// adding the renewable cluster
if (not add(cluster))
{
// This error should never happen
logs.error() << "Impossible to add the renewable cluster '" << cluster->name()
<< "'";
continue;
}
add(cluster);
}
}

Expand Down
12 changes: 3 additions & 9 deletions src/libs/antares/study/parts/thermal/cluster_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,10 @@ bool ThermalClusterList::loadFromFolder(Study& study, const AnyString& folder, A
cluster->integrityCheck();

// adding the thermal cluster
auto added = add(cluster);
if (not added)
{
// This error should never happen
logs.error() << "Impossible to add the thermal cluster '" << cluster->name()
<< "'";
continue;
}
add(cluster);

// keeping track of the cluster
mapping[cluster->id()] = added;
mapping[cluster->id()] = cluster;
}

return ret;
Expand Down
15 changes: 4 additions & 11 deletions src/libs/antares/study/parts/thermal/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,10 @@ uint PartThermal::prepareClustersInMustRunMode()
if (!cluster->enabled)
continue;
// ...and attaching it into the second list
if (!mustrunList.add(cluster))
{
logs.error() << "Impossible to prepare the thermal cluster in 'must-run' mode: "
<< cluster->parentArea->name << "::" << cluster->name();
}
else
{
++count;
logs.info() << "enabling 'must-run' mode for the cluster "
<< cluster->parentArea->name << "::" << cluster->name();
}
mustrunList.add(cluster);
++count;
logs.info() << "enabling 'must-run' mode for the cluster "
<< cluster->parentArea->name << "::" << cluster->name();

// the iterator has been invalidated, loop again
mustContinue = true;
Expand Down
4 changes: 2 additions & 2 deletions src/tests/end-to-end/utils/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ std::shared_ptr<ThermalCluster> addClusterToArea(Area* area, const std::string&
cluster->setName(clusterName);
cluster->reset();

auto added = area->thermal.list.add(cluster);
area->thermal.list.add(cluster);

area->thermal.list.mapping[cluster->id()] = added;
area->thermal.list.mapping[cluster->id()] = cluster;
area->thermal.prepareAreaWideIndexes();

return cluster;
Expand Down

0 comments on commit ee1e5f5

Please sign in to comment.