Skip to content

Commit

Permalink
Remove sts container (#1804)
Browse files Browse the repository at this point in the history
Remove storageById
  • Loading branch information
payetvin authored Dec 11, 2023
1 parent 4b8b7a9 commit d2092b5
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ bool STStorageCluster::loadFromSection(const IniFile::Section& section)
return true;
}

bool STStorageCluster::validate()
bool STStorageCluster::validate() const
{
logs.debug() << "Validating properties and series for st storage: " << id;
return properties.validate() && series->validate();
Expand Down
4 changes: 2 additions & 2 deletions src/libs/antares/study/parts/short-term-storage/cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace Antares::Data::ShortTermStorage
class STStorageCluster
{
public:
bool validate();
bool validate() const;
bool loadFromSection(const IniFile::Section& section);

bool loadSeries(const std::string& folder) const;
Expand All @@ -48,7 +48,7 @@ class STStorageCluster
std::string id;

std::shared_ptr<Series> series = std::make_shared<Series>();
Properties properties;
mutable Properties properties;

};
} // namespace Antares::Data::ShortTermStorage
19 changes: 10 additions & 9 deletions src/libs/antares/study/parts/short-term-storage/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <antares/logs/logs.h>
#include <yuni/io/file.h>
#include <filesystem>
#include <algorithm>
#include <string>

#include "container.h"
Expand All @@ -39,7 +40,7 @@ namespace Antares::Data::ShortTermStorage
bool STStorageInput::validate() const
{
return std::all_of(storagesByIndex.cbegin(), storagesByIndex.cend(), [](auto& cluster) {
return cluster->validate();
return cluster.validate();
});
}

Expand All @@ -61,12 +62,12 @@ bool STStorageInput::createSTStorageClustersFromIniFile(const std::string& path)
if (!cluster.loadFromSection(*section))
return false;

storagesById.try_emplace(cluster.properties.name, cluster);
storagesByIndex.push_back(cluster);
}

storagesByIndex.reserve(storagesById.size());
for (auto& [id, storage] : storagesById)
storagesByIndex.push_back(&storage);
std::sort(storagesByIndex.begin(), storagesByIndex.end(), [&](const auto& a, const auto& b){
return a.properties.name < b.properties.name;
});

return true;
}
Expand All @@ -80,8 +81,8 @@ bool STStorageInput::loadSeriesFromFolder(const std::string& folder) const

for (auto& cluster : storagesByIndex)
{
const std::string buffer(folder + SEP + cluster->id);
ret = cluster->loadSeries(buffer) && ret;
const std::string buffer(folder + SEP + cluster.id);
ret = cluster.loadSeries(buffer) && ret;
}

return ret;
Expand All @@ -95,15 +96,15 @@ bool STStorageInput::saveToFolder(const std::string& folder) const
logs.notice() << "created empty ini: " << folder + SEP + "list.ini";

return std::all_of(storagesByIndex.cbegin(), storagesByIndex.cend(), [&folder](auto& storage) {
return storage->saveProperties(folder);
return storage.saveProperties(folder);
});
}

bool STStorageInput::saveDataSeriesToFolder(const std::string& folder) const
{
Yuni::IO::Directory::Create(folder);
return std::all_of(storagesByIndex.cbegin(), storagesByIndex.cend(), [&folder](auto& storage) {
return storage->saveSeries(folder + SEP + storage->id);
return storage.saveSeries(folder + SEP + storage.id);
});
}

Expand Down
4 changes: 1 addition & 3 deletions src/libs/antares/study/parts/short-term-storage/container.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ class STStorageInput
bool saveToFolder(const std::string& folder) const;
bool saveDataSeriesToFolder(const std::string& folder) const;


std::vector<STStorageCluster*> storagesByIndex;
std::map<std::string, STStorageCluster> storagesById;
std::vector<STStorageCluster> storagesByIndex;
};
} // namespace Antares::Data::ShortTermStorage
18 changes: 9 additions & 9 deletions src/solver/simulation/sim_calcul_economique.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ static void importShortTermStorages(
toInsert.clusterGlobalIndex = clusterGlobalIndex;

// Properties
toInsert.reservoirCapacity = st->properties.reservoirCapacity.value();
toInsert.efficiency = st->properties.efficiencyFactor;
toInsert.injectionNominalCapacity = st->properties.injectionNominalCapacity.value();
toInsert.withdrawalNominalCapacity = st->properties.withdrawalNominalCapacity.value();
toInsert.initialLevel = st->properties.initialLevel;
toInsert.initialLevelOptim = st->properties.initialLevelOptim;
toInsert.name = st->properties.name;

toInsert.series = st->series;
toInsert.reservoirCapacity = st.properties.reservoirCapacity.value();
toInsert.efficiency = st.properties.efficiencyFactor;
toInsert.injectionNominalCapacity = st.properties.injectionNominalCapacity.value();
toInsert.withdrawalNominalCapacity = st.properties.withdrawalNominalCapacity.value();
toInsert.initialLevel = st.properties.initialLevel;
toInsert.initialLevelOptim = st.properties.initialLevelOptim;
toInsert.name = st.properties.name;

toInsert.series = st.series;

// TODO add missing properties, or use the same struct
storageIndex++;
Expand Down
4 changes: 2 additions & 2 deletions src/solver/variable/economy/STStorageCashFlowByCluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ class STstorageCashFlowByCluster : public Variable::IVariable<STstorageCashFlowB
for (uint clusterIndex = 0; clusterIndex < nbClusters_; ++clusterIndex)
{
// Write the data for the current year
const auto* cluster = shortTermStorage.storagesByIndex[clusterIndex];
results.variableCaption = cluster->properties.name;
const auto& cluster = shortTermStorage.storagesByIndex[clusterIndex];
results.variableCaption = cluster.properties.name;
results.variableUnit = VCardType::Unit();
pValuesForTheCurrentYear[numSpace][clusterIndex]
.template buildAnnualSurveyReport<VCardType>(results, fileLevel, precision);
Expand Down
4 changes: 2 additions & 2 deletions src/solver/variable/economy/STStorageInjectionByCluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ class STstorageInjectionByCluster : public Variable::IVariable<STstorageInjectio
for (uint clusterIndex = 0; clusterIndex < nbClusters_; ++clusterIndex)
{
// Write the data for the current year
const auto* cluster = shortTermStorage.storagesByIndex[clusterIndex];
results.variableCaption = cluster->properties.name;
const auto& cluster = shortTermStorage.storagesByIndex[clusterIndex];
results.variableCaption = cluster.properties.name;
results.variableUnit = VCardType::Unit();
pValuesForTheCurrentYear[numSpace][clusterIndex]
.template buildAnnualSurveyReport<VCardType>(results, fileLevel, precision);
Expand Down
4 changes: 2 additions & 2 deletions src/solver/variable/economy/STStorageLevelsByCluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ class STstorageLevelsByCluster
for (uint clusterIndex = 0; clusterIndex < nbClusters_; ++clusterIndex)
{
// Write the data for the current year
const auto* cluster = shortTermStorage.storagesByIndex[clusterIndex];
results.variableCaption = cluster->properties.name;
const auto& cluster = shortTermStorage.storagesByIndex[clusterIndex];
results.variableCaption = cluster.properties.name;
results.variableUnit = VCardType::Unit();
pValuesForTheCurrentYear[numSpace][clusterIndex].template buildAnnualSurveyReport<VCardType>(
results, fileLevel, precision);
Expand Down
4 changes: 2 additions & 2 deletions src/solver/variable/economy/STStorageWithdrawalByCluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ class STstorageWithdrawalByCluster
for (uint clusterIndex = 0; clusterIndex < nbClusters_; ++clusterIndex)
{
// Write the data for the current year
const auto* cluster = shortTermStorage.storagesByIndex[clusterIndex];
results.variableCaption = cluster->properties.name;
const auto& cluster = shortTermStorage.storagesByIndex[clusterIndex];
results.variableCaption = cluster.properties.name;
results.variableUnit = VCardType::Unit();
pValuesForTheCurrentYear[numSpace][clusterIndex].template buildAnnualSurveyReport<VCardType>(
results, fileLevel, precision);
Expand Down
4 changes: 2 additions & 2 deletions src/solver/variable/economy/shortTermStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ class ShortTermStorageByGroup
using namespace Antares::Data::ShortTermStorage;
for (uint stsIndex = 0; stsIndex < state.area->shortTermStorage.count(); stsIndex++)
{
const auto* cluster = state.area->shortTermStorage.storagesByIndex[stsIndex];
const uint group = groupIndex(cluster->properties.group);
const auto& cluster = state.area->shortTermStorage.storagesByIndex[stsIndex];
const uint group = groupIndex(cluster.properties.group);

// Injection
pValuesForTheCurrentYear[numSpace][3 * group][state.hourInTheYear]
Expand Down
2 changes: 1 addition & 1 deletion src/solver/variable/info.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ struct VariableAccessor<ResultsT, Category::dynamicColumns>
if (st_storage_details)
{
auto& st_storage_part = results.data.area->shortTermStorage;
results.variableCaption = st_storage_part.storagesByIndex[idx]->properties.name;
results.variableCaption = st_storage_part.storagesByIndex[idx].properties.name;
return true;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ BOOST_FIXTURE_TEST_CASE(check_container_properties_load, Fixture)
createIniFile();

BOOST_CHECK(container.createSTStorageClustersFromIniFile(folder));
BOOST_CHECK(container.storagesByIndex[0]->properties.validate());
BOOST_CHECK(container.storagesByIndex[0].properties.validate());

removeIniFile();
}
Expand All @@ -259,7 +259,7 @@ BOOST_FIXTURE_TEST_CASE(check_container_properties_wrong_value, Fixture)
createIniFileWrongValue();

BOOST_CHECK(container.createSTStorageClustersFromIniFile(folder));
BOOST_CHECK(!container.storagesByIndex[0]->properties.validate());
BOOST_CHECK(!container.storagesByIndex[0].properties.validate());

removeIniFile();
}
Expand Down

0 comments on commit d2092b5

Please sign in to comment.