Memosa-FVM  0.2
ElecOffDiagonalTensor.h
Go to the documentation of this file.
1 // This file os part of FVM
2 // Copyright (c) 2012 FVM Authors
3 // See LICENSE file for terms.
4 
5 #ifndef _ELECOFFDIAGONALTENSOR_H_
6 #define _ELECOFFDIAGONALTENSOR_H_
7 
8 #include "NumType.h"
9 #include "Vector.h"
10 #include <sstream>
11 #include "ElecDiagonalTensor.h"
12 //this structure is used to store the off dianogal tensor in dielectric charging model
13 //the full diag tensor looks like
14 /*
15  | 0 0 0 ... 0 |
16  | 0 0 0 ... 0 |
17  | 0 0 0 ... 0 |
18  | 0 0 0 ... Nc |
19 */
20 // only one element is non-zero. it connects to the diagonal tensor via drift model
21 // thus, a scalar is stored to represent the whole tensor
22 
23 
24 template <class T, int N>
26 {
27 public:
28  enum { TN = N+1 } ;
32 
34  {}
35 
37  {
38  _data = o._data;
39  }
40 
42  {
43  _data = o;
44  }
45 
46  static string getTypeName()
47  {
48  return "ElecOffDiagonalTensor<" + NumTypeTraits<T>::getTypeName() +
49  "," + intAsString(N) +
50  ">";
51  }
52 
53  static int getDimension() {return 1;}
54 
55  static void getShape(int *shp) { *shp = TN;}
56 
57  static int getDataSize()
58  {
60  }
61 
62  T& operator[](int n) {return _data;}
63 
64  const T& operator[](int n) const {return _data;}
65 
66  void printFromC(ostream &os) const
67  {
68  os << "[ " << _data << " " << "]";
69  }
70 
71  static void write(FILE* fp, const ElecOffDiagonalTensor& x)
72  {
74  }
75 
77  {
78  _data = o;
79  return *this;
80  }
81 
83  {
84  _data = o._data;
85  return *this;
86  }
87 
89  {
91  r._data=-_data;
92  return r;
93  }
94 
96  {
97  _data += o._data;
98  return *this;
99  }
100 
102  {
103  _data += s;
104  return *this;
105  }
106 
108  {
109  _data -= o._data;
110  return *this;
111  }
112 
114  {
115  _data -= s;
116  return *this;
117  }
118 
120  {
121  throw CException("operator not defined for elec offdiag /= s");
122  _data /= s;
123  return *this;
124  }
125 
126 
128  {
129  throw CException("no operator defined for /= elec offdiag");
130  }
131 
132 
134  {
135  throw CException("operator not defined for elec offdiag *= s");
136  _data *= s;
137  return *this;
138  }
139 
140 
142  {
143  throw CException("no operator defined for *= elec offdiag");
144  }
145 
146  void zero()
147  {
149  }
150 
151  T mag2() const
152  {
154  r+=_data * _data;
155  return r;
156  }
157 
158  bool operator<(const double tolerance) const
159  {
160  return mag2() < tolerance*tolerance;
161  }
162 
164  {
166  z.zero();
167  return z;
168  }
169 
170  static double doubleMeasure(const ElecOffDiagonalTensor& x)
171  {
172  return 0.0;
173  }
174 
176  {
179 
180  return n;
181  }
182 
184  {
187 
188  return n;
189  }
190 
192  {
193  throw CException("elec offdiag accumlateOneNorm is not defined!");
194  for(int i=0; i<N; i++)
196  }
197 
199  const ElecOffDiagonalTensor& v1)
200  {
201  throw CException("elec offdiag accumlateDotProduct is not defined!");
202  for(int i=0; i<N; i++)
203  NumTypeTraits<T>::accumulateDotProduct(sum[i],v0[i],v1[i]);
204  }
205 
206  static void reduceSum(T_Scalar& sum, const This_T& x)
207  {
208  throw CException(" elec offdiag reduceSume is not defined!");
209  for(int i=0; i<N; i++)
210  NumTypeTraits<T>::reduceSum(sum,x[i]);
211  }
212 
214  {
215  throw CException(" elec offdiag safeDivide is not defined!");
216  for(int i=0; i<N; i++)
217  NumTypeTraits<T>::safeDivide(x[i],y[i]);
218  }
219 
221  {
222  throw CException(" elec offdiag normalize is not defined!");
223  for(int i=0; i<N; i++)
224  NumTypeTraits<T>::normalize(x[i],y[i]);
225  }
226 
228  {
229  throw CException(" elec offdiag setMax is not defined!");
230  for(int i=0; i<N; i++)
231  NumTypeTraits<T>::setMax(x[i],y[i]);
232  }
233 
234 
235 
236  private:
237  T _data;
238 
239 };
240 
241 
242 
243 template<class T, int N>
244 inline ostream& operator<<(ostream &os,
246 {
247  v.printFromC(os);
248  return os;
249 }
250 
251 
252 template<class T, int N>
255 {
256  return ElecOffDiagonalTensor<T,N>(a) += b;
257 }
258 
259 template<class T, int N>
262 {
263  return ElecOffDiagonalTensor<T,N>(a) -= b;
264 }
265 
266 template<class T, int N>
269 {
270  return -ElecOffDiagonalTensor<T,N>(a);
271 }
272 
273 template<class T, int N>
276 {
277  throw CException("no operator defined for diag * diag");
278 }
279 
280 template<class T, int N>
283 {
284  return ElecOffDiagonalTensor<T,N>(a) *= s;
285 }
286 
287 template<class T, int N>
290 {
291  return ElecOffDiagonalTensor<T,N>(a) *= s;
292 }
293 
294 template<class T, int N>
297 {
298  Vector<T,N+1> r;
299  r = 0;
300  r[N] += a[N] * b[N];
301 
302  return r;
303 }
304 
305 template<class T, int N>
308 {
309  return ElecOffDiagonalTensor<T,N>(a) /= s;
310 }
311 
312 template<class T, int N>
315 {
316  Vector<T,N+1> x;
317  x = 0;
318  x[N] = a[N] / b[N];
319  return x;
320 }
321 
322 
323 template<class T, int N>
326 {
327  throw CException("operator not defined for offdiag/offdiag");
328 }
329 
330 
331 
332 template<class T, int N>
335 {
336  throw CException("operator not defined for s/diag");
337 }
338 
339 template<class T, int N>
341 {
342  throw CException("diag to offdiag not defined");
343 }
344 
345 
346 
347 #endif
348 
349 
350 
351 
352 
353 
354 
355 
static void reduceSum(T_Scalar &sum, const This_T &x)
ElecOffDiagonalTensor & operator/=(const T s)
ElecOffDiagonalTensor & operator+=(const ElecOffDiagonalTensor &o)
NumTypeTraits< T >::T_Scalar T_Scalar
Definition: Vector.h:19
static void accumulateDotProduct(ElecOffDiagonalTensor &sum, const ElecOffDiagonalTensor &v0, const ElecOffDiagonalTensor &v1)
static ElecOffDiagonalTensor getNegativeUnity()
ElecOffDiagonalTensor & operator*=(const ElecOffDiagonalTensor &o)
ElecOffDiagonalTensor & operator/=(const ElecOffDiagonalTensor &o)
ElecOffDiagonalTensor & operator=(const T &o)
static void getShape(int *shp)
static void setMax(ElecOffDiagonalTensor &x, const ElecOffDiagonalTensor &y)
static void write(FILE *fp, const ElecOffDiagonalTensor &x)
bool operator<(const double tolerance) const
ElecOffDiagonalTensor & operator=(const ElecOffDiagonalTensor &o)
T DiagToOffDiag(const ElecOffDiagonalTensor< T, N > &x)
void printFromC(ostream &os) const
ElecOffDiagonalTensor< T, N > This_T
ElecOffDiagonalTensor & operator*=(const T s)
const T & operator[](int n) const
ElecOffDiagonalTensor< T, N > operator/(const ElecOffDiagonalTensor< T, N > &a, const T s)
ElecOffDiagonalTensor operator-()
ElecOffDiagonalTensor< T, N > operator*(const ElecOffDiagonalTensor< T, N > &a, const ElecOffDiagonalTensor< T, N > &b)
ElecOffDiagonalTensor< T, N > operator+(const ElecOffDiagonalTensor< T, N > &a, const ElecOffDiagonalTensor< T, N > &b)
ElecOffDiagonalTensor< T, N > operator-(const ElecOffDiagonalTensor< T, N > &a, const ElecOffDiagonalTensor< T, N > &b)
string intAsString(const int i)
Definition: Vector.h:11
ostream & operator<<(ostream &os, const ElecOffDiagonalTensor< T, N > &v)
static ElecOffDiagonalTensor getUnity()
static void normalize(ElecOffDiagonalTensor &x, const ElecOffDiagonalTensor &y)
static void accumulateOneNorm(ElecOffDiagonalTensor &sum, const ElecOffDiagonalTensor &v)
NumTypeTraits< T >::T_BuiltIn T_BuiltIn
ElecOffDiagonalTensor(const ElecOffDiagonalTensor &o)
static void safeDivide(ElecOffDiagonalTensor &x, const ElecOffDiagonalTensor &y)
ElecOffDiagonalTensor & operator-=(const T s)
static double doubleMeasure(const ElecOffDiagonalTensor &x)
ElecOffDiagonalTensor & operator-=(const ElecOffDiagonalTensor &o)
ElecOffDiagonalTensor & operator+=(const T s)
static ElecOffDiagonalTensor getZero()