← Back to team overview

dolfin team mailing list archive

Re: [Bug 457262] [NEW] function and expression does not give the same result

 

Quoting oelgaard <k.b.oelgaard@xxxxxxxxxx>:

> 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]);
>   }
> };
>
> 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

Initialising approx with the FunctionSpace Vu works, but shouldn't it throw an
error since the function space is different from the one that the form expects?
(or should expect)

Kristian

-- 
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;
}


References