1
// Copyright (C) 2007 Anders Logg.
2
// Licensed under the GNU LGPL Version 2.1.
4
// Modified by Garth N. Wells, 2008.
6
// First added: 2007-05-24
7
// Last changed: 2008-07-17
9
// Unit tests for the function library
12
#include <dolfin/common/unittest.h>
13
#include "Projection.h"
15
using namespace dolfin;
17
class Eval : public CppUnit::TestFixture
19
CPPUNIT_TEST_SUITE(Eval);
20
CPPUNIT_TEST(testArbitraryEval);
21
CPPUNIT_TEST_SUITE_END();
25
void testArbitraryEval()
27
class F0 : public Function
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]); }
35
class F1 : public Function
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]; }
43
UnitCube mesh(8, 8, 8);
44
real x[3] = {0.3, 0.3, 0.3};
48
// User-defined functions (one from finite element space, one not)
52
// Test evaluation of a user-defined function
54
CPPUNIT_ASSERT(v[0] == sin(3.0*x[0])*sin(3.0*x[1])*sin(3.0*x[2]));
57
// Test evaluation of a discrete function
58
ProjectionBilinearForm a;
59
ProjectionLinearForm L(f1);
60
LinearPDE pde(a, L, mesh);
64
const real tol = 1.0e-6;
67
CPPUNIT_ASSERT( std::abs(u[0]-v[0]) < tol );
72
CPPUNIT_TEST_SUITE_REGISTRATION(Eval);