Skip to content

Commit

Permalink
Collect hydro validation errors (#2204)
Browse files Browse the repository at this point in the history
collect *n* hydro validation errors (10 per area ) before exiting

---------

Co-authored-by: Florian Omnès <florian.omnes@rte-france.com>
  • Loading branch information
a-zakir and flomnes authored Jul 2, 2024
1 parent 7145e40 commit 5bdf788
Show file tree
Hide file tree
Showing 12 changed files with 276 additions and 219 deletions.
2 changes: 0 additions & 2 deletions src/libs/antares/study/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ set(SRC_STUDY_PART_HYDRO
include/antares/study/parts/hydro/allocation.h
include/antares/study/parts/hydro/allocation.hxx
parts/hydro/allocation.cpp
include/antares/study/parts/hydro/finalLevelValidator.h
parts/hydro/finalLevelValidator.cpp
include/antares/study/parts/hydro/hydromaxtimeseriesreader.h
parts/hydro/hydromaxtimeseriesreader.cpp
)
Expand Down
6 changes: 4 additions & 2 deletions src/solver/hydro/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ set(SRC_MANAGEMENT
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
include/antares/solver/hydro/management/HydroErrorsCollector.h
management/HydroErrorsCollector.cpp
include/antares/solver/hydro/management/finalLevelValidator.h
management/finalLevelValidator.cpp
)


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
** 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 <map>
#include <sstream>
#include <string>
#include <vector>

namespace Antares
{

class HydroErrorsCollector
{
public:
class AreaReference
{
public:
AreaReference(HydroErrorsCollector* collector, const std::string& name);
template<class T>
AreaReference& operator<<(const T& msg);

private:
std::string& areaSingleErrorMessage_;
};

AreaReference operator()(const std::string& name);
HydroErrorsCollector() = default;
void CheckForErrors() const;

private:
std::map<std::string, std::vector<std::string>> areasErrorMap_;
std::string& CurrentMessage(const std::string& name);
};

template<class T>
HydroErrorsCollector::AreaReference& HydroErrorsCollector::AreaReference::operator<<(const T& msg)
{
std::ostringstream strfy;
strfy << msg;
areaSingleErrorMessage_ += strfy.str();
return *this;
}

} // namespace Antares
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#pragma once
#include <antares/study/area/area.h>
#include "antares/date/date.h"
#include "antares/solver/hydro/management/HydroErrorsCollector.h"
#include "antares/solver/hydro/management/MinGenerationScaling.h"
#include "antares/solver/hydro/management/PrepareInflows.h"
#include "antares/study/study.h"
Expand All @@ -33,31 +34,31 @@ class HydroInputsChecker
public:
explicit HydroInputsChecker(Antares::Data::Study& study);
void Execute(uint year);
void CheckForErrors() const;
void CheckFinalReservoirLevelsConfiguration(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_;
HydroErrorsCollector errorCollector_;

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

} // namespace Antares
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,30 @@
*/
#pragma once

#include "antares/solver/hydro/management/HydroErrorsCollector.h"
#include "antares/study/parts/hydro/container.h"

namespace Antares::Data
namespace Antares
{
namespace Data
{
class PartHydro;
}

namespace Solver
{
class FinalLevelValidator
{
public:
FinalLevelValidator(PartHydro& hydro,
FinalLevelValidator(Antares::Data::PartHydro& hydro,
unsigned int areaIndex,
const AreaName areaName,
const Antares::Data::AreaName areaName,
double initialLevel,
double finalLevel,
const unsigned int year,
const unsigned int lastSimulationDay,
const unsigned int firstMonthOfSimulation);
const unsigned int firstMonthOfSimulation,
HydroErrorsCollector& errorCollector);
bool check();
bool finalLevelFineForUse();

Expand All @@ -62,12 +69,16 @@ class FinalLevelValidator
unsigned int firstMonthOfSimulation_ = 0;

// Data from area
PartHydro& hydro_;
Antares::Data::PartHydro& hydro_;
unsigned int areaIndex_;
const AreaName areaName_;
const Antares::Data::AreaName areaName_;
double initialLevel_;
double finalLevel_;

bool finalLevelFineForUse_ = false;

// area input errors
HydroErrorsCollector& errorCollector_;
};
} // namespace Antares::Data
} // namespace Solver
} // namespace Antares

This file was deleted.

45 changes: 45 additions & 0 deletions src/solver/hydro/management/HydroErrorsCollector.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "antares/solver/hydro/management/HydroErrorsCollector.h"

#include <ranges>
#include <set>

#include <yuni/core/logs.h>

#include "antares/antares/fatal-error.h"

namespace Antares
{

void HydroErrorsCollector::CheckForErrors() const
{
if (!areasErrorMap_.empty())
{
for (const auto& [key, values]: areasErrorMap_)
{
for (const auto& value: values | std::views::take(10))
{
logs.error() << "In Area " << key << ": " << value << " ";
}
}

throw FatalError("Hydro validation has failed !");
}
}

HydroErrorsCollector::AreaReference::AreaReference(HydroErrorsCollector* collector,
const std::string& name):
areaSingleErrorMessage_(collector->CurrentMessage(name))
{
}

HydroErrorsCollector::AreaReference HydroErrorsCollector::operator()(const std::string& name)
{
return AreaReference(this, name);
}

std::string& HydroErrorsCollector::CurrentMessage(const std::string& name)
{
auto& msgs = areasErrorMap_[name];
return *msgs.insert(msgs.end(), "");
}
} // namespace Antares
Loading

0 comments on commit 5bdf788

Please sign in to comment.