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

Error when running code from nsbench

+2 votes

Hi,

I'm not sure if this is the right place to ask this question (or if it should be in a forum for bugs). Anyway, I'm having some troubles to get the code from nsbench (ch. 21 in the FEniCS book) working. In particular I'm trying to use the g2 and g3 solvers. I've been troubleshooting some myself and I think I have localized what causes the problem, but I'm not sure how to fix it. In the solvers (g2 and g3) a parameter, d1, is defined by the following command:

d1 = Expression(cppcode_d1, element=DG)

And in the cppcode_d1 there is a code segment like this one:

for (CellIterator cell(mesh); !cell.end(); ++cell)
{
  some code
  for (VertexIterator vertex(*cell); !vertex.end(); ++vertex)
  {
    for (uint i = 0; i < gdim; ++i)
    {
      some code again
    }
  }
  some more code
}

However, when compiling I get the following error message:

error: ‘VertexIterator’ was not declared in this scope

The CellIterator works fine though. I'm not a C++ programmer (or a programmer at all...) so I don't know how to proceed from this. Any tips?

Thank you in advance!

P.S I have the latest version of FEniCS installed (1.2.0). If anyone wants to try the code from nsbench: I believe that PeriodicBC changed name to PeriodicBoundaryComputation in the new version (you will need to change this in the code).

edit: Here is an example demonstrating my problem.

I have a file named test.py where I have the this code

from dolfin import *
from testcppcode import *

d1 = Expression(testcppcode_d1)

and in testcppcode.py I have the following code

testcppcode_d1 = """

class Delta1 : public Expression
{
public:

  Delta1() : Expression() {}

  void update(boost::shared_ptr<dolfin::Function> u)
  {
    const Mesh& mesh = *(*(u->function_space())).mesh();
    double U = 0.0;

    for (CellIterator cell(mesh); !cell.end(); ++cell)
    {
      for (VertexIterator vertex(*cell); !vertex.end(); ++vertex)
      {
        U++;
      }
    }
  }
};"""

This gives me the error message: ‘VertexIterator’ was not declared in this scope.

asked Jul 15, 2013 by anna FEniCS Novice (180 points)
edited Jul 19, 2013 by anna

Can you provide runnable example?

Thank you for your reply. I have now edited my original question to include a better example.

1 Answer

0 votes
 
Best answer

You have to specifically include needed headers as only Expression dependencies are included by default.

#include "dolfin/mesh/Vertex.h"

namespace dolfin {

  class Delta1 : public Expression
  {
  public:

    Delta1() : Expression() {}

    void update(boost::shared_ptr<Function> u)
    {
      const Mesh& mesh = *u->function_space()->mesh();
      double U = 0.0;

      for (CellIterator cell(mesh); !cell.end(); ++cell)
      {
        for (VertexIterator vertex(*cell); !vertex.end(); ++vertex)
        {
          U++;
        }
      }
    }
  };
}
answered Jul 19, 2013 by Jan Blechta FEniCS Expert (51,420 points)
selected Jul 22, 2013 by anna

Thank you! After including GenericVector.h as well the g2 and g3 solvers works fine.

...