-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Collect hydro validation errors (#2204)
collect *n* hydro validation errors (10 per area ) before exiting --------- Co-authored-by: Florian Omnès <florian.omnes@rte-france.com>
- Loading branch information
Showing
12 changed files
with
276 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 0 additions & 41 deletions
41
...ver/hydro/include/antares/solver/hydro/management/hydro-final-reservoir-level-functions.h
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.