Mapping for mesh.face to index into gfu.vec

I am working with a 0th order DG L2 FES on a 2D mesh. I have created a gridfunction and projected a scalar field onto it.

I am trying to group elements together based on the value of the scalar field in each element, and later output that grouping back into a different gridfunction (same FES) to visualize the results.

I know that the mesh will provide me with all of the faces (which for a 2D are the elements) using mesh.faces. I naively assumed that gfu.vec[face.nr] would store the value associated with a given face.

Testing this, I found that this isn’t true. Using:

gfu = GridFunction(fes)
for face in mesh.faces:
gfu.vec[face.nr] = face.nr

I then export to vtk and compare the verticies of the element which has a specific value of face.nr and the vertex coordinates given by vertex.point for the verticies in face.verticies.

So, is there a built-in way to get this mapping so that I can read/write a value from gfu.vec given a face (a MeshNode)?

Alex

Hi Alex,

the GridFunction entries are sorted in terms of globals dofs. Checkout the doku here for getting dogs from an element. I thing you just need to do

gfu.vec[fes.GetDofNrs(face)[0]] = face.nr

in your case.

Best wishes,
Henry

The works great, thank you!