source: XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/weight_transform_connector.cpp @ 2313

Last change on this file since 2313 was 2313, checked in by ymipsl, 2 years ago

Take into account detect_missing_value and renormalize attribute for interpolate class transformation.

YM

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 1.7 KB
Line 
1#include "weight_transform_connector.hpp"
2
3namespace xios
4{
5
6  CWeightTransformConnector::CWeightTransformConnector(shared_ptr<CLocalView> srcView, shared_ptr<CLocalView> dstView, unordered_map<int, std::vector<int>>& indexMap, 
7                                                       unordered_map<int, std::vector<double>>& weightMap,  bool detectMissingValue, bool renormalize) : 
8                                                       srcView_(srcView), dstView_(dstView), detectMissingValue_(detectMissingValue), renormalize_(renormalize)
9  {
10    computeConnector(indexMap, weightMap) ;
11  }
12
13  void CWeightTransformConnector::computeConnector(unordered_map<int, std::vector<int>>& indexMap, 
14                                                   unordered_map<int, std::vector<double>>& weightMap)
15  {
16    CArray<size_t,1> dstGlobalIndex ;
17    CArray<size_t,1> srcGlobalIndex ;
18    dstView_->getGlobalIndexView(dstGlobalIndex) ;
19    srcView_->getGlobalIndexView(srcGlobalIndex) ;
20    unordered_map<size_t,int> srcMapIndex ;
21    srcSize_ = srcGlobalIndex.numElements() ;
22    dstSize_ = dstGlobalIndex.numElements() ;
23
24    for(int i=0;i<srcSize_;i++) srcMapIndex[srcGlobalIndex(i)]=i ;
25    for(int i=0; i< dstSize_;i++) 
26    {
27      if (indexMap.count(dstGlobalIndex(i))!=0 && weightMap.count(dstGlobalIndex(i))!=0)
28      {
29        auto& vectIndex  = indexMap[dstGlobalIndex(i)] ;
30        auto& vectWeight = weightMap[dstGlobalIndex(i)] ;
31        nWeights_.push_back(vectIndex.size()) ;
32        for(int j=0; j<vectIndex.size();j++)
33        {
34          connector_.push_back(srcMapIndex[vectIndex[j]]) ;
35          weights_.push_back(vectWeight[j]) ;
36        }
37      }
38      else nWeights_.push_back(0) ;
39    }
40  }
41
42}
Note: See TracBrowser for help on using the repository browser.