Heidelberg Educational Numerics Library Version 0.24 (from 9 September 2011)

src/pde.hh

Go to the documentation of this file.
00001 // -*- tab-width: 4; indent-tabs-mode: nil -*-
00002 #ifndef HDNUM_PDE_HH
00003 #define HDNUM_PDE_HH
00004 
00005 #include<vector>
00006 #include "newton.hh"
00007 
00012 namespace hdnum {
00013 
00022   template<class M>
00023   class StationarySolver
00024   {
00025   public:
00027     typedef typename M::size_type size_type;
00028 
00030     typedef typename M::time_type time_type;
00031 
00033     typedef typename M::number_type number_type;
00034 
00036     StationarySolver (const M& model_)
00037       : model(model_), x(model.size())
00038     {
00039     }
00040 
00042     void solve ()
00043     {
00044       const size_t n_dofs = model.size();
00045   
00046       DenseMatrix<number_type> A(n_dofs,n_dofs,0.);
00047       Vector<number_type> b(n_dofs,0.);
00048 
00049       Vector<number_type> s(n_dofs);              // scaling factors
00050       Array<size_t> p(n_dofs);                 // row permutations
00051       Array<size_t> q(n_dofs);                 // column permutations
00052 
00053       number_type t = 0.;
00054 
00055       x = 0.;
00056 
00057       model.f_x(t, x, A);
00058       model.f(t, x, b);
00059 
00060       b*=-1.;
00061 
00062       row_equilibrate(A,s);                         // equilibrate rows
00063       lr_fullpivot(A,p,q);                          // LR decomposition of A
00064       apply_equilibrate(s,b);                       // equilibration of right hand side
00065       permute_forward(p,b);                         // permutation of right hand side
00066       solveL(A,b,b);                                // forward substitution
00067       solveR(A,x,b);                                // backward substitution
00068       permute_backward(q,x);                        // backward permutation
00069     }
00070 
00072     const Vector<number_type>& get_state () const
00073     {
00074       return x;
00075     }
00076 
00078     size_type get_order () const
00079     {
00080       return 2;
00081     }
00082     
00083   private:
00084     const M& model;
00085     Vector<number_type> x;
00086   };
00087 
00088 
00090   template<class N, class G>
00091   inline void pde_gnuplot2d (const std::string& fname, const Vector<N> solution, 
00092                              const G & grid)
00093   {
00094 
00095     const std::vector<Vector<N> > coords = grid.getNodeCoordinates();
00096     Vector<typename G::size_type> gsize = grid.getGridSize();
00097 
00098     std::fstream f(fname.c_str(),std::ios::out);
00099     // f << "set dgrid3d ";
00100 
00101     // f << gsize[0] << "," << gsize[1] << std::endl;
00102 
00103     // f << "set hidden3d" << std::endl;
00104     f << "set ticslevel 0" << std::endl;
00105     f << "splot \"-\" using 1:2:3 with points" << std::endl;
00106     f << "#" << std::endl;
00107     for (typename Vector<N>::size_type n=0; n<solution.size(); n++)
00108       {
00109         for (typename Vector<N>::size_type d=0; d<coords[n].size(); d++){
00110           f << std::scientific << std::showpoint 
00111             << std::setprecision(16) << coords[n][d] << " ";
00112         }
00113 
00114         f << std::scientific << std::showpoint 
00115           << std::setprecision(solution.precision()) << solution[n];
00116 
00117         f << std::endl;
00118       }
00119     f << "end" << std::endl;
00120     f << "pause -1" << std::endl;
00121     f.close();
00122   }
00123 
00124 
00125 }
00126 #endif