OPAL (Object Oriented Parallel Accelerator Library)
2024.2
OPAL
ippl
src
SubParticle
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
27
#include "
SubParticle/SubParticleAttrib.h
"
28
#include "
Particle/ParticleAttrib.h
"
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>
37
SubParticleAttrib<PA,T,Dim>
&
38
SubParticleAttrib<PA,T,Dim>::operator=
(
const
SubParticleAttrib<PA,T,Dim>
&t) {
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>
50
SubParticleAttrib<PA,T,Dim>
&
51
SubParticleAttrib<PA,T,Dim>::operator=
(T t) {
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>
66
typename
SubParticleAttrib<PA,T,Dim>::iterator
67
SubParticleAttrib<PA,T,Dim>::begin
()
const
{
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>
76
typename
SubParticleAttrib<PA,T,Dim>::iterator
77
SubParticleAttrib<PA,T,Dim>::end
()
const
{
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>
90
int
SubParticleAttrib<PA,T,Dim>::adjustSize
() {
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++] << std::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
***************************************************************************/
SubParticleAttrib.h
assign
void assign(const BareField< T, Dim > &a, RHS b, OP op, ExprTag< true >)
ParticleAttrib.h
PAssert.h
PInsist
#define PInsist(c, m)
Definition
PAssert.h:120
IpplInfo.h
SIndex::const_iterator_iv
container_t::const_iterator const_iterator_iv
Definition
SIndex.h:71
SIndex::const_iterator_indx
LSIndex< Dim >::const_iterator const_iterator_indx
Definition
SIndex.h:74
PETE_Scalar
Definition
PETE.h:143
SubParticleAttrib
Definition
SubParticleAttrib.h:150
SubParticleAttrib::operator=
SubParticleAttrib< PA, T, Dim > & operator=(const SubParticleAttrib< PA, T, Dim > &)
Definition
SubParticleAttrib.hpp:38
SubParticleAttrib::begin
iterator begin() const
Definition
SubParticleAttrib.hpp:67
SubParticleAttrib::write
void write(std::ostream &) const
Definition
SubParticleAttrib.hpp:113
SubParticleAttrib::end
iterator end() const
Definition
SubParticleAttrib.hpp:77
SubParticleAttrib::adjustSize
int adjustSize()
Definition
SubParticleAttrib.hpp:90
SubParticleAttribIter
Definition
SubParticleAttrib.h:68
Generated on Tue Apr 14 2026 07:18:44 for OPAL (Object Oriented Parallel Accelerator Library) by
1.9.8