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

Evaluating a quadrature function in cpp expression

0 votes

Hi, I was wondering if it is possible to evaluate a quadrature function in an expression. In the following python code, I was able to evaluate a DG function in the following cpp expression using "eval" but I understand that you can't do that for a quadrature function as there are no basis functions in the functional space. Is there any way to get around it, especially since that expression are also evaluated at the integration points?

Thanks!

Python code:

from dolfin import *

deg = 2
parameters["form_compiler"]["representation"] ="quadrature"
parameters["form_compiler"]["quadrature_degree"]=deg

nx = 1
ny = 1
nz = 1
mesh = BoxMesh(Point(0.0, 0.0, 0.0), Point(10.0, 10.0, 1.0), nx, ny, nz)
dx = dolfin.dx(mesh)

Quadelem = FiniteElement("Quadrature", mesh.ufl_cell(), degree=deg, quad_scheme="default")
Quadelem._quad_scheme = 'default'
Quad = FunctionSpace(mesh, Quadelem)


DG = FunctionSpace(mesh, "DG", 0)

#Evalue = Function(Quad) # This doesn't  work 
Evalue = Function(DG) # This works

header_file1 = open("./testprojectquadrature_original.cpp","r")
cppcode = header_file1.read()


Expr = dolfin.Expression(cppcode, element=Quadelem)
Expr.U = Evalue

L = dolfin.assemble(Expr*dx)

testprojectquadrature_original.cpp:

namespace dolfin
{

class MyFunc : public Expression
{

  mutable Array<double> UX;

public:

  std::shared_ptr<const Function> U;

  MyFunc() : Expression(), UX(1)
  {
  }

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

};

void MyFunc::eval(Array<double>& values, const Array<double>& x) const
{
    U->eval(UX, x);

};

}
asked Jun 4, 2017 by lee FEniCS User (1,170 points)

Isn't projecting an option? Or you haven't considered it? Projecting an expression creates a function, so it would work. Best regards

...