XIOS  1.0
Xml I/O Server
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Définitions de type Énumérations Valeurs énumérées Amis Macros
average_reduction.cpp
Aller à la documentation de ce fichier.
1 
9 #include "average_reduction.hpp"
10 #include "utils.hpp"
11 
12 namespace xios {
13 
15  : CReductionAlgorithm(), resetWeight_(true)
16 {
17 }
18 
20 {
21  return (new CAverageReductionAlgorithm());
22 }
23 
25 {
27 }
28 
29 void CAverageReductionAlgorithm::apply(const std::vector<std::pair<int,double> >& localIndex,
30  const double* dataInput,
31  CArray<double,1>& dataOut,
32  std::vector<bool>& flagInitial,
33  bool ignoreMissingValue, bool firstPass)
34 {
35  if (resetWeight_) { weights_.resize(flagInitial.size()); weights_ = 1.0; resetWeight_ = false; }
36 
37  if (ignoreMissingValue)
38  {
39  int nbLocalIndex = localIndex.size();
40  int currentlocalIndex = 0;
41  double currentWeight = 0.0;
42 
43  if (firstPass) dataOut=std::numeric_limits<double>::quiet_NaN();
44 
45  for (int idx = 0; idx < nbLocalIndex; ++idx)
46  {
47  currentlocalIndex = localIndex[idx].first;
48  currentWeight = localIndex[idx].second;
49  if (!NumTraits<double>::isNan(*(dataInput + idx)))
50  {
51  if (flagInitial[currentlocalIndex])
52  {
53  dataOut(currentlocalIndex) = *(dataInput + idx);
54  flagInitial[currentlocalIndex] = false;
55  }
56  else
57  {
58  dataOut(currentlocalIndex) += *(dataInput + idx);
59  weights_(currentlocalIndex) += 1.0;
60  }
61  }
62  }
63  }
64  else
65  {
66  int nbLocalIndex = localIndex.size();
67  int currentlocalIndex = 0;
68  double currentWeight = 0.0;
69  for (int idx = 0; idx < nbLocalIndex; ++idx)
70  {
71  currentlocalIndex = localIndex[idx].first;
72  currentWeight = localIndex[idx].second;
73 
74  if (flagInitial[currentlocalIndex])
75  {
76  dataOut(currentlocalIndex) = *(dataInput + idx);
77  flagInitial[currentlocalIndex] = false;
78  }
79  else
80  {
81  dataOut(currentlocalIndex) += *(dataInput + idx);
82  weights_(currentlocalIndex) += 1.0;
83  }
84  }
85  }
86 }
87 
89 {
90  dataOut /= weights_;
91  resetWeight_ = true;
92 }
93 
94 }
virtual size_t size(void) const
Definition: array_new.hpp:548
Some utils for Xios.
#define xios(arg)
virtual void updateData(CArray< double, 1 > &dataOut)
Update local data In some case (e.g average) we need global information (e.g weights) then update dat...
void resize(int extent)
Definition: array_new.hpp:320
static CReductionAlgorithm * create()
virtual void apply(const std::vector< std::pair< int, double > > &localIndex, const double *dataInput, CArray< double, 1 > &dataOut, std::vector< bool > &flagInitial, bool ignoreMissingValue, bool firstPass)
Apply a reduction operation on local data.
static bool registerOperation(EReductionType reduceType, CreateOperationCallBack createFn)
Definition: reduction.cpp:46
Interface for all reduction alogrithms.
Definition: reduction.hpp:22