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

How to get a mesh function with the global numbering scheme in a distributed mesh

0 votes

The documentation for MeshFunctions cite this as an example of its use.

"A MeshFunction may for example be used to store a global numbering scheme for the entities of a (parallel) mesh"

How would one accomplish this?

Thanks,

Ben

asked Sep 8, 2015 by brk888 FEniCS Novice (990 points)

1 Answer

0 votes

You can get the global index of an entity with the global_index() method:

for c in cells(mesh):
     print c.index(), c.global_index()

If you want, you could put this in a MeshFunction.

answered Sep 8, 2015 by chris_richardson FEniCS Expert (31,740 points)

Ok, I'm having trouble creating a meshfunction in c++. Could you give me an example of how to create and initialize a meshfunction? It seems I am failing to provide the compiler with a proper template.

Thanks,

Ben

It depends what you want to use it for.

CellFunction<std::size_t> cell_fn(mesh); // don't set values
VertexFunction<bool> vertex_fn(mesh, false); // Initialise to all false

for (CellIterator c(mesh); !c.end(); ++c)
    cell_fn[*c] = c->index();

Thank you! Very helpful. I'm finding the jump into c++ syntax very difficult. Sometimes the path from reading the docs to getting a small example working is very tricky (for someone with my level of experience in c++, anyway).

brk888, for what it's worth I had the same trouble. I know c++ well but my python is weak - tracking the underlying c++ through the swig interface can be tricky. I found the demos which are in both c++ and python very helpful.

...