ESyS-Particle  4.0.1
pi_storage.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 #include "Foundation/vec3.h"
14 #include "Fields/ScalarInteractionFieldSlave.h"
15 #include "Fields/CheckedScalarInteractionFieldSlave.h"
16 #include "Fields/ScalarInteractionFieldSlaveTagged.h"
17 #include "Fields/CheckedScalarInteractionFieldSlaveTagged.h"
18 #include "Fields/VectorInteractionFieldSlave.h"
19 
20 #include "ppa/src/pp_array.h"
21 
22 template <typename I>
24 {
25  return m_ppa->isInInner(it->getPosFirst());
26 }
27 
28 template <typename I>
30  Iterator begin,
31  Iterator end,
33 )
34  : m_numRemaining(0),
35  m_it(end),
36  m_end(end),
37  m_ppa(ppa)
38 {
39  m_numRemaining = 0;
40  for (Iterator it = begin; it != end; it++) {
41  if (isInner(it)) {
42  m_numRemaining++;
43  }
44  }
45  m_it = begin;
46  m_end = end;
47 }
48 
49 template <typename I>
51 {
52  return (m_numRemaining > 0);
53 }
54 
55 template <typename I>
56 typename TParallelInteractionStorage<I>::InteractionIterator::Interaction &
58 {
59  while (!isInner(m_it)) {
60  m_it++;
61  }
62  Interaction &i = *m_it;
63  m_it++;
64  m_numRemaining--;
65  return i;
66 }
67 
68 template <typename I>
70 {
71  return m_numRemaining;
72 }
73 
74 template <typename I>
77 {
78  return
79  InteractionIterator(m_interactions.begin(), m_interactions.end(), m_ppa);
80 }
81 
82 
89 template <typename I>
90 template <typename P>
92 {
93  vector<pair<Vec3,P> > res;
94 
95  for(typename list<I>::iterator iter=m_interactions.begin();
96  iter!=m_interactions.end();
97  iter++){
98  Vec3 pos=iter->getPosFirst();
99  if(m_ppa->isInInner(pos)) res.push_back(make_pair(iter->getPos(),((*iter).*rdf)()));
100  }
101 
102  return res;
103 }
104 
111 template <typename I>
112 template <typename P>
113 vector<pair<typename TParallelInteractionStorage<I>::Raw2Data,P> >
115 {
116  vector<pair<Raw2Data,P> > res;
117 
118  for(typename list<I>::iterator iter=m_interactions.begin();
119  iter!=m_interactions.end();
120  iter++){
121  if(m_ppa->isInInner(iter->getPosFirst())) {
122  const Raw2Data data = iter->getRaw2Data();
123  res.push_back(pair<Raw2Data,P>(data,((*iter).*rdf)()));
124  }
125  }
126 
127  return res;
128 }
129 
136 template <typename I>
137 template <typename P>
138 vector<pair<typename TParallelInteractionStorage<I>::DataWithPosID,P> >
140 {
141  vector<pair<DataWithPosID,P> > res;
142 
143  for(typename list<I>::iterator iter=m_interactions.begin();
144  iter!=m_interactions.end();
145  iter++){
146  if(m_ppa->isInInner(iter->getPosFirst())) {
147  vector<int> ids=iter->getAllID();
148  int id1=ids[0];
149  int id2;
150  if(ids.size()>=2) {
151  id2=ids[1];
152  } else {
153  id2=-1;
154  }
155  const Raw2Data data = iter->getRaw2Data();
156  Vec3 pos1=data.get<0>();
157  Vec3 pos2=data.get<2>();
158  Vec3 ipos=data.get<4>();
159  res.push_back(pair<DataWithPosID,P>(DataWithPosID(id1,id2,pos1,pos2,ipos),((*iter).*rdf)()));
160  }
161  }
162 
163  return res;
164 }
165 
172 template <typename I>
173 template <typename P>
174 vector<pair<typename TParallelInteractionStorage<I>::DataWithID,P> >
176 {
177  vector<pair<DataWithID,P> > res;
178 
179  for(typename list<I>::iterator iter=m_interactions.begin();
180  iter!=m_interactions.end();
181  iter++){
182  if(m_ppa->isInInner(iter->getPosFirst())) {
183  vector<int> ids=iter->getAllID();
184  int id1=ids[0];
185  int id2;
186  if(ids.size()>=2) {
187  id2=ids[1];
188  } else {
189  id2=-1;
190  }
191  Vec3 pos=iter->getPos();
192  res.push_back(pair<DataWithID,P>(DataWithID(id1,id2,pos),((*iter).*rdf)()));
193  }
194  }
195 
196  return res;
197 }
198 
207 template <typename I>
208 template <typename P>
209 void TParallelInteractionStorage<I>::forAllInnerInteractionsGet(P& cont,typename P::value_type (I::*rdf)()const)
210 {
211  for(typename list<I>::iterator iter=m_interactions.begin();
212  iter!=m_interactions.end();
213  iter++){
214  Vec3 pos=iter->getPosFirst();
215  if(m_ppa->isInInner(pos)) cont.push_back(((*iter).*rdf)());
216  }
217 }
218 
219 
229 template <typename I>
230 template <typename P>
231 vector<pair<Vec3,P> > TParallelInteractionStorage<I>::forAllTaggedInnerInteractionsGetWithPos(P (I::*rdf)() const,int tag,int mask)
232 {
233  vector<pair<Vec3,P> > res;
234 
235  for(typename list<I>::iterator iter=m_interactions.begin();
236  iter!=m_interactions.end();
237  iter++){
238  Vec3 pos=iter->getPosFirst();
239  if(iter->hasTag(tag,mask)){
240  if(m_ppa->isInInner(pos)) res.push_back(make_pair(iter->getPos(),((*iter).*rdf)()));
241  }
242  }
243 
244  return res;
245 }
246 
256 template <typename I>
257 template <typename P>
258 void TParallelInteractionStorage<I>::forAllTaggedInnerInteractionsGet(P& cont,typename P::value_type (I::*rdf)()const,int tag,int mask)
259 {
260  for(typename list<I>::iterator iter=m_interactions.begin();
261  iter!=m_interactions.end();
262  iter++){
263  Vec3 pos=iter->getPosFirst();
264  if(iter->hasTag(tag,mask)){
265  if(m_ppa->isInInner(pos)) cont.push_back(((*iter).*rdf)());
266  }
267  }
268 }
269 
280 template <typename I>
281 AFieldSlave* TParallelInteractionStorage<I>::generateNewScalarFieldSlave(TML_Comm* comm,const string& fieldname,int is_checked,int is_tagged,int tag,int mask)
282 {
283  InteractionFieldSlave<I>* new_ifs;
284 
285 
286  if(is_checked==0){
287  typename I::ScalarFieldFunction rdf=I::getScalarFieldFunction(fieldname);
288  if(is_tagged==0){
289  new_ifs=new ScalarInteractionFieldSlave<I>(comm,this,rdf);
290  } else {
291  new_ifs=new ScalarInteractionFieldSlaveTagged<I>(comm,this,rdf,tag,mask);
292  }
293  } else {
294  typename I::CheckedScalarFieldFunction rdf=I::getCheckedScalarFieldFunction(fieldname);
295  if(is_tagged==0){
296  new_ifs=new CheckedScalarInteractionFieldSlave<I>(comm,this,rdf);
297  } else {
298  new_ifs=new CheckedScalarInteractionFieldSlaveTagged<I>(comm,this,rdf,tag,mask);
299  }
300  }
301 
302  return new_ifs;
303 }
304 
315 template <typename I>
316 AFieldSlave* TParallelInteractionStorage<I>::generateNewVectorFieldSlave(TML_Comm* comm,const string& fieldname,int is_checked,int is_tagged,int tag,int mask)
317 {
318  InteractionFieldSlave<I>* new_ifs = NULL;
319 
320 
321  if(is_checked==0){
322  typename I::VectorFieldFunction rdf=I::getVectorFieldFunction(fieldname);
323  if(is_tagged==0){
324  new_ifs=new VectorInteractionFieldSlave<I>(comm,this,rdf);
325  } else {
326  // new_ifs=new VectorInteractionFieldSlaveTagged<I>(comm,this,rdf,tag,mask);
327  }
328  } else {
329  // typename I::CheckedVectorFieldFunction rdf=I::getCheckedVectorFieldFunction(fieldname);
330  if(is_tagged==0){
331  // new_ifs=new CheckedVectorInteractionFieldSlave<I>(comm,this,rdf);
332  } else {
333  // new_ifs=new CheckedVectorInteractionFieldSlaveTagged<I>(comm,this,rdf,tag,mask);
334  }
335  }
336 
337  return new_ifs;
338 }