src/SubField/SubField.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 SUB_FIELD_H
00012 #define SUB_FIELD_H
00013 
00014 // include files
00015 #include "SubField/SubBareField.h"
00016 #include "SubField/SubFieldTraits.h"
00017 
00018 
00019 // forward declarations
00020 template <class T> class PETE_Expr;
00021 template<class T, unsigned D, class M, class C> class Field;
00022 
00023 
00024 /***************************************************************************
00025   SubField - represent a view on a given Field, referring to a
00026   subset of the original field data.  This is meant as an eventual
00027   replacement for IndexedField.  It is the same as SubBareField, but also
00028   includes the Mesh and Centering template parameters.
00029  ***************************************************************************/
00030 
00031 template<class T, unsigned int Dim, class M, class C, class S>
00032 class SubField : public SubBareField<T,Dim,S> {
00033 
00034   friend class Field<T,Dim,M,C>;
00035 
00036 public:
00037   //
00038   // accessor functions
00039   //
00040 
00041   // return a reference to the field we are subsetting
00042   Field<T,Dim,M,C>&       getField() const { return F; }
00043 
00044   //
00045   // bracket operators
00046   //
00047 
00048   // bracket operator, which select subsets of the BareField.
00049   //mwerks template<class S2>
00050   //mwerks SubField<T,Dim,M,C,typename SubFieldTraits<T,Dim,S,S2>::Return_t>
00051   //mwerks  operator[](const S2&);
00053   // bracket operators, which select subsets of the Field.  This
00054   // further subsets from the current SubField based on the type of
00055   // input subset object.
00056   template<class S2>
00057   SubField<T,Dim,M,C,typename SubFieldTraits<T,Dim,S,S2>::Return_t>
00058   operator[](const S2& s) {
00059     // create a new instance of the resulting subset object
00060     typename SubFieldTraits<T,Dim,S,S2>::Return_t newdomain;
00061     TAU_TYPE_STRING(taustr, CT(newdomain) + " (" + CT(s) + " )" );
00062     TAU_PROFILE("SubBareField::operator[]()", taustr, TAU_SUBFIELD);
00063 
00064     // make sure we can subset by the number of dimensions requested, then
00065     // combine the current subset value with the new one
00066     int B = SubFieldTraits<T,Dim,S,S2>::Brackets_u;
00067     if (this->checkAddBrackets(B)) {
00068         SubFieldTraits<T,Dim,S,S2>::combine(
00069             SubBareField<T,Dim,S>::MyDomain, 
00070             s, 
00071             newdomain, 
00072             SubBareField<T,Dim,S>::Brackets, 
00073             SubBareField<T,Dim,S>::A);
00074         SubBareField<T,Dim,S>::Brackets += B;
00075     }
00076 
00077     // return a new SubField
00078     return SubField<T,Dim,M,C,
00079       typename SubFieldTraits<T,Dim,S,S2>::Return_t>(F, newdomain);
00080   }
00081 
00082 
00083   //
00084   // assignment operators
00085   //
00086 
00087   // assignment of a scalar
00088   void operator=(T);
00089 
00090   // assignment of another subfield
00091   SubField<T,Dim,M,C,S>& operator=(const SubField<T,Dim,M,C,S> &);
00092 
00093   // assignment of an arbitrary expression
00094   //mwerks  template<class B>
00095   //mwerks  SubField<T,Dim,M,C,S>& operator=(const PETE_Expr<B> &);
00097   // assignment of an arbitrary expression
00098   template<class B>
00099   SubField<T,Dim,M,C,S>&
00100   operator=(const PETE_Expr<B> &b) {
00101     TAU_TYPE_STRING(taustr, CT(*this) +  " (" + CT(b) + " )" );
00102     TAU_PROFILE("SubBareField::operator=()", taustr, 
00103                 TAU_SUBFIELD | TAU_ASSIGN);
00104     assign(*this, b);
00105     return *this;
00106   }
00107 
00108 
00109 
00110 protected: 
00111   // the field we are subsetting
00112   Field<T,Dim,M,C>& F;
00113 
00114 public:
00115 
00116   // Make the constructor private so that only this class and it's friends
00117   // can construct them.
00118   //mwerks  template<class S2>
00119   //mwerks  SubField(Field<T,Dim,M,C>&, const S2&);
00121   // Make the constructor private so that only this class and it's friends
00122   // can construct them.
00123   template<class S2>
00124   SubField(Field<T,Dim,M,C>& f, const S2& s)
00125     : SubBareField<T,Dim,S>(f, s), F(f) { }
00126 
00127 };
00128 
00129 #include "SubField/SubField.cpp"
00130 
00131 #endif // SUB_FIELD_H
00132 
00133 /***************************************************************************
00134  * $RCSfile: SubField.h,v $   $Author: adelmann $
00135  * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:33 $
00136  * IPPL_VERSION_ID: $Id: SubField.h,v 1.1.1.1 2003/01/23 07:40:33 adelmann Exp $ 
00137  ***************************************************************************/

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