Antares Simulator
Power System Simulator
intermediate.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_INTERMEDIATE_HXX__
22 #define __SOLVER_VARIABLE_STORAGE_INTERMEDIATE_HXX__
23 
24 #include <antares/solver/variable/print.h>
25 
26 namespace Antares::Solver::Variable
27 {
29 {
31 }
32 
34 {
35  Antares::Memory::Zero(HOURS_PER_YEAR, hour);
36  memset(month, 0, sizeof(month));
37  memset(week, 0, sizeof(week));
38  memset(day, 0, sizeof(day));
39 }
40 
41 inline IntermediateValues::Type& IntermediateValues::operator[](const unsigned int index)
42 {
43  return hour[index];
44 }
45 
47  const unsigned int index) const
48 {
49  return hour[index];
50 }
51 
52 template<class VCardT>
53 inline void IntermediateValues::buildAnnualSurveyReport(SurveyResults& report,
54  int fileLevel,
55  int precision) const
56 {
57  if (!(fileLevel & Category::FileLevel::id))
58  {
59  switch (precision)
60  {
61  case Category::hourly:
62  internalExportAnnualValues<HOURS_PER_YEAR, VCardT>(report, hour, false);
63  break;
64  case Category::daily:
65  internalExportAnnualValues<DAYS_PER_YEAR, VCardT>(report, day, false);
66  break;
67  case Category::weekly:
68  internalExportAnnualValues<WEEKS_PER_YEAR, VCardT>(report, week, false);
69  break;
70  case Category::monthly:
71  internalExportAnnualValues<MONTHS_PER_YEAR, VCardT>(report, month, false);
72  break;
73  case Category::annual:
74  internalExportAnnualValues<1, VCardT>(report, &year, true);
75  break;
76  }
77  }
78 }
79 
80 template<unsigned int Size, class VCardT, class A>
81 void IntermediateValues::internalExportAnnualValues(SurveyResults& report,
82  const A& array,
83  bool annual) const
84 {
85  using namespace Yuni;
86  assert(report.data.columnIndex < report.maxVariables && "Column index out of bounds");
87 
88  // Caption
89  report.captions[0][report.data.columnIndex] = report.variableCaption;
90  report.captions[1][report.data.columnIndex] = report.variableUnit;
91  report.captions[2][report.data.columnIndex] = nullptr;
92  // Precision
93  report.precision[report.data.columnIndex] = PrecisionToPrintfFormat<VCardT::decimal>::Value();
94  // Non applicability
95  report.nonApplicableStatus[report.data.columnIndex] = *report.isCurrentVarNA;
96 
97  // Values
98  if (not annual)
99  {
100  (void)::memcpy(report.values[report.data.columnIndex], array, sizeof(double) * Size);
101  }
102  else
103  {
104  double& target = *(report.values[report.data.columnIndex]);
105  target = year;
106  }
107 
108  // Next column index
109  ++report.data.columnIndex;
110 }
111 
112 } // namespace Antares::Solver::Variable
113 
114 #endif // __SOLVER_VARIABLE_STORAGE_INTERMEDIATE_HXX__
static void Release(T *&pointer)
Release a raw pointer.
Definition: memory.hxx:32
Type week[WEEKS_PER_YEAR]
Values for each week.
Definition: intermediate.h:128
Type & operator[](const uint index)
Vector alias for an hour in the year.
Type year
Year.
Definition: intermediate.h:134
void reset()
Reset all values.
Definition: intermediate.hxx:33
Antares::Memory::Stored< Type >::Type hour
Values for each hour in the year.
Definition: intermediate.h:132
double Type
Basic type.
Definition: intermediate.h:45
Type month[MONTHS_PER_YEAR]
Values for each month.
Definition: intermediate.h:126
Type day[DAYS_PER_YEAR]
Values for each day in the year.
Definition: intermediate.h:130
~IntermediateValues()
Destructor.
Definition: intermediate.hxx:28