ESyS-Particle  4.0.1
pi_storage_ed_t.hpp
1 
2 // //
3 // Copyright (c) 2003-2011 by The University of Queensland //
4 // Earth Systems Science Computational Centre (ESSCC) //
5 // http://www.uq.edu.au/esscc //
6 // //
7 // Primary Business: Brisbane, Queensland, Australia //
8 // Licensed under the Open Software License version 3.0 //
9 // http://www.opensource.org/licenses/osl-3.0.php //
10 // //
12 
13 template<typename P,typename I>
14 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)
15 {
16  if(tag1<=tag2){ // sort tags so that m_tag1<=m_tag2
17  m_tag1=tag1;
18  m_mask1=mask1;
19  m_tag2=tag2;
20  m_mask2=mask2;
21  } else {
22  m_tag1=tag2;
23  m_mask1=mask2;
24  m_tag2=tag1;
25  m_mask2=mask1;
26  }
27 }
28 
29 
33 template<typename T,typename InteractionType>
35 {
36  console.XDebug() << "ParallelInteractionStorage_ED_T::update at node " << this->m_comm.rank() << "\n";
37 
38  int count_l=0;
39  bool res=true;
40 
41  if (this->m_update_timestamp != this->m_ppa->getTimeStamp()){// m_ppa rebuild since last update
42  console.XDebug() << "node " << this->m_comm.rank() << " ppa has been rebuilt\n";
43  // clean out old interactions if not flagged as persistent
44  typename list<InteractionType>::iterator iter = this->m_interactions.begin();
45  while(iter != this->m_interactions.end()){
46  if(iter->isPersistent()){
47  iter++;
48  //console.XDebug() << "node " << m_comm.rank() << "persistent interaction\n";
49  }else{
50  typename list<InteractionType>::iterator er_iter=iter;
51  // get particle ids and remove pair from set
52  vector<int> rm_pids=iter->getAllID();
53  this->m_set.erase(make_pair(rm_pids[0],rm_pids[1]));
54  iter++;
55  this->m_interactions.erase(er_iter);
56  }
57  }
58  // get list of pairs from m_ppa
59  typename ParallelParticleArray<T>::PairListHandle plh =
60  ((ParallelParticleArray<T>*)this->m_ppa)->getFullPairList();
61  // generate interactions from pairs
62  for(typename ParallelParticleArray<T>::PairListIterator iter=plh->begin();
63  iter!=plh->end();
64  iter++){
65  //--- check particle tags ---
66  // get tags
67  int t1=iter->first->getTag();
68  int t2=iter->second->getTag();
69  // sort tags
70  if(t1>t2){
71  int th=t1;
72  t1=t2;
73  t2=th;
74  }
75  // tags fit -> go on
76  if(((t1 & m_mask1)==(m_tag1 & m_mask1)) && ((t2 & m_mask2)==(m_tag2 & m_mask2))){
77  // check vs. ExIG
78  vector<int> tv;
79  // ids in pair
80  int id1=iter->first->getID();
81  int id2=iter->second->getID();
82  tv.push_back(id1);
83  tv.push_back(id2);
84  if(this->m_exIG!=NULL){ // if there is an ExIG
85  if((!(this->m_exIG)->isIn(tv))&&(!this->isIn(tv))){ // if not already in or in ExIG
86  this->m_interactions.push_back(InteractionType(iter->first,iter->second,this->m_param));
87  this->m_set.insert(make_pair(id1,id2));
88  count_l++;
89  }
90  } else if (!(this->isIn(tv))) { // if no ExIG -> check only if alrady in
91  this->m_interactions.push_back(InteractionType(iter->first,iter->second,this->m_param));
92  this->m_set.insert(make_pair(id1,id2));
93  }
94  }
95  }
96  } else { // m_ppa not rebuild since last update -> just get additional interactions
97  console.XDebug() << "node " << this->m_comm.rank() << " ppa not rebuilt\n";
98  // get list of pairs from m_ppa
99  typename ParallelParticleArray<T>::PairListHandle plh =
100  ((ParallelParticleArray<T>*)this->m_ppa)->getNewPairList();
101  for (
102  typename ParallelParticleArray<T>::PairListIterator iter=plh->begin();
103  iter!=plh->end();
104  iter++
105  ){
106  //--- check particle tags ---
107  // get tags
108  int t1=iter->first->getTag();
109  int t2=iter->second->getTag();
110  // sort tags
111  if(t1>t2){
112  int th=t1;
113  t1=t2;
114  t2=th;
115  }
116  // tags fit -> go on
117  if(((t1 & m_mask1)==(m_tag1 & m_mask1)) && ((t2 & m_mask2)==(m_tag2 & m_mask2))){
118  // check vs. ExIG
119  vector<int> tv;
120  // ids in pair
121  int id1=iter->first->getID();
122  int id2=iter->second->getID();
123  tv.push_back(id1);
124  tv.push_back(id2);
125  if(this->m_exIG!=NULL){
126  if((!(this->m_exIG)->isIn(tv))&&(!(this->isIn(tv)))) {
127  this->m_interactions.push_back(InteractionType(iter->first,iter->second, this->m_param));
128  this->m_set.insert(make_pair(id1,id2));
129  count_l++;
130  }
131  } else if (!(this->isIn(tv))) {
132  this->m_interactions.push_back(InteractionType(iter->first,iter->second,this->m_param));
133  this->m_set.insert(make_pair(id1,id2));
134  }
135  }
136  }
137  }
138  this->m_update_timestamp = this->m_ppa->getTimeStamp();
139 
140  console.Debug() << "added " << count_l << " pairs to ParallelInteractionStorage_ED_T\n";
141 
142  return res;
143 }