### How to get the global indexes of all the four vertices of a tetrahedron in C++?

181
views
0
8 months ago by
Hi all, I have encountered a problem while trying to obtain the global indexes of the vertices of a cell (tetrahedron). In order to do this, I have tried to compute these quantities for the first cell (the 0th), and then, using a function equal to zero everywhere, I marked the vertices value of this function where the vertices should be. The code should be more expressing:

// create mesh Th (unit cube) and function space Vh (P1, continuous Lagrange)

// create the function (P1, continuous Lagrange)
auto fun = std::make_shared<Function>(Vh);

// create an auxiliary vector containing the vertices values of the above function
std::vector<double> funvect(Th->num_vertices(),0.0);

// set f(x) = 0
(fun->vector())->set_local(funvect);

// initialize 0-dim entities. Tried also with init(0)
Th->init_global(0);

// create the first cell (0th cell)
Cell myCell(*Th, 0);

// create an ufc::cell in order to get the Cell topology
ufc::cell c1;

// get cell topology
myCell.get_cell_topology(c1);

// get the GLOBAL INDEXES of the 4 vertices
std::vector<long unsigned int> vertex= c1.entity_indices[0];

// mark with 1000 the vertices
for(int ee=0; ee<vertex.size(); ee++) {
funvect[vertex[ee]] = 1000;
}

// reset the function
(fun->vector())->set_local(funvect);

// save the results
File file1("function.pvd");
file1<<*fun;​

When I visualize the function, the vertices marked are four, but they are scattered in the whole domain without any criterion! I expect to see four vertices marked on a single cell.
There could be several problems:
1) the ufc::cell global vertices indexes are different from the dolfin::Mesh ones.
2) the ufc::cell global vertices indexes are different from those of dolfin::Function::vector()
3) the line "(fun.vector())->set_local(funvect);" does not put the values in the right order. But this was ensured in this topic: https://www.allanswered.com/post/rwwv/how-to-extract-the-coefficients-of-a-dolphinfunction-in-c/ , and furthermore I have used this procedure in other problems, and it worked fine.
Community: FEniCS Project
I have found this documentation about this issue, it can explain this (it is for Python but I think it is fine also for C++): https://github.com/mikaem/fenicstools/wiki/DofMap-plotter
written 8 months ago by Francesco Clerici