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

Last change on this file since 1999 was 1999, checked in by ymipsl, 3 years ago

Adapt transformation algorithm to new infrastructure (on going...)

YM

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 1.7 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        break ;
18      case EReduction::max :
19        break ;
20      case EReduction::extract :
21        break ;
22      case EReduction::average :
23        break ;
24      default :
25       ERROR("CReduceTransformConnector::CReduceTransformConnector",
26             <<"reduction operator "<<(int)op<<" is not defined for this operation") ;
27       break ;
28    }
29
30    computeConnector(indexMap) ;
31  }
32
33  void CReduceTransformConnector::computeConnector(unordered_map<int, std::vector<int>>& indexMap)
34  {
35    CArray<size_t,1> dstGlobalIndex ;
36    CArray<size_t,1> srcGlobalIndex ;
37    dstView_->getGlobalIndexView(dstGlobalIndex) ;
38    srcView_->getGlobalIndexView(srcGlobalIndex) ;
39    unordered_map<size_t,int> srcMapIndex ;
40    srcSize_ = srcGlobalIndex.numElements() ;
41    dstSize_ = dstGlobalIndex.numElements() ;
42
43    for(int i=0;i<srcSize_;i++) srcMapIndex[srcGlobalIndex(i)]=i ;
44    for(int i=0; i< dstSize_;i++) 
45    {
46      if (indexMap.count(dstGlobalIndex(i))!=0)
47      {
48        auto& vectIndex  = indexMap[dstGlobalIndex(i)] ;
49        nSrc_.push_back(vectIndex.size()) ;
50        for(int j=0; j<vectIndex.size();j++) connector_.push_back(srcMapIndex[vectIndex[j]]) ;
51      }
52      else nSrc_.push_back(0) ;
53    }
54  }
55
56}
Note: See TracBrowser for help on using the repository browser.