I often need to access the mesh coordinates of a function, so that I can manually set their values. The script below, for example, sets func(x,y,z) = x+y+z, where func is a vector on a mesh.
My question is, is it possible to implement a similar method, only instead of a function space with "Lagrange" 1, it has "DG" 0.
from dolfin import *
import numpy as np
mesh = BoxMesh(-1,-1,-1,1,1,1,20,20,20)
V = FunctionSpace(mesh, "Lagrange", 1)
func = Function(V)
n = V.dim()
d = mesh.geometry().dim()
coor = V.dofmap().tabulate_all_coordinates(mesh)
coor.resize((n,d))
vertex_values = np.zeros(mesh.num_vertices())
for vertex in vertices(mesh):
x = vertex.x(0)
y = vertex.x(1)
z = vertex.x(2)
vertex_values[vertex.index()] = x+y+z
func.vector()[:] = vertex_values[dof_to_vertex_map(V)]
plot(func,interactive=True)