source: XIOS/dev/branch_yushan/src/transformation/Functions/average_reduction.cpp @ 1037

Last change on this file since 1037 was 1037, checked in by yushan, 7 years ago

initialize the branch

File size: 1.5 KB
RevLine 
[979]1/*!
2   \file average.cpp
3   \author Ha NGUYEN
4   \since 8 Sep 2016
[1037]5   \date 8 Sep 2016
[979]6
7   \brief average reduction
8 */
9#include "average_reduction.hpp"
10
11namespace xios {
12
13CAverageReductionAlgorithm::CAverageReductionAlgorithm()
14  : CReductionAlgorithm(), resetWeight_(true)
15{
16}
17
18CReductionAlgorithm* CAverageReductionAlgorithm::create()
19{
20  return (new CAverageReductionAlgorithm());
21}
22
23bool CAverageReductionAlgorithm::registerTrans()
24{
25  return registerOperation(TRANS_REDUCE_AVERAGE, CAverageReductionAlgorithm::create);
26}
27
28void CAverageReductionAlgorithm::apply(const std::vector<std::pair<int,double> >& localIndex,
29                                       const double* dataInput,
30                                       CArray<double,1>& dataOut,
[1037]31                                       std::vector<bool>& flagInitial)
[979]32{
33  if (resetWeight_) { weights_.resize(flagInitial.size()); weights_ = 1.0; resetWeight_ = false; }
34
[1037]35  int nbLocalIndex = localIndex.size();
36  int currentlocalIndex = 0;
37  double currentWeight  = 0.0;
38  for (int idx = 0; idx < nbLocalIndex; ++idx)
[979]39  {
[1037]40    currentlocalIndex = localIndex[idx].first;
41    currentWeight     = localIndex[idx].second;
42
43    if (flagInitial[currentlocalIndex])
[979]44    {
[1037]45      dataOut(currentlocalIndex) = *(dataInput + idx);
46      flagInitial[currentlocalIndex] = false;
[979]47    }
[1037]48    else
[979]49    {
[1037]50      dataOut(currentlocalIndex)  += *(dataInput + idx);
51      weights_(currentlocalIndex) += 1.0;
[979]52    }
53  }
54}
55
56void CAverageReductionAlgorithm::updateData(CArray<double,1>& dataOut)
57{
58  dataOut /= weights_;
59  resetWeight_ = true;
60}
61
62}
Note: See TracBrowser for help on using the repository browser.