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

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Johannes Ring
  • Date: 2008-09-16 08:41:20 UTC
  • Revision ID: james.westby@ubuntu.com-20080916084120-i8k3u6lhx3mw3py3
Tags: upstream-0.9.2
ImportĀ upstreamĀ versionĀ 0.9.2

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: 2008-11-19
 
6
//
 
7
// Demonstrating function 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
  void eval(double* values, const double* x) const
 
18
  {
 
19
    values[0] = sin(3.0*x[0])*sin(3.0*x[1])*sin(3.0*x[2]);
 
20
  }
 
21
};
 
22
 
 
23
int main()
 
24
{
 
25
  // Create mesh and a point in the mesh
 
26
  UnitCube mesh(8, 8, 8);
 
27
  double x[3] = {0.31, 0.32, 0.33};
 
28
 
 
29
  // A user-defined function
 
30
  F f;
 
31
 
 
32
  // Project to a discrete function
 
33
  ProjectionFunctionSpace V(mesh);
 
34
  ProjectionBilinearForm a(V, V);
 
35
  ProjectionLinearForm L(V);
 
36
  L.f = f;
 
37
  VariationalProblem pde(a, L);
 
38
  Function g;
 
39
  pde.solve(g);
 
40
 
 
41
  // Evaluate user-defined function f
 
42
  double value = 0.0;
 
43
  f.eval(&value, x);
 
44
  message("f(x) = %g", value);
 
45
 
 
46
  // Evaluate discrete function g (projection of f)
 
47
  g.eval(&value, x);
 
48
  message("g(x) = %g", value);
 
49
}