ESyS-Particle  2.3.4
pi_storage_e.hpp
Go to the documentation of this file.
1 // //
3 // Copyright (c) 2003-2017 by The University of Queensland //
4 // Centre for Geoscience Computing //
5 // http://earth.uq.edu.au/centre-geoscience-computing //
6 // //
7 // Primary Business: Brisbane, Queensland, Australia //
8 // Licensed under the Open Software License version 3.0 //
9 // http://www.apache.org/licenses/LICENSE-2.0 //
10 // //
12 
13 // STL includes
14 #include <algorithm> // for sort, copy
15 #include <iterator> // for back_inserter
16 
17 using std::sort;
18 using std::copy;
19 using std::back_inserter;
20 
21 template<typename P,typename InteractionType>
23 
30 template<typename P,typename I>
33  const typename I::ParameterType& param
34 )
36  m_comm(PPA->getComm()),
37  m_param(param)
38 {
39  m_unbreakable=false;
40 }
41 
45 template<typename P,typename InteractionType>
47 {
48  for(int i=0;i<3;i++){
49  if(m_comm.get_dim(i)>1){
50  // -- up --
51  exchange_boundary(i,1);
52  // -- down --
53  exchange_boundary(i,-1);
54  }
55  }
56 }
57 
64 template<typename P,typename InteractionType>
66 {
67  console.XDebug() << "PIS_E::exchange_boundary(" << dim << "," << dir << ") at node " << m_comm.rank() << "\n";
68  set<int> bdry_ids;
69  vector<InteractionType> recv_buffer;
70  vector<InteractionType> send_buffer;
71 
72  // get boundary
73  bdry_ids = this->m_ppa->getBoundarySlabIds(dim,dir);
74  // for all interactions
75  for(
76  typename list<InteractionType>::iterator iter = this->m_interactions.begin();
77  iter != this->m_interactions.end();
78  iter++
79  ){
80  vector<int> pids=iter->getAllID(); // get particle IDs
81  bool flag=false;
82  // check if any id is in boundary slab
83  vector<int>::iterator it2=pids.begin();
84  while(it2!=pids.end() && !flag){
85  flag=(bdry_ids.find(*it2)!=bdry_ids.end());
86  it2++;
87  }
88  if(flag){
89  send_buffer.push_back(*iter);
90  }
91  }
92  // shift
93  m_comm.shift_cont_packed(send_buffer,recv_buffer,dim,dir,m_exchg_tag);
94  // try to insert the received interactions
95  for(typename vector<InteractionType>::iterator iter=recv_buffer.begin();
96  iter!=recv_buffer.end();
97  iter++){
98  tryInsert(*iter);
99  }
100  // clean buffers
101  send_buffer.clear();
102  recv_buffer.clear();
103  console.XDebug() << "end PIS_E::exchange_boundary(" << dim << "," << dir << ") at node " << m_comm.rank() << "\n";
104 }
105 
110 template<typename P,typename InteractionType>
112 {
113  console.XDebug() << "PIS_E::rebuild at node " << m_comm.rank() << "\n";
114  console.XDebug() << "size pre rebuild: " << this->m_interactions.size() << "\n";
115 
116  // -- DEBUG ---
117  for(typename list<InteractionType>::iterator iter = this->m_interactions.begin();
118  iter!=this->m_interactions.end();
119  iter++){
120  vector<int> pids=iter->getAllID();
121  console.XDebug() << pids[0] << " - " << pids[1] << "\n";
122  }
123  // --- END DEBUG ---
124  vector<P*> pptr;
125  ParallelParticleArray<P>* t_ppa=(ParallelParticleArray<P>*)(this->m_ppa);
126  typename list<InteractionType>::iterator iter = this->m_interactions.begin();
127  while(iter != this->m_interactions.end()){
128  vector<int> pids=iter->getAllID();
129  vector<int>::const_iterator it2=pids.begin();
130  bool flag=true;
131  // check if the particles with the stored IDs are here
132  while(it2!=pids.end() && flag){
133  P* ptr=t_ppa->getParticlePtrByIndex(*it2);
134  if(ptr!=NULL){
135  pptr.push_back(ptr);
136  } else {
137  flag=false;
138  }
139  it2++;
140  }
141  if(flag){ // if all particle IDs are valid -> set particle pointers
142  iter->setPP(pptr);
143  iter->checkIDs();
144  iter++;
145  } else { // if not -> erase interactions
146  const typename list<InteractionType>::iterator er_iter=iter;
147  iter++;
148  this->m_interactions.erase(er_iter);
149  m_set.erase(make_pair(pids[0],pids[1]));
150  }
151  pptr.clear();
152  }
153  console.XDebug() << "size post rebuild: " << this->m_interactions.size() << "\n";
154  // cout << "end PIS_E::rebuild at node " << m_comm.rank() << endl;
155 }
156 
157 
164 template<typename P,typename InteractionType>
166 {
167  bool flag=true;
168 
169  ParallelParticleArray<P>* t_ppa=(ParallelParticleArray<P>*)(this->m_ppa);
170  // check if interaction is already in
171  vector<int> pids=In.getAllID();
172  flag=!isIn(pids);
173  // try to get particle pointers from ppa
174  vector<int>::const_iterator iter=pids.begin();
175  while(iter!=pids.end() && flag){
176  P* ptr=t_ppa->getParticlePtrByIndex(*iter);
177  if(ptr!=NULL){
178  //pptr.push_back(ptr);
179  } else {
180  flag=false;
181  }
182  iter++;
183  }
184 
185  if(flag){
186  this->m_interactions.push_back(In);
187  m_set.insert(make_pair(pids[0],pids[1]));
188  }
189 }
190 
194 template<typename P,typename InteractionType>
196 {
197  bool res;
198 
199  if(pids[0] > pids [1]){
200  console.Debug()<< "flipped PIDS : " << pids[0] << "," << pids[1] << "\n";
201  }
202  res=m_set.find(make_pair(pids[0],pids[1]))!=m_set.end();
203 
204  return res;
205 }
206 
207 
215 template<typename P,typename InteractionType>
217 {
218  vector<P*> pptr;
219  bool flag=true;
220 
221  // can't sort pids directly because of const -> need copy
222  vector<int> pids;
223  copy(cpids.begin(),cpids.end(),back_inserter(pids));
224  sort(pids.begin(),pids.end());
225 
226  ParallelParticleArray<P>* t_ppa=(ParallelParticleArray<P>*)(this->m_ppa);
227  // check if interaction is already in
228  flag=!isIn(pids);
229  // try to get particle pointers from ppa
230  vector<int>::const_iterator iter=pids.begin();
231  while(iter!=pids.end() && flag){
232  P* ptr=t_ppa->getParticlePtrByIndex(*iter);
233  if(ptr!=NULL){
234  pptr.push_back(ptr);
235  } else {
236  flag=false;
237  }
238  iter++;
239  }
240 
241  if(flag){
242  // initialize interaction from particle pointers and interaction parameters
243  InteractionType new_interaction(pptr[0],pptr[1],m_param);
244  vector<int> allid=new_interaction.getAllID();
245  console.XDebug() << allid[0] << " , " << allid[1] << "\n";
246  // insert interaction
247  this->m_interactions.push_back(new_interaction);
248  this->m_set.insert(make_pair(pids[0],pids[1]));
249  }
250 }
251 
255 template<typename P,typename InteractionType>
257 {
258  console.Debug()
259  << "calculating "
260  << this->m_interactions.size()
261  << " interaction forces\n" ;
262 
263  for(
264  typename list<InteractionType>::iterator it = this->m_interactions.begin();
265  it != this->m_interactions.end();
266  it++
267  ){
268  it->calcForces();
269  }
270 }
271 
277 template<typename P,typename InteractionType>
279 {
280  m_unbreakable=b;
281 }
Console::Debug
Console & Debug()
set verbose level of next message to "dbg"
ParallelInteractionStorage_E::rebuild
virtual void rebuild()
Definition: pi_storage_e.hpp:111
ParallelParticleArray::getParticlePtrByIndex
T * getParticlePtrByIndex(int)
Definition: pp_array.hpp:220
ParallelInteractionStorage_E
parallel interaction storage array with exchange
Definition: pi_storage_e.h:37
ParallelInteractionStorage_E::isIn
virtual bool isIn(const std::vector< int > &)
Definition: pi_storage_e.hpp:195
ParallelParticleArray
parrallel particle storage array with neighborsearch and variable exchange
Definition: pp_array.h:75
Console::XDebug
Console & XDebug()
set verbose level of next message to "xdg"
NULL
#define NULL
Definition: t_list.h:17
AParallelParticleArray
abstract base class for parallel particle storage array
Definition: pp_array.h:42
ParallelInteractionStorage_E::ParallelInteractionStorage_E
ParallelInteractionStorage_E(AParallelParticleArray *, const typename I::ParameterType &)
Definition: pi_storage_e.hpp:31
TParallelInteractionStorage
templated abstract base class for parallel interaction storage array. Adds the vector of interactions...
Definition: pi_storage.h:91
ParallelInteractionStorage_E::setUnbreakable
virtual void setUnbreakable(bool)
Definition: pi_storage_e.hpp:278
esys::lsm::bpu::iter
boost::python::object iter(const boost::python::object &pyOb)
Definition: Util.h:25
ParallelInteractionStorage_E::exchange_boundary
void exchange_boundary(int, int)
Definition: pi_storage_e.hpp:65
ParallelInteractionStorage_E::tryInsert
virtual void tryInsert(const I &)
ParallelInteractionStorage_E::m_unbreakable
bool m_unbreakable
Definition: pi_storage_e.h:42
ParallelInteractionStorage_E::calcForces
virtual void calcForces()
Definition: pi_storage_e.hpp:256
console
Console console
Definition: console.cpp:25
ParallelInteractionStorage_E::exchange
virtual void exchange()
Definition: pi_storage_e.hpp:46