Skip to content

Commit

Permalink
Move thermal noises to class Simulation (#1594)
Browse files Browse the repository at this point in the history
* [skip ci] Remove global vars : a bit of cleaning

* Remove global vars : valeursGenereesParPays's allocation moved in a constructor + simplifying runtime

* Remove global vars : unnecessary initialization of HydrauliqueModulableQuotidien (already done in simulation)

* Remove global vars : remove unnecessary function, as it only calls one other function

* Remove global vars : back to previous state, before wrong correction

* Remove global vars : a bit of clarification in ALEA_TirageAuSortChroniques

* Remove global vars : renaming

* Remove global vars : simplifying and clarifying a bit thermal noises

* Remove global vars : moving thermal noises to where it belongs + removing the useless AleaCoutDeProductionParPalier

* Remove global vars : forgot to update adequacy mode with the new way we add thermal noise

* Remove global vars : regression fix

* Remove global vars : extract thermal part of weekly problem building, because of adq patch

* [skip ci] Remove global vars : just clarifying

* Remove global vars : remove call to SIM_RenseignementProblemeHebdo in AdequacyPatchOptimization::solve

* Remove global vars : after previous commit removal, simplifications come naturally

* Remove global vars : some cleaning

* Fix/global var hydro modulable (#1614)

* Global vars - try remove HydrauliqueModulableQuotidien : simple renaming

* Global vars - try remove HydrauliqueModulableQuotidien : cleaning n class HydroManagement

* Global vars : rename and move down struct VALEURS_GENEREES_PAR_PAYS

* [skip ci] Global vars : small simplification

* remove TS number global var : we don't need timeseriesNumberYear in StudyRuntimeInfos (#1618)

* [skip ci] remove TS number global var : correction after review

* Update src/libs/antares/study/area/scratchpad.cpp

Co-authored-by: abdoulbari zakir <[email protected]>

* Apply a-zakir's remark

* Remove unused argument from StudyRuntimeInfos's ctor (#1634)

---------

Co-authored-by: Florian Omnès <[email protected]>
Co-authored-by: abdoulbari zakir <[email protected]>
  • Loading branch information
3 people authored Sep 19, 2023
1 parent 948c9c9 commit 967433f
Show file tree
Hide file tree
Showing 37 changed files with 507 additions and 582 deletions.
5 changes: 3 additions & 2 deletions src/libs/antares/study/area/scratchpad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ AreaScratchpad::AreaScratchpad(const StudyRuntimeInfos& rinfos, Area& area) : ts
{
// alias to the simulation mode
auto mode = rinfos.mode;
uint nbMonthsPerYear = 12;

for (uint i = 0; i != 168; ++i)
dispatchableGenerationMargin[i] = 0;
Expand Down Expand Up @@ -123,8 +124,8 @@ AreaScratchpad::AreaScratchpad(const StudyRuntimeInfos& rinfos, Area& area) : ts
auto& colPowerOverWater = m[PreproHydro::powerOverWater];
auto& colMaxEnergy = m[PreproHydro::maximumEnergy];

for (uint m = 0; m < rinfos.nbMonthsPerYear; ++m)
valueCol += colMaxEnergy[m] * (1. - colPowerOverWater[m]);
for (uint month = 0; month < nbMonthsPerYear; ++month)
valueCol += colMaxEnergy[month] * (1. - colPowerOverWater[month]);

hydroHasInflows = (valueCol > 0.);
}
Expand Down
27 changes: 6 additions & 21 deletions src/libs/antares/study/runtime/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,23 +245,13 @@ void StudyRuntimeInfos::initializeRangeLimits(const Study& study, StudyRangeLimi
}
}

StudyRuntimeInfos::StudyRuntimeInfos(uint nbYearsParallel) :
nbYears(0),
nbHoursPerYear(0),
nbDaysPerYear(0),
nbMonthsPerYear(0),
parameters(nullptr),
timeseriesNumberYear(nullptr),
thermalPlantTotalCount(0),
thermalPlantTotalCountMustRun(0),
quadraticOptimizationHasFailed(false)
StudyRuntimeInfos::StudyRuntimeInfos() :
nbYears(0),
parameters(nullptr),
thermalPlantTotalCount(0),
thermalPlantTotalCountMustRun(0),
quadraticOptimizationHasFailed(false)
{
// Evite les confusions de numeros de TS entre AMC
timeseriesNumberYear = new uint[nbYearsParallel];
for (uint numSpace = 0; numSpace < nbYearsParallel; numSpace++)
{
timeseriesNumberYear[numSpace] = 999999;
}
}

void StudyRuntimeInfos::checkThermalTSGeneration(Study& study)
Expand All @@ -284,9 +274,6 @@ bool StudyRuntimeInfos::loadFromStudy(Study& study)
auto& gd = study.parameters;

nbYears = gd.nbYears;
nbHoursPerYear = 8760;
nbDaysPerYear = 365;
nbMonthsPerYear = 12;
parameters = &study.parameters;
mode = gd.mode;
thermalPlantTotalCount = 0;
Expand Down Expand Up @@ -453,8 +440,6 @@ void StudyRuntimeInfos::removeAllRenewableClustersFromSolverComputations(Study&
StudyRuntimeInfos::~StudyRuntimeInfos()
{
logs.debug() << "Releasing runtime data";

delete[] timeseriesNumberYear;
}

#ifndef NDEBUG
Expand Down
16 changes: 1 addition & 15 deletions src/libs/antares/study/runtime/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class StudyRuntimeInfos
/*!
** \brief Default constructor
*/
StudyRuntimeInfos(uint nbYearsParallel);
StudyRuntimeInfos();
/*!
** \brief Destructor
*/
Expand All @@ -91,12 +91,6 @@ class StudyRuntimeInfos
public:
//! The number of years to process
uint nbYears;
//! How many hours per year
uint nbHoursPerYear; // default: 8760
//! Number of days per year
uint nbDaysPerYear;
//! Number
uint nbMonthsPerYear;

//! Alias for General data
Parameters* parameters;
Expand All @@ -115,14 +109,6 @@ class StudyRuntimeInfos
//! Random numbers generators
MersenneTwister random[seedMax];

/*!
** \brief The index to use when retrieving the time-series numbers
**
** To allow the drop of the years with no solution, we can not fully rely
** on the current year. So we have to maintain a rotating index (0..nbYears)
*/
uint* timeseriesNumberYear;

//! Total
uint thermalPlantTotalCount;
uint thermalPlantTotalCountMustRun;
Expand Down
2 changes: 1 addition & 1 deletion src/libs/antares/study/study.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ bool Study::checkHydroHotStart()
bool Study::initializeRuntimeInfos()
{
delete runtime;
runtime = new StudyRuntimeInfos(maxNbYearsInParallel);
runtime = new StudyRuntimeInfos();
return runtime->loadFromStudy(*this);
}

Expand Down
14 changes: 4 additions & 10 deletions src/solver/aleatoire/alea_fonctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,11 @@
**
** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions
*/
#ifndef __SOLVER_ALEA_H__
#define __SOLVER_ALEA_H__
#pragma once

#include "../simulation/sim_structure_donnees.h"
#include "antares/study/study.h"

void ALEA_TirageAuSortChroniques(const Antares::Data::Study& study,
double const* const* thermalNoisesByArea,
uint numSpace,
VAL_GEN_PAR_PAYS& valeursGenereesParPays);

void HydroVentilation();

#endif // __SOLVER_ALEA_H__
void ApplyRandomTSnumbers(const Antares::Data::Study& study,
unsigned int year,
uint numSpace);
105 changes: 23 additions & 82 deletions src/solver/aleatoire/alea_tirage_au_sort_chroniques.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,42 +24,26 @@
**
** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions
*/
#include "alea_sys.h"
#include <yuni/core/math.h>

#include "../simulation/sim_structure_probleme_economique.h"
#include "../simulation/sim_extern_variables_globales.h"
#include "alea_fonctions.h"
#include <algorithm>
#include <iterator>
#include <limits>
#include <antares/logs/logs.h>
#include <antares/date/date.h>
#include <antares/fatal-error.h>
#include <cassert>

using namespace Yuni;
using namespace Antares;
using namespace Antares::Data;

static void InitializeTimeSeriesNumbers_And_ThermalClusterProductionCost(
const Study& study,
double const* const* thermalNoisesByArea,
uint numSpace,
VAL_GEN_PAR_PAYS& valeursGenereesParPays)
void ApplyRandomTSnumbers(const Study& study,
unsigned int year,
uint numSpace)
{
auto& runtime = *study.runtime;

uint year = runtime.timeseriesNumberYear[numSpace];

// each area
const unsigned int count = study.areas.size();
for (unsigned int i = 0; i != count; ++i)
for (unsigned int areaIndex = 0; areaIndex != count; ++areaIndex)
{
// Variables - the current area
NUMERO_CHRONIQUES_TIREES_PAR_PAYS& ptchro = NumeroChroniquesTireesParPays[numSpace][i];
auto& area = *(study.areas.byIndex[i]);
VALEURS_GENEREES_PAR_PAYS& ptvalgen = valeursGenereesParPays[numSpace][i];
NUMERO_CHRONIQUES_TIREES_PAR_PAYS& ptchro = NumeroChroniquesTireesParPays[numSpace][areaIndex];
auto& area = *(study.areas.byIndex[areaIndex]);

// Load
{
Expand All @@ -81,9 +65,6 @@ static void InitializeTimeSeriesNumbers_And_ThermalClusterProductionCost(
assert(year < data.timeseriesNumbers.height);
ptchro.Hydraulique
= (data.count != 1) ? (long)data.timeseriesNumbers[0][year] : 0; // zero-based
// Hydro - mod
std::fill(ptvalgen.HydrauliqueModulableQuotidien.begin(),
ptvalgen.HydrauliqueModulableQuotidien.end(),0);
}
// Wind
{
Expand All @@ -105,87 +86,59 @@ static void InitializeTimeSeriesNumbers_And_ThermalClusterProductionCost(

const auto& data = *cluster->series;
assert(year < data.timeseriesNumbers.height);
unsigned int index = cluster->areaWideIndex;
unsigned int clusterIndex = cluster->areaWideIndex;

ptchro.RenouvelableParPalier[index] = (data.timeSeries.width != 1)
? (long)data.timeseriesNumbers[0][year]
: 0; // zero-based
ptchro.RenouvelableParPalier[clusterIndex] = (data.timeSeries.width != 1)
? (long)data.timeseriesNumbers[0][year]
: 0; // zero-based
}
}

// Thermal
{
uint indexCluster = 0;
auto end = area.thermal.list.mapping.end();
for (auto it = area.thermal.list.mapping.begin(); it != end; ++it)
{
ThermalClusterList::SharedPtr cluster = it->second;
// Draw a new random number, whatever the cluster is
double rnd = thermalNoisesByArea[i][indexCluster];

if (!cluster->enabled)
{
indexCluster++;
continue;
}

const auto& data = *cluster->series;
assert(year < data.timeseriesNumbers.height);
unsigned int index = cluster->areaWideIndex;
unsigned int clusterIndex = cluster->areaWideIndex;

// the matrix data.series should be properly initialized at this stage
// because the ts-generator has already been launched
ptchro.ThermiqueParPalier[index] = (data.timeSeries.width != 1)
? (long)data.timeseriesNumbers[0][year]
: 0; // zero-based

// ptvalgen.AleaCoutDeProductionParPalier[index] =
// (rnd - 0.5) * (cluster->spreadCost + 1e-4);
// MBO
// 15/04/2014 : bornage du cout thermique
// 01/12/2014 : prise en compte du spreadCost non nul

if (cluster->spreadCost == 0) // 5e-4 < |AleaCoutDeProductionParPalier| < 6e-4
{
if (rnd < 0.5)
ptvalgen.AleaCoutDeProductionParPalier[index] = 1e-4 * (5 + 2 * rnd);
else
ptvalgen.AleaCoutDeProductionParPalier[index]
= -1e-4 * (5 + 2 * (rnd - 0.5));
}
else
{
ptvalgen.AleaCoutDeProductionParPalier[index]
= (rnd - 0.5) * (cluster->spreadCost);

if (Math::Abs(ptvalgen.AleaCoutDeProductionParPalier[index]) < 5.e-4)
{
if (Math::Abs(ptvalgen.AleaCoutDeProductionParPalier[index]) >= 0)
ptvalgen.AleaCoutDeProductionParPalier[index] += 5.e-4;
else
ptvalgen.AleaCoutDeProductionParPalier[index] -= 5.e-4;
}
}

indexCluster++;
ptchro.ThermiqueParPalier[clusterIndex] = (data.timeSeries.width != 1)
? (long)data.timeseriesNumbers[0][year]
: 0; // zero-based
}
} // thermal
} // each area

// ------------------------------
// Transmission capacities
// ------------------------------
// each link
for (unsigned int i = 0; i < runtime.interconnectionsCount(); ++i)
for (unsigned int linkIndex = 0; linkIndex < study.runtime->interconnectionsCount(); ++linkIndex)
{
AreaLink* link = runtime.areaLink[i];
AreaLink* link = study.runtime->areaLink[linkIndex];
assert(year < link->timeseriesNumbers.height);
NUMERO_CHRONIQUES_TIREES_PAR_INTERCONNEXION& ptchro
= NumeroChroniquesTireesParInterconnexion[numSpace][i];
= NumeroChroniquesTireesParInterconnexion[numSpace][linkIndex];
const uint directWidth = link->directCapacities.width;
[[maybe_unused]] const uint indirectWidth = link->indirectCapacities.width;
assert(directWidth == indirectWidth);
ptchro.TransmissionCapacities
= (directWidth != 1) ? link->timeseriesNumbers[0][year] : 0; // zero-based
}

// ------------------------------
//Binding constraints
// ------------------------------
//Setting 0 for time_series of width 0 is done when using the value.
//To do this here we would have to check every BC for its width
for (const auto& group: study.bindingConstraintsGroups) {
Expand All @@ -194,15 +147,3 @@ static void InitializeTimeSeriesNumbers_And_ThermalClusterProductionCost(
NumeroChroniquesTireesParGroup[numSpace][group->name()] = group->timeseriesNumbers[0][year];
}
}

void ALEA_TirageAuSortChroniques(const Antares::Data::Study& study,
double const* const* thermalNoisesByArea,
uint numSpace,
VAL_GEN_PAR_PAYS& valeursGenereesParPays)
{
// Time-series numbers
// Retrieve all time-series numbers
// Initialize in the same time the production costs of all thermal clusters.
InitializeTimeSeriesNumbers_And_ThermalClusterProductionCost(study,
thermalNoisesByArea, numSpace, valeursGenereesParPays);
}
2 changes: 1 addition & 1 deletion src/solver/hydro/daily2/h2o2_j_donnees_optimisation.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ constexpr unsigned int seed = 0x79683264; // "hyd2" in hexa
class Hydro_problem_costs
{
public:
Hydro_problem_costs(const Data::Study& study);
Hydro_problem_costs(const Data::Parameters& parameters);

inline double get_end_days_levels_cost() const
{
Expand Down
4 changes: 2 additions & 2 deletions src/solver/hydro/daily2/h2o2_j_optim_costs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
#include "h2o2_j_donnees_optimisation.h"
#include "antares/study/fwd.h"

Hydro_problem_costs::Hydro_problem_costs(const Data::Study& study)
Hydro_problem_costs::Hydro_problem_costs(const Data::Parameters& parameters)
{
noiseGenerator.reset(Constants::seed);
end_days_levels = -1. / 32.;
overflow = 32 * 68. + 1.;
deviations = 1.;
violations = 68.;

switch (study.parameters.hydroHeuristicPolicy.hhPolicy)
switch (parameters.hydroHeuristicPolicy.hhPolicy)
{
case Data::hhpMaximizeGeneration:
waste = 33 * 68.;
Expand Down
Loading

0 comments on commit 967433f

Please sign in to comment.