I have found a somewhat unexpected behavior of dolfin that occurs when I manually set the nodal values of the boundaries of a CR
FE space. See the pictures and the code example attached.
More precisely, I proceed as follows:
- setup the space
V
- extract the
dofs
associated with the boundary of the mesh
- setup a vector of ones of the size
V.dim()
- set the boundary dofs to
-1
- assign this vector to the nodal values of a function
v
in V
- plot the results
Obviously, for CR
the lower boundary is not set, while the values just below upper boundary are doubled.
For a CG
space everything is as expected.
Any ideas on that??
Here are the pics:
1. for V
is CG
or order 2
2. for V
is CR
And here is the code:
import dolfin
import numpy as np
N = 4
mesh = dolfin.UnitSquareMesh(N, N, 'crossed')
scheme = 'CR' # 'TH' or 'CR'
if scheme == 'TH':
V = dolfin.VectorFunctionSpace(mesh, "CG", 2)
elif scheme == 'CR':
V = dolfin.VectorFunctionSpace(mesh, "CR", 1)
# define the boundary
def topleftbotright(x, on_boundary):
return (np.fabs(x[1] - 1.0) < dolfin.DOLFIN_EPS
or np.fabs(x[0] - 1.0) < dolfin.DOLFIN_EPS
or np.fabs(x[1]) < dolfin.DOLFIN_EPS
or np.fabs(x[0]) < dolfin.DOLFIN_EPS)
noslip = dolfin.Constant((0.0, 0.0))
bc = dolfin.DirichletBC(V, noslip, topleftbotright)
bcdict = bc.get_boundary_values()
bcinds = bcdict.keys()
innerinds = np.setdiff1d(range(V.dim()), bcinds)
bcinds = np.setdiff1d(range(V.dim()), innerinds)
# vector of -1
vvec = np.zeros((V.dim(), 1)) - 1
# set inner nodes to 1
vvec[innerinds, 0] = 1
# assign to function
v = dolfin.Function(V)
v.vector().set_local(vvec)
dolfin.plot(v)
dolfin.interactive(True)
"""