- Thank you received: 0
Mapping for mesh.face to index into gfu.vec
2 years 10 months ago - 2 years 10 months ago #4211
by alex.v
Mapping for mesh.face to index into gfu.vec was created 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
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 10 months ago by alex.v.
2 years 9 months ago #4214
by hvwahl
Replied by hvwahl on topic Mapping for mesh.face to index into gfu.vec
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
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
Time to create page: 0.108 seconds