ESyS-Particle  4.0.1
pi_storage_ed_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_ED_T<P,I>::ParallelInteractionStorage_ED_T(AParallelParticleArray* ppa,const typename I::ParameterType& param,int tag1, int mask1, int tag2, int mask2):ParallelInteractionStorage_ED<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_ED_T<T,InteractionType>::update()
00035 {
00036   console.XDebug() << "ParallelInteractionStorage_ED_T::update at node " << this->m_comm.rank() << "\n";
00037 
00038   int count_l=0;
00039   bool res=true;
00040 
00041   if (this->m_update_timestamp != this->m_ppa->getTimeStamp()){// m_ppa rebuild since last update 
00042     console.XDebug() << "node " << this->m_comm.rank() << " ppa has been rebuilt\n";
00043     // clean out old interactions if not flagged as persistent
00044     typename list<InteractionType>::iterator iter = this->m_interactions.begin();
00045     while(iter != this->m_interactions.end()){
00046       if(iter->isPersistent()){
00047         iter++;
00048         //console.XDebug() << "node " << m_comm.rank() << "persistent interaction\n";
00049       }else{
00050         typename list<InteractionType>::iterator er_iter=iter;
00051         // get particle ids and remove pair from set
00052         vector<int> rm_pids=iter->getAllID();
00053         this->m_set.erase(make_pair(rm_pids[0],rm_pids[1]));
00054         iter++;
00055         this->m_interactions.erase(er_iter);
00056       }
00057     }
00058     // get list  of pairs from m_ppa
00059     typename ParallelParticleArray<T>::PairListHandle plh =
00060       ((ParallelParticleArray<T>*)this->m_ppa)->getFullPairList();
00061     // generate interactions from pairs
00062     for(typename ParallelParticleArray<T>::PairListIterator iter=plh->begin();
00063         iter!=plh->end();
00064         iter++){
00065       //--- check particle tags ---
00066       // get tags
00067       int t1=iter->first->getTag();
00068       int t2=iter->second->getTag();
00069       // sort tags
00070       if(t1>t2){
00071         int th=t1;
00072         t1=t2;
00073         t2=th;
00074       }
00075       // tags fit -> go on
00076       if(((t1 & m_mask1)==(m_tag1 & m_mask1)) && ((t2 & m_mask2)==(m_tag2 & m_mask2))){
00077         // check vs. ExIG
00078         vector<int> tv;
00079         // ids in pair
00080         int id1=iter->first->getID();
00081         int id2=iter->second->getID();
00082         tv.push_back(id1);
00083         tv.push_back(id2);
00084         if(this->m_exIG!=NULL){ // if there is an ExIG
00085           if((!(this->m_exIG)->isIn(tv))&&(!this->isIn(tv))){  // if not already in or in ExIG
00086             this->m_interactions.push_back(InteractionType(iter->first,iter->second,this->m_param));
00087             this->m_set.insert(make_pair(id1,id2));
00088             count_l++;
00089           }
00090         } else if (!(this->isIn(tv))) { // if no ExIG -> check only if alrady in
00091           this->m_interactions.push_back(InteractionType(iter->first,iter->second,this->m_param));
00092           this->m_set.insert(make_pair(id1,id2));
00093         }
00094       }
00095     }
00096   } else { // m_ppa not rebuild since last update -> just get additional interactions
00097     console.XDebug() << "node " << this->m_comm.rank() << " ppa not rebuilt\n";
00098     // get list  of pairs from m_ppa
00099     typename ParallelParticleArray<T>::PairListHandle plh =
00100       ((ParallelParticleArray<T>*)this->m_ppa)->getNewPairList();
00101     for (
00102       typename ParallelParticleArray<T>::PairListIterator iter=plh->begin();
00103       iter!=plh->end();
00104       iter++
00105     ){
00106       //--- check particle tags ---
00107       // get tags
00108       int t1=iter->first->getTag();
00109       int t2=iter->second->getTag();
00110       // sort tags
00111       if(t1>t2){
00112         int th=t1;
00113         t1=t2;
00114         t2=th;
00115       }
00116       // tags fit -> go on
00117       if(((t1 & m_mask1)==(m_tag1 & m_mask1)) && ((t2 & m_mask2)==(m_tag2 & m_mask2))){      
00118         // check vs. ExIG
00119         vector<int> tv;
00120         // ids in pair
00121         int id1=iter->first->getID();
00122         int id2=iter->second->getID();
00123         tv.push_back(id1);
00124         tv.push_back(id2); 
00125         if(this->m_exIG!=NULL){
00126           if((!(this->m_exIG)->isIn(tv))&&(!(this->isIn(tv)))) {
00127             this->m_interactions.push_back(InteractionType(iter->first,iter->second, this->m_param));
00128             this->m_set.insert(make_pair(id1,id2));
00129             count_l++;
00130           }
00131         } else if (!(this->isIn(tv))) {
00132           this->m_interactions.push_back(InteractionType(iter->first,iter->second,this->m_param));
00133           this->m_set.insert(make_pair(id1,id2));
00134         }
00135       }
00136     }
00137   }
00138   this->m_update_timestamp = this->m_ppa->getTimeStamp();
00139 
00140   console.Debug() << "added " << count_l << " pairs to ParallelInteractionStorage_ED_T\n";
00141 
00142   return res;
00143 }