1
// Copyright (C) 2006-2008 Anders Logg.
2
// Licensed under the GNU LGPL Version 2.1.
4
// First added: 2006-09-19
5
// Last changed: 2008-12-13
7
// This demo program computes the value of the functional
9
// M(v) = int v^2 + (grad v)^2 dx
11
// on the unit square for v = sin(x) + cos(y). The exact
12
// value of the functional is M(v) = 2 + 2*sin(1)*(1-cos(1))
14
// The functional M corresponds to the energy norm for a
15
// simple reaction-diffusion equation.
18
#include "EnergyNorm.h"
20
using namespace dolfin;
25
class MyFunction : public Function
29
MyFunction(const FunctionSpace& V) : Function(V) {}
31
void eval(double* values, const double* x) const
33
values[0] = sin(x[0]) + cos(x[1]);
39
UnitSquare mesh(16, 16);
40
EnergyNormCoefficientSpace V(mesh);
42
EnergyNormFunctional M;
45
// Evaluate functional
46
double approximate_value = assemble(M);
48
// Compute exact value
49
double exact_value = 2.0 + 2.0*sin(1.0)*(1.0 - cos(1.0));
51
message("The energy norm of v is: %.15g", approximate_value);
52
message("It should be: %.15g", exact_value);