Changeset 1397


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

Add a method to retrive the local mask of a grid

YM

Location:
XIOS/dev/XIOS_DEV_CMIP6/src/node
Files:
2 edited

Legend:

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

    r1371 r1397  
    424424   } 
    425425 
     426 
     427/*! 
     428  A grid can have multiple dimension, so can its mask in the form of multi-dimension array. 
     429It's not a good idea to store all multi-dimension arrays corresponding to each mask. 
     430One of the ways is to convert this array into 1-dimension one and every process is taken place on it. 
     431  \param [in] multi-dimension array grid mask 
     432*/ 
     433 
     434  void CGrid::getLocalMask(CArray<bool,1>& localMask) 
     435  { 
     436      std::vector<CDomain*> domainP = this->getDomains(); 
     437      std::vector<CAxis*> axisP = this->getAxis(); 
     438      int dim = domainP.size() * 2 + axisP.size(); 
     439 
     440      switch (dim) 
     441      { 
     442        case 0: 
     443          getLocalMask(mask_0d, localMask); 
     444          break; 
     445        case 1: 
     446          getLocalMask(mask_1d, localMask); 
     447          break; 
     448        case 2: 
     449          getLocalMask(mask_2d, localMask); 
     450          break; 
     451        case 3: 
     452          getLocalMask(mask_3d, localMask); 
     453          break; 
     454        case 4: 
     455          getLocalMask(mask_4d, localMask); 
     456          break; 
     457        case 5: 
     458          getLocalMask(mask_5d, localMask); 
     459          break; 
     460        case 6: 
     461          getLocalMask(mask_6d, localMask); 
     462          break; 
     463        case 7: 
     464          getLocalMask(mask_7d, localMask); 
     465          break; 
     466        default: 
     467          break; 
     468      } 
     469  } 
     470       
    426471   /* 
    427472     Modify value of mask in a certain index 
  • 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.