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

« back to all changes in this revision

Viewing changes to doc/usrman/d-dx.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
// TODO: extensions
 
2
//  approx P1 -> P0 and P2 -> P1d
 
3
//  option -x i ==> "d_dxi" i=1,2,3
 
4
//
 
5
/*P:d_dx
 
6
NAME: Computing the Gradient
 
7
\cindex{gradient}
 
8
\cindex{discontinuous approximation}
 
9
\cindex{block-diagonal matrix}
 
10
\foindex{mass}
 
11
 
 
12
   Remark that the gradient ${\bf q}_h = \nabla u_h$ of a continuous picewise linear function $u_h$
 
13
   is a discontinuous piecewise constant function.
 
14
   Conversely, the gradient of a continuous picewise quadratic
 
15
   function is a discontinuous piecewise linear function.
 
16
\subsection{Formulation}
 
17
   For all $i=1\ldots N$, the $i$-th component $q_{h,i}$ of the gradient belongs to the space:
 
18
   $$
 
19
       T_h \ \{ \phi_h \in L^2(\Omega); \ 
 
20
           \phi_{h/K} \in P_{k-1}, \ 
 
21
           \forall K \in {\cal T}_h 
 
22
           \}
 
23
   $$
 
24
   By introducing the two following bilinear forms:
 
25
   $$
 
26
       m_T(\psi_h,\phi_h) = \int_\Omega \psi_h \phi_h \, dx
 
27
   $$
 
28
   $$
 
29
       b_i(u_h,\phi_h) = \int_\Omega \frac{\partial u_h}{\partial x_i} \phi_h \, dx
 
30
   $$
 
31
   the gradient satisfies the following variational formulation:
 
32
   $$
 
33
       m_T(q_{h,i},\phi_h) = b_i(u_h, \phi_h), \ \forall \psi_h \in Th
 
34
   $$
 
35
   Remark that the matrix associated to the $m_T(.,,)$ bilinear form 
 
36
   is block-diagonal. Each block is associated to an element, and can
 
37
   be inverted at the element level.
 
38
   The following code uses this property on step (e), 
 
39
   as the \code{"inv\\_mass"} form.
 
40
END:
 
41
*/
 
42
//<d_dx:
 
43
#include "rheolef/rheolef.h"
 
44
using namespace std;
 
45
 
 
46
string get_approx_grad (const space &Vh)
 
47
{
 
48
    string Pk = Vh.get_approx();
 
49
    if (Pk == "P1") return "P0";
 
50
    if (Pk == "P2") return "P1d";
 
51
    cerr << "unexpected approximation " << Pk << endl;
 
52
    exit (1);
 
53
}
 
54
int main(int argc, char**argv)
 
55
{
 
56
    field uh;
 
57
    cin >> uh;
 
58
    space Vh      = uh.get_space();
 
59
    geo   omega_h = Vh.get_geo();
 
60
    string approx_grad = get_approx_grad(Vh);
 
61
    space Th (omega_h, approx_grad);
 
62
    form b(Vh, Th, "d_dx0");
 
63
    form inv_mass (Th, Th, "inv_mass");
 
64
    field du_dx0 = inv_mass*(b*uh);
 
65
    int digits10 = numeric_limits<Float>::digits10;
 
66
    cout << setprecision(digits10) << du_dx0;
 
67
}
 
68
//>d_dx: