~njansson/dolfin/hpc

« back to all changes in this revision

Viewing changes to demo/function/cpp/main.cpp

  • Committer: Anders Logg
  • Date: 2008-03-17 14:59:22 UTC
  • mto: This revision was merged to the branch mainline in revision 2414.
  • Revision ID: logg@simula.no-20080317145922-83cfli6k6ev22qu7
Implement evaluation of Functions at arbitrary points.
Now, f.eval(x) works for any x inside the mesh. Broken
in Python since FFC does not generate evaluate_basis
by default.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (C) 2008 Anders Logg.
 
2
// Licensed under the GNU LGPL Version 2.1.
 
3
//
 
4
// First added:  2008-03-11
 
5
// Last changed: 2007-03-17
 
6
//
 
7
// Testing evaluation at arbitrary points
 
8
 
 
9
#include <dolfin.h>
 
10
#include "Projection.h"
 
11
 
 
12
using namespace dolfin;
 
13
 
 
14
class F : public Function
 
15
{
 
16
public:
 
17
  
 
18
  F(Mesh& mesh) : Function(mesh) {}
 
19
 
 
20
  real eval(const real* x) const
 
21
  {
 
22
    return sin(3.0*x[0])*sin(3.0*x[1])*sin(3.0*x[2]);
 
23
  }
 
24
  
 
25
};
 
26
 
 
27
int main()
 
28
{
 
29
  // Create mesh and a point in the mesh
 
30
  UnitCube mesh(8, 8, 8);
 
31
  real x[3] = {0.3, 0.3, 0.3};
 
32
  real values[1] = {0.0};
 
33
 
 
34
  // A user-defined function
 
35
  F f(mesh);
 
36
 
 
37
  // Project to a discrete function
 
38
  ProjectionBilinearForm a;
 
39
  ProjectionLinearForm L(f);
 
40
  LinearPDE pde(a, L, mesh);
 
41
  Function g;
 
42
  pde.solve(g);
 
43
 
 
44
  // Evaluate user-defined function f
 
45
  message("f(x) = %g", f.eval(x));
 
46
 
 
47
  // Evaluate discrete function g (projection of f)
 
48
  message("g(x) = %g", g.eval(x));
 
49
}