Antares Simulator
Power System Simulator
thermalAirPollutantEmissions.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_ECONOMY_thermalAirPollutantEmissions_H__
22 #define __SOLVER_VARIABLE_ECONOMY_thermalAirPollutantEmissions_H__
23 
24 #include <antares/study/study.h>
25 #include "antares/solver/variable/variable.h"
26 
27 namespace Antares::Solver::Variable::Economy
28 {
30 {
32  static std::string Caption()
33  {
34  return "";
35  }
36 
38  static std::string Unit()
39  {
40  return "Tons";
41  }
42 
44  static std::string Description()
45  {
46  return "Overall pollutant emissions expected from all the thermal clusters";
47  }
48 
50  typedef Results<R::AllYears::Average< // The average values throughout all years
51  R::AllYears::StdDeviation< // The standard deviation values throughout all years
52  R::AllYears::Min< // The minimum values throughout all years
53  R::AllYears::Max< // The maximum values throughout all years
54  >>>>>
56 
59 
61  static constexpr uint8_t categoryDataLevel = Category::DataLevel::area;
63  static constexpr uint8_t categoryFileLevel = ResultsType::categoryFile
64  & (Category::FileLevel::id
65  | Category::FileLevel::va);
67  static constexpr uint8_t precision = Category::all;
69  static constexpr uint8_t nodeDepthForGUI = +0;
71  static constexpr uint8_t decimal = 0;
73  static constexpr int columnCount = Antares::Data::Pollutant::POLLUTANT_MAX;
75  static constexpr uint8_t spatialAggregate = Category::spatialAggregateSum;
76  static constexpr uint8_t spatialAggregateMode = Category::spatialAggregateEachYear;
77  static constexpr uint8_t spatialAggregatePostProcessing = 0;
79  static constexpr uint8_t hasIntermediateValues = 1;
81  static constexpr uint8_t isPossiblyNonApplicable = 0;
82 
83  typedef IntermediateValues IntermediateValuesBaseType[columnCount];
84  typedef IntermediateValuesBaseType* IntermediateValuesType;
85 
86  using IntermediateValuesTypeForSpatialAg = std::unique_ptr<IntermediateValuesBaseType[]>;
87 
88  struct Multiple
89  {
90  static std::string Caption(const unsigned int indx)
91  {
92  if (indx < Antares::Data::Pollutant::POLLUTANT_MAX)
93  {
94  return Antares::Data::Pollutant::getPollutantName(indx).c_str();
95  }
96 
97  return "<unknown>";
98  }
99 
100  static std::string Unit([[maybe_unused]] const unsigned int indx)
101  {
103  }
104  };
105 }; // class VCard
106 
110 template<class NextT = Container::EndOfList>
111 class ThermalAirPollutantEmissions: public Variable::IVariable<ThermalAirPollutantEmissions<NextT>,
112  NextT,
113  VCardThermalAirPollutantEmissions>
114 {
115 public:
117  typedef NextT NextType;
122 
125 
127 
128  enum
129  {
131  count = 1 + NextT::count,
132  };
133 
134  template<int CDataLevel, int CFile>
135  struct Statistics
136  {
137  enum
138  {
139  count = ((VCardType::categoryDataLevel & CDataLevel
140  && VCardType::categoryFileLevel & CFile)
141  ? (NextType::template Statistics<CDataLevel, CFile>::count
143  : NextType::template Statistics<CDataLevel, CFile>::count),
144  };
145  };
146 
147 public:
149  {
150  delete[] pValuesForTheCurrentYear;
151  }
152 
153  void initializeFromStudy(Data::Study& study)
154  {
155  pNbYearsParallel = study.maxNbYearsInParallel;
156 
157  InitializeResultsFromStudy(AncestorType::pResults, study);
158 
159  pValuesForTheCurrentYear = new VCardType::IntermediateValuesBaseType[pNbYearsParallel];
160  for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; ++numSpace)
161  {
162  for (unsigned int i = 0; i != VCardType::columnCount; ++i)
163  {
164  pValuesForTheCurrentYear[numSpace][i].initializeFromStudy(study);
165  }
166  }
167 
168  // Next
169  NextType::initializeFromStudy(study);
170  }
171 
172  template<class R>
173  static void InitializeResultsFromStudy(R& results, Data::Study& study)
174  {
175  for (unsigned int i = 0; i != VCardType::columnCount; ++i)
176  {
177  results[i].initializeFromStudy(study);
178  results[i].reset();
179  }
180  }
181 
182  void initializeFromArea(Data::Study* study, Data::Area* area)
183  {
184  // Next
185  NextType::initializeFromArea(study, area);
186  }
187 
188  void initializeFromLink(Data::Study* study, Data::AreaLink* link)
189  {
190  // Next
191  NextType::initializeFromAreaLink(study, link);
192  }
193 
194  void simulationBegin()
195  {
196  // Next
197  NextType::simulationBegin();
198  }
199 
200  void simulationEnd()
201  {
202  NextType::simulationEnd();
203  }
204 
205  void yearBegin(unsigned int year, unsigned int numSpace)
206  {
207  // Reset the values for the current year
208  for (unsigned int i = 0; i != VCardType::columnCount; ++i)
209  {
210  pValuesForTheCurrentYear[numSpace][i].reset();
211  }
212  // Next variable
213  NextType::yearBegin(year, numSpace);
214  }
215 
216  void yearEndBuild(State& state, unsigned int year, unsigned int numSpace)
217  {
218  // Next variable
219  NextType::yearEndBuild(state, year, numSpace);
220  }
221 
222  void yearEnd(unsigned int year, unsigned int numSpace)
223  {
224  VariableAccessorType::template ComputeStatistics<VCardType>(
225  pValuesForTheCurrentYear[numSpace]);
226 
227  // Next variable
228  NextType::yearEnd(year, numSpace);
229  }
230 
231  void computeSummary(unsigned int year, unsigned int numSpace)
232  {
233  // Merge all those values with the global results
234  VariableAccessorType::ComputeSummary(pValuesForTheCurrentYear[numSpace],
236  year);
237 
238  // Next variable
239  NextType::computeSummary(year, numSpace);
240  }
241 
242  void hourBegin(unsigned int hourInTheYear)
243  {
244  // Next variable
245  NextType::hourBegin(hourInTheYear);
246  }
247 
248  void hourForEachArea(State& state, unsigned int numSpace)
249  {
250  auto area = state.area;
251  auto& thermal = state.thermal;
252  for (auto& cluster: area->thermal.list.each_enabled())
253  {
254  // Multiply every pollutant factor with production
255  for (int pollutant = 0; pollutant < Antares::Data::Pollutant::POLLUTANT_MAX;
256  pollutant++)
257  {
258  pValuesForTheCurrentYear[numSpace][pollutant][state.hourInTheYear]
259  += cluster->emissions.factors[pollutant]
260  * thermal[state.area->index].thermalClustersProductions[cluster->enabledIndex];
261  }
262  }
263 
264  // Next variable
265  NextType::hourForEachArea(state, numSpace);
266  }
267 
268  Antares::Memory::Stored<double>::ConstReturnType retrieveRawHourlyValuesForCurrentYear(
269  unsigned int column,
270  unsigned int numSpace) const
271  {
272  return pValuesForTheCurrentYear[numSpace][column].hour;
273  }
274 
275  void localBuildAnnualSurveyReport(SurveyResults& results,
276  int fileLevel,
277  int precision,
278  unsigned int numSpace) const
279  {
280  // The current variable is actually a multiple-variable.
281  results.isCurrentVarNA = AncestorType::isNonApplicable;
282 
283  for (uint i = 0; i != VCardType::columnCount; ++i)
284  {
285  if (AncestorType::isPrinted[i])
286  {
287  // Write the data for the current year
288  results.variableCaption = VCardType::Multiple::Caption(i);
289  results.variableUnit = VCardType::Multiple::Unit(i);
290  pValuesForTheCurrentYear[numSpace][i]
291  .template buildAnnualSurveyReport<VCardType>(results, fileLevel, precision);
292  }
293  results.isCurrentVarNA++;
294  }
295  }
296 
297 private:
299  typename VCardType::IntermediateValuesType pValuesForTheCurrentYear;
300  unsigned int pNbYearsParallel;
301 
302 }; // class ThermalAirPollutantEmissions
303 
304 } // namespace Antares::Solver::Variable::Economy
305 
306 #endif // __SOLVER_VARIABLE_ECONOMY_thermalAirPollutantEmissions_H__
Definition for a single area.
Definition: area.h:51
Definition: study.h:57
Marginal ThermalAirPollutantEmissions.
Definition: thermalAirPollutantEmissions.h:114
VCardType::ResultsType ResultsType
List of expected results.
Definition: thermalAirPollutantEmissions.h:124
NextT NextType
Type of the next static variable.
Definition: thermalAirPollutantEmissions.h:117
Variable::IVariable< ThermalAirPollutantEmissions< NextT >, NextT, VCardType > AncestorType
Ancestor.
Definition: thermalAirPollutantEmissions.h:121
VCardThermalAirPollutantEmissions VCardType
VCard.
Definition: thermalAirPollutantEmissions.h:119
@ count
How many items have we got.
Definition: thermalAirPollutantEmissions.h:131
Interface for any variable.
Definition: variable.h:47
StoredResultType pResults
All the results about this variable.
Definition: variable.h:323
Temporary buffer for allocating results for a single year.
Definition: intermediate.h:42
Definition: results.h:44
@ count
The count if item in the list.
Definition: results.h:52
Definition: cbuilder.h:120
static constexpr uint8_t hasIntermediateValues
Intermediate values.
Definition: thermalAirPollutantEmissions.h:79
static std::string Description()
The short description of the variable.
Definition: thermalAirPollutantEmissions.h:44
static std::string Unit()
Unit.
Definition: thermalAirPollutantEmissions.h:38
static constexpr uint8_t precision
Precision (views)
Definition: thermalAirPollutantEmissions.h:67
static constexpr int columnCount
Number of columns used by the variable (One ResultsType per column)
Definition: thermalAirPollutantEmissions.h:73
static constexpr uint8_t isPossiblyNonApplicable
Can this variable be non applicable (0 : no, 1 : yes)
Definition: thermalAirPollutantEmissions.h:81
static constexpr uint8_t nodeDepthForGUI
Indentation (GUI)
Definition: thermalAirPollutantEmissions.h:69
Results< R::AllYears::Average< R::AllYears::StdDeviation< R::AllYears::Min< R::AllYears::Max< > > > > > ResultsType
The expecte results.
Definition: thermalAirPollutantEmissions.h:55
static constexpr uint8_t categoryDataLevel
Data Level.
Definition: thermalAirPollutantEmissions.h:61
static constexpr uint8_t spatialAggregate
The Spatial aggregation.
Definition: thermalAirPollutantEmissions.h:75
static std::string Caption()
Caption not used: several columns.
Definition: thermalAirPollutantEmissions.h:32
static constexpr uint8_t decimal
Decimal precision.
Definition: thermalAirPollutantEmissions.h:71
VCardThermalAirPollutantEmissions VCardForSpatialAggregate
The VCard to look for for calculating spatial aggregates.
Definition: thermalAirPollutantEmissions.h:58
static constexpr uint8_t categoryFileLevel
File level (provided by the type of the results)
Definition: thermalAirPollutantEmissions.h:63