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