Memosa-FVM  0.2
SquareTensor.h File Reference
#include "NumType.h"
#include "Vector.h"
#include <sstream>
#include "CRConnectivity.h"
Include dependency graph for SquareTensor.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  SquareTensor< T, N >
 

Functions

template<class T , int N>
ostream & operator<< (ostream &os, const SquareTensor< T, N > &v)
 
template<class T , int N>
SquareTensor< T, N > operator+ (const SquareTensor< T, N > &a, const SquareTensor< T, N > &b)
 
template<class T , int N>
SquareTensor< T, N > operator- (const SquareTensor< T, N > &a, const SquareTensor< T, N > &b)
 
template<class T , int N>
SquareTensor< T, N > operator- (const SquareTensor< T, N > &a)
 
template<class T , int N>
SquareTensor< T, N > operator* (const SquareTensor< T, N > &a, const SquareTensor< T, N > &b)
 
template<class T , int N>
SquareTensor< T, N > operator* (const T s, const SquareTensor< T, N > &a)
 
template<class T , int N>
SquareTensor< T, N > operator* (const SquareTensor< T, N > &a, const T s)
 
template<class T , int N>
Vector< T, N > operator* (const SquareTensor< T, N > &a, const Vector< T, N > &b)
 
template<class T , int N>
SquareTensor< T, N > operator/ (const SquareTensor< T, N > &a, const T s)
 
template<class T , int N>
Vector< T, N > operator/ (const Vector< T, N > &a, const SquareTensor< T, N > &b)
 
template<class T , int N>
SquareTensor< T, N > operator/ (const SquareTensor< T, N > &a, const SquareTensor< T, N > &b)
 
template<class T , int N>
SquareTensor< T, N > operator/ (const T s, const SquareTensor< T, N > &a)
 
template<class T >
SquareTensor< T, 2 > inverse (const SquareTensor< T, 2 > &a)
 
template<class T >
SquareTensor< T, 3 > inverse (const SquareTensor< T, 3 > &a)
 
template<int N>
void setFlatCoeffs (Array< double > &flatCoeffs, const CRConnectivity &flatConnectivity, const Array< SquareTensor< double, N > > &diag, const Array< SquareTensor< double, N > > &offDiag, const CRConnectivity &connectivity)
 

Function Documentation

template<class T >
SquareTensor<T,2> inverse ( const SquareTensor< T, 2 > &  a)

Definition at line 358 of file SquareTensor.h.

Referenced by operator/(), and SquareTensor< X, K >::operator/=().

359 {
360  SquareTensor<T,2> inv;
361  T det = a(0,0)*a(1,1)-a(0,1)*a(1,0);
362  inv(0,0) = a(1,1) / det;
363  inv(0,1) = -a(0,1) / det;
364  inv(1,0) = -a(1,0) / det;
365  inv(1,1) = a(0,0) / det;
366 
367  return inv;
368 }
template<class T >
SquareTensor<T,3> inverse ( const SquareTensor< T, 3 > &  a)

Definition at line 373 of file SquareTensor.h.

374 {
375  SquareTensor<T,3> inv;
376  T det = a(0,0)*(a(1,1)*a(2,2)-a(1,2)*a(2,1))
377  -a(0,1)*(a(1,0)*a(2,2) - a(1,2)*a(2,0))
378  +a(0,2)*(a(1,0)*a(2,1) - a(1,1)*a(2,0));
379 
380  inv(0,0) = (a(1,1)*a(2,2) - a(1,2)*a(2,1)) / det;
381  inv(0,1) = (a(0,2)*a(2,1) - a(0,1)*a(2,2)) / det;
382  inv(0,2) = (a(0,1)*a(1,2) - a(0,2)*a(1,1)) / det;
383  inv(1,0) = (a(1,2)*a(2,0) - a(1,0)*a(2,2)) / det;
384  inv(1,1) = (a(0,0)*a(2,2) - a(0,2)*a(2,0)) / det;
385  inv(1,2) = (a(0,2)*a(1,0) - a(0,0)*a(1,2)) / det;
386  inv(2,0) = (a(1,0)*a(2,1) - a(1,1)*a(2,0)) / det;
387  inv(2,1) = (a(0,1)*a(2,0) - a(0,0)*a(2,1)) / det;
388  inv(2,2) = (a(0,0)*a(1,1) - a(0,1)*a(1,0)) / det;
389 
390  return inv;
391 
392 }
template<class T , int N>
SquareTensor<T,N> operator* ( const SquareTensor< T, N > &  a,
const SquareTensor< T, N > &  b 
)

Definition at line 291 of file SquareTensor.h.

292 {
293  return SquareTensor<T,N>(a) *= b;
294 }
template<class T , int N>
SquareTensor<T,N> operator* ( const T  s,
const SquareTensor< T, N > &  a 
)

Definition at line 298 of file SquareTensor.h.

299 {
300  return SquareTensor<T,N>(a) *= s;
301 }
template<class T , int N>
SquareTensor<T,N> operator* ( const SquareTensor< T, N > &  a,
const T  s 
)

Definition at line 305 of file SquareTensor.h.

306 {
307  return SquareTensor<T,N>(a) *= s;
308 }
template<class T , int N>
Vector<T,N> operator* ( const SquareTensor< T, N > &  a,
const Vector< T, N > &  b 
)

Definition at line 312 of file SquareTensor.h.

313 {
314  Vector<T,N> r;
315  for(int i=0; i<N; i++)
316  {
317  r[i] = 0;
318  for(int j=0; j<N; j++)
319  r[i] += a(i,j)*b[j];
320  }
321  return r;
322 }
Definition: Vector.h:19
template<class T , int N>
SquareTensor<T,N> operator+ ( const SquareTensor< T, N > &  a,
const SquareTensor< T, N > &  b 
)

Definition at line 270 of file SquareTensor.h.

271 {
272  return SquareTensor<T,N>(a) += b;
273 }
template<class T , int N>
SquareTensor<T,N> operator- ( const SquareTensor< T, N > &  a,
const SquareTensor< T, N > &  b 
)

Definition at line 277 of file SquareTensor.h.

278 {
279  return SquareTensor<T,N>(a) -= b;
280 }
template<class T , int N>
SquareTensor<T,N> operator- ( const SquareTensor< T, N > &  a)

Definition at line 284 of file SquareTensor.h.

285 {
286  return -SquareTensor<T,N>(a);
287 }
template<class T , int N>
SquareTensor<T,N> operator/ ( const SquareTensor< T, N > &  a,
const T  s 
)

Definition at line 326 of file SquareTensor.h.

327 {
328  return SquareTensor<T,N>(a) /= s;
329 }
template<class T , int N>
Vector<T,N> operator/ ( const Vector< T, N > &  a,
const SquareTensor< T, N > &  b 
)

Definition at line 333 of file SquareTensor.h.

References inverse().

334 {
335  return inverse(b)*a;
336 }
SquareTensor< T, 2 > inverse(const SquareTensor< T, 2 > &a)
Definition: SquareTensor.h:358
template<class T , int N>
SquareTensor<T,N> operator/ ( const SquareTensor< T, N > &  a,
const SquareTensor< T, N > &  b 
)

Definition at line 340 of file SquareTensor.h.

References inverse().

341 {
342 
343  return inverse(b)*a;
344 }
SquareTensor< T, 2 > inverse(const SquareTensor< T, 2 > &a)
Definition: SquareTensor.h:358
template<class T , int N>
SquareTensor<T,N> operator/ ( const T  s,
const SquareTensor< T, N > &  a 
)

Definition at line 348 of file SquareTensor.h.

References inverse().

349 {
350  SquareTensor<T,N> r(0);
351  for(int i=0; i<N; i++) r(i,i) = s;
352  return inverse(a)*r;
353 }
SquareTensor< T, 2 > inverse(const SquareTensor< T, 2 > &a)
Definition: SquareTensor.h:358
template<class T , int N>
ostream& operator<< ( ostream &  os,
const SquareTensor< T, N > &  v 
)
inline

Definition at line 260 of file SquareTensor.h.

References SquareTensor< T, N >::printFromC().

262 {
263  v.printFromC(os);
264  return os;
265 }
void printFromC(ostream &os) const
Definition: SquareTensor.h:64
template<int N>
void setFlatCoeffs ( Array< double > &  flatCoeffs,
const CRConnectivity flatConnectivity,
const Array< SquareTensor< double, N > > &  diag,
const Array< SquareTensor< double, N > > &  offDiag,
const CRConnectivity connectivity 
)

Definition at line 396 of file SquareTensor.h.

References CRConnectivity::getCoeffPosition(), CRConnectivity::getCol(), CRConnectivity::getRow(), and CRConnectivity::getRowDim().

401 {
402  const Array<int>& myRow = connectivity.getRow();
403  const Array<int>& myCol = connectivity.getCol();
404  const int rowDim = connectivity.getRowDim();
405 
406  for(int i=0; i<rowDim; i++)
407  {
408  for(int ndr=0; ndr<N; ndr++)
409  for(int ndc=0; ndc<N; ndc++)
410  {
411  const int nfr = i*N + ndr;
412  const int nfc = i*N + ndc;
413 
414  const int fp = flatConnectivity.getCoeffPosition(nfc,nfr);
415  flatCoeffs[fp] = diag[i](ndr,ndc);
416  }
417 
418  for(int jp=myRow[i]; jp<myRow[i+1]; jp++)
419  {
420  const int j = myCol[jp];
421 
422  for(int ndr=0; ndr<N; ndr++)
423  for(int ndc=0; ndc<N; ndc++)
424  {
425  const int nfr = i*N + ndr;
426  const int nfc = j*N + ndc;
427  const int fp = flatConnectivity.getCoeffPosition(nfc,nfr);
428  flatCoeffs[fp] = offDiag[jp](ndr,ndc);
429  }
430  }
431  }
432 }
const Array< int > & getCol() const
const Array< int > & getRow() const
int getCoeffPosition(const int i, const int j) const
int getRowDim() const