Memosa-FVM  0.2
SquareTensor< T, N > Class Template Reference

#include <SquareTensor.h>

Inheritance diagram for SquareTensor< T, N >:
Collaboration diagram for SquareTensor< T, N >:

Public Types

enum  { NSQR = N*N }
 
typedef SquareTensor< T, N > This_T
 
typedef NumTypeTraits< T >
::T_Scalar 
T_Scalar
 
typedef NumTypeTraits< T >
::T_BuiltIn 
T_BuiltIn
 

Public Member Functions

 SquareTensor ()
 
 SquareTensor (const SquareTensor &o)
 
 SquareTensor (const T &s)
 
T & operator() (int i, int j)
 
const T & operator() (int i, int j) const
 
void printFromC (ostream &os) const
 
SquareTensoroperator= (const T &s)
 
SquareTensoroperator= (const SquareTensor &o)
 
SquareTensor operator- ()
 
SquareTensoroperator+= (const SquareTensor &o)
 
SquareTensoroperator+= (const T s)
 
SquareTensoroperator-= (const SquareTensor &o)
 
SquareTensoroperator-= (const T s)
 
SquareTensoroperator/= (const T s)
 
SquareTensoroperator/= (const SquareTensor &o)
 
SquareTensoroperator*= (const T s)
 
SquareTensoroperator*= (const SquareTensor &o)
 
void zero ()
 
mag2 () const
 
bool operator< (const double tolerance) const
 

Static Public Member Functions

static string getTypeName ()
 
static int getDimension ()
 
static void getShape (int *shp)
 
static int getDataSize ()
 
static void write (FILE *fp, const SquareTensor &x)
 
static SquareTensor getZero ()
 
static double doubleMeasure (const SquareTensor &x)
 
static SquareTensor getNegativeUnity ()
 
static SquareTensor getUnity ()
 
static void accumulateOneNorm (SquareTensor &sum, const SquareTensor &v)
 
static void accumulateDotProduct (SquareTensor &sum, const SquareTensor &v0, const SquareTensor &v1)
 
static void reduceSum (T_Scalar &sum, const This_T &x)
 
static void safeDivide (SquareTensor &x, const SquareTensor &y)
 
static void normalize (SquareTensor &x, const SquareTensor &y)
 
static void setMax (SquareTensor &x, const SquareTensor &y)
 

Private Attributes

_data [NSQR]
 

Detailed Description

template<class T, int N>
class SquareTensor< T, N >

Definition at line 15 of file SquareTensor.h.

Member Typedef Documentation

template<class T, int N>
typedef NumTypeTraits<T>::T_BuiltIn SquareTensor< T, N >::T_BuiltIn

Definition at line 23 of file SquareTensor.h.

template<class T, int N>
typedef NumTypeTraits<T>::T_Scalar SquareTensor< T, N >::T_Scalar

Definition at line 22 of file SquareTensor.h.

template<class T, int N>
typedef SquareTensor<T,N> SquareTensor< T, N >::This_T

Definition at line 21 of file SquareTensor.h.

Member Enumeration Documentation

template<class T, int N>
anonymous enum
Enumerator
NSQR 

Definition at line 19 of file SquareTensor.h.

19 { NSQR = N*N };

Constructor & Destructor Documentation

template<class T, int N>
SquareTensor< T, N >::SquareTensor ( )
inline

Definition at line 25 of file SquareTensor.h.

26  {}
template<class T, int N>
SquareTensor< T, N >::SquareTensor ( const SquareTensor< T, N > &  o)
inline

Definition at line 28 of file SquareTensor.h.

29  {
30  for(int i=0; i<NSQR; i++)
31  _data[i] = o._data[i];
32  }
T _data[NSQR]
Definition: SquareTensor.h:256
template<class T, int N>
SquareTensor< T, N >::SquareTensor ( const T &  s)
inline

Definition at line 34 of file SquareTensor.h.

35  {
36  for(int i=0; i<N; i++)
37  for(int j=0; j<N; j++)
38  (*this)(i,j) = (i==j) ? s : 0;
39  }

Member Function Documentation

template<class T, int N>
static void SquareTensor< T, N >::accumulateDotProduct ( SquareTensor< T, N > &  sum,
const SquareTensor< T, N > &  v0,
const SquareTensor< T, N > &  v1 
)
inlinestatic

Definition at line 224 of file SquareTensor.h.

226  {
227  for(int i=0; i<NSQR; i++)
229  }
T _data[NSQR]
Definition: SquareTensor.h:256
template<class T, int N>
static void SquareTensor< T, N >::accumulateOneNorm ( SquareTensor< T, N > &  sum,
const SquareTensor< T, N > &  v 
)
inlinestatic

Definition at line 218 of file SquareTensor.h.

219  {
220  for(int i=0; i<NSQR; i++)
222  }
T _data[NSQR]
Definition: SquareTensor.h:256
template<class T, int N>
static double SquareTensor< T, N >::doubleMeasure ( const SquareTensor< T, N > &  x)
inlinestatic

Definition at line 192 of file SquareTensor.h.

193  {
194  double m=0;
195  for (int i=0; i<N; i++)
196  m += NumTypeTraits<T>::doubleMeasure(x(i,i));
197  return m;
198  }
template<class T, int N>
static int SquareTensor< T, N >::getDataSize ( )
inlinestatic

Definition at line 52 of file SquareTensor.h.

template<class T, int N>
static int SquareTensor< T, N >::getDimension ( )
inlinestatic

Definition at line 49 of file SquareTensor.h.

49 {return 1;}
template<class T, int N>
static SquareTensor SquareTensor< T, N >::getNegativeUnity ( )
inlinestatic

Definition at line 200 of file SquareTensor.h.

201  {
202  SquareTensor n(getZero());
203  for(int i=0; i<N; i++)
205 
206  return n;
207  }
static SquareTensor getZero()
Definition: SquareTensor.h:185
template<class T, int N>
static void SquareTensor< T, N >::getShape ( int *  shp)
inlinestatic

Definition at line 51 of file SquareTensor.h.

51 { *shp = NSQR;}
template<class T, int N>
static string SquareTensor< T, N >::getTypeName ( )
inlinestatic

Definition at line 42 of file SquareTensor.h.

43  {
44  return "SquareTensor<" + NumTypeTraits<T>::getTypeName() +
45  "," + intAsString(N) +
46  ">";
47  }
string intAsString(const int i)
Definition: Vector.h:11
template<class T, int N>
static SquareTensor SquareTensor< T, N >::getUnity ( )
inlinestatic

Definition at line 209 of file SquareTensor.h.

210  {
211  SquareTensor n(getZero());
212  for(int i=0; i<N; i++)
213  n(i,i) = NumTypeTraits<T>::getUnity();
214 
215  return n;
216  }
static SquareTensor getZero()
Definition: SquareTensor.h:185
template<class T, int N>
static SquareTensor SquareTensor< T, N >::getZero ( )
inlinestatic

Definition at line 185 of file SquareTensor.h.

Referenced by SquareTensor< X, K >::getNegativeUnity(), and SquareTensor< X, K >::getUnity().

186  {
187  SquareTensor z;
188  z.zero();
189  return z;
190  }
template<class T, int N>
T SquareTensor< T, N >::mag2 ( ) const
inline

Definition at line 172 of file SquareTensor.h.

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

173  {
175  for(int i=0; i<N; i++)
176  r += (*this)(i,i) * (*this)(i,i);
177  return r;
178  }
template<class T, int N>
static void SquareTensor< T, N >::normalize ( SquareTensor< T, N > &  x,
const SquareTensor< T, N > &  y 
)
inlinestatic

Definition at line 243 of file SquareTensor.h.

244  {
245  for(int i=0; i<NSQR; i++)
247  }
T _data[NSQR]
Definition: SquareTensor.h:256
template<class T, int N>
T& SquareTensor< T, N >::operator() ( int  i,
int  j 
)
inline

Definition at line 58 of file SquareTensor.h.

58 {return _data[i*N+j];}
T _data[NSQR]
Definition: SquareTensor.h:256
template<class T, int N>
const T& SquareTensor< T, N >::operator() ( int  i,
int  j 
) const
inline

Definition at line 62 of file SquareTensor.h.

62 {return _data[i*N+j];}
T _data[NSQR]
Definition: SquareTensor.h:256
template<class T, int N>
SquareTensor& SquareTensor< T, N >::operator*= ( const T  s)
inline

Definition at line 145 of file SquareTensor.h.

146  {
147  for(int i=0;i<NSQR;i++)
148  _data[i] *= s;
149  return *this;
150  }
T _data[NSQR]
Definition: SquareTensor.h:256
template<class T, int N>
SquareTensor& SquareTensor< T, N >::operator*= ( const SquareTensor< T, N > &  o)
inline

Definition at line 152 of file SquareTensor.h.

153  {
154  SquareTensor p;
155  for(int i=0;i<N;i++)
156  for(int j=0;j<N;j++)
157  {
158  p(i,j) = 0;
159  for(int k=0;k<N;k++)
160  p(i,j) += (*this)(i,k) * o(k,j);
161  }
162 
163  *this = p;
164  return *this;
165  }
template<class T, int N>
SquareTensor& SquareTensor< T, N >::operator+= ( const SquareTensor< T, N > &  o)
inline

Definition at line 104 of file SquareTensor.h.

105  {
106  for(int i=0;i<NSQR;i++)
107  _data[i] += o._data[i];
108  return *this;
109  }
T _data[NSQR]
Definition: SquareTensor.h:256
template<class T, int N>
SquareTensor& SquareTensor< T, N >::operator+= ( const T  s)
inline

Definition at line 111 of file SquareTensor.h.

112  {
113  for(int i=0;i<N;i++)
114  (*this)(i,i) += s;
115  return *this;
116  }
template<class T, int N>
SquareTensor SquareTensor< T, N >::operator- ( )
inline

Definition at line 96 of file SquareTensor.h.

97  {
98  SquareTensor r;
99  for(int i=0;i<NSQR;i++)
100  r._data[i]=-_data[i];
101  return r;
102  }
T _data[NSQR]
Definition: SquareTensor.h:256
template<class T, int N>
SquareTensor& SquareTensor< T, N >::operator-= ( const SquareTensor< T, N > &  o)
inline

Definition at line 118 of file SquareTensor.h.

119  {
120  for(int i=0;i<NSQR;i++)
121  _data[i] -= o._data[i];
122  return *this;
123  }
T _data[NSQR]
Definition: SquareTensor.h:256
template<class T, int N>
SquareTensor& SquareTensor< T, N >::operator-= ( const T  s)
inline

Definition at line 125 of file SquareTensor.h.

126  {
127  for(int i=0;i<N;i++)
128  (*this)(i,i) -= s;
129  return *this;
130  }
template<class T, int N>
SquareTensor& SquareTensor< T, N >::operator/= ( const T  s)
inline

Definition at line 132 of file SquareTensor.h.

133  {
134  for(int i=0;i<NSQR;i++)
135  _data[i] /= s;
136  return *this;
137  }
T _data[NSQR]
Definition: SquareTensor.h:256
template<class T, int N>
SquareTensor& SquareTensor< T, N >::operator/= ( const SquareTensor< T, N > &  o)
inline

Definition at line 139 of file SquareTensor.h.

140  {
141  *this *= inverse(o);
142  return *this;
143  }
SquareTensor< T, 2 > inverse(const SquareTensor< T, 2 > &a)
Definition: SquareTensor.h:358
template<class T, int N>
bool SquareTensor< T, N >::operator< ( const double  tolerance) const
inline

Definition at line 180 of file SquareTensor.h.

181  {
182  return mag2() < tolerance*tolerance;
183  }
T mag2() const
Definition: SquareTensor.h:172
template<class T, int N>
SquareTensor& SquareTensor< T, N >::operator= ( const T &  s)
inline

Definition at line 81 of file SquareTensor.h.

82  {
83  for(int i=0; i<N; i++)
84  for(int j=0; j<N; j++)
85  (*this)(i,j) = (i==j) ? s : T(0.);
86  return *this;
87  }
template<class T, int N>
SquareTensor& SquareTensor< T, N >::operator= ( const SquareTensor< T, N > &  o)
inline

Definition at line 89 of file SquareTensor.h.

90  {
91  for(int i=0;i<NSQR;i++)
92  _data[i] = o._data[i];
93  return *this;
94  }
T _data[NSQR]
Definition: SquareTensor.h:256
template<class T, int N>
void SquareTensor< T, N >::printFromC ( ostream &  os) const
inline

Definition at line 64 of file SquareTensor.h.

Referenced by operator<<().

65  {
66  os << "[ " ;
67  for(int i=0;i<NSQR;i++)
68  os << _data[i] << " " ;
69  os << "]";
70  }
T _data[NSQR]
Definition: SquareTensor.h:256
template<class T, int N>
static void SquareTensor< T, N >::reduceSum ( T_Scalar sum,
const This_T x 
)
inlinestatic

Definition at line 231 of file SquareTensor.h.

232  {
233  for(int i=0; i<NSQR; i++)
234  NumTypeTraits<T>::reduceSum(sum,x._data[i]);
235  }
template<class T, int N>
static void SquareTensor< T, N >::safeDivide ( SquareTensor< T, N > &  x,
const SquareTensor< T, N > &  y 
)
inlinestatic

Definition at line 237 of file SquareTensor.h.

238  {
239  for(int i=0; i<NSQR; i++)
241  }
T _data[NSQR]
Definition: SquareTensor.h:256
template<class T, int N>
static void SquareTensor< T, N >::setMax ( SquareTensor< T, N > &  x,
const SquareTensor< T, N > &  y 
)
inlinestatic

Definition at line 249 of file SquareTensor.h.

250  {
251  for(int i=0; i<NSQR; i++)
253  }
T _data[NSQR]
Definition: SquareTensor.h:256
template<class T, int N>
static void SquareTensor< T, N >::write ( FILE *  fp,
const SquareTensor< T, N > &  x 
)
inlinestatic

Definition at line 72 of file SquareTensor.h.

73  {
74  for(int i=0; i<NSQR; i++)
75  {
76  NumTypeTraits<T>::write(fp,x[i]);
77  fprintf(fp, " ");
78  }
79  }
template<class T, int N>
void SquareTensor< T, N >::zero ( )
inline

Member Data Documentation


The documentation for this class was generated from the following file: