21 #ifndef __SOLVER_VARIABLE_INFO_H__
22 #define __SOLVER_VARIABLE_INFO_H__
26 #include "antares/solver/variable/surveyresults.h"
27 #include "antares/study/fwd.h"
29 namespace Antares::Solver::Variable
37 template<
class T,
int N>
49 template<
class T,
int N>
61 template<
class ResultsT,
int ColumnCountT>
64 typedef typename SpecifierRemover<ResultsT>::Type CleanType;
65 typedef CleanType Type[ColumnCountT];
68 static void MultiplyHourlyResultsBy(U& intermediateValues,
const double v)
70 assert(!std::isnan(v));
71 for (uint i = 0; i != ColumnCountT; ++i)
73 Antares::Memory::Stored<double>::ReturnType array = intermediateValues[i].hour;
74 for (uint y = 0; y != HOURS_PER_YEAR; ++y)
82 static void SetTo1IfPositive(U& intermediateValues)
84 for (uint i = 0; i != ColumnCountT; ++i)
86 Antares::Memory::Stored<double>::ReturnType array = intermediateValues[i].hour;
87 for (uint y = 0; y != HOURS_PER_YEAR; ++y)
89 array[y] = std::abs(array[y]) > 0. ? 1. : 0.;
95 static void Or(U& intermediateValues)
97 for (uint i = 0; i != ColumnCountT; ++i)
99 Antares::Memory::Stored<double>::ReturnType array = intermediateValues[i].hour;
100 for (uint y = 0; y != HOURS_PER_YEAR; ++y)
102 array[y] = std::abs(array[y]) > 0. ? 100. : 0.;
108 static void InitializeAndReset(U& out,
Data::Study& study)
110 for (uint i = 0; i != ColumnCountT; ++i)
112 out[i].initializeFromStudy(study);
118 static void Reset(U& out)
120 for (uint i = 0; i != ColumnCountT; ++i)
126 template<
class VCardT,
class U>
127 static void ComputeStatistics(U& intermediateValues)
129 for (uint i = 0; i != ColumnCountT; ++i)
132 if (VCardT::spatialAggregate & Category::spatialAggregateOr)
134 intermediateValues[i].computeStatisticsOrForTheCurrentYear();
138 if (VCardT::spatialAggregatePostProcessing
139 == (
int)Category::spatialAggregatePostProcessingPrice)
141 intermediateValues[i].computeAveragesForCurrentYearFromHourlyResults();
145 intermediateValues[i].computeStatisticsForTheCurrentYear();
152 static void ComputeSummary(U& intermediateValues, Type& container, uint year)
154 for (uint i = 0; i != ColumnCountT; ++i)
157 container[i].merge(year, intermediateValues[i]);
161 template<
class VCardT>
163 const Type& container,
167 for (uint i = 0; i != ColumnCountT; ++i)
172 results.variableUnit = VCardT::Multiple::Unit(i);
173 container[i].template buildDigest<VCardT>(results, digestLevel, dataLevel);
181 template<
class VCardType>
183 const Type& container,
188 for (uint i = 0; i != ColumnCountT; ++i)
193 results.variableUnit = VCardType::Multiple::Unit(i);
194 container[i].template buildSurveyReport<ResultsT, VCardType>(results,
206 template<
class VCardType>
208 const Type& container,
212 for (uint i = 0; i != ColumnCountT; ++i)
217 container[i].template buildAnnualSurveyReport<VCardType>(results,
227 template<
class U,
class VarT>
228 static void ComputeSum(U& out,
const VarT& var, uint numSpace)
230 for (uint i = 0; i != ColumnCountT; ++i)
232 Antares::Memory::Stored<double>::ConstReturnType src
233 = var.retrieveRawHourlyValuesForCurrentYear(i, numSpace);
236 for (uint h = 0; h != HOURS_PER_YEAR; ++h)
238 out[i].hour[h] += src[h];
243 template<
class U,
class VarT>
244 static void ComputeMax(U& out,
const VarT& var, uint numSpace)
246 for (uint i = 0; i != ColumnCountT; ++i)
248 Antares::Memory::Stored<double>::ConstReturnType src
249 = var.retrieveRawHourlyValuesForCurrentYear(i, numSpace);
252 for (uint h = 0; h != HOURS_PER_YEAR; ++h)
254 if (out[i].hour[h] < src[h])
256 out[i].hour[h] = src[h];
263 template<
class ResultsT>
266 typedef typename SpecifierRemover<ResultsT>::Type CleanType;
267 typedef std::vector<CleanType> Type;
270 static void MultiplyHourlyResultsBy(U& intermediateValues,
const double v)
272 assert(!std::isnan(v));
274 const typename Type::const_iterator end = intermediateValues.end();
275 for (
typename Type::const_iterator i = intermediateValues.begin(); i != end; ++i)
278 for (uint y = 0; y != HOURS_PER_YEAR; ++y)
286 static void SetTo1IfPositive(U& intermediateValues)
289 const typename Type::const_iterator end = intermediateValues.end();
290 for (
typename Type::const_iterator i = intermediateValues.begin(); i != end; ++i)
293 for (uint y = 0; y != HOURS_PER_YEAR; ++y)
295 array[y] = std::abs(array[y]) > 0. ? 1. : 0.;
301 static void Or(U& intermediateValues)
304 const typename Type::const_iterator end = intermediateValues.end();
305 for (
typename Type::const_iterator i = intermediateValues.begin(); i != end; ++i)
308 for (uint y = 0; y != HOURS_PER_YEAR; ++y)
310 array[y] = std::abs(array[y]) > 0. ? 100. : 0.;
316 static void InitializeAndReset(U& out,
Data::Study& study)
318 const typename Type::const_iterator end = out.end();
319 for (
typename Type::const_iterator i = out.begin(); i != end; ++i)
321 (*i).initializeFromStudy(study);
327 static void Reset(U& out)
329 const typename Type::const_iterator end = out.end();
330 for (
typename Type::const_iterator i = out.begin(); i != end; ++i)
336 template<
class VCardT,
class U>
337 static void ComputeStatistics(U& intermediateValues, Type& container, uint)
339 for (uint i = 0; i != container.size(); ++i)
341 if (VCardT::spatialAggregate & Category::spatialAggregateOr)
343 intermediateValues[i].computeStatisticsOrForTheCurrentYear();
348 if (VCardT::spatialAggregatePostProcessing
349 == (
int)Category::spatialAggregatePostProcessingPrice)
352 intermediateValues[i].computeAveragesForCurrentYearFromHourlyResults();
356 intermediateValues[i].computeStatisticsForTheCurrentYear();
363 static void ComputeSummary(U& intermediateValues, Type& container, uint year)
365 for (uint i = 0; i != container.size(); ++i)
368 container[i].merge(year, intermediateValues[i]);
372 template<
class VCardT>
374 const Type& container,
381 for (uint i = 0; i != container.size(); ++i)
385 container[i].template buildDigest<VCardT>(results, digestLevel, dataLevel);
390 static bool setClusterCaption(
SurveyResults& results,
int fileLevel, uint idx)
392 assert(results.
data.
area &&
"Area is NULL");
393 const bool thermal_details = fileLevel & Category::FileLevel::de;
394 const bool renewable_details = fileLevel & Category::FileLevel::de_res;
395 const bool st_storage_details = fileLevel & Category::FileLevel::de_sts;
397 std::array<bool, 3> kind_of_details = {thermal_details,
403 auto how_many_kinds_of_details = std::count(kind_of_details.begin(),
404 kind_of_details.end(),
407 if (how_many_kinds_of_details != 1)
409 logs.error() <<
"Inconsistent fileLevel detected";
415 auto& thermal = results.
data.
area->thermal;
419 if (renewable_details)
421 auto& renewable = results.
data.
area->renewable;
422 results.
variableCaption = renewable.list.enabledClusterAt(idx)->name();
425 if (st_storage_details)
427 auto& st_storage_part = results.
data.
area->shortTermStorage;
428 results.
variableCaption = st_storage_part.storagesByIndex[idx].properties.name;
434 template<
class VCardType>
436 const Type& container,
444 for (uint i = 0; i != container.size(); ++i)
446 res = setClusterCaption(results, fileLevel, i);
451 results.variableUnit = VCardType::Unit();
453 container[i].template buildSurveyReport<ResultsT, VCardType>(results,
462 template<
class VCardType>
464 const Type& container,
471 for (uint i = 0; i != container.size(); ++i)
473 res = setClusterCaption(results, fileLevel, i);
478 container[i].template buildAnnualSurveyReport<VCardType>(results,
485 template<
class U,
class VarT>
486 static void ComputeSum(U& out,
const VarT& var, uint numSpace)
488 for (uint i = 0; i != var.results().size(); ++i)
490 Antares::Memory::Stored<double>::ConstReturnType src
491 = var.retrieveRawHourlyValuesForCurrentYear(i, numSpace);
494 for (uint h = 0; h != HOURS_PER_YEAR; ++h)
496 out[i].hour[h] += src[h];
501 template<
class U,
class VarT>
502 static void ComputeMax(U& out,
const VarT& var, uint numSpace)
504 for (uint i = 0; i != var.results().size(); ++i)
506 Antares::Memory::Stored<double>::ConstReturnType src
507 = var.retrieveRawHourlyValuesForCurrentYear(i, numSpace);
510 for (uint h = 0; h != HOURS_PER_YEAR; ++h)
512 if (out[i].hour[h] < src[h])
514 out[i].hour[h] = src[h];
521 template<
class ResultsT>
524 typedef typename SpecifierRemover<ResultsT>::Type CleanType;
525 typedef CleanType Type;
528 static void MultiplyHourlyResultsBy(U& intermediateValues,
const double v)
530 assert(!std::isnan(v));
531 for (uint y = 0; y != HOURS_PER_YEAR; ++y)
533 intermediateValues.hour[y] *= v;
538 static void SetTo1IfPositive(U& intermediateValues)
540 for (uint y = 0; y != HOURS_PER_YEAR; ++y)
542 intermediateValues.hour[y] = std::abs(intermediateValues.hour[y]) > 0. ? 1. : 0.;
547 static void Or(U& intermediateValues)
549 for (uint y = 0; y != HOURS_PER_YEAR; ++y)
551 intermediateValues.hour[y] = std::abs(intermediateValues.hour[y]) > 0. ? 100. : 0.;
556 static void InitializeAndReset(U& out,
Data::Study& study)
558 out.initializeFromStudy(study);
563 static void Reset(U& out)
568 template<
class VCardT,
class U>
569 static void ComputeStatistics(U& intermediateValues)
571 if (VCardT::spatialAggregate & Category::spatialAggregateOr)
573 intermediateValues.computeStatisticsOrForTheCurrentYear();
578 if (VCardT::spatialAggregatePostProcessing
579 == (
int)Category::spatialAggregatePostProcessingPrice)
582 intermediateValues.computeAveragesForCurrentYearFromHourlyResults();
586 intermediateValues.computeStatisticsForTheCurrentYear();
592 static void ComputeSummary(U& intermediateValues, Type& container, uint year)
595 container.merge(year, intermediateValues);
598 template<
class VCardT>
600 const Type& container,
607 results.variableUnit = VCardT::Unit();
608 container.template buildDigest<VCardT>(results, digestLevel, dataLevel);
612 template<
class VCardType>
614 const Type& container,
618 bool updateCaption =
true)
625 results.variableUnit = VCardType::Unit();
627 container.template buildSurveyReport<ResultsT, VCardType>(results,
635 template<
class VCardType>
637 const Type& container,
644 results.variableUnit = VCardType::Unit();
645 container.template buildAnnualSurveyReport<VCardType>(results, fileLevel, precision);
649 template<
class U,
class VarT>
650 static void ComputeSum(U& out,
const VarT& var, uint numSpace)
652 Antares::Memory::Stored<double>::ConstReturnType src
653 = var.retrieveRawHourlyValuesForCurrentYear(-1, numSpace);
656 for (uint h = 0; h != HOURS_PER_YEAR; ++h)
658 out.hour[h] += src[h];
662 template<
class U,
class VarT>
663 static void ComputeMax(U& out,
const VarT& var, uint numSpace)
665 Antares::Memory::Stored<double>::ConstReturnType src
666 = var.retrieveRawHourlyValuesForCurrentYear(-1, numSpace);
669 for (uint h = 0; h != HOURS_PER_YEAR; ++h)
671 if (out.hour[h] < src[h])
673 out.hour[h] = src[h];
679 template<
class ResultsT>
682 typedef typename SpecifierRemover<ResultsT>::Type CleanType;
683 typedef CleanType Type;
686 static void MultiplyHourlyResultsBy(U&,
const double)
692 static void SetTo1IfPositive(U&)
708 static void Reset(U&)
713 template<
class VCardT,
class U>
714 static void ComputeStatisticsAndMerge(U&, Type&, uint)
719 static uint64_t Value(
const Type&)
724 template<
class VCardType>
725 static void BuildSurveyReport(
SurveyResults&,
const Type&,
int,
int,
int)
730 template<
class VCardType>
731 static void BuildAnnualSurveyReport(
SurveyResults&,
const Type&,
int,
int)
736 template<
class VCardT>
737 static void BuildDigest(
SurveyResults&,
const Type&,
int,
int)
742 template<
class U,
class VarT>
743 static void ComputeSum(U&,
const VarT&, uint)
748 template<
class U,
class VarT>
749 static void ComputeMax(U&,
const VarT&, uint)
755 template<
class VCardT>
763 template<
bool Allowed,
int OperationT,
class VCardT>
766 template<
class U,
class VarT>
767 static void Perform(U&,
const VarT&, uint)
773 template<
class VCardT>
776 template<
class U,
class VarT>
777 static void Perform(U& intermediateResults,
const VarT& var, uint numSpace)
779 typedef typename VCardT::ResultsType ResultsType;
787 template<
class VCardT>
790 template<
class U,
class VarT>
791 static void Perform(U& intermediateResults,
const VarT& var, uint numSpace)
793 typedef typename VCardT::ResultsType ResultsType;
801 template<
class VCardT>
804 template<
class U,
class VarT>
805 static void Perform(U& intermediateResults,
const VarT& var, uint numSpace)
807 typedef typename VCardT::ResultsType ResultsType;
815 template<
class VCardT>
818 template<
class U,
class VarT>
819 static void Perform(U& intermediateResults,
const VarT& var, uint numSpace)
821 typedef typename VCardT::ResultsType ResultsType;
829 template<
class VCardT>
832 template<
class U,
class VarT>
833 static void Perform(U& intermediateResults,
const VarT& var, uint numSpace)
835 typedef typename VCardT::ResultsType ResultsType;
Definition: container.h:31
ThermalClusterList list
List of all thermal clusters (enabled and disabled) except must-run clusters.
Definition: container.h:88
const Data::Area * area
Current area.
Definition: data.h:63
Class utility for building CSV results files.
Definition: surveyresults.h:41
bool * isPrinted
Same thing for print status (do we print the current output variable ?)
Definition: surveyresults.h:134
CaptionType variableCaption
Caption for the current variable.
Definition: surveyresults.h:95
Solver::Variable::Private::SurveyResultsData data
Data (not related to the template parameter)
Definition: surveyresults.h:92
bool * isCurrentVarNA
Definition: surveyresults.h:132
VariableAccessor< typename VCardT::ResultsType, VCardT::columnCount >::Type ResultsType
The true type used for the results.
Definition: info.h:760