Problem with reflective boundary conditions

Dear all,

The idea of this code is to solve the diffusion equation on a mesh with different boundary conditions. On the left and bottom sides, I want to have reflective boundary conditions which mean \gradient \phi = 0 and on the right and top sides, I want Dirichlet boundary conditions which mean \phi = 0. I’m struggling to define these boundary conditions correctly and I would really appreciate any kind of help. Here is the following code with which I have some trouble:

import dolfin as df
import numpy as np
from dolfin import *

dx = np.array ([7.5] * 22)
dy = np.array ([7.5] * 22)

mesh = df.RectangleMesh(df.Point(0, 0), df.Point(165, 165), 22, 22)

V0 = df.FunctionSpace (mesh, "DG", 0)
V1 = df.FunctionSpace (mesh, "CG", 2)

rank = V0.dim()

a0 = df.Function(V0)
f0 = df.Function(V0)
f1 = df.Function(V1)

u = df.TrialFunction(V1)
v = df.TestFunction(V1)

# Neumann with all derivatives equal to zero
def left_boundary(x, on_boundary):
    tol = 1E-14
    return on_boundary and near(x[0], 0, tol)

# Dirichlet with all values equal to zero
def right_boundary(x, on_boundary):
    tol = 1E-14
    return on_boundary and near(x[0], 165, tol)

# Neumann with all derivatives equal to zero
def bottom_boundary(x, on_boundary):
    tol = 1E-14
    return on_boundary and near(x[1], 0, tol)

# Dirichlet with all values equal to zero
def top_boundary(x, on_boundary):
    tol = 1E-14
    return on_boundary and near(x[1], 165, tol)

u_left = df.Constant(1.0)
u_right = df.Constant(0.0)

# Create the Dirichlet boundary condition instances
bc_L = df.DirichletBC(V1, u_left, left_boundary)
bc_R = df.DirichletBC(V1, u_right, right_boundary)

u_bottom = df.Constant(1.0)
u_top = df.Constant(0.0)

# Create the Dirichlet boundary condition instances
bc_B = df.DirichletBC(V1, u_bottom, bottom_boundary)
bc_T = df.DirichletBC(V1, u_top, top_boundary)

bcs = [bc_L, bc_R, bc_B, bc_T]

ds = df.Measure('ds', domain=mesh, subdomain_data=bcs)

n = df.FacetNormal(mesh)

coo1 = V1.tabulate_dof_coordinates()
coo0 = V0.tabulate_dof_coordinates()

ufl_dudv = a0 * df.inner(df.grad(u), df.grad(v))*df.dx
ufl_uvdx = a0 * u * v * df.dx
ufl_uvds = u * v * df.ds

#these functions are defined in another file but it is only to assemble the matrix in blf and csr format for another code
save_blf ("dudv.blf", ufl_dudv, a0)
save_blf ("uvdx.blf", ufl_uvdx, a0)
save_csr ("uvds.csr", ufl_uvds)

np.savetxt ("dg0.coo", coo0)
np.savetxt ("cg2.coo", coo1)

Thank you in advance for your time!!

Please use 3x` encapsulation, i.e.

```python
from dolfin import * 
#add code here
```