OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
SubBareField.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /***************************************************************************
3  *
4  * The IPPL Framework
5  *
6  *
7  * Visit http://people.web.psi.ch/adelmann/ for more details
8  *
9  ***************************************************************************/
10 
11 #ifndef SUB_BARE_FIELD_H
12 #define SUB_BARE_FIELD_H
13 
14 /***************************************************************************
15  SubBareField - represent a view on a given BareField, referring to a
16  subset of the original field data. This is meant as an eventual
17  replacement for IndexedBareField.
18 
19  SubBareField is templated on the T and Dim of the Field, and also on the
20  type of subset object used to refer to the field subsection. This can
21  range from NDIndex for a rectangular block, to SIndex for an arbitrary
22  list of points, to SOffset to store a single point. The behavior of this
23  class, and in particular the iterator for this class, is specialized to
24  each subset object using a traits class 'SFTraits' and a couple of global
25  functions.
26 
27  From a BareField, you create a SubBareField by using the bracket
28  operators [], giving a particular type of data to further index the object.
29  Indexing with and Index or NDIndex object results in a SubBareField object
30  templated on NDIndex, etc. A SubBareField keeps track of the number of
31  'Brackets' its been given; an expression can only involve a SubBareField
32  if Brackets == Dim. Using [] on a SubBareField will generally increase the
33  number of brackets, and result in a new SubBareField incorporating the
34  info about how to select the subset as specified by the object in brackets.
35  For example, Field<T,Dim>[Index] results in a SubBareField<T,Dim,NDIndex<Dim>>
36  object with Brackets==1; further application of [Index] operators increases
37  the number of Brackets and stores each Index in the internal NDIndex at the
38  proper location. SFTraits provides the information on what types of objects
39  can be used to subset, and what type of subset object they produce.
40 
41  For the future, it might be useful to make this 'SubBareField' be the actual
42  class employed by the user, with the current 'BareField' some form of
43  internal class used only to store the data in whatever representation is
44  most efficient.
45  ***************************************************************************/
46 
47 // include files
48 #include "SubField/SubFieldIter.h"
50 #include "PETE/IpplExpressions.h"
51 #include <iostream>
52 
53 // forward declarations
54 template <class T, unsigned Dim, class S> class SubBareField;
55 template <class T, unsigned Dim, class S> class SubFieldIter;
56 template <class T, unsigned Dim, class S>
57 std::ostream& operator<<(std::ostream&,const SubBareField<T,Dim,S>&);
58 
59 
60 template <class T, unsigned Dim, class S>
61 class SubBareField : public PETE_Expr< SubBareField<T,Dim,S> > {
62 
63  friend class BareField<T,Dim>;
64 
65 public:
66  //# public typedefs
67  typedef T T_t;
68  typedef S Index_t;
70 
71  //# public enumerations
72  enum { Dim_u = Dim };
73 
74  // Return the beginning and end iterators for this class.
75  iterator begin() const;
76  iterator end() const;
77 
78  //
79  // accessor functions
80  //
81 
82  // return the 'domain', that is, the information which subsets the field
83  const S& getDomain() const { return MyDomain; }
84 
85  // fill in the second argument with the data for the 'bounding box' of
86  // the domain. This could be the whole field domain, a single point, or
87  // perhaps just a subset of the whole domain.
88  void makeNDIndex(NDIndex<Dim> &i) { iterator::makeNDIndex(MyDomain, i); }
89 
90  // return a reference to the field we are subsetting
91  BareField<T,Dim>& getBareField() const { return A; }
92 
93  // Return a single value.
94  T get() { T r; get(r); return r; }
95  void get(T& r);
96 
97  // Return a typecode for the subset object
98  static int getSubsetType() { return iterator::getSubsetType(); }
99 
100  // check to make sure Dim == Brackets.
101  bool checkBrackets() const { return Brackets == Dim; }
102 
103  //
104  // bracket operators
105  //
106 
107  // bracket operator, which select subsets of the BareField.
108  //mwerks template<class S2>
109  //mwerks SubBareField<T,Dim,typename SubFieldTraits<T,Dim,S,S2>::Return_t>
110  //mwerks operator[](const S2&);
112  // bracket operators, which select subsets of the BareField. This
113  // further subsets from the current SubBareField based on the type of
114  // input subset object.
115  template<class S2>
117  operator[](const S2& s) {
118  // create a new instance of the resulting subset object
119  typename SubFieldTraits<T,Dim,S,S2>::Return_t newdomain;
120 
121 
122 
123  // make sure we can subset by the number of dimensions requested, then
124  // combine the current subset value with the new one
126  if (checkAddBrackets(B)) {
128  Brackets += B;
129  }
130 
131  // return a new SubBareField
132  return SubBareField<T,Dim,
133  typename SubFieldTraits<T,Dim,S,S2>::Return_t>(A,newdomain);
134  }
135 
136 
137  //
138  // assignment operators
139  //
140 
141  // assignment of another SubBareField
143 
144  // assignment of a scalar
146 
147  // assignment of an arbitrary expression
148  //mwerks template<class B>
149  //mwerks SubBareField<T,Dim,S>& operator=(const PETE_Expr<B> &);
151  // assignment of an arbitrary expression
152  template<class B>
155 
156 
157  assign(*this, b);
158  return *this;
159  }
160 
161 
162  //
163  // I/O
164  //
165 
166  void write(std::ostream&);
167 
168  //
169  // PETE interface
170  //
171 
172  enum { IsExpr = 1 };
174  iterator MakeExpression() const { return begin(); }
175 
176  // Pass operator() down to each element of type T.
177  // Could also build versions with 2 or more arguments...
178  // Without member templates we are restricted to passing an integer down.
180  checkBrackets();
181  typedef PETE_TUTree<OpParens<int>, iterator> Elem_t;
182  return Elem_t(arg, begin());
183  }
185  checkBrackets();
187  return Elem_t(std::pair<int,int>(a1,a2), begin());
188  }
189 
190 protected:
191  // the field we are subsetting
193 
194  // the 'domain', that is, the information which subsets the field
196 
197  // the current number of dimensions we have indexed via bracket operators.
198  // An expression can only be carried out if the number of brackets == Dim.
199  unsigned int Brackets;
200 
201  // check to see if it is ok to add the given number of brackets to our
202  // current number
203  bool checkAddBrackets(unsigned int);
204 
205 public:
206  // the class constructor, used by BareField or SubBareField to make a new one
207  //mwerks template<class S2>
208  //mwerks SubBareField(BareField<T,Dim>&, const S2&);
210  // Make the constructor private so that only this class and it's friends
211  // can construct them.
212  template<class S2>
213  SubBareField(BareField<T,Dim>& f, const S2& s) : A(f) {
214 
215 
216 
217  // initialize the subset object, to a state where it can be combined
218  // with the given input data. Then, put in data from given subset object.
220  }
221 
222 };
223 
224 // I/O
225 
226 // write a subfield to the given ostream
227 template<class T, unsigned int Dim, class S>
228 inline
229 std::ostream& operator<<(std::ostream& o, const SubBareField<T,Dim,S>& s) {
230 
231 
232  SubBareField<T,Dim,S>& ncs = const_cast<SubBareField<T,Dim,S>&>(s);
233  ncs.write(o);
234  return o;
235 }
236 
237 
238 #include "SubField/SubBareField.hpp"
239 
240 #endif // SUB_BARE_FIELD_H
241 
242 /***************************************************************************
243  * $RCSfile: SubBareField.h,v $ $Author: adelmann $
244  * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:33 $
245  * IPPL_VERSION_ID: $Id: SubBareField.h,v 1.1.1.1 2003/01/23 07:40:33 adelmann Exp $
246  ***************************************************************************/
BareField< T, Dim > & getBareField() const
Definition: SubBareField.h:91
Definition: PETE.h:80
Definition: rbendmap.h:8
SubFieldIter< T, Dim, S > iterator
Definition: SubBareField.h:69
unsigned int Brackets
Definition: SubBareField.h:199
bool checkAddBrackets(unsigned int)
void assign(const BareField< T, Dim > &a, RHS b, OP op, ExprTag< true >)
const S & getDomain() const
Definition: SubBareField.h:83
iterator PETE_Expr_t
Definition: SubBareField.h:173
SubBareField< T, Dim, typename SubFieldTraits< T, Dim, S, S2 >::Return_t > operator[](const S2 &s)
Definition: SubBareField.h:117
static int getSubsetType()
Definition: SubBareField.h:98
static int construct(S1 &, const S2 &, BareField< T, Dim > &)
bool checkBrackets() const
Definition: SubBareField.h:101
SubBareField< T, Dim, S > & operator=(const PETE_Expr< B > &b)
Definition: SubBareField.h:154
Definition: FFT.h:30
arg(a))
void write(std::ostream &)
static void combine(const S1 &, const S2 &, S3 &, unsigned int &, BareField< T, Dim > &)
iterator end() const
void makeNDIndex(NDIndex< Dim > &i)
Definition: SubBareField.h:88
iterator begin() const
SubBareField< T, Dim, S > & operator=(const SubBareField< T, Dim, S > &)
SubBareField(BareField< T, Dim > &f, const S2 &s)
Definition: SubBareField.h:213
PETE_TUTree< OpParens< int >, iterator > operator()(int arg)
Definition: SubBareField.h:179
PETE_TUTree< OpParens< std::pair< int, int > >, iterator > operator()(int a1, int a2)
Definition: SubBareField.h:184
iterator MakeExpression() const
Definition: SubBareField.h:174
const unsigned Dim
BareField< T, Dim > & A
Definition: SubBareField.h:192