22 #ifndef __PLUMED_tools_Tensor_h
23 #define __PLUMED_tools_Tensor_h
69 template <
unsigned n,
unsigned m>
82 TensorGeneric(
double,
double,
double,
double,
double,
double,
double,
double,
double);
88 const double &
operator() (
unsigned i,
unsigned j)
const;
110 template<
unsigned n_,
unsigned m_>
113 template<
unsigned n_,
unsigned m_>
116 template<
unsigned n_,
unsigned m_>
119 template<
unsigned n_,
unsigned m_>
122 template<
unsigned n_,
unsigned m_>
133 template<
unsigned n_,
unsigned m_,
unsigned l_>
136 template<
unsigned n_,
unsigned m_>
139 template<
unsigned n_,
unsigned m_>
142 template<
unsigned n_,
unsigned m_,
unsigned l_,
unsigned i_>
145 template<
unsigned n_,
unsigned m_,
unsigned l_>
148 template<
unsigned n_,
unsigned m_,
unsigned l_>
155 template<
unsigned n_,
unsigned m_>
158 template<
unsigned n_,
unsigned m_>
164 template<
unsigned n,
unsigned m>
166 for(
unsigned i=0;i<
n*
m;i++)d[i]=0.0;
169 template<
unsigned n,
unsigned m>
171 for(
unsigned i=0;i<
n;i++)
for(
unsigned j=0;j<
m;j++)d[i*m+j]=v1[i]*v2[j];
197 template<
unsigned n,
unsigned m>
199 for(
unsigned i=0;i<
n*
m;i++)d[i]=0.0;
202 template<
unsigned n,
unsigned m>
207 template<
unsigned n,
unsigned m>
212 template<
unsigned n,
unsigned m>
214 for(
unsigned i=0;i<
n*
m;i++)d[i]+=b.
d[i];
218 template<
unsigned n,
unsigned m>
220 for(
unsigned i=0;i<
n*
m;i++)d[i]-=b.
d[i];
224 template<
unsigned n,
unsigned m>
226 for(
unsigned i=0;i<
n*
m;i++)d[i]*=s;
230 template<
unsigned n,
unsigned m>
232 return (*
this)*=1.0/s;
235 template<
unsigned n,
unsigned m>
240 template<
unsigned n,
unsigned m>
243 for(
unsigned i=0;i<
n*
m;i++)r.
d[i]=-d[i];
247 template<
unsigned n,
unsigned m>
249 for(
unsigned i=0;i<
n;++i) (*
this)(i,j)=c(i);
253 template<
unsigned n,
unsigned m>
255 for(
unsigned j=0;j<
m;++j) (*
this)(i,j)=r(j);
259 template<
unsigned n,
unsigned m>
262 for(
unsigned i=0;i<
n;++i) v(i)=(*this)(i,j);
266 template<
unsigned n,
unsigned m>
269 for(
unsigned j=0;j<
m;++j) v(j)=(*this)(i,j);
273 template<
unsigned n,
unsigned m>
280 template<
unsigned n,
unsigned m>
287 template<
unsigned n,
unsigned m>
294 template<
unsigned n,
unsigned m>
299 template<
unsigned n,
unsigned m>
316 template<
unsigned n,
unsigned m>
320 for(
unsigned i=0;i<
n;i++) t(i,i)=1.0;
324 template<
unsigned n,
unsigned m>
327 for(
unsigned i=0;i<
n;i++)
for(
unsigned j=0;j<
m;j++) t(i,j)=(*this)(j,i);
336 for(
unsigned i=0;i<3;i++)
for(
unsigned j=0;j<3;j++)
337 t(j,i)=invdet*( (*this)((i+1)%3,(j+1)%3)*(*
this)((i+2)%3,(j+2)%3)
338 -(*
this)((i+1)%3,(j+2)%3)*(*
this)((i+2)%3,(j+1)%3));
342 template<
unsigned n,
unsigned m,
unsigned l>
345 for(
unsigned i=0;i<
n;i++)
for(
unsigned j=0;j<l;j++)
for(
unsigned k=0;k<
m;k++) {
346 t(i,j)+=
a(i,k)*b(k,j);
351 template<
unsigned n,
unsigned m>
354 for(
unsigned i=0;i<
n;i++)
for(
unsigned j=0;j<
m;j++) t(i)+=
a(i,j)*b(j);
358 template<
unsigned n,
unsigned m>
361 for(
unsigned i=0;i<
n;i++)
for(
unsigned j=0;j<
m;j++) t(i)+=
a(j)*b(j,i);
365 template<
unsigned n,
unsigned m,
unsigned l,
unsigned i>
370 template<
unsigned n,
unsigned m,
unsigned l>
375 template<
unsigned n,
unsigned m,
unsigned l>
390 template<
unsigned n,
unsigned m>
395 template<
unsigned n,
unsigned m>
void zero()
set it to zero
TensorGeneric< 3, 3 > dcrossDv2(const VectorGeneric< 3 > &v1, const VectorGeneric< 3 > &v2)
double determinant(const TensorGeneric< 3, 3 > &t)
VectorGeneric< n > getCol(unsigned j) const
get j-th column
TensorGeneric< 3, 3 > inverse(const TensorGeneric< 3, 3 > &t)
TensorGeneric< m, n > transpose() const
return the transpose matrix
Class implementing fixed size matrices of doubles.
TensorGeneric< n, l > matmul(const TensorGeneric< n, m > &a, const TensorGeneric< m, l > &b)
Class implementing fixed size vectors of doubles.
TensorGeneric & setCol(unsigned j, const VectorGeneric< n > &c)
set j-th column
friend TensorGeneric< 3, 3 > dcrossDv2(const VectorGeneric< 3 > &, const VectorGeneric< 3 > &)
Utility class to add [][] access.
TensorGeneric< n, m > operator*(const TensorGeneric< n, m > &t1, double s)
void transpose(const Matrix< T > &A, Matrix< T > &AT)
TensorGeneric< n, m > operator/(const TensorGeneric< n, m > &t1, double s)
double & operator()(unsigned i, unsigned j)
access element
double determinant() const
returns the determinant
static TensorGeneric< n, n > identity()
return an identity tensor
TensorGeneric< 2, 2 > Tensor2d
TensorGeneric< 3, 3 > dcrossDv1(const VectorGeneric< 3 > &v1, const VectorGeneric< 3 > &v2)
friend TensorGeneric< n_, l_ > matmul(const TensorGeneric< n_, m_ > &, const TensorGeneric< m_, l_ > &)
matrix-matrix multiplication
TensorGeneric< n, m > operator-(const TensorGeneric< n, m > &t1, const TensorGeneric< n, m > &t2)
TensorGeneric()
initialize the tensor to zero
TensorGeneric & operator/=(double)
divide
friend TensorGeneric< n_, m_ > extProduct(const VectorGeneric< n > &, const VectorGeneric< m > &)
returns the transpose of a tensor (same as TensorGeneric(const VectorGeneric&,const VectorGeneric&)) ...
friend TensorGeneric< n_, m_ > operator/(const TensorGeneric< n_, m_ > &, double s)
scale the tensor by a factor 1/s
TensorGeneric & operator+=(const TensorGeneric< n, m > &b)
increment
TensorGeneric & operator-=(const TensorGeneric< n, m > &b)
decrement
TensorGeneric operator-() const
return -t
TensorGeneric & operator*=(double)
multiply
TensorGeneric< n, m > extProduct(const VectorGeneric< n > &v1, const VectorGeneric< m > &v2)
TensorGeneric< n, m > operator+(const TensorGeneric< n, m > &t1, const TensorGeneric< n, m > &t2)
TensorGeneric< 4, 4 > Tensor4d
TensorGeneric & setRow(unsigned i, const VectorGeneric< m > &r)
set i-th row
TensorGeneric< 3, 3 > Tensor3d
friend TensorGeneric< 3, 3 > dcrossDv1(const VectorGeneric< 3 > &, const VectorGeneric< 3 > &)
VectorGeneric< m > getRow(unsigned i) const
get i-th row
TensorGeneric inverse() const
return the matrix inverse
TensorGeneric operator+() const
return +t
friend TensorGeneric< n_, m_ > operator*(double, const TensorGeneric< n_, m_ > &)
scale the tensor by a factor s