~ubuntu-branches/ubuntu/trusty/rheolef/trusty-proposed

« back to all changes in this revision

Viewing changes to doc/usrman/dirichlet-nh-error.cc

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme
  • Date: 2010-06-12 09:08:59 UTC
  • Revision ID: james.westby@ubuntu.com-20100612090859-8gpm2gc7j3ab43et
Tags: upstream-5.89
ImportĀ upstreamĀ versionĀ 5.89

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*P:dirichlet-nh-error
 
2
NAME: Error analysis (@PAKAGE@-@VERSION@)
 
3
\cindex{error analysis}
 
4
\foindex{mass}
 
5
PRINCIPE:
 
6
  Since the solution $u$ is regular, the following error estimates
 
7
  holds:
 
8
  $$
 
9
      \Vert u - u_h \Vert_{0,2,\Omega} \approx {\cal O}(h^{k+1})  
 
10
  $$
 
11
  $$
 
12
      \Vert u - u_h \Vert_{0,\infty,\Omega} \approx O(h^{k+1})  
 
13
  $$
 
14
  providing the approximate solution $u_h$ uses
 
15
  $P_k$ continuous finite element method, $k \geq 1$.
 
16
  Here, $\Vert.\Vert_{0,2,\Omega}$ and  $\Vert.\Vert_{0,\infty,\Omega}$
 
17
  denotes as usual the $L^2(\Omega)$ and $L^\infty(\Omega)$ norms.
 
18
 
 
19
  By denoting $\pi_h$ the Lagrange interpolation operator,
 
20
  the triangular inequality leads to:
 
21
  $$
 
22
      \Vert u - u_h \Vert_{0,2,\Omega}
 
23
      \leq
 
24
      \Vert u - \pi_h u \Vert_{0,2,\Omega}
 
25
      +
 
26
      \Vert u_h - \pi_h u \Vert_{0,2,\Omega}
 
27
  $$
 
28
  Since $\Vert u - \pi_h u \Vert_{0,2,\Omega} \approx O(h^{k+1})$,
 
29
  we have just to check the $\Vert u_h - \pi_h u \Vert_{0,2,\Omega}$
 
30
  error term.
 
31
 
 
32
END:
 
33
*/
 
34
 
 
35
//<dirichlet-nh-error:
 
36
#include "rheolef/rheolef.h"
 
37
using namespace std;
 
38
 
 
39
Float u (const point& x) { return sin(x[0]+x[1]+x[2]); }
 
40
 
 
41
int main(int argc, char**argv)
 
42
{
 
43
    field u_h;
 
44
    cin >> u_h;
 
45
    space Vh = u_h.get_space();
 
46
    field pi_h_u = interpolate(Vh, u);
 
47
    field eh = pi_h_u - u_h;
 
48
    form m(Vh, Vh, "mass");
 
49
    cout << "error_inf "  << eh.max_abs()       << endl;
 
50
    cout << "error_l2  "  << sqrt(m(eh,eh)) << endl;
 
51
    return 0;
 
52
}
 
53
//>dirichlet-nh-error:
 
54
/*P:dirichlet-nh-error
 
55
RUNNING THE PROGRAM:
 
56
  Remarks on step~(b) the use of the \code{get\_space} member
 
57
  function.
 
58
  Thus, the previous implementation does not depend upon
 
59
  the degree of the polynomial approximation.
 
60
 
 
61
  After compilation, run the code by using the command:
 
62
  \begin{verbatim}
 
63
        dirichlet-nh square-h=0.1.geo P1 | dirichlet-nh-error
 
64
  \end{verbatim}
 
65
 
 
66
  The two errors in $L^\infty$ and $L^2$ are printed 
 
67
  for a $h=0.1$ quasi-uniform mesh.
 
68
 
 
69
  Let $nelt$ denotes the number of elements in the mesh.
 
70
  Since the mesh is quasi-uniform, we have
 
71
  $h \approx nelt^{\frac{1}{N}}$. Here $N=2$ for our
 
72
  bidimensionnal mesh.
 
73
  The figure~\ref{fig-dirichlet-nh-err} plots in logarithmic scale the
 
74
  error versus $nelt^{\frac{1}{2}}$
 
75
  for both $P_1$ (on the left) and $P_2$ (on the right) 
 
76
  approximations.
 
77
 
 
78
  % latex2html does not support tabular in figures yet...
 
79
  \begin{figure}[H]
 
80
    \begin{center}
 
81
      \begin{tabular}{cc}
 
82
        \hbox to -4cm {\hss} \input{demo2-P1-uniform.tex}
 
83
        &
 
84
        \hbox to -4cm {\hss} \input{demo2-P2-uniform.tex}
 
85
      \end{tabular}
 
86
    \end{center}
 
87
    \caption{Error analysis in $L^2$ and $L^\infty$ norms.}
 
88
    \label{fig-dirichlet-nh-err}
 
89
  \end{figure}
 
90
 
 
91
END:
 
92
*/