Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
a-zakir committed Dec 13, 2024
1 parent 0cfd4ab commit b5b63a3
Show file tree
Hide file tree
Showing 13 changed files with 199 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,8 @@ namespace Antares::Data::ShortTermStorage {
bool saveDataSeriesToFolder(const std::string &folder) const;

std::vector<STStorageCluster> storagesByIndex;

/// Number cumulative - constraint
std::size_t cumulativeConstraintCount() const;
};
} // namespace Antares::Data::ShortTermStorage
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class StudyRuntimeInfos
uint thermalPlantTotalCountMustRun;

uint shortTermStorageCount = 0;
uint shortTermStorageCumulativeConstraintCount = 0;

//! Override enable/disable TS generation per cluster
bool thermalTSRefresh = false;
Expand Down
9 changes: 9 additions & 0 deletions src/libs/antares/study/parts/short-term-storage/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,15 @@ bool STStorageInput::saveDataSeriesToFolder(const std::string& folder) const
{ return storage.saveSeries(folder + SEP + storage.id); });
}

std::size_t STStorageInput::cumulativeConstraintCount() const
{
size_t result = 0;
for (const auto& cluster: storagesByIndex)
{
result += cluster.additional_constraints.size();
}
}

std::size_t STStorageInput::count() const
{
return std::ranges::count_if(storagesByIndex,
Expand Down
2 changes: 2 additions & 0 deletions src/libs/antares/study/runtime/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ static void StudyRuntimeInfosInitializeAllAreas(Study& study, StudyRuntimeInfos&
r.thermalPlantTotalCountMustRun += area.thermal.list.enabledAndMustRunCount();

r.shortTermStorageCount += area.shortTermStorage.count();
r.shortTermStorageCumulativeConstraintCount += area.shortTermStorage.
cumulativeConstraintCount();
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/solver/optimisation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ set(RTESOLVER_OPT
include/antares/solver/optimisation/constraints/ShortTermStorageLevel.h
constraints/ShortTermStorageLevel.cpp
include/antares/solver/optimisation/constraints/ShortTermStorageCostVariation.h
include/antares/solver/optimisation/constraints/ShortTermStorageCumulation.h
constraints/ShortTermStorageCostVariation.cpp
constraints/ShortTermStorageCumulation.cpp
constraints/ShortTermStorageCostVariationInjectionForward.cpp
constraints/ShortTermStorageCostVariationInjectionBackward.cpp
constraints/ShortTermStorageCostVariationWithdrawalForward.cpp
Expand Down
94 changes: 94 additions & 0 deletions src/solver/optimisation/constraints/ShortTermStorageCumulation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright 2007-2024, RTE (https://www.rte-france.com)
* See AUTHORS.txt
* SPDX-License-Identifier: MPL-2.0
* This file is part of Antares-Simulator,
* Adequacy and Performance assessment for interconnected energy networks.
*
* Antares_Simulator is free software: you can redistribute it and/or modify
* it under the terms of the Mozilla Public Licence 2.0 as published by
* the Mozilla Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* Antares_Simulator is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Mozilla Public Licence 2.0 for more details.
*
* You should have received a copy of the Mozilla Public Licence 2.0
* along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
*/

#pragma once
#include "antares/solver/optimisation/constraints/ShortTermStorageCumulation.h"

void ShortTermStorageCumulation::Injection(unsigned int index,
const ::ShortTermStorage::PROPERTIES& input
){
builder.ShortTermStorageInjection(index, 1.0);
}
void ShortTermStorageCumulation::Withdrawal(unsigned int index,
const ::ShortTermStorage::PROPERTIES& input
){
builder.ShortTermStorageWithdrawal(index, 1.0);}
void ShortTermStorageCumulation::Netting(unsigned int index,
const ::ShortTermStorage::PROPERTIES& input){


builder.ShortTermStorageInjection(index, input.injectionEfficiency ).
ShortTermStorageWithdrawal(index, -input.withdrawalEfficiency);
}
auto getMemberFunction = [](const std::string& name)
-> void (ShortTermStorageCumulation::*)(unsigned int,
const ::ShortTermStorage::PROPERTIES& ) {
if (name == "withdrawal") {
return &ShortTermStorageCumulation::Withdrawal;
} else if (name == "injection") {
return &ShortTermStorageCumulation::Injection;
}
else if (name == "netting"){
return &ShortTermStorageCumulation::Netting;
}
return nullptr; // Return null if no match
};


char ConvertSign(const std::string& sign){
if (sign == "greater") {
return '>';
}
else if (sign == "less") {
return '<';
}
else {
return '=';
}
}

void ShortTermStorageCumulation::add(int pays){

ConstraintNamer namer(builder.data.NomDesContraintes);
namer.UpdateArea(builder.data.NomsDesPays[pays]);

for (const auto& storage: data.ShortTermStorage[pays])
{
for(const auto& constraint: storage.additional_constraints){

//sum (var[h]) sign rhs, h in list provied by user

namer.ShortTermStorageLevel(builder.data.nombreDeContraintes, storage.name);
const auto index = storage.clusterGlobalIndex;
//TODO
data.CorrespondanceCntNativesCntOptimHebdomadaires.ShortTermStorageCumulation[index]
= builder.data.nombreDeContraintes;
auto memberFunction = getMemberFunction(constraint.variable);
for (const auto& hour: constraint.hours){
const int hourInTheYear = builder.data.weekInTheYear * 168 + hour-1;
builder.updateHourWithinWeek(hour-1);
(this->*memberFunction)(index, storage);
builder.SetOperator(ConvertSign(constraint.operatorType))
.build();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,8 @@ struct ShortTermStorageData

const std::vector<::ShortTermStorage::AREA_INPUT>& ShortTermStorage;
};

struct ShortTermStorageCumulativeConstraintData: ShortTermStorageData
{
CORRESPONDANCES_DES_CONTRAINTES_HEBDOMADAIRES CorrespondanceCntNativesCntOptimHebdomadaires;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2007-2024, RTE (https://www.rte-france.com)
* See AUTHORS.txt
* SPDX-License-Identifier: MPL-2.0
* This file is part of Antares-Simulator,
* Adequacy and Performance assessment for interconnected energy networks.
*
* Antares_Simulator is free software: you can redistribute it and/or modify
* it under the terms of the Mozilla Public Licence 2.0 as published by
* the Mozilla Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* Antares_Simulator is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Mozilla Public Licence 2.0 for more details.
*
* You should have received a copy of the Mozilla Public Licence 2.0
* along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
*/

#pragma once
#include "ConstraintBuilder.h"

class ShortTermStorageCumulation: private ConstraintFactory
{
public:
ShortTermStorageCumulation(ConstraintBuilder& builder, ShortTermStorageCumulativeConstraintData& data):
ConstraintFactory(builder),
data(data)
{
}

void add(int pays);
void Injection(unsigned int index,
const ::ShortTermStorage::PROPERTIES& input);
void Withdrawal(unsigned int index,
const ::ShortTermStorage::PROPERTIES& input);
void Netting(unsigned int index,
const ::ShortTermStorage::PROPERTIES& input);

private:
ShortTermStorageCumulativeConstraintData& data;
};
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ class ConstraintNamer: public Namer
unsigned int constraint,
const std::string& short_term_name);

void ShortTermStorageCumulation(const std::string& constraint_type,
unsigned int constraint,
const std::string& short_term_name,
const std::string& constraint_name);

private:
void nameWithTimeGranularity(unsigned int constraint,
const std::string& name,
Expand All @@ -177,6 +182,11 @@ inline std::string TimeIdentifier(unsigned int timeStep, const std::string& time
return timeStepType + "<" + std::to_string(timeStep) + ">";
}

inline std::string ShortTermStorageCumulationIdentifier(const std::string& name)
{
return "Constraint<" + name + ">";
}

inline std::string LocationIdentifier(const std::string& location, const std::string& locationType)
{
return locationType + "<" + location + ">";
Expand Down
18 changes: 16 additions & 2 deletions src/solver/optimisation/opt_rename_problem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ const std::string AREA("area");

std::string BuildName(const std::string& name,
const std::string& location,
const std::string& timeIdentifier)
const std::string& additional_identifier)
{
std::string result = name + SEPARATOR + location + SEPARATOR + timeIdentifier;
std::string result = name + SEPARATOR + location + SEPARATOR + additional_identifier;
std::replace(result.begin(), result.end(), ' ', '*');
return result;
}
Expand Down Expand Up @@ -414,3 +414,17 @@ void ConstraintNamer::ShortTermStorageCostVariation(const std::string& constrain
TimeIdentifier(timeStep_, HOUR)),
constraint);
}

void ConstraintNamer::ShortTermStorageCumulation(const std::string& constraint_type,
unsigned int constraint,
const std::string& short_term_name,
const std::string& constraint_name)
{
targetUpdater_.UpdateTargetAtIndex(BuildName(constraint_type,
LocationIdentifier(area_, AREA) + SEPARATOR
+ "ShortTermStorage" + "<" + short_term_name
+ ">",
ShortTermStorageCumulationIdentifier(
constraint_name)),
constraint);
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ void SIM_AllocationLinks(PROBLEME_HEBDO& problem,
void SIM_AllocationConstraints(PROBLEME_HEBDO& problem,
const Antares::Data::Study& study,
unsigned NombreDePasDeTemps);
void SIM_AllocationShortermStorageCumulation(PROBLEME_HEBDO& problem,
const Antares::Data::Study& study);

void SIM_AllocateAreas(PROBLEME_HEBDO& problem,
const Antares::Data::Study& study,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ struct CORRESPONDANCES_DES_CONTRAINTES_JOURNALIERES
struct CORRESPONDANCES_DES_CONTRAINTES_HEBDOMADAIRES
{
std::vector<int> NumeroDeContrainteDesContraintesCouplantes;
std::vector<int> ShortTermStorageCumulation;
};

struct VALEURS_DE_NTC_ET_RESISTANCES
Expand Down
10 changes: 10 additions & 0 deletions src/solver/simulation/sim_alloc_probleme_hebdo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ void SIM_AllocationProblemeHebdo(const Data::Study& study,
SIM_AllocationProblemePasDeTemps(problem, study, NombreDePasDeTemps);
SIM_AllocationLinks(problem, study.runtime.interconnectionsCount(), NombreDePasDeTemps);
SIM_AllocationConstraints(problem, study, NombreDePasDeTemps);
SIM_AllocationShortermStorageCumulation(problem, study);
SIM_AllocateAreas(problem, study, NombreDePasDeTemps);
}
catch (const std::bad_alloc& e)
Expand Down Expand Up @@ -245,6 +246,15 @@ void SIM_AllocationLinks(PROBLEME_HEBDO& problem, const uint linkCount, unsigned
}
}

void SIM_AllocationShortermStorageCumulation(PROBLEME_HEBDO& problem,
const Antares::Data::Study& study)
{
problem.CorrespondanceCntNativesCntOptimHebdomadaires
.ShortTermStorageCumulation.assign(
study.runtime.shortTermStorageCumulativeConstraintCount,
0);
}

void SIM_AllocationConstraints(PROBLEME_HEBDO& problem,
const Antares::Data::Study& study,
unsigned NombreDePasDeTemps)
Expand Down

0 comments on commit b5b63a3

Please sign in to comment.