src/Field/Field.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /***************************************************************************
00003  *
00004  * The IPPL Framework
00005  * 
00006  *
00007  * Visit http://people.web.psi.ch/adelmann/ for more details
00008  *
00009  ***************************************************************************/
00010 
00011 #ifndef FIELD_H
00012 #define FIELD_H
00013 
00014 // include files
00015 #include "Field/BareField.h"
00016 #include "Field/FieldSpec.h"
00017 #include "Field/LField.h"
00018 #include "Field/BCond.h"
00019 #include "Field/ReductionLoc.h"
00020 #include "SubField/SubField.h"
00021 #include "DataSource/DataSource.h"
00022 #include "Meshes/UniformCartesian.h"
00023 
00024 // forward declarations
00025 template <class T, unsigned D, unsigned B, class M, class C> 
00026 class IndexedField;
00027 
00028 /***********************************************************************
00029       This is the user visible Field of type T.
00030       It doesn't even really do expression evaluation; that is
00031       handled with the templates in PETE.h
00032 ***********************************************************************/
00033 
00034 template<class T, unsigned Dim,
00035          class M=UniformCartesian<Dim,double>,
00036          class C=typename M::DefaultCentering >
00037 class Field : public BareField<T,Dim>, public DataSource {
00038 
00039   friend class BareFieldIterator<T,Dim>;
00040 
00041 public: 
00042   //# public typedefs
00043   typedef M Mesh_t;
00044   typedef C Centering_t;
00045   typedef BareField<T,Dim>                   Base_t;
00046   typedef FieldLayout<Dim>                   Layout_t;
00047   typedef BConds<T,Dim,M,C>                  bcond_container;
00048   typedef BCondBase<T,Dim,M,C>               bcond_value;
00049   typedef typename bcond_container::iterator bcond_iterator;
00050 
00051   // A default constructor, which should be used only if the user calls the
00052   // 'initialize' function before doing anything else.  There are no special
00053   // checks in the rest of the Field methods to check that the Field has
00054   // been properly initialized.
00055   Field();
00056 
00057   // Destroy the Field.
00058   virtual ~Field();
00059 
00060   // Create a new Field with a given layout and optional guard cells.
00061   // The default type of BCond lets you add new ones dynamically.
00062   // The makeMesh() global function is a way to allow for different types of
00063   // constructor arguments for different mesh types.
00064   Field(Layout_t &);
00065   Field(Layout_t &,const GuardCellSizes<Dim>&);
00066   Field(Layout_t &,const BConds<T,Dim,M,C>&);
00067   Field(Layout_t &,const GuardCellSizes<Dim>&,const BConds<T,Dim,M,C>&);
00068   Field(Layout_t &,const BConds<T,Dim,M,C>&,const GuardCellSizes<Dim>&);
00069   Field(FieldSpec<T,Dim,M,C>&);
00070 
00071   // Constructors including a Mesh object as argument:
00072   Field(Mesh_t&, Layout_t &);
00073   Field(Mesh_t&, Layout_t &, const GuardCellSizes<Dim>&);
00074   Field(Mesh_t&, Layout_t &, const BConds<T,Dim,M,C>&);
00075   Field(Mesh_t&, Layout_t &, const GuardCellSizes<Dim>&,
00076         const BConds<T,Dim,M,C>&);
00077   Field(Mesh_t&, Layout_t &, const BConds<T,Dim,M,C>&,
00078         const GuardCellSizes<Dim>&);
00079   Field(Mesh_t&, FieldSpec<T,Dim,M,C>&);
00080 
00081   // Initialize the Field, if it was constructed from the default constructor.
00082   // This should NOT be called if the Field was constructed by providing
00083   // a FieldLayout or FieldSpec
00084   void initialize(Layout_t &);
00085   void initialize(Layout_t &, const GuardCellSizes<Dim>&);
00086   void initialize(Layout_t &, const BConds<T,Dim,M,C>&);
00087   void initialize(Layout_t &, const GuardCellSizes<Dim>&,
00088                   const BConds<T,Dim,M,C>&);
00089   void initialize(Layout_t &, const BConds<T,Dim,M,C>&,
00090                   const GuardCellSizes<Dim>&);
00091   void initialize(FieldSpec<T,Dim,M,C>&);
00092 
00093   // Initialize the Field, also specifying a mesh
00094   void initialize(Mesh_t&, Layout_t &);
00095   void initialize(Mesh_t&, Layout_t &, const GuardCellSizes<Dim>&);
00096   void initialize(Mesh_t&, Layout_t &, const BConds<T,Dim,M,C>&);
00097   void initialize(Mesh_t&, Layout_t &, const GuardCellSizes<Dim>&,
00098                   const BConds<T,Dim,M,C>&);
00099   void initialize(Mesh_t&, Layout_t &, const BConds<T,Dim,M,C>&,
00100                   const GuardCellSizes<Dim>&);
00101   void initialize(Mesh_t&, FieldSpec<T,Dim,M,C>&);
00102 
00103   // Definitions for accessing boundary conditions.
00104   const bcond_value&     getBCond(int bc) const { return *(Bc[bc]); }
00105   bcond_value&           getBCond(int bc)       { return *(Bc[bc]); }
00106   const bcond_container& getBConds()      const { return Bc; }
00107   bcond_container&       getBConds()            { return Bc; }
00108   bcond_iterator         begin_BConds()         { return Bc.begin(); }
00109   bcond_iterator         end_BConds()           { return Bc.end(); }
00110 
00111   // Access to the mesh
00112   Mesh_t& get_mesh() const { return *mesh; }
00113 
00114   // When we apply a bracket it converts the type to IndexedField so
00115   // that we can check at compile time that we have the right number
00116   // of indexes and brackets.  There are a number of different types
00117   // which we can use to index a Field in order to get a reference to
00118   // a subset of that Field.
00119   IndexedField<T,Dim,1,M,C>   operator[](const Index&);
00120   IndexedField<T,Dim,1,M,C>   operator[](int);
00121   IndexedField<T,Dim,Dim,M,C> operator[](const NDIndex<Dim>&);
00122   SubField<T,Dim,M,C,SIndex<Dim> >  operator[](const SIndex<Dim>&);
00123 
00124   // Assignment from constants and other arrays.
00125   const Field<T,Dim,M,C>& operator=(T x) {
00126     assign(*this,x);
00127     return *this;
00128   }
00129 
00130   const Field<T,Dim,M,C>& operator=(const Field<T,Dim,M,C>& x) {
00131     assign(*this,x);
00132     return *this;
00133   }
00134 
00135   template<class X>
00136   const Field<T,Dim,M,C>& operator=(const BareField<X,Dim>& x) {
00137     assign(*this,x);
00138     return *this;
00139   }
00140 
00141   template<class B>
00142   const Field<T,Dim,M,C>& operator=(const PETE_Expr<B>& x) {
00143     assign(*this,x);
00144     return *this;
00145   }
00146 
00147   // If you make any modifications using an iterator, you must call this.
00148   void fillGuardCells(bool reallyFill = true) const;
00149 
00150   // I/O (special stuff not inherited from BareField):
00151   // Print out contents of Centering class
00152   void print_Centerings(ostream&);
00153 
00154   //
00155   // virtual functions for FieldLayoutUser's (and other UserList users)
00156   //
00157 
00158   // Repartition onto a new layout, or when the mesh changes
00159   virtual void Repartition(UserList *);
00160 
00161   // Tell this object that an object is being deleted
00162   virtual void notifyUserOfDelete(UserList *);
00163 
00164 protected:
00165   // a virtual function which is called by this base class to get a
00166   // specific instance of DataSourceObject based on the type of data
00167   // and the connection method (the argument to the call).
00168   virtual DataSourceObject *createDataSourceObject(const char *, DataConnect *,
00169                                                    int);
00170 
00171 private:
00172   // The boundary conditions.
00173   bcond_container Bc;
00174 
00175   // The Mesh object, and a flag indicating if we constructed it
00176   Mesh_t* mesh;
00177   bool WeOwnMesh;
00178 
00179   // store the given mesh object pointer, and the flag whether we own it or not.
00180   // if we own it, we must make sure to delete it when this Field is deleted.
00181   void store_mesh(Mesh_t*, bool);
00182 
00183   // delete the mesh object, if necessary; otherwise, just zero the pointer
00184   void delete_mesh();
00185 };
00186 
00187 #include "Field/Field.cpp"
00188 
00189 #endif // FIELD_H
00190 
00191 /***************************************************************************
00192  * $RCSfile: Field.h,v $   $Author: adelmann $
00193  * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:26 $
00194  * IPPL_VERSION_ID: $Id: Field.h,v 1.1.1.1 2003/01/23 07:40:26 adelmann Exp $ 
00195  ***************************************************************************/

Generated on Mon Jan 16 13:23:44 2006 for IPPL by  doxygen 1.4.6