Changeset 630 for XIOS/trunk/src/transformation/grid_transformation.cpp
- Timestamp:
- 07/07/15 10:46:25 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/trunk/src/transformation/grid_transformation.cpp
r624 r630 3 3 \author Ha NGUYEN 4 4 \since 14 May 2015 5 \date 18 June20155 \date 02 Jul 2015 6 6 7 7 \brief Interface for all transformations. … … 10 10 #include "axis_algorithm_inverse.hpp" 11 11 #include "axis_algorithm_zoom.hpp" 12 #include "axis_algorithm_interpolate.hpp" 12 13 #include "context.hpp" 13 14 #include "context_client.hpp" 14 15 #include "transformation_mapping.hpp" 15 16 16 #include "axis_algorithm_transformation.hpp" 17 17 … … 19 19 CGridTransformation::CGridTransformation(CGrid* destination, CGrid* source) 20 20 : gridSource_(source), gridDestination_(destination), originalGridSource_(source), 21 globalIndexOfCurrentGridSource_(0), globalIndexOfOriginalGridSource_(0) 21 globalIndexOfCurrentGridSource_(0), globalIndexOfOriginalGridSource_(0), weightOfGlobalIndexOfOriginalGridSource_(0) 22 22 { 23 23 //Verify the compatibity between two grids … … 78 78 globalIndexOfCurrentGridSource_ = new CArray<size_t,1>(globalIndexGridDestSendToServer.numElements()); 79 79 globalIndexOfOriginalGridSource_ = new CArray<size_t,1>(globalIndexGridDestSendToServer.numElements()); 80 weightOfGlobalIndexOfOriginalGridSource_ = new CArray<double,1>(globalIndexGridDestSendToServer.numElements()); 80 81 *globalIndexOfCurrentGridSource_ = globalIndexGridDestSendToServer; 81 82 *globalIndexOfOriginalGridSource_ = globalIndexGridDestSendToServer; 83 *weightOfGlobalIndexOfOriginalGridSource_ = 1.0; 82 84 } 83 85 … … 87 89 ite = algoTransformation_.end(); 88 90 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 }98 91 99 92 std::map<int, CArray<int,1>* >::const_iterator itMap, iteMap; … … 104 97 if (0 != globalIndexOfCurrentGridSource_) delete globalIndexOfCurrentGridSource_; 105 98 if (0 != globalIndexOfOriginalGridSource_) delete globalIndexOfOriginalGridSource_; 99 if (0 != weightOfGlobalIndexOfOriginalGridSource_) delete weightOfGlobalIndexOfOriginalGridSource_; 106 100 } 107 101 … … 194 188 195 189 CZoomAxis* zoomAxis = 0; 190 CInterpolateAxis* interpAxis = 0; 196 191 CGenericAlgorithmTransformation* algo = 0; 197 192 switch (transType) 198 193 { 194 case TRANS_INTERPOLATE_AXIS: 195 interpAxis = dynamic_cast<CInterpolateAxis*> (it->second); 196 algo = new CAxisAlgorithmInterpolate(axisListDestP[axisIndex], axisListSrcP[axisIndex], interpAxis); 197 break; 199 198 case TRANS_ZOOM_AXIS: 200 199 zoomAxis = dynamic_cast<CZoomAxis*> (it->second); … … 237 236 switch (transType) 238 237 { 238 case TRANS_INTERPOLATE_AXIS: 239 239 case TRANS_ZOOM_AXIS: 240 240 case TRANS_INVERSE_AXIS: … … 263 263 ite = listAlgos_.end(), it; 264 264 CGenericAlgorithmTransformation* algo = 0; 265 265 266 for (it = itb; it != ite; ++it) 266 267 { 267 std::map<size_t, std::set<size_t> > globaIndexMapFromDestToSource;268 268 int elementPositionInGrid = it->first; 269 269 ETranformationType transType = (it->second).first; 270 270 int transformationOrder = (it->second).second; 271 std::map<size_t, std::vector<std::pair<size_t,double> > > globaIndexWeightFromDestToSource; 271 272 272 273 // First of all, select an algorithm … … 284 285 gridDestinationDimensionSize, 285 286 globalIndexGridDestSendToServer, 286 globaIndex MapFromDestToSource);287 globaIndexWeightFromDestToSource); 287 288 288 289 // Compute transformation of global indexes among grids 289 computeTransformationFromOriginalGridSource(globaIndex MapFromDestToSource);290 computeTransformationFromOriginalGridSource(globaIndexWeightFromDestToSource); 290 291 291 292 // Now grid destination becomes grid source in a new transformation … … 357 358 the final grid destination 358 359 */ 359 void CGridTransformation::computeTransformationFromOriginalGridSource(const std::map<size_t, std:: set<size_t> >& globaIndexMapFromDestToSource)360 void CGridTransformation::computeTransformationFromOriginalGridSource(const std::map<size_t, std::vector<std::pair<size_t,double> > >& globaIndexMapFromDestToSource) 360 361 { 361 362 CContext* context = CContext::getCurrent(); … … 367 368 transformationMap.computeTransformationMapping(globaIndexMapFromDestToSource); 368 369 369 const std::map<int,std::vector<std::vector<s ize_t> > >& globalIndexToReceive = transformationMap.getGlobalIndexReceivedOnGridDestMapping();370 const std::map<int,std::vector<std::vector<std::pair<size_t,double> > > >& globalIndexToReceive = transformationMap.getGlobalIndexReceivedOnGridDestMapping(); 370 371 const std::map<int,std::vector<size_t> >& globalIndexToSend = transformationMap.getGlobalIndexSendToGridDestMapping(); 371 372 … … 404 405 405 406 // Receiving global index of grid source sending from current grid source 406 std::map<int,std::vector<std::vector<s ize_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(); 408 409 int recvBuffSize = 0; 409 410 for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv) recvBuffSize += (itRecv->second).size(); … … 438 439 delete globalIndexOfCurrentGridSource_; 439 440 globalIndexOfCurrentGridSource_ = new CArray<size_t,1>(nbCurrentGridSource); 440 }441 442 if (globalIndexOfOriginalGridSource_->numElements() != nbCurrentGridSource)443 {444 441 delete globalIndexOfOriginalGridSource_; 445 442 globalIndexOfOriginalGridSource_ = new CArray<size_t,1>(nbCurrentGridSource); 443 delete weightOfGlobalIndexOfOriginalGridSource_; 444 weightOfGlobalIndexOfOriginalGridSource_ = new CArray<double,1>(nbCurrentGridSource); 446 445 } 447 446 … … 456 455 for (int i = 0; i < ssize; ++i) 457 456 { 458 (*globalIndexOfCurrentGridSource_)(k) = (itRecv->second)[idx][i]; 457 (*globalIndexOfCurrentGridSource_)(k) = ((itRecv->second)[idx][i]).first; 458 (*weightOfGlobalIndexOfOriginalGridSource_)(k) = ((itRecv->second)[idx][i]).second; 459 459 (*globalIndexOfOriginalGridSource_)(k) = *currentRecvBuff; 460 460 ++k; … … 479 479 CTransformationMapping transformationMap(gridDestination_, originalGridSource_); 480 480 481 std::map<size_t, std::set<size_t> > globaIndexMapFromDestToSource; 482 481 std::map<size_t, std::vector<std::pair<size_t,double> > > globaIndexWeightFromDestToSource; 483 482 int nb = globalIndexOfCurrentGridSource_->numElements(); 484 483 const size_t sfmax = NumTraits<unsigned long>::sfmax(); … … 486 485 { 487 486 if (sfmax != (*globalIndexOfOriginalGridSource_)(idx)) 488 globaIndex MapFromDestToSource[(*globalIndexOfCurrentGridSource_)(idx)].insert((*globalIndexOfOriginalGridSource_)(idx));487 globaIndexWeightFromDestToSource[(*globalIndexOfCurrentGridSource_)(idx)].push_back(make_pair((*globalIndexOfOriginalGridSource_)(idx),(*weightOfGlobalIndexOfOriginalGridSource_)(idx))) ; 489 488 } 490 489 491 490 // Then compute transformation mapping among clients 492 transformationMap.computeTransformationMapping(globaIndex MapFromDestToSource);493 494 const std::map<int,std::vector<std::vector<s ize_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(); 495 494 const std::map<int,std::vector<size_t> >& globalIndexToSend = transformationMap.getGlobalIndexSendToGridDestMapping(); 496 495 … … 498 497 CDistributionClient distributionClientSrc(client->clientRank, originalGridSource_); 499 498 500 // const CArray<int, 1>& localIndexOnClientDest = distributionClientDest.getLocalDataIndexOnClient(); //gridDestination_->getDistributionClient()->getLocalDataIndexOnClient();501 499 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(); 506 504 507 505 std::vector<size_t>::const_iterator itbVec, itVec, iteVec; 508 506 CArray<size_t, 1>::const_iterator itbArr, itArr, iteArr; 509 507 510 std::map<int,std::vector<std::vector<s ize_t> > >::const_iterator itbMapRecv, itMapRecv, iteMapRecv;508 std::map<int,std::vector<std::vector<std::pair<size_t,double> > > >::const_iterator itbMapRecv, itMapRecv, iteMapRecv; 511 509 512 510 // Find out local index on grid destination (received) … … 522 520 { 523 521 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; 526 523 for (int idx = 0; idx < vecSize; ++idx) 527 524 { 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); 529 528 if (iteArr != itArr) 530 529 { 531 530 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)); 534 532 } 535 533 } 534 localIndexToReceiveOnGridDest_[sourceRank].push_back(tmpVec); 536 535 } 537 536 } 538 537 538 // Find out local index on grid source (to send) 539 539 std::map<int,std::vector<size_t> >::const_iterator itbMap, itMap, iteMap; 540 // Find out local index on grid source (to send)541 540 itbMap = globalIndexToSend.begin(); 542 541 iteMap = globalIndexToSend.end(); … … 555 554 { 556 555 int localIdx = std::distance(itbArr, itArr); 557 // (*localIndexToSendFromGridSource_[destRank])(idx) = localIndexOnClientSrc(localIdx);558 556 (*localIndexToSendFromGridSource_[destRank])(idx) = (localIdx); 559 557 } … … 575 573 \return local index of data 576 574 */ 577 const std::map<int, std::vector<CArray<int,1>*> >& CGridTransformation::getLocalIndexToReceiveOnGridDest() const575 const std::map<int,std::vector<std::vector<std::pair<int,double> > > >& CGridTransformation::getLocalIndexToReceiveOnGridDest() const 578 576 { 579 577 return localIndexToReceiveOnGridDest_;
Note: See TracChangeset
for help on using the changeset viewer.