src/SubParticle/SubParticleAttrib.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 "SubParticle/SubParticleAttrib.h"
00028 #include "Particle/ParticleAttrib.h"
00029 #include "Utility/IpplInfo.h"
00030 #include "Utility/PAssert.h"
00031 #include "Profile/Profiler.h"
00032 
00033 
00035 // assignment of another SubParticleAttrib
00036 template<class PA, class T, unsigned Dim>
00037 SubParticleAttrib<PA,T,Dim>&
00038 SubParticleAttrib<PA,T,Dim>::operator=(const SubParticleAttrib<PA,T,Dim> &t) {
00039   TAU_TYPE_STRING(taustr, CT(*this) + " (" + CT(t) + " )" );
00040   TAU_PROFILE("SubParticleAttrib::operator=()", taustr,
00041               TAU_SUBFIELD | TAU_ASSIGN);
00042 
00043   // just do a regular attribute assignment
00044   //A = t.getAttrib();
00045   assign(*this, t);
00046   return *this;
00047 }
00048 
00049 
00051 // assignment of a scalar
00052 template<class PA, class T, unsigned Dim>
00053 SubParticleAttrib<PA,T,Dim>&
00054 SubParticleAttrib<PA,T,Dim>::operator=(T t) {
00055   TAU_TYPE_STRING(taustr, CT(*this) + " (" + CT(t) + " )" );
00056   TAU_PROFILE("SubParticleAttrib::operator=()", taustr,
00057               TAU_SUBFIELD | TAU_ASSIGN);
00058 
00059   // make a PETE_Scalar so that we can do a regular assignment
00060   //A = t;
00061   PETE_Scalar<T> scalar(t);
00062   assign(*this, scalar);
00063   return *this;
00064 }
00065 
00066 
00067 
00068 
00070 // Return the beginning and end iterators for this class.
00071 template<class PA, class T, unsigned Dim>
00072 typename SubParticleAttrib<PA,T,Dim>::iterator
00073 SubParticleAttrib<PA,T,Dim>::begin() const {
00074   TAU_TYPE_STRING(taustr, CT(*this) + "::iterator ()" );
00075   TAU_PROFILE("SubParticleAttrib::begin()", taustr, TAU_SUBFIELD );
00076 
00077   PA &p = const_cast<PA &>(A);
00078   return iterator(p, MyDomain.begin_iv(), 0, MyDomain);
00079 }
00080 
00081 template<class PA, class T, unsigned Dim>
00082 typename SubParticleAttrib<PA,T,Dim>::iterator
00083 SubParticleAttrib<PA,T,Dim>::end() const {
00084   TAU_TYPE_STRING(taustr, CT(*this) + "::iterator ()" );
00085   TAU_PROFILE("SubParticleAttrib::end()", taustr, TAU_SUBFIELD );
00086 
00087   PA &p = const_cast<PA &>(A);
00088   return iterator(p, MyDomain.end_iv(), MyDomain.size(), MyDomain);
00089 }
00090 
00092 // Make sure the LHS ParticleAttrib has the proper length.  It should
00093 // have the same length as the number of LOCAL sparse index points.
00094 // If it does not, we adjust the length.  Return size of result.
00095 template<class PA, class T, unsigned Dim>
00096 int SubParticleAttrib<PA,T,Dim>::adjustSize() {
00097   TAU_TYPE_STRING(taustr, CT(*this) + " ()" );
00098   TAU_PROFILE("SubParticleAttrib::adjustSize()", taustr, TAU_SUBFIELD);
00099 
00100   // get length of sparse index list local pieces
00101   int points = MyDomain.size();
00102   int currpoints = A.size();
00103 
00104   // adjust length of attrib
00105   if (points < currpoints)
00106     A.destroy((currpoints - points), points);
00107   else if (points > currpoints)
00108     A.create(points - currpoints);
00109 
00110   return points;
00111 }
00112 
00113 
00115 // write out the contents of this SubParticleAttrib to the given ostream.
00116 // This not only prints out the values of the attribute, but also prints
00117 // out the local sindex points
00118 template<class PA, class T, unsigned Dim>
00119 void SubParticleAttrib<PA,T,Dim>::write(ostream &o) const {
00120   TAU_TYPE_STRING(taustr, CT(*this) + " (" + CT(o) + " )" );
00121   TAU_PROFILE("SubParticleAttrib::write()", taustr, TAU_SUBFIELD );
00122 
00123   // make sure the sizes match
00124   PInsist(A.size() == MyDomain.size(),
00125           "SubParticleAttrib::write must have an attrib with enough elements");
00126 
00127   // loop over all the local lfields, printing out particles as we go
00128   int i = 0;
00129   typename Index_t::const_iterator_iv lfi = MyDomain.begin_iv();
00130   for ( ; lfi != MyDomain.end_iv(); ++lfi) {
00131     // for each lfield, print out particles
00132     typename Index_t::const_iterator_indx lsi = (*lfi)->begin();
00133     for ( ; lsi != (*lfi)->end(); ++lsi)
00134       o << *lsi + MyDomain.getOffset() << " ==> " << A[i++] << endl;
00135   }
00136 
00137 }
00138 
00139 
00140 /***************************************************************************
00141  * $RCSfile: SubParticleAttrib.cpp,v $   $Author: adelmann $
00142  * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:33 $
00143  * IPPL_VERSION_ID: $Id: SubParticleAttrib.cpp,v 1.1.1.1 2003/01/23 07:40:33 adelmann Exp $ 
00144  ***************************************************************************/

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