Getting all cells adjacent to a line

41 views
Skip to first unread message

Joshua Hansel

unread,
Nov 24, 2015, 10:47:34 AM11/24/15
to deal.II User Group
Hi, I'm computing a quantity that is piecewise constant in each cell, and its definition is basically a maximum over the lines of a quantity in each cell. To be clear, what I mean by line is a pair of nodes (equivalently, a pair of DoFs since I'm using 1st-order Langrangian FE). So, in 1-D this is a cell, in 2-D a face, and in 3-D an edge of a face. To perform this computation, I loop over lines by doing this:

// reset line flags                                                                             
triangulation->clear_user_flags_line();                                                         
 
for (cell = dof_handler->begin_active(); cell != endc; ++cell, ++i_cell)                        
  // loop over lines of cell 
  for (unsigned int line = 0; line < GeometryInfo<dim>::lines_per_cell; ++line)
  { 
    // skip line if it has already been traversed
    if (!cell->line(line)->user_flag_set())
    {                                                                                           
      // mark line to signal it has been traversed
      cell->line(line)->set_user_flag(); 
      
      // get dof indices on line
      cell->line(line)->get_dof_indices(local_dof_indices);

      // compute quantity on line: quantity_line

      // update quantity on current cell since we know it is adjacent to this line
      quantity[cell] = max(quantity[cell], quantity_line);

      // update quantity on all other adjacent cells, if any
      for (all other adjacent cells: cell_other)
        quantity[cell_other] = max(quantity[cell_other], quantity_line);
    }
  }
}

Is there any way to get a list of cells adjacent to the line, like in the last loop here? Or will I need to repeat these computations on the line from all other cells; i.e., remove all of the user flag stuff and thus possibly traverse a line multiple times?

Thanks!

Bruno Turcksin

unread,
Nov 24, 2015, 11:18:29 AM11/24/15
to deal.II User Group
Josh,

if you use the development version of deal.II, you can get all the cells adjacent to each vertex (https://dealii.org/developer/doxygen/deal.II/namespaceGridTools.html#a9b7e2ca8ecd26a472e5225ba91a58acb). In 8.3, you can also get the same information vertex by vertex but you need to redo the whole computation every time (https://dealii.org/developer/doxygen/deal.II/namespaceGridTools.html#ae8163cc8b6959635d7137edcabc9da7d). Unfortunately, there is nothing similar for lines.

Best,

Bruno

Wolfgang Bangerth

unread,
Nov 24, 2015, 11:30:00 AM11/24/15
to dea...@googlegroups.com
On 11/24/2015 10:18 AM, Bruno Turcksin wrote:
>
> if you use the development version of deal.II, you can get all the cells
> adjacent to each vertex
> (https://dealii.org/developer/doxygen/deal.II/namespaceGridTools.html#a9b7e2ca8ecd26a472e5225ba91a58acb).
> In 8.3, you can also get the same information vertex by vertex but you
> need to redo the whole computation every time
> (https://dealii.org/developer/doxygen/deal.II/namespaceGridTools.html#ae8163cc8b6959635d7137edcabc9da7d).
> Unfortunately, there is nothing similar for lines.

But you can create a
std::map<line_iterator,...>
so you can store information associated with a line and re-use this
later. The question whether you already touched a line is then simply
whether the key for that line already exists in the map. If it doesn't,
you'll have to compute the quantity associated with that edge.

Best
W.

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

Joshua Hansel

unread,
Nov 24, 2015, 2:10:28 PM11/24/15
to deal.II User Group
Ok, so using this approach, I'm guessing I would basically get sets of cell iterators for each of the 2 vertices on a line, and then I would get the intersection of those sets, which would be the set of cells adjacent to the line. Is this right?

Joshua Hansel

unread,
Nov 24, 2015, 2:11:35 PM11/24/15
to deal.II User Group
That last post was to Bruno. Dr. Bangerth, that's a good (and simple) idea, so I think I'll try that. Thank you both for the help!

Bruno Turcksin

unread,
Nov 24, 2015, 2:50:32 PM11/24/15
to dea...@googlegroups.com
Yes, that's correct.

Best,

Bruno
Reply all
Reply to author
Forward
0 new messages