oomph::VectorHelpers Namespace Reference

Namespace for helper functions for Vector<double> More...

Functions

double two_norm (const Vector< double > &a)
 
Vector< doublevector_diff (const Vector< double > &a, const Vector< double > &b)
 
void check_lengths_match (const Vector< double > &a, const Vector< double > &b)
 Check the lengths if two Vectors are the same length. More...
 
double dot (const Vector< double > &a, const Vector< double > &b)
 
double magnitude (const Vector< double > &a)
 Get the magnitude of a vector. More...
 
double angle (const Vector< double > &a, const Vector< double > &b)
 Get the angle between two vector. More...
 
void cross (const Vector< double > &A, const Vector< double > &B, Vector< double > &C)
 
Vector< doublecross (const Vector< double > &A, const Vector< double > &B)
 

Detailed Description

Namespace for helper functions for Vector<double>

Function Documentation

◆ angle()

double oomph::VectorHelpers::angle ( const Vector< double > &  a,
const Vector< double > &  b 
)
inline

Get the angle between two vector.

310  {
311  // Notice that we use one square root operation by avoiding the
312  // call to magnitude(...)
313  return std::acos(dot(a, b) / std::sqrt(dot(a, a) * dot(b, b)));
314  }
AnnoyingScalar acos(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:138
AnnoyingScalar sqrt(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:134
Scalar * b
Definition: benchVecAdd.cpp:17
Scalar EIGEN_BLAS_FUNC_NAME() dot(int *n, Scalar *px, int *incx, Scalar *py, int *incy)
Definition: level1_real_impl.h:52
const Scalar * a
Definition: level2_cplx_impl.h:32

References a, acos(), b, dot(), and sqrt().

Referenced by oomph::FaceElement::continuous_tangent_and_outer_unit_normal().

◆ check_lengths_match()

void oomph::VectorHelpers::check_lengths_match ( const Vector< double > &  a,
const Vector< double > &  b 
)
inline

Check the lengths if two Vectors are the same length.

273  {
274 #ifdef PARANOID
275  if (a.size() != b.size())
276  {
277  std::ostringstream err;
278  err << "Vectors must be the same length."
279  << "len(a) = " << a.size() << ", "
280  << "len(b) = " << b.size() << ".";
281 
282  throw OomphLibError(
284  }
285 #endif
286  }
#define OOMPH_EXCEPTION_LOCATION
Definition: oomph_definitions.h:61
#define OOMPH_CURRENT_FUNCTION
Definition: oomph_definitions.h:86

References a, b, OOMPH_CURRENT_FUNCTION, and OOMPH_EXCEPTION_LOCATION.

Referenced by dot(), and vector_diff().

◆ cross() [1/2]

Vector<double> oomph::VectorHelpers::cross ( const Vector< double > &  A,
const Vector< double > &  B 
)
inline

Cross product using "proper" output (move semantics means this is ok This calls the other cross(...) function.

346  {
347  Vector<double> output(3, 0.0);
348  cross(A, B, output);
349 
350  return output;
351  }
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition: bench_gemm.cpp:47
Definition: matrices.h:74
Vector< double > cross(const Vector< double > &A, const Vector< double > &B)
Definition: oomph-lib/src/generic/Vector.h:344
void output(std::ostream &outfile, const unsigned &nplot)
Overload output function.
Definition: overloaded_element_body.h:490

References cross(), and oomph::output().

◆ cross() [2/2]

void oomph::VectorHelpers::cross ( const Vector< double > &  A,
const Vector< double > &  B,
Vector< double > &  C 
)
inline

Cross product using "proper" output (move semantics means this is ok nowadays).

322  {
323 #ifdef PARANOID
324  if ((A.size() != 3) || (B.size() != 3) || (C.size() != 3))
325  {
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() << ".";
331 
332  throw OomphLibError(
334  }
335 #endif
336 
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];
340  }

References OOMPH_CURRENT_FUNCTION, and OOMPH_EXCEPTION_LOCATION.

Referenced by ChuteWithPeriodicInflow::computeInternalForces(), oomph::FaceElement::continuous_tangent_and_outer_unit_normal(), cross(), oomph::SCoupledElement< ELEMENT >::get_momentum_and_energy(), oomph::VolumeCoupledElement< ELEMENT >::get_momentum_and_energy(), SolidProblem< ELEMENT_TYPE >::getMassMomentumEnergy(), and oomph::FaceElement::outer_unit_normal().

◆ dot()

double oomph::VectorHelpers::dot ( const Vector< double > &  a,
const Vector< double > &  b 
)
inline

Probably not always best/fastest because not optimised for dimension but useful...

292  {
294  double temp = 0;
295  for (unsigned i = 0, ni = a.size(); i < ni; i++)
296  {
297  temp += a[i] * b[i];
298  }
299  return temp;
300  }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
void check_lengths_match(const Vector< double > &a, const Vector< double > &b)
Check the lengths if two Vectors are the same length.
Definition: oomph-lib/src/generic/Vector.h:271

References a, b, check_lengths_match(), and i.

Referenced by angle(), oomph::FaceElement::continuous_tangent_and_outer_unit_normal(), magnitude(), and two_norm().

◆ magnitude()

◆ two_norm()

◆ vector_diff()

Vector<double> oomph::VectorHelpers::vector_diff ( const Vector< double > &  a,
const Vector< double > &  b 
)
inline
47  {
49  unsigned ni = a.size();
50  Vector<double> diff(ni, 0.0);
51  for(unsigned i=0; i<ni; i++) {diff[i] = a[i] - b[i];}
52  return diff;
53  }

References a, b, check_lengths_match(), and i.

Referenced by oomph::ODEProblem::get_error_norm().