What is the preferred way to access data stored in the Data class now that it has been removed.

Asked by Renier Marchand

From the changelog of Dolfin 0.9.10

 - Make GenericFunction::eval thread-safe (Data class removed)

But I have code that access the Data class as described by the docstring help of Expression i.e.

class MyFunc : public Expression
{
public:

    MyFunc() : Expression(3)
    {
    }

    void eval(Array<double>& values, const Data& data) const
    {
Point n = data.normal();
values[0] = -n.x()*n.y()*sin(13.34256380792608*data.x[0]);
values[1] = pow(n.x(), 2)*sin(13.34256380792608*data.x[0]) + pow(n.z(), 2)*sin(13.34256380792608*data.x[0]);
values[2] = -n.y()*n.z()*sin(13.34256380792608*data.x[0]);
    }

};

This leads to the compile.log error:
...
dolfin_compile_code_2c2c0d2515ec19610942d91a460c7b2d_wrap.cxx:2858: error: ISO C++ forbids declaration of ‘Data’ with no type
...

I assume this is because of the change mentioned above.

If so, how should data such as normals etc. be accessed?

If not, what else have change that might cause this new error?

I am running Lucid on a 64-bit platform.

Thanks

Renier

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
Launchpad Janitor (janitor) said :
#1

This question was expired because it remained in the 'Open' state without activity for the last 15 days.

Revision history for this message
Garth Wells (garth-wells) said :
#2

Take a look at

  /demo/pde/mixed-poisson/cpp/main.cpp

Revision history for this message
Garth Wells (garth-wells) said :
#3

-

Revision history for this message
Renier Marchand (renierm) said :
#4

Thanks, this helped but,

I now get an error that new_MyFunc() takes exactly 1 argument (0 given)

(I am using Python with the complex C++ snippet)

I assume this is because the mesh is not sent as a parameter.

I tried to clear the parameter requirement specified in the constructor and moving the mesh to be public,
i.e.

class MyFunc : public Expression
{
public:

    const Mesh& mesh;

    MyFunc() : Expression(3), mesh(mesh) {}

    void eval(Array<double>& values, const Array<double>& x, const ufc::cell& ufc_cell) const
    {
         assert(ufc_cell.local_facet >= 0);
         Cell cell(mesh, ufc_cell.index);
         Point n = cell.normal(ufc_cell.local_facet);
         values[0] = -n.x()*n.y()*sin(13.34256380792608*x[0]);
         values[1] = pow(n.x(), 2)*sin(13.34256380792608*x[0]) + pow(n.z(), 2)*sin(13.34256380792608*x[0]);
         values[2] = -n.y()*n.z()*sin(13.34256380792608*x[0]);
    }

};

and then setting mesh in the PyDolfin code i.e.

dbc_expression = Expression(CODE, element=V.ufl_element())
dbc_expression.mesh = mesh
bc = DirichletBC(V,dbc_expression, Boundary())

But I now get an error that:

python: /build/buildd/dolfin-0.9.10/dolfin/mesh/MeshTopology.h:50: dolfin::uint dolfin::MeshTopology::size(dolfin::uint) const: Assertion `num_entities' failed.

What is the correct way of passing the mesh? or is this the correct way and this is related to some other error?

Thank you.

Revision history for this message
Best Johan Hake (johan-hake) said :
#5

On Tuesday March 22 2011 03:57:44 bluejerry wrote:
> Question #147330 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/147330
>
> Status: Answered => Open
>
> bluejerry is still having a problem:
> Thanks, this helped but,
>
> I now get an error that new_MyFunc() takes exactly 1 argument (0 given)
>
> (I am using Python with the complex C++ snippet)
>
> I assume this is because the mesh is not sent as a parameter.
>
> I tried to clear the parameter requirement specified in the constructor and
> moving the mesh to be public, i.e.

Try with:

CODE = """ class MyFunc : public Expression
 {
 public:
     boost::shared_ptr<Mesh> mesh;
     MyFunc() : Expression(3), mesh(static_cast<Mesh* >(0)) {}
     void eval(Array<double>& values, const Array<double>& x, const
 ufc::cell& ufc_cell) const {
          assert(ufc_cell.local_facet >= 0);
          assert(mesh);
          Cell cell(*mesh, ufc_cell.index);
          Point n = cell.normal(ufc_cell.local_facet);
          values[0] = -n.x()*n.y()*sin(13.34256380792608*x[0]);
          values[1] = pow(n.x(), 2)*sin(13.34256380792608*x[0]) + pow(n.z(),
 2)*sin(13.34256380792608*x[0]); values[2] =
 -n.y()*n.z()*sin(13.34256380792608*x[0]);
     }
 };
"""

Johan

> and then setting mesh in the PyDolfin code i.e.
>
> dbc_expression = Expression(CODE, element=V.ufl_element())
> dbc_expression.mesh = mesh
> bc = DirichletBC(V,dbc_expression, Boundary())
>
> But I now get an error that:
>
> python: /build/buildd/dolfin-0.9.10/dolfin/mesh/MeshTopology.h:50:
> dolfin::uint dolfin::MeshTopology::size(dolfin::uint) const: Assertion
> `num_entities' failed.
>
> What is the correct way of passing the mesh? or is this the correct way
> and this is related to some other error?
>
> Thank you.

Revision history for this message
Renier Marchand (renierm) said :
#6

Thank you! This works!