New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to import a 2nd order mesh? #982
Comments
The PETSc gmsh reader doesn't know about second order (or higher) coordinate fields. I thought that @mlange05 had done some work on this for nektar, but it doesn't appear to have been merged in PETSc. If that was available we would just need to do a little work in firedrake to recognise these cases. |
Thanks for the reply. For the moment I can try a workaround by interpolating To emphasize the relevance of higher order meshes, let me mention that |
It seems that DMPlex has been updated. Now the error message reads:
|
That check is traversing the mesh by cell and then gathering all the mesh points in the closure of the cells. We require in Firedrake that union(c, closure(c)) == mesh. I.e. all mesh points can be visited by walking the closure of some cell. Sometimes when you make a gmsh mesh, that is not the case. Have you done the necessary magic with Physical Line/Point etc...? |
the |
In this case, it looks like somehow things that dmplex reads as "facets" are not in the closure of the cells. |
e.g.
|
So I think you need to fix the mesh reading first... |
I literally have no idea how to do that. The
returns :( |
So this is telling you that there are 313 mesh points in the mesh. But not all of them are reachable by traversing the closure of the cells. As evidenced by some of those entries being 0. In particular a bunch of the facets have no support (i.e. they are not connected to a cell). If the terminology is confusing, I recommend Matt's notes http://www.caam.rice.edu/~caam519/CSBook.pdf, particularly chapter 7. |
@wence- I'm running into a similar issue but your link to Matt's notes has gone dead -- do you have an updated link? |
Updated link (Matt is now at Buffalo): https://cse.buffalo.edu/~knepley/classes/caam519/CSBook.pdf |
I now get a different error when trying Alberto's mesh. I can lead the order-2 mesh, but when I try to read the .coordinate field, I get the following error:
I think PETSc can read higher-order meshes from gmsh now and the problem might just be some impedance mismatch on the Firedrake side? |
We don't inspect the PETSc object to determine the element for the coordinate space (so |
I get the same error when I manually change 1 to 2 at this line in mesh.py. That line is definitely going to be a problem because it hard-codes the element degree. This code is also going to hurt because the assumed shape is (num_vertices, geometric_dimension), but that's no longer true for higher-order coordinate fields. Do you know how to sniff the degree of the coordinate field from the DMPlex? Can't seem to find this in the PETSc docs. |
Let's ask @knepley. I think you have to pull the |
@wence- is correct, but we can just use the Field directly here. The sequence would be something like
|
Ok, I used the Python equivalent of the code that @knepley wrote to get the degree and made some changes on this branch. When I manually create the plex for Alberto's mesh, I'm able to get out the FE, basis space, and degree. For some of the utility meshes I only get a PETSc Object from .getField, which I don't understand, but I was able to work around that with a try/except. Something's still not right though. For piecewise parabolic functions on triangles, there should be one degree of freedom for every vertex and one for every edge. Alberto's mesh has 41 vertices and 104 edges. I'm still hitting the same error as before only now it's unable to reshape an array of size 768 into an array of size (145, 2), whereas before when it was only counting the number of vertices that was an array of size (41, 2). I don't understand how the coordinate field from the PETSc side has 768 elements if this is the number of mesh vertices and edges. |
@danshapero The reason you get a PetscObject sometimes is that Plex allows you not to create an FE space for the coordinates, and just falls back to linear. I felt I needed to do this when FE was very immature. Now it seems like a mistake. We should be able to see what it thinks about coordinates by printing the section. So |
Gotcha, thanks for clarifying -- the code that I have falls back to linear when the result is PetscObject instead of an FE. So whether or not this suggests some change to PETSc it's good to know that it's at least doing the right thing. The following code from firedrake.petsc import PETSc
viewer = PETSc.Viewer().create()
viewer.setType("ascii")
viewer.setFileMode("r")
viewer.setFileName("disc.msh")
plex = PETSc.DMPlex().createGmsh(viewer)
print(plex.getDepthStratum(0), plex.getDepthStratum(1), plex.getDepthStratum(2), end="\n\n")
dm = plex.getCoordinateDM()
section = dm.getSection()
section.view() gives me this:
So it looks like there are 12 degrees of freedom for each of the entities in the 2nd depth stratum. All of this suggests that internally the plex is storing everything on the triangles and not on the vertices or edges (64 triangles * 6 points per triangle for parabolics * 2 DoFs per point = 768). Am I reading this right? |
That is the DG coordinate field, so the mesh is periodic. However, Plex will not give this back for dm.getCoordinates(), you need dm.getCellCoordinates(). |
I don't understand -- this shouldn't be a periodic mesh at all. When I generate an order-1 mesh, all the degrees of freedom for the coordinate field are clearly located at the vertices. Is the code that I wrote above just accessing a DG view of the coordinates and I have to do something different to access them with a different order? DMGetCellCoordinates and the related functions aren't wrapped in petsc4py. I added them and tried using them on the order-2 disc mesh but I just get a seg fault whenever I try and inspect the Vec that I get out of getCellCoordinates when I use it either on the plex itself or on the coordinate DM. Also, if this is all written down some place please let me know -- there's something I'm missing that falls between the high-level overview of DMPlex and the API reference in the PETSc docs. |
I don't understand either. Plex only makes a DG coordinate field for a periodic mesh, and even in that case, the default coordinate field is CG and you have to ask specifically for the DG one. Maybe we need to Zoom on this. I will be back in the US on Monday. |
That sounds great, I'll email you to figure out a time. Meanwhile I wrote to the PETSc mailing list to see if anyone there can clear this up for me. |
I replied over on petsc-users:
|
An alternative to avoid getting hands dirty would be to do a projection of the discontinuous coordinates into a continuous space. |
Yes, I suggested that over on petsc-users. |
Sorry for the cross-posting and thanks @jedbrown for clearing this up! I'll see if we can hack together a workaround on the Firedrake side for now. |
The minimal example
from firedrake import * mesh = Mesh("disc.msh")
fails with message
Error: error code 62 [0] DMPlexCreateGmsh() line 200 in /private/tmp/pip-8t0buL-build/src/dm/impls/plex/plexgmsh.c [0] DMPlexCreateGmsh_ReadElement() line 385 in /private/tmp/pip-8t0buL-build/src/dm/impls/plex/plexgmsh.c [0] Invalid argument [0] Unsupported Gmsh element type 8
when
disc.msh
is generated with the commandgmsh disc.geo -2 -order 2
,which creates a "2nd order" mesh (no problem arises when
disc.msh
is generatedwith
gmsh disc.geo -2 -order 1
). The filedisc.geo
describes a disc; its content readsThe text was updated successfully, but these errors were encountered: