Changeset 622


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

Final testing transfomation algorithm: inverse axis (local commit)

+) Make some minor change to make sure one element (axis or domain) be able to have several similar transformation

Test
+) On Curie
+) test_new_feature: test passed with correct data written

Location:
XIOS/trunk
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/inputs/Version2/iodef.xml

    r621 r622  
    1111     <field id="field_Axis"  operation="average" freq_op="3600s" grid_ref="grid_Axis" /> 
    1212     <field id="field_Two_Axis"  operation="average" freq_op="3600s" grid_ref="grid_Two_Axis" /> 
    13      <field id="field_Axis_transformed"  operation="average" freq_op="3600s" field_ref="field_A" grid_ref="grid_Axis_tranformed" /> 
     13     <field id="field_Axis_transformed"  operation="average" freq_op="3600s" field_ref="field_Two_Axis" grid_ref="grid_Axis_tranformed" /> 
    1414     <field id="field_All_Axis" operation="average" freq_op="3600s" grid_ref="grid_All_Axis" /> 
    1515     <field id="field_Scalar" operation="average" freq_op="3600s" grid_ref="ScalarGrid" /> 
     
    4141     <axis id="axis_C" /> 
    4242     <axis id="axis_D" /> 
    43      <axis id="axis_E" axis_ref="axis_C"> 
    44 <!--        <transformation type="zoom" />--> 
     43     <axis id="axis_E" axis_ref="axis_B"> 
    4544        <inverse_axis /> 
    46 <!--        <zoom_axis zoom_begin=1 zoom_size=1 />--> 
     45        <inverse_axis /> 
     46<!--        <zoom_axis zoom_begin="1" zoom_size="3" />--> 
     47     </axis> 
     48     <axis id="axis_F" axis_ref="axis_A"> 
     49       <inverse_axis /> 
    4750     </axis> 
    4851   </axis_definition> 
     
    6669       </grid> 
    6770       <grid id="grid_Axis_tranformed"> 
    68          <domain domain_ref="domain_A" /> 
    69 <!--         <axis axis_ref="axis_A" />--> 
    70 <!--         <axis axis_ref="axis_B" />--> 
     71<!--         <domain domain_ref="domain_A" />--> 
     72<!--         <axis axis_ref="axis_E" />--> 
     73         <axis axis_ref="axis_F" /> 
    7174         <axis axis_ref="axis_E" /> 
     75 
    7276       </grid> 
    7377       <grid id="grid_All_Axis"> 
  • XIOS/trunk/src/filter/axis_algorithm_transformation.cpp

    r621 r622  
    55namespace xios { 
    66 
    7 CAxisAlgorithmTransformation::CAxisAlgorithmTransformation(CAxis* axisDestination, CAxis* axisSource, std::vector<ETranformationType>& algos) 
     7CAxisAlgorithmTransformation::CAxisAlgorithmTransformation(CAxis* axisDestination, CAxis* axisSource) 
    88 : CGenericAlgorithmTransformation() 
    99{ 
    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(); 
     10//  if (axisDestination->size.getValue() != axisSource->size.getValue()) 
     11//  { 
     12//    ERROR("CAxisZoom::CAxisZoom(CAxis* axisDestination, CAxis* axisSource)", 
     13//           << "Two axis have different size" 
     14//           << "Size of axis source " <<axisSource->getId() << " is " << axisSource->size.getValue()  << std::endl 
     15//           << "Size of axis destionation " <<axisDestination->getId() << " is " << axisDestination->size.getValue()); 
     16//  } 
     17// 
     18// 
     19//  axisDestGlobalSize_ = axisDestination->size.getValue(); 
     20//  int niDest = axisDestination->ni.getValue(); 
     21//  int ibeginDest = axisDestination->ibegin.getValue(); 
     22// 
     23//  for (int idx = 0; idx < niDest; ++idx) axisDestGlobalIndex_.push_back(ibeginDest+idx); 
    2524} 
    2625 
    2726CAxisAlgorithmTransformation::~CAxisAlgorithmTransformation() 
    2827{ 
    29   for (int idx = 0; idx < algosOfAnAxis_.size(); ++idx) delete algosOfAnAxis_[idx]; 
     28//  for (int idx = 0; idx < algosOfAnAxis_.size(); ++idx) delete algosOfAnAxis_[idx]; 
    3029} 
    3130 
    3231void CAxisAlgorithmTransformation::computeIndexSourceMapping() 
    3332{ 
    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   } 
     33//  if (!algosOfAnAxis_.empty()) 
     34//  { 
     35//    algosOfAnAxis_[0]->computeIndexSourceMapping(this->transformationMapping_); 
     36//    for (int idx = 1; idx < algosOfAnAxis_.size(); ++idx) 
     37//    { 
     38//      algosOfAnAxis_[idx]->computeIndexSourceMapping(algosOfAnAxis_[idx-1]->getTransformationMapping()); 
     39//    } 
     40//    this->transformationMapping_ = algosOfAnAxis_[algosOfAnAxis_.size()-1]->getTransformationMapping(); 
     41//  } 
    4342} 
    4443 
  • XIOS/trunk/src/filter/axis_algorithm_transformation.hpp

    r621 r622  
    1111{ 
    1212public: 
    13   CAxisAlgorithmTransformation(CAxis* axisDestination, CAxis* axisSource, std::vector<ETranformationType>&); 
     13  CAxisAlgorithmTransformation(CAxis* axisDestination, CAxis* axisSource); 
    1414 
    1515  virtual ~CAxisAlgorithmTransformation(); 
     
    2525  void computeIndexSourceMapping(); 
    2626protected: 
    27   std::vector<CConcreteAlgo*> algosOfAnAxis_; 
     27  std::vector<int> axisDestGlobalIndex_; 
     28  int axisDestGlobalSize_; 
    2829 
    2930}; 
  • XIOS/trunk/src/filter/axis_inverse.cpp

    r621 r622  
    44 
    55CAxisInverse::CAxisInverse(CAxis* axisDestination, CAxis* axisSource) 
    6  : CConcreteAlgo() 
     6 : CAxisAlgorithmTransformation(axisDestination, axisSource) 
    77{ 
    88  if (axisDestination->size.getValue() != axisSource->size.getValue()) 
     
    2020 
    2121  for (int idx = 0; idx < niDest; ++idx) axisDestGlobalIndex_.push_back(ibeginDest+idx); 
     22  this->computeIndexSourceMapping(); 
    2223} 
    2324 
    24 void CAxisInverse::computeIndexSourceMapping(const std::map<int, std::vector<int> >& transformationMappingOfPreviousAlgo) 
     25void CAxisInverse::computeIndexSourceMapping() 
    2526{ 
    2627  std::map<int, std::vector<int> >& transMap = this->transformationMapping_; 
    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   } 
     28 
     29  int globalIndexSize = axisDestGlobalIndex_.size(); 
     30  for (int idx = 0; idx < globalIndexSize; ++idx) 
     31    transMap[axisDestGlobalIndex_[idx]].push_back(axisDestGlobalSize_-axisDestGlobalIndex_[idx]-1); 
    4232} 
    4333 
  • XIOS/trunk/src/filter/axis_inverse.hpp

    r621 r622  
    22#define __XIOS_AXIS_ALGORITHM_INVERSE_HPP__ 
    33 
    4 #include "concrete_algo.hpp" 
     4#include "axis_algorithm_transformation.hpp" 
    55#include "axis.hpp" 
    66 
    77namespace xios { 
    88 
    9 class CAxisInverse : public CConcreteAlgo 
     9class CAxisInverse : public CAxisAlgorithmTransformation //public CConcreteAlgo 
    1010{ 
    1111public: 
     
    1414  virtual ~CAxisInverse() {} 
    1515 
    16   virtual void computeIndexSourceMapping(const std::map<int, std::vector<int> >& transformationMappingOfPreviousAlgo); 
    17  
    18 protected: 
    19   std::vector<int> axisDestGlobalIndex_; 
    20  
    21 private: 
    22   int axisDestGlobalSize_; 
     16  virtual void computeIndexSourceMapping(); 
    2317}; 
    2418 
  • XIOS/trunk/src/filter/axis_zoom.cpp

    r621 r622  
    33namespace xios { 
    44 
    5 CAxisZoom::CAxisZoom(CAxis* axisDestination, CAxis* axisSource) 
    6  : CConcreteAlgo() 
     5CAxisZoom::CAxisZoom(CAxis* axisDestination, CAxis* axisSource, CZoomAxis* zoomAxis) 
     6: CAxisAlgorithmTransformation(axisDestination, axisSource), axisDest_(axisDestination), axisSrc_(axisSource) 
    77{ 
    8   if (axisDestination->size.getValue() != axisSource->size.getValue()) 
     8  zoomAxis->checkValid(axisSource); 
     9  zoomBegin_ = zoomAxis->zoom_begin.getValue(); 
     10  zoomEnd_   = zoomAxis->zoom_end.getValue(); 
     11  zoomSize_  = zoomAxis->zoom_size.getValue(); 
     12 
     13  if (zoomSize_ > axisSource->size.getValue()) 
    914  { 
    10     ERROR("CAxisZoom::CAxisZoom(CAxis* axisDestination, CAxis* axisSource)", 
    11            << "Two axis have different size" 
     15    ERROR("CAxisZoom::CAxisZoom(CAxis* axisDestination, CAxis* axisSource, CZoomAxis* zoomAxis)", 
     16           << "Zoom size is greater than size of axis source" 
    1217           << "Size of axis source " <<axisSource->getId() << " is " << axisSource->size.getValue()  << std::endl 
    13            << "Size of axis destionation " <<axisDestination->getId() << " is " << axisDestination->size.getValue()); 
     18           << "Zoom size is " << zoomSize_ ); 
    1419  } 
    1520 
    16  
    17   axisDestGlobalSize_ = axisDestination->size.getValue(); 
    18   int niDest = axisDestination->ni.getValue(); 
    19   int ibeginDest = axisDestination->ibegin.getValue(); 
    20  
    21   for (int idx = 0; idx < niDest; ++idx) axisDestGlobalIndex_.push_back(ibeginDest+idx); 
     21  // Axis destination now must have new size equal to zoom size 
     22  axisDestination->size.setValue(zoomSize_); 
     23  computeIndexSourceMapping(); 
    2224} 
    2325 
    24 void CAxisZoom::computeIndexSourceMapping(const std::map<int, std::vector<int> >& transformationMappingOfPreviousAlgo) 
     26void CAxisZoom::computeIndexSourceMapping() 
    2527{ 
    26 //  std::map<int, std::vector<int> >& transMap = this->transformationMapping_; 
    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 //  } 
     28  StdSize niSource = axisSrc_->ni.getValue(); 
     29  StdSize ibeginSource = axisSrc_->ibegin.getValue(); 
     30  StdSize iendSource = ibeginSource + niSource - 1; 
     31 
     32  StdSize ibegin = std::max(ibeginSource, zoomBegin_); 
     33  StdSize iend = std::min(iendSource, zoomEnd_); 
     34  StdSize ni = iend + 1 - ibegin; 
     35  if (ibeginSource > zoomEnd_) 
     36  { 
     37    axisDest_->ibegin.setValue(0); 
     38    axisDest_->ni.setValue(0); 
     39  } 
     40  else 
     41  { 
     42    axisDest_->ibegin.setValue(ibegin - zoomBegin_); 
     43    axisDest_->ni.setValue(ni); 
     44  } 
     45 
     46  std::map<int, std::vector<int> >& transMap = this->transformationMapping_; 
     47  StdSize axisDestIBegin = axisDest_->ibegin.getValue(); 
     48  for (StdSize idx = 0; idx < ni; ++idx) 
     49  { 
     50    transMap[axisDestIBegin+idx].push_back(ibegin+idx); 
     51  } 
    4252} 
    4353 
  • XIOS/trunk/src/filter/axis_zoom.hpp

    r621 r622  
    22#define __XIOS_AXIS_ALGORITHM_ZOOM_HPP__ 
    33 
    4 #include "concrete_algo.hpp" 
     4#include "axis_algorithm_transformation.hpp" 
    55#include "axis.hpp" 
     6#include "zoom_axis.hpp" 
    67 
    78namespace xios { 
    89 
    9 class CAxisZoom : public CConcreteAlgo 
     10class CAxisZoom : public CAxisAlgorithmTransformation 
    1011{ 
    1112public: 
    12   CAxisZoom(CAxis* axisDestination, CAxis* axisSource); 
     13  CAxisZoom(CAxis* axisDestination, CAxis* axisSource, CZoomAxis* zoomAxis); 
    1314 
    1415  virtual ~CAxisZoom() {} 
    1516 
    16   virtual void computeIndexSourceMapping(const std::map<int, std::vector<int> >& transformationMappingOfPreviousAlgo); 
    17  
    18 protected: 
    19   std::vector<int> axisDestGlobalIndex_; 
     17  virtual void computeIndexSourceMapping(); 
    2018 
    2119private: 
    22   int axisDestGlobalSize_; 
     20  StdSize zoomBegin_; 
     21  StdSize zoomEnd_; 
     22  StdSize zoomSize_; 
     23 
     24private: 
     25  CAxis* axisDest_; 
     26  CAxis* axisSrc_; 
    2327}; 
    2428 
  • XIOS/trunk/src/filter/generic_algorithm_transformation.hpp

    r620 r622  
    1919                                const CArray<size_t,1>& globalIndexGridDestSendToServer, 
    2020                                std::map<size_t, std::set<size_t> >& globaIndexMapFromDestToSource); 
     21 
     22                                  /*! 
     23  Compute global index mapping from one element of destination grid to the corresponding element of source grid 
     24  */ 
     25  virtual void computeIndexSourceMapping() = 0; 
     26 
    2127protected: 
    2228  /*! 
     
    3844                                                        std::vector<CArray<size_t,1> >& globalIndexSrcGrid) = 0; 
    3945 
    40   /*! 
    41   Compute global index mapping from one element of destination grid to the corresponding element of source grid 
    42   */ 
    43   virtual void computeIndexSourceMapping() = 0; 
     46 
    4447 
    4548protected: 
  • XIOS/trunk/src/filter/grid_transformation.cpp

    r621 r622  
    11#include "grid_transformation.hpp" 
    22#include "axis_inverse.hpp" 
     3#include "axis_zoom.hpp" 
     4#include "context.hpp" 
     5#include "context_client.hpp" 
    36#include "transformation_mapping.hpp" 
    4 #include "transformation_enum.hpp" 
     7 
    58#include "axis_algorithm_transformation.hpp" 
    69 
    710namespace xios { 
    811CGridTransformation::CGridTransformation(CGrid* destination, CGrid* source) 
    9 : gridSource_(source), gridDestination_(destination) 
     12: gridSource_(source), gridDestination_(destination), originalGridSource_(source), 
     13  globalIndexOfCurrentGridSource_(0), globalIndexOfOriginalGridSource_(0) 
    1014{ 
    1115  //Verify the compatibity between two grids 
     
    2630  } 
    2731 
     32  std::vector<CAxis*> axisSrcTmp = gridSource_->getAxis(), axisSrc; 
     33  std::vector<CDomain*> domainSrcTmp = gridSource_->getDomains(), domainSrc; 
     34  for (int idx = 0; idx < axisSrcTmp.size(); ++idx) 
     35  { 
     36    CAxis* axis = CAxis::createAxis(); 
     37    axisSrcTmp[idx]->duplicateAttributes(axis); 
     38    axisSrc.push_back(axis); 
     39  } 
     40 
     41  for (int idx = 0; idx < domainSrcTmp.size(); ++idx) 
     42  { 
     43    CDomain* domain = CDomain::createDomain(); 
     44    domainSrcTmp[idx]->duplicateAttributes(domain); 
     45    domainSrc.push_back(domain); 
     46  } 
     47 
     48  gridSource_ = CGrid::createGrid(domainSrc, axisSrc, gridDestination_->axis_domain_order); 
    2849  gridSourceDimensionSize_ = gridSource_->getGlobalDimension(); 
    2950  gridDestinationDimensionSize_ = gridDestination_->getGlobalDimension(); 
     51 
     52  initializeMappingOfOriginalGridSource(); 
    3053  initializeAlgorithms(); 
    3154} 
    3255 
     56void CGridTransformation::initializeMappingOfOriginalGridSource() 
     57{ 
     58  CContext* context = CContext::getCurrent(); 
     59  CContextClient* client=context->client; 
     60 
     61  CDistributionClient distribution(client->clientRank, originalGridSource_); 
     62  const CArray<size_t,1>& globalIndexGridDestSendToServer = distribution.getGlobalDataIndexSendToServer(); 
     63 
     64  globalIndexOfCurrentGridSource_   = new CArray<size_t,1>(globalIndexGridDestSendToServer.numElements()); 
     65  globalIndexOfOriginalGridSource_  = new CArray<size_t,1>(globalIndexGridDestSendToServer.numElements()); 
     66  *globalIndexOfCurrentGridSource_  = globalIndexGridDestSendToServer; 
     67  *globalIndexOfOriginalGridSource_ = globalIndexGridDestSendToServer; 
     68} 
     69 
    3370CGridTransformation::~CGridTransformation() 
    3471{ 
    35   std::map<int, std::vector<CGenericAlgorithmTransformation*> >::const_iterator itb = algoTransformation_.begin(), it, 
    36                                                                                 ite = algoTransformation_.end(); 
    37   for (it = itb; it != ite; ++it) 
    38     for (int idx = 0; idx < (it->second).size(); ++idx) 
    39       delete (it->second)[idx]; 
     72  std::list<CGenericAlgorithmTransformation*>::const_iterator itb = algoTransformation_.begin(), it, 
     73                                                              ite = algoTransformation_.end(); 
     74  for (it = itb; it != ite; ++it) delete (*it); 
    4075 
    4176  std::map<int, std::vector<CArray<int,1>* > >::const_iterator itMapRecv, iteMapRecv; 
     
    5287  iteMap = localIndexToSendFromGridSource_.end(); 
    5388  for (; itMap != iteMap; ++itMap) delete (itMap->second); 
     89 
     90  if (0 != globalIndexOfCurrentGridSource_) delete globalIndexOfCurrentGridSource_; 
     91  if (0 != globalIndexOfOriginalGridSource_) delete globalIndexOfOriginalGridSource_; 
    5492} 
    5593 
     
    86124    for (int i = 0; i < axisListDestP.size(); ++i) 
    87125    { 
     126      elementPosition2AxisPositionInGrid_[axisPositionInGrid[i]] = i; 
    88127      if (axisListDestP[i]->hasTransformation()) 
    89128      { 
    90         CGenericAlgorithmTransformation* algo = 0; 
    91129        CAxis::TransMapTypes trans = axisListDestP[i]->getAllTransformations(); 
    92130        CAxis::TransMapTypes::const_iterator itb = trans.begin(), it, 
    93131                                             ite = trans.end(); 
    94         std::vector<ETranformationType> algoAxis; 
     132        int transformationOrder = 0; 
    95133        for (it = itb; it != ite; ++it) 
    96134        { 
    97           algoAxis.push_back(it->first); 
     135          listAlgos_.push_back(std::make_pair(axisPositionInGrid[i], std::make_pair(it->first, transformationOrder))); 
     136          ++transformationOrder; 
    98137        } 
    99         algo = new CAxisAlgorithmTransformation(axisListDestP[i], axisListSrcP[i], algoAxis); 
    100         algoTransformation_[axisPositionInGrid[i]].push_back(algo); 
    101138      } 
    102139    } 
     
    108145 
    109146} 
     147 
     148void CGridTransformation::selectAlgo(int elementPositionInGrid, ETranformationType transType, int transformationOrder) 
     149{ 
     150   selectAxisAlgo(elementPositionInGrid, transType, transformationOrder); 
     151} 
     152 
     153void CGridTransformation::selectAxisAlgo(int elementPositionInGrid, ETranformationType transType, int transformationOrder) 
     154{ 
     155  std::vector<CAxis*> axisListDestP = gridDestination_->getAxis(); 
     156  std::vector<CAxis*> axisListSrcP = gridSource_->getAxis(); 
     157 
     158  int axisIndex =  elementPosition2AxisPositionInGrid_[elementPositionInGrid]; 
     159  CAxis::TransMapTypes trans = axisListDestP[axisIndex]->getAllTransformations(); 
     160  CAxis::TransMapTypes::const_iterator it = trans.begin(); 
     161 
     162  for (int i = 0; i < transformationOrder; ++i, ++it) {}  // Find the correct transformation 
     163 
     164  CZoomAxis* zoomAxis = 0; 
     165  CGenericAlgorithmTransformation* algo = 0; 
     166  switch (transType) 
     167  { 
     168    case TRANS_ZOOM_AXIS: 
     169      zoomAxis = dynamic_cast<CZoomAxis*> (it->second); 
     170      algo = new CAxisZoom(axisListDestP[axisIndex], axisListSrcP[axisIndex], zoomAxis); 
     171      break; 
     172    case TRANS_INVERSE_AXIS: 
     173      algo = new CAxisInverse(axisListDestP[axisIndex], axisListSrcP[axisIndex]); 
     174      break; 
     175    default: 
     176      break; 
     177  } 
     178  algoTransformation_.push_back(algo); 
     179 
     180} 
     181 
     182void CGridTransformation::selectDomainAlgo(int elementPositionInGrid, ETranformationType transType, int transformationOrder) 
     183{ 
     184 
     185} 
     186 
     187void CGridTransformation::setUpGrid(int elementPositionInGrid, ETranformationType transType) 
     188{ 
     189  std::vector<CAxis*> axisListDestP = gridDestination_->getAxis(); 
     190  std::vector<CAxis*> axisListSrcP = gridSource_->getAxis(); 
     191 
     192  int axisIndex; 
     193  switch (transType) 
     194  { 
     195    case TRANS_ZOOM_AXIS: 
     196    case TRANS_INVERSE_AXIS: 
     197      axisIndex =  elementPosition2AxisPositionInGrid_[elementPositionInGrid]; 
     198      axisListDestP[axisIndex]->duplicateAttributes(axisListSrcP[axisIndex]); 
     199      break; 
     200    default: 
     201      break; 
     202  } 
     203} 
     204 
     205void CGridTransformation::computeAll() 
     206{ 
     207  CContext* context = CContext::getCurrent(); 
     208  CContextClient* client=context->client; 
     209 
     210  ListAlgoType::const_iterator itb = listAlgos_.begin(), 
     211                               ite = listAlgos_.end(), it; 
     212  CGenericAlgorithmTransformation* algo = 0; 
     213  for (it = itb; it != ite; ++it) 
     214  { 
     215    std::map<size_t, std::set<size_t> > globaIndexMapFromDestToSource; 
     216    int elementPositionInGrid = it->first; 
     217    ETranformationType transType = (it->second).first; 
     218    int transformationOrder = (it->second).second; 
     219 
     220    // First of all, select an algorithm 
     221    selectAlgo(elementPositionInGrid, transType, transformationOrder); 
     222    algo = algoTransformation_.back(); 
     223 
     224    // Recalculate the distribution of grid destination 
     225    CDistributionClient distributionClientDest(client->clientRank, gridDestination_); 
     226    const CArray<size_t,1>& globalIndexGridDestSendToServer = distributionClientDest.getGlobalDataIndexSendToServer(); 
     227 
     228    // ComputeTransformation of global index of each element 
     229    std::vector<int> gridDestinationDimensionSize = gridDestination_->getGlobalDimension(); 
     230    int elementPosition = it->first; 
     231    algo->computeGlobalSourceIndex(elementPosition, 
     232                                   gridDestinationDimensionSize, 
     233                                   globalIndexGridDestSendToServer, 
     234                                   globaIndexMapFromDestToSource); 
     235 
     236    // Compute transformation of global indexes among grids 
     237    computeTransformationFromOriginalGridSource(globaIndexMapFromDestToSource); 
     238 
     239    // Now grid destination becomes grid source in a new transformation 
     240    setUpGrid(elementPositionInGrid, transType); 
     241  } 
     242 
     243 std::cout << "global index destination 0 " << *globalIndexOfCurrentGridSource_ << std::endl; 
     244 std::cout << "global index destination 1 " << *globalIndexOfOriginalGridSource_ << std::endl; 
     245  computeFinalTransformationMapping(); 
     246} 
     247 
    110248 
    111249/*! 
     
    116254void CGridTransformation::computeTransformation() 
    117255{ 
    118   const CArray<size_t,1>& globalIndexGridDestSendToServer = gridDestination_->getDistributionClient()->getGlobalDataIndexSendToServer(); 
    119   std::map<int, std::vector<CGenericAlgorithmTransformation*> >::const_iterator itbMap, itMap, iteMap; 
    120   itbMap = algoTransformation_.begin(); 
    121   iteMap = algoTransformation_.end(); 
    122  
    123   std::vector<CGenericAlgorithmTransformation*>::const_iterator itbVec, itVec, iteVec; 
    124  
    125   for (itMap = itbMap; itMap != iteMap; ++itMap) 
    126   { 
    127     int elementPosition = itMap->first; 
    128     itbVec = (itMap->second).begin(); 
    129     iteVec = (itMap->second).end(); 
    130     for (itVec = itbVec; itVec != iteVec; ++itVec) 
    131     { 
    132       (*itVec)->computeGlobalSourceIndex(elementPosition, 
    133                                          gridDestinationDimensionSize_, 
    134                                          globalIndexGridDestSendToServer, 
    135                                          globaIndexMapFromDestToSource_); 
    136     } 
    137   } 
     256//  const CArray<size_t,1>& globalIndexGridDestSendToServer = gridDestination_->getDistributionClient()->getGlobalDataIndexSendToServer(); 
     257//  std::list<std::pair<int,CGenericAlgorithmTransformation*> >::const_iterator itbMap, itMap, iteMap; 
     258//  itbMap = algoTransformation_.begin(); 
     259//  iteMap = algoTransformation_.end(); 
     260// 
     261//  std::vector<CGenericAlgorithmTransformation*>::const_iterator itbVec, itVec, iteVec; 
     262// 
     263//  for (itMap = itbMap; itMap != iteMap; ++itMap) 
     264//  { 
     265//    int elementPosition = itMap->first; 
     266//    itbVec = (itMap->second).begin(); 
     267//    iteVec = (itMap->second).end(); 
     268//    for (itVec = itbVec; itVec != iteVec; ++itVec) 
     269//    { 
     270//      (*itVec)->computeGlobalSourceIndex(elementPosition, 
     271//                                         gridDestinationDimensionSize_, 
     272//                                         globalIndexGridDestSendToServer, 
     273//                                         globaIndexMapFromDestToSource_); 
     274//    } 
     275//  } 
     276} 
     277 
     278/*! 
     279  A transformation from a grid source to grid destination often passes several intermediate grids, which play a role of 
     280temporary grid source and/or grid destination. This function makes sure that global index of original grid source are mapped correctly to 
     281the final grid destination 
     282*/ 
     283void CGridTransformation::computeTransformationFromOriginalGridSource(const std::map<size_t, std::set<size_t> >& globaIndexMapFromDestToSource) 
     284{ 
     285  CContext* context = CContext::getCurrent(); 
     286  CContextClient* client=context->client; 
     287 
     288  CTransformationMapping transformationMap(gridDestination_, gridSource_); 
     289 
     290    // Then compute transformation mapping among clients 
     291  transformationMap.computeTransformationMapping(globaIndexMapFromDestToSource); 
     292 
     293  const std::map<int,std::vector<std::vector<size_t> > >& globalIndexToReceive = transformationMap.getGlobalIndexReceivedOnGridDestMapping(); 
     294  const std::map<int,std::vector<size_t> >& globalIndexToSend = transformationMap.getGlobalIndexSendToGridDestMapping(); 
     295 
     296 // Sending global index of original grid source 
     297  std::map<int,std::vector<size_t> >::const_iterator itbSend = globalIndexToSend.begin(), itSend, 
     298                                                     iteSend = globalIndexToSend.end(); 
     299  CArray<size_t,1>::const_iterator itbArr = globalIndexOfCurrentGridSource_->begin(), itArr, 
     300                                   iteArr = globalIndexOfCurrentGridSource_->end(); 
     301 int sendBuffSize = 0; 
     302 for (itSend = itbSend; itSend != iteSend; ++itSend) sendBuffSize += (itSend->second).size(); 
     303 
     304 unsigned long* sendBuff, *currentSendBuff; 
     305 if (0 != sendBuffSize) sendBuff = new unsigned long [sendBuffSize]; 
     306 int currentBuffPosition = 0; 
     307 for (itSend = itbSend; itSend != iteSend; ++itSend) 
     308 { 
     309   int destRank = itSend->first; 
     310   const std::vector<size_t>& globalIndexOfCurrentGridSourceToSend = itSend->second; 
     311   int countSize = globalIndexOfCurrentGridSourceToSend.size(); 
     312   for (int idx = 0; idx < (countSize); ++idx) 
     313   { 
     314     itArr = std::find(itbArr, iteArr, globalIndexOfCurrentGridSourceToSend[idx]); 
     315     if (iteArr != itArr) 
     316     { 
     317       int index = std::distance(itbArr, itArr); 
     318       sendBuff[idx+currentBuffPosition] = (*globalIndexOfOriginalGridSource_)(index); 
     319     } 
     320   } 
     321   currentSendBuff = sendBuff + currentBuffPosition; 
     322   MPI_Send(currentSendBuff, countSize, MPI_UNSIGNED_LONG, destRank, 14, client->intraComm); 
     323   currentBuffPosition += countSize; 
     324 } 
     325 
     326 // Receiving global index of grid source sending from current grid source 
     327 std::map<int,std::vector<std::vector<size_t> > >::const_iterator itbRecv = globalIndexToReceive.begin(), itRecv, 
     328                                                                  iteRecv = globalIndexToReceive.end(); 
     329 int recvBuffSize = 0; 
     330 for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv) recvBuffSize += (itRecv->second).size(); 
     331 
     332 unsigned long* recvBuff, *currentRecvBuff; 
     333 if (0 != recvBuffSize) recvBuff = new unsigned long [recvBuffSize]; 
     334 int currentRecvBuffPosition = 0; 
     335 for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv) 
     336 { 
     337   MPI_Status status; 
     338   int srcRank = itRecv->first; 
     339   int countSize = (itRecv->second).size(); 
     340   currentRecvBuff = recvBuff + currentRecvBuffPosition; 
     341   MPI_Recv(currentRecvBuff, countSize, MPI_UNSIGNED_LONG, srcRank, 14, client->intraComm, &status); 
     342   currentRecvBuffPosition += countSize; 
     343 } 
     344 
     345 int nbCurrentGridSource = 0; 
     346 for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv) 
     347 { 
     348   int ssize = (itRecv->second).size(); 
     349   for (int idx = 0; idx < ssize; ++idx) 
     350   { 
     351     nbCurrentGridSource += (itRecv->second)[idx].size(); 
     352   } 
     353 } 
     354 
     355 globalIndexOfCurrentGridSource_->resize(nbCurrentGridSource); 
     356 globalIndexOfOriginalGridSource_->resize(nbCurrentGridSource); 
     357 int k = 0; 
     358 currentRecvBuff = recvBuff; 
     359 for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv) 
     360 { 
     361   int countSize = (itRecv->second).size(); 
     362   for (int idx = 0; idx < countSize; ++idx, ++currentRecvBuff) 
     363   { 
     364     int ssize = (itRecv->second)[idx].size(); 
     365     for (int i = 0; i < ssize; ++i) 
     366     { 
     367       (*globalIndexOfCurrentGridSource_)(k) = (itRecv->second)[idx][i]; 
     368       (*globalIndexOfOriginalGridSource_)(k) = *currentRecvBuff; 
     369       ++k; 
     370     } 
     371   } 
     372 } 
     373 
     374 if (0 != sendBuffSize) delete [] sendBuff; 
     375 if (0 != recvBuffSize) delete [] recvBuff; 
    138376} 
    139377 
     
    143381of two grids. Then local index mapping between data on each grid will be found out thanks to these global indexes 
    144382*/ 
    145 void CGridTransformation::computeTransformationMapping() 
    146 { 
    147   CTransformationMapping transformationMap(gridDestination_, gridSource_); 
    148  
    149   // First of all, need to compute global index mapping representing transformation algorithms 
    150   computeTransformation(); 
     383void CGridTransformation::computeFinalTransformationMapping() 
     384{ 
     385  CContext* context = CContext::getCurrent(); 
     386  CContextClient* client=context->client; 
     387 
     388  CTransformationMapping transformationMap(gridDestination_, originalGridSource_); 
     389 
     390  std::map<size_t, std::set<size_t> > globaIndexMapFromDestToSource; 
     391 
     392  int nb = globalIndexOfCurrentGridSource_->numElements(); 
     393  for (int idx = 0; idx < nb; ++idx) 
     394  { 
     395    globaIndexMapFromDestToSource[(*globalIndexOfCurrentGridSource_)(idx)].insert((*globalIndexOfOriginalGridSource_)(idx)); 
     396  } 
    151397 
    152398  // Then compute transformation mapping among clients 
    153   transformationMap.computeTransformationMapping(globaIndexMapFromDestToSource_); 
     399  transformationMap.computeTransformationMapping(globaIndexMapFromDestToSource); 
    154400 
    155401  const std::map<int,std::vector<std::vector<size_t> > >& globalIndexToReceive = transformationMap.getGlobalIndexReceivedOnGridDestMapping(); 
    156402  const std::map<int,std::vector<size_t> >& globalIndexToSend = transformationMap.getGlobalIndexSendToGridDestMapping(); 
    157403 
    158   CArray<int, 1> localIndexOnClientDest = gridDestination_->getDistributionClient()->getLocalDataIndexOnClient(); 
    159   CArray<size_t,1> globalIndexOnClientDest = gridDestination_->getDistributionClient()->getGlobalDataIndexSendToServer(); 
    160  
    161   CArray<int, 1> localIndexOnClientSrc = gridSource_->getDistributionClient()->getLocalDataIndexOnClient(); 
    162   CArray<size_t,1> globalIndexOnClientSrc = gridSource_->getDistributionClient()->getGlobalDataIndexSendToServer(); 
    163  
     404  CDistributionClient distributionClientDest(client->clientRank, gridDestination_); 
     405  CDistributionClient distributionClientSrc(client->clientRank, gridSource_); 
     406 
     407  CArray<int, 1> localIndexOnClientDest = distributionClientDest.getLocalDataIndexOnClient(); //gridDestination_->getDistributionClient()->getLocalDataIndexOnClient(); 
     408  CArray<size_t,1> globalIndexOnClientDest = distributionClientDest.getGlobalDataIndexSendToServer(); //gridDestination_->getDistributionClient()->getGlobalDataIndexSendToServer(); 
     409 
     410 std::cout << "dest: local index " << localIndexOnClientDest << std::endl; 
     411 std::cout << "dest: global index " << globalIndexOnClientDest << std::endl; 
     412  CArray<int, 1> localIndexOnClientSrc = distributionClientSrc.getLocalDataIndexOnClient(); //gridSource_->getDistributionClient()->getLocalDataIndexOnClient(); 
     413  CArray<size_t,1> globalIndexOnClientSrc = distributionClientSrc.getGlobalDataIndexSendToServer(); //gridSource_->getDistributionClient()->getGlobalDataIndexSendToServer(); 
     414 std::cout << "src: local index " << localIndexOnClientSrc << std::endl; 
     415 std::cout << "src: global index " << globalIndexOnClientSrc << std::endl; 
    164416  std::vector<size_t>::const_iterator itbVec, itVec, iteVec; 
    165417  CArray<size_t, 1>::iterator itbArr, itArr, iteArr; 
  • XIOS/trunk/src/filter/grid_transformation.hpp

    r620 r622  
    66#include "grid.hpp" 
    77#include "generic_algorithm_transformation.hpp" 
     8#include "transformation_enum.hpp" 
    89 
    910namespace xios { 
     
    1819  ~CGridTransformation(); 
    1920 
    20   void computeTransformationMapping(); 
     21  void computeAll(); 
     22 
     23 
    2124  std::map<int, CArray<int,1>* > getLocalIndexToSendFromGridSource(); 
    2225  std::map<int, std::vector<CArray<int,1>* > > getLocalIndexToReceiveOnGridDest(); 
     
    2730  void initializeAxisAlgorithms(); 
    2831  void initializeDomainAlgorithms(); 
     32  void initializeMappingOfOriginalGridSource(); 
     33 
     34  void selectAxisAlgo(int elementPositionInGrid, ETranformationType transType, int transformationOrder); 
     35  void selectDomainAlgo(int elementPositionInGrid, ETranformationType transType, int transformationOrder); 
     36  void selectAlgo(int elementPositionInGrid, ETranformationType transType, int transformationOrder); 
     37  void setUpGrid(int elementPositionInGrid, ETranformationType transType); 
     38  void computeFinalTransformationMapping(); 
     39  void computeTransformationFromOriginalGridSource(const std::map<size_t, std::set<size_t> >& globaIndexMapFromDestToSource); 
    2940 
    3041private: 
    3142  CGrid* gridSource_; 
    3243  CGrid* gridDestination_; 
     44  CGrid* originalGridSource_; 
    3345 
    3446  std::vector<int> gridSourceDimensionSize_; 
    3547  std::vector<int> gridDestinationDimensionSize_; 
    3648 
     49private: 
     50  typedef std::list<std::pair<int,std::pair<ETranformationType,int> > > ListAlgoType; 
     51 
    3752  // Mapping between position of an element in grid and its transformation (if any) 
    38   std::map<int, std::vector<CGenericAlgorithmTransformation*> > algoTransformation_; 
     53  std::list<CGenericAlgorithmTransformation*> algoTransformation_; 
     54  ListAlgoType listAlgos_; 
    3955  std::map<size_t, std::set<size_t> > globaIndexMapFromDestToSource_; 
    4056 
    4157  std::map<int, CArray<int,1>* > localIndexToSendFromGridSource_; 
    4258  std::map<int, std::vector<CArray<int,1>* > > localIndexToReceiveOnGridDest_; 
     59 
     60  std::map<int, int> elementPosition2AxisPositionInGrid_, elementPosition2DomainPositionInGrid_; 
     61 
     62  CArray<size_t,1>* globalIndexOfCurrentGridSource_; 
     63  CArray<size_t,1>* globalIndexOfOriginalGridSource_; 
    4364}; 
    4465 
  • XIOS/trunk/src/filter/transformation_mapping.cpp

    r621 r622  
    33#include "context.hpp" 
    44#include "context_client.hpp" 
     5#include "distribution_client.hpp" 
    56 
    67namespace xios { 
     
    1314  int clientRank = client->clientRank; 
    1415 
    15   const CArray<size_t,1>& globalIndexGridSrc = gridSource_->getDistributionClient()->getGlobalDataIndexSendToServer(); 
     16  CDistributionClient distributionClientDest(client->clientRank, gridSource_); 
     17 
     18  const CArray<size_t,1>& globalIndexGridSrc = distributionClientDest.getGlobalDataIndexSendToServer(); //gridSource_->getDistributionClient()->getGlobalDataIndexSendToServer(); 
    1619  boost::unordered_map<size_t,int> globalIndexOfServer; 
    1720  int globalIndexSize = globalIndexGridSrc.numElements(); 
     
    3538this function tries to find out which clients a client needs to send and receive these global indexes to accomplish the transformations. 
    3639  The grid destination is the grid whose global indexes demande global indexes from the grid source 
    37   Grid destination and grid source are also distributed among clients but in a different manner. 
     40  Grid destination and grid source are also distributed among clients but in different manners. 
    3841  \param [in] globaIndexMapFromDestToSource mapping representing the transformations 
    3942*/ 
  • XIOS/trunk/src/node/axis.cpp

    r621 r622  
    6262 
    6363   //---------------------------------------------------------------- 
     64 
     65   CAxis* CAxis::createAxis() 
     66   { 
     67     CAxis* axis = CAxisGroup::get("axis_definition")->createChild(); 
     68     return axis; 
     69   } 
     70 
     71   void CAxis::duplicateAttributes(CAxis* axis) 
     72   { 
     73     axis->setAttributes(this); 
     74   } 
    6475 
    6576   void CAxis::checkAttributes(void) 
     
    374385          CInverseAxis* tmp = (CInverseAxisGroup::get(inverseAxisDefRoot))->createChild(); 
    375386          tmp->parse(node); 
    376           transformationMap_[TRANS_INVERSE_AXIS] = tmp; 
     387          transformationMap_.push_back(std::make_pair(TRANS_INVERSE_AXIS,tmp)); 
    377388        } else if (node.getElementName() == zoom) { 
    378389          CZoomAxis* tmp = (CZoomAxisGroup::get(zoomAxisDefRoot))->createChild(); 
    379390          tmp->parse(node); 
    380           transformationMap_[TRANS_ZOOM_AXIS] = tmp; 
     391          transformationMap_.push_back(std::make_pair(TRANS_ZOOM_AXIS,tmp)); 
    381392        } 
    382393      } while (node.goToNextElement()) ; 
  • XIOS/trunk/src/node/axis.hpp

    r621 r622  
    6161         CAxis(const CAxis * const axis); // Not implemented yet. 
    6262 
     63         static CAxis* createAxis(); 
     64 
    6365         /// Accesseurs /// 
    6466         const std::set<StdString> & getRelFiles(void) const; 
     67         void duplicateAttributes(CAxis* axis); 
    6568 
    6669         /// Test /// 
  • XIOS/trunk/src/node/domain.cpp

    r611 r622  
    3838 
    3939   ///--------------------------------------------------------------- 
     40 
     41   CDomain* CDomain::createDomain() 
     42   { 
     43     CDomain* domain = CDomainGroup::get("domain_definition")->createChild(); 
     44     return domain; 
     45   } 
     46 
     47   void CDomain::duplicateAttributes(CDomain* domain) 
     48   { 
     49     domain->setAttributes(this); 
     50   } 
    4051 
    4152   const std::set<StdString> & CDomain::getRelFiles(void) const 
  • XIOS/trunk/src/node/domain.hpp

    r611 r622  
    5555         CDomain(const CDomain & domain);       // Not implemented yet. 
    5656         CDomain(const CDomain * const domain); // Not implemented yet. 
     57 
     58         static CDomain* createDomain(); 
     59         void duplicateAttributes(CDomain* domain); 
    5760 
    5861         /// Vérifications /// 
  • XIOS/trunk/src/node/grid.cpp

    r621 r622  
    450450      std::vector<CDomain*> vecDom(1,domain); 
    451451      std::vector<CAxis*> vecAxis; 
    452  
    453       CGrid* grid = createGrid(vecDom, vecAxis); 
     452      CArray<bool,1> axisDomainOrder; 
     453      CGrid* grid = createGrid(vecDom, vecAxis, axisDomainOrder); 
    454454 
    455455      return (grid); 
     
    460460      std::vector<CDomain*> vecDom(1,domain); 
    461461      std::vector<CAxis*> vecAxis(1,axis); 
    462       CGrid* grid = createGrid(vecDom, vecAxis); 
     462      CArray<bool,1> axisDomainOrder; 
     463      CGrid* grid = createGrid(vecDom, vecAxis, axisDomainOrder); 
    463464 
    464465      return (grid); 
    465466   } 
    466467 
    467    CGrid* CGrid::createGrid(std::vector<CDomain*> domains, std::vector<CAxis*> axis) 
     468   CGrid* CGrid::createGrid(std::vector<CDomain*> domains, std::vector<CAxis*> axis, CArray<bool,1> axisDomainOrder) 
    468469   { 
    469470      StdString new_id = StdString("__"); 
     
    478479 
    479480      //By default, domains are always the first ones of a grid 
    480       if (grid->axis_domain_order.isEmpty()) 
     481      if (0 == axisDomainOrder.numElements()) 
    481482      { 
    482483        int size = domains.size()+axis.size(); 
     
    487488          else grid->axis_domain_order(i) = false; 
    488489        } 
     490      } 
     491      else 
     492      { 
     493        grid->axis_domain_order.resize(axisDomainOrder.numElements()); 
     494        grid->axis_domain_order = axisDomainOrder; 
    489495      } 
    490496 
     
    11511157 
    11521158    transformations_ = new CGridTransformation(transformedGrid, this); 
    1153     transformations_->computeTransformationMapping(); 
     1159    transformations_->computeAll(); 
    11541160  } 
    11551161 
  • XIOS/trunk/src/node/grid.hpp

    r620 r622  
    132132         static CGrid* createGrid(CDomain* domain); 
    133133         static CGrid* createGrid(CDomain* domain, CAxis* axis); 
    134          static CGrid* createGrid(std::vector<CDomain*> domains, std::vector<CAxis*> axis); 
     134         static CGrid* createGrid(std::vector<CDomain*> domains, std::vector<CAxis*> axis, CArray<bool,1> axisDomainOrder = CArray<bool,1>()); 
    135135 
    136136      public : 
  • XIOS/trunk/src/node/transformation.hpp

    r621 r622  
    1616  { 
    1717  public: 
    18     typedef typename boost::unordered_map<ETranformationType, CTransformation<T>*, boost::hash<int> > TransformationMapTypes; 
     18    typedef typename std::list<std::pair<ETranformationType, CTransformation<T>* > > TransformationMapTypes; 
    1919    typedef TransformationMapTypes TransMapTypes; 
    2020 
  • XIOS/trunk/src/node/zoom_axis.cpp

    r621 r622  
    2626  { 
    2727    StdSize axisIBegin, axisNi, axisSize; 
    28     StdSize zoom_begin,zoom_end, zoom_size; 
     28    StdSize zoom_begin, zoom_end, zoom_size; 
    2929 
    3030    axisIBegin = axisDest->ibegin.getValue(); 
Note: See TracChangeset for help on using the changeset viewer.