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

Implementing transformation algorithm: zoom axis (local commit)

+) Implement zoom axis: zoomed points are points not masked
+) Correct some minor bugs

Test
+) Ok with normal cases: zoom in the last of transformation list
+) There is still a bug in case of zoom then inverse

File:
1 edited

Legend:

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

    r622 r623  
     1/*! 
     2   \file grid_transformation.cpp 
     3   \author Ha NGUYEN 
     4   \since 14 May 2015 
     5   \date 09 June 2015 
     6 
     7   \brief Interface for all transformations. 
     8 */ 
    19#include "grid_transformation.hpp" 
    2 #include "axis_inverse.hpp" 
    3 #include "axis_zoom.hpp" 
     10#include "axis_algorithm_inverse.hpp" 
     11#include "axis_algorithm_zoom.hpp" 
    412#include "context.hpp" 
    513#include "context_client.hpp" 
     
    3543  { 
    3644    CAxis* axis = CAxis::createAxis(); 
    37     axisSrcTmp[idx]->duplicateAttributes(axis); 
     45    axis->setAttributes(axisSrcTmp[idx]); 
    3846    axisSrc.push_back(axis); 
    3947  } 
     
    4250  { 
    4351    CDomain* domain = CDomain::createDomain(); 
    44     domainSrcTmp[idx]->duplicateAttributes(domain); 
     52    domain->setAttributes(domainSrcTmp[idx]); 
    4553    domainSrc.push_back(domain); 
    4654  } 
     
    168176    case TRANS_ZOOM_AXIS: 
    169177      zoomAxis = dynamic_cast<CZoomAxis*> (it->second); 
    170       algo = new CAxisZoom(axisListDestP[axisIndex], axisListSrcP[axisIndex], zoomAxis); 
     178      algo = new CAxisAlgorithmZoom(axisListDestP[axisIndex], axisListSrcP[axisIndex], zoomAxis); 
    171179      break; 
    172180    case TRANS_INVERSE_AXIS: 
    173       algo = new CAxisInverse(axisListDestP[axisIndex], axisListSrcP[axisIndex]); 
     181      algo = new CAxisAlgorithmInverse(axisListDestP[axisIndex], axisListSrcP[axisIndex]); 
    174182      break; 
    175183    default: 
     
    196204    case TRANS_INVERSE_AXIS: 
    197205      axisIndex =  elementPosition2AxisPositionInGrid_[elementPositionInGrid]; 
    198       axisListDestP[axisIndex]->duplicateAttributes(axisListSrcP[axisIndex]); 
     206      axisListSrcP[axisIndex]->duplicateAttributes(axisListDestP[axisIndex]); 
    199207      break; 
    200208    default: 
     
    226234    const CArray<size_t,1>& globalIndexGridDestSendToServer = distributionClientDest.getGlobalDataIndexSendToServer(); 
    227235 
     236   std::cout << "global index grid  dest send to server " << globalIndexGridDestSendToServer << std::endl; 
    228237    // ComputeTransformation of global index of each element 
    229238    std::vector<int> gridDestinationDimensionSize = gridDestination_->getGlobalDimension(); 
     
    241250  } 
    242251 
    243  std::cout << "global index destination 0 " << *globalIndexOfCurrentGridSource_ << std::endl; 
    244  std::cout << "global index destination 1 " << *globalIndexOfOriginalGridSource_ << std::endl; 
     252 std::cout << "global index destination 0 final " << *globalIndexOfCurrentGridSource_ << std::endl; 
     253 std::cout << "global index destination 1 final " << *globalIndexOfOriginalGridSource_ << std::endl; 
     254  updateFinalGridDestination(); 
    245255  computeFinalTransformationMapping(); 
    246256} 
     
    248258 
    249259/*! 
    250   Compute index mapping representing transformation between two grids 
    251   Each domain and each axis can contain some information of transformation, these information are then converted into 
    252 form of global index mapping reprensenting transformation between two grids. 
     260  After applying the algorithms, there are some informations on grid destination needing change, for now, there are: 
     261   +) mask 
    253262*/ 
    254 void CGridTransformation::computeTransformation() 
    255 { 
    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 //  } 
     263void CGridTransformation::updateFinalGridDestination() 
     264{ 
     265  CContext* context = CContext::getCurrent(); 
     266  CContextClient* client=context->client; 
     267 
     268  //First of all, retrieve info of local mask of grid destination 
     269  CDistributionClient distributionClientDest(client->clientRank, gridDestination_); 
     270  const CArray<int, 1>& localMaskIndexOnClientDest = distributionClientDest.getLocalMaskIndexOnClient(); 
     271  std::cout << "local mask " << localMaskIndexOnClientDest << std::endl; 
     272 
     273  const CArray<size_t,1>& globalIndexOnClientDest = distributionClientDest.getGlobalDataIndexSendToServer(); 
     274  std::cout << "global index " << globalIndexOnClientDest <<  std::endl; 
     275  CArray<size_t, 1>::const_iterator itbArr, itArr, iteArr; 
     276  itbArr = globalIndexOnClientDest.begin(); 
     277  iteArr = globalIndexOnClientDest.end(); 
     278 
     279  // Then find out which index became invalid (become masked after being applied the algorithms, or demande some masked points from grid source) 
     280  int num = globalIndexOfOriginalGridSource_->numElements(); 
     281  const size_t sfmax = NumTraits<unsigned long>::sfmax(); 
     282  int maskIndexNum = 0; 
     283  for (int idx = 0; idx < num; ++idx) 
     284  { 
     285    if (sfmax == (*globalIndexOfOriginalGridSource_)(idx)) 
     286    { 
     287      size_t maskedGlobalIndex = (*globalIndexOfCurrentGridSource_)(idx); 
     288      itArr = std::find(itbArr, iteArr, maskedGlobalIndex); 
     289      if (iteArr != itArr) ++maskIndexNum; 
     290    } 
     291  } 
     292 
     293  CArray<int,1>* maskIndexToModify = new CArray<int,1>(maskIndexNum); 
     294  maskIndexNum = 0; 
     295  for (int idx = 0; idx < num; ++idx) 
     296  { 
     297    if (sfmax == (*globalIndexOfOriginalGridSource_)(idx)) 
     298    { 
     299      size_t maskedGlobalIndex = (*globalIndexOfCurrentGridSource_)(idx); 
     300      itArr = std::find(itbArr, iteArr, maskedGlobalIndex); 
     301      if (iteArr != itArr) 
     302      { 
     303        int localIdx = std::distance(itbArr, itArr); 
     304        (*maskIndexToModify)(maskIndexNum) = (localMaskIndexOnClientDest)(localIdx); 
     305        ++maskIndexNum; 
     306      } 
     307    } 
     308  } 
     309 
     310  std::cout << "index to modify " << *maskIndexToModify << std::endl; 
     311  gridDestination_->modifyMask(*maskIndexToModify); 
     312 
     313  delete maskIndexToModify; 
    276314} 
    277315 
     
    302340 for (itSend = itbSend; itSend != iteSend; ++itSend) sendBuffSize += (itSend->second).size(); 
    303341 
     342 std::cout << "global index destination 0 before" << *globalIndexOfCurrentGridSource_ << std::endl; 
     343 std::cout << "global index destination 1 before" << *globalIndexOfOriginalGridSource_ << std::endl; 
     344 
     345 typedef unsigned long Scalar; 
    304346 unsigned long* sendBuff, *currentSendBuff; 
    305347 if (0 != sendBuffSize) sendBuff = new unsigned long [sendBuffSize]; 
     348 for (StdSize idx = 0; idx < sendBuffSize; ++idx) sendBuff[idx] = NumTraits<Scalar>::sfmax(); 
     349 
    306350 int currentBuffPosition = 0; 
    307351 for (itSend = itbSend; itSend != iteSend; ++itSend) 
     
    332376 unsigned long* recvBuff, *currentRecvBuff; 
    333377 if (0 != recvBuffSize) recvBuff = new unsigned long [recvBuffSize]; 
     378 for (StdSize idx = 0; idx < recvBuffSize; ++idx) recvBuff[idx] = NumTraits<Scalar>::sfmax(); 
     379 
    334380 int currentRecvBuffPosition = 0; 
    335381 for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv) 
     
    353399 } 
    354400 
    355  globalIndexOfCurrentGridSource_->resize(nbCurrentGridSource); 
    356  globalIndexOfOriginalGridSource_->resize(nbCurrentGridSource); 
     401 if (globalIndexOfCurrentGridSource_->numElements()  != nbCurrentGridSource) 
     402 { 
     403   if ((0 != nbCurrentGridSource) && (0 != globalIndexOfCurrentGridSource_)) 
     404   { 
     405     delete globalIndexOfCurrentGridSource_; 
     406     globalIndexOfCurrentGridSource_ = new CArray<size_t,1>(nbCurrentGridSource); 
     407   } 
     408 } 
     409 
     410 if (globalIndexOfOriginalGridSource_->numElements() != nbCurrentGridSource) 
     411 { 
     412   if ((0 != nbCurrentGridSource) && (0 != globalIndexOfOriginalGridSource_)) 
     413   { 
     414     delete globalIndexOfOriginalGridSource_; 
     415     globalIndexOfOriginalGridSource_ = new CArray<size_t,1>(nbCurrentGridSource); 
     416   } 
     417 } 
     418 
    357419 int k = 0; 
    358420 currentRecvBuff = recvBuff; 
     
    372434 } 
    373435 
     436 std::cout << "global index destination 0 after " << *globalIndexOfCurrentGridSource_ << std::endl; 
     437 std::cout << "global index destination 1 after " << *globalIndexOfOriginalGridSource_ << std::endl; 
    374438 if (0 != sendBuffSize) delete [] sendBuff; 
    375439 if (0 != recvBuffSize) delete [] recvBuff; 
     
    391455 
    392456  int nb = globalIndexOfCurrentGridSource_->numElements(); 
     457  const size_t sfmax = NumTraits<unsigned long>::sfmax(); 
    393458  for (int idx = 0; idx < nb; ++idx) 
    394459  { 
    395     globaIndexMapFromDestToSource[(*globalIndexOfCurrentGridSource_)(idx)].insert((*globalIndexOfOriginalGridSource_)(idx)); 
     460    if (sfmax != (*globalIndexOfOriginalGridSource_)(idx)) 
     461      globaIndexMapFromDestToSource[(*globalIndexOfCurrentGridSource_)(idx)].insert((*globalIndexOfOriginalGridSource_)(idx)); 
    396462  } 
    397463 
     
    403469 
    404470  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(); 
     471  CDistributionClient distributionClientSrc(client->clientRank, originalGridSource_); 
     472 
     473//  const CArray<int, 1>& localIndexOnClientDest = distributionClientDest.getLocalDataIndexOnClient(); //gridDestination_->getDistributionClient()->getLocalDataIndexOnClient(); 
     474  const CArray<int, 1>& localIndexOnClientDest = distributionClientDest.getLocalDataIndexSendToServer(); 
     475  const CArray<size_t,1>& globalIndexOnClientDest = distributionClientDest.getGlobalDataIndexSendToServer(); //gridDestination_->getDistributionClient()->getGlobalDataIndexSendToServer(); 
    409476 
    410477 std::cout << "dest: local index " << localIndexOnClientDest << std::endl; 
    411478 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(); 
     479  const CArray<int, 1>& localIndexOnClientSrc = distributionClientSrc.getLocalDataIndexOnClient(); //gridSource_->getDistributionClient()->getLocalDataIndexOnClient(); 
     480  const CArray<size_t,1>& globalIndexOnClientSrc = distributionClientSrc.getGlobalDataIndexSendToServer(); //gridSource_->getDistributionClient()->getGlobalDataIndexSendToServer(); 
    414481 std::cout << "src: local index " << localIndexOnClientSrc << std::endl; 
    415482 std::cout << "src: global index " << globalIndexOnClientSrc << std::endl; 
    416483  std::vector<size_t>::const_iterator itbVec, itVec, iteVec; 
    417   CArray<size_t, 1>::iterator itbArr, itArr, iteArr; 
     484  CArray<size_t, 1>::const_iterator itbArr, itArr, iteArr; 
    418485 
    419486  std::map<int,std::vector<std::vector<size_t> > >::const_iterator itbMapRecv, itMapRecv, iteMapRecv; 
     
    439506        { 
    440507          int localIdx = std::distance(itbArr, itArr); 
    441 //          (*localIndexToReceiveOnGridDest_[sourceRank][i])(idx) = localIndexOnClientDest(localIdx); // Local index of un-extracted data (only domain) 
    442           (*localIndexToReceiveOnGridDest_[sourceRank][i])(idx) = (localIdx); // Local index of extracted data 
     508          (*localIndexToReceiveOnGridDest_[sourceRank][i])(idx) = localIndexOnClientDest(localIdx); // Local index of un-extracted data (only domain) 
     509//          (*localIndexToReceiveOnGridDest_[sourceRank][i])(idx) = (localIdx); // Local index of extracted data 
    443510        } 
    444511      } 
    445512    } 
     513//    std::cout << "local index to receive from source Rank = " << sourceRank << (*localIndexToReceiveOnGridDest_[sourceRank][i]) << std::endl; 
    446514  } 
    447515 
     
    468536      } 
    469537    } 
     538    std::cout << "local index to send to dest Rank = " << destRank << (*localIndexToSendFromGridSource_[destRank]) << std::endl; 
    470539  } 
    471540} 
Note: See TracChangeset for help on using the changeset viewer.