source: XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/reduce_transform_connector.cpp @ 2000

Last change on this file since 2000 was 2000, checked in by ymipsl, 10 months ago

Add reduce operation for transformation (sum was already fonctional)
min, max, average
YM

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 1.9 KB
Line 
1#include "reduce_transform_connector.hpp"
2#include "exception.hpp"
3
4namespace xios
5{
6
7  CReduceTransformConnector::CReduceTransformConnector(CLocalView* srcView, CLocalView* dstView, EReduction op, 
8                                                       unordered_map<int, std::vector<int>>& indexMap, bool detectMissingValue)
9   : srcView_(srcView), dstView_(dstView), detectMissingValue_(detectMissingValue)
10  {
11    switch(op)
12    {
13      case EReduction::sum :
14        transfer_=&CReduceTransformConnector::transferSum ;
15        break ;
16      case EReduction::min :
17        transfer_=&CReduceTransformConnector::transferMin ;
18        break ;
19      case EReduction::max :
20        transfer_=&CReduceTransformConnector::transferMax ;
21        break ;
22     case EReduction::average :
23        transfer_=&CReduceTransformConnector::transferAverage ;
24        break ;
25      default :
26       ERROR("CReduceTransformConnector::CReduceTransformConnector",
27             <<"reduction operator "<<(int)op<<" is not defined for this operation") ;
28       break ;
29    }
30
31    computeConnector(indexMap) ;
32  }
33
34  void CReduceTransformConnector::computeConnector(unordered_map<int, std::vector<int>>& indexMap)
35  {
36    CArray<size_t,1> dstGlobalIndex ;
37    CArray<size_t,1> srcGlobalIndex ;
38    dstView_->getGlobalIndexView(dstGlobalIndex) ;
39    srcView_->getGlobalIndexView(srcGlobalIndex) ;
40    unordered_map<size_t,int> srcMapIndex ;
41    srcSize_ = srcGlobalIndex.numElements() ;
42    dstSize_ = dstGlobalIndex.numElements() ;
43
44    for(int i=0;i<srcSize_;i++) srcMapIndex[srcGlobalIndex(i)]=i ;
45    for(int i=0; i< dstSize_;i++) 
46    {
47      if (indexMap.count(dstGlobalIndex(i))!=0)
48      {
49        auto& vectIndex  = indexMap[dstGlobalIndex(i)] ;
50        nSrc_.push_back(vectIndex.size()) ;
51        for(int j=0; j<vectIndex.size();j++) connector_.push_back(srcMapIndex[vectIndex[j]]) ;
52      }
53      else nSrc_.push_back(0) ;
54    }
55  }
56
57}
Note: See TracBrowser for help on using the repository browser.