Antares Simulator
Power System Simulator
minmax.hxx
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 #ifndef __SOLVER_VARIABLE_STORAGE_MIN_HXX__
22 #define __SOLVER_VARIABLE_STORAGE_MIN_HXX__
23 
24 namespace Antares::Solver::Variable::R::AllYears
25 {
26 template<bool OpInferior, class NextT>
27 inline void MinMaxBase<OpInferior, NextT>::initializeFromStudy(Data::Study& study)
28 {
29  // Next
30  NextType::initializeFromStudy(study);
31 }
32 
33 template<bool OpInferior, class NextT>
34 inline void MinMaxBase<OpInferior, NextT>::reset()
35 {
36  // Reset at the begining of the simulation
37  if (OpInferior)
38  {
39  minmax.resetInf();
40  }
41  else
42  {
43  minmax.resetSup();
44  }
45  // Next
46  NextType::reset();
47 }
48 
49 template<bool OpInferior, class NextT>
50 inline void MinMaxBase<OpInferior, NextT>::merge(uint year, const IntermediateValues& rhs)
51 {
52  if (OpInferior)
53  {
54  minmax.mergeInf(year, rhs);
55  }
56  else
57  {
58  minmax.mergeSup(year, rhs);
59  }
60  // Next
61  NextType::merge(year, rhs);
62 }
63 
64 template<bool OpInferior, class NextT>
65 template<uint Size, class VCardT>
66 void MinMaxBase<OpInferior, NextT>::InternalExportIndices(SurveyResults& report,
67  const MinMaxData::Data* array,
68  int fileLevel)
69 {
70  assert(array);
71  assert(report.data.columnIndex < report.maxVariables && "Column index out of bounds");
72 
73  // Caption
74  report.captions[0][report.data.columnIndex] = report.variableCaption;
75  report.captions[1][report.data.columnIndex] = report.variableUnit;
76  report.captions[2][report.data.columnIndex] = (OpInferior ? "min" : "max");
77 
78  // Precision
79  int recommendedPrecision = (int)Category::MaxDecimalPrecision(fileLevel);
80  uint decimalPrec = (recommendedPrecision < (int)VCardT::decimal) ? (uint)recommendedPrecision
81  : (uint)VCardT::decimal;
82 
83  // Non applicability
84  report.nonApplicableStatus[report.data.columnIndex] = *report.isCurrentVarNA;
85 
86  Solver::Variable::AssignPrecisionToPrintfFormat(report.precision[report.data.columnIndex],
87  decimalPrec);
88 
89  // Values
90  double* v = report.values[report.data.columnIndex];
91  for (uint i = 0; i != Size; ++i)
92  {
93  v[i] = array[i].index;
94  }
95 
96  // Next column index
97  ++report.data.columnIndex;
98 }
99 
100 template<bool OpInferior, class NextT>
101 template<uint Size, class VCardT>
102 inline void MinMaxBase<OpInferior, NextT>::InternalExportValues(SurveyResults& report,
103  const MinMaxData::Data* array)
104 {
105  assert(array);
106  assert(report.data.columnIndex < report.maxVariables && "Column index out of bounds");
107 
108  // Caption
109  report.captions[0][report.data.columnIndex] = report.variableCaption;
110  report.captions[1][report.data.columnIndex] = report.variableUnit;
111  report.captions[2][report.data.columnIndex] = (OpInferior ? "min" : "max");
112  // Precision
113  Solver::Variable::AssignPrecisionToPrintfFormat(report.precision[report.data.columnIndex],
114  VCardT::decimal);
115 
116  // Non applicability
117  report.nonApplicableStatus[report.data.columnIndex] = *report.isCurrentVarNA;
118 
119  // Values
120  double* v = report.values[report.data.columnIndex];
121  for (uint i = 0; i != Size; ++i)
122  {
123  v[i] = array[i].value;
124  }
125 
126  // Next column index
127  ++report.data.columnIndex;
128 }
129 
130 } // namespace Antares::Solver::Variable::R::AllYears
131 
132 #endif // __SOLVER_VARIABLE_STORAGE_MIN_HXX__