How to construct p::d::Triangulation from a locally refined Triangulation?

58 views
Skip to first unread message

Ce Qin

unread,
Feb 2, 2021, 9:03:00 AM2/2/21
to dea...@googlegroups.com
Dear all,

I want to create a p::d::Triangulation from a locally refined Triangulation which is loaded from a file (for example, we can create a triangulation using the python interface, refine some cells, then save it to file). I am aware that we can't use copy_triangulation since the triangulation being copied must be a *coarse mesh*. Is there a way to achieve this? Any suggestion will be appreciated.

Thanks.

Best regards,
Ce

Bruno Turcksin

unread,
Feb 2, 2021, 10:59:29 AM2/2/21
to deal.II User Group
Ce,

If you don't have hanging nodes, you can flatten the triangulation (C++, python) before saving the triangulation. This will create a new coarse mesh. The other solution is to load the mesh from a vtu file (see here).

Best,

Bruno

Daniel Arndt

unread,
Feb 2, 2021, 11:10:03 AM2/2/21
to dea...@googlegroups.com
Ce,

There is also save_refine_flags and load_refine_flags but you need to make sure that smoothing flags are also the same as explained here in "History of a Triangulation".
This is tested, e.g., in tests/mpi/interpolate_to_different_mesh_01.cc.

Best
Daniel

--
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/3f51912a-2e9d-47ae-bac1-70f0aade81dbn%40googlegroups.com.

Ce Qin

unread,
Feb 2, 2021, 9:57:33 PM2/2/21
to dea...@googlegroups.com
Thank you for your prompt response.

My use case can be described as follows
1) Create a triangulation in Python, refine some cells (several times)
2) Serialize the triangulation in to file using Triangulation::save
3) Load the triangulation from file using Triangulation::load
4) Reconstruct a parallel::distributed::Triangulation from the serial Triangulation

So my question is how to reconstruct a parallel::distributed::Triangulation from a serial Triangulation (with hanging nodes, n_levels() greater than 2)?

Best regards,
Ce

Daniel Arndt <d.arnd...@gmail.com> 于2021年2月3日周三 上午12:10写道:

Wolfgang Bangerth

unread,
Feb 3, 2021, 12:06:21 AM2/3/21
to dea...@googlegroups.com
On 2/2/21 7:57 PM, Ce Qin wrote:
>
> My use case can be described as follows
> 1) Create a triangulation in Python, refine some cells (several times)
> 2) Serialize the triangulation in to file using Triangulation::save
> 3) Load the triangulation from file using Triangulation::load
> 4) Reconstruct a parallel::distributed::Triangulation from the serial
> Triangulation
>
> So my question is how to reconstruct a *parallel::distributed::Triangulation*
> from a *serial* Triangulation (with hanging nodes, n_levels() greater than 2)?

There might not be a function for it right now. But it seems not impossible to
write a function (or, better, incorporate this into the existing copy_from()
function). Want to give this a try?

I think what would need to happen is that the p::d::T::copy_triangulation()
function extracts the coarse mesh of the given triangulation and calls the
copy_triangulation() function of the base class with it. It would then need to
recursively walk through the original and the current triangulation and refine
the current one based on whether a cell of the original triangulation was refined.

I suspect that that could be done with 200 lines of code, and you'd end up
with what you actually needed. I'd be happy to help along if you were
interested in giving that a try!

Best
W.

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

Ce Qin

unread,
Feb 3, 2021, 2:14:50 AM2/3/21
to dea...@googlegroups.com
Thank you, Wolfgang.

Definitely I want to give it a try. Will let you know when I make progress or encounter difficulties.

Best regards,
Ce

Wolfgang Bangerth <bang...@colostate.edu> 于2021年2月3日周三 下午1:06写道:
--
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.

Ce Qin

unread,
Feb 7, 2021, 9:28:24 AM2/7/21
to dea...@googlegroups.com
Hi, Wolfgang!

According to your suggestion, I wrote a simple program to copy a serial Triangulation
to a p::d::Triangulation by looping over all levels and refine cells which have children,
but the number of global active cells in the resulting p::d::Triangulation does not
equal to that in the serial Triangulation.

It seems that we will get different triangulations using the same refinement procedure.
Please check the attached files for more details.

Best regards,
Ce

Ce Qin <qinc...@gmail.com> 于2021年2月3日周三 下午3:14写道:
output.log
copy_serial_tria.cc

Ce Qin

unread,
Feb 7, 2021, 10:44:54 AM2/7/21
to dea...@googlegroups.com
After digging a bit deeper, I found that the problem is about mesh smoothing.
It seems that the default mesh smoothing for p::d::Triangulation is stricter than
::Triangulation. After adding the limit_level_difference_at_vertices option to
::Triangulation, I can get exactly the same meshes.

Will test with more complex cases.

Best regards,
Ce

Ce Qin <qinc...@gmail.com> 于2021年2月7日周日 下午10:28写道:

Wolfgang Bangerth

unread,
Feb 8, 2021, 11:07:40 PM2/8/21
to dea...@googlegroups.com
On 2/7/21 7:28 AM, Ce Qin wrote:
>
> According to your suggestion, I wrote a simple program to copy a serial
> Triangulation to a p::d::Triangulation by looping over all levels and
> refine cells which have children,

Ah, that's actually really elegant. Very nicely done!


> but the number of global active cells in
> the resulting p::d::Triangulation does not equal to that in the serial
> Triangulation.
>
> It seems that we will get different triangulations using the same
> refinement procedure. Please check the attached files for more details.

Is your concern that

DEAL:0::n_cells on level 0 : 8
DEAL:0::n_cells on level 1 : 64
DEAL:0::n_cells on level 2 : 96
DEAL:0::n_cells on level 3 : 344
DEAL:0::n_cells on level 4 : 1648
DEAL:0::n_cells on level 5 : 9344
DEAL:0::n_global_active_cells:34903 ---- this number
DEAL:0::n_cells on level 0 : 8
DEAL:0::n_cells on level 1 : 64
DEAL:0::n_cells on level 2 : 216
DEAL:0::n_cells on level 3 : 1000
DEAL:0::n_cells on level 4 : 5824
DEAL:0::n_cells on level 5 : 32768
DEAL:0::n_global_active_cells:34896 ---- and this number

...are not the same? Have you tried to investigate why that is so, for example
by visualizing the two meshes?

Ce Qin

unread,
Feb 9, 2021, 9:01:54 AM2/9/21
to dea...@googlegroups.com
At the first glance, I thought it would be the mesh smoothing issue.
It is true for the simple example, as I initialize the ::Triangulation with limit_level_difference_at_vertices,
the two triangulations became identical.

But for another randomly refined triangulation, things become complicated.
The two triangulations are very different (see figures below).
It seems that the refinement procedure is not reproducible in p::d::Triangulation.

I have no idea about the problem. Please check the attached files for the example code.

Best regards,
Ce

image.pngimage.png
copy_serial_tria.cc

Wolfgang Bangerth

unread,
Feb 9, 2021, 9:32:29 AM2/9/21
to dea...@googlegroups.com
On 2/9/21 7:01 AM, Ce Qin wrote:
>
> But for another randomly refined triangulation, things become complicated.
> The two triangulations are very different (see figures below).

I think that this is an artifact of the way you generate the output. You are
writing the same file from all processors, and so in essence what you are
visualizing is the mesh written by the last processor that gets to write. But
that includes ghost and artificial cells in the case of a p::d::T. That
processor does not actually know all cells of the mesh.

Ce Qin

unread,
Feb 9, 2021, 10:01:53 AM2/9/21
to dea...@googlegroups.com
I think that this is an artifact of the way you generate the output. You are
writing the same file from all processors, and so in essence what you are
visualizing is the mesh written by the last processor that gets to write. But
that includes ghost and artificial cells in the case of a p::d::T. That
processor does not actually know all cells of the mesh.

I'm sorry, I did not describe clearly. The figures in the previous mail are
generated using only one MPI process, and the number of active cells in the two
triangulations are not the same. So I think that there may exist some differences
between the refinement procedure of ::Triangulation and p::d::Triangulation that
I'm not aware of.

May I ask you to run the example code to verify the problem when you are convenient?

Best regards,
Ce
Reply all
Reply to author
Forward
0 new messages