Skip to content

Commit

Permalink
Add enabled property to ST storage objects, fix bug in save (#1839)
Browse files Browse the repository at this point in the history
Co-authored-by: Vincent Payet <[email protected]>
Co-authored-by: payetvin <[email protected]>
  • Loading branch information
3 people authored Dec 21, 2023
1 parent 326068f commit 51d6bd4
Show file tree
Hide file tree
Showing 15 changed files with 125 additions and 58 deletions.
12 changes: 10 additions & 2 deletions src/libs/antares/study/parts/short-term-storage/cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,16 @@ bool STStorageCluster::loadFromSection(const IniFile::Section& section)
return true;
}

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();
}
Expand All @@ -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.save(ini);
}

bool STStorageCluster::saveSeries(const std::string& path) const
Expand Down
5 changes: 3 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,12 +37,13 @@ namespace Antares::Data::ShortTermStorage
class STStorageCluster
{
public:
bool enabled() const;
bool validate() const;
bool loadFromSection(const IniFile::Section& section);

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;
Expand Down
29 changes: 24 additions & 5 deletions src/libs/antares/study/parts/short-term-storage/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,15 @@ 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
Expand All @@ -110,6 +113,22 @@ bool STStorageInput::saveDataSeriesToFolder(const std::string& folder) const

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
9 changes: 6 additions & 3 deletions src/libs/antares/study/parts/short-term-storage/container.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@ 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;
Expand Down
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
Expand Up @@ -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::save(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);
Expand All @@ -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()
Expand Down
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
Expand Up @@ -54,25 +54,28 @@ class Properties
public:
bool validate();
bool loadKey(const IniFile::Property* p);
bool saveToFolder(const std::string& folder) const;
void save(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;
Expand Down
10 changes: 10 additions & 0 deletions src/libs/antares/study/runtime/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ bool StudyRuntimeInfos::loadFromStudy(Study& study)
// Removing disabled thermal clusters from solver computations
removeDisabledThermalClustersFromSolverComputations(study);

// Removing disabled short-term storage objects from solver computations
removeDisabledShortTermStorageClustersFromSolverComputations(study);

switch (gd.renewableGeneration())
{
case rgClusters:
Expand Down Expand Up @@ -423,6 +426,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(
Expand Down
1 change: 1 addition & 0 deletions src/libs/antares/study/runtime/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions src/solver/variable/economy/STStorageCashFlowByCluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.variableUnit = VCardType::Unit();
pValuesForTheCurrentYear[numSpace][clusterIndex]
.template buildAnnualSurveyReport<VCardType>(results, fileLevel, precision);

clusterIndex++;
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/solver/variable/economy/STStorageInjectionByCluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.variableUnit = VCardType::Unit();
pValuesForTheCurrentYear[numSpace][clusterIndex]
.template buildAnnualSurveyReport<VCardType>(results, fileLevel, precision);

clusterIndex++;
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/solver/variable/economy/STStorageLevelsByCluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.variableUnit = VCardType::Unit();
pValuesForTheCurrentYear[numSpace][clusterIndex].template buildAnnualSurveyReport<VCardType>(
results, fileLevel, precision);

clusterIndex++;
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/solver/variable/economy/STStorageWithdrawalByCluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.variableUnit = VCardType::Unit();
pValuesForTheCurrentYear[numSpace][clusterIndex].template buildAnnualSurveyReport<VCardType>(
results, fileLevel, precision);

clusterIndex++;
}
}
}
Expand Down
15 changes: 9 additions & 6 deletions src/solver/variable/economy/shortTermStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,22 +235,25 @@ class ShortTermStorageByGroup
void hourForEachArea(State& state, unsigned int numSpace)
{
using namespace Antares::Data::ShortTermStorage;
for (uint stsIndex = 0; stsIndex < state.area->shortTermStorage.count(); stsIndex++)
const auto& shortTermStorage = state.area->shortTermStorage;

// Write the data for the current year
uint clusterIndex = 0;
for (const auto& cluster : shortTermStorage.storagesByIndex)
{
const auto& cluster = state.area->shortTermStorage.storagesByIndex[stsIndex];
const uint group = groupIndex(cluster.properties.group);

// Injection
pValuesForTheCurrentYear[numSpace][3 * group][state.hourInTheYear]
+= state.hourlyResults->ShortTermStorage[state.hourInTheWeek].injection[stsIndex];
+= state.hourlyResults->ShortTermStorage[state.hourInTheWeek].injection[clusterIndex];

// Withdrawal
pValuesForTheCurrentYear[numSpace][3 * group + 1][state.hourInTheYear]
+= state.hourlyResults->ShortTermStorage[state.hourInTheWeek].withdrawal[stsIndex];
+= state.hourlyResults->ShortTermStorage[state.hourInTheWeek].withdrawal[clusterIndex];

// Levels
pValuesForTheCurrentYear[numSpace][3 * group + 2][state.hourInTheYear]
+= state.hourlyResults->ShortTermStorage[state.hourInTheWeek].level[stsIndex];
+= state.hourlyResults->ShortTermStorage[state.hourInTheWeek].level[clusterIndex];
clusterIndex++;
}

// Next item in the list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set(src_libs_antares_study "${CMAKE_SOURCE_DIR}/libs/antares/study")
# Tests on reading scenario-builder
# ====================================
set(SRC_SC_BUILDER_READ
short-term-storage-input.cpp
short-term-storage-input-output.cpp
)
add_executable(short-term-storage-input ${SRC_SC_BUILDER_READ})

Expand Down
Loading

0 comments on commit 51d6bd4

Please sign in to comment.