Memosa-FVM  0.2
OneDConduction.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 _ONEDCONDUCTION_H_
6 #define _ONEDCONDUCTION_H_
7 
8 #include "Array.h"
9 
10 template<class T>
11 void TDMA(Array<T>& ap, Array<T>& ae, Array<T>& aw, Array<T>& b, Array<T>& x)
12 {
13  const int n=ap.getLength();
14  for(int i=1; i<n; i++)
15  {
16  const T m(aw[i]/ap[i-1]);
17  ap[i] -= m*ae[i-1];
18  b[i] -= m*b[i-1];
19  }
20  x[n-1] = -b[n-1]/ap[n-1];
21  for(int i=n-2; i>=0; i--)
22  x[i] = (b[i] - ae[i]*x[i+1])/ap[i];
23 }
24 
25 template<class T>
27 {
28 public:
29  OneDConduction(const int nCells, const T& kConst) :
30  _nCells(nCells),
31  _kConst(kConst),
32  _xL(0),
33  _xR(1),
34  _x(new Array<T>(_nCells))
35  {}
36 
37  void solve()
38  {
39  Array<T> ae(_nCells);
40  Array<T> aw(_nCells);
41  Array<T> ap(_nCells);
42  Array<T> b(_nCells);
43 
44  ae = T(0.);
45  aw = T(0.);
46  ap = T(0.);
47  b = T(0.);
48 
49  const T dx = T(1.0)/_nCells;
50 
51  for(int nf=0; nf<=_nCells; nf++)
52  {
53  int c0 = nf-1;
54  int c1 = nf;
55 
56  const T xf = dx*nf;
57  const T kf = 1.0 + _kConst*xf;
58  T coeff = kf/dx;
59  if (nf==0)
60  {
61  coeff *= 2.;
62  c0 = 0;
63  b[c0] += coeff*_xL;
64  ap[c0] -= coeff;
65  }
66  else if (nf==_nCells)
67  {
68  coeff *=2;
69  b[c0] += coeff*_xR;
70  ap[c0] -= coeff;
71  }
72  else
73  {
74  ae[c0] = coeff;
75  aw[c1] = coeff;
76  ap[c0] -= coeff;
77  ap[c1] -= coeff;
78  }
79  }
80 
81  cout << " ae[0] " << ae[0] << endl;
82  TDMA(ap,ae,aw,b,*_x);
83  }
84 
85  boost::shared_ptr<Array<T> > getSolution() {return _x;}
86 
87 private:
88  const int _nCells;
90  T _xL;
91  T _xR;
92  boost::shared_ptr<Array<T> > _x;
93 
94 };
95 #endif
const int _nCells
boost::shared_ptr< Array< T > > _x
boost::shared_ptr< Array< T > > getSolution()
void TDMA(Array< T > &ap, Array< T > &ae, Array< T > &aw, Array< T > &b, Array< T > &x)
Definition: Array.h:14
OneDConduction(const int nCells, const T &kConst)
int getLength() const
Definition: Array.h:87