~ubuntu-branches/ubuntu/maverick/dolfin/maverick

« back to all changes in this revision

Viewing changes to demo/pde/dg/poisson/cpp/main.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Johannes Ring
  • Date: 2009-10-12 14:13:18 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20091012141318-hkbxl0sq555vqv7d
Tags: 0.9.4-1
* New upstream release. This version cleans up the design of the
  function class by adding a new abstraction for user-defined
  functions called Expression. A number of minor bugfixes and
  improvements have also been made.
* debian/watch: Update for new flat directory structure.
* Update debian/copyright.
* debian/rules: Use explicit paths to PETSc 3.0.0 and SLEPc 3.0.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
// Licensed under the GNU LGPL Version 2.1.
3
3
//
4
4
// First added:  2006-12-05
5
 
// Last changed: 2008-12-18
 
5
// Last changed: 2009-10-05
6
6
//
7
7
// This demo program solves Poisson's equation,
8
8
//
21
21
 
22
22
#include <dolfin.h>
23
23
#include "Poisson.h"
24
 
#include "P1Projection.h"
25
24
 
26
25
using namespace dolfin;
27
26
 
28
27
int main()
29
28
{
30
29
  // Source term
31
 
  class Source : public Function
 
30
  class Source : public Expression
32
31
  {
 
32
  public:
 
33
 
 
34
    Source() : Expression(2) {}
 
35
 
33
36
    void eval(double* values, const double* x) const
34
37
    {
35
38
      double dx = x[0] - 0.5;
36
39
      double dy = x[1] - 0.5;
37
40
      values[0] = 500.0*exp(-(dx*dx + dy*dy)/0.02);
38
41
    }
 
42
 
39
43
  };
40
 
 
 
44
 
41
45
  // Create mesh
42
46
  UnitSquare mesh(24, 24);
43
47
 
44
 
  dolfin_set("linear algebra backend", "uBLAS");
 
48
  // Use uBLAS
 
49
  parameters["linear_algebra_backend"] = "uBLAS";
45
50
 
46
51
  // Create functions
47
52
  Source f;
48
 
  FacetNormal n;
49
 
  AvgMeshSize h;
 
53
  CellSize h(mesh);
50
54
 
51
55
  // Create funtion space
52
 
  PoissonFunctionSpace V(mesh);
 
56
  Poisson::FunctionSpace V(mesh);
53
57
 
54
58
  // Define forms and attach functions
55
 
  PoissonBilinearForm a(V, V);
56
 
  PoissonLinearForm L(V);
57
 
  a.n = n; a.h = h; L.f = f;
58
 
 
59
 
  // Create PDE
60
 
  VariationalProblem pde(a, L);
61
 
  pde.set("symmetric", true);
62
 
 
63
 
  // Solve PDE
64
 
  Function u;
65
 
  pde.solve(u);
66
 
 
67
 
  // Plot solution projected
 
59
  Poisson::BilinearForm a(V, V);
 
60
  Poisson::LinearForm L(V);
 
61
  a.h = h; L.f = f;
 
62
 
 
63
  // Create variational problem
 
64
  VariationalProblem problem(a, L);
 
65
  //problem.parameters["symmetric"] = true;
 
66
 
 
67
  // Solve variational problem
 
68
  Function u(V);
 
69
  problem.solve(u);
 
70
 
 
71
  // Plot solution
68
72
  plot(u);
69
73
 
70
74
  // Save solution in VTK format