ESyS-Particle  4.0.1
pi_storage_e.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 InteractionType>
15 
22 template<typename P,typename I>
25  const typename I::ParameterType& param
26 )
28  m_comm(PPA->getComm()),
29  m_param(param)
30 {
31  m_unbreakable=false;
32 }
33 
37 template<typename P,typename InteractionType>
39 {
40  for(int i=0;i<3;i++){
41  if(m_comm.get_dim(i)>1){
42  // -- up --
43  exchange_boundary(i,1);
44  // -- down --
45  exchange_boundary(i,-1);
46  }
47  }
48 }
49 
56 template<typename P,typename InteractionType>
58 {
59  console.XDebug() << "PIS_E::exchange_boundary(" << dim << "," << dir << ") at node " << m_comm.rank() << "\n";
60  set<int> bdry_ids;
61  vector<InteractionType> recv_buffer;
62  vector<InteractionType> send_buffer;
63 
64  // get boundary
65  bdry_ids = this->m_ppa->getBoundarySlabIds(dim,dir);
66  // for all interactions
67  for(
68  typename list<InteractionType>::iterator iter = this->m_interactions.begin();
69  iter != this->m_interactions.end();
70  iter++
71  ){
72  vector<int> pids=iter->getAllID(); // get particle IDs
73  bool flag=false;
74  // check if any id is in boundary slab
75  vector<int>::iterator it2=pids.begin();
76  while(it2!=pids.end() && !flag){
77  flag=(bdry_ids.find(*it2)!=bdry_ids.end());
78  it2++;
79  }
80  if(flag){
81  send_buffer.push_back(*iter);
82  }
83  }
84  // shift
85  m_comm.shift_cont_packed(send_buffer,recv_buffer,dim,dir,m_exchg_tag);
86  // try to insert the received interactions
87  for(typename vector<InteractionType>::iterator iter=recv_buffer.begin();
88  iter!=recv_buffer.end();
89  iter++){
90  tryInsert(*iter);
91  }
92  // clean buffers
93  send_buffer.clear();
94  recv_buffer.clear();
95  console.XDebug() << "end PIS_E::exchange_boundary(" << dim << "," << dir << ") at node " << m_comm.rank() << "\n";
96 }
97 
102 template<typename P,typename InteractionType>
104 {
105  console.XDebug() << "PIS_E::rebuild at node " << m_comm.rank() << "\n";
106  console.XDebug() << "size pre rebuild: " << this->m_interactions.size() << "\n";
107 
108  // -- DEBUG ---
109  for(typename list<InteractionType>::iterator iter = this->m_interactions.begin();
110  iter!=this->m_interactions.end();
111  iter++){
112  vector<int> pids=iter->getAllID();
113  console.XDebug() << pids[0] << " - " << pids[1] << "\n";
114  }
115  // --- END DEBUG ---
116  vector<P*> pptr;
117  ParallelParticleArray<P>* t_ppa=(ParallelParticleArray<P>*)(this->m_ppa);
118  typename list<InteractionType>::iterator iter = this->m_interactions.begin();
119  while(iter != this->m_interactions.end()){
120  vector<int> pids=iter->getAllID();
121  vector<int>::const_iterator it2=pids.begin();
122  bool flag=true;
123  // check if the particles with the stored IDs are here
124  while(it2!=pids.end() && flag){
125  P* ptr=t_ppa->getParticlePtrByIndex(*it2);
126  if(ptr!=NULL){
127  pptr.push_back(ptr);
128  } else {
129  flag=false;
130  }
131  it2++;
132  }
133  if(flag){ // if all particle IDs are valid -> set particle pointers
134  iter->setPP(pptr);
135  iter->checkIDs();
136  iter++;
137  } else { // if not -> erase interactions
138  const typename list<InteractionType>::iterator er_iter=iter;
139  iter++;
140  this->m_interactions.erase(er_iter);
141  m_set.erase(make_pair(pids[0],pids[1]));
142  }
143  pptr.clear();
144  }
145  console.XDebug() << "size post rebuild: " << this->m_interactions.size() << "\n";
146  // cout << "end PIS_E::rebuild at node " << m_comm.rank() << endl;
147 }
148 
149 
156 template<typename P,typename InteractionType>
158 {
159  bool flag=true;
160 
161  ParallelParticleArray<P>* t_ppa=(ParallelParticleArray<P>*)(this->m_ppa);
162  // check if interaction is already in
163  vector<int> pids=In.getAllID();
164  flag=!isIn(pids);
165  // try to get particle pointers from ppa
166  vector<int>::const_iterator iter=pids.begin();
167  while(iter!=pids.end() && flag){
168  P* ptr=t_ppa->getParticlePtrByIndex(*iter);
169  if(ptr!=NULL){
170  //pptr.push_back(ptr);
171  } else {
172  flag=false;
173  }
174  iter++;
175  }
176 
177  if(flag){
178  this->m_interactions.push_back(In);
179  m_set.insert(make_pair(pids[0],pids[1]));
180  }
181 }
182 
186 template<typename P,typename InteractionType>
188 {
189  bool res;
190 
191  if(pids[0] > pids [1]){
192  console.Debug()<< "flipped PIDS : " << pids[0] << "," << pids[1] << "\n";
193  }
194  res=m_set.find(make_pair(pids[0],pids[1]))!=m_set.end();
195 
196  return res;
197 }
198 
199 
207 template<typename P,typename InteractionType>
209 {
210  vector<P*> pptr;
211  bool flag=true;
212 
213  ParallelParticleArray<P>* t_ppa=(ParallelParticleArray<P>*)(this->m_ppa);
214  // check if interaction is already in
215  flag=!isIn(pids);
216  // try to get particle pointers from ppa
217  vector<int>::const_iterator iter=pids.begin();
218  while(iter!=pids.end() && flag){
219  P* ptr=t_ppa->getParticlePtrByIndex(*iter);
220  if(ptr!=NULL){
221  pptr.push_back(ptr);
222  } else {
223  flag=false;
224  }
225  iter++;
226  }
227 
228  if(flag){
229  // initialize interaction from particle pointers and interaction parameters
230  InteractionType new_interaction(pptr[0],pptr[1],m_param);
231  vector<int> allid=new_interaction.getAllID();
232  console.XDebug() << allid[0] << " , " << allid[1] << "\n";
233  // insert interaction
234  this->m_interactions.push_back(new_interaction);
235  this->m_set.insert(make_pair(pids[0],pids[1]));
236  }
237 }
238 
242 template<typename P,typename InteractionType>
244 {
245  console.Debug()
246  << "calculating "
247  << this->m_interactions.size()
248  << " interaction forces\n" ;
249 
250  for(
251  typename list<InteractionType>::iterator it = this->m_interactions.begin();
252  it != this->m_interactions.end();
253  it++
254  ){
255  it->calcForces();
256  }
257 }
258 
264 template<typename P,typename InteractionType>
266 {
267  m_unbreakable=b;
268 }