Ignore:
Timestamp:
02/01/22 15:28:48 (2 years ago)
Author:
ymipsl
Message:

Improve reduction transformation

  • make the difference between reduction over geometry or reduction between process.
  • geometrical reduction :

domain -> axis
axis -> scalar
domain -> scalar

  • reduction across processes for redondant geometrical cell :

axis -> axis
scalar -> scalar

Reduction can be local (only for the geometrical cell owned by current process) or global, using the "local" attribute (bool) over the reduction.

YM

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/dev/dev_ym/XIOS_COUPLING/src/transformation/axis_algorithm/axis_algorithm_reduce_domain.cpp

    r2270 r2291  
    5151TRY 
    5252{ 
    53   algo->checkValid(axisDestination, domainSource); 
    54   axisDestination->checkAttributes() ; 
    5553  switch (algo->operation) 
    5654  { 
     
    7472 
    7573  } 
    76  
     74   
     75  algo->checkValid(axisDestination, domainSource); 
    7776  dir_ = (CReduceDomainToAxis::direction_attr::iDir == algo->direction)  ? iDir : jDir; 
    78   bool local = algo->local ; 
     77 
     78  bool local = false; 
     79  if (!algo->local.isEmpty()) local=algo->local ; 
     80   
     81  size_t nj_glo = domainSource->nj_glo ; 
     82  size_t ni_glo = domainSource->ni_glo ; 
     83 
     84  bool validAxis = axisDestination->checkGeometricAttributes(false) ; 
     85  if (validAxis && !local)  
     86  { 
     87     
     88    axisDestination->checkAttributes() ;  
     89    if (dir_==jDir) 
     90    { 
     91        if (axisDestination->n_glo != domainSource->nj_glo) 
     92          ERROR("CAxisAlgorithmReduceDomain::CAxisAlgorithmReduceDomain(bool isSource, CAxis* axisDestination, CDomain* domainSource, CReduceDomainToAxis* algo)", 
     93            << "Extract domain along j, axis destination should have n_glo equal to nj_glo of domain source" 
     94            << "Domain source " <<domainSource->getId() << " has nj_glo " << domainSource->nj_glo << std::endl 
     95            << "Axis destination " << axisDestination->getId() << " has n_glo " << axisDestination->n_glo) 
     96    } 
     97    else 
     98    { 
     99      if (axisDestination->n_glo != domainSource->ni_glo) 
     100          ERROR("CAxisAlgorithmReduceDomain::CAxisAlgorithmReduceDomain(bool isSource, CAxis* axisDestination, CDomain* domainSource, CReduceDomainToAxis* algo)", 
     101            << "Extract domain along j, axis destination should have n_glo equal to ni_glo of domain source" 
     102            << "Domain source " <<domainSource->getId() << " has ni_glo " << domainSource->ni_glo << std::endl 
     103            << "Axis destination " << axisDestination->getId() << " has n_glo " << axisDestination->n_glo); 
     104    } 
     105  } 
     106  else 
     107  { 
     108    // create axis destination from source domain 
     109 
     110    axisDestination->resetGeometricAttributes(); 
     111    if (dir_== jDir) 
     112    { 
     113      axisDestination->n_glo = domainSource->nj_glo ; 
     114       
     115      CArray<size_t, 1> srcGlobalIndex ; 
     116      set<size_t> indexFullView; 
     117      set<size_t> indexWorkflowView; 
     118      domainSource->getLocalView(CElementView::FULL)->getGlobalIndexView(srcGlobalIndex) ; 
     119      for(int i=0; i<srcGlobalIndex.numElements(); i++) indexFullView.insert(srcGlobalIndex(i)/ni_glo) ; 
     120      domainSource->getLocalView(CElementView::WORKFLOW)->getGlobalIndexView(srcGlobalIndex) ; 
     121      for(int i=0; i<srcGlobalIndex.numElements(); i++) indexWorkflowView.insert(srcGlobalIndex(i)/ni_glo) ; 
     122 
     123      axisDestination-> n = indexFullView.size() ; 
     124      axisDestination-> index.resize(axisDestination-> n) ; 
     125      axisDestination-> mask.resize(axisDestination-> n) ; 
     126       
     127      map<size_t,int> globalToLocalIndex ; 
     128      auto it=indexFullView.begin(); 
     129      for(int i=0; it!=indexFullView.end(); ++i,++it)  
     130      { 
     131        axisDestination->index(i) = *it ; 
     132        if (indexWorkflowView.count(*it)==0) axisDestination->mask(i) = false ; 
     133        else axisDestination->mask(i) = true ; 
     134        globalToLocalIndex[*it] = i ; 
     135      } 
     136      if (domainSource->hasLonLat && domainSource->type == CDomain::type_attr::rectilinear) 
     137      { 
     138        axisDestination->value.resize(axisDestination-> n) ; 
     139        axisDestination->axis_type.setValue(CAxis::axis_type_attr::Y) ; 
     140        if (domainSource->hasBounds) axisDestination-> bounds.resize(axisDestination-> n, 2) ; 
     141 
     142        domainSource->getLocalView(CElementView::FULL)->getGlobalIndexView(srcGlobalIndex) ; 
     143        for(int i=0; i<srcGlobalIndex.numElements(); i++)  
     144        { 
     145          axisDestination->value(globalToLocalIndex[srcGlobalIndex(i)/ni_glo]) = domainSource->latvalue(i) ; 
     146          if (domainSource->hasBounds)  
     147          { 
     148            axisDestination->bounds(globalToLocalIndex[srcGlobalIndex(i)/ni_glo,0]) = domainSource->bounds_latvalue(i,0) ; 
     149            axisDestination->bounds(globalToLocalIndex[srcGlobalIndex(i)/ni_glo,1]) = domainSource->bounds_latvalue(i,1) ; 
     150          } 
     151        }  
     152      } 
     153       
     154    } 
     155    else // dir_== iDir 
     156    { 
     157      axisDestination->n_glo = domainSource->ni_glo ; 
     158       
     159      CArray<size_t, 1> srcGlobalIndex ; 
     160      set<size_t> indexFullView; 
     161      set<size_t> indexWorkflowView; 
     162      domainSource->getLocalView(CElementView::FULL)->getGlobalIndexView(srcGlobalIndex) ; 
     163      for(int i=0; i<srcGlobalIndex.numElements(); i++) indexFullView.insert(srcGlobalIndex(i)%ni_glo) ; 
     164      domainSource->getLocalView(CElementView::WORKFLOW)->getGlobalIndexView(srcGlobalIndex) ; 
     165      for(int i=0; i<srcGlobalIndex.numElements(); i++) indexWorkflowView.insert(srcGlobalIndex(i)%ni_glo) ; 
     166 
     167      axisDestination-> n = indexFullView.size() ; 
     168      axisDestination-> index.resize(axisDestination-> n) ; 
     169      axisDestination-> mask.resize(axisDestination-> n) ; 
     170      map<size_t,int> globalToLocalIndex ; 
     171      auto it=indexFullView.begin(); 
     172      for(int i=0; it!=indexFullView.end(); ++i,++it)  
     173      { 
     174        axisDestination->index(i) = *it ; 
     175        if (indexWorkflowView.count(*it)==0) axisDestination->mask(i) = false ; 
     176        else axisDestination->mask(i) = true ; 
     177        globalToLocalIndex[*it] = i ; 
     178      } 
     179     
     180      if (domainSource->hasLonLat && domainSource->type == CDomain::type_attr::rectilinear) 
     181      { 
     182        axisDestination-> value.resize(axisDestination-> n) ; 
     183        axisDestination-> axis_type.setValue(CAxis::axis_type_attr::X) ; 
     184        if (domainSource->hasBounds) axisDestination->bounds.resize(axisDestination-> n, 2) ; 
     185 
     186        domainSource->getLocalView(CElementView::FULL)->getGlobalIndexView(srcGlobalIndex) ; 
     187        for(int i=0; i<srcGlobalIndex.numElements(); i++)  
     188        { 
     189          axisDestination->value(globalToLocalIndex[srcGlobalIndex(i)%ni_glo]) = domainSource->lonvalue(i) ; 
     190          if (domainSource->hasBounds)  
     191          { 
     192            axisDestination->bounds(globalToLocalIndex[srcGlobalIndex(i)%ni_glo,0]) = domainSource->bounds_lonvalue(i,0) ; 
     193            axisDestination->bounds(globalToLocalIndex[srcGlobalIndex(i)%ni_glo,1]) = domainSource->bounds_lonvalue(i,1) ; 
     194          } 
     195        }  
     196      } 
     197     
     198    } 
     199    
     200    axisDestination->checkAttributes() ;    
     201  } 
     202   
     203  // compute needed index for tranformation 
     204 
     205  TransformationIndexMap& transMap = transformationMapping_; 
     206 
     207  CArray<size_t, 1> srcGlobalIndex ; 
     208  domainSource->getLocalView(CElementView::WORKFLOW)->getGlobalIndexView(srcGlobalIndex) ; 
     209  CArray<size_t, 1> dstGlobalIndex ; 
     210  axisDestination->getLocalView(CElementView::WORKFLOW)->getGlobalIndexView(dstGlobalIndex) ; 
     211   
     212  if (local) 
     213  { 
     214     
     215    set<size_t> dstGlobalIndexSet ; 
     216    for(int i=0; i<dstGlobalIndex.numElements() ; i++) dstGlobalIndexSet.insert(dstGlobalIndex(i)) ; // for mask 
     217 
     218    size_t dstInd ;  
     219    for(int i=0; i<srcGlobalIndex.numElements(); i++)  
     220    { 
     221      if (dir_== jDir) dstInd=srcGlobalIndex(i)/ni_glo ; 
     222      else dstInd=srcGlobalIndex(i)%ni_glo ; 
     223      if (dstGlobalIndexSet.count(dstInd)!=0) transMap[dstInd].push_back(srcGlobalIndex(i)) ;  
     224    } 
     225  } 
     226  else 
     227  { 
     228    for(int i=0; i<dstGlobalIndex.numElements() ;i++) 
     229    { 
     230      if (dir_== jDir)  
     231        for(size_t j=0; j<ni_glo;j++) transMap[dstGlobalIndex(i)].push_back(dstGlobalIndex(i)*ni_glo+j) ; 
     232      else 
     233        for(size_t j=0; j<nj_glo;j++) transMap[dstGlobalIndex(i)].push_back(ni_glo*j+dstGlobalIndex(i)) ; 
     234    } 
     235  } 
     236 
     237/* 
     238 
    79239 
    80240  TransformationIndexMap& transMap = transformationMapping_; 
     
    148308 
    149309  axisDestination->checkAttributes() ; 
     310*/ 
    150311  this->computeAlgorithm(domainSource->getLocalView(CElementView::WORKFLOW), axisDestination->getLocalView(CElementView::WORKFLOW)) ; 
    151312 
Note: See TracChangeset for help on using the changeset viewer.