ESyS-Particle  4.0.1
pi_storage_ne_t.hpp
00001 
00002 //                                                         //
00003 // Copyright (c) 2003-2011 by The University of Queensland //
00004 // Earth Systems Science Computational Centre (ESSCC)      //
00005 // http://www.uq.edu.au/esscc                              //
00006 //                                                         //
00007 // Primary Business: Brisbane, Queensland, Australia       //
00008 // Licensed under the Open Software License version 3.0    //
00009 // http://www.opensource.org/licenses/osl-3.0.php          //
00010 //                                                         //
00012 
00013 template<typename P,typename I>
00014 ParallelInteractionStorage_NE_T<P,I>::ParallelInteractionStorage_NE_T(AParallelParticleArray* ppa,const typename I::ParameterType& param,int tag1, int mask1, int tag2, int mask2):ParallelInteractionStorage_NE<P,I>(ppa,param)
00015 {
00016   if(tag1<=tag2){ // sort tags so that m_tag1<=m_tag2
00017     m_tag1=tag1;
00018     m_mask1=mask1;
00019     m_tag2=tag2;
00020     m_mask2=mask2;
00021   } else {
00022     m_tag1=tag2;
00023     m_mask1=mask2;
00024     m_tag2=tag1;
00025     m_mask2=mask1;
00026   }
00027 }
00028 
00029 
00033 template<typename T,typename InteractionType>
00034 bool ParallelInteractionStorage_NE_T<T,InteractionType>::update()
00035 {
00036   console.XDebug() << "ParallelInteractionStorage_NE_T::Update\n";
00037   int count_l=0;
00038   bool res=true;
00039 
00040   if(this->m_update_timestamp != this->m_ppa->getTimeStamp()){// m_ppa rebuild since last update 
00041     // clean out old interactions
00042     this->m_interactions.clear();
00043     this->m_set.erase(this->m_set.begin(),this->m_set.end());
00044     // get list  of pairs from m_ppa
00045     typename ParallelParticleArray<T>::PairListHandle plh =
00046       ((ParallelParticleArray<T>*)this->m_ppa)->getFullPairList();
00047     // generate interactions from pairs
00048     for(typename ParallelParticleArray<T>::PairListIterator iter=plh->begin();
00049         iter!=plh->end();
00050         iter++){
00051       //--- check particle tags ---
00052       // get tags
00053       int t1=iter->first->getTag();
00054       int t2=iter->second->getTag();
00055       // sort tags
00056       if(t1>t2){
00057         int th=t1;
00058         t1=t2;
00059         t2=th;
00060       }
00061       // tags fit -> go on
00062       if(((t1 & m_mask1)==(m_tag1 & m_mask1)) && ((t2 & m_mask2)==(m_tag2 & m_mask2))){      
00063         // check vs. ExIG
00064         vector<int> tv;
00065         tv.push_back(iter->first->getID());
00066         tv.push_back(iter->second->getID());
00067         if(this->m_exIG!=NULL){
00068           if(!this->m_exIG->isIn(tv)){
00069             this->m_interactions.push_back(InteractionType(iter->first,iter->second,this->m_param));
00070             this->m_set.insert(pair<int,int>(iter->first->getID(),iter->second->getID()));
00071             count_l++;
00072           }
00073         } else {
00074           this->m_interactions.push_back(InteractionType(iter->first,iter->second,this->m_param));
00075           this->m_set.insert(pair<int,int>(iter->first->getID(),iter->second->getID()));
00076           count_l++;
00077         }
00078       }
00079     }
00080   } else { // m_ppa not rebuild since last update -> just get additional interactions
00081     // get list  of pairs from m_ppa
00082     typename ParallelParticleArray<T>::PairListHandle plh =
00083       ((ParallelParticleArray<T>*)this->m_ppa)->getNewPairList();
00084     for(typename ParallelParticleArray<T>::PairListIterator iter=plh->begin();
00085         iter!=plh->end();
00086         iter++){
00087       //--- check particle tags ---
00088       // get tags
00089       int t1=iter->first->getTag();
00090       int t2=iter->second->getTag();
00091       // sort tags
00092       if(t1>t2){
00093         int th=t1;
00094         t1=t2;
00095         t2=th;
00096       }
00097       // tags fit -> go on
00098       if(((t1 & m_mask1)==(m_tag1 & m_mask1)) && ((t2 & m_mask2)==(m_tag2 & m_mask2))){      
00099         // check vs. ExIG
00100         vector<int> tv;
00101         tv.push_back(iter->first->getID());
00102         tv.push_back(iter->second->getID());
00103         if(this->m_exIG!=NULL){
00104           if(!this->m_exIG->isIn(tv)){
00105             this->m_interactions.push_back(InteractionType(iter->first,iter->second,this->m_param));
00106             this->m_set.insert(pair<int,int>(iter->first->getID(),iter->second->getID()));
00107             count_l++;
00108           }
00109         } else {
00110           this->m_interactions.push_back(InteractionType(iter->first,iter->second,this->m_param));
00111           this->m_set.insert(pair<int,int>(iter->first->getID(),iter->second->getID()));
00112           count_l++;
00113         }
00114       }
00115     }
00116   }
00117   this->m_update_timestamp = this->m_ppa->getTimeStamp();
00118 
00119   console.XDebug() << "added " << count_l << " pairs to EIG\n";
00120   console.XDebug() << "end ParallelInteractionStorage_NE_T::Update\n";
00121 
00122   return res;
00123 }