Antares Simulator
Power System Simulator
Loading...
Searching...
No Matches
applyToMatrix.hxx
1/*
2** Copyright 2007-2024, 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// Created by marechaljas on 03/07/23.
23//
24
25#pragma once
26
27#include <cstdlib>
28
29#include "yuni/core/system/stdint.h"
30
31#include "antares/study/binding_constraint/BindingConstraintGroup.h"
32#include "antares/study/parts/hydro/series.h"
33#include "antares/study/scenario-builder/TSnumberData.h"
34
35namespace Antares::Data::ScenarioBuilder
36{
37
38static constexpr unsigned maxErrors = 20;
39
40template<class D>
41static inline bool CheckValidity(uint value, const D& data, uint tsGenMax)
42{
43 // When the TS-Generators are not used
44 return (!tsGenMax) ? (value < data.timeSeries.width) : (value < tsGenMax);
45}
46
47template<>
48inline bool CheckValidity<Data::DataSeriesHydro>(uint value,
49 const Data::DataSeriesHydro& data,
50 uint tsGenMax)
51{
52 // When the TS-Generators are not used
53 return (!tsGenMax) ? (value < data.TScount()) : (value < tsGenMax);
54}
55
56template<>
57inline bool CheckValidity<Data::AreaLink>(uint value,
58 const Data::AreaLink& data,
59 uint /* tsGenMax */)
60{
61 // Value = index of time series
62 // Direct Capacities = all time series
63 // directCapacities.timeSeries.width = Number of time series
64 return value < data.directCapacities.timeSeries.width;
65}
66
67template<>
68inline bool CheckValidity<BindingConstraintGroup>(uint value,
69 const BindingConstraintGroup& group,
70 uint)
71{
72 return value < group.numberOfTimeseries();
73}
74
75template<class StringT, class D>
76bool ApplyToMatrix(uint& errors,
77 StringT& logprefix,
78 D& data,
80 uint tsGenMax)
81{
82 bool ret = true;
83
84 // In this case, m.height represents the total number of years
85 const uint nbYears = data.timeseriesNumbers.height();
86 // The matrix m has only one column
87 auto& target = data.timeseriesNumbers;
88
89 for (uint y = 0; y != nbYears; ++y)
90 {
91 if (years[y] != 0)
92 {
93 // The new TS number
94 uint32_t tsNum = years[y] - 1;
95
96 // When the TS-Generators are not used
97 if (!CheckValidity(tsNum, data, tsGenMax))
98 {
99 if (errors <= maxErrors)
100 {
101 if (++errors == maxErrors)
102 {
103 logs.warning() << "scenario-builder: ... (skipped)";
104 }
105 else
106 {
107 logs.warning() << "scenario-builder: " << logprefix
108 << "value out of bounds for the year " << (y + 1);
109 }
110 }
111 ret = false;
112 continue;
113 }
114 // Ok, assign. The value provided by the interface is user-friendly
115 // and starts from 1.
116 target[y] = tsNum;
117 }
118 }
119
120 return ret;
121}
122} // namespace Antares::Data::ScenarioBuilder
Data series (Hydro)
Definition series.h:40
typename Antares::Memory::Stored< uint32_t >::Type ColumnType
Definition matrix.h:62
uint width
Width of the matrix.
Definition matrix.h:441