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

« back to all changes in this revision

Viewing changes to demo/pde/functional/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-09-19
5
 
// Last changed: 2008-12-13
 
5
// Last changed: 2009-10-06
6
6
//
7
7
// This demo program computes the value of the functional
8
8
//
16
16
 
17
17
#include <dolfin.h>
18
18
#include "EnergyNorm.h"
19
 
  
 
19
 
20
20
using namespace dolfin;
21
21
 
22
22
int main()
23
23
{
24
24
  // The function v
25
 
  class MyFunction : public Function
 
25
  class MyFunction : public Expression
26
26
  {
27
 
  public: 
 
27
  public:
28
28
 
29
 
    MyFunction(const FunctionSpace& V) : Function(V) {}
 
29
    MyFunction() : Expression(2) {}
30
30
 
31
31
    void eval(double* values, const double* x) const
32
32
    {
33
33
      values[0] = sin(x[0]) + cos(x[1]);
34
34
    }
35
 
    
 
35
 
36
36
  };
37
37
 
38
38
  // Define functional
39
39
  UnitSquare mesh(16, 16);
40
 
  EnergyNormCoefficientSpace V(mesh);
41
 
  MyFunction v(V);
42
 
  EnergyNormFunctional M;
43
 
  M.v = v;
 
40
  MyFunction v;
 
41
  EnergyNorm::Functional M(mesh, v);
44
42
 
45
43
  // Evaluate functional
46
44
  double approximate_value = assemble(M);
48
46
  // Compute exact value
49
47
  double exact_value = 2.0 + 2.0*sin(1.0)*(1.0 - cos(1.0));
50
48
 
51
 
  message("The energy norm of v is: %.15g", approximate_value);
52
 
  message("It should be:            %.15g", exact_value);
53
 
  
 
49
  info("The energy norm of v is: %.15g", approximate_value);
 
50
  info("It should be:            %.15g", exact_value);
 
51
 
54
52
  return 0;
55
53
}