Index of inner nodes (or boundary nodes)

Hi everyone,

I’m using macOS Mojave (10.14.6), miniconda, and FEniCS 2018 with Python.
Say I have a mesh, a FunctionSpace V and a function u living in V, i.e.

mesh = UnitSquareMesh(25, 25)
V = FunctionSpace(mesh, 'P', 1)
u = interpolate(Constant(1.0), V)

What I want to do is to set the inner nodes of u to 0, so I want to do something like

u.vector()[index of inner nodes] = 0

The thing is that I’m working with time dependent problems and I have to set, for each time, the inner nodes to zero. So I have a Matrix U \in \mathbb{R}^{N_t \times N_h}, where N_t is the amount of time-steps. In each row of U I saved the nodal values of the solution to time, say n. E.g.

U[n, :] = u.vector()[:]

So I want something like U[:, (index of inner nodes)] = 0. I have totally no idea how I could do that.

Hi, consider the following

from dolfin import *

mesh = UnitSquareMesh(128, 128)

V = FunctionSpace(mesh, 'CG', 1)
bc = DirichletBC(V, Constant(0), 'on_boundary')
bdry_dofs = bc.get_boundary_values().keys()

first, last = V.dofmap().ownership_range()
all_dofs = range(last-first)
interior_dofs = list(set(all_dofs) - set(bdry_dofs))

This is really elegant.
Meanwhile I was also a bit lucky and got this

from dolfin import *

mesh = UnitSquareMesh(128, 128)

V = FunctionSpace(mesh, 'CG', 1)
bc = DirichletBC(V, Constant(1.0), 'on_boundary')

u = Function(V)
bc.apply(u.vector())
idx_inner = np.where(u.vector()[:] == 0.0); idx_inner = idx_inner[0]

Yours is way more better. Mine has this ugly u.vector()[:] == 0.0 term in it.
Thank you very much!