Obtain degrees of freedom starting from the cell

58 views
Skip to first unread message

bob bill

unread,
Nov 30, 2021, 2:36:33 PM11/30/21
to deal.II User Group
Hi everyone,

I'm in a strange situation at the moment. Basically, I have the number of a cell in my triangulation, and I want to know the degrees of freedom associated to that cell.
Namely, given the integer number associated to the global cell, I'd like to know the global numbers of the DoFs associated to that particular cell. 

I looked up and down through the documentation, but I can't really find a way to do this. 
Of course, I have a DoFHandler attached to that triangulation, so as long as there's a way to obtain the global indices, I'm fine with it.

Best,
Bob

Marc Fehling

unread,
Nov 30, 2021, 3:11:39 PM11/30/21
to deal.II User Group
Hello Bob,

I think the function DoFAccessor::get_dof_indices() is the one you are looking for.

Its use is demonstrated in multiple tutorial programs, e.g. step-4.

I hope this helps!
Marc

bob bill

unread,
Nov 30, 2021, 3:33:16 PM11/30/21
to deal.II User Group
Hi Marc,

there's a problem: that function assumes that you do the usual 
cell->get_dof_indices(local_to_global);

In my case, I only have the integer number associated to that cell, say 80, and I wanna know what are the DoFs associated to cell number 80 of my triangulation. If it's not clear, I can add more context, even though I don't think it's relevant.

Best,
Bob

Marc Fehling

unread,
Nov 30, 2021, 4:51:30 PM11/30/21
to deal.II User Group
Hi Bob,

you should be able to create a `DoFAccessor` iterator object with your index in some way, and then call this particular function. Or you can iterate over all active cells, and then check for their index and store the corresponding dof indices in some container.

In general, I would advise you to use `CellId` objects instead of pure integers to identify cells. In case you want to parallelize your code at some point, you will make your life a lot easier. You can also convert `CellId` objects easily into cell iterators using this function.

Marc

bob bill

unread,
Nov 30, 2021, 5:30:49 PM11/30/21
to deal.II User Group
Thanks Marc for your answer. 

I should have given more context, as maybe in this particular case things can be simpler. I'm using compute_point_locations() and so in my code I have:

auto cmp = GridTools::compute_point_locations(*cache,fe_emb_values.get_quadrature_points()); //returns a tuple
auto cells = std::get<0>(cmp);

the type of cells is Triangulation< dim, spacedim >::active_cell_iterator.

In this particular case, is there any straightforward way to get the dofs indices for each cell in cells? Or should I follow one of those you gave me in your last answer?

Best,
Bob

Marc Fehling

unread,
Nov 30, 2021, 5:37:36 PM11/30/21
to deal.II User Group
You can convert your Triangulation::cell_iterators into a DoFHandler::cell_iterators. An example is shown here.

Marc

bob bill

unread,
Nov 30, 2021, 7:11:41 PM11/30/21
to deal.II User Group
Thanks a lot Marc, now it compiles. Without your help it wouldn't have been possible.

Best,
Bob
Reply all
Reply to author
Forward
0 new messages