Re: [petsc-users] Inquiry regarding DMAdaptLabel function

2023-02-27 Thread Pierre Jolivet


> On 27 Feb 2023, at 4:42 PM, Matthew Knepley  wrote:
> 
> On Mon, Feb 27, 2023 at 10:26 AM Pierre Jolivet  > wrote:
>>> On 27 Feb 2023, at 4:16 PM, Matthew Knepley >> > wrote:
>>> 
>>> On Mon, Feb 27, 2023 at 10:13 AM Pierre Jolivet >> > wrote:
> On 27 Feb 2023, at 3:59 PM, Matthew Knepley  > wrote:
> 
> On Mon, Feb 27, 2023 at 9:53 AM Zongze Yang  > wrote:
>> Hi, Matt,
>> 
>> I tested coarsening a mesh by using ParMMg without firedrake, and found 
>> some issues:
>>  see the code and results here:  
>> https://gitlab.com/petsc/petsc/-/issues/1331
>> 
>> Could you have a look and give some comments or suggestions?
> 
> I replied on the issue. More generally, the adaptive refinement software 
> has not seen wide use
 
 :)
 Matt probably meant “the _DMPlex interface_ to adaptive refinement 
 software has not seen wide use”, Mmg has been rather widely used for 10+ 
 years (here is a 13-year old presentation 
 https://www.ljll.math.upmc.fr/hecht/ftp/ff++days/2010/exposes/Morice-MeshMetric.pdf).
>>> 
>>> The interface is certainly new, but even ParMMG is only from Nov 2016, 
>>> which is very new if you are an old person :)
>> 
>> Indeed. In fact, I do believe we should add a DMPlex mechanism to centralize 
>> (redistribute on a single process) a DMPlex and to call Mmg instead of 
>> ParMmg.
>> It would certainly not be scalable for large meshes but:
>> 1) there is no need for ParMmg on small-/medium-scale meshes
>> 2) Mmg is more robust than ParMmg at this point in time
>> 3) Mmg has more feature than ParMmg at this point in time, e.g., implicit 
>> remeshing using a level-set
>> 4) there is more industry money funnelled into Mmg than into ParMmg 
>> I think the mechanism I mentioned initially was in the TODO list of the 
>> Firedrake people (or yours?), maybe it’s already done, but in any case it’s 
>> not hooked in the Mmg adaptor code, though it should (erroring out in the 
>> case where the communicator is of size greater than one would then not 
>> happen anymore).
> 
> Yes, we used to do the same thing with partitioners. We can use 
> DMPlexGather().
> 
> I thought MMG only did 2D and ParMMG only did 3D, but this must be wrong now. 
> Can MMG do both?

Mmg does 2D, 3D, and 3D surfaces.
ParMmg only does 3D (with no short-term plan for 2D or 3D surfaces).

Thanks,
Pierre

>   Thanks,
> 
>  Matt
>  
>> Thanks,
>> Pierre
>> 
>>>   Thanks,
>>> 
>>> Matt
>>>  
 Thanks,
 Pierre
 
> , and I expect
> more of these kinds of bugs until more people use it.
> 
>   Thanks,
> 
>  Matt
>  
>> Best wishes,
>> Zongze
>> 
>> 
>> On Mon, 27 Feb 2023 at 20:19, Matthew Knepley > > wrote:
>>> On Sat, Feb 18, 2023 at 6:41 AM Zongze Yang >> > wrote:
 Another question on mesh coarsening is about `DMCoarsen` which will 
 fail when running in parallel.
 
 I generate a mesh in Firedrake, and then create function space and 
 functions, after that, I get the dmplex and coarsen it.
 When running in serials, I get the mesh coarsened correctly. But it 
 failed with errors in ParMMG when running parallel.
 
 However, If I did not create function space and functions on the 
 original mesh, everything works fine too.
 
 The code and the error logs are attached.
>>> 
>>> I believe the problem is that Firedrake and PETSc currently have 
>>> incompatible coordinate spaces. We are working
>>> to fix this, and I expect it to work by this summer.
>>> 
>>>   Thanks,
>>> 
>>>  Matt
>>>  
 Thank you for your time and attention。
 
 Best wishes,
 Zongze
 
 
 On Sat, 18 Feb 2023 at 15:24, Zongze Yang >>> > wrote:
> Dear PETSc Group,
> 
> I am writing to inquire about the function DMAdaptLabel in PETSc. 
> I am trying to use it coarse a mesh, but the resulting mesh is 
> refined.
> 
> In the following code, all of the `adpat` label values were set to 2 
> (DM_ADAPT_COARSEN).
> There must be something wrong. Could you give some suggestions?
>  
> ```python
> from firedrake import *
> from firedrake.petsc import PETSc
> 
> def mark_all_cells(mesh):
> plex = mesh.topology_dm
> with PETSc.Log.Event("ADD_ADAPT_LABEL"):
> plex.createLabel('adapt')
> cs, ce = plex.getHeightStratum(0)
> for i in range(cs, ce):
> plex.setLabelValue('adapt', i, 2)
> 
>   

Re: [petsc-users] Inquiry regarding DMAdaptLabel function

2023-02-27 Thread Matthew Knepley
On Mon, Feb 27, 2023 at 10:26 AM Pierre Jolivet  wrote:

> On 27 Feb 2023, at 4:16 PM, Matthew Knepley  wrote:
>
> On Mon, Feb 27, 2023 at 10:13 AM Pierre Jolivet  wrote:
>
>> On 27 Feb 2023, at 3:59 PM, Matthew Knepley  wrote:
>>
>> On Mon, Feb 27, 2023 at 9:53 AM Zongze Yang  wrote:
>>
>>> Hi, Matt,
>>>
>>> I tested coarsening a mesh by using ParMMg without firedrake, and found
>>> some issues:
>>>  see the code and results here:
>>> https://gitlab.com/petsc/petsc/-/issues/1331
>>>
>>> Could you have a look and give some comments or suggestions?
>>>
>>
>> I replied on the issue. More generally, the adaptive refinement software
>> has not seen wide use
>>
>>
>> :)
>> Matt probably meant “the _DMPlex interface_ to adaptive refinement
>> software has not seen wide use”, Mmg has been rather widely used for 10+
>> years (here is a 13-year old presentation
>> https://www.ljll.math.upmc.fr/hecht/ftp/ff++days/2010/exposes/Morice-MeshMetric.pdf
>> ).
>>
>
> The interface is certainly new, but even ParMMG is only from Nov 2016,
> which is very new if you are an old person :)
>
>
> Indeed. In fact, I do believe we should add a DMPlex mechanism to
> centralize (redistribute on a single process) a DMPlex and to call Mmg
> instead of ParMmg.
> It would certainly not be scalable for large meshes but:
> 1) there is no need for ParMmg on small-/medium-scale meshes
> 2) Mmg is more robust than ParMmg at this point in time
> 3) Mmg has more feature than ParMmg at this point in time, e.g., implicit
> remeshing using a level-set
> 4) there is more industry money funnelled into Mmg than into ParMmg
> I think the mechanism I mentioned initially was in the TODO list of the
> Firedrake people (or yours?), maybe it’s already done, but in any case it’s
> not hooked in the Mmg adaptor code, though it should (erroring out in the
> case where the communicator is of size greater than one would then not
> happen anymore).
>

Yes, we used to do the same thing with partitioners. We can use
DMPlexGather().

I thought MMG only did 2D and ParMMG only did 3D, but this must be wrong
now. Can MMG do both?

  Thanks,

 Matt


> Thanks,
> Pierre
>
>   Thanks,
>
> Matt
>
>
>> Thanks,
>> Pierre
>>
>> , and I expect
>> more of these kinds of bugs until more people use it.
>>
>>   Thanks,
>>
>>  Matt
>>
>>
>>> Best wishes,
>>> Zongze
>>>
>>>
>>> On Mon, 27 Feb 2023 at 20:19, Matthew Knepley  wrote:
>>>
 On Sat, Feb 18, 2023 at 6:41 AM Zongze Yang 
 wrote:

> Another question on mesh coarsening is about `DMCoarsen` which will
> fail when running in parallel.
>
> I generate a mesh in Firedrake, and then create function space and
> functions, after that, I get the dmplex and coarsen it.
> When running in serials, I get the mesh coarsened correctly. But it
> failed with errors in ParMMG when running parallel.
>
> However, If I did not create function space and functions on the
> original mesh, everything works fine too.
>
> The code and the error logs are attached.
>

 I believe the problem is that Firedrake and PETSc currently have
 incompatible coordinate spaces. We are working
 to fix this, and I expect it to work by this summer.

   Thanks,

  Matt


> Thank you for your time and attention。
>
> Best wishes,
> Zongze
>
>
> On Sat, 18 Feb 2023 at 15:24, Zongze Yang 
> wrote:
>
>> Dear PETSc Group,
>>
>> I am writing to inquire about the function DMAdaptLabel in PETSc.
>> I am trying to use it coarse a mesh, but the resulting mesh is
>> refined.
>>
>> In the following code, all of the `adpat` label values were set to 2
>> (DM_ADAPT_COARSEN).
>> There must be something wrong. Could you give some suggestions?
>>
>> ```python
>> from firedrake import *
>> from firedrake.petsc import PETSc
>>
>> def mark_all_cells(mesh):
>> plex = mesh.topology_dm
>> with PETSc.Log.Event("ADD_ADAPT_LABEL"):
>> plex.createLabel('adapt')
>> cs, ce = plex.getHeightStratum(0)
>> for i in range(cs, ce):
>> plex.setLabelValue('adapt', i, 2)
>>
>> return plex
>>
>> mesh = RectangleMesh(10, 10, 1, 1)
>>
>> x = SpatialCoordinate(mesh)
>> V = FunctionSpace(mesh, 'CG', 1)
>> f = Function(V).interpolate(10 + 10*sin(x[0]))
>> triplot(mesh)
>>
>> plex = mark_all_cells(mesh)
>> new_plex = plex.adaptLabel('adapt')
>> mesh = Mesh(new_plex)
>> triplot(mesh)
>> ```
>>
>> Thank you very much for your time.
>>
>> Best wishes,
>> Zongze
>>
>

 --
 What most experimenters take for granted before they begin their
 experiments is infinitely more interesting than any results to which their
 experiments lead.
 -- Norbert Wiener

 https://www.cse.buffalo.edu/~knepley/
 

Re: [petsc-users] Inquiry regarding DMAdaptLabel function

2023-02-27 Thread Zongze Yang
Yes, It seems that firedrake only works with DMPlex. Thanks.

Best wishes,
Zongze


On Mon, 27 Feb 2023 at 22:53, Matthew Knepley  wrote:

> On Mon, Feb 27, 2023 at 9:45 AM Zongze Yang  wrote:
>
>> Hi, Matt
>>
>> Thanks for your clarification. Can I change the type of DMPlex to
>> DMForest?
>>
>
> You can, however DMForest is for structured adaptive meshes using
> quadtrees, and I do not believe
> Firedrake works with that.
>
>   Thanks,
>
> Matt
>
>
>> Best wishes,
>> Zongze
>>
>>
>> On Mon, 27 Feb 2023 at 20:18, Matthew Knepley  wrote:
>>
>>> On Sat, Feb 18, 2023 at 2:25 AM Zongze Yang 
>>> wrote:
>>>
 Dear PETSc Group,

 I am writing to inquire about the function DMAdaptLabel in PETSc.
 I am trying to use it coarse a mesh, but the resulting mesh is refined.

 In the following code, all of the `adpat` label values were set to 2
 (DM_ADAPT_COARSEN).
 There must be something wrong. Could you give some suggestions?

>>>
>>> Sorry for the late reply. You are right, I need to put in error messages
>>> for this. Here is what is happening.
>>> PETSc tries to fallback if you do not have certain packages. In this
>>> case, you are not using DMForest,
>>> which responds to both coarsen and refine, so the
>>> mesh generator interprets all markers as refine (they
>>> cannot coarsen). I will add a check that fails on the coarsen marker.
>>>
>>> Coarsening is much more difficult in the presence of boundaries, which
>>> is why it is not implemented in
>>> most packages. For unstructured coarsening, I do not think there is any
>>> choice but MMG.
>>>
>>>   Thanks,
>>>
>>>  Matt
>>>
>>> ```python
 from firedrake import *
 from firedrake.petsc import PETSc

 def mark_all_cells(mesh):
 plex = mesh.topology_dm
 with PETSc.Log.Event("ADD_ADAPT_LABEL"):
 plex.createLabel('adapt')
 cs, ce = plex.getHeightStratum(0)
 for i in range(cs, ce):
 plex.setLabelValue('adapt', i, 2)

 return plex

 mesh = RectangleMesh(10, 10, 1, 1)

 x = SpatialCoordinate(mesh)
 V = FunctionSpace(mesh, 'CG', 1)
 f = Function(V).interpolate(10 + 10*sin(x[0]))
 triplot(mesh)

 plex = mark_all_cells(mesh)
 new_plex = plex.adaptLabel('adapt')
 mesh = Mesh(new_plex)
 triplot(mesh)
 ```

 Thank you very much for your time.

 Best wishes,
 Zongze

>>>
>>>
>>> --
>>> What most experimenters take for granted before they begin their
>>> experiments is infinitely more interesting than any results to which their
>>> experiments lead.
>>> -- Norbert Wiener
>>>
>>> https://www.cse.buffalo.edu/~knepley/
>>> 
>>>
>>
>
> --
> What most experimenters take for granted before they begin their
> experiments is infinitely more interesting than any results to which their
> experiments lead.
> -- Norbert Wiener
>
> https://www.cse.buffalo.edu/~knepley/
> 
>


Re: [petsc-users] Inquiry regarding DMAdaptLabel function

2023-02-27 Thread Pierre Jolivet


> On 27 Feb 2023, at 4:16 PM, Matthew Knepley  wrote:
> 
> On Mon, Feb 27, 2023 at 10:13 AM Pierre Jolivet  > wrote:
>>> On 27 Feb 2023, at 3:59 PM, Matthew Knepley >> > wrote:
>>> 
>>> On Mon, Feb 27, 2023 at 9:53 AM Zongze Yang >> > wrote:
 Hi, Matt,
 
 I tested coarsening a mesh by using ParMMg without firedrake, and found 
 some issues:
  see the code and results here:  
 https://gitlab.com/petsc/petsc/-/issues/1331
 
 Could you have a look and give some comments or suggestions?
>>> 
>>> I replied on the issue. More generally, the adaptive refinement software 
>>> has not seen wide use
>> 
>> :)
>> Matt probably meant “the _DMPlex interface_ to adaptive refinement software 
>> has not seen wide use”, Mmg has been rather widely used for 10+ years (here 
>> is a 13-year old presentation 
>> https://www.ljll.math.upmc.fr/hecht/ftp/ff++days/2010/exposes/Morice-MeshMetric.pdf).
> 
> The interface is certainly new, but even ParMMG is only from Nov 2016, which 
> is very new if you are an old person :)

Indeed. In fact, I do believe we should add a DMPlex mechanism to centralize 
(redistribute on a single process) a DMPlex and to call Mmg instead of ParMmg.
It would certainly not be scalable for large meshes but:
1) there is no need for ParMmg on small-/medium-scale meshes
2) Mmg is more robust than ParMmg at this point in time
3) Mmg has more feature than ParMmg at this point in time, e.g., implicit 
remeshing using a level-set
4) there is more industry money funnelled into Mmg than into ParMmg 
I think the mechanism I mentioned initially was in the TODO list of the 
Firedrake people (or yours?), maybe it’s already done, but in any case it’s not 
hooked in the Mmg adaptor code, though it should (erroring out in the case 
where the communicator is of size greater than one would then not happen 
anymore).

Thanks,
Pierre

>   Thanks,
> 
> Matt
>  
>> Thanks,
>> Pierre
>> 
>>> , and I expect
>>> more of these kinds of bugs until more people use it.
>>> 
>>>   Thanks,
>>> 
>>>  Matt
>>>  
 Best wishes,
 Zongze
 
 
 On Mon, 27 Feb 2023 at 20:19, Matthew Knepley >>> > wrote:
> On Sat, Feb 18, 2023 at 6:41 AM Zongze Yang  > wrote:
>> Another question on mesh coarsening is about `DMCoarsen` which will fail 
>> when running in parallel.
>> 
>> I generate a mesh in Firedrake, and then create function space and 
>> functions, after that, I get the dmplex and coarsen it.
>> When running in serials, I get the mesh coarsened correctly. But it 
>> failed with errors in ParMMG when running parallel.
>> 
>> However, If I did not create function space and functions on the 
>> original mesh, everything works fine too.
>> 
>> The code and the error logs are attached.
> 
> I believe the problem is that Firedrake and PETSc currently have 
> incompatible coordinate spaces. We are working
> to fix this, and I expect it to work by this summer.
> 
>   Thanks,
> 
>  Matt
>  
>> Thank you for your time and attention。
>> 
>> Best wishes,
>> Zongze
>> 
>> 
>> On Sat, 18 Feb 2023 at 15:24, Zongze Yang > > wrote:
>>> Dear PETSc Group,
>>> 
>>> I am writing to inquire about the function DMAdaptLabel in PETSc. 
>>> I am trying to use it coarse a mesh, but the resulting mesh is refined.
>>> 
>>> In the following code, all of the `adpat` label values were set to 2 
>>> (DM_ADAPT_COARSEN).
>>> There must be something wrong. Could you give some suggestions?
>>>  
>>> ```python
>>> from firedrake import *
>>> from firedrake.petsc import PETSc
>>> 
>>> def mark_all_cells(mesh):
>>> plex = mesh.topology_dm
>>> with PETSc.Log.Event("ADD_ADAPT_LABEL"):
>>> plex.createLabel('adapt')
>>> cs, ce = plex.getHeightStratum(0)
>>> for i in range(cs, ce):
>>> plex.setLabelValue('adapt', i, 2)
>>> 
>>> return plex
>>> 
>>> mesh = RectangleMesh(10, 10, 1, 1)
>>> 
>>> x = SpatialCoordinate(mesh)
>>> V = FunctionSpace(mesh, 'CG', 1)
>>> f = Function(V).interpolate(10 + 10*sin(x[0]))
>>> triplot(mesh)
>>> 
>>> plex = mark_all_cells(mesh)
>>> new_plex = plex.adaptLabel('adapt')
>>> mesh = Mesh(new_plex)
>>> triplot(mesh)
>>> ```
>>> 
>>> Thank you very much for your time.
>>> 
>>> Best wishes,
>>> Zongze
> 
> 
> -- 
> What most experimenters take for granted before they begin their 
> experiments is infinitely more interesting than any results to which 
> their experiments lead.
> -- Norbert Wiener
> 
> https://www.cse.buffalo.edu/~knepley/ 
> 

Re: [petsc-users] Inquiry regarding DMAdaptLabel function

2023-02-27 Thread Matthew Knepley
On Mon, Feb 27, 2023 at 10:13 AM Pierre Jolivet  wrote:

> On 27 Feb 2023, at 3:59 PM, Matthew Knepley  wrote:
>
> On Mon, Feb 27, 2023 at 9:53 AM Zongze Yang  wrote:
>
>> Hi, Matt,
>>
>> I tested coarsening a mesh by using ParMMg without firedrake, and found
>> some issues:
>>  see the code and results here:
>> https://gitlab.com/petsc/petsc/-/issues/1331
>>
>> Could you have a look and give some comments or suggestions?
>>
>
> I replied on the issue. More generally, the adaptive refinement software
> has not seen wide use
>
>
> :)
> Matt probably meant “the _DMPlex interface_ to adaptive refinement
> software has not seen wide use”, Mmg has been rather widely used for 10+
> years (here is a 13-year old presentation
> https://www.ljll.math.upmc.fr/hecht/ftp/ff++days/2010/exposes/Morice-MeshMetric.pdf
> ).
>

The interface is certainly new, but even ParMMG is only from Nov 2016,
which is very new if you are an old person :)

  Thanks,

Matt


> Thanks,
> Pierre
>
> , and I expect
> more of these kinds of bugs until more people use it.
>
>   Thanks,
>
>  Matt
>
>
>> Best wishes,
>> Zongze
>>
>>
>> On Mon, 27 Feb 2023 at 20:19, Matthew Knepley  wrote:
>>
>>> On Sat, Feb 18, 2023 at 6:41 AM Zongze Yang 
>>> wrote:
>>>
 Another question on mesh coarsening is about `DMCoarsen` which will
 fail when running in parallel.

 I generate a mesh in Firedrake, and then create function space and
 functions, after that, I get the dmplex and coarsen it.
 When running in serials, I get the mesh coarsened correctly. But it
 failed with errors in ParMMG when running parallel.

 However, If I did not create function space and functions on the
 original mesh, everything works fine too.

 The code and the error logs are attached.

>>>
>>> I believe the problem is that Firedrake and PETSc currently have
>>> incompatible coordinate spaces. We are working
>>> to fix this, and I expect it to work by this summer.
>>>
>>>   Thanks,
>>>
>>>  Matt
>>>
>>>
 Thank you for your time and attention。

 Best wishes,
 Zongze


 On Sat, 18 Feb 2023 at 15:24, Zongze Yang  wrote:

> Dear PETSc Group,
>
> I am writing to inquire about the function DMAdaptLabel in PETSc.
> I am trying to use it coarse a mesh, but the resulting mesh is refined.
>
> In the following code, all of the `adpat` label values were set to 2
> (DM_ADAPT_COARSEN).
> There must be something wrong. Could you give some suggestions?
>
> ```python
> from firedrake import *
> from firedrake.petsc import PETSc
>
> def mark_all_cells(mesh):
> plex = mesh.topology_dm
> with PETSc.Log.Event("ADD_ADAPT_LABEL"):
> plex.createLabel('adapt')
> cs, ce = plex.getHeightStratum(0)
> for i in range(cs, ce):
> plex.setLabelValue('adapt', i, 2)
>
> return plex
>
> mesh = RectangleMesh(10, 10, 1, 1)
>
> x = SpatialCoordinate(mesh)
> V = FunctionSpace(mesh, 'CG', 1)
> f = Function(V).interpolate(10 + 10*sin(x[0]))
> triplot(mesh)
>
> plex = mark_all_cells(mesh)
> new_plex = plex.adaptLabel('adapt')
> mesh = Mesh(new_plex)
> triplot(mesh)
> ```
>
> Thank you very much for your time.
>
> Best wishes,
> Zongze
>

>>>
>>> --
>>> What most experimenters take for granted before they begin their
>>> experiments is infinitely more interesting than any results to which their
>>> experiments lead.
>>> -- Norbert Wiener
>>>
>>> https://www.cse.buffalo.edu/~knepley/
>>> 
>>>
>>
>
> --
> What most experimenters take for granted before they begin their
> experiments is infinitely more interesting than any results to which their
> experiments lead.
> -- Norbert Wiener
>
> https://www.cse.buffalo.edu/~knepley/
> 
>
>
>

-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener

https://www.cse.buffalo.edu/~knepley/ 


Re: [petsc-users] Inquiry regarding DMAdaptLabel function

2023-02-27 Thread Pierre Jolivet


> On 27 Feb 2023, at 3:59 PM, Matthew Knepley  wrote:
> 
> On Mon, Feb 27, 2023 at 9:53 AM Zongze Yang  > wrote:
>> Hi, Matt,
>> 
>> I tested coarsening a mesh by using ParMMg without firedrake, and found some 
>> issues:
>>  see the code and results here:  https://gitlab.com/petsc/petsc/-/issues/1331
>> 
>> Could you have a look and give some comments or suggestions?
> 
> I replied on the issue. More generally, the adaptive refinement software has 
> not seen wide use

:)
Matt probably meant “the _DMPlex interface_ to adaptive refinement software has 
not seen wide use”, Mmg has been rather widely used for 10+ years (here is a 
13-year old presentation 
https://www.ljll.math.upmc.fr/hecht/ftp/ff++days/2010/exposes/Morice-MeshMetric.pdf).

Thanks,
Pierre

> , and I expect
> more of these kinds of bugs until more people use it.
> 
>   Thanks,
> 
>  Matt
>  
>> Best wishes,
>> Zongze
>> 
>> 
>> On Mon, 27 Feb 2023 at 20:19, Matthew Knepley > > wrote:
>>> On Sat, Feb 18, 2023 at 6:41 AM Zongze Yang >> > wrote:
 Another question on mesh coarsening is about `DMCoarsen` which will fail 
 when running in parallel.
 
 I generate a mesh in Firedrake, and then create function space and 
 functions, after that, I get the dmplex and coarsen it.
 When running in serials, I get the mesh coarsened correctly. But it failed 
 with errors in ParMMG when running parallel.
 
 However, If I did not create function space and functions on the original 
 mesh, everything works fine too.
 
 The code and the error logs are attached.
>>> 
>>> I believe the problem is that Firedrake and PETSc currently have 
>>> incompatible coordinate spaces. We are working
>>> to fix this, and I expect it to work by this summer.
>>> 
>>>   Thanks,
>>> 
>>>  Matt
>>>  
 Thank you for your time and attention。
 
 Best wishes,
 Zongze
 
 
 On Sat, 18 Feb 2023 at 15:24, Zongze Yang >>> > wrote:
> Dear PETSc Group,
> 
> I am writing to inquire about the function DMAdaptLabel in PETSc. 
> I am trying to use it coarse a mesh, but the resulting mesh is refined.
> 
> In the following code, all of the `adpat` label values were set to 2 
> (DM_ADAPT_COARSEN).
> There must be something wrong. Could you give some suggestions?
>  
> ```python
> from firedrake import *
> from firedrake.petsc import PETSc
> 
> def mark_all_cells(mesh):
> plex = mesh.topology_dm
> with PETSc.Log.Event("ADD_ADAPT_LABEL"):
> plex.createLabel('adapt')
> cs, ce = plex.getHeightStratum(0)
> for i in range(cs, ce):
> plex.setLabelValue('adapt', i, 2)
> 
> return plex
> 
> mesh = RectangleMesh(10, 10, 1, 1)
> 
> x = SpatialCoordinate(mesh)
> V = FunctionSpace(mesh, 'CG', 1)
> f = Function(V).interpolate(10 + 10*sin(x[0]))
> triplot(mesh)
> 
> plex = mark_all_cells(mesh)
> new_plex = plex.adaptLabel('adapt')
> mesh = Mesh(new_plex)
> triplot(mesh)
> ```
> 
> Thank you very much for your time.
> 
> Best wishes,
> Zongze
>>> 
>>> 
>>> -- 
>>> What most experimenters take for granted before they begin their 
>>> experiments is infinitely more interesting than any results to which their 
>>> experiments lead.
>>> -- Norbert Wiener
>>> 
>>> https://www.cse.buffalo.edu/~knepley/ 
> 
> 
> -- 
> What most experimenters take for granted before they begin their experiments 
> is infinitely more interesting than any results to which their experiments 
> lead.
> -- Norbert Wiener
> 
> https://www.cse.buffalo.edu/~knepley/ 


Re: [petsc-users] Inquiry regarding DMAdaptLabel function

2023-02-27 Thread Matthew Knepley
On Mon, Feb 27, 2023 at 9:53 AM Zongze Yang  wrote:

> Hi, Matt,
>
> I tested coarsening a mesh by using ParMMg without firedrake, and found
> some issues:
>  see the code and results here:
> https://gitlab.com/petsc/petsc/-/issues/1331
>
> Could you have a look and give some comments or suggestions?
>

I replied on the issue. More generally, the adaptive refinement software
has not seen wide use, and I expect
more of these kinds of bugs until more people use it.

  Thanks,

 Matt


> Best wishes,
> Zongze
>
>
> On Mon, 27 Feb 2023 at 20:19, Matthew Knepley  wrote:
>
>> On Sat, Feb 18, 2023 at 6:41 AM Zongze Yang  wrote:
>>
>>> Another question on mesh coarsening is about `DMCoarsen` which will fail
>>> when running in parallel.
>>>
>>> I generate a mesh in Firedrake, and then create function space and
>>> functions, after that, I get the dmplex and coarsen it.
>>> When running in serials, I get the mesh coarsened correctly. But it
>>> failed with errors in ParMMG when running parallel.
>>>
>>> However, If I did not create function space and functions on the
>>> original mesh, everything works fine too.
>>>
>>> The code and the error logs are attached.
>>>
>>
>> I believe the problem is that Firedrake and PETSc currently have
>> incompatible coordinate spaces. We are working
>> to fix this, and I expect it to work by this summer.
>>
>>   Thanks,
>>
>>  Matt
>>
>>
>>> Thank you for your time and attention。
>>>
>>> Best wishes,
>>> Zongze
>>>
>>>
>>> On Sat, 18 Feb 2023 at 15:24, Zongze Yang  wrote:
>>>
 Dear PETSc Group,

 I am writing to inquire about the function DMAdaptLabel in PETSc.
 I am trying to use it coarse a mesh, but the resulting mesh is refined.

 In the following code, all of the `adpat` label values were set to 2
 (DM_ADAPT_COARSEN).
 There must be something wrong. Could you give some suggestions?

 ```python
 from firedrake import *
 from firedrake.petsc import PETSc

 def mark_all_cells(mesh):
 plex = mesh.topology_dm
 with PETSc.Log.Event("ADD_ADAPT_LABEL"):
 plex.createLabel('adapt')
 cs, ce = plex.getHeightStratum(0)
 for i in range(cs, ce):
 plex.setLabelValue('adapt', i, 2)

 return plex

 mesh = RectangleMesh(10, 10, 1, 1)

 x = SpatialCoordinate(mesh)
 V = FunctionSpace(mesh, 'CG', 1)
 f = Function(V).interpolate(10 + 10*sin(x[0]))
 triplot(mesh)

 plex = mark_all_cells(mesh)
 new_plex = plex.adaptLabel('adapt')
 mesh = Mesh(new_plex)
 triplot(mesh)
 ```

 Thank you very much for your time.

 Best wishes,
 Zongze

>>>
>>
>> --
>> What most experimenters take for granted before they begin their
>> experiments is infinitely more interesting than any results to which their
>> experiments lead.
>> -- Norbert Wiener
>>
>> https://www.cse.buffalo.edu/~knepley/
>> 
>>
>

-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener

https://www.cse.buffalo.edu/~knepley/ 


Re: [petsc-users] Inquiry regarding DMAdaptLabel function

2023-02-27 Thread Matthew Knepley
On Mon, Feb 27, 2023 at 9:45 AM Zongze Yang  wrote:

> Hi, Matt
>
> Thanks for your clarification. Can I change the type of DMPlex to DMForest?
>

You can, however DMForest is for structured adaptive meshes using
quadtrees, and I do not believe
Firedrake works with that.

  Thanks,

Matt


> Best wishes,
> Zongze
>
>
> On Mon, 27 Feb 2023 at 20:18, Matthew Knepley  wrote:
>
>> On Sat, Feb 18, 2023 at 2:25 AM Zongze Yang  wrote:
>>
>>> Dear PETSc Group,
>>>
>>> I am writing to inquire about the function DMAdaptLabel in PETSc.
>>> I am trying to use it coarse a mesh, but the resulting mesh is refined.
>>>
>>> In the following code, all of the `adpat` label values were set to 2
>>> (DM_ADAPT_COARSEN).
>>> There must be something wrong. Could you give some suggestions?
>>>
>>
>> Sorry for the late reply. You are right, I need to put in error messages
>> for this. Here is what is happening.
>> PETSc tries to fallback if you do not have certain packages. In this
>> case, you are not using DMForest,
>> which responds to both coarsen and refine, so the
>> mesh generator interprets all markers as refine (they
>> cannot coarsen). I will add a check that fails on the coarsen marker.
>>
>> Coarsening is much more difficult in the presence of boundaries, which is
>> why it is not implemented in
>> most packages. For unstructured coarsening, I do not think there is any
>> choice but MMG.
>>
>>   Thanks,
>>
>>  Matt
>>
>> ```python
>>> from firedrake import *
>>> from firedrake.petsc import PETSc
>>>
>>> def mark_all_cells(mesh):
>>> plex = mesh.topology_dm
>>> with PETSc.Log.Event("ADD_ADAPT_LABEL"):
>>> plex.createLabel('adapt')
>>> cs, ce = plex.getHeightStratum(0)
>>> for i in range(cs, ce):
>>> plex.setLabelValue('adapt', i, 2)
>>>
>>> return plex
>>>
>>> mesh = RectangleMesh(10, 10, 1, 1)
>>>
>>> x = SpatialCoordinate(mesh)
>>> V = FunctionSpace(mesh, 'CG', 1)
>>> f = Function(V).interpolate(10 + 10*sin(x[0]))
>>> triplot(mesh)
>>>
>>> plex = mark_all_cells(mesh)
>>> new_plex = plex.adaptLabel('adapt')
>>> mesh = Mesh(new_plex)
>>> triplot(mesh)
>>> ```
>>>
>>> Thank you very much for your time.
>>>
>>> Best wishes,
>>> Zongze
>>>
>>
>>
>> --
>> What most experimenters take for granted before they begin their
>> experiments is infinitely more interesting than any results to which their
>> experiments lead.
>> -- Norbert Wiener
>>
>> https://www.cse.buffalo.edu/~knepley/
>> 
>>
>

-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener

https://www.cse.buffalo.edu/~knepley/ 


Re: [petsc-users] Inquiry regarding DMAdaptLabel function

2023-02-27 Thread Zongze Yang
Hi, Matt,

I tested coarsening a mesh by using ParMMg without firedrake, and found
some issues:
 see the code and results here:
https://gitlab.com/petsc/petsc/-/issues/1331

Could you have a look and give some comments or suggestions?

Best wishes,
Zongze


On Mon, 27 Feb 2023 at 20:19, Matthew Knepley  wrote:

> On Sat, Feb 18, 2023 at 6:41 AM Zongze Yang  wrote:
>
>> Another question on mesh coarsening is about `DMCoarsen` which will fail
>> when running in parallel.
>>
>> I generate a mesh in Firedrake, and then create function space and
>> functions, after that, I get the dmplex and coarsen it.
>> When running in serials, I get the mesh coarsened correctly. But it
>> failed with errors in ParMMG when running parallel.
>>
>> However, If I did not create function space and functions on the original
>> mesh, everything works fine too.
>>
>> The code and the error logs are attached.
>>
>
> I believe the problem is that Firedrake and PETSc currently have
> incompatible coordinate spaces. We are working
> to fix this, and I expect it to work by this summer.
>
>   Thanks,
>
>  Matt
>
>
>> Thank you for your time and attention。
>>
>> Best wishes,
>> Zongze
>>
>>
>> On Sat, 18 Feb 2023 at 15:24, Zongze Yang  wrote:
>>
>>> Dear PETSc Group,
>>>
>>> I am writing to inquire about the function DMAdaptLabel in PETSc.
>>> I am trying to use it coarse a mesh, but the resulting mesh is refined.
>>>
>>> In the following code, all of the `adpat` label values were set to 2
>>> (DM_ADAPT_COARSEN).
>>> There must be something wrong. Could you give some suggestions?
>>>
>>> ```python
>>> from firedrake import *
>>> from firedrake.petsc import PETSc
>>>
>>> def mark_all_cells(mesh):
>>> plex = mesh.topology_dm
>>> with PETSc.Log.Event("ADD_ADAPT_LABEL"):
>>> plex.createLabel('adapt')
>>> cs, ce = plex.getHeightStratum(0)
>>> for i in range(cs, ce):
>>> plex.setLabelValue('adapt', i, 2)
>>>
>>> return plex
>>>
>>> mesh = RectangleMesh(10, 10, 1, 1)
>>>
>>> x = SpatialCoordinate(mesh)
>>> V = FunctionSpace(mesh, 'CG', 1)
>>> f = Function(V).interpolate(10 + 10*sin(x[0]))
>>> triplot(mesh)
>>>
>>> plex = mark_all_cells(mesh)
>>> new_plex = plex.adaptLabel('adapt')
>>> mesh = Mesh(new_plex)
>>> triplot(mesh)
>>> ```
>>>
>>> Thank you very much for your time.
>>>
>>> Best wishes,
>>> Zongze
>>>
>>
>
> --
> What most experimenters take for granted before they begin their
> experiments is infinitely more interesting than any results to which their
> experiments lead.
> -- Norbert Wiener
>
> https://www.cse.buffalo.edu/~knepley/
> 
>


Re: [petsc-users] Inquiry regarding DMAdaptLabel function

2023-02-27 Thread Zongze Yang
Hi, Matt

Thanks for your clarification. Can I change the type of DMPlex to DMForest?

Best wishes,
Zongze


On Mon, 27 Feb 2023 at 20:18, Matthew Knepley  wrote:

> On Sat, Feb 18, 2023 at 2:25 AM Zongze Yang  wrote:
>
>> Dear PETSc Group,
>>
>> I am writing to inquire about the function DMAdaptLabel in PETSc.
>> I am trying to use it coarse a mesh, but the resulting mesh is refined.
>>
>> In the following code, all of the `adpat` label values were set to 2
>> (DM_ADAPT_COARSEN).
>> There must be something wrong. Could you give some suggestions?
>>
>
> Sorry for the late reply. You are right, I need to put in error messages
> for this. Here is what is happening.
> PETSc tries to fallback if you do not have certain packages. In this case,
> you are not using DMForest,
> which responds to both coarsen and refine, so the
> mesh generator interprets all markers as refine (they
> cannot coarsen). I will add a check that fails on the coarsen marker.
>
> Coarsening is much more difficult in the presence of boundaries, which is
> why it is not implemented in
> most packages. For unstructured coarsening, I do not think there is any
> choice but MMG.
>
>   Thanks,
>
>  Matt
>
> ```python
>> from firedrake import *
>> from firedrake.petsc import PETSc
>>
>> def mark_all_cells(mesh):
>> plex = mesh.topology_dm
>> with PETSc.Log.Event("ADD_ADAPT_LABEL"):
>> plex.createLabel('adapt')
>> cs, ce = plex.getHeightStratum(0)
>> for i in range(cs, ce):
>> plex.setLabelValue('adapt', i, 2)
>>
>> return plex
>>
>> mesh = RectangleMesh(10, 10, 1, 1)
>>
>> x = SpatialCoordinate(mesh)
>> V = FunctionSpace(mesh, 'CG', 1)
>> f = Function(V).interpolate(10 + 10*sin(x[0]))
>> triplot(mesh)
>>
>> plex = mark_all_cells(mesh)
>> new_plex = plex.adaptLabel('adapt')
>> mesh = Mesh(new_plex)
>> triplot(mesh)
>> ```
>>
>> Thank you very much for your time.
>>
>> Best wishes,
>> Zongze
>>
>
>
> --
> What most experimenters take for granted before they begin their
> experiments is infinitely more interesting than any results to which their
> experiments lead.
> -- Norbert Wiener
>
> https://www.cse.buffalo.edu/~knepley/
> 
>


Re: [petsc-users] Inquiry regarding DMAdaptLabel function

2023-02-27 Thread Matthew Knepley
On Sat, Feb 18, 2023 at 6:41 AM Zongze Yang  wrote:

> Another question on mesh coarsening is about `DMCoarsen` which will fail
> when running in parallel.
>
> I generate a mesh in Firedrake, and then create function space and
> functions, after that, I get the dmplex and coarsen it.
> When running in serials, I get the mesh coarsened correctly. But it failed
> with errors in ParMMG when running parallel.
>
> However, If I did not create function space and functions on the original
> mesh, everything works fine too.
>
> The code and the error logs are attached.
>

I believe the problem is that Firedrake and PETSc currently have
incompatible coordinate spaces. We are working
to fix this, and I expect it to work by this summer.

  Thanks,

 Matt


> Thank you for your time and attention。
>
> Best wishes,
> Zongze
>
>
> On Sat, 18 Feb 2023 at 15:24, Zongze Yang  wrote:
>
>> Dear PETSc Group,
>>
>> I am writing to inquire about the function DMAdaptLabel in PETSc.
>> I am trying to use it coarse a mesh, but the resulting mesh is refined.
>>
>> In the following code, all of the `adpat` label values were set to 2
>> (DM_ADAPT_COARSEN).
>> There must be something wrong. Could you give some suggestions?
>>
>> ```python
>> from firedrake import *
>> from firedrake.petsc import PETSc
>>
>> def mark_all_cells(mesh):
>> plex = mesh.topology_dm
>> with PETSc.Log.Event("ADD_ADAPT_LABEL"):
>> plex.createLabel('adapt')
>> cs, ce = plex.getHeightStratum(0)
>> for i in range(cs, ce):
>> plex.setLabelValue('adapt', i, 2)
>>
>> return plex
>>
>> mesh = RectangleMesh(10, 10, 1, 1)
>>
>> x = SpatialCoordinate(mesh)
>> V = FunctionSpace(mesh, 'CG', 1)
>> f = Function(V).interpolate(10 + 10*sin(x[0]))
>> triplot(mesh)
>>
>> plex = mark_all_cells(mesh)
>> new_plex = plex.adaptLabel('adapt')
>> mesh = Mesh(new_plex)
>> triplot(mesh)
>> ```
>>
>> Thank you very much for your time.
>>
>> Best wishes,
>> Zongze
>>
>

-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener

https://www.cse.buffalo.edu/~knepley/ 


Re: [petsc-users] Inquiry regarding DMAdaptLabel function

2023-02-27 Thread Matthew Knepley
On Sat, Feb 18, 2023 at 2:25 AM Zongze Yang  wrote:

> Dear PETSc Group,
>
> I am writing to inquire about the function DMAdaptLabel in PETSc.
> I am trying to use it coarse a mesh, but the resulting mesh is refined.
>
> In the following code, all of the `adpat` label values were set to 2
> (DM_ADAPT_COARSEN).
> There must be something wrong. Could you give some suggestions?
>

Sorry for the late reply. You are right, I need to put in error messages
for this. Here is what is happening.
PETSc tries to fallback if you do not have certain packages. In this case,
you are not using DMForest,
which responds to both coarsen and refine, so the
mesh generator interprets all markers as refine (they
cannot coarsen). I will add a check that fails on the coarsen marker.

Coarsening is much more difficult in the presence of boundaries, which is
why it is not implemented in
most packages. For unstructured coarsening, I do not think there is any
choice but MMG.

  Thanks,

 Matt

```python
> from firedrake import *
> from firedrake.petsc import PETSc
>
> def mark_all_cells(mesh):
> plex = mesh.topology_dm
> with PETSc.Log.Event("ADD_ADAPT_LABEL"):
> plex.createLabel('adapt')
> cs, ce = plex.getHeightStratum(0)
> for i in range(cs, ce):
> plex.setLabelValue('adapt', i, 2)
>
> return plex
>
> mesh = RectangleMesh(10, 10, 1, 1)
>
> x = SpatialCoordinate(mesh)
> V = FunctionSpace(mesh, 'CG', 1)
> f = Function(V).interpolate(10 + 10*sin(x[0]))
> triplot(mesh)
>
> plex = mark_all_cells(mesh)
> new_plex = plex.adaptLabel('adapt')
> mesh = Mesh(new_plex)
> triplot(mesh)
> ```
>
> Thank you very much for your time.
>
> Best wishes,
> Zongze
>


-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener

https://www.cse.buffalo.edu/~knepley/