Antares Simulator
Power System Simulator
raw.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 #ifndef __SOLVER_VARIABLE_STORAGE_RAW_H__
22 #define __SOLVER_VARIABLE_STORAGE_RAW_H__
23 
24 #include <float.h>
25 
26 #include <yuni/yuni.h>
27 
28 #include <antares/memory/memory.h>
29 
30 #include "rawdata.h"
31 
32 namespace Antares::Solver::Variable::R::AllYears
33 {
34 template<class NextT /*= Empty*/, int FileFilter /*= Variable::Category::FileLevel::allFile*/>
35 struct Raw: public NextT
36 {
37 public:
39  typedef NextT NextType;
40 
41  enum
42  {
44  count = 1 + NextT::count,
45 
46  categoryFile = NextT::categoryFile | Variable::Category::FileLevel::allFile,
47  };
48 
49  struct Data
50  {
51  double value;
52  uint32_t indice;
53  };
54 
56  static const char* Name()
57  {
58  return "raw";
59  }
60 
61 public:
62  Raw()
63  {
64  }
65 
66  ~Raw()
67  {
68  }
69 
70 protected:
71  void initializeFromStudy(Antares::Data::Study& study);
72 
73  inline void reset()
74  {
75  rawdata.reset();
76  // Next
77  NextType::reset();
78  }
79 
80  inline void merge(uint year, const IntermediateValues& rhs)
81  {
82  rawdata.merge(year, rhs);
83  // Next
84  NextType::merge(year, rhs);
85  }
86 
87  template<class S, class VCardT>
88  void buildSurveyReport(SurveyResults& report,
89  const S& results,
90  int dataLevel,
91  int fileLevel,
92  int precision) const
93  {
94  if (fileLevel & FileFilter && !(fileLevel & Category::FileLevel::id))
95  {
96  switch (precision)
97  {
98  case Category::hourly:
99  InternalExportValues<Category::hourly, HOURS_PER_YEAR, VCardT>(
100  report,
101  ::Antares::Memory::RawPointer(rawdata.hourly));
102  break;
103  case Category::daily:
104  InternalExportValues<Category::daily, DAYS_PER_YEAR, VCardT>(report, rawdata.daily);
105  break;
106  case Category::weekly:
107  InternalExportValues<Category::weekly, WEEKS_PER_YEAR, VCardT>(report,
108  rawdata.weekly);
109  break;
110  case Category::monthly:
111  InternalExportValues<Category::monthly, MONTHS_PER_YEAR, VCardT>(report,
112  rawdata.monthly);
113  break;
114  case Category::annual:
115  InternalExportValues<Category::annual, 1, VCardT>(report, rawdata.year.data());
116  break;
117  }
118  }
119  // Next
120  NextType::template buildSurveyReport<S, VCardT>(report,
121  results,
122  dataLevel,
123  fileLevel,
124  precision);
125  }
126 
127  template<class VCardT>
128  void buildDigest(SurveyResults& report, int digestLevel, int dataLevel) const
129  {
130  if ((dataLevel & Category::DataLevel::area || dataLevel & Category::DataLevel::setOfAreas)
131  && digestLevel & Category::digestAllYears)
132  {
133  assert(report.data.columnIndex < report.maxVariables && "Column index out of bounds");
134 
135  report.captions[0][report.data.columnIndex] = report.variableCaption;
136  report.captions[1][report.data.columnIndex] = report.variableUnit;
137  report.captions[2][report.data.columnIndex] = "values";
138 
139  // Precision
140  report.precision[report.data.columnIndex] = PrecisionToPrintfFormat<
141  VCardT::decimal>::Value();
142  // Value
143  report.values[report.data.columnIndex][report.data.rowIndex] = rawdata.allYears;
144  // Non applicability
145  report.digestNonApplicableStatus[report.data.rowIndex][report.data.columnIndex]
146  = *report.isCurrentVarNA;
147 
148  ++(report.data.columnIndex);
149  }
150  // Next
151  NextType::template buildDigest<VCardT>(report, digestLevel, dataLevel);
152  }
153 
154  template<template<class, int> class DecoratorT>
155  Antares::Memory::Stored<double>::ConstReturnType hourlyValuesForSpatialAggregate() const
156  {
157  if (Yuni::Static::Type::StrictlyEqual<DecoratorT<Empty, 0>, Raw<Empty, 0>>::Yes)
158  {
159  return rawdata.hourly;
160  }
161  return NextType::template hourlyValuesForSpatialAggregate<DecoratorT>();
162  }
163 
164 public:
165  RawData rawdata;
166 
167 private:
168  template<int PrecisionT, uint Size, class VCardT>
169  void InternalExportValues(SurveyResults& report, const double* array) const
170  {
171  assert(array);
172  assert(report.data.columnIndex < report.maxVariables && "Column index out of bounds");
173 
174  // Caption
175  report.captions[0][report.data.columnIndex] = report.variableCaption;
176  report.captions[1][report.data.columnIndex] = report.variableUnit;
177  report.captions[2][report.data.columnIndex] = "values";
178  // Precision
179  report.precision[report.data.columnIndex] = Solver::Variable::PrecisionToPrintfFormat<
180  VCardT::decimal>::Value();
181  // Non applicability
182  report.nonApplicableStatus[report.data.columnIndex] = *report.isCurrentVarNA;
183 
184  // Values
185  if (PrecisionT == Category::annual)
186  {
187  rawdata.allYears = 0.;
188  for (uint i = 0; i != rawdata.nbYearsCapacity; ++i)
189  {
190  rawdata.allYears += array[i];
191  }
192  *(report.values[report.data.columnIndex]) = rawdata.allYears;
193  }
194  else
195  {
196  (void)::memcpy(report.values[report.data.columnIndex], array, sizeof(double) * Size);
197  }
198 
199  // Next column index
200  ++report.data.columnIndex;
201  }
202 
203  template<uint Size, class VCardT>
204  void InternalExportValuesMC(int precision, SurveyResults& report, const double* array) const
205  {
206  if (not(precision & Category::annual))
207  {
208  return;
209  }
210  assert(report.data.columnIndex < report.maxVariables && "Column index out of bounds");
211 
212  // Caption
213  report.captions[0][report.data.columnIndex] = report.variableCaption;
214  report.captions[1][report.data.columnIndex] = report.variableUnit;
215  report.captions[2][report.data.columnIndex] = "values";
216  // Precision
217  report.precision[report.data.columnIndex] = Solver::Variable::PrecisionToPrintfFormat<
218  VCardT::decimal>::Value();
219  // Non applicability
220  report.nonApplicableStatus[report.data.columnIndex] = *report.isCurrentVarNA;
221 
222  (void)::memcpy(report.data.matrix[report.data.columnIndex],
223  array,
224  report.data.nbYears * sizeof(double));
225 
226  // Next column index
227  ++report.data.columnIndex;
228  }
229 
230 }; // class Raw
231 
232 } // namespace Antares::Solver::Variable::R::AllYears
233 
234 #include "raw.hxx"
235 
236 #endif // __SOLVER_VARIABLE_STORAGE_RAW_H__
Definition: study.h:57
NextT NextType
Type of the net item in the list.
Definition: raw.h:39
static const char * Name()
Name of the filter.
Definition: raw.h:56
@ count
The count if item in the list.
Definition: raw.h:44