interpolation of a function in a defined function space

Asked by Xujun Zhao

Hi,

I am using the 'interpolate' function of a Function class, but it doesn't work......
P1_3D.h was generated from ffc for tetrahedron linear element. I defined an Expression F and FunctionSpace. When I tried to interpolate F on the defined function space, it gave the following error:

*** -------------------------------------------------------------------------
*** Error: Unable to evaluate expression.
*** Reason: Missing eval() function (must be overloaded).
*** Where: This error was encountered inside Expression.cpp.
*** -------------------------------------------------------------------------

However, I tested f.eval(vals,x), it worked well. The problem only took place when I used interpolate. Where was I wrong?
Thank you.

#include <dolfin.h>
#include <iostream>
#include "P1_3D.h"

using namespace dolfin;
using namespace std;

// ==========================================
class F : public Expression
{
  public:
  F() : Expression() {}
  void eval(double* values, const double* x) const
  {
    values[0] = sin(1.0*x[0])*sin(2.0*x[1])*sin(3.0*x[2]);
  }

};

//==========================================
int main()
{
  UnitCube mesh(20, 20, 20);

  F f; // expression
  std::cout<< "value_rank() of Expression f is " << f.value_rank() << "\n";

  // Create function spaces
  P1_3D::FunctionSpace V0(mesh);

  // Create functions
  Function f0(V0);
  f0.interpolate(f);

  return 0;

}

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Johan Hake
Solved:
Last query:
Last reply:
Revision history for this message
Best Johan Hake (johan-hake) said :
#1

You are overloading the wrong method. The signatur need to be:

void eval(Array<double>& values, const Array<double>& x) const;

Johan

On 12/05/2012 01:55 AM, Xujun Zhao wrote:
> New question #215985 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/215985
>
> Hi,
>
> I am using the 'interpolate' function of a Function class, but it doesn't work......
> P1_3D.h was generated from ffc for tetrahedron linear element. I defined an Expression F and FunctionSpace. When I tried to interpolate F on the defined function space, it gave the following error:
>
> *** -------------------------------------------------------------------------
> *** Error: Unable to evaluate expression.
> *** Reason: Missing eval() function (must be overloaded).
> *** Where: This error was encountered inside Expression.cpp.
> *** -------------------------------------------------------------------------
>
> However, I tested f.eval(vals,x), it worked well. The problem only took place when I used interpolate. Where was I wrong?
> Thank you.
>
>
> #include <dolfin.h>
> #include <iostream>
> #include "P1_3D.h"
>
> using namespace dolfin;
> using namespace std;
>
> // ==========================================
> class F : public Expression
> {
> public:
> F() : Expression() {}
> void eval(double* values, const double* x) const
> {
> values[0] = sin(1.0*x[0])*sin(2.0*x[1])*sin(3.0*x[2]);
> }
>
> };
>
> //==========================================
> int main()
> {
> UnitCube mesh(20, 20, 20);
>
> F f; // expression
> std::cout<< "value_rank() of Expression f is " << f.value_rank() << "\n";
>
> // Create function spaces
> P1_3D::FunctionSpace V0(mesh);
>
> // Create functions
> Function f0(V0);
> f0.interpolate(f);
>
> return 0;
>
> }
>
>
>
>

Revision history for this message
Xujun Zhao (xzhao99) said :
#2

Thank you, Johan.