Skip to content

Commit

Permalink
Perform hydro checks prior to the simulation [ANT-1720] (#2132)
Browse files Browse the repository at this point in the history
Co-authored-by: Florian Omnès <[email protected]>
Co-authored-by: Florian OMNES <[email protected]>
Co-authored-by: payetvin <[email protected]>
Co-authored-by: Guillaume PIERRE <[email protected]>
Co-authored-by: guilpier-code <[email protected]>
Co-authored-by: Milos A <[email protected]>
Co-authored-by: Milos <[email protected]>
Co-authored-by: NikolaIlic <[email protected]>
  • Loading branch information
9 people authored Jun 28, 2024
1 parent 8dc4f18 commit a00b90a
Show file tree
Hide file tree
Showing 29 changed files with 1,013 additions and 599 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,60 @@

namespace Antares::Data
{

//! The maximum number of days in a year
constexpr size_t dayYearCount = 366;

struct DailyDemand
{
//! Net demand, for each day of the year, for each area
double DLN = 0.;
//! Daily local effective load
double DLE = 0.;
};

struct MonthlyGenerationTargetData
{
//! Monthly local effective demand
double MLE = 0.;
//! Monthly optimal generation
double MOG = 0.;
//! Monthly optimal level
double MOL = 0.;
//! Monthly target generations
double MTG = 0.;
};

//! Hydro Management Data for a given area
struct TimeDependantHydroManagementData
{
std::array<DailyDemand, dayYearCount> daily{0};
std::array<MonthlyGenerationTargetData, 12> monthly{0};
};

//! Area Hydro Management Data for a given year
struct AreaDependantHydroManagementData
{
//! inflows
std::array<double, 12> inflows{};
//! monthly minimal generation
std::array<double, 12> mingens{};

//! daily minimal generation
std::array<double, dayYearCount> dailyMinGen{};

// Data for minGen<->inflows preChecks
//! monthly total mingen
std::array<double, 12> totalMonthMingen{};
//! monthly total inflows
std::array<double, 12> totalMonthInflows{};
//! yearly total mingen
double totalYearMingen = 0;
//! yearly total inflows
double totalYearInflows = 0;

}; // struct AreaDependantHydroManagementData

/*!
** \brief Hydro for a single area
*/
Expand Down Expand Up @@ -165,6 +219,7 @@ class PartHydro
// which contains other time.
Matrix<double, double> dailyNbHoursAtGenPmax;
Matrix<double, double> dailyNbHoursAtPumpPmax;
std::unordered_map<uint, AreaDependantHydroManagementData> managementData;

std::vector<std::optional<double>> deltaBetweenFinalAndInitialLevels;

Expand Down
1 change: 1 addition & 0 deletions src/libs/antares/study/runtime/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ void StudyRuntimeInfos::initializeRangeLimits(const Study& study, StudyRangeLimi
limits.month[rangeCount] = limits.month[rangeEnd] - limits.month[rangeBegin] + 1;
// year
limits.year[rangeBegin] = 0;
/// reminder to get rangeLimits.year[Data::rangeEnd]
limits.year[rangeEnd] = study.parameters.nbYears - 1;
limits.year[rangeCount] = study.parameters.effectiveNbYears;

Expand Down
6 changes: 4 additions & 2 deletions src/solver/application/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
set(HEADERS
include/antares/application/application.h
include/antares/application/ScenarioBuilderOwner.h
)
set(SRC_APPLICATION
${HEADERS}
application.cpp
process-priority.cpp
ScenarioBuilderOwner.cpp
)
source_group("application" FILES ${SRC_APPLICATION})

Expand All @@ -29,10 +31,10 @@ target_link_libraries(application
)

target_include_directories(application
PUBLIC
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)

install(DIRECTORY include/antares
install(DIRECTORY include/antares
DESTINATION "include"
)
57 changes: 57 additions & 0 deletions src/solver/application/ScenarioBuilderOwner.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
** 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/>.
*/

#include <antares/antares/fatal-error.h>
#include <antares/application/ScenarioBuilderOwner.h>
#include "antares/solver/simulation/apply-scenario.h"
#include "antares/solver/simulation/timeseries-numbers.h"
#include "antares/solver/ts-generator/generator.h"
#include "antares/study/study.h"

Antares::Solver::ScenarioBuilderOwner::ScenarioBuilderOwner(Data::Study& study):
study_(study)
{
}

void Antares::Solver::ScenarioBuilderOwner::callScenarioBuilder() {
TSGenerator::ResizeGeneratedTimeSeries(study_.areas, study_.parameters);

// Sampled time-series Numbers
// We will resize all matrix related to the time-series numbers
// This operation can be done once since the number of years is constant
// for a single simulation
study_.resizeAllTimeseriesNumbers(1 + study_.runtime->rangeLimits.year[Data::rangeEnd]);
if (not TimeSeriesNumbers::CheckNumberOfColumns(study_.areas))
{
throw FatalError(
"Inconsistent number of time-series detected. Please check your input data.");
}

if (not TimeSeriesNumbers::Generate(study_))
{
throw FatalError("An unrecoverable error has occurred. Can not continue.");
}
if (study_.parameters.useCustomScenario)
{
ApplyCustomScenario(study_);
}
}

4 changes: 3 additions & 1 deletion src/solver/application/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <yuni/datetime/timestamp.h>

#include <antares/antares/fatal-error.h>
#include <antares/application/ScenarioBuilderOwner.h>
#include <antares/benchmarking/timer.h>
#include <antares/checks/checkLoadedInputData.h>
#include <antares/exception/LoadingError.hpp>
Expand Down Expand Up @@ -232,6 +233,8 @@ void Application::readDataForTheStudy(Data::StudyLoadOptions& options)
// Apply transformations needed by the solver only (and not the interface for example)
study.performTransformationsBeforeLaunchingSimulation();

ScenarioBuilderOwner(study).callScenarioBuilder();

// alloc global vectors
SIM_AllocationTableaux(study);
}
Expand All @@ -256,7 +259,6 @@ void Application::startSimulation(Data::StudyLoadOptions& options)
pStudy = std::make_unique<Antares::Data::Study>(true /* for the solver */);

pParameters = &(pStudy->parameters);

readDataForTheStudy(options);

postParametersChecks();
Expand Down
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

namespace Antares
{
namespace Data
{
class Study;
}

namespace Solver
{

class ScenarioBuilderOwner
{
public:
explicit ScenarioBuilderOwner(Antares::Data::Study& study);

void callScenarioBuilder();

private:
Antares::Data::Study& study_;
};
} // namespace Solver
} // namespace Antares
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,6 @@ class Application final: public Yuni::IEventObserver<Application, Yuni::Policy::
bool parseCommandLine(Data::StudyLoadOptions& options);
void handleParserReturn(Yuni::GetOpt::Parser* parser);
void postParametersChecks() const;

}; // class Application
} // namespace Antares::Solver
9 changes: 9 additions & 0 deletions src/solver/hydro/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,16 @@ set(SRC_EXT_SOLVER_H2O2_DAILY
set(SRC_MANAGEMENT
include/antares/solver/hydro/management/management.h
management/management.cpp
include/antares/solver/hydro/management/PrepareInflows.h
management/PrepareInflows.cpp
management/monthly.cpp
management/daily.cpp
include/antares/solver/hydro/management/MinGenerationScaling.h
management/MinGenerationScaling.cpp
include/antares/solver/hydro/management/HydroInputsChecker.h
management/HydroInputsChecker.cpp
include/antares/solver/hydro/management/hydro-final-reservoir-level-functions.h
management/hydro-final-reservoir-level-functions.cpp
)


Expand All @@ -73,6 +81,7 @@ target_link_libraries(antares-solver-hydro
sirius_solver
Antares::date
Antares::result_writer

)

target_include_directories(antares-solver-hydro
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
** 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/study/area/area.h>
#include "antares/date/date.h"
#include "antares/solver/hydro/management/MinGenerationScaling.h"
#include "antares/solver/hydro/management/PrepareInflows.h"
#include "antares/study/study.h"
namespace Antares
{

class HydroInputsChecker
{
public:
explicit HydroInputsChecker(Antares::Data::Study& study);
void Execute(uint year);

private:
Data::AreaList& areas_;
const Data::Parameters& parameters_;
const Date::Calendar& calendar_;
Data::SimulationMode simulationMode_;
const uint firstYear_;
const uint endYear_;
PrepareInflows prepareInflows_;
MinGenerationScaling minGenerationScaling_;
const Data::TimeSeries::TS& scenarioInitialHydroLevels_;
const Data::TimeSeries::TS& scenarioFinalHydroLevels_;

//! return false if checkGenerationPowerConsistency or checkMinGeneration returns false
bool checkMonthlyMinGeneration(uint year, const Data::Area& area) const;
//! check Yearly minimum generation is lower than available inflows
bool checkYearlyMinGeneration(uint year, const Data::Area& area) const;
//! check Weekly minimum generation is lower than available inflows
bool checkWeeklyMinGeneration(uint year, const Data::Area& area) const;
//! check Hourly minimum generation is lower than available inflows
bool checkGenerationPowerConsistency(uint year) const;
//! return false if checkGenerationPowerConsistency or checkMinGeneration returns false
bool checksOnGenerationPowerBounds(uint year) const;
//! check minimum generation is lower than available inflows
bool checkMinGeneration(uint year) const;
};

} // namespace Antares
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
** 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/study/area/area.h>
#include "antares/date/date.h"

namespace Antares
{

//! Prepare minimum generation scaling for each area
class MinGenerationScaling
{
public:
MinGenerationScaling(Data::AreaList& areas, const Date::Calendar& calendar);
void Run(uint year);

private:
Data::AreaList& areas_;
const Date::Calendar& calendar_;
};

} // namespace Antares
Loading

0 comments on commit a00b90a

Please sign in to comment.