33 #ifndef OOMPH_VECTOR_HEADER 34 #define OOMPH_VECTOR_HEADER 38 #include <oomph-lib-config.h> 63 class Vector:
public std::vector<_Tp>
89 if (__n>=this->size())
92 std::ostringstream error_message;
95 error_message <<
"Range Error: Vector is empty but you requested entry " 100 error_message <<
"Range Error: " << __n
101 <<
" is not in the range (0," 102 << this->size()-1 <<
")";
107 OOMPH_CURRENT_FUNCTION,
108 OOMPH_EXCEPTION_LOCATION);
111 return std::vector<_Tp>::operator[](__n);
115 return std::vector<_Tp>::operator[](__n);
124 if (__n>=this->size())
127 std::ostringstream error_message;
128 error_message <<
"Range Error: " << __n
129 <<
" is not in the range (0," 130 << this->size()-1 <<
")";
134 OOMPH_CURRENT_FUNCTION,
135 OOMPH_EXCEPTION_LOCATION);
138 return std::vector<_Tp>::operator[](__n);
142 return std::vector<_Tp>::operator[](__n);
157 explicit Vector(size_type __n) :
std::vector<_Tp>(__n) { }
161 Vector(size_type __n,
const _Tp& __value) :
std::vector<_Tp>(__n,__value) {}
173 for(
typename std::vector<_Tp>::iterator it = std::vector<_Tp>::begin();
174 it != std::vector<_Tp>::end(); it++)
180 #ifdef RANGE_CHECKING 204 class Vector<bool>:
private std::vector<bool>
224 Vector(
const double& dont_call_this_constructor)
227 throw OomphLibError(
"Please use vector<bool> instead of Vector<bool>",
228 OOMPH_CURRENT_FUNCTION,
229 OOMPH_EXCEPTION_LOCATION);
241 explicit Vector(size_type __n) :
std::vector<bool>(__n) { }
245 Vector(size_type __n,
const bool& __value) :
std::vector<bool>(__n,__value) {}
253 for(std::vector<bool>::iterator it = std::vector<bool>::begin();
254 it != std::vector<bool>::end(); it++)
266 namespace VectorHelpers
273 if (a.size() != b.size())
275 std::ostringstream err;
276 err <<
"Vectors must be the same length." 277 <<
"len(a) = " << a.size() <<
", " 278 <<
"len(b) = " << b.size() <<
".";
281 OOMPH_EXCEPTION_LOCATION);
293 for(
unsigned i=0, ni=a.size();
i<ni;
i++)
303 return(std::sqrt(
dot(a,a)));
311 return std::acos(
dot(a,b) / std::sqrt(
dot(a,a) *
dot(b,b)));
321 if((A.size() != 3) || (B.size() != 3) || (C.size() !=3))
323 std::ostringstream err;
324 err <<
"Cross product only defined for vectors of length 3.\n" 325 <<
"len(a) = " << A.size() <<
", " 326 <<
"len(b) = " << B.size() <<
", " 327 <<
"len(c) = " << C.size() <<
".";
330 OOMPH_EXCEPTION_LOCATION);
334 C[0] = A[1]*B[2] - A[2]*B[1];
335 C[1] = A[2]*B[0] - A[0]*B[2];
336 C[2] = A[0]*B[1] - A[1]*B[0];
Vector(size_type __n, const bool &__value)
A constructor that creates a vector of size __n and initialises every entry to __value.
const value_type & const_reference
Typedef to make the constructors look a bit cleaner.
_Tp value_type
Typedef to make the constructors look a bit cleaner.
Vector()
Construct an empty vector.
size_t size_type
Typedef to make the constructors look a bit cleaner.
reference error_checked_access(size_type __n)
Vector(size_type __n)
A constructor that creates a vector of size __n. Note the use of explicit for "strong" type checking...
void check_lengths_match(const Vector< double > &a, const Vector< double > &b)
Check the lengths if two Vectors are the same length.
const_reference operator[](size_type __n) const
Overloaded, range-checking, bracket access operator (const version)
value_type & reference
Typedef to make the constructors look a bit cleaner.
const_reference error_checked_access(size_type __n) const
void initialise(const bool &__value)
Iterate over all values and set to the desired value.
reference operator[](size_type __n)
double angle(const Vector< double > &a, const Vector< double > &b)
Get the angle between two vector.
Vector(const Vector< bool > &__x)
Copy constructor.
double magnitude(const Vector< double > &a)
Get the magnitude of a vector.
bool value_type
Typedef to make the constructors look a bit cleaner.
void output(std::ostream &outfile)
Output with default number of plot points.
void initialise(const _Tp &__value)
Iterate over all values and set to the desired value.
Vector< double > cross(const Vector< double > &A, const Vector< double > &B)
Cross product using "proper" output (move semantics means this is ok This calls the other cross(...
double dot(const Vector< double > &a, const Vector< double > &b)
Probably not always best/fastest because not optimised for dimension but useful...
size_t size_type
Typedef to make the constructors look a bit cleaner.
Vector(size_type __n)
A constructor that creates a vector of size __n. Note the use of explicit for "strong" type checking...
value_type & reference
Typedef to make the constructors look a bit cleaner.
Vector(const double &dont_call_this_constructor)
Dummy constructor to avoid compiler from warning about only-private constructors. ...
Vector()
Construct an empty vector.
A Vector of bools cannot be created because the is no compiler-independent implementation of the bit ...
Vector(const Vector< _Tp > &__x)
Copy constructor.
const value_type & const_reference
Typedef to make the constructors look a bit cleaner.
Vector(size_type __n, const _Tp &__value)
A constructor that creates a vector of size __n and initialises every entry to __value.