Ignore:
Timestamp:
07/07/15 10:46:25 (9 years ago)
Author:
mhnguyen
Message:

Implementing interpolation (polynomial) and correct some bugs

+) Implement interpolation (polynomial)
+) Correct some minor bugs relating to memory allocation
+) Clear some redundant codes

Test
+) On Curie
+) test_client and test_complete pass

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/transformation/grid_transformation.cpp

    r624 r630  
    33   \author Ha NGUYEN 
    44   \since 14 May 2015 
    5    \date 18 June 2015 
     5   \date 02 Jul 2015 
    66 
    77   \brief Interface for all transformations. 
     
    1010#include "axis_algorithm_inverse.hpp" 
    1111#include "axis_algorithm_zoom.hpp" 
     12#include "axis_algorithm_interpolate.hpp" 
    1213#include "context.hpp" 
    1314#include "context_client.hpp" 
    1415#include "transformation_mapping.hpp" 
    15  
    1616#include "axis_algorithm_transformation.hpp" 
    1717 
     
    1919CGridTransformation::CGridTransformation(CGrid* destination, CGrid* source) 
    2020: gridSource_(source), gridDestination_(destination), originalGridSource_(source), 
    21   globalIndexOfCurrentGridSource_(0), globalIndexOfOriginalGridSource_(0) 
     21  globalIndexOfCurrentGridSource_(0), globalIndexOfOriginalGridSource_(0), weightOfGlobalIndexOfOriginalGridSource_(0) 
    2222{ 
    2323  //Verify the compatibity between two grids 
     
    7878  globalIndexOfCurrentGridSource_   = new CArray<size_t,1>(globalIndexGridDestSendToServer.numElements()); 
    7979  globalIndexOfOriginalGridSource_  = new CArray<size_t,1>(globalIndexGridDestSendToServer.numElements()); 
     80  weightOfGlobalIndexOfOriginalGridSource_  = new CArray<double,1>(globalIndexGridDestSendToServer.numElements()); 
    8081  *globalIndexOfCurrentGridSource_  = globalIndexGridDestSendToServer; 
    8182  *globalIndexOfOriginalGridSource_ = globalIndexGridDestSendToServer; 
     83  *weightOfGlobalIndexOfOriginalGridSource_ = 1.0; 
    8284} 
    8385 
     
    8789                                                              ite = algoTransformation_.end(); 
    8890  for (it = itb; it != ite; ++it) delete (*it); 
    89  
    90   std::map<int, std::vector<CArray<int,1>* > >::const_iterator itMapRecv, iteMapRecv; 
    91   itMapRecv = localIndexToReceiveOnGridDest_.begin(); 
    92   iteMapRecv = localIndexToReceiveOnGridDest_.end(); 
    93   for (; itMapRecv != iteMapRecv; ++itMapRecv) 
    94   { 
    95     int numVec = (itMapRecv->second).size(); 
    96     for (int idx = 0; idx < numVec; ++idx) delete (itMapRecv->second)[idx]; 
    97   } 
    9891 
    9992  std::map<int, CArray<int,1>* >::const_iterator itMap, iteMap; 
     
    10497  if (0 != globalIndexOfCurrentGridSource_) delete globalIndexOfCurrentGridSource_; 
    10598  if (0 != globalIndexOfOriginalGridSource_) delete globalIndexOfOriginalGridSource_; 
     99  if (0 != weightOfGlobalIndexOfOriginalGridSource_) delete weightOfGlobalIndexOfOriginalGridSource_; 
    106100} 
    107101 
     
    194188 
    195189  CZoomAxis* zoomAxis = 0; 
     190  CInterpolateAxis* interpAxis = 0; 
    196191  CGenericAlgorithmTransformation* algo = 0; 
    197192  switch (transType) 
    198193  { 
     194    case TRANS_INTERPOLATE_AXIS: 
     195      interpAxis = dynamic_cast<CInterpolateAxis*> (it->second); 
     196      algo = new CAxisAlgorithmInterpolate(axisListDestP[axisIndex], axisListSrcP[axisIndex], interpAxis); 
     197      break; 
    199198    case TRANS_ZOOM_AXIS: 
    200199      zoomAxis = dynamic_cast<CZoomAxis*> (it->second); 
     
    237236  switch (transType) 
    238237  { 
     238    case TRANS_INTERPOLATE_AXIS: 
    239239    case TRANS_ZOOM_AXIS: 
    240240    case TRANS_INVERSE_AXIS: 
     
    263263                               ite = listAlgos_.end(), it; 
    264264  CGenericAlgorithmTransformation* algo = 0; 
     265 
    265266  for (it = itb; it != ite; ++it) 
    266267  { 
    267     std::map<size_t, std::set<size_t> > globaIndexMapFromDestToSource; 
    268268    int elementPositionInGrid = it->first; 
    269269    ETranformationType transType = (it->second).first; 
    270270    int transformationOrder = (it->second).second; 
     271    std::map<size_t, std::vector<std::pair<size_t,double> > > globaIndexWeightFromDestToSource; 
    271272 
    272273    // First of all, select an algorithm 
     
    284285                                   gridDestinationDimensionSize, 
    285286                                   globalIndexGridDestSendToServer, 
    286                                    globaIndexMapFromDestToSource); 
     287                                   globaIndexWeightFromDestToSource); 
    287288 
    288289    // Compute transformation of global indexes among grids 
    289     computeTransformationFromOriginalGridSource(globaIndexMapFromDestToSource); 
     290    computeTransformationFromOriginalGridSource(globaIndexWeightFromDestToSource); 
    290291 
    291292    // Now grid destination becomes grid source in a new transformation 
     
    357358the final grid destination 
    358359*/ 
    359 void CGridTransformation::computeTransformationFromOriginalGridSource(const std::map<size_t, std::set<size_t> >& globaIndexMapFromDestToSource) 
     360void CGridTransformation::computeTransformationFromOriginalGridSource(const std::map<size_t, std::vector<std::pair<size_t,double> > >& globaIndexMapFromDestToSource) 
    360361{ 
    361362  CContext* context = CContext::getCurrent(); 
     
    367368  transformationMap.computeTransformationMapping(globaIndexMapFromDestToSource); 
    368369 
    369   const std::map<int,std::vector<std::vector<size_t> > >& globalIndexToReceive = transformationMap.getGlobalIndexReceivedOnGridDestMapping(); 
     370  const std::map<int,std::vector<std::vector<std::pair<size_t,double> > > >& globalIndexToReceive = transformationMap.getGlobalIndexReceivedOnGridDestMapping(); 
    370371  const std::map<int,std::vector<size_t> >& globalIndexToSend = transformationMap.getGlobalIndexSendToGridDestMapping(); 
    371372 
     
    404405 
    405406 // Receiving global index of grid source sending from current grid source 
    406  std::map<int,std::vector<std::vector<size_t> > >::const_iterator itbRecv = globalIndexToReceive.begin(), itRecv, 
    407                                                                   iteRecv = globalIndexToReceive.end(); 
     407 std::map<int,std::vector<std::vector<std::pair<size_t,double> > > >::const_iterator itbRecv = globalIndexToReceive.begin(), itRecv, 
     408                                                                                     iteRecv = globalIndexToReceive.end(); 
    408409 int recvBuffSize = 0; 
    409410 for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv) recvBuffSize += (itRecv->second).size(); 
     
    438439   delete globalIndexOfCurrentGridSource_; 
    439440   globalIndexOfCurrentGridSource_ = new CArray<size_t,1>(nbCurrentGridSource); 
    440  } 
    441  
    442  if (globalIndexOfOriginalGridSource_->numElements() != nbCurrentGridSource) 
    443  { 
    444441   delete globalIndexOfOriginalGridSource_; 
    445442   globalIndexOfOriginalGridSource_ = new CArray<size_t,1>(nbCurrentGridSource); 
     443   delete weightOfGlobalIndexOfOriginalGridSource_; 
     444   weightOfGlobalIndexOfOriginalGridSource_ = new CArray<double,1>(nbCurrentGridSource); 
    446445 } 
    447446 
     
    456455     for (int i = 0; i < ssize; ++i) 
    457456     { 
    458        (*globalIndexOfCurrentGridSource_)(k) = (itRecv->second)[idx][i]; 
     457       (*globalIndexOfCurrentGridSource_)(k) = ((itRecv->second)[idx][i]).first; 
     458       (*weightOfGlobalIndexOfOriginalGridSource_)(k) = ((itRecv->second)[idx][i]).second; 
    459459       (*globalIndexOfOriginalGridSource_)(k) = *currentRecvBuff; 
    460460       ++k; 
     
    479479  CTransformationMapping transformationMap(gridDestination_, originalGridSource_); 
    480480 
    481   std::map<size_t, std::set<size_t> > globaIndexMapFromDestToSource; 
    482  
     481  std::map<size_t, std::vector<std::pair<size_t,double> > > globaIndexWeightFromDestToSource; 
    483482  int nb = globalIndexOfCurrentGridSource_->numElements(); 
    484483  const size_t sfmax = NumTraits<unsigned long>::sfmax(); 
     
    486485  { 
    487486    if (sfmax != (*globalIndexOfOriginalGridSource_)(idx)) 
    488       globaIndexMapFromDestToSource[(*globalIndexOfCurrentGridSource_)(idx)].insert((*globalIndexOfOriginalGridSource_)(idx)); 
     487      globaIndexWeightFromDestToSource[(*globalIndexOfCurrentGridSource_)(idx)].push_back(make_pair((*globalIndexOfOriginalGridSource_)(idx),(*weightOfGlobalIndexOfOriginalGridSource_)(idx))) ; 
    489488  } 
    490489 
    491490  // Then compute transformation mapping among clients 
    492   transformationMap.computeTransformationMapping(globaIndexMapFromDestToSource); 
    493  
    494   const std::map<int,std::vector<std::vector<size_t> > >& globalIndexToReceive = transformationMap.getGlobalIndexReceivedOnGridDestMapping(); 
     491  transformationMap.computeTransformationMapping(globaIndexWeightFromDestToSource); 
     492 
     493  const std::map<int,std::vector<std::vector<std::pair<size_t,double> > > >& globalIndexToReceive = transformationMap.getGlobalIndexReceivedOnGridDestMapping(); 
    495494  const std::map<int,std::vector<size_t> >& globalIndexToSend = transformationMap.getGlobalIndexSendToGridDestMapping(); 
    496495 
     
    498497  CDistributionClient distributionClientSrc(client->clientRank, originalGridSource_); 
    499498 
    500 //  const CArray<int, 1>& localIndexOnClientDest = distributionClientDest.getLocalDataIndexOnClient(); //gridDestination_->getDistributionClient()->getLocalDataIndexOnClient(); 
    501499  const CArray<int, 1>& localIndexOnClientDest = distributionClientDest.getLocalDataIndexSendToServer(); 
    502   const CArray<size_t,1>& globalIndexOnClientDest = distributionClientDest.getGlobalDataIndexSendToServer(); //gridDestination_->getDistributionClient()->getGlobalDataIndexSendToServer(); 
    503  
    504   const CArray<int, 1>& localIndexOnClientSrc = distributionClientSrc.getLocalDataIndexOnClient(); //gridSource_->getDistributionClient()->getLocalDataIndexOnClient(); 
    505   const CArray<size_t,1>& globalIndexOnClientSrc = distributionClientSrc.getGlobalDataIndexSendToServer(); //gridSource_->getDistributionClient()->getGlobalDataIndexSendToServer(); 
     500  const CArray<size_t,1>& globalIndexOnClientDest = distributionClientDest.getGlobalDataIndexSendToServer(); 
     501 
     502  const CArray<int, 1>& localIndexOnClientSrc = distributionClientSrc.getLocalDataIndexOnClient(); 
     503  const CArray<size_t,1>& globalIndexOnClientSrc = distributionClientSrc.getGlobalDataIndexSendToServer(); 
    506504 
    507505  std::vector<size_t>::const_iterator itbVec, itVec, iteVec; 
    508506  CArray<size_t, 1>::const_iterator itbArr, itArr, iteArr; 
    509507 
    510   std::map<int,std::vector<std::vector<size_t> > >::const_iterator itbMapRecv, itMapRecv, iteMapRecv; 
     508  std::map<int,std::vector<std::vector<std::pair<size_t,double> > > >::const_iterator itbMapRecv, itMapRecv, iteMapRecv; 
    511509 
    512510  // Find out local index on grid destination (received) 
     
    522520    { 
    523521      int vecSize = ((itMapRecv->second)[i]).size(); 
    524       CArray<int,1>* ptr = new CArray<int,1>(vecSize); 
    525       localIndexToReceiveOnGridDest_[sourceRank].push_back(ptr); 
     522      std::vector<std::pair<int,double> > tmpVec; 
    526523      for (int idx = 0; idx < vecSize; ++idx) 
    527524      { 
    528         itArr = std::find(itbArr, iteArr, (itMapRecv->second)[i][idx]); 
     525        size_t globalIndex = (itMapRecv->second)[i][idx].first; 
     526        double weight = (itMapRecv->second)[i][idx].second; 
     527        itArr = std::find(itbArr, iteArr, globalIndex); 
    529528        if (iteArr != itArr) 
    530529        { 
    531530          int localIdx = std::distance(itbArr, itArr); 
    532 //          (*localIndexToReceiveOnGridDest_[sourceRank][i])(idx) = localIndexOnClientDest(localIdx); // Local index of un-extracted data (only domain) 
    533           (*localIndexToReceiveOnGridDest_[sourceRank][i])(idx) = (localIdx); // Local index of extracted data 
     531          tmpVec.push_back(make_pair(localIdx, weight)); 
    534532        } 
    535533      } 
     534      localIndexToReceiveOnGridDest_[sourceRank].push_back(tmpVec); 
    536535    } 
    537536  } 
    538537 
     538  // Find out local index on grid source (to send) 
    539539  std::map<int,std::vector<size_t> >::const_iterator itbMap, itMap, iteMap; 
    540   // Find out local index on grid source (to send) 
    541540  itbMap = globalIndexToSend.begin(); 
    542541  iteMap = globalIndexToSend.end(); 
     
    555554      { 
    556555        int localIdx = std::distance(itbArr, itArr); 
    557 //        (*localIndexToSendFromGridSource_[destRank])(idx) = localIndexOnClientSrc(localIdx); 
    558556        (*localIndexToSendFromGridSource_[destRank])(idx) = (localIdx); 
    559557      } 
     
    575573  \return local index of data 
    576574*/ 
    577 const std::map<int, std::vector<CArray<int,1>* > >& CGridTransformation::getLocalIndexToReceiveOnGridDest() const 
     575const std::map<int,std::vector<std::vector<std::pair<int,double> > > >& CGridTransformation::getLocalIndexToReceiveOnGridDest() const 
    578576{ 
    579577  return localIndexToReceiveOnGridDest_; 
Note: See TracChangeset for help on using the changeset viewer.