Forum Message

 

 

We have moved the forum to https://forum.ngsolve.org . This is an archived version of the topics until 05/05/23. All the topics were moved to the new forum and conversations can be continued there. This forum is just kept as legacy to not invalidate old links. If you want to continue a conversation just look for the topic in the new forum.

Notice

The forum is in read only mode.

Mapping for mesh.face to index into gfu.vec

More
2 years 2 months ago - 2 years 2 months ago #4211 by alex.v
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
Last edit: 2 years 2 months ago by alex.v.
More
2 years 1 month ago #4214 by hvwahl
Hi Alex,

the GridFunction entries are sorted in terms of globals dofs. Checkout the [url=https://docu.ngsolve.org/nightly/i-tutorials/unit-1.8-meshtopology/meshtopology.html#Dofs ]doku[/url] 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 
More
2 years 1 month ago #4218 by alex.v
The works great, thank you!
Time to create page: 0.125 seconds