Dear all,
I am trying to change the values of a function on some vertices of the mesh, but I am finding errors. To be more clear,
- I first define a mesh over a domain and then I have create a submesh using BoundaryMesh.
- I define a function over the main mesh and I set it to zero.
- I try to change only its values over the boundary, based on another function, defined on the boundarymesh, using boundarymesh.entity_map(0) to have a map between vertices on the boundary and vertices on the domain.
However this does not work. I am copying part of the code below.
What am I doing wrong?
Thanks!
from dolfin import *
from fenics import *
from mshr import *
Omega = Circle(Point(0,0), 2)
mesh = generate_mesh(Omega,10)
bmesh = BoundaryMesh(mesh, 'exterior')
vb_2_v = bmesh.entity_map(0)
V = FunctionSpace(mesh, 'P', 1)
V_Boundary = FunctionSpace(bmesh,'P', 1)
f = Expression('x[1] < Eps + tol && x[1] > - Eps - tol ? 1 : 0', degree=1, tol=1E-14, Eps = 0.3)
fb = interpolate(f, V_Boundary)
F_domain = interpolate(Constant(0.0), V)
for i in range(bmesh.num_vertices()):
j = vb_2_v.array()[i]
F_domain.vector()[j] = fb.vector().array()[i]
interpolate(F_domain, V)
plot(F_domain, interactive = True)