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

« back to all changes in this revision

Viewing changes to demo/pde/periodic/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:  2007-07-11
5
 
// Last changed: 2008-12-12
 
5
// Last changed: 2009-10-05
6
6
//
7
7
// This demo program solves Poisson's equation,
8
8
//
13
13
 
14
14
#include <dolfin.h>
15
15
#include "Poisson.h"
16
 
  
 
16
 
17
17
using namespace dolfin;
18
18
 
19
19
int main()
20
20
{
21
21
  // Source term
22
 
  class Source : public Function
 
22
  class Source : public Expression
23
23
  {
 
24
  public:
 
25
 
 
26
    Source() : Expression(2) {}
 
27
 
24
28
    void eval(double* values, const double* x) const
25
29
    {
26
30
      double dx = x[0] - 0.5;
27
31
      double dy = x[1] - 0.5;
28
32
      values[0] = x[0]*sin(5.0*DOLFIN_PI*x[1]) + 1.0*exp(-(dx*dx + dy*dy)/0.02);
29
33
    }
 
34
 
30
35
  };
31
36
 
32
37
  // Sub domain for Dirichlet boundary condition
60
65
  Source f;
61
66
 
62
67
  // Define PDE
63
 
  PoissonFunctionSpace V(mesh);
64
 
  PoissonBilinearForm a(V, V);
65
 
  PoissonLinearForm L(V);
 
68
  Poisson::FunctionSpace V(mesh);
 
69
  Poisson::BilinearForm a(V, V);
 
70
  Poisson::LinearForm L(V);
66
71
  L.f = f;
67
72
 
68
73
  // Create Dirichlet boundary condition
69
 
  Constant u0(0.0);
 
74
  Constant u0(mesh, 0.0);
70
75
  DirichletBoundary dirichlet_boundary;
71
76
  DirichletBC bc0(V, u0, dirichlet_boundary);
72
 
  
 
77
 
73
78
  // Create periodic boundary condition
74
79
  PeriodicBoundary periodic_boundary;
75
80
  PeriodicBC bc1(V, periodic_boundary);
76
81
 
77
82
  // Collect boundary conditions
78
 
  std::vector<BoundaryCondition*> bcs;
 
83
  std::vector<const BoundaryCondition*> bcs;
79
84
  bcs.push_back(&bc0); bcs.push_back(&bc1);
80
85
 
81
86
  // Define PDE
82
87
  VariationalProblem pde(a, L, bcs);
83
88
 
84
89
  // Solve PDE
85
 
  Function u;
 
90
  Function u(V);
86
91
  pde.solve(u);
87
92
 
88
93
  // Plot solution