OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
SubParticleAttrib.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
29 #include "Utility/IpplInfo.h"
30 #include "Utility/PAssert.h"
31 
32 
33 
35 // assignment of another SubParticleAttrib
36 template<class PA, class T, unsigned Dim>
39 
40  // just do a regular attribute assignment
41  //A = t.getAttrib();
42  assign(*this, t);
43  return *this;
44 }
45 
46 
48 // assignment of a scalar
49 template<class PA, class T, unsigned Dim>
52 
53  // make a PETE_Scalar so that we can do a regular assignment
54  //A = t;
55  PETE_Scalar<T> scalar(t);
56  assign(*this, scalar);
57  return *this;
58 }
59 
60 
61 
62 
64 // Return the beginning and end iterators for this class.
65 template<class PA, class T, unsigned Dim>
68 
69 
70 
71  PA &p = const_cast<PA &>(A);
72  return iterator(p, MyDomain.begin_iv(), 0, MyDomain);
73 }
74 
75 template<class PA, class T, unsigned Dim>
78 
79 
80 
81  PA &p = const_cast<PA &>(A);
82  return iterator(p, MyDomain.end_iv(), MyDomain.size(), MyDomain);
83 }
84 
86 // Make sure the LHS ParticleAttrib has the proper length. It should
87 // have the same length as the number of LOCAL sparse index points.
88 // If it does not, we adjust the length. Return size of result.
89 template<class PA, class T, unsigned Dim>
91 
92 
93 
94  // get length of sparse index list local pieces
95  int points = MyDomain.size();
96  int currpoints = A.size();
97 
98  // adjust length of attrib
99  if (points < currpoints)
100  A.destroy((currpoints - points), points);
101  else if (points > currpoints)
102  A.create(points - currpoints);
103 
104  return points;
105 }
106 
107 
109 // write out the contents of this SubParticleAttrib to the given ostream.
110 // This not only prints out the values of the attribute, but also prints
111 // out the local sindex points
112 template<class PA, class T, unsigned Dim>
113 void SubParticleAttrib<PA,T,Dim>::write(std::ostream &o) const {
114 
115 
116 
117  // make sure the sizes match
118  PInsist(A.size() == MyDomain.size(),
119  "SubParticleAttrib::write must have an attrib with enough elements");
120 
121  // loop over all the local lfields, printing out particles as we go
122  int i = 0;
123  typename Index_t::const_iterator_iv lfi = MyDomain.begin_iv();
124  for ( ; lfi != MyDomain.end_iv(); ++lfi) {
125  // for each lfield, print out particles
126  typename Index_t::const_iterator_indx lsi = (*lfi)->begin();
127  for ( ; lsi != (*lfi)->end(); ++lsi)
128  o << *lsi + MyDomain.getOffset() << " ==> " << A[i++] << endl;
129  }
130 
131 }
132 
133 
134 /***************************************************************************
135  * $RCSfile: SubParticleAttrib.cpp,v $ $Author: adelmann $
136  * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:33 $
137  * IPPL_VERSION_ID: $Id: SubParticleAttrib.cpp,v 1.1.1.1 2003/01/23 07:40:33 adelmann Exp $
138  ***************************************************************************/
Definition: rbendmap.h:8
LSIndex< Dim >::const_iterator const_iterator_indx
Definition: SIndex.h:75
iterator end() const
void assign(const BareField< T, Dim > &a, RHS b, OP op, ExprTag< true >)
container_t::const_iterator const_iterator_iv
Definition: SIndex.h:72
iterator begin() const
std::string::iterator iterator
Definition: MSLang.h:16
#define PInsist(c, m)
Definition: PAssert.h:135
SubParticleAttrib< PA, T, Dim > & operator=(const SubParticleAttrib< PA, T, Dim > &)
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
void write(std::ostream &) const