~njansson/dolfin/hpc

« back to all changes in this revision

Viewing changes to sandbox/dg/cg-dg-comparison/cg/main.cpp

  • Committer: Johannes Ring
  • Date: 2008-03-05 22:43:06 UTC
  • Revision ID: johannr@simula.no-20080305224306-2npsdyhfdpl2esji
The BIG commit!

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <dolfin.h>
 
2
#include "Poisson.h"
 
3
 
 
4
using namespace dolfin;
 
5
 
 
6
int main()
 
7
{
 
8
  // Source term
 
9
  class Source : public Function
 
10
  {
 
11
  public:
 
12
    
 
13
    Source(Mesh& mesh) : Function(mesh) {}
 
14
 
 
15
    real eval(const real* x) const
 
16
    {
 
17
      real dx = x[0] - 0.5;
 
18
      real dy = x[1] - 0.5;
 
19
      return 500.0*exp(-(dx*dx + dy*dy)/0.02);
 
20
    }
 
21
 
 
22
  };
 
23
 
 
24
  // Create mesh
 
25
  UnitCube mesh(8, 8, 8);
 
26
 
 
27
  // Create functions
 
28
  Source f(mesh);
 
29
 
 
30
  FacetNormal n(mesh);
 
31
  InvMeshSize h(mesh);
 
32
 
 
33
  // Define PDE
 
34
  PoissonBilinearForm a(n,h);
 
35
  PoissonLinearForm L(f);
 
36
  LinearPDE pde(a, L, mesh);
 
37
 
 
38
  // Solve PDE
 
39
  Function u;
 
40
  pde.set("PDE linear solver", "direct");
 
41
  pde.solve(u);
 
42
 
 
43
  // Plot solution
 
44
  plot(u);
 
45
 
 
46
  // Save solution to file
 
47
  File file("poisson.pvd");
 
48
  file << u;
 
49
 
 
50
  return 0;
 
51
}