Skip to content

Commit

Permalink
New implementation for overriden apply function
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolaredstork authored and Milos-RTEi committed Jul 31, 2023
1 parent 53a7180 commit 46c36e8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
13 changes: 4 additions & 9 deletions src/libs/antares/study/scenario-builder/hydroLevelsData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ namespace Data
{
namespace ScenarioBuilder
{
hydroLevelsData::hydroLevelsData(std::string& iniFilePrefix) :
addToPrefix(iniFilePrefix)
hydroLevelsData::hydroLevelsData(std::string& iniFilePrefix,
std::function<void(Study&, MatrixType&)> applyToTarget) :
addToPrefix(iniFilePrefix), applyToTarget_(applyToTarget)
{
}

Expand Down Expand Up @@ -90,13 +91,7 @@ void hydroLevelsData::set_value(uint x, uint y, double value)

bool hydroLevelsData::apply(Study& study)
{
study.scenarioInitialHydroLevels.copyFrom(pHydroLevelsRules);
return true;
}

bool hydroLevelsData::applyHydroLevels(Matrix<double>& scenarioHydroLevels) const
{
scenarioHydroLevels.copyFrom(pHydroLevelsRules);
applyToTarget_(study, pHydroLevelsRules);
return true;
}

Expand Down
21 changes: 17 additions & 4 deletions src/libs/antares/study/scenario-builder/hydroLevelsData.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#define __LIBS_STUDY_SCENARIO_BUILDER_DATA_HYDRO_LEVELS_H__

#include "scBuilderDataInterface.h"
#include <functional>

namespace Antares
{
Expand All @@ -46,8 +47,9 @@ class hydroLevelsData final : public dataInterface

public:
// Constructor

hydroLevelsData(std::string& iniFilePrefix);

hydroLevelsData(std::string& iniFilePrefix,
std::function<void(Study&, Matrix<double>&)> applyToTarget);

//! \name Data manupulation
//@{
Expand Down Expand Up @@ -79,15 +81,16 @@ class hydroLevelsData final : public dataInterface

void set_value(uint x, uint y, double value);

bool apply(Study& study);
bool applyHydroLevels(Matrix<double>& scenarioHydroLevels) const;
bool apply(Study& study) override;

private:
//! Hydro levels overlay (0 if auto)
MatrixType pHydroLevelsRules;
// prefix to be added when calling saveToINIFileHydroLevel
std::string& addToPrefix;

std::function<void(Study&, Matrix<double>&)> applyToTarget_;

}; // class hydroLevelsData

// class hydroLevelsData : inline functions
Expand All @@ -114,6 +117,16 @@ inline double hydroLevelsData::get_value(uint x, uint y) const
return pHydroLevelsRules.entry[y][x];
}

inline void initLevelApply(Study& study, Matrix<double>& matrix)
{
study.scenarioInitialHydroLevels.copyFrom(matrix);
}

inline void finalLevelApply(Study& study, Matrix<double>& matrix)
{
study.scenarioFinalHydroLevels.copyFrom(matrix);
}

} // namespace ScenarioBuilder
} // namespace Data
} // namespace Antares
Expand Down
4 changes: 2 additions & 2 deletions src/libs/antares/study/scenario-builder/rules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,8 @@ bool Rules::apply()
returned_status = renewable[i].apply(study_) && returned_status;
returned_status = linksNTC[i].apply(study_) && returned_status;
}
returned_status = hydroInitialLevels.applyHydroLevels(study_.scenarioInitialHydroLevels) && returned_status;
returned_status = hydroFinalLevels.applyHydroLevels(study_.scenarioFinalHydroLevels) && returned_status;
returned_status = hydroInitialLevels.apply(study_) && returned_status;
returned_status = hydroFinalLevels.apply(study_) && returned_status;
returned_status = binding_constraints.apply(study_) && returned_status;
}
else
Expand Down
4 changes: 2 additions & 2 deletions src/libs/antares/study/scenario-builder/rules.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ class Rules final : private Yuni::NonCopyable<Rules>

//! hydro initial levels
std::string prefixInitial = "hl,";
hydroLevelsData hydroInitialLevels = hydroLevelsData(prefixInitial);
hydroLevelsData hydroInitialLevels = hydroLevelsData(prefixInitial, initLevelApply);
//! hydro final levels
std::string prefixFinal = "hfl,";
hydroLevelsData hydroFinalLevels = hydroLevelsData(prefixFinal);
hydroLevelsData hydroFinalLevels = hydroLevelsData(prefixFinal, finalLevelApply);

// Links NTC
std::vector<ntcTSNumberData> linksNTC;
Expand Down

0 comments on commit 46c36e8

Please sign in to comment.