find all vertices connected to a given vertex

22 views
Skip to first unread message

Mathieu

unread,
May 16, 2023, 6:13:06 PM5/16/23
to deal.II User Group
Hello everyone,

I have a 2d grid (no hanging nodes) where a scalar finite element field is defined on it (i.e., one degree of freedom per support point).

For all vertices defined on that grid, I want to get the global dof indices of all connected vertices.
E.g.: an vertex inside the grid has four vertices connected to it (five-point stencil), the four corner vertices have two connected vertices each,...

Is there a built-in function for this purpose?
I thought Gridtools is the correct place to look for it, but I could not find something in there.

Thanks,
Math

Wolfgang Bangerth

unread,
May 16, 2023, 11:25:48 PM5/16/23
to dea...@googlegroups.com
On 5/16/23 16:13, Mathieu wrote:
>
> I have a 2d grid (no hanging nodes) where a scalar finite element field is
> defined on it (i.e., one degree of freedom per support point).
>
> For all vertices defined on that grid, I want to get the global dof indices of
> all connected vertices.
> E.g.: an vertex inside the grid has four vertices connected to it (five-point
> stencil), the four corner vertices have two connected vertices each,...

There isn't a function for this at the moment primarily because "connected
vertices" can be interpreted in many ways. You are specifically considering
"connected by a common edge", whereas a more common interpretation in the
finite element context would be "share a common cell".

But if you want "connected by an edge", that suggests the following algorithm:

std::vector<std::set<types::global_dof_indices>>
connections(dof_handler.n_dofs());
for (auto &cell : ...)
for (unsigned int e=0; e<cell->n_lines(); ++e)
{
std::vector<types::global_dof_indices> edge_dofs;
// ...need to set edge_dofs to the right size...
cell->line(e)->get_dof_indices (edge_dofs);
for (auto i : edge_dofs)
for (auto j : edge_dofs)
if (i != j)
connections[i].insert(j);
}

Best
W.

--
------------------------------------------------------------------------
Wolfgang Bangerth email: bang...@colostate.edu
www: http://www.math.colostate.edu/~bangerth/


Reply all
Reply to author
Forward
0 new messages