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

Add enabled property for ST storage objects, fix bug related to saving ST objects #1807

Merged
merged 20 commits into from
Dec 19, 2023
Merged
Changes from 15 commits
Commits
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
14 changes: 11 additions & 3 deletions src/libs/antares/study/parts/short-term-storage/cluster.cpp
Original file line number Diff line number Diff line change
@@ -63,8 +63,16 @@ bool STStorageCluster::loadFromSection(const IniFile::Section& section)
return true;
}

bool STStorageCluster::validate()
bool STStorageCluster::enabled() const
{
return properties.enabled;
}

bool STStorageCluster::validate() const
{
if (!enabled())
return true;

logs.debug() << "Validating properties and series for st storage: " << id;
return properties.validate() && series->validate();
}
@@ -76,9 +84,9 @@ bool STStorageCluster::loadSeries(const std::string& folder) const
return ret;
}

bool STStorageCluster::saveProperties(const std::string& path) const
void STStorageCluster::saveProperties(IniFile& ini) const
{
return properties.saveToFolder(path);
properties.saveToFolder(ini);
}

bool STStorageCluster::saveSeries(const std::string& path) const
9 changes: 5 additions & 4 deletions src/libs/antares/study/parts/short-term-storage/cluster.h
Original file line number Diff line number Diff line change
@@ -37,18 +37,19 @@ namespace Antares::Data::ShortTermStorage
class STStorageCluster
{
public:
bool validate();
bool loadFromSection(const IniFile::Section& section);
bool enabled() const;
bool validate() const;

bool loadFromSection(const IniFile::Section& section);
bool loadSeries(const std::string& folder) const;

bool saveProperties(const std::string& path) const;
void saveProperties(IniFile& ini) const;
bool saveSeries(const std::string& path) const;

std::string id;

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

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

#include "container.h"
@@ -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();
});
}

@@ -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;
}
@@ -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;
@@ -91,24 +92,44 @@ bool STStorageInput::saveToFolder(const std::string& folder) const
{
// create empty list.ini if there's no sts in this area
Yuni::IO::Directory::Create(folder);
Yuni::IO::File::CreateEmptyFile(folder + SEP + "list.ini");
logs.notice() << "created empty ini: " << folder + SEP + "list.ini";
const std::string pathIni(folder + SEP + "list.ini");
IniFile ini;

return std::all_of(storagesByIndex.cbegin(), storagesByIndex.cend(), [&folder](auto& storage) {
return storage->saveProperties(folder);
logs.debug() << "saving file " << pathIni;

std::for_each(storagesByIndex.cbegin(), storagesByIndex.cend(), [&ini](auto& storage) {
return storage.saveProperties(ini);
});

return ini.save(pathIni);
}

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);
});
}

std::size_t STStorageInput::count() const
{
return storagesByIndex.size();
return std::count_if(storagesByIndex.begin(),
storagesByIndex.end(),
[](const STStorageCluster& st) {
return st.properties.enabled;
});
}

uint STStorageInput::removeDisabledClusters()
{
const auto& it = std::remove_if(storagesByIndex.begin(), storagesByIndex.end(),
[](const auto& c) { return c.enabled(); });

uint disabledCount = std::distance(it, storagesByIndex.end());
storagesByIndex.erase(it, storagesByIndex.end());

return disabledCount;
}

} // namespace Antares::Data::ShortTermStorage
13 changes: 7 additions & 6 deletions src/libs/antares/study/parts/short-term-storage/container.h
Original file line number Diff line number Diff line change
@@ -36,18 +36,19 @@ class STStorageInput
{
public:
bool validate() const;
// 1. Read list.ini
/// 1. Read list.ini
bool createSTStorageClustersFromIniFile(const std::string& path);
// 2. Read ALL series
/// 2. Read ALL series
bool loadSeriesFromFolder(const std::string& folder) const;
// Number of ST storages
/// Number of enabled ST storages, ignoring disabled ST storages
std::size_t count() const;
/// erase disabled cluster from the vector
uint removeDisabledClusters();


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
21 changes: 5 additions & 16 deletions src/libs/antares/study/parts/short-term-storage/properties.cpp
Original file line number Diff line number Diff line change
@@ -115,23 +115,14 @@ bool Properties::loadKey(const IniFile::Property* p)
return false;
}

if (p->key == "enabled")
return p->value.to<bool>(this->enabled);

return false;
}

bool Properties::saveToFolder(const std::string& folder) const
void Properties::saveToFolder(IniFile& ini) const
{
const std::string pathIni(folder + SEP + "list.ini");

// Make sure the folder is created
if (!Yuni::IO::Directory::Create(folder))
{
logs.warning() << "Couldn't create dir for sts: " << folder;
return false;
}

logs.debug() << "saving file " << pathIni;

IniFile ini;
IniFile::Section* s = ini.addSection(this->name);

s->add("name", this->name);
@@ -147,9 +138,7 @@ bool Properties::saveToFolder(const std::string& folder) const

s->add("efficiency", this->efficiencyFactor);
s->add("initialleveloptim", this->initialLevelOptim);


return ini.save(pathIni);
s->add("enabled", this->enabled);
}

bool Properties::validate()
21 changes: 12 additions & 9 deletions src/libs/antares/study/parts/short-term-storage/properties.h
Original file line number Diff line number Diff line change
@@ -54,25 +54,28 @@ class Properties
public:
bool validate();
bool loadKey(const IniFile::Property* p);
bool saveToFolder(const std::string& folder) const;
void saveToFolder(IniFile& ini) const;

// Not optional Injection nominal capacity, >= 0
/// Not optional Injection nominal capacity, >= 0
std::optional<double> injectionNominalCapacity;
// Not optional Withdrawal nominal capacity, >= 0
/// Not optional Withdrawal nominal capacity, >= 0
std::optional<double> withdrawalNominalCapacity;
// Not optional Reservoir capacity in MWh, >= 0
/// Not optional Reservoir capacity in MWh, >= 0
std::optional<double> reservoirCapacity;
// Initial level, <= 1
/// Initial level, <= 1
double initialLevel = initiallevelDefault;
// Bool to optimise or not initial level
/// Bool to optimise or not initial level
bool initialLevelOptim = false;
// Efficiency factor between 0 and 1
/// Efficiency factor between 0 and 1
double efficiencyFactor = 1;
// Used to sort outputs
/// Used to sort outputs
Group group = Group::Other1;
// cluster name
/// cluster name
std::string name;

/// Enabled ?
bool enabled = true;

static const std::map<std::string, enum Group> ST_STORAGE_PROPERTY_GROUP_ENUM;
private:
static constexpr double initiallevelDefault = .5;
7 changes: 7 additions & 0 deletions src/libs/antares/study/runtime/runtime.cpp
Original file line number Diff line number Diff line change
@@ -423,6 +423,13 @@ void StudyRuntimeInfos::removeDisabledRenewableClustersFromSolverComputations(St
});
}

void StudyRuntimeInfos::removeDisabledShortTermStorageClustersFromSolverComputations(Study& study)
{
removeClusters(
study, "short term storage", [](Area& area)
{ return area.shortTermStorage.removeDisabledClusters(); });
}

void StudyRuntimeInfos::removeAllRenewableClustersFromSolverComputations(Study& study)
{
removeClusters(
1 change: 1 addition & 0 deletions src/libs/antares/study/runtime/runtime.h
Original file line number Diff line number Diff line change
@@ -138,6 +138,7 @@ class StudyRuntimeInfos
void initializeThermalClustersInMustRunMode(Study& study) const;
void removeDisabledThermalClustersFromSolverComputations(Study& study);
void removeDisabledRenewableClustersFromSolverComputations(Study& study);
void removeDisabledShortTermStorageClustersFromSolverComputations(Study& study);
void removeAllRenewableClustersFromSolverComputations(Study& study);
void disableAllFilters(Study& study);
void checkThermalTSGeneration(Study& study);
18 changes: 9 additions & 9 deletions src/solver/simulation/sim_calcul_economique.cpp
Original file line number Diff line number Diff line change
@@ -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++;
8 changes: 5 additions & 3 deletions src/solver/variable/economy/STStorageCashFlowByCluster.h
Original file line number Diff line number Diff line change
@@ -278,14 +278,16 @@ class STstorageCashFlowByCluster : public Variable::IVariable<STstorageCashFlowB
const auto& shortTermStorage = results.data.area->shortTermStorage;

// Write the data for the current year
for (uint clusterIndex = 0; clusterIndex < nbClusters_; ++clusterIndex)
uint clusterIndex = 0;
for (const auto& cluster : shortTermStorage.storagesByIndex)
{
// Write the data for the current year
const auto* cluster = shortTermStorage.storagesByIndex[clusterIndex];
results.variableCaption = cluster->properties.name;
results.variableCaption = cluster.properties.name;
results.variableUnit = VCardType::Unit();
pValuesForTheCurrentYear[numSpace][clusterIndex]
.template buildAnnualSurveyReport<VCardType>(results, fileLevel, precision);

clusterIndex++;
}
}
}
8 changes: 5 additions & 3 deletions src/solver/variable/economy/STStorageInjectionByCluster.h
Original file line number Diff line number Diff line change
@@ -280,14 +280,16 @@ class STstorageInjectionByCluster : public Variable::IVariable<STstorageInjectio
const auto& shortTermStorage = results.data.area->shortTermStorage;

// Write the data for the current year
for (uint clusterIndex = 0; clusterIndex < nbClusters_; ++clusterIndex)
uint clusterIndex = 0;
for (const auto& cluster : shortTermStorage.storagesByIndex)
{
// Write the data for the current year
const auto* cluster = shortTermStorage.storagesByIndex[clusterIndex];
results.variableCaption = cluster->properties.name;
results.variableCaption = cluster.properties.name;
results.variableUnit = VCardType::Unit();
pValuesForTheCurrentYear[numSpace][clusterIndex]
.template buildAnnualSurveyReport<VCardType>(results, fileLevel, precision);

clusterIndex++;
}
}
}
8 changes: 5 additions & 3 deletions src/solver/variable/economy/STStorageLevelsByCluster.h
Original file line number Diff line number Diff line change
@@ -280,14 +280,16 @@ class STstorageLevelsByCluster
const auto& shortTermStorage = results.data.area->shortTermStorage;

// Write the data for the current year
for (uint clusterIndex = 0; clusterIndex < nbClusters_; ++clusterIndex)
uint clusterIndex = 0;
for (const auto& cluster : shortTermStorage.storagesByIndex)
{
// Write the data for the current year
const auto* cluster = shortTermStorage.storagesByIndex[clusterIndex];
results.variableCaption = cluster->properties.name;
results.variableCaption = cluster.properties.name;
results.variableUnit = VCardType::Unit();
pValuesForTheCurrentYear[numSpace][clusterIndex].template buildAnnualSurveyReport<VCardType>(
results, fileLevel, precision);

clusterIndex++;
}
}
}
8 changes: 5 additions & 3 deletions src/solver/variable/economy/STStorageWithdrawalByCluster.h
Original file line number Diff line number Diff line change
@@ -280,14 +280,16 @@ class STstorageWithdrawalByCluster
const auto& shortTermStorage = results.data.area->shortTermStorage;

// Write the data for the current year
for (uint clusterIndex = 0; clusterIndex < nbClusters_; ++clusterIndex)
uint clusterIndex = 0;
for (const auto& cluster : shortTermStorage.storagesByIndex)
{
// Write the data for the current year
const auto* cluster = shortTermStorage.storagesByIndex[clusterIndex];
results.variableCaption = cluster->properties.name;
results.variableCaption = cluster.properties.name;
results.variableUnit = VCardType::Unit();
pValuesForTheCurrentYear[numSpace][clusterIndex].template buildAnnualSurveyReport<VCardType>(
results, fileLevel, precision);

clusterIndex++;
}
}
}
Loading