00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef PHX_ENTITY_TEMPLATES
00033 #define PHX_ENTITY_TEMPLATES
00034
00035 #include "Phalanx_ConfigDefs.hpp"
00036 #include "Sacado.hpp"
00037
00038
00039
00040
00041
00042 template <typename T> class MyVector {
00043 T val[3];
00044 public:
00045 MyVector() { }
00046 MyVector(const T& value)
00047 {
00048 this->init(value);
00049 }
00050 MyVector(const T& v0, const T& v1, const T& v2)
00051 {
00052 val[0] = v0;
00053 val[1] = v1;
00054 val[2] = v2;
00055 }
00056 void init(const T& value)
00057 {
00058 for (std::size_t i=0; i < 3; ++i)
00059 val[i] = value;
00060 }
00061 T& operator[](std::size_t i)
00062 {
00063 return val[i];
00064 }
00065 const T& operator[](std::size_t i) const
00066 {
00067 return val[i];
00068 }
00069 MyVector<T> operator+()
00070 {
00071 return *this;
00072 }
00073 MyVector<T> operator-()
00074 {
00075 return MyVector<T>(-val[0], -val[1], -val[2]);
00076 }
00077 MyVector<T>& operator+=(const MyVector<T>& a)
00078 {
00079 for (std::size_t i=0; i < 3; ++i)
00080 val[i] += a[i];
00081 return *this;
00082 }
00083 MyVector<T>& operator-=(const MyVector<T>& a)
00084 {
00085 for (std::size_t i=0; i < 3; ++i)
00086 val[i] -= a[i];
00087 return *this;
00088 }
00089 MyVector<T>& operator*=(const MyVector<T>& a)
00090 {
00091 for (std::size_t i=0; i < 3; ++i)
00092 val[i] *= a.val[i];
00093 return *this;
00094 }
00095 MyVector<T>& operator/=(const MyVector<T>& a)
00096 {
00097 for (std::size_t i=0; i < 3; ++i)
00098 val[i] /= a.val[i];
00099 return *this;
00100 }
00101 void print(std::ostream& os) const
00102 {
00103 for (std::size_t i=0; i < 3; ++i)
00104 os << "MyVector[" << i << "] = " << val[i] << std::endl;
00105 }
00106
00107 };
00108
00109
00110 template <class T, class U>
00111 inline MyVector< typename Sacado::Promote<T,U>::type>
00112 operator*(const MyVector<T>& v, const U& sc)
00113 {
00114 typedef typename Sacado::Promote<T,U>::type ValueT;
00115 return MyVector<ValueT>(v[0] * sc, v[1] * sc, v[2] * sc);
00116 }
00117
00118 template <class T, class U>
00119 inline MyVector< typename Sacado::Promote<T,U>::type>
00120 operator*(const T& sc, const MyVector<U>& u)
00121 {
00122 typedef typename Sacado::Promote<T,U>::type ValueT;
00123 return MyVector<ValueT>(u[0] * sc, u[1] * sc, u[2] * sc);
00124 }
00125
00126
00127 template <class T, class U>
00128 inline MyVector< typename Sacado::Promote<T,U>::type>
00129 operator*(const MyVector<T>& v , const MyVector<U>& u)
00130 {
00131 typedef typename Sacado::Promote<T,U>::type ValueT;
00132 return MyVector<ValueT>(v[0] * u[0], v[1] * u[1], v[2] * u[2]);
00133 }
00134
00135 template <class T, class U>
00136 inline MyVector< typename Sacado::Promote<T,U>::type>
00137 operator/(const MyVector<T>& v , const MyVector<U>& u)
00138 {
00139 typedef typename Sacado::Promote<T,U>::type ValueT;
00140 return MyVector<ValueT>(v[0] / u[0], v[1] / u[1], v[2] / u[2]);
00141 }
00142
00143 template <class T, class U>
00144 inline MyVector< typename Sacado::Promote<T,U>::type>
00145 operator+(const MyVector<T>& v , const MyVector<U>& u)
00146 {
00147 typedef typename Sacado::Promote<T,U>::type ValueT;
00148 return MyVector<ValueT>(v[0] + u[0], v[1] + u[1], v[2] + u[2]);
00149 }
00150
00151 template <class T, class U>
00152 inline MyVector< typename Sacado::Promote<T,U>::type>
00153 operator-(const MyVector<T>& v , const MyVector<U>& u)
00154 {
00155 typedef typename Sacado::Promote<T,U>::type ValueT;
00156 return MyVector<ValueT>(v[0] - u[0], v[1] - u[1], v[2] - u[2]);
00157 }
00158
00159
00160 template <typename T>
00161 std::ostream& operator<<(std::ostream& os, const MyVector<T>& v)
00162 {
00163 v.print(os);
00164 return os;
00165 }
00166
00167
00168
00169
00170 template <typename T> class MyTensor {
00171 T val[9];
00172 public:
00173 void init(const T& value)
00174 {
00175 for (std::size_t i=0; i < 9; ++i)
00176 val[i] = value;
00177 }
00178 T& operator[](std::size_t i)
00179 {
00180 return val[i];
00181 }
00182 MyTensor<T>& operator*(MyVector<T>& a)
00183 {
00184 for (std::size_t i=0; i < 9; ++i)
00185 val[i] = val[i] * a[i];
00186 return *this;
00187 }
00188 void print()
00189 {
00190 for (std::size_t i=0; i < 9; ++i)
00191 std::cout << "MyTensor[" << i << "] = " << val[i] << std::endl;
00192 }
00193 };
00194
00195
00196
00197
00198 #endif