Skip to content
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

Exception generated when trying to get the face indices on a specific element #172

Closed
i3s93 opened this issue Mar 13, 2023 · 5 comments
Closed
Assignees
Labels

Comments

@i3s93
Copy link

i3s93 commented Mar 13, 2023

Hello,

I'm working with an application where I need to loop over faces associated with a particular element. My initial approach for this was to generate the element-to-face table using elem_face_tbl = mesh.ElementToFaceTable(), but it seems that this method is not currently supported by PyMFEM. Instead, for each element, I use the method faces, orientations = mesh.GetElementFaces(i) to return the face indices and their respective orientations as separate Python lists. When I do this, I see the following exception:

Verification failed: (el_to_face != NULL) is false:
 --> el_to_face not generated
 ... in function: void mfem::Mesh::GetElementFaces(int, mfem::Array<int>&, mfem::Array<int>&) const
 ... in file: /PyMFEM/external/mfem/mesh/mesh.cpp:6150

The relevant part of the traceback is here:

  File "/PyMFEM_env/lib/python3.9/site-packages/mfem/_ser/mesh.py", line 670, in GetElementFaces
    _mesh.Mesh_GetElementFaces(self, i, ia, ib)
RuntimeError: PyMFEM error (mfem::ErrorException): Verification failed: (el_to_face != NULL) is false:
 --> el_to_face not generated
 ... in function: void mfem::Mesh::GetElementFaces(int, mfem::Array<int>&, mfem::Array<int>&) const
 ... in file: /PyMFEM/external/mfem/mesh/mesh.cpp:6150

Internally, the call to MFEM uses the element to face table that I was originally trying to use, and I think the two problems might be related. I've checked other methods, such as mesh.GetElementVertices(i), and they work just fine, but I need access to the faces in my particular application. I'm following the API provided in docs/manual.txt (see 4-4). I'm looking to see if there are any recommendations for fixing this.

Thank you, in advance, for your help and suggestions!

@sshiraiwa
Copy link
Member

sshiraiwa commented Mar 19, 2023

@i3s93
In my environment, both work just fine. See below. Actually, I do recall that I encountered this issue before.
Reading mesh.cpp, this table is created from GetElementToFaceTable. And this method is, generally, called
when dim>2 (3D mesh). How are you creating the mesh object? Maybe there is a specific pattern in which the table
is not create.

Python 3.8.10 (default, Nov 14 2022, 12:59:47) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mfem
>>> mfem.__version__
'4.5.0.2rc1'
>>> import mfem.ser as mfem
>>> mesh = mfem.Mesh('beam-tet.mesh')
>>> faces, orientations = mesh.GetElementFaces(2)
>>> faces
[7, 8, 6, 9]
>>> mesh.ElementToFaceTable()
<mfem._ser.table.Table; proxy of <Swig Object of type 'mfem::Table *' at 0x37a88b0> >

@sshiraiwa sshiraiwa self-assigned this Mar 19, 2023
@i3s93
Copy link
Author

i3s93 commented Mar 20, 2023

Hi @sshiraiwa, thank you for your response. Actually, the mesh I used in my example is a 2-D Cartesian grid, which I create using mesh = mfem.Mesh(N_x, N_y, elem_type). As a workaround, I manually created this lookup table, which works fine, but I was hoping to just use the existing functionality. By any chance, do you recall what caused this issue before?

@i3s93
Copy link
Author

i3s93 commented Mar 20, 2023

@sshiraiwa Just to follow up, the issue only seems to happen when I use a Cartesian mesh. If I read in the mesh, as you have done, the error goes away. It looks like the table is not being generated for Cartesian meshes.

@v-dobrev
Copy link
Member

Mesh::GetElementFaces is a 3D-only method. In 2D you probably want to call Mesh::GetElementEdges.

One has to be cautious -- sometimes mfem uses "faces" to refer to (dim-1)-dimensional mesh entities and sometimes to refer specifically to 2-dimensional mesh entities.

@sshiraiwa
Copy link
Member

@v-dobrev , Thank you for the clarification. @i3s93, closing this for now. Feel free to open if your issue is not resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants