Hello Daniel, thanks for your message.
I wrote a statement to check if the cell exists. for (const auto &cell : solid_3d.dof_handler_ref.active_cell_iterators()) { //***********************************************************************************************************************************// if(cell->at_boundary()){ continue; }//to check whether the cell exists //**********************filter if the cell is at boundary ,if yes, the cell iterator will move forward*************************************// //*******otherwise if the cell exists,the cell index will be calculated*************************************************************// const unsigned int cell_index = cell->active_cell_index(); if (visited_cells[cell_index]) continue; // Skip if the cell has been visited by its all neighbors // Loop over all degrees of freedom on the current cell for (unsigned int i = 0; i < solid_3d.dofs_per_cell; ++i) { // Loop over all neighboring cells for (unsigned int f = 0; f < cell->n_faces(); ++f) { auto neighbor = cell->neighbor(f);//find the neighbor ,but not sure if it exists if(neighbor->at_boundary()) continue;//check if the neighbor of cell exists int neighbor_index = neighbor->active_cell_index();//get the global index of the cell if it exists Best regards Lance On Wednesday, November 29, 2023 at 6:04:45 PM UTC+2 d.arnd...@gmail.com wrote: > Lance, > > You would check for the cell being at a boundary first before asking for > its neighbor: > > // Loop over all neighboring cells > for (unsigned int f = 0; f < cell->n_faces(); ++f) > { > if (cell->at_boundary(f)) > continue; > auto neighbor = cell->neighbor(f); > int neighbor_index = neighbor->active_cell_index();//get the > global index of the cell if it exists > [...] > > > Best, > Daniel > > On Wed, Nov 29, 2023 at 9:43 AM Lance Zhang <dim...@gmail.com> wrote: > >> Hello Wolfgang, >> >> thanks for your message. >> >> May I know which method or keywords can be used to stand for the >> non-existing cell and could I use cell->at_boundary() to check whether >> the cell exists or not? >> >> I would like to know how we can identify if the object >> of >> dealii::IteratorRange<dealii::TriaActiveIterator<dealii::DoFCellAccessor<3, >> 3, false> > >::IteratorOverIterators does not exist. I have tried ==NULL >> and nullptr, however, it doe snot work. >> >> There is the code snippet below, please take a look: >> >> for (const auto &cell : solid_3d.dof_handler_ref.active_cell_iterators()) >> { >> >> if(cell->at_boundary()){ >> continue; >> }//to check whether the cell exists >> >> const unsigned int cell_index = cell->active_cell_index(); >> >> if (visited_cells[cell_index]) >> continue; // Skip if the cell has been visited by its all >> neighbors >> >> // Loop over all degrees of freedom on the current cell >> for (unsigned int i = 0; i < solid_3d.dofs_per_cell; ++i) >> { >> >> // Loop over all neighboring cells >> for (unsigned int f = 0; f < cell->n_faces(); ++f) >> { >> auto neighbor = cell->neighbor(f);//find the neighbor ,but >> not sure if it exists >> >> if(neighbor->at_boundary()) >> continue;//check if the neighbor of cell exists >> int neighbor_index = neighbor->active_cell_index();//get the >> global index of the cell if it exists >> ... >> >> The whole code can be found via the link : >> https://github.com/Lancelof2019/cook_membrane_snippet/blob/main/code_snippet.cpp >> >> Thanks in advance! >> >> Best regards >> Lance >> >> Wolfgang Bangerth <bang...@colostate.edu> 于2023年11月28日周二 01:54写道: >> >>> >>> On 11/27/23 14:52, Lance Zhang wrote: >>> > >>> > May I know how to find the neighbor of a cell? >>> > >>> > Here is one part of my code: >>> > >>> ---------------------------------------------------------------------------------------------------------------------- >>> > for (const auto &cell : >>> solid_3d.get_dof_handler().active_cell_iterators() >>> > { >>> > const unsigned int cell_index = cell->active_cell_index(); >>> > >>> > // Loop over all degrees of freedom on the current cell >>> > for (unsigned int i = 0; i < dofs_per_cell.dofs_per_cell; ++i) >>> > { >>> > // Loop over all neighboring cells >>> > for (const auto &neighbor : Find_neighbors?)){ >>> >>> You can write this as >>> for (unsigned int f=0; f<cell->n_faces(); ++f) >>> { >>> DoFHandler::cell_iterator neighbor = cell->neighbor(f); >>> ... >>> } >>> >>> Best >>> W. >>> >>> -- >>> The deal.II project is located at http://www.dealii.org/ >>> For mailing list/forum options, see >>> https://groups.google.com/d/forum/dealii?hl=en >>> --- >>> You received this message because you are subscribed to a topic in the >>> Google Groups "deal.II User Group" group. >>> To unsubscribe from this topic, visit >>> https://groups.google.com/d/topic/dealii/XYNlOZYskis/unsubscribe. >>> To unsubscribe from this group and all its topics, send an email to >>> dealii+un...@googlegroups.com. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/dealii/ef1fdaad-0bde-4478-8054-74df1a572c5f%40colostate.edu >>> . >>> >> -- >> The deal.II project is located at http://www.dealii.org/ >> For mailing list/forum options, see >> https://groups.google.com/d/forum/dealii?hl=en >> --- >> > You received this message because you are subscribed to the Google Groups >> "deal.II User Group" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to dealii+un...@googlegroups.com. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/dealii/CADwW6P%3Dy7uJAdD5q8DwpUnK-3iQBgTnVh5ioi-Pr62w54D0ikw%40mail.gmail.com >> >> <https://groups.google.com/d/msgid/dealii/CADwW6P%3Dy7uJAdD5q8DwpUnK-3iQBgTnVh5ioi-Pr62w54D0ikw%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> > -- The deal.II project is located at http://www.dealii.org/ For mailing list/forum options, see https://groups.google.com/d/forum/dealii?hl=en --- You received this message because you are subscribed to the Google Groups "deal.II User Group" group. To unsubscribe from this group and stop receiving emails from it, send an email to dealii+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/dealii/c8cd8a1d-d248-413d-b9aa-2202f84be1b5n%40googlegroups.com.