Antares Simulator
Power System Simulator
hour_utils.h
1 /*
2  * Copyright 2007-2025, RTE (https://www.rte-france.com)
3  * See AUTHORS.txt
4  * SPDX-License-Identifier: MPL-2.0
5  * This file is part of Antares-Simulator,
6  * Adequacy and Performance assessment for interconnected energy networks.
7  *
8  * Antares_Simulator is free software: you can redistribute it and/or modify
9  * it under the terms of the Mozilla Public Licence 2.0 as published by
10  * the Mozilla Foundation, either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * Antares_Simulator is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * Mozilla Public Licence 2.0 for more details.
17  *
18  * You should have received a copy of the Mozilla Public Licence 2.0
19  * along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
20  */
21 
22 #ifndef ANTARES_SOLVER_VARIABLE_COMMONS_HOUR_UTILS_H
23 #define ANTARES_SOLVER_VARIABLE_COMMONS_HOUR_UTILS_H
24 
25 #include <concepts>
26 #include <cstddef>
27 #include <type_traits>
28 
29 namespace Antares::Solver::Variable::Util
30 {
31 
32 template<class T>
33 concept HourlySeries = requires(T t, unsigned y) {
34  { t.series.getColumn(y) } -> std::convertible_to<const double*>;
35  { t.series.timeSeries.height } -> std::convertible_to<size_t>;
36 };
37 
38 template<class Ptr, class F>
39 inline void for_each_hour(const Ptr data, size_t n, F&& f) noexcept
40 {
41  for (size_t h = 0; h < n; ++h)
42  {
43  f(h, data[h]);
44  }
45 }
46 
47 template<class Container, class F>
48 inline void for_each_hour(Container& c, F&& f) noexcept(noexcept(f(size_t{}, *c.data())))
49 {
50  for (size_t h = 0; h < c.size(); ++h)
51  {
52  f(h, c[h]);
53  }
54 }
55 
56 template<class Range, class F>
57 inline void transform_in_place(Range&& r, F&& f) noexcept(noexcept(f(*r.begin())))
58 {
59  for (auto& v: r)
60  {
61  v = f(v);
62  }
63 }
64 
65 } // namespace Antares::Solver::Variable::Util
66 
67 #endif // ANTARES_SOLVER_VARIABLE_COMMONS_HOUR_UTILS_H