scikit-fem: Indexing error in find_dofs

Hi,

first off, great library: Indeed fills an important niche, thanks for creating!

While using it, being new to finite element methods, I have encountered an error that I am not sure how to fix (whether it’s a wrong use on my end or a problem with the code). When trying to implement Dirichlet boundary conditions (following example 14) in a MeshTet, I am encountering a numpy indexing error.

My script condenses to the following:

m = MeshTet3D(p=some_nodes, t=some_elements, boundaries=some_boundaries)
e = ElementTetP1()
basis = InteriorBasis(m, e)
surface_basis = FacetBasis(m, e, facets=m.boundaries["top"])
surface_dofs = surface_basis.find_dofs()['all'].all()

The boundaries dict contains, among others, an array of faces belonging to the top side. Things run smoothly up to the surface_basis.find_dofs() call, where the following error is raised:

~/.local/lib/python3.8/site-packages/skfem/mesh/mesh3d/mesh3d.py in boundary_edges(self)
     39                               facets]))
     40                    for itr in range(self.facets.shape[0])])).T, axis=1)
---> 41         return np.nonzero((self.edges.T[:, None] == boundary_edges)
     42                           .all(-1).any(-1))[0]
     43 
AttributeError: 'bool' object has no attribute 'all'

The error occurs because the shapes of self.edges.T[:,None], (180751, 1, 2), and boundary_edges, (107076, 2), do not match for an elementwise comparison. From a quick skim of the code, I assume that some sort of element comparison is taking place in that function, but I am not sure about that (without some in depth study of the source). I thought to open this issue because maybe there is something fundamentally wrong in my code snipped above and I hope it’s not too stupid, or otherwise it might be a bug.

Thanks in advance, Malte

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (12 by maintainers)

Most upvoted comments

Since you are using linear elements, as a workaround you should be able to dig those DOF-numbers directly from the mesh structure. E.g., if you are assembling only scalar problems, just use the indices boundary_dofs = m.boundary_nodes().