Heidelberg Educational Numerics Library Version 0.27 (from 15 March 2021)
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
12namespace 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
37 : model(model_), x(model.size())
38 {
39 }
40
42 void solve ()
43 {
44 const size_t n_dofs = model.size();
45
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
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();
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
Class with mathematical matrix operations.
Definition densematrix.hh:33
std::size_t precision() const
get data precision for pretty-printing
Definition densematrix.hh:188
Stationary problem solver. E.g. for elliptic problmes.
Definition pde.hh:24
const Vector< number_type > & get_state() const
get current state
Definition pde.hh:72
StationarySolver(const M &model_)
constructor stores reference to the model
Definition pde.hh:36
M::number_type number_type
export number_type
Definition pde.hh:33
M::time_type time_type
export time_type
Definition pde.hh:30
size_type get_order() const
return consistency order of the method
Definition pde.hh:78
void solve()
do one step
Definition pde.hh:42
M::size_type size_type
export size_type
Definition pde.hh:27
std::size_t size_type
Type used for array indices.
Definition vector.hh:34
void permute_forward(const Vector< std::size_t > &p, Vector< T > &b)
apply permutations to a right hand side vector
Definition lr.hh:160
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:171
void apply_equilibrate(Vector< T > &s, Vector< T > &b)
apply row equilibration to right hand side vector
Definition lr.hh:203
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:233
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:215
void row_equilibrate(DenseMatrix< T > &A, Vector< T > &s)
perform a row equilibration of a matrix; return scaling for later use
Definition lr.hh:182
Newton's method with line search.
void pde_gnuplot2d(const std::string &fname, const Vector< N > solution, const G &grid)
gnuplot output for stationary state
Definition pde.hh:91