This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Projection Function in C++

+7 votes

I found function project in python interface here. But can not find it in c++.
If i use u2 = project(u, V); I have error: "project" was not declared in this scope.
Does c++ interface have same functionality?

asked Sep 27, 2013 by Sheva FEniCS Novice (910 points)
edited Sep 30, 2013 by Garth N. Wells

1 Answer

+9 votes
 
Best answer

Hi, I think project is only available in python. When implementing its functionality in C++, the following might be helpful:

#include <dolfin.h>
#include "New.h"
#include "Old.h"

/*
Old.ufl:
  element = FiniteElement("Lagrange", triangle, 1)

New.ufl:
  V = FiniteElement("Lagrange", triangle, 2)
  W = FiniteElement("Lagrange", triangle, 1)

  u = TrialFunction(V)
  v = TestFunction(V)
  f = Coefficient(W)

  a = dot(u, v)*dx
  L = dot(f, v)*dx
*/

int main()
{
  UnitSquareMesh mesh(10, 10);
  New::FunctionSpace V(mesh);
  Old::FunctionSpace W(mesh);

  Function u(V);
  Function f(W);

  New::BilinearForm a(V, V);
  New::LinearForm L(V);
  L.f = f;

  solve(a == L, u);

  return 0;
} 
answered Sep 27, 2013 by MiroK FEniCS Expert (80,920 points)
selected Sep 28, 2013 by Sheva
...