DirichletBC 'on_boundary' Expressions evaluated on the interior

Issue #867 duplicate
Nico Schlömer created an issue

(This is from an old Q&A.)

When defining an Expression for DirichletBC, I noticed that this expression is evaluated for points which do not sit on the boundary, more precisely for vertices and edge midpoints of all cells (not facets) adjacent to a boundary.

This is becoming a problem for me now since I'm dealing with an expression which is only defined on the boundary.

The following code marks all points at which the DirichletBC is evaluated.

from dolfin import *

import matplotlib.pyplot as plt


class MyExpr(Expression):
    def eval(self, values, x):
        values[0] = 0.0
        plt.plot(x[0], x[1], 'xk')
        return


my_expr = MyExpr(degree=0)

mesh = UnitSquareMesh(5, 5)
V = FunctionSpace(mesh, 'CG', 2)

u = TrialFunction(V)
v = TestFunction(V)

a = dot(grad(u), grad(v)) * dx
L = v * dx

bcs = DirichletBC(V, my_expr, 'on_boundary')

sol = Function(V)
solve(a == L, sol, bcs=bcs)

plt.show()

Figure_1.png

Comments (3)

  1. Jan Blechta

    DirichletBC computes a result by restricting a given value (GenericFunction) by restricting it to a target element. This happens by

    • taking dof values from Function::vector() if value is Function and function spaces (elements and meshes) match,
    • or restricting GenericFunction to target element otherwise.

    Target element is a cell element and restrictions is done by evaluating dual basis on given Dirichlet value (which has a GenericFunction::eval method by contract) using the assumption that target element is nodal. Dual basis (nodes) are typically spread across whole cell, so that's why the interior evaluation.

    (The issue is that if meshes do not match, there is a silent interpolation. Mentioned here and below in the thread.)

    There was already some discussion about pointwise/quadrature expressions which might solve this problem in the future.

  2. Log in to comment