Antares Simulator
Power System Simulator
Loading...
Searching...
No Matches
max-mrg-csr.h
1/*
2** Copyright 2007-2023 RTE
3** Authors: Antares_Simulator Team
4**
5** This file is part of Antares_Simulator.
6**
7** Antares_Simulator is free software: you can redistribute it and/or modify
8** it under the terms of the GNU General Public License as published by
9** the Free Software Foundation, either version 3 of the License, or
10** (at your option) any later version.
11**
12** There are special exceptions to the terms and conditions of the
13** license as they are applied to this software. View the full text of
14** the exceptions in file COPYING.txt in the directory of this software
15** distribution
16**
17** Antares_Simulator is distributed in the hope that it will be useful,
18** but WITHOUT ANY WARRANTY; without even the implied warranty of
19** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20** GNU General Public License for more details.
21**
22** You should have received a copy of the GNU General Public License
23** along with Antares_Simulator. If not, see <http://www.gnu.org/licenses/>.
24**
25** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions
26*/
27#pragma once
28
29#include "../variable.h"
30#include "max-mrg-utils.h"
31
32namespace Antares::Solver::Variable::Economy
33{
35{
37 static std::string Caption()
38 {
39 return "MAX MRG CSR";
40 }
41
43 static std::string Unit()
44 {
45 return "MWh";
46 }
47
49 static std::string Description()
50 {
51 return "Max margin for CSR";
52 }
53
55 typedef Results<R::AllYears::Average< // The average values throughout all years
56 R::AllYears::StdDeviation< // The standard deviation values throughout all years
57 R::AllYears::Min< // The minimum values throughout all years
58 R::AllYears::Max< // The maximum values throughout all years
59 >>>>>
61
64
65 static constexpr uint8_t categoryDataLevel = Category::DataLevel::area;
67 static constexpr uint8_t categoryFileLevel = ResultsType::categoryFile
68 & (Category::FileLevel::id
69 | Category::FileLevel::va);
71 static constexpr uint8_t precision = Category::all;
73 static constexpr uint8_t nodeDepthForGUI = +0;
75 static constexpr uint8_t decimal = 0;
77 static constexpr int columnCount = 1;
79 static constexpr uint8_t spatialAggregate = Category::spatialAggregateSum;
80 static constexpr uint8_t spatialAggregateMode = Category::spatialAggregateEachYear;
81 static constexpr uint8_t spatialAggregatePostProcessing = 0;
83 static constexpr uint8_t hasIntermediateValues = 1;
85 static constexpr uint8_t isPossiblyNonApplicable = 0;
86
88 typedef std::vector<IntermediateValues> IntermediateValuesType;
89
91
92}; // class VCard
93
97template<bool WithSimplexT>
98void PrepareMaxMRGFor(const State& state, double* opmrg, uint numSpace);
99
103template<class NextT = Container::EndOfList>
104class MaxMrgCsr: public Variable::IVariable<MaxMrgCsr<NextT>, NextT, VCardMAX_MRG_CSR>
105{
106public:
108 typedef NextT NextType;
113
116
118
119 enum
120 {
122 count = 1 + NextT::count,
123 };
124
125 template<int CDataLevel, int CFile>
127 {
128 enum
129 {
130 count = ((VCardType::categoryDataLevel & CDataLevel
132 ? (NextType::template Statistics<CDataLevel, CFile>::count
134 : NextType::template Statistics<CDataLevel, CFile>::count),
135 };
136 };
137
138public:
139 void initializeFromStudy(Data::Study& study)
140 {
141 pNbYearsParallel = study.maxNbYearsInParallel;
142
143 // Intermediate values
144 InitializeResultsFromStudy(AncestorType::pResults, study);
145
146 pValuesForTheCurrentYear.resize(pNbYearsParallel);
147 for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++)
148 {
149 pValuesForTheCurrentYear[numSpace].initializeFromStudy(study);
150 }
151
152 // Next
153 NextType::initializeFromStudy(study);
154 }
155
156 template<class R>
157 static void InitializeResultsFromStudy(R& results, Data::Study& study)
158 {
159 VariableAccessorType::InitializeAndReset(results, study);
160 }
161
162 void yearBegin(unsigned int year, unsigned int numSpace)
163 {
164 // Reset the values for the current year
165 pValuesForTheCurrentYear[numSpace].reset();
166 // Next variable
167 NextType::yearBegin(year, numSpace);
168 }
169
170 void yearEnd(unsigned int year, unsigned int numSpace)
171 {
172 // Compute all statistics for the current year (daily,weekly,monthly)
173 pValuesForTheCurrentYear[numSpace].computeStatisticsForTheCurrentYear();
174
175 // Next variable
176 NextType::yearEnd(year, numSpace);
177 }
178
179 void computeSummary(std::map<unsigned int, unsigned int>& numSpaceToYear,
180 unsigned int nbYearsForCurrentSummary)
181 {
182 for (unsigned int numSpace = 0; numSpace < nbYearsForCurrentSummary; ++numSpace)
183 {
184 // Merge all those values with the global results
185 AncestorType::pResults.merge(numSpaceToYear[numSpace] /*year*/,
186 pValuesForTheCurrentYear[numSpace]);
187 }
188
189 // Next variable
190 NextType::computeSummary(numSpaceToYear, nbYearsForCurrentSummary);
191 }
192
193 void weekForEachArea(State& state, unsigned int numSpace)
194 {
195 double* rawhourly = Memory::RawPointer(pValuesForTheCurrentYear[numSpace].hour);
196
197 // Getting data required to compute max margin
198 MaxMrgCSRdataFactory maxMRGcsrDataFactory(state, numSpace);
199 MaxMRGinput maxMRGinput = maxMRGcsrDataFactory.data();
200 computeMaxMRG(rawhourly + state.hourInTheYear, maxMRGinput);
201
202 // next
203 NextType::weekForEachArea(state, numSpace);
204 }
205
206 Antares::Memory::Stored<double>::ConstReturnType retrieveRawHourlyValuesForCurrentYear(
207 unsigned int,
208 unsigned int numSpace) const
209 {
210 return pValuesForTheCurrentYear[numSpace].hour;
211 }
212
213 void localBuildAnnualSurveyReport(SurveyResults& results,
214 int fileLevel,
215 int precision,
216 unsigned int numSpace) const
217 {
218 // Initializing external pointer on current variable non applicable status
219 results.isCurrentVarNA = AncestorType::isNonApplicable;
220
221 if (AncestorType::isPrinted[0])
222 {
223 // Write the data for the current year
224 results.variableCaption = VCardType::Caption();
225 results.variableUnit = VCardType::Unit();
226 pValuesForTheCurrentYear[numSpace]
227 .template buildAnnualSurveyReport<VCardType>(results, fileLevel, precision);
228 }
229 }
230
231private:
233 typename VCardType::IntermediateValuesType pValuesForTheCurrentYear;
234 unsigned int pNbYearsParallel;
235
236}; // class MaxMrgCsr
237
238} // namespace Antares::Solver::Variable::Economy
Definition study.h:61
Max MRG.
Definition max-mrg-csr.h:105
VCardMAX_MRG_CSR VCardType
VCard.
Definition max-mrg-csr.h:110
Variable::IVariable< MaxMrgCsr< NextT >, NextT, VCardType > AncestorType
Ancestor.
Definition max-mrg-csr.h:112
VCardType::ResultsType ResultsType
List of expected results.
Definition max-mrg-csr.h:115
@ count
How many items have we got.
Definition max-mrg-csr.h:122
NextT NextType
Type of the next static variable.
Definition max-mrg-csr.h:108
Interface for any variable.
Definition variable.h:51
StoredResultType pResults
All the results about this variable.
Definition variable.h:327
Temporary buffer for allocating results for a single year.
Definition intermediate.h:46
Definition results.h:48
@ count
The count if item in the list.
Definition results.h:56
Definition cbuilder.h:120
static constexpr uint8_t spatialAggregate
The Spatial aggregation.
Definition max-mrg-csr.h:79
static constexpr uint8_t nodeDepthForGUI
Indentation (GUI)
Definition max-mrg-csr.h:73
static constexpr uint8_t hasIntermediateValues
Intermediate values.
Definition max-mrg-csr.h:83
static std::string Unit()
Unit.
Definition max-mrg-csr.h:43
static std::string Description()
The short description of the variable.
Definition max-mrg-csr.h:49
static constexpr int columnCount
Number of columns used by the variable (One ResultsType per column)
Definition max-mrg-csr.h:77
static std::string Caption()
Caption.
Definition max-mrg-csr.h:37
static constexpr uint8_t precision
Precision (views)
Definition max-mrg-csr.h:71
Results< R::AllYears::Average< R::AllYears::StdDeviation< R::AllYears::Min< R::AllYears::Max< > > > > > ResultsType
The expecte results.
Definition max-mrg-csr.h:60
static constexpr uint8_t decimal
Decimal precision.
Definition max-mrg-csr.h:75
VCardMAX_MRG_CSR VCardForSpatialAggregate
The VCard to look for for calculating spatial aggregates.
Definition max-mrg-csr.h:63
static constexpr uint8_t categoryFileLevel
File level (provided by the type of the results)
Definition max-mrg-csr.h:67
static constexpr uint8_t isPossiblyNonApplicable
Can this variable be non applicable (0 : no, 1 : yes)
Definition max-mrg-csr.h:85