OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
ParticleInteractAttrib.hpp
Go to the documentation of this file.
1 // -*- C++ -*-
2 /***************************************************************************
3  *
4  * The IPPL Framework
5  *
6  * This program was prepared by PSI.
7  * All rights in the program are reserved by PSI.
8  * Neither PSI nor the author(s)
9  * makes any warranty, express or implied, or assumes any liability or
10  * responsibility for the use of this software
11  *
12  * Visit www.amas.web.psi for more details
13  *
14  ***************************************************************************/
15 
16 // -*- C++ -*-
17 /***************************************************************************
18  *
19  * The IPPL Framework
20  *
21  *
22  * Visit http://people.web.psi.ch/adelmann/ for more details
23  *
24  ***************************************************************************/
25 
26 // include files
28 #include "Message/Message.h"
29 
30 
31 
33 // put the data for M particles into a message, starting from index I.
34 // This will either put in local or ghost particle data, but not both.
35 template<class T>
36 size_t
38  size_t M, size_t I) {
39 
40  if (I >= this->size()) {
41  // put in ghost particles
42  typename ParticleList_t::iterator currp = GhostList.begin() + (I - this->size());
43  typename ParticleList_t::iterator endp = currp + M;
44  ::putMessage(msg, currp, endp);
45  }
46  else {
47  typename ParticleList_t::iterator currp = this->ParticleList.begin() + I;
48  typename ParticleList_t::iterator endp = currp + M;
49  ::putMessage(msg, currp, endp);
50  }
51  return M;
52 }
53 
54 
56 // Delete the ghost attrib storage for M particles, starting at pos I.
57 // Items from the end of the list are moved up to fill in the space.
58 // Return the number of items actually destroyed.
59 template<class T>
60 size_t
62 
63  if (M > 0) {
64  // get iterators for where the data to be deleted begins, and where
65  // the data we copy from the end begins
66  typename ParticleList_t::iterator putloc = GhostList.begin() + I;
67  typename ParticleList_t::iterator getloc = GhostList.end() - M;
68  typename ParticleList_t::iterator endloc = GhostList.end();
69 
70  // make sure we do not copy too much
71  if ((I + M) > (GhostList.size() - M))
72  getloc = putloc + M;
73 
74  // copy over the data
75  while (getloc != endloc)
76  *putloc++ = *getloc++;
77 
78  // delete the last M items
79  GhostList.erase(GhostList.end() - M, GhostList.end());
80  }
81 
82  return M;
83 }
84 
85 
87 // Get ghost data out of a Message containing M particle's attribute data,
88 // and store it here. Data is appended to the end of the list. Return
89 // the number of particles retrieved.
90 template<class T>
91 size_t
93 
94  size_t currsize = GhostList.size();
95  GhostList.insert(GhostList.end(), M, T());
96  ::getMessage_iter(msg, GhostList.begin() + currsize);
97  return M;
98 }
99 
100 
102 // Print out information for debugging purposes. This version just
103 // prints out static information, so it is static
104 template<class T>
106 
107  o << "PAttr: size = " << this->ParticleList.size()
108  << ", capacity = " << this->ParticleList.capacity()
109  << ", ghosts = " << GhostList.size();
110 }
111 
112 
113 /***************************************************************************
114  * $RCSfile: ParticleInteractAttrib.cpp,v $ $Author: adelmann $
115  * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:29 $
116  * IPPL_VERSION_ID: $Id: ParticleInteractAttrib.cpp,v 1.1.1.1 2003/01/23 07:40:29 adelmann Exp $
117  ***************************************************************************/
virtual size_t ghostDestroy(size_t M, size_t I)
Definition: rbendmap.h:8
void getMessage_iter(Message &m, OutputIterator o)
Definition: Message.h:603
virtual size_t putMessage(Message &, size_t, size_t)
virtual size_t ghostGetMessage(Message &, size_t)
std::string::iterator iterator
Definition: MSLang.h:16
void putMessage(Message &m, const T &t)
Definition: Message.h:557
Definition: Inform.h:41
virtual void printDebug(Inform &)