src/SubField/SubBareField.cpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /***************************************************************************
00003  *
00004  * The IPPL Framework
00005  * 
00006  * This program was prepared by PSI. 
00007  * All rights in the program are reserved by PSI.
00008  * Neither PSI nor the author(s)
00009  * makes any warranty, express or implied, or assumes any liability or
00010  * responsibility for the use of this software
00011  *
00012  * Visit http://www.acl.lanl.gov/POOMS for more details
00013  *
00014  ***************************************************************************/
00015 
00016 // -*- C++ -*-
00017 /***************************************************************************
00018  *
00019  * The IPPL Framework
00020  * 
00021  *
00022  * Visit http://people.web.psi.ch/adelmann/ for more details
00023  *
00024  ***************************************************************************/
00025 
00026 // include files
00027 #include "SubField/SubBareField.h"
00028 #include "SubField/SubFieldTraits.h"
00029 #include "SubField/SubFieldAssign.h"
00030 #include "Field/BareField.h"
00031 #include "Field/LField.h"
00032 #include "Utility/IpplInfo.h"
00033 #include "Utility/PAssert.h"
00034 #include "Profile/Profiler.h"
00035 
00036 
00038 // check to see if it is ok to add the given number of brackets to our
00039 // current number
00040 template<class T, unsigned int Dim, class S>
00041 bool SubBareField<T,Dim,S>::checkAddBrackets(unsigned int B) {
00042   TAU_TYPE_STRING(taustr, CT(*this) + "bool (unsigned int)" );
00043   TAU_PROFILE("SubBareField::checkAddBrackets()", taustr, TAU_SUBFIELD);
00044 
00045   if ((Brackets + B) > Dim) {
00046     ERRORMSG("Too many dimensions indexed in SubBareField: ");
00047     ERRORMSG((Brackets + B) << " > " << Dim << endl);
00048     return false;
00049   }
00050   return true;
00051 }
00052 
00053 
00054 
00056 // assignment of another SubBareField
00057 template<class T, unsigned int Dim, class S>
00058 SubBareField<T,Dim,S>&
00059 SubBareField<T,Dim,S>::operator=(const SubBareField<T,Dim,S> &t) {
00060   TAU_TYPE_STRING(taustr, CT(*this) + " (" + CT(t) + " )" );
00061   TAU_PROFILE("SubBareField::operator=()", taustr, TAU_SUBFIELD | TAU_ASSIGN);
00062   assign(*this, t);
00063   return *this;
00064 }
00065 
00066 
00068 // assignment of a scalar
00069 template<class T, unsigned int Dim, class S>
00070 SubBareField<T,Dim,S>&
00071 SubBareField<T,Dim,S>::operator=(T t) {
00072   TAU_TYPE_STRING(taustr, CT(*this) + " (" + CT(t) + " )" );
00073   TAU_PROFILE("SubBareField::operator=()", taustr, TAU_SUBFIELD | TAU_ASSIGN);
00074   assign(*this, t);
00075   return *this;
00076 }
00077 
00078 
00080 // get a single value and return it in the given storage.  Whichever
00081 // node owns the value must broadcast it to the other nodes.
00082 template<class T, unsigned int Dim, class S>
00083 void SubBareField<T,Dim,S>::get(T& r) {
00084   TAU_TYPE_STRING(taustr, CT(*this) + "void (" + CT(r) + " )" );
00085   TAU_PROFILE("SubBareField::get()", taustr, TAU_SUBFIELD );
00086   // make sure we have a properly bracketed object
00087   PAssert(checkBrackets());
00088 
00089   // construct an NDIndex which refers to the single point.
00090   NDIndex<Dim> Indexes;
00091   iterator::makeNDIndex(MyDomain, Indexes);
00092 
00093   // get the value from the BareField
00094   A.get(Indexes, r);
00095 }
00096 
00097 
00099 // Return the beginning and end iterators for this class.
00100 template<class T, unsigned int Dim, class S>
00101 typename SubBareField<T,Dim,S>::iterator SubBareField<T,Dim,S>::begin() const {
00102   TAU_TYPE_STRING(taustr, CT(*this) + "::iterator ()" );
00103   TAU_PROFILE("SubBareField::begin()", taustr, TAU_SUBFIELD );
00104 
00105   return iterator(A, A.begin_if(), MyDomain, Brackets);
00106 }
00107 
00108 template<class T, unsigned int Dim, class S>
00109 typename SubBareField<T,Dim,S>::iterator SubBareField<T,Dim,S>::end() const {
00110   TAU_TYPE_STRING(taustr, CT(*this) + "::iterator ()" );
00111   TAU_PROFILE("SubBareField::end()", taustr, TAU_SUBFIELD );
00112 
00113   return iterator(A, A.end_if(), MyDomain, Brackets);
00114 }
00115 
00116 
00118 // write this subfield to the given ostream
00119 template<class T, unsigned int Dim, class S>
00120 void SubBareField<T,Dim,S>::write(ostream& o) {
00121   TAU_TYPE_STRING(taustr, CT(*this) + "void (ostream)" );
00122   TAU_PROFILE("SubBareField::write()", taustr, TAU_SUBFIELD | TAU_IO );
00123   // make sure we have the right number of brackets
00124   PAssert(Dim == Brackets);
00125 
00126   // determine the range of values which we need to print
00127   NDIndex<Dim> testIndex;
00128   iterator::makeNDIndex(MyDomain, testIndex);
00129 
00130   // finally, print out the subfield
00131   o << A[testIndex];
00132 }
00133 
00134 
00136 
00137 /***************************************************************************
00138  * $RCSfile: SubBareField.cpp,v $   $Author: adelmann $
00139  * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:33 $
00140  * IPPL_VERSION_ID: $Id: SubBareField.cpp,v 1.1.1.1 2003/01/23 07:40:33 adelmann Exp $ 
00141  ***************************************************************************/

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