OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
matrix_vector_operation.h
Go to the documentation of this file.
1 
10 #ifndef MATRIX_OPERATION_H
11 #define MATRIX_OPERATION_H
12 
13 #include <boost/numeric/ublas/matrix.hpp>
14 #include <boost/numeric/ublas/matrix_proxy.hpp>
15 #include <boost/numeric/ublas/matrix_sparse.hpp>
16 
17 #include <boost/numeric/ublas/vector.hpp>
18 
19 #include <stdexcept>
20 
26 namespace matt_boost {
28  namespace ublas = boost::numeric::ublas;
29 
31  template<class V>
32  BOOST_UBLAS_INLINE
33  V trace(ublas::matrix<V>& e) {
34  V tr = 0;
35  if (e.size1() == e.size2()) {
36  ublas::matrix_vector_range<ublas::matrix<V> > diag(e,ublas::range(0,e.size1()),ublas::range(0,e.size2()));
37  tr = sum(diag);
38  }
39  else
40  throw std::length_error("Error in function trace() of matrix_vector_operation.h: Wrong matrix dimensions.");
41 
42  return tr;
43  }
44 
46  template<class V>
47  BOOST_UBLAS_INLINE
48  ublas::vector<V> cross_prod(ublas::vector<V>& v1, ublas::vector<V>& v2) {
49  ublas::vector<V> v(v1.size());
50  if (v1.size() == v2.size() && v1.size() == 3) {
51  v(0) = v1(1) * v2(2) - v1(2) * v2(1);
52  v(1) = v1(2) * v2(0) - v1(0) * v2(2);
53  v(2) = v1(0) * v2(1) - v1(1) * v2(0);
54  }
55  else
56  throw std::length_error("Error in function cross_prod() of matrix_vector_operation.h: Wrong vector dimensions.");
57 
58  return v;
59  }
60 
62  template<class V>
63  BOOST_UBLAS_INLINE
64  ublas::matrix<V> taylor_exp(const ublas::matrix<V>& F, const V ds, const unsigned int order) {
65  double fac = 1.0;
66  ublas::matrix<V> Fn = ublas::identity_matrix<V>(6);
67  ublas::matrix<V> M = Fn;
68 
69  for (unsigned int k = 1; k < order; ++k) {
70  fac *= ds / V(k);
71  Fn = prod(Fn,F);
72  M = M + fac * Fn;
73  }
74  return M;
75  }
76 
78  template<class M, class E1, class E2, class E3>
79  BOOST_UBLAS_INLINE
80  M gemmm(const ublas::matrix_expression<E1>& e1, const ublas::matrix_expression<E2>& e2, const ublas::matrix_expression<E3>& e3) {
81  M tmp = prod(e2,e3);
82  return prod(e1,tmp);
83  }
84 }
85 
88 #endif
constexpr double e
The value of .
Definition: Physics.h:40
T::PETE_Expr_t::PETE_Return_t sum(const PETE_Expr< T > &expr)
Definition: PETE.h:1213
BOOST_UBLAS_INLINE ublas::matrix< V > taylor_exp(const ublas::matrix< V > &F, const V ds, const unsigned int order)
Computes Taylor-Series of M(s) = exp(F*s)
BOOST_UBLAS_INLINE V trace(ublas::matrix< V > &e)
Computes the trace of a square matrix.
T::PETE_Expr_t::PETE_Return_t prod(const PETE_Expr< T > &expr)
Definition: PETE.h:1243
BOOST_UBLAS_INLINE M gemmm(const ublas::matrix_expression< E1 > &e1, const ublas::matrix_expression< E2 > &e2, const ublas::matrix_expression< E3 > &e3)
Generalized matrix-matrix-matrix multiplication .
BOOST_UBLAS_INLINE ublas::vector< V > cross_prod(ublas::vector< V > &v1, ublas::vector< V > &v2)
Computes the cross product of two vectors in .