dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #16353
Re: [Bug 457262] [NEW] function and expression does not give the same result
oelgaard wrote:
> Quoting Garth Wells <gnw20@xxxxxxxxx>:
>
>> oelgaard wrote:
>>> Public bug reported:
>>>
>>> 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]);
>>> }
>>> };
>>>
>> The above class shouldn't be possible with the development version of
>> DOLFIN. Are you using an older version?
>
> Yes:
>
> changeset: 7392:70596970a173
> tag: tip
> user: Anders Logg <logg@xxxxxxxxx>
> date: Wed Oct 21 17:34:32 2009 +0200
> summary: Attempt at bug fix in application of periodic boundary conditions
> on
>
>
> Why shouldn't it be possible to derive a class from Function?
>
In the new design, Function is strictly a finite element function, and
not a user-defined function. We may need to fix something to make it
impossible to create a Function with a user-provided eval(..).
Expression should be used instead.
Garth
> Kristian
>
>> Garth
>>
>>> 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;
>>> }
>>>
>>> ** Affects: dolfin
>>> Importance: Undecided
>>> Status: New
>>>
>> --
>> function and expression does not give the same result
>> https://bugs.launchpad.net/bugs/457262
>> You received this bug notification because you are a direct subscriber
>> of the bug.
>>
>> Status in DOLFIN: New
>>
>> 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;
>> }
>>
>
--
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: New
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;
}
Follow ups
References