Re: [petsc-users] DMPlex periodic face coordinates

2024-05-15 Thread Jed Brown




 Matteo Semplice  writes: >> The way that periodic coordinates work is that it stores a DG >> coordinate field by cell. Faces default back to the vertices. You >> could think about  also




ZjQcmQRYFpfptBannerStart




  

  
	This Message Is From an External Sender
  
  
This message came from outside your organization.
  



 
  


ZjQcmQRYFpfptBannerEnd




Matteo Semplice  writes:

>> The way that periodic coordinates work is that it stores a DG 
>> coordinate field by cell. Faces default back to the vertices. You 
>> could think about  also putting DG coordinates on faces, but no one 
>> had asked, and it is potentially expensive.
>>
>> If you really need them to keep going, face coordinates can be 
>> extracted from cell coordinates. Otherwise, I can do it after the 
>> PETSc Meeting. Or, we are happy to take contributions adding this.
>
> Hi.
>
> I mainly wanted to check that this was expected and not a result of a 
> setup of my DM. No need to change Petsc now except maybe issuing a 
> warning if the fallback to continuous coordinates will give wrong 
> results. As for my code, I think I can extract the info from the cell 
> coordinates in a pre-processing phase and if this crazy FV methods I am 
> implementing will survive for long enough, I'll think about contributing.

You can also check out the "isoperiodic" example (src/dm/impls/plex/tests/ex49.c) if you want the semantic that donor and image points are separate points that map to the same global dofs. This avoids having any "DG coordinate field".



Re: [petsc-users] DMPlex periodic face coordinates

2024-05-15 Thread Matteo Semplice

Il 14/05/24 15:02, Matthew Knepley ha scritto:
On Tue, May 14, 2024 at 12:14 AM Matteo Semplice 
 wrote:


Dear petsc-users, I am playing with DMPlexGetCellCoordinates and
observing that it returns correct periodic coordinates for cells,
but not for faces. More precisely, adding
PetscCall(DMPlexGetHeightStratum(dm, 1, , )); for
ZjQcmQRYFpfptBannerStart
This Message Is From an External Sender
This message came from outside your organization.
ZjQcmQRYFpfptBannerEnd

Dear petsc-users,

    I am playing with DMPlexGetCellCoordinates and observing that
it returns correct periodic coordinates for cells, but not for faces.

More precisely, adding

PetscCall(DMPlexGetHeightStratum(dm, 1, , ));
    for (f = fStart; f < fEnd; ++f) {
  const PetscScalar *array;
  PetscScalar   *x = NULL;
  PetscInt   ndof;
  PetscBool  isDG;

  PetscCall(DMPlexGetCellCoordinates(dm, f, , ,
, ));
  PetscCheck(ndof % cdim == 0, PETSC_COMM_SELF,
PETSC_ERR_ARG_INCOMP, "ndof not divisible by cdim");
  PetscCall(PetscPrintf(PETSC_COMM_SELF, "Face #%"
PetscInt_FMT " coordinates\n", f - fStart));
  for (PetscInt i = 0; i < ndof; i += cdim)
PetscCall(PetscScalarView(cdim, [i], PETSC_VIEWER_STDOUT_SELF));
  PetscCall(DMPlexRestoreCellCoordinates(dm, f, , ,
, ));
    }

to src/dm/impls/plex/tutorials/ex8.c, I get

$ ./ex8 -dm_plex_dim 2 -petscspace_degree 1 -dm_plex_simplex 0
-dm_plex_box_faces 3,2 -dm_plex_box_bd periodic,none -dm_view
-view_coord
DM Object: box 1 MPI process
  type: plex
box in 2 dimensions:
  Number of 0-cells per rank: 9
  Number of 1-cells per rank: 15
  Number of 2-cells per rank: 6
Periodic mesh (PERIODIC, NONE) coordinates localized

[...]

Element #2 coordinates
 0:   6.6667e-01   0.e+00
 0:   1.e+00   0.e+00 <<<- correct
 0:   1.e+00   5.e-01
 0:   6.6667e-01   5.e-01
[...]

Face #0 coordinates
 0:   0.e+00   0.e+00
 0:   3.e-01   0.e+00
Face #1 coordinates
 0:   3.e-01   0.e+00
 0:   6.6667e-01   0.e+00
Face #2 coordinates
 0:   6.6667e-01   0.e+00
 0:   0.e+00   0.e+00  <<< should be (0.66,0.00) and
(1.00,0.00)

Is there a way to recover correct periodic coordinates in the case
of periodic DMPLex?

The way that periodic coordinates work is that it stores a DG 
coordinate field by cell. Faces default back to the vertices. You 
could think about  also putting DG coordinates on faces, but no one 
had asked, and it is potentially expensive.


If you really need them to keep going, face coordinates can be 
extracted from cell coordinates. Otherwise, I can do it after the 
PETSc Meeting. Or, we are happy to take contributions adding this.


Hi.

I mainly wanted to check that this was expected and not a result of a 
setup of my DM. No need to change Petsc now except maybe issuing a 
warning if the fallback to continuous coordinates will give wrong 
results. As for my code, I think I can extract the info from the cell 
coordinates in a pre-processing phase and if this crazy FV methods I am 
implementing will survive for long enough, I'll think about contributing.


Just to double-check, can I assume that the order in which 
DMPlexGetCellCoordinates returns the coordinates matches the ordering of 
vertices in DMPlexGetCone for the uninterpolated DM, right?


Best

    Matteo


Re: [petsc-users] DMPlex periodic face coordinates

2024-05-14 Thread Matthew Knepley
On Tue, May 14, 2024 at 12:14 AM Matteo Semplice <
matteo.sempl...@uninsubria.it> wrote:

> Dear petsc-users, I am playing with DMPlexGetCellCoordinates and observing
> that it returns correct periodic coordinates for cells, but not for faces.
> More precisely, adding PetscCall(DMPlexGetHeightStratum(dm, 1, ,
> )); for
> ZjQcmQRYFpfptBannerStart
> This Message Is From an External Sender
> This message came from outside your organization.
>
> ZjQcmQRYFpfptBannerEnd
>
> Dear petsc-users,
>
> I am playing with DMPlexGetCellCoordinates and observing that it
> returns correct periodic coordinates for cells, but not for faces.
>
> More precisely, adding
>
> PetscCall(DMPlexGetHeightStratum(dm, 1, , ));
> for (f = fStart; f < fEnd; ++f) {
>   const PetscScalar *array;
>   PetscScalar   *x = NULL;
>   PetscInt   ndof;
>   PetscBool  isDG;
>
>   PetscCall(DMPlexGetCellCoordinates(dm, f, , , , ));
>   PetscCheck(ndof % cdim == 0, PETSC_COMM_SELF, PETSC_ERR_ARG_INCOMP,
> "ndof not divisible by cdim");
>   PetscCall(PetscPrintf(PETSC_COMM_SELF, "Face #%" PetscInt_FMT "
> coordinates\n", f - fStart));
>   for (PetscInt i = 0; i < ndof; i += cdim)
> PetscCall(PetscScalarView(cdim, [i], PETSC_VIEWER_STDOUT_SELF));
>   PetscCall(DMPlexRestoreCellCoordinates(dm, f, , , ,
> ));
> }
>
> to src/dm/impls/plex/tutorials/ex8.c, I get
>
> $ ./ex8 -dm_plex_dim 2 -petscspace_degree 1 -dm_plex_simplex 0
> -dm_plex_box_faces 3,2 -dm_plex_box_bd periodic,none -dm_view -view_coord
> DM Object: box 1 MPI process
>   type: plex
> box in 2 dimensions:
>   Number of 0-cells per rank: 9
>   Number of 1-cells per rank: 15
>   Number of 2-cells per rank: 6
> Periodic mesh (PERIODIC, NONE) coordinates localized
>
> [...]
>
> Element #2 coordinates
>  0:   6.6667e-01   0.e+00
>  0:   1.e+00   0.e+00  <<<- correct
>  0:   1.e+00   5.e-01
>  0:   6.6667e-01   5.e-01
> [...]
>
> Face #0 coordinates
>  0:   0.e+00   0.e+00
>  0:   3.e-01   0.e+00
> Face #1 coordinates
>  0:   3.e-01   0.e+00
>  0:   6.6667e-01   0.e+00
> Face #2 coordinates
>  0:   6.6667e-01   0.e+00
>  0:   0.e+00   0.e+00  <<< should be (0.66,0.00) and
> (1.00,0.00)
>
> Is there a way to recover correct periodic coordinates in the case of
> periodic DMPLex?
>
> The way that periodic coordinates work is that it stores a DG coordinate
field by cell. Faces default back to the vertices. You could think about
also putting DG coordinates on faces, but no one had asked, and it is
potentially expensive.

If you really need them to keep going, face coordinates can be extracted
from cell coordinates. Otherwise, I can do it after the PETSc Meeting. Or,
we are happy to take contributions adding this.

  Thanks,

 Matt

> Thanks in advance
>
> Matteo
>


-- 
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://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!Z9-i-9O8yBcNimBXW2alc9XHsn9MWWFwaobajlfkDcoghfrtZlVX4CRMW0BdrXaX2hOabPupZN8g9FrtoNf2$
  



[petsc-users] DMPlex periodic face coordinates

2024-05-13 Thread Matteo Semplice

Dear petsc-users,

    I am playing with DMPlexGetCellCoordinates and observing that it 
returns correct periodic coordinates for cells, but not for faces.


More precisely, adding

PetscCall(DMPlexGetHeightStratum(dm, 1, , ));
    for (f = fStart; f < fEnd; ++f) {
  const PetscScalar *array;
  PetscScalar   *x = NULL;
  PetscInt   ndof;
  PetscBool  isDG;

  PetscCall(DMPlexGetCellCoordinates(dm, f, , , , ));
  PetscCheck(ndof % cdim == 0, PETSC_COMM_SELF, 
PETSC_ERR_ARG_INCOMP, "ndof not divisible by cdim");
  PetscCall(PetscPrintf(PETSC_COMM_SELF, "Face #%" PetscInt_FMT " 
coordinates\n", f - fStart));
  for (PetscInt i = 0; i < ndof; i += cdim) 
PetscCall(PetscScalarView(cdim, [i], PETSC_VIEWER_STDOUT_SELF));
  PetscCall(DMPlexRestoreCellCoordinates(dm, f, , , 
, ));

    }

to src/dm/impls/plex/tutorials/ex8.c, I get

$ ./ex8 -dm_plex_dim 2 -petscspace_degree 1 -dm_plex_simplex 0 
-dm_plex_box_faces 3,2 -dm_plex_box_bd periodic,none -dm_view -view_coord

DM Object: box 1 MPI process
  type: plex
box in 2 dimensions:
  Number of 0-cells per rank: 9
  Number of 1-cells per rank: 15
  Number of 2-cells per rank: 6
Periodic mesh (PERIODIC, NONE) coordinates localized

[...]

Element #2 coordinates
 0:   6.6667e-01   0.e+00
 0:   1.e+00   0.e+00 <<<- correct
 0:   1.e+00   5.e-01
 0:   6.6667e-01   5.e-01
[...]

Face #0 coordinates
 0:   0.e+00   0.e+00
 0:   3.e-01   0.e+00
Face #1 coordinates
 0:   3.e-01   0.e+00
 0:   6.6667e-01   0.e+00
Face #2 coordinates
 0:   6.6667e-01   0.e+00
 0:   0.e+00   0.e+00  <<< should be (0.66,0.00) and 
(1.00,0.00)


Is there a way to recover correct periodic coordinates in the case of 
periodic DMPLex?


Thanks in advance

Matteo