40 template<
typename DataType>
48 template<
typename DataType>
56 template<
typename DataType>
62 std::fill_n(m_data.get(), m_size, a);
65 template<
typename DataType>
73 std::vector<DataType> values = FromString<DataType>(vectorValues);
74 m_size = values.size();
76 std::copy(values.begin(), values.end(), m_data.begin());
78 ASSERTL0(m_size > 0,
"Error converting string values to vector");
80 catch(std::runtime_error& e)
86 template<
typename DataType>
88 typename boost::call_traits<DataType>::const_reference y,
89 typename boost::call_traits<DataType>::const_reference z) :
99 template<
typename DataType>
101 m_size(
rhs.GetDimension()),
103 m_wrapperType(
rhs.m_wrapperType)
105 if( m_wrapperType ==
eCopy )
112 template<
typename DataType>
120 template<
typename DataType>
122 m_size(ptr.num_elements()),
133 template<
typename DataType>
142 std::to_string(size) +
" but the incoming array only has " +
150 template<
typename DataType>
152 m_size(ptr.num_elements()),
163 template<
typename DataType>
172 std::to_string(size) +
" but the incoming array only has " +
180 template<
typename DataType>
183 template<
typename DataType>
186 if( m_wrapperType ==
eCopy )
190 if( GetDimension() !=
rhs.GetDimension() )
192 m_size =
rhs.GetDimension();
196 else if( m_wrapperType ==
eWrapper )
200 ASSERTL0(GetDimension() ==
rhs.GetDimension(),
"Wrapped NekVectors must have the same dimension in operator=");
208 template<
typename DataType>
214 template<
typename DataType>
220 template<
typename DataType>
223 return this->GetData().get();
226 template<
typename DataType>
229 template<
typename DataType>
235 template<
typename DataType>
238 template<
typename DataType>
241 template<
typename DataType>
244 template<
typename DataType>
247 template<
typename DataType>
250 template<
typename DataType>
254 "Invalid access to m_data via parenthesis operator");
255 return this->GetData()[i];
258 template<
typename DataType>
261 return this->GetData()[i];
264 template<
typename DataType>
267 ASSERTL1(this->GetDimension() >= 1,
"Invalid use of NekVector::x");
271 template<
typename DataType>
274 ASSERTL1(this->GetDimension() >= 2,
"Invalid use of NekVector::y");
278 template<
typename DataType>
281 ASSERTL1(this->GetDimension() >= 3,
"Invalid use of NekVector::z");
285 template<
typename DataType>
288 ASSERTL1(this->GetDimension() >= 1,
"Invalid use of NekVector::SetX");
289 this->GetData()[0] = val;
292 template<
typename DataType>
295 ASSERTL1(this->GetDimension() >= 2,
"Invalid use of NekVector::SetX");
296 this->GetData()[1] = val;
299 template<
typename DataType>
302 ASSERTL1(this->GetDimension() >= 3,
"Invalid use of NekVector::SetX");
303 this->GetData()[2] = val;
306 template<
typename DataType>
313 template<
typename DataType>
320 template<
typename DataType>
327 template<
typename DataType>
334 template<
typename DataType>
337 template<
typename DataType>
341 "Invalid access to m_data via parenthesis operator");
345 template<
typename DataType>
351 template<
typename DataType>
354 ASSERTL1( GetDimension() >= 1,
"Invalid use of NekVector::x");
358 template<
typename DataType>
361 ASSERTL1( GetDimension() >= 2,
"Invalid use of NekVector::y");
365 template<
typename DataType>
368 ASSERTL1( GetDimension() >= 3,
"Invalid use of NekVector::z");
372 template<
typename DataType>
375 template<
typename DataType>
378 template<
typename DataType>
381 template<
typename DataType>
387 template<
typename DataType>
391 template<
typename DataType>
394 template<
typename DataType>
397 template<
typename DataType>
400 template<
typename DataType>
403 template<
typename DataType>
406 template<
typename DataType>
409 template<
typename DataType>
412 template<
typename DataType>
415 template<
typename DataType>
418 if(m_data.num_elements() < newSize )
427 template<
typename DataType>
433 const DataType* lhs_buf =
lhs.GetRawPtr();
434 const DataType* rhs_buf =
rhs.GetRawPtr();
435 const unsigned int ldim =
lhs.GetDimension();
436 for(
int i = 0; i < ldim; ++i)
438 r_buf[i] = lhs_buf[i] + rhs_buf[i];
442 template<
typename DataType>
448 const DataType* lhs_buf =
lhs.GetRawPtr();
449 const DataType* rhs_buf =
rhs.GetRawPtr();
450 const unsigned int ldim =
lhs.GetDimension();
451 for(
int i = 0; i < ldim; ++i)
453 r_buf[i] = -lhs_buf[i] + rhs_buf[i];
464 template<
typename DataType>
469 const DataType* rhs_buf =
rhs.GetRawPtr();
470 const unsigned int rdim =
rhs.GetDimension();
471 for(
int i = 0; i < rdim; ++i)
473 r_buf[i] += rhs_buf[i];
477 template<
typename DataType>
482 const DataType* rhs_buf =
rhs.GetRawPtr();
483 const unsigned int rdim =
rhs.GetDimension();
484 for(
int i = 0; i < rdim; ++i)
486 r_buf[i] = -r_buf[i] + rhs_buf[i];
511 template<
typename ResultDataType,
typename InputDataType>
516 ResultDataType* r_buf = result.
GetRawPtr();
517 typename std::add_const<InputDataType>::type* lhs_buf =
lhs.GetRawPtr();
518 typename std::add_const<InputDataType>::type* rhs_buf =
rhs.GetRawPtr();
519 const unsigned int ldim =
lhs.GetDimension();
520 for(
int i = 0; i < ldim; ++i)
522 r_buf[i] = lhs_buf[i] - rhs_buf[i];
526 template<
typename ResultDataType,
typename InputDataType>
531 ResultDataType* r_buf = result.
GetRawPtr();
532 typename std::add_const<InputDataType>::type* lhs_buf =
lhs.GetRawPtr();
533 typename std::add_const<InputDataType>::type* rhs_buf =
rhs.GetRawPtr();
534 const unsigned int ldim =
lhs.GetDimension();
535 for(
int i = 0; i < ldim; ++i)
537 r_buf[i] = -lhs_buf[i] - rhs_buf[i];
551 template<
typename ResultDataType,
typename InputDataType>
555 ResultDataType* r_buf = result.
GetRawPtr();
556 typename std::add_const<InputDataType>::type* rhs_buf =
rhs.GetRawPtr();
557 const unsigned int rdim =
rhs.GetDimension();
558 for(
int i = 0; i < rdim; ++i)
560 r_buf[i] -= rhs_buf[i];
564 template<
typename ResultDataType,
typename InputDataType>
568 ResultDataType* r_buf = result.
GetRawPtr();
569 typename std::add_const<InputDataType>::type* rhs_buf =
rhs.GetRawPtr();
570 const unsigned int rdim =
rhs.GetDimension();
571 for(
int i = 0; i < rdim; ++i)
573 r_buf[i] = -r_buf[i] - rhs_buf[i];
585 template<
typename DataType>
600 template<
typename ResultDataType,
typename InputDataType>
605 ResultDataType* r_buf = result.
GetRawPtr();
606 typename std::add_const<InputDataType>::type* lhs_buf =
lhs.GetRawPtr();
608 const unsigned int ldim =
lhs.GetDimension();
609 for(
int i = 0; i < ldim; ++i)
611 r_buf[i] = lhs_buf[i] /
rhs;
620 template<
typename ResultDataType>
624 ResultDataType* r_buf = result.
GetRawPtr();
627 for(
int i = 0; i < resdim; ++i)
637 template<
typename DataType>
653 template<
typename ResultDataType,
typename InputDataType>
658 ResultDataType* result_buf = result.
GetRawPtr();
659 const InputDataType* rhs_buf =
rhs.GetRawPtr();
660 const InputDataType* lhs_buf =
lhs.GetRawPtr();
662 for(
int i = 0; i < resdim; ++i)
664 result_buf[i] = lhs_buf[i] * rhs_buf[i];
671 template<
typename ResultDataType,
typename InputDataType>
675 ResultDataType* result_buf = result.
GetRawPtr();
676 const InputDataType* rhs_buf =
rhs.GetRawPtr();
678 for(
int i = 0; i < resdim; ++i)
680 result_buf[i] *= rhs_buf[i];
687 template<
typename DataType,
typename InputDataType>
702 template<
typename ResultDataType,
typename InputDataType>
707 ResultDataType* r_buf = result.
GetRawPtr();
708 const InputDataType* lhs_buf =
lhs.GetRawPtr();
710 const unsigned int ldim =
lhs.GetDimension();
711 for(
int i = 0; i < ldim; ++i)
713 r_buf[i] = lhs_buf[i] *
rhs;
722 template<
typename ResultDataType>
726 ResultDataType* r_buf = result.
GetRawPtr();
728 for(
unsigned int i = 0; i < rdim; ++i)
737 template<
typename DataType>
752 template<
typename ResultDataType,
typename InputDataType>
760 template<
typename ResultDataType,
typename InputDataType>
765 ResultDataType* r_buf = result.
GetRawPtr();
766 const InputDataType* rhs_buf =
rhs.GetRawPtr();
769 const unsigned int rdim =
rhs.GetDimension();
770 for(
int i = 0; i < rdim; ++i)
772 r_buf[i] = inverse * rhs_buf[i];
786 template<
typename DataType>
798 template<
typename DataType>
801 os <<
rhs.AsString();
808 template<
typename DataType>
813 for(
unsigned int i = 0; i < 3; ++i)
815 result[i] = dest[i]-source[i];
825 template<
typename DataType>
830 for(
unsigned int i = 0; i < 3; ++i)
832 result[i] =
lhs[i]*t;
842 template<
typename DataType>
846 if(
lhs.GetDimension() !=
rhs.GetDimension() )
851 return std::equal(
lhs.begin(),
lhs.end(),
rhs.begin());
858 template<
typename DataType>
869 template<
typename DataType>
872 std::vector<DataType> result;
876 typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
877 boost::char_separator<char> sep(
"(<,>) ");
878 tokenizer tokens(str, sep);
879 for( tokenizer::iterator strIter = tokens.begin(); strIter != tokens.end(); ++strIter)
881 result.push_back(boost::lexical_cast<DataType>(*strIter));
884 catch(boost::bad_lexical_cast&)
892 std::vector<NekDouble>
FromString(
const std::string& str);
894 template<
typename DataType>
900 for(
typename VectorType::const_iterator iter = v.
begin(); iter != v.
end(); ++iter)
902 result += fabs(*iter);
911 template<
typename DataType>
917 for(
typename VectorType::const_iterator iter = v.
begin(); iter != v.
end(); ++iter)
919 DataType v = fabs(*iter);
928 template<
typename DataType>
931 DataType result = fabs(v[0]);
933 for(
unsigned int i = 0; i < vdim; ++i)
935 result = std::max(fabs(v[i]), result);
943 template<
typename DataType>
948 for(
unsigned int i = 0; i < tdim; ++i)
958 template<
typename DataType>
963 for(
unsigned int i = 0; i < vdim; ++i)
972 template<
typename DataType>
975 DataType result = DataType(0);
978 for(
unsigned int i = 0; i < vdim; ++i)
988 template<
typename DataType>
992 ASSERTL1(
lhs.GetDimension() ==
rhs.GetDimension(),
"Dot, dimension of the two operands must be identical.");
994 DataType result = DataType(0);
995 const unsigned int ldim =
lhs.GetDimension();
996 for(
unsigned int i = 0; i < ldim; ++i)
1008 template<
typename DataType>
1012 if( m > DataType(0) )
1024 template<
typename DataType>
1028 ASSERTL1(
lhs.GetDimension() == 3 &&
rhs.GetDimension() == 3,
"Cross is only valid for 3D vectors.");
1041 template<
typename DataType>
1045 std::string result =
"(";
1046 for(
unsigned int i = 0; i < d; ++i)
1048 result += boost::lexical_cast<std::string>(v[i]);
#define ASSERTL0(condition, msg)
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
#define LIB_UTILITIES_EXPORT
Array< OneD, const DataType >::const_iterator begin() const
1D Array of constant elements with garbage collection and bounds checking.
const_iterator begin() const
size_t num_elements() const
Returns the array's size.
boost::call_traits< DataType >::reference x()
void SetZ(typename boost::call_traits< DataType >::const_reference val)
void SetWrapperType(PointerWrapper p)
boost::call_traits< DataType >::reference operator[](unsigned int i)
Array< OneD, DataType > & GetData()
NekVector< DataType > Cross(const NekVector< DataType > &rhs) const
Array< OneD, DataType > & GetPtr()
unsigned int GetDimension() const
Returns the number of dimensions for the point.
NekVector< DataType > & operator+=(const NekVector< DataType > &rhs)
NekVector< DataType > & operator=(const NekVector< DataType > &rhs)
PointerWrapper GetWrapperType() const
void SetY(typename boost::call_traits< DataType >::const_reference val)
void Resize(unsigned int newSize)
DataType Dot(const NekVector< DataType > &rhs) const
unsigned int GetRows() const
std::string AsString() const
void SetSize(unsigned int s)
NekVector< DataType > & operator/=(typename boost::call_traits< DataType >::const_reference rhs)
boost::call_traits< DataType >::reference y()
NekVector< DataType > & operator*=(typename boost::call_traits< DataType >::const_reference rhs)
const DataType * const_iterator
DataType InfinityNorm() const
boost::call_traits< DataType >::reference operator()(unsigned int i)
Returns i^{th} element.
DataType Magnitude() const
NekVector< DataType > & operator-=(const NekVector< DataType > &rhs)
NekVector()
Creates an empty vector.
void SetData(const Array< OneD, DataType > &newData)
boost::call_traits< DataType >::reference z()
NekVector< DataType > operator-() const
void SetX(typename boost::call_traits< DataType >::const_reference val)
void Normalize(NekVector< DataType > &v)
std::string AsString(const NekVector< DataType > &v)
void InvertInPlace(NekDouble &v)
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs
bool operator==(const Array< OneD, NekDouble > &lhs, const Array< OneD, NekDouble > &rhs)
void MultiplyInvertedLhs(NekVector< ResultDataType > &result, const NekDouble &lhs, const NekVector< InputDataType > &rhs)
void AddEqualNegatedLhs(NekMatrix< DataType, StandardMatrixTag > &result, const NekMatrix< RhsDataType, RhsMatrixType > &rhs)
DataType InfinityNorm(const NekVector< DataType > &v)
void Divide(NekVector< ResultDataType > &result, const NekVector< InputDataType > &lhs, const NekDouble &rhs)
NekVector< DataType > Negate(const NekVector< DataType > &v)
RhsMatrixType void AddEqual(NekMatrix< DataType, StandardMatrixTag > &result, const NekMatrix< RhsDataType, RhsMatrixType > &rhs)
std::vector< DataType > FromString(const std::string &str)
RhsMatrixType void Subtract(NekMatrix< DataType, StandardMatrixTag > &result, const NekMatrix< LhsDataType, LhsMatrixType > &lhs, const NekMatrix< RhsDataType, RhsMatrixType > &rhs)
void Multiply(NekMatrix< ResultDataType, StandardMatrixTag > &result, const NekMatrix< LhsDataType, LhsMatrixType > &lhs, const ResultDataType &rhs)
void DivideEqual(NekVector< ResultDataType > &result, const NekDouble &rhs)
NekVector< DataType > createVectorFromPoints(const NekPoint< DataType > &source, const NekPoint< DataType > &dest)
void MultiplyEqual(NekMatrix< LhsDataType, StandardMatrixTag > &lhs, typename boost::call_traits< LhsDataType >::const_reference rhs)
void AddNegatedLhs(NekMatrix< DataType, StandardMatrixTag > &result, const NekMatrix< LhsDataType, LhsMatrixType > &lhs, const NekMatrix< RhsDataType, RhsMatrixType > &rhs)
void SubtractEqualNegatedLhs(NekMatrix< DataType, StandardMatrixTag > &result, const NekMatrix< RhsDataType, RhsMatrixType > &rhs)
void NegateInPlace(NekVector< DataType > &v)
DataType Magnitude(const NekVector< DataType > &v)
NekVector< DataType > Cross(const NekVector< DataType > &lhs, const NekVector< DataType > &rhs)
void SubtractNegatedLhs(NekMatrix< DataType, StandardMatrixTag > &result, const NekMatrix< LhsDataType, LhsMatrixType > &lhs, const NekMatrix< RhsDataType, RhsMatrixType > &rhs)
std::ostream & operator<<(std::ostream &os, const NekMatrix< DataType, FormType > &rhs)
DataType L2Norm(const NekVector< DataType > &v)
DataType L1Norm(const NekVector< DataType > &v)
NekPoint< DataType > findPointAlongVector(const NekVector< DataType > &lhs, const DataType &t)
DNekMat void Add(NekMatrix< DataType, StandardMatrixTag > &result, const NekMatrix< LhsDataType, LhsMatrixType > &lhs, const NekMatrix< RhsDataType, RhsMatrixType > &rhs)
bool operator!=(const Array< OneD, T1 > &lhs, const Array< OneD, T2 > &rhs)
DNekMat void SubtractEqual(NekMatrix< DataType, StandardMatrixTag > &result, const NekMatrix< RhsDataType, RhsMatrixType > &rhs)
PointerWrapper
Specifies if the pointer passed to a NekMatrix or NekVector is copied into an internal representation...
DataType Dot(const NekVector< DataType > &lhs, const NekVector< DataType > &rhs)
void CopyArray(const Array< OneD, ConstDataType > &source, Array< OneD, DataType > &dest)