Heidelberg Educational Numerics Library  Version 0.24 (from 9 September 2011)
pde.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil -*-
2 #ifndef HDNUM_PDE_HH
3 #define HDNUM_PDE_HH
4 
5 #include<vector>
6 #include "newton.hh"
7 
12 namespace hdnum {
13 
22  template<class M>
24  {
25  public:
27  typedef typename M::size_type size_type;
28 
30  typedef typename M::time_type time_type;
31 
33  typedef typename M::number_type number_type;
34 
36  StationarySolver (const M& model_)
37  : model(model_), x(model.size())
38  {
39  }
40 
42  void solve ()
43  {
44  const size_t n_dofs = model.size();
45 
46  DenseMatrix<number_type> A(n_dofs,n_dofs,0.);
47  Vector<number_type> b(n_dofs,0.);
48 
49  Vector<number_type> s(n_dofs); // scaling factors
50  Vector<size_t> p(n_dofs); // row permutations
51  Vector<size_t> q(n_dofs); // column permutations
52 
53  number_type t = 0.;
54 
55  x = 0.;
56 
57  model.f_x(t, x, A);
58  model.f(t, x, b);
59 
60  b*=-1.;
61 
62  row_equilibrate(A,s); // equilibrate rows
63  lr_fullpivot(A,p,q); // LR decomposition of A
64  apply_equilibrate(s,b); // equilibration of right hand side
65  permute_forward(p,b); // permutation of right hand side
66  solveL(A,b,b); // forward substitution
67  solveR(A,x,b); // backward substitution
68  permute_backward(q,x); // backward permutation
69  }
70 
73  {
74  return x;
75  }
76 
78  size_type get_order () const
79  {
80  return 2;
81  }
82 
83  private:
84  const M& model;
86  };
87 
88 
90  template<class N, class G>
91  inline void pde_gnuplot2d (const std::string& fname, const Vector<N> solution,
92  const G & grid)
93  {
94 
95  const std::vector<Vector<N> > coords = grid.getNodeCoordinates();
96  Vector<typename G::size_type> gsize = grid.getGridSize();
97 
98  std::fstream f(fname.c_str(),std::ios::out);
99  // f << "set dgrid3d ";
100 
101  // f << gsize[0] << "," << gsize[1] << std::endl;
102 
103  // f << "set hidden3d" << std::endl;
104  f << "set ticslevel 0" << std::endl;
105  f << "splot \"-\" using 1:2:3 with points" << std::endl;
106  f << "#" << std::endl;
107  for (typename Vector<N>::size_type n=0; n<solution.size(); n++)
108  {
109  for (typename Vector<N>::size_type d=0; d<coords[n].size(); d++){
110  f << std::scientific << std::showpoint
111  << std::setprecision(16) << coords[n][d] << " ";
112  }
113 
114  f << std::scientific << std::showpoint
115  << std::setprecision(solution.precision()) << solution[n];
116 
117  f << std::endl;
118  }
119  f << "end" << std::endl;
120  f << "pause -1" << std::endl;
121  f.close();
122  }
123 
124 
125 }
126 #endif
void solve()
do one step
Definition: pde.hh:42
void lr_fullpivot(DenseMatrix< T > &A, Vector< std::size_t > &p, Vector< std::size_t > &q)
lr decomposition of A with full pivoting
Definition: lr.hh:107
void permute_backward(const Vector< std::size_t > &q, Vector< T > &z)
apply permutations to a solution vector
Definition: lr.hh:176
void solveR(const DenseMatrix< T > &A, Vector< T > &x, const Vector< T > &b)
Assume R = upper triangle of A and solve R x = b.
Definition: lr.hh:243
M::size_type size_type
export size_type
Definition: pde.hh:27
std::size_t precision() const
get data precision for pretty-printing
Definition: vector.hh:422
void row_equilibrate(DenseMatrix< T > &A, Vector< T > &s)
perform a row equilibration of a matrix; return scaling for later use
Definition: lr.hh:192
Stationary problem solver. E.g. for elliptic problmes.
Definition: pde.hh:23
void apply_equilibrate(Vector< T > &s, Vector< T > &b)
apply row equilibration to right hand side vector
Definition: lr.hh:213
void solveL(const DenseMatrix< T > &A, Vector< T > &x, const Vector< T > &b)
Assume L = lower triangle of A with l_ii=1, solve L x = b.
Definition: lr.hh:225
Newton&#39;s method with line search.
size_type get_order() const
return consistency order of the method
Definition: pde.hh:78
void pde_gnuplot2d(const std::string &fname, const Vector< N > solution, const G &grid)
gnuplot output for stationary state
Definition: pde.hh:91
M::number_type number_type
export number_type
Definition: pde.hh:33
void permute_forward(const Vector< std::size_t > &p, Vector< T > &b)
apply permutations to a right hand side vector
Definition: lr.hh:160
Definition: densematrix.hh:21
const Vector< number_type > & get_state() const
get current state
Definition: pde.hh:72
std::size_t size_type
Type used for array indices.
Definition: vector.hh:32
StationarySolver(const M &model_)
constructor stores reference to the model
Definition: pde.hh:36
M::time_type time_type
export time_type
Definition: pde.hh:30