OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
GenVektor.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /***************************************************************************
3  *
4  * The IPPL Framework
5  *
6  *
7  * Visit http://people.web.psi.ch/adelmann/ for more details
8  *
9  ***************************************************************************/
10 
12 #ifndef GEN_VEKTOR_H
13 #define GEN_VEKTOR_H
14 
16 
17 template<unsigned Dim, unsigned IDim>
19 {
20 private:
21  // No actual data.
22 public:
23  // Allow access rather like a regular Vektor.
24  bool operator[](const unsigned int &d) const { return (d==IDim); }
25 };
26 
28 
29 template<class T, unsigned Dim, unsigned IDim>
31 {
32 private:
34 
35 public:
36  // Construct with or without a value.
38  ComponentVektor(T value) : Value(value) {}
39 
40  // Allow access rather like a regular Vektor.
41  T& operator[](const unsigned int &d) { return (d==IDim) ? Value : 0; }
42  T operator[](const unsigned int &d) const { return (d==IDim) ? Value : 0; }
43 };
44 
46 
47 // Dot product of a UnitComponentVektor with a regular Vektor.
48 // The UnitComponentVektor just selects a value, no floating point ops.
49 
50 // In the first two it takes in a Vektor& and returns a T&.
51 // That way this could be put on the left hand side like
52 // dot(vec,zhat) = 1.0;
53 
54 template<class T, unsigned Dim, unsigned IDim>
55 inline
57 {
58  return v[IDim];
59 }
60 
61 template<class T, unsigned Dim, unsigned IDim>
62 inline
64 {
65  return v[IDim];
66 }
67 
68 // If the Vektor is const though, return by value so you
69 // can't assign to it.
70 
71 template<class T, unsigned Dim, unsigned IDim>
72 inline
74 {
75  return v[IDim];
76 }
77 
78 template<class T, unsigned Dim, unsigned IDim>
79 inline
81 {
82  return v[IDim];
83 }
84 
86 
87 //
88 // These dot a regular Vektor with a ComponentVektor.
89 // They just do one multipply.
90 // The return by value of course.
91 //
92 
93 template<class T, unsigned Dim, unsigned IDim>
94 inline
96 {
97  return v[IDim]*c[IDim];
98 }
99 
100 template<class T, unsigned Dim, unsigned IDim>
101 inline
103 {
104  return v[IDim]*c[IDim];
105 }
106 
107 
108 #endif
109 /***************************************************************************
110  * $RCSfile: GenVektor.h,v $ $Author: adelmann $
111  * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:24 $
112  * IPPL_VERSION_ID: $Id: GenVektor.h,v 1.1.1.1 2003/01/23 07:40:24 adelmann Exp $
113  ***************************************************************************/
T & dot_ref(Vektor< T, Dim > &v, const UnitComponentVektor< Dim, IDim > &)
Definition: GenVektor.h:56
Definition: rbendmap.h:8
The VALUE command.
Definition: Value.h:28
bool operator[](const unsigned int &d) const
Definition: GenVektor.h:24
T operator[](const unsigned int &d) const
Definition: GenVektor.h:42
double dot(const Vector3D &lhs, const Vector3D &rhs)
Vector dot product.
Definition: Vector3D.cpp:118
constexpr double c
The velocity of light in m/s.
Definition: Physics.h:52
T & operator[](const unsigned int &d)
Definition: GenVektor.h:41
ComponentVektor(T value)
Definition: GenVektor.h:38