OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
Field.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 FIELD_H
12 #define FIELD_H
13 
14 // include files
15 #include "Field/BareField.h"
16 #include "Field/FieldSpec.h"
17 #include "Field/LField.h"
18 #include "Field/BCond.h"
19 #include "Field/ReductionLoc.h"
20 #include "SubField/SubField.h"
21 #include "DataSource/DataSource.h"
23 
24 // forward declarations
25 template <class T, unsigned D, unsigned B, class M, class C>
27 
28 /***********************************************************************
29  This is the user visible Field of type T.
30  It doesn't even really do expression evaluation; that is
31  handled with the templates in PETE.h
32 ***********************************************************************/
33 
34 template<class T, unsigned Dim,
36  class C=typename M::DefaultCentering >
37 class Field : public BareField<T,Dim>, public DataSource {
38 
39  friend class BareFieldIterator<T,Dim>;
40 
41 public:
42  //# public typedefs
43  typedef M Mesh_t;
44  typedef C Centering_t;
50 
51  // A default constructor, which should be used only if the user calls the
52  // 'initialize' function before doing anything else. There are no special
53  // checks in the rest of the Field methods to check that the Field has
54  // been properly initialized.
55  Field();
56 
57  // Destroy the Field.
58  virtual ~Field();
59 
60  // Create a new Field with a given layout and optional guard cells.
61  // The default type of BCond lets you add new ones dynamically.
62  // The makeMesh() global function is a way to allow for different types of
63  // constructor arguments for different mesh types.
64  Field(Layout_t &);
70 
71  // Constructors including a Mesh object as argument:
72  Field(Mesh_t&, Layout_t &);
76  const BConds<T,Dim,M,C>&);
78  const GuardCellSizes<Dim>&);
80 
81  // Initialize the Field, if it was constructed from the default constructor.
82  // This should NOT be called if the Field was constructed by providing
83  // a FieldLayout or FieldSpec
84  void initialize(Layout_t &);
85  void initialize(Layout_t &, const GuardCellSizes<Dim>&);
86  void initialize(Layout_t &, const BConds<T,Dim,M,C>&);
88  const BConds<T,Dim,M,C>&);
89  void initialize(Layout_t &, const BConds<T,Dim,M,C>&,
90  const GuardCellSizes<Dim>&);
92 
93  // Initialize the Field, also specifying a mesh
94  void initialize(Mesh_t&, Layout_t &);
95  void initialize(Mesh_t&, Layout_t &, const bool); //UL: for pinned memory allocation
97  void initialize(Mesh_t&, Layout_t &, const BConds<T,Dim,M,C>&);
99  const BConds<T,Dim,M,C>&);
100  void initialize(Mesh_t&, Layout_t &, const BConds<T,Dim,M,C>&,
101  const GuardCellSizes<Dim>&);
103 
104  // Definitions for accessing boundary conditions.
105  const bcond_value& getBCond(int bc) const { return *(Bc[bc]); }
106  bcond_value& getBCond(int bc) { return *(Bc[bc]); }
107  const bcond_container& getBConds() const { return Bc; }
108  bcond_container& getBConds() { return Bc; }
110  bcond_iterator end_BConds() { return Bc.end(); }
111 
112  // Access to the mesh
113  Mesh_t& get_mesh() const { return *mesh; }
114 
115  // When we apply a bracket it converts the type to IndexedField so
116  // that we can check at compile time that we have the right number
117  // of indexes and brackets. There are a number of different types
118  // which we can use to index a Field in order to get a reference to
119  // a subset of that Field.
124 
125  // Assignment from constants and other arrays.
127  assign(*this,x);
128  return *this;
129  }
130 
132  assign(*this,x);
133  return *this;
134  }
135 
136  template<class X>
138  assign(*this,x);
139  return *this;
140  }
141 
142  template<class B>
144  assign(*this,x);
145  return *this;
146  }
147 
148  // If you make any modifications using an iterator, you must call this.
149  void fillGuardCells(bool reallyFill = true) const;
150 
151  // I/O (special stuff not inherited from BareField):
152  // Print out contents of Centering class
153  void print_Centerings(std::ostream&);
154 
155  //
156  // virtual functions for FieldLayoutUser's (and other UserList users)
157  //
158 
159  // Repartition onto a new layout, or when the mesh changes
160  virtual void Repartition(UserList *);
161 
162  // Tell this object that an object is being deleted
163  virtual void notifyUserOfDelete(UserList *);
164 
165 protected:
166  // a virtual function which is called by this base class to get a
167  // specific instance of DataSourceObject based on the type of data
168  // and the connection method (the argument to the call).
169  virtual DataSourceObject *createDataSourceObject(const char *, DataConnect *,
170  int);
171 
172 private:
173  // The boundary conditions.
175 
176  // The Mesh object, and a flag indicating if we constructed it
178  bool WeOwnMesh;
179 
180  // store the given mesh object pointer, and the flag whether we own it or not.
181  // if we own it, we must make sure to delete it when this Field is deleted.
182  void store_mesh(Mesh_t*, bool);
183 
184  // delete the mesh object, if necessary; otherwise, just zero the pointer
185  void delete_mesh();
186 };
187 
188 #include "Field/Field.hpp"
189 
190 #endif // FIELD_H
191 
192 /***************************************************************************
193  * $RCSfile: Field.h,v $ $Author: adelmann $
194  * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:26 $
195  * IPPL_VERSION_ID: $Id: Field.h,v 1.1.1.1 2003/01/23 07:40:26 adelmann Exp $
196  ***************************************************************************/
iterator begin()
Definition: vmap.h:125
virtual ~Field()
BareField< T, Dim > Base_t
Definition: Field.h:45
Definition: PETE.h:80
BConds< T, Dim, M, C > bcond_container
Definition: Field.h:47
Definition: rbendmap.h:8
C Centering_t
Definition: Field.h:44
Definition: SIndex.h:28
bcond_iterator end_BConds()
Definition: Field.h:110
virtual void Repartition(UserList *)
const Field< T, Dim, M, C > & operator=(const PETE_Expr< B > &x)
Definition: Field.h:143
const Field< T, Dim, M, C > & operator=(const BareField< X, Dim > &x)
Definition: Field.h:137
bcond_iterator begin_BConds()
Definition: Field.h:109
void assign(const BareField< T, Dim > &a, RHS b, OP op, ExprTag< true >)
BCondBase< T, Dim, M, C > bcond_value
Definition: Field.h:48
bool WeOwnMesh
Definition: Field.h:178
void fillGuardCells(bool reallyFill=true) const
Definition: Index.h:236
M Mesh_t
Definition: Field.h:43
bcond_value & getBCond(int bc)
Definition: Field.h:106
const bcond_container & getBConds() const
Definition: Field.h:107
bcond_container & getBConds()
Definition: Field.h:108
vmap< int, RefCountedP< BCondBase< int, D, M, C > > >::iterator iterator
Definition: BCond.h:240
bcond_container Bc
Definition: Field.h:174
void delete_mesh()
const Field< T, Dim, M, C > & operator=(T x)
Definition: Field.h:126
const bcond_value & getBCond(int bc) const
Definition: Field.h:105
Definition: FFT.h:30
bcond_container::iterator bcond_iterator
Definition: Field.h:49
const Field< T, Dim, M, C > & operator=(const Field< T, Dim, M, C > &x)
Definition: Field.h:131
void print_Centerings(std::ostream &)
FieldLayout< Dim > Layout_t
Definition: Field.h:46
void store_mesh(Mesh_t *, bool)
IndexedField< T, Dim, 1, M, C > operator[](const Index &)
void initialize(Layout_t &)
const unsigned Dim
Mesh_t & get_mesh() const
Definition: Field.h:113
Mesh_t * mesh
Definition: Field.h:177
virtual DataSourceObject * createDataSourceObject(const char *, DataConnect *, int)
virtual void notifyUserOfDelete(UserList *)
iterator end()
Definition: vmap.h:126