dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #16370
[Bug 457262] Re: function and expression does not give the same result
I'm going to invalidate this bug since Function is not designed for
Function::eval to be implemented by the user. Doing so will lead to
unpredictable results, but there is nothing in C++ that allows us to
stop a user from overriding a base class function in a sub-lcass.
** Changed in: dolfin
Status: New => Invalid
--
function and expression does not give the same result
https://bugs.launchpad.net/bugs/457262
You received this bug notification because you are subscribed to DOLFIN.
Status in DOLFIN: Invalid
Bug description:
The following two files will reproduce the bug.
M.ufl:
exact = FiniteElement("Lagrange", triangle, 6)
approx = FiniteElement("Lagrange", triangle, 1)
u = Function(exact)
uh = Function(approx)
M = (uh - u)*(uh - u)*dx
main.cpp:
#include <dolfin.h>
#include "M.h"
using namespace dolfin;
class Expr : public Expression
{
public:
Expr() : Expression(2) {}
void eval(double* values, const double* x) const
{
values[0] = 10*x[0]*x[1];
}
};
class Expr2 : public Expression
{
public:
Expr2() : Expression(2) {}
void eval(double* values, const double* x) const
{
values[0] = sin(5*x[0]);
}
};
class Func2 : public Function
{
public:
Func2(FunctionSpace& v) : Function(v) {}
void eval(double* values, const double* x) const
{
values[0] = sin(5*x[0]);
}
};
int main()
{
// Create mesh and function space
UnitSquare mesh(8, 8);
M::CoefficientSpace_u Vu(mesh);
M::CoefficientSpace_uh Vuh(mesh);
Expr exact;
// Expr2 approx; // 12.5251
// Func2 approx(Vuh); // 11.1111
Func2 approx(Vu); // 11.1111
M::Functional m(mesh);
m.u = exact;
m.uh = approx;
double error = assemble(m);
std::cout << "error: " << error << std::endl;
return 0;
}
References