Skip to content

Commit

Permalink
CSR - add output vars (ANT-2295) : isolating the max mrg data buildin…
Browse files Browse the repository at this point in the history
…g in a factory class
  • Loading branch information
guilpier-code committed Oct 25, 2024
1 parent 54b37f3 commit eebdd56
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 23 deletions.
39 changes: 18 additions & 21 deletions src/solver/variable/economy/max-mrg-utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,32 @@ const unsigned int nbHoursInWeek = 168;
namespace Antares::Solver::Variable::Economy
{

MaxMRGinput dataToComputeMaxMRG(const State& state, unsigned int numSpace)
MaxMrgDataFactory::MaxMrgDataFactory(const State &state, unsigned int numSpace) :
state_(state),
numSpace_(numSpace),
weeklyResults_(state.problemeHebdo->ResultatsHoraires[state.area->index])
{
auto& area = *state.area;
auto index = area.index;
auto& problem = *state.problemeHebdo;
auto& weeklyResults = problem.ResultatsHoraires[index];

MaxMRGinput maxMrGinput;
maxMRGinput_.hydroGeneration = weeklyResults_.TurbinageHoraire.data();
maxMRGinput_.hydroMaxPower = state_.area->hydro.maxPower[Data::PartHydro::genMaxP];
maxMRGinput_.dtgMargin = state_.area->scratchpad[numSpace].dispatchableGenerationMargin;
maxMRGinput_.hourInYear = state.hourInTheYear;
maxMRGinput_.calendar = &state.study.calendar;
maxMRGinput_.areaName = state_.area->name.c_str();
}

// Spillage
if (state.simplexRunNeeded)
MaxMRGinput MaxMrgUsualDataFactory::data()
{
if (state_.simplexRunNeeded)
{
maxMrGinput.spillage = weeklyResults.ValeursHorairesDeDefaillanceNegative.data();
maxMRGinput_.spillage = weeklyResults_.ValeursHorairesDeDefaillanceNegative.data();
}
else
{
maxMrGinput.spillage = state.resSpilled[index];
maxMRGinput_.spillage = state_.resSpilled[state_.area->index];
}

maxMrGinput.dens = weeklyResults.ValeursHorairesDeDefaillancePositive.data();

maxMrGinput.hydroGeneration = weeklyResults.TurbinageHoraire.data();
maxMrGinput.hydroMaxPower = area.hydro.maxPower[Data::PartHydro::genMaxP];
maxMrGinput.dtgMargin = area.scratchpad[numSpace].dispatchableGenerationMargin;
maxMrGinput.hourInYear = state.hourInTheYear;
maxMrGinput.calendar = &state.study.calendar;
maxMrGinput.areaName = area.name.c_str();

return maxMrGinput;
maxMRGinput_.dens = weeklyResults_.ValeursHorairesDeDefaillancePositive.data();
return maxMRGinput_;
}

void computeMaxMRG(double* opmrg, const MaxMRGinput& in)
Expand Down
22 changes: 21 additions & 1 deletion src/solver/variable/economy/max-mrg-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,28 @@ struct MaxMRGinput
std::string areaName;
};

MaxMRGinput dataToComputeMaxMRG(const State &state, unsigned int numSpace);
void computeMaxMRG(double *opmrg, const MaxMRGinput &in);

class MaxMrgDataFactory
{
public:
MaxMrgDataFactory(const State &state, unsigned int numSpace);
virtual MaxMRGinput data() = 0;
protected:
// in data
const State& state_;
const unsigned int numSpace_ = 0;
RESULTATS_HORAIRES& weeklyResults_;
// data to be built
MaxMRGinput maxMRGinput_;
};

class MaxMrgUsualDataFactory : public MaxMrgDataFactory
{
using MaxMrgDataFactory::MaxMrgDataFactory;
public:
virtual MaxMRGinput data() override;
};

} // Antares::Solver::Variable::Economy

3 changes: 2 additions & 1 deletion src/solver/variable/economy/max-mrg.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ class Marge : public Variable::IVariable<Marge<NextT>, NextT, VCardMARGE>
double* rawhourly = Memory::RawPointer(pValuesForTheCurrentYear[numSpace].hour);

// Getting data required to compute max margin
MaxMRGinput maxMRGinput = dataToComputeMaxMRG(state, numSpace);
MaxMrgUsualDataFactory maxMRGdataFactory(state, numSpace);
MaxMRGinput maxMRGinput = maxMRGdataFactory.data();
computeMaxMRG(rawhourly + state.hourInTheYear, maxMRGinput);

// next
Expand Down

0 comments on commit eebdd56

Please sign in to comment.