~njansson/dolfin/hpc

« back to all changes in this revision

Viewing changes to test/unit/function/cpp/test.cpp

  • Committer: Niclas Jansson
  • Date: 2011-06-14 07:30:24 UTC
  • Revision ID: njansson@csc.kth.se-20110614073024-ygy9rpk7jj0dxncv
Cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright (C) 2007 Anders Logg.
2
 
// Licensed under the GNU LGPL Version 2.1.
3
 
//
4
 
// Modified by Garth N. Wells, 2008.
5
 
//
6
 
// First added:  2007-05-24
7
 
// Last changed: 2008-07-17
8
 
//
9
 
// Unit tests for the function library
10
 
 
11
 
#include <dolfin.h>
12
 
#include <dolfin/common/unittest.h>
13
 
#include "Projection.h"
14
 
 
15
 
using namespace dolfin;
16
 
 
17
 
class Eval : public CppUnit::TestFixture
18
 
{
19
 
  CPPUNIT_TEST_SUITE(Eval);
20
 
  CPPUNIT_TEST(testArbitraryEval);
21
 
  CPPUNIT_TEST_SUITE_END();
22
 
 
23
 
public: 
24
 
 
25
 
  void testArbitraryEval()
26
 
  {
27
 
    class F0 : public Function
28
 
    {
29
 
    public:
30
 
      F0(Mesh& mesh) : Function(mesh) {}
31
 
      void eval(real* values, const real* x) const
32
 
      { values[0] = sin(3.0*x[0])*sin(3.0*x[1])*sin(3.0*x[2]); } 
33
 
    };
34
 
 
35
 
    class F1 : public Function
36
 
    {
37
 
    public:
38
 
      F1(Mesh& mesh) : Function(mesh) {}
39
 
      void eval(real* values, const real* x) const
40
 
      { values[0] = 1.0 + 3.0*x[0] + 4.0*x[1] + 0.5*x[2]; } 
41
 
    };
42
 
 
43
 
    UnitCube mesh(8, 8, 8);
44
 
    real x[3] = {0.3, 0.3, 0.3};
45
 
    real u[1] = {0.0};
46
 
    real v[1] = {0.0};
47
 
  
48
 
    // User-defined functions (one from finite element space, one not)
49
 
    F0 f0(mesh);
50
 
    F1 f1(mesh);
51
 
 
52
 
    // Test evaluation of a user-defined function
53
 
    f0.eval(v, x);
54
 
    CPPUNIT_ASSERT(v[0] == sin(3.0*x[0])*sin(3.0*x[1])*sin(3.0*x[2]));
55
 
 
56
 
#ifdef HAS_GTS
57
 
    // Test evaluation of a discrete function
58
 
    ProjectionBilinearForm a;
59
 
    ProjectionLinearForm L(f1);
60
 
    LinearPDE pde(a, L, mesh);
61
 
    Function g;
62
 
    pde.solve(g);
63
 
 
64
 
    const real tol = 1.0e-6;
65
 
    f1.eval(u, x);
66
 
    g.eval(v, x);
67
 
    CPPUNIT_ASSERT( std::abs(u[0]-v[0]) < tol );
68
 
#endif
69
 
  }
70
 
};
71
 
 
72
 
CPPUNIT_TEST_SUITE_REGISTRATION(Eval);
73
 
 
74
 
int main()
75
 
{
76
 
  DOLFIN_TEST;
77
 
}