Re: [deal.II] How to find the neighbor of one cell

2023-11-29 Thread Wolfgang Bangerth

On 11/29/23 09:23, Lance Zhang wrote:


//***//
         if(cell->at_boundary()){
           continue;
           }//to check whether the cell exists


I don't think this is what you want. Here, you are only asking whether 
the cell has *any* faces that are at the boundary. But if you want to 
know whether a cell has a neighbor across a certain face, you need to 
ask whether the cell is at the boundary *at that particular face*. 
Daniel's code does that.


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 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/88a5f345-a088-473e-a893-1ed6736440de%40colostate.edu.


Re: [deal.II] How to find the neighbor of one cell

2023-11-29 Thread Lance Zhang
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  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> 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  于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; fn_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 

Re: [deal.II] How to find the neighbor of one cell

2023-11-29 Thread Daniel Arndt
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  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 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  于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; fn_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+unsubscr...@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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/dealii/CADwW6P%3Dy7uJAdD5q8DwpUnK-3iQBgTnVh5ioi-Pr62w54D0ikw%40mail.gmail.com
> 
> .
>

-- 
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/CAOYDWbL757Zyb9kWNGCUhKDJ38qaVKCt%2BN%2Bq%3Dk46vcdpJ0GUWA%40mail.gmail.com.


Re: [deal.II] How to find the neighbor of one cell

2023-11-29 Thread Lance Zhang
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 > >::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  于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; fn_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+unsubscr...@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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/dealii/CADwW6P%3Dy7uJAdD5q8DwpUnK-3iQBgTnVh5ioi-Pr62w54D0ikw%40mail.gmail.com.


Re: [deal.II] How to find the neighbor of one cell

2023-11-27 Thread Wolfgang Bangerth



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; fn_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 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/ef1fdaad-0bde-4478-8054-74df1a572c5f%40colostate.edu.


[deal.II] How to find the neighbor of one cell

2023-11-27 Thread Lance Zhang
Hello team,

I have one quick question.

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?)){
 ...

-
Thanks in advance!
Best regards
Lance   

-- 
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/4ae3d66e-faaa-401d-8027-12b6f7602bf0n%40googlegroups.com.