#ifndef __VEC_H #define __VEC_H /*! \file vec.hh \brief static vector \date 30 April 2010 \author Clemens Pechstein Institute of Computational Mathematics Johannes Kepler University Linz, Austria Tutorials -- Numerical methods for elliptic PDEs summer semester 2010 */ #include #include #include using namespace std; template class Vec { public: /// default constructor: set vector to zero Vec() { for (int i=0; i and Vec<3> Vec(T v0, T v1, T v2=0) { data_[0] = v0; data_[1] = v1; if (Size == 3) data_[2] = v2; } /// destructor ~Vec() { ; } /// copy constructor Vec (const Vec& v) { for (int i=0; i= 2 void set (T v0, T v1, T v2=0) { data_[0] = v0; data_[1] = v1; if (Size > 2) data_[2] = v2; } /// increment Vec& operator+= (const Vec& v) { for (int i=0; i Vec operator+ (const Vec& v, const Vec& w) { Vec res(v); // copy res += w; return res; } /// vector subtraction template Vec operator- (const Vec& v, const Vec& w) { Vec res(v); // copy res -= w; return res; } /// scale vector template Vec operator* (const T factor, const Vec& v) { Vec res(v); res *= factor; return res; } /// Euclidean inner product template T inner_product (const Vec& v, const Vec& w) { T sum = 0; for (int i=0; i cross_product (const Vec<3>& a, const Vec<3>& b) { Vec<3> c; c[0] = a[1] * b[2] - a[2] * b[1]; c[1] = a[2] * b[0] - a[0] * b[2]; c[2] = a[0] * b[1] - a[1] * b[0]; return c; } /// Euclidean norm template double l2norm (const Vec& v) { double norm=0; for (int i=0; i std::ostream& operator<< (std::ostream& os, const Vec& v) { v.print (os); return os; } typedef Vec<2, double> Point2D; #endif // __VEC_H