Problem about cell iterator

116 views
Skip to first unread message

Toddy Liu

unread,
Nov 11, 2021, 10:22:48 PM11/11/21
to deal.II User Group
Dear Deal.II community,

I'm programming on modifying step 35 using Parallel computing with multiple processors using distributed memory. In step35, the tutorial program used "synchronous" iterator which consists of two iterators, one for velocity and the other for pressure.

Now I'm struggling with the cell iterator when I assemble system. In step 40,  it's enough to access cells using access like
const auto &cell : dof_handler.active_cell_iterators()". But how can I do this when the assemble_system needs two iterators (in my case one for velocity and the other for pressure)?

Any advice or suggestions will be appreciated!
Thank you.

Best,
Toddy

Jean-Paul Pelteret

unread,
Nov 12, 2021, 12:03:04 PM11/12/21
to dea...@googlegroups.com
Hi Toddy,

It’s possible to convert a triangulation iterator to a DoF iterator using the technique described here:
So one way would be just to loop over the triangulation and convert that to a velocity DoFHandler iterator and a pressure DoFHandler iterator. But it looks to me that you can convert between iterators in the same manner, so if you want you could also just use a standard loop over (DoF) cell iterators, and convert that primary iterator to the other kind.

I hope that this helps!

Best,
Jean-Paul


--
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/cb916c9f-c84c-4f94-86b9-360e0e19c7b4n%40googlegroups.com.

Toddy Liu

unread,
Nov 12, 2021, 9:31:07 PM11/12/21
to deal.II User Group

Hello, Jean

I'll look at the material and have a try. Thanks for your help

Best,
Toddy

Toddy Liu

unread,
Nov 22, 2021, 8:55:18 PM11/22/21
to deal.II User Group
Hi, Jean

I used the method that you taught me. but unfortunately the results seems bad. And I'm not sure where the problem is including the transform between dofhandler iterator and triangulation iterator. So please take a look at my codes(two pieces of codes shown in the following figures) and tell me which one will be the right one. 
The first one is 
1.png
And the second one is
2.png

Thank you very much.

Best,
Toddy

Wolfgang Bangerth

unread,
Nov 22, 2021, 10:53:44 PM11/22/21
to dea...@googlegroups.com
On 11/22/21 6:55 PM, Toddy Liu wrote:
>
> I used the method that you taught me. but unfortunately the results seems bad.
> And I'm not sure where the problem is including the transform between
> dofhandler iterator and triangulation iterator. So please take a look at my
> codes(two pieces of codes shown in the following figures) and tell me which
> one will be the right one.

Toddy -- for both this post and the other one you sent earlier, you need to
learn techniques to debug your codes. This typically starts with asking the
right questions. So when you say above "the results seems bad", you should ask
what specifically is wrong? Does the solution look right in the interior but
is wrong at the boundary? Or the other way around? Does it work on a single
processor, and is only wrong when run in parallel? What happens for cases
where you set the right hand side function to zero?

All of these questions help you *observe* what specifically is wrong, and
helps you formulate *hypotheses* where the bug may lie. When you have a
hypothesis, you can star to test it, play with variations that allow you to
identify whether your guess that the problem is, for example, at the boundary,
and narrow the places where the bug might be.

In the codes you show, I believe that they should be identical. Both codes
should work the same. If you get different results, then that would be
strange, but you could in that case test *why* the results are different --
for example by outputting the cell matrices and vectors.

Best
W.

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

Toddy Liu

unread,
Nov 23, 2021, 1:57:24 AM11/23/21
to deal.II User Group
Professor Wolfgang,

Thanks for your advice and I will try my best to do what you told me. I asked the problem about the transform between dofhandler iterator and triangulation iterator because I have never used this function. Except this function, I 'm familiar with the other functions used in other parts of my code. So I'm not sure whether the transform is right or not. Of course, if I got the right way to do the transformation, I can make sure that the bad results do not result from this part and I can focus on other parts of my code.

Thank you again. And I learned a lot from your excellent lecture videos, including debugging my code using eclipse, that help me find and solve many problems.

Best,
Toddy

Jean-Paul Pelteret

unread,
Nov 23, 2021, 1:37:07 PM11/23/21
to dea...@googlegroups.com
Dear Toddy,

This is a link to the documentation, where this function (a class constructor) is explained in more detail
I can’t see that you’re misusing it in any way. The order of the arguments that you’ve provided to it look correct to me.

Regarding the two approaches that you outlined a couple of posts earlier, I think that the intention is to use it in the way that you first proposed. Iterating over the triangulation, selecting a particular cell to perform and action on, and then converting that Tria cell iterator to the two DoFHandler cell iterators seems meaningful. The second approach is probably less meaningful - if you want the iterators outside of the loop, then you may as well have started with the first active iterator retrieved straight from the individual DoFHandlers in the first place. 

Best,
Jean-Paul


-- 
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.

Toddy Liu

unread,
Nov 23, 2021, 8:32:42 PM11/23/21
to deal.II User Group
Dear Jean,

I followed your suggestions and used the first method (triangulation iterator outside of loop and two dofhandler iterators inside of loop). After making sure of this, I managed to fix several other bugs and finally the code works well. And the results are nearly the same as the tutorial step-35. The running time has been decreased from 5min(workstream in step-35) to 50s (MPI using 4 cores).

Thank you very much for your help!

Best,
Toddy

Reply all
Reply to author
Forward
0 new messages