29 #ifndef OOMPH_VECTOR_HEADER
30 #define OOMPH_VECTOR_HEADER
34 #include <oomph-lib-config.h>
57 class Vector :
public std::vector<_Tp>
80 if (__n >= this->size())
83 std::ostringstream error_message;
84 if (this->size() == 0)
87 <<
"Range Error: Vector is empty but you requested entry " << __n;
91 error_message <<
"Range Error: " << __n <<
" is not in the range (0,"
92 << this->size() - 1 <<
")";
97 OOMPH_CURRENT_FUNCTION,
98 OOMPH_EXCEPTION_LOCATION);
101 return std::vector<_Tp>::operator[](__n);
105 return std::vector<_Tp>::operator[](__n);
114 if (__n >= this->size())
117 std::ostringstream error_message;
118 error_message <<
"Range Error: " << __n <<
" is not in the range (0,"
119 << this->size() - 1 <<
")";
123 OOMPH_CURRENT_FUNCTION,
124 OOMPH_EXCEPTION_LOCATION);
127 return std::vector<_Tp>::operator[](__n);
131 return std::vector<_Tp>::operator[](__n);
158 Vector(std::initializer_list<_Tp> init) : std::vector<_Tp>(init) {}
169 for (
typename std::vector<_Tp>::iterator it = std::vector<_Tp>::begin();
170 it != std::vector<_Tp>::end();
177 #ifdef RANGE_CHECKING
200 class Vector<bool> :
private std::vector<bool>
218 Vector(
const double& dont_call_this_constructor)
221 throw OomphLibError(
"Please use vector<bool> instead of Vector<bool>",
222 OOMPH_CURRENT_FUNCTION,
223 OOMPH_EXCEPTION_LOCATION);
247 Vector(std::initializer_list<bool> init) : std::vector<bool>(init) {}
255 for (std::vector<bool>::iterator it = std::vector<bool>::begin();
256 it != std::vector<bool>::end();
268 namespace VectorHelpers
275 if (a.size() != b.size())
277 std::ostringstream err;
278 err <<
"Vectors must be the same length."
279 <<
"len(a) = " << a.size() <<
", "
280 <<
"len(b) = " << b.size() <<
".";
283 err.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
295 for (
unsigned i = 0, ni = a.size();
i < ni;
i++)
305 return (std::sqrt(
dot(a, a)));
313 return std::acos(
dot(a, b) / std::sqrt(
dot(a, a) *
dot(b, b)));
324 if ((A.size() != 3) || (
B.size() != 3) || (C.size() != 3))
326 std::ostringstream err;
327 err <<
"Cross product only defined for vectors of length 3.\n"
328 <<
"len(a) = " << A.size() <<
", "
329 <<
"len(b) = " <<
B.size() <<
", "
330 <<
"len(c) = " << C.size() <<
".";
333 err.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
337 C[0] = A[1] *
B[2] - A[2] *
B[1];
338 C[1] = A[2] *
B[0] - A[0] *
B[2];
339 C[2] = A[0] *
B[1] - A[1] *
B[0];
An OomphLibError object which should be thrown when an run-time error is encountered....
A Vector of bools cannot be created because the is no compiler-independent implementation of the bit ...
size_t size_type
Typedef to make the constructors look a bit cleaner.
Vector(std::initializer_list< bool > init)
A constructor that creates a vector with entries set by the values in the input initialiser_list....
Vector(const double &dont_call_this_constructor)
Dummy constructor to avoid compiler from warning about only-private constructors.
void initialise(const bool &__value)
Iterate over all values and set to the desired value.
Vector()
Construct an empty vector.
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.
Vector(size_type __n)
A constructor that creates a vector of size __n. Note the use of explicit for "strong" type checking.
Vector(const Vector< bool > &__x)
Copy constructor.
bool value_type
Typedef to make the constructors look a bit cleaner.
value_type & reference
Typedef to make the constructors look a bit cleaner.
A slight extension to the standard template vector class so that we can include "graceful" array rang...
Vector()
Construct an empty vector.
Vector(size_type __n, const _Tp &__value)
A constructor that creates a vector of size __n and initialises every entry to __value.
Vector(std::initializer_list< _Tp > init)
A constructor that creates a vector with entries set by the values in the input initialiser_list Exam...
Vector(const Vector< _Tp > &__x)
Copy constructor.
reference operator[](size_type __n)
Overload the bracket access operator to include array-range checking if the RANGE_CHECKING flag is se...
_Tp value_type
Typedef to make the constructors look a bit cleaner.
value_type & reference
Typedef to make the constructors look a bit cleaner.
size_t size_type
Typedef to make the constructors look a bit cleaner.
const_reference error_checked_access(size_type __n) const
const_reference operator[](size_type __n) const
Overloaded, range-checking, bracket access operator (const version)
Vector(size_type __n)
A constructor that creates a vector of size __n. Note the use of explicit for "strong" type checking.
reference error_checked_access(size_type __n)
const value_type & const_reference
Typedef to make the constructors look a bit cleaner.
void initialise(const _Tp &__value)
Iterate over all values and set to the desired value.
void output()
Doc the command line arguments.
double dot(const Vector< double > &a, const Vector< double > &b)
Probably not always best/fastest because not optimised for dimension but useful...
void cross(const Vector< double > &A, const Vector< double > &B, Vector< double > &C)
Cross product using "proper" output (move semantics means this is ok nowadays).
double angle(const Vector< double > &a, const Vector< double > &b)
Get the angle between two vector.
void check_lengths_match(const Vector< double > &a, const Vector< double > &b)
Check the lengths if two Vectors are the same length.
double magnitude(const Vector< double > &a)
Get the magnitude of a vector.
//////////////////////////////////////////////////////////////////// ////////////////////////////////...