Setting Delta-function-like initial condition

Consider:

from dolfin import *

p = Point(0.41, 0.42, 0)

mesh = UnitSquareMesh(10,10)
tree = mesh.bounding_box_tree()

# Find which cell point is located in
cell, distance = tree.compute_closest_entity(p)
vertices = mesh.cells()[cell]

V = FunctionSpace(mesh, "CG", 1)

# Find the closest vertex in the cell
vertex_coordinates = mesh.coordinates()[vertices]
dist = 1e3
closest = None
for i, v in enumerate(vertex_coordinates):
    p_ = Point(v)
    dist_ = p.distance(p_)
    print(v)
    if dist_ < dist:
        dist = dist_
        closest_local = i
closest_vertex = vertices[closest_local]

# Find dof corresponding to vertex
vtd_p = vertex_to_dof_map(V)
dof_number = vtd_p[closest_vertex]

print(closest_vertex)
# Set value to 1
v = Function(V)
v.vector()[dof_number] = 1
print("Function at ", V.tabulate_dof_coordinates()[dof_number], " is ", v.vector().get_local()[dof_number])
1 Like