How to define a function space of rank 1

4 months ago by
Hello everyone,

I am doing a projection of a vector expression bb that is

class B : public Expressionclass B : public Expression
B () : Expression(2) {} void eval(Array<double>& values, const Array<double>& x) const
{           values[0] = ((1-pow(x[0],2))*M_PI*cos(2*M_PI*x[1]))/25;     
            values[1] = 1/5 ;    

} };


B bb;


Projection::FunctionSpace V4(mesh);
auto b_inter = std::make_shared<dolfin::Function>(V4);

and inside the Projecton.ufl I have the following  
cell = triangle
V = VectorElement("CG", triangle, 2)
scalar = FiniteElement("Discontinuous Lagrange", cell, 1)

v = TrialFunction(scalar)
w = TestFunction(scalar)
f = Coefficient(V)
g = Coefficient(scalar)
a = w*dot(f,grad(v))*dx
l = g*w*dx

however when I run the code I get

*** Error: Unable to interpolate function into function space.
*** Reason: Rank of function (1) does not match rank of function space (0).
*** Where: This error was encountered inside FunctionSpace.cpp.
*** Process: unknown

I thought Vector Element function space will be of rank 1, anyone knows what is going on here ?

Thanks in advance.
Community: FEniCS Project
I suggest adding the code for the bb class to give a more complete MWE.  You probably don't have it declared  as a subclass of expression with degree 2.
written 4 months ago by jwinkle  
Have edited the question :)
written 4 months ago by noname  
I would suggest to post your .ufl file also. 
If you look at the bottom of your generated Projection.h file, you should see some typedefs, one for FunctionSpace.  It may be you don't use the vector element on the bilinear form 'a' side of the equation a==L.
written 4 months ago by jwinkle  
Thanks for the comment, here is what is written at the end of Projection.h. P.S: the question is updated

// Class typedefs
typedef Form_a BilinearForm;
typedef Form_a JacobianForm;
typedef Form_a::TestSpace FunctionSpace;
written 4 months ago by noname  
What is the PDE you are trying to solve?
In your .ufl file you have your trial and test spaces as a scalar function.  Is it the function f that you want to interpolate before passing into the solver?
In the .ufl file "Coefficients" will be input functions, so f is a vector function input, and the TrialFunction is the output solution.  So you have scalar function output (thus the error). 
At present you are trying to interpolate initial values into the function that is your solution (two errors), so clarifying the PDE and the resulting variational form should solve your issue
written 4 months ago by jwinkle  
Please login to add an answer/comment or follow this question.

Similar posts:
Search »