Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

src/AppTypes/GenVektor.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 
00012 #ifndef GEN_VEKTOR_H
00013 #define GEN_VEKTOR_H
00014 
00016 
00017 template<unsigned Dim, unsigned IDim>
00018 class UnitComponentVektor
00019 {
00020 private:
00021   // No actual data.
00022 public:
00023   // Allow access rather like a regular Vektor.
00024   bool operator[](const unsigned int &d) const { return (d==IDim); }
00025 };
00026 
00028 
00029 template<class T, unsigned Dim, unsigned IDim>
00030 class ComponentVektor
00031 {
00032 private:
00033   T Value;
00034 
00035 public:
00036   // Construct with or without a value.
00037   ComponentVektor() {}
00038   ComponentVektor(T value) : Value(value) {}
00039 
00040   // Allow access rather like a regular Vektor.
00041   T& operator[](const unsigned int &d) { return (d==IDim) ? Value : 0; }
00042   T  operator[](const unsigned int &d) const { return (d==IDim) ? Value : 0; }
00043 };
00044 
00046 
00047 // Dot product of a UnitComponentVektor with a regular Vektor.
00048 // The UnitComponentVektor just selects a value, no floating point ops.
00049 
00050 // In the first two it takes in a Vektor& and returns a T&.
00051 // That way this could be put on the left hand side like
00052 // dot(vec,zhat) = 1.0;
00053 
00054 template<class T, unsigned Dim, unsigned IDim>
00055 inline
00056 T& dot_ref(Vektor<T,Dim>& v, const UnitComponentVektor<Dim,IDim>&)
00057 {
00058   return v[IDim];
00059 }
00060 
00061 template<class T, unsigned Dim, unsigned IDim>
00062 inline
00063 T& dot_ref(const UnitComponentVektor<Dim,IDim>& , Vektor<T,Dim>& v)
00064 {
00065   return v[IDim];
00066 }
00067 
00068 // If the Vektor is const though, return by value so you
00069 // can't assign to it.
00070 
00071 template<class T, unsigned Dim, unsigned IDim>
00072 inline
00073 T dot(const Vektor<T,Dim>& v, const UnitComponentVektor<Dim,IDim>&)
00074 {
00075   return v[IDim];
00076 }
00077 
00078 template<class T, unsigned Dim, unsigned IDim>
00079 inline
00080 T dot(const UnitComponentVektor<Dim,IDim>& , const Vektor<T,Dim>& v)
00081 {
00082   return v[IDim];
00083 }
00084 
00086 
00087 //
00088 // These dot a regular Vektor with a ComponentVektor.
00089 // They just do one multipply.
00090 // The return by value of course.
00091 //
00092 
00093 template<class T, unsigned Dim, unsigned IDim>
00094 inline
00095 T dot(const Vektor<T,Dim>& v, const ComponentVektor<T,Dim,IDim>& c)
00096 {
00097   return v[IDim]*c[IDim];
00098 }
00099 
00100 template<class T, unsigned Dim, unsigned IDim>
00101 inline
00102 T dot(const ComponentVektor<T,Dim,IDim>& c, const Vektor<T,Dim>& v)
00103 {
00104   return v[IDim]*c[IDim];
00105 }
00106 
00107 
00108 #endif
00109 /***************************************************************************
00110  * $RCSfile: GenVektor.h,v $   $Author: adelmann $
00111  * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:24 $
00112  * IPPL_VERSION_ID: $Id: GenVektor.h,v 1.1.1.1 2003/01/23 07:40:24 adelmann Exp $ 
00113  ***************************************************************************/

Generated on Fri Nov 2 01:25:54 2007 for IPPL by doxygen 1.3.5