# Index of inner nodes (or boundary nodes)

**URL:** <https://fenicsproject.discourse.group/t/index-of-inner-nodes-or-boundary-nodes/1524>\
**Category:** Uncategorized\
**Created:** [September 13, 2019, 7:36am UTC](https://fenicsproject.discourse.group/t/index-of-inner-nodes-or-boundary-nodes/1524 "2019-09-13T07:36:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yannik](https://avatars.discourse-cdn.com/v4/letter/y/5fc32e/32.png) [@Yannik](https://fenicsproject.discourse.group/u/Yannik)\
**Post date:** [September 13, 2019, 7:36am UTC](https://fenicsproject.discourse.group/t/index-of-inner-nodes-or-boundary-nodes/1524/1 "2019-09-13T07:36:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![MiroK](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/mirok/32/33_2.png) [@MiroK](https://fenicsproject.discourse.group/u/MiroK)\
**Post date:** [September 13, 2019, 8:49am UTC](https://fenicsproject.discourse.group/t/index-of-inner-nodes-or-boundary-nodes/1524/2 "2019-09-13T08:49:01Z")

</div>

Hi, consider the following

```python
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))

```

---

<div class="post-metadata">

**Author:** ![Yannik](https://avatars.discourse-cdn.com/v4/letter/y/5fc32e/32.png) [@Yannik](https://fenicsproject.discourse.group/u/Yannik)\
**Post date:** [September 13, 2019, 9:41am UTC](https://fenicsproject.discourse.group/t/index-of-inner-nodes-or-boundary-nodes/1524/3 "2019-09-13T09:41:38Z")

</div>

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!
