Ignore:
Timestamp:
01/10/18 16:07:16 (4 years ago)
Author:
ymipsl
Message:

Add a method to retrive the local mask of a grid

YM

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/dev/XIOS_DEV_CMIP6/src/node/grid.hpp

    r1390 r1397  
    203203         bool hasTransform(); 
    204204         size_t getGlobalWrittenSize(void) ; 
    205  
     205         void getLocalMask(CArray<bool,1>& localMask) ; 
     206         template<int N> 
     207         void getLocalMask(const CArray<bool,N>& gridMask, CArray<bool,1>& localMask) ; 
    206208      public: 
    207209         CArray<int, 1> storeIndex_client; 
     
    540542   ///-------------------------------------------------------------- 
    541543 
     544 
     545/*! 
     546  A grid can have multiple dimension, so can its mask in the form of multi-dimension array. 
     547It's not a good idea to store all multi-dimension arrays corresponding to each mask. 
     548One of the ways is to convert this array into 1-dimension one and every process is taken place on it. 
     549  \param [in] multi-dimension array grid mask 
     550*/ 
     551template<int N> 
     552void CGrid::getLocalMask(const CArray<bool,N>& gridMask, CArray<bool,1>& localMask) 
     553{ 
     554  int dim = gridMask.dimensions(); 
     555  std::vector<int> dimensionSizes(dim); 
     556  for (int i = 0; i < dim; ++i) dimensionSizes[i] = gridMask.extent(i); 
     557 
     558  std::vector<int> idxLoop(dim,0); 
     559  int ssize = gridMask.numElements(), idx = 0; 
     560  localMask.resize(ssize); 
     561  while (idx < ssize) 
     562  { 
     563    for (int i = 0; i < dim-1; ++i) 
     564    { 
     565      if (idxLoop[i] == dimensionSizes[i]) 
     566      { 
     567        idxLoop[i] = 0; 
     568        ++idxLoop[i+1]; 
     569      } 
     570    } 
     571 
     572    int maskIndex = idxLoop[0]; 
     573    int mulDim = 1; 
     574    for (int k = 1; k < dim; ++k) 
     575    { 
     576      mulDim *= dimensionSizes[k-1]; 
     577      maskIndex += idxLoop[k]*mulDim; 
     578    } 
     579    localMask(maskIndex) = *(gridMask.dataFirst()+maskIndex); 
     580 
     581    ++idxLoop[0]; 
     582    ++idx; 
     583  } 
     584} 
     585 
    542586   // Declare/Define CGridGroup and CGridDefinition 
    543587   DECLARE_GROUP(CGrid); 
Note: See TracChangeset for help on using the changeset viewer.