Changeset 621 for XIOS/trunk/src/filter


Ignore:
Timestamp:
06/22/15 13:36:21 (9 years ago)
Author:
mhnguyen
Message:

Implementing generic transformation algorithm (local commit)

+) Change a little bit to make sure everything work in order

Test
+) test_new_features passe with inverse

Location:
XIOS/trunk/src/filter
Files:
3 added
6 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/filter/axis_algorithm_transformation.cpp

    r620 r621  
    11#include "axis_algorithm_transformation.hpp" 
     2#include "axis_inverse.hpp" 
     3#include "axis_zoom.hpp" 
    24 
    35namespace xios { 
    46 
    5 CAxisAlgorithmTransformation::CAxisAlgorithmTransformation(CAxis* axisDestination) 
     7CAxisAlgorithmTransformation::CAxisAlgorithmTransformation(CAxis* axisDestination, CAxis* axisSource, std::vector<ETranformationType>& algos) 
    68 : CGenericAlgorithmTransformation() 
    79{ 
    8   int niDest = axisDestination->ni.getValue(); 
    9   int ibeginDest = axisDestination->ibegin.getValue(); 
     10  for (int idx = 0; idx < algos.size(); ++idx) 
     11  { 
     12    switch (algos[idx]) 
     13    { 
     14      case TRANS_ZOOM_AXIS: 
     15        algosOfAnAxis_.push_back(new CAxisZoom(axisDestination, axisSource)); 
     16        break; 
     17      case TRANS_INVERSE_AXIS: 
     18        algosOfAnAxis_.push_back(new CAxisInverse(axisDestination, axisSource)); 
     19        break; 
     20      default: 
     21        break; 
     22    } 
     23  } 
     24  computeIndexSourceMapping(); 
     25} 
    1026 
    11   for (int idx = 0; idx < niDest; ++idx) axisDestGlobalIndex_.push_back(ibeginDest+idx); 
     27CAxisAlgorithmTransformation::~CAxisAlgorithmTransformation() 
     28{ 
     29  for (int idx = 0; idx < algosOfAnAxis_.size(); ++idx) delete algosOfAnAxis_[idx]; 
     30} 
     31 
     32void CAxisAlgorithmTransformation::computeIndexSourceMapping() 
     33{ 
     34  if (!algosOfAnAxis_.empty()) 
     35  { 
     36    algosOfAnAxis_[0]->computeIndexSourceMapping(this->transformationMapping_); 
     37    for (int idx = 1; idx < algosOfAnAxis_.size(); ++idx) 
     38    { 
     39      algosOfAnAxis_[idx]->computeIndexSourceMapping(algosOfAnAxis_[idx-1]->getTransformationMapping()); 
     40    } 
     41    this->transformationMapping_ = algosOfAnAxis_[algosOfAnAxis_.size()-1]->getTransformationMapping(); 
     42  } 
    1243} 
    1344 
  • XIOS/trunk/src/filter/axis_algorithm_transformation.hpp

    r620 r621  
    44#include "generic_algorithm_transformation.hpp" 
    55#include "axis.hpp" 
     6#include "concrete_algo.hpp" 
    67 
    78namespace xios { 
     
    1011{ 
    1112public: 
    12   CAxisAlgorithmTransformation(CAxis* axisDestination); 
    13   virtual ~CAxisAlgorithmTransformation() {} 
     13  CAxisAlgorithmTransformation(CAxis* axisDestination, CAxis* axisSource, std::vector<ETranformationType>&); 
     14 
     15  virtual ~CAxisAlgorithmTransformation(); 
    1416 
    1517protected: 
     
    2123                                                        CArray<size_t,1>& globalIndexDestGrid, 
    2224                                                        std::vector<CArray<size_t,1> >& globalIndexSrcGrid); 
    23   virtual void computeIndexSourceMapping() = 0; 
    24  
     25  void computeIndexSourceMapping(); 
    2526protected: 
    26   std::vector<int> axisDestGlobalIndex_; 
     27  std::vector<CConcreteAlgo*> algosOfAnAxis_; 
    2728 
    2829}; 
  • XIOS/trunk/src/filter/axis_inverse.cpp

    r620 r621  
    44 
    55CAxisInverse::CAxisInverse(CAxis* axisDestination, CAxis* axisSource) 
    6  : CAxisAlgorithmTransformation(axisDestination) 
     6 : CConcreteAlgo() 
    77{ 
    88  if (axisDestination->size.getValue() != axisSource->size.getValue()) 
     
    1414  } 
    1515 
     16 
    1617  axisDestGlobalSize_ = axisDestination->size.getValue(); 
     18  int niDest = axisDestination->ni.getValue(); 
     19  int ibeginDest = axisDestination->ibegin.getValue(); 
    1720 
    18   this->computeIndexSourceMapping(); 
     21  for (int idx = 0; idx < niDest; ++idx) axisDestGlobalIndex_.push_back(ibeginDest+idx); 
    1922} 
    2023 
    21 void CAxisInverse::computeIndexSourceMapping() 
     24void CAxisInverse::computeIndexSourceMapping(const std::map<int, std::vector<int> >& transformationMappingOfPreviousAlgo) 
    2225{ 
    2326  std::map<int, std::vector<int> >& transMap = this->transformationMapping_; 
    24   if (!transMap.empty()) transMap.clear(); 
    25  
    26   int globalIndexSize = axisDestGlobalIndex_.size(); 
    27   for (int idx = 0; idx < globalIndexSize; ++idx) 
    28     transMap[axisDestGlobalIndex_[idx]].push_back(axisDestGlobalSize_-axisDestGlobalIndex_[idx]-1); 
     27  if (transformationMappingOfPreviousAlgo.empty()) 
     28  { 
     29    int globalIndexSize = axisDestGlobalIndex_.size(); 
     30    for (int idx = 0; idx < globalIndexSize; ++idx) 
     31      transMap[axisDestGlobalIndex_[idx]].push_back(axisDestGlobalSize_-axisDestGlobalIndex_[idx]-1); 
     32  } 
     33  else 
     34  { 
     35    std::map<int, std::vector<int> >::const_iterator itb = transformationMappingOfPreviousAlgo.begin(), it, 
     36                                                     ite = transformationMappingOfPreviousAlgo.end(); 
     37    for (it = itb; it != ite; ++it) 
     38    { 
     39      transMap[it->first].push_back(axisDestGlobalSize_-it->first-1); 
     40    } 
     41  } 
    2942} 
    3043 
    31  
    3244} 
  • XIOS/trunk/src/filter/axis_inverse.hpp

    r620 r621  
    22#define __XIOS_AXIS_ALGORITHM_INVERSE_HPP__ 
    33 
    4 #include "axis_algorithm_transformation.hpp" 
     4#include "concrete_algo.hpp" 
    55#include "axis.hpp" 
    66 
    77namespace xios { 
    88 
    9 class CAxisInverse : public CAxisAlgorithmTransformation 
     9class CAxisInverse : public CConcreteAlgo 
    1010{ 
    1111public: 
     
    1313 
    1414  virtual ~CAxisInverse() {} 
     15 
     16  virtual void computeIndexSourceMapping(const std::map<int, std::vector<int> >& transformationMappingOfPreviousAlgo); 
     17 
    1518protected: 
    16   virtual void computeIndexSourceMapping(); 
     19  std::vector<int> axisDestGlobalIndex_; 
    1720 
    1821private: 
  • XIOS/trunk/src/filter/grid_transformation.cpp

    r620 r621  
    22#include "axis_inverse.hpp" 
    33#include "transformation_mapping.hpp" 
     4#include "transformation_enum.hpp" 
     5#include "axis_algorithm_transformation.hpp" 
    46 
    57namespace xios { 
     
    8688      if (axisListDestP[i]->hasTransformation()) 
    8789      { 
    88         CGenericAlgorithmTransformation* algo = new CAxisInverse(axisListDestP[i], axisListSrcP[i]); 
     90        CGenericAlgorithmTransformation* algo = 0; 
     91        CAxis::TransMapTypes trans = axisListDestP[i]->getAllTransformations(); 
     92        CAxis::TransMapTypes::const_iterator itb = trans.begin(), it, 
     93                                             ite = trans.end(); 
     94        std::vector<ETranformationType> algoAxis; 
     95        for (it = itb; it != ite; ++it) 
     96        { 
     97          algoAxis.push_back(it->first); 
     98        } 
     99        algo = new CAxisAlgorithmTransformation(axisListDestP[i], axisListSrcP[i], algoAxis); 
    89100        algoTransformation_[axisPositionInGrid[i]].push_back(algo); 
    90101      } 
     
    98109} 
    99110 
     111/*! 
     112  Compute index mapping representing transformation between two grids 
     113  Each domain and each axis can contain some information of transformation, these information are then converted into 
     114form of global index mapping reprensenting transformation between two grids. 
     115*/ 
    100116void CGridTransformation::computeTransformation() 
    101117{ 
     
    122138} 
    123139 
     140/*! 
     141  Compute transformation mapping between grid source and grid destination 
     142  The transformation between grid source and grid destination is represented in form of mapping between global index 
     143of two grids. Then local index mapping between data on each grid will be found out thanks to these global indexes 
     144*/ 
    124145void CGridTransformation::computeTransformationMapping() 
    125146{ 
     
    141162  CArray<size_t,1> globalIndexOnClientSrc = gridSource_->getDistributionClient()->getGlobalDataIndexSendToServer(); 
    142163 
    143  
    144164  std::vector<size_t>::const_iterator itbVec, itVec, iteVec; 
    145165  CArray<size_t, 1>::iterator itbArr, itArr, iteArr; 
    146166 
    147167  std::map<int,std::vector<std::vector<size_t> > >::const_iterator itbMapRecv, itMapRecv, iteMapRecv; 
     168 
    148169  // Find out local index on grid destination (received) 
    149170  itbMapRecv = globalIndexToReceive.begin(); 
     
    166187        { 
    167188          int localIdx = std::distance(itbArr, itArr); 
    168           (*localIndexToReceiveOnGridDest_[sourceRank][i])(idx) = localIndexOnClientDest(localIdx); 
     189//          (*localIndexToReceiveOnGridDest_[sourceRank][i])(idx) = localIndexOnClientDest(localIdx); // Local index of un-extracted data (only domain) 
     190          (*localIndexToReceiveOnGridDest_[sourceRank][i])(idx) = (localIdx); // Local index of extracted data 
    169191        } 
    170192      } 
    171193    } 
    172  
    173194  } 
    174195 
     
    183204    CArray<int,1>* ptr = new CArray<int,1>((itMap->second).size()); 
    184205    localIndexToSendFromGridSource_[itMap->first] = ptr; 
     206    int destRank = itMap->first; 
    185207    int vecSize = (itMap->second).size(); 
    186208    for (int idx = 0; idx < vecSize; ++idx) 
     
    190212      { 
    191213        int localIdx = std::distance(itbArr, itArr); 
    192         (*localIndexToSendFromGridSource_[itMap->first])(idx) = localIndexOnClientSrc(localIdx); 
    193       } 
    194     } 
    195   } 
    196 } 
    197  
     214//        (*localIndexToSendFromGridSource_[destRank])(idx) = localIndexOnClientSrc(localIdx); 
     215        (*localIndexToSendFromGridSource_[destRank])(idx) = (localIdx); 
     216      } 
     217    } 
     218  } 
     219} 
     220 
     221/*! 
     222  Local index of data which need sending from the grid source 
     223  \return local index of data 
     224*/ 
    198225std::map<int, CArray<int,1>* > CGridTransformation::getLocalIndexToSendFromGridSource() 
    199226{ 
     
    201228} 
    202229 
     230/*! 
     231  Local index of data which will be received on the grid destination 
     232  \return local index of data 
     233*/ 
    203234std::map<int, std::vector<CArray<int,1>* > > CGridTransformation::getLocalIndexToReceiveOnGridDest() 
    204235{ 
  • XIOS/trunk/src/filter/transformation_mapping.cpp

    r620 r621  
    3333/*! 
    3434  Suppose that we have transformations between two grids, which are represented in form of mapping between global indexes of these two grids, 
    35 this function tries to find out which clients a client need to send and receive these global indexes to accomplish the transformations. 
     35this function tries to find out which clients a client needs to send and receive these global indexes to accomplish the transformations. 
    3636  The grid destination is the grid whose global indexes demande global indexes from the grid source 
    3737  Grid destination and grid source are also distributed among clients but in a different manner. 
Note: See TracChangeset for help on using the changeset viewer.