Antares Simulator
Power System Simulator
profitByPlant.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 
22 #pragma once
23 
24 #include "antares/solver/variable/variable.h"
25 
26 namespace Antares::Solver::Variable::Economy
27 {
29 {
31  static std::string Caption()
32  {
33  return "Profit by plant";
34  }
35 
37  static std::string Unit()
38  {
39  return "Profit - Euro";
40  }
41 
43  static std::string Description()
44  {
45  return "Profit for thermal units";
46  }
47 
49  typedef Results<R::AllYears::Average< // The average values throughout all years
50  >>
52 
55 
57  static constexpr uint8_t categoryDataLevel = Category::DataLevel::area;
59  static constexpr uint8_t categoryFileLevel = ResultsType::categoryFile
60  & (Category::FileLevel::de);
62  static constexpr uint8_t precision = Category::all;
64  static constexpr uint8_t nodeDepthForGUI = +0;
66  static constexpr uint8_t decimal = 0;
68  static constexpr int columnCount = Category::dynamicColumns;
70  static constexpr uint8_t spatialAggregate = Category::spatialAggregateSum;
71  static constexpr uint8_t spatialAggregateMode = Category::spatialAggregateEachYear;
72  static constexpr uint8_t spatialAggregatePostProcessing = 0;
74  static constexpr uint8_t hasIntermediateValues = 1;
76  static constexpr uint8_t isPossiblyNonApplicable = 0;
77 
79  typedef std::vector<IntermediateValues> IntermediateValuesBaseType;
80  typedef std::vector<IntermediateValuesBaseType> IntermediateValuesType;
81 }; // class VCard
82 
87 template<class NextT = Container::EndOfList>
88 class ProfitByPlant: public Variable::IVariable<ProfitByPlant<NextT>, NextT, VCardProfitByPlant>
89 {
90 public:
92  typedef NextT NextType;
97 
100 
102 
103  enum
104  {
106  count = 1 + NextT::count,
107  };
108 
109  template<int CDataLevel, int CFile>
110  struct Statistics
111  {
112  enum
113  {
114  count = ((VCardType::categoryDataLevel & CDataLevel
115  && VCardType::categoryFileLevel & CFile)
116  ? (NextType::template Statistics<CDataLevel, CFile>::count
118  : NextType::template Statistics<CDataLevel, CFile>::count),
119  };
120  };
121 
122 public:
123  ProfitByPlant():
124  pNbClustersOfArea(0)
125  {
126  }
127 
128  void initializeFromStudy(Data::Study& study)
129  {
130  // Next
131  NextType::initializeFromStudy(study);
132  }
133 
134  void initializeFromArea(Data::Study* study, Data::Area* area)
135  {
136  // Get the number of years in parallel
137  pNbYearsParallel = study->maxNbYearsInParallel;
138  pValuesForTheCurrentYear.resize(pNbYearsParallel);
139 
140  // Get the area
141  pNbClustersOfArea = area->thermal.list.enabledCount();
142  if (pNbClustersOfArea)
143  {
144  AncestorType::pResults.resize(pNbClustersOfArea);
145  for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++)
146  {
147  pValuesForTheCurrentYear[numSpace].resize(pNbClustersOfArea);
148  }
149 
150  for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++)
151  {
152  for (unsigned int i = 0; i != pNbClustersOfArea; ++i)
153  {
154  pValuesForTheCurrentYear[numSpace][i].initializeFromStudy(*study);
155  }
156  }
157 
158  for (unsigned int i = 0; i != pNbClustersOfArea; ++i)
159  {
160  AncestorType::pResults[i].initializeFromStudy(*study);
161  AncestorType::pResults[i].reset();
162  }
163  }
164  else
165  {
166  AncestorType::pResults.clear();
167  }
168 
169  // Next
170  NextType::initializeFromArea(study, area);
171  }
172 
173  size_t getMaxNumberColumns() const
174  {
175  return pNbClustersOfArea * ResultsType::count;
176  }
177 
178  void initializeFromLink(Data::Study* study, Data::AreaLink* link)
179  {
180  // Next
181  NextType::initializeFromAreaLink(study, link);
182  }
183 
184  void simulationBegin()
185  {
186  // Next
187  NextType::simulationBegin();
188  }
189 
190  void simulationEnd()
191  {
192  NextType::simulationEnd();
193  }
194 
195  void yearBegin(unsigned int year, unsigned int numSpace)
196  {
197  // Reset the values for the current year
198  for (unsigned int i = 0; i != pNbClustersOfArea; ++i)
199  {
200  pValuesForTheCurrentYear[numSpace][i].reset();
201  }
202 
203  // Next variable
204  NextType::yearBegin(year, numSpace);
205  }
206 
207  void yearEndBuild(State& state, unsigned int year, unsigned int numSpace)
208  {
209  // Next variable
210  NextType::yearEndBuild(state, year, numSpace);
211  }
212 
213  void yearEnd(unsigned int year, unsigned int numSpace)
214  {
215  // Merge all results for all thermal clusters
216  {
217  for (unsigned int i = 0; i < pNbClustersOfArea; ++i)
218  {
219  // Compute all statistics for the current year (daily,weekly,monthly)
220  pValuesForTheCurrentYear[numSpace][i].computeStatisticsForTheCurrentYear();
221  }
222  }
223  // Next variable
224  NextType::yearEnd(year, numSpace);
225  }
226 
227  void computeSummary(unsigned int year, unsigned int numSpace)
228  {
229  for (unsigned int clusterIndex = 0; clusterIndex < pNbClustersOfArea; ++clusterIndex)
230  {
231  // Merge all those values with the global results
232  AncestorType::pResults[clusterIndex]
233  .merge(year, pValuesForTheCurrentYear[numSpace][clusterIndex]);
234  }
235 
236  // Next variable
237  NextType::computeSummary(year, numSpace);
238  }
239 
240  void hourBegin(unsigned int hourInTheYear)
241  {
242  // Next variable
243  NextType::hourBegin(hourInTheYear);
244  }
245 
246  void hourForEachArea(State& state, unsigned int numSpace)
247  {
248  // Useful local variables
249  auto area = state.area;
250  auto& thermal = state.thermal;
251  const std::vector<double>& areaMarginalCosts = state.hourlyResults->CoutsMarginauxHoraires;
252  uint hourInTheWeek = state.hourInTheWeek;
253  uint hourInTheYear = state.hourInTheYear;
254 
255  for (auto& cluster: area->thermal.list.each_enabled())
256  {
257  double hourlyClusterProduction = thermal[area->index]
258  .thermalClustersProductions[cluster->enabledIndex];
259  uint tsIndex = cluster->series.timeseriesNumbers[state.year];
260 
261  // Thermal cluster profit
262  pValuesForTheCurrentYear[numSpace][cluster->enabledIndex].hour[hourInTheYear]
263  = std::max((hourlyClusterProduction - cluster->PthetaInf[hourInTheYear]), 0.)
264  * (-areaMarginalCosts[hourInTheWeek]
265  - cluster->getCostProvider().getMarginalCost(tsIndex, hourInTheYear));
266  }
267 
268  // Next variable
269  NextType::hourForEachArea(state, numSpace);
270  }
271 
272  Antares::Memory::Stored<double>::ConstReturnType retrieveRawHourlyValuesForCurrentYear(
273  unsigned int,
274  unsigned int numSpace) const
275  {
276  return pValuesForTheCurrentYear[numSpace][0].hour;
277  }
278 
279  void localBuildAnnualSurveyReport(SurveyResults& results,
280  int fileLevel,
281  int precision,
282  unsigned int numSpace) const
283  {
284  // Initializing external pointer on current variable non applicable status
285  results.isCurrentVarNA = AncestorType::isNonApplicable;
286 
287  if (AncestorType::isPrinted[0])
288  {
289  assert(NULL != results.data.area);
290  const auto& thermal = results.data.area->thermal;
291 
292  // Write the data for the current year
293  for (auto& cluster: thermal.list.each_enabled())
294  {
295  // Write the data for the current year
296  results.variableCaption = cluster->name(); // VCardType::Caption();
297  results.variableUnit = VCardType::Unit();
298  pValuesForTheCurrentYear[numSpace][cluster->enabledIndex]
299  .template buildAnnualSurveyReport<VCardType>(results, fileLevel, precision);
300  }
301  }
302  }
303 
304 private:
306  typename VCardType::IntermediateValuesType pValuesForTheCurrentYear;
307  size_t pNbClustersOfArea;
308  unsigned int pNbYearsParallel;
309 
310 }; // class
311 
312 } // namespace Antares::Solver::Variable::Economy
Definition for a single area.
Definition: area.h:51
Definition: study.h:57
C02 Average value of the overrall OperatingCost emissions expected from all the thermal dispatchable ...
Definition: profitByPlant.h:89
VCardProfitByPlant VCardType
VCard.
Definition: profitByPlant.h:94
VCardType::ResultsType ResultsType
List of expected results.
Definition: profitByPlant.h:99
Variable::IVariable< ProfitByPlant< NextT >, NextT, VCardType > AncestorType
Ancestor.
Definition: profitByPlant.h:96
NextT NextType
Type of the next static variable.
Definition: profitByPlant.h:92
@ count
How many items have we got.
Definition: profitByPlant.h:106
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
VCardProfitByPlant VCardForSpatialAggregate
The VCard to look for calculating spatial aggregates.
Definition: profitByPlant.h:54
static constexpr uint8_t spatialAggregate
The Spatial aggregation.
Definition: profitByPlant.h:70
static constexpr uint8_t nodeDepthForGUI
Indentation (GUI)
Definition: profitByPlant.h:64
static constexpr uint8_t decimal
Decimal precision.
Definition: profitByPlant.h:66
static constexpr uint8_t hasIntermediateValues
Intermediate values.
Definition: profitByPlant.h:74
static std::string Unit()
Unit.
Definition: profitByPlant.h:37
static constexpr uint8_t precision
Precision (views)
Definition: profitByPlant.h:62
static constexpr uint8_t categoryFileLevel
File level (provided by the type of the results)
Definition: profitByPlant.h:59
static constexpr int columnCount
Number of columns used by the variable.
Definition: profitByPlant.h:68
static std::string Description()
The short description of the variable.
Definition: profitByPlant.h:43
Results< R::AllYears::Average< > > ResultsType
The expected results.
Definition: profitByPlant.h:51
static constexpr uint8_t categoryDataLevel
Data Level.
Definition: profitByPlant.h:57
static std::string Caption()
Caption.
Definition: profitByPlant.h:31
static constexpr uint8_t isPossiblyNonApplicable
Can this variable be non applicable (0 : no, 1 : yes)
Definition: profitByPlant.h:76