Dear all,
I would like to set values of a function manually based on an unstructured grid file (in the VTK format). For this reason I have came up with the following solution, that seems to yield correct values:
reader = vtk.vtkUnstructuredGridReader()
reader.SetFileName("scalarField.vtk")
pointData = reader.GetOutput().GetPointData()
scalarsNp = np.float64(numpy_support.vtk_to_numpy(pointData.GetArray(0)))
mesh = Mesh('mesh.xml.gz')
Q = FunctionSpace(mesh, "CG", 1)
fun = Function(Q)
fun.vector().set_local(scalarsNp[Q.dofmap().vertex_to_dof_map(mesh)])
This essentially works because the CG(1) element uses samples from the vertex positions that are set to the field values at these positions based on the input file.
The question I have is given samples from the cells of the unstructured grid instead of the vertices how could I store this information in DG(0) elements?
By inspecting the length of the vector of samples for this function space, it does not equal the cell count of the unstructured grid (101896 vs 88744), so manual setting does not equal copying over the cell values.
Thanks a lot!