Notation warning and measure flux on an edge

Hello,

I am trying to implement a flux BC on the Poisson’s equation for the top boundary and then measure the flux at the bottom boundary, I received a warning says that

Notation dx[meshfunction] is deprecated. Please use dx(subdomain_data=meshfunction) instead.

I didn’t use dx[meshfunction] in my code but I still received this warning, so I am concerned if my implementation was incorrect; also, the out flux on the bottom edge I computed is the same as the applied flux on the top boundary, this seems odd. following is my code:

from dolfin import *

mesh = UnitSquareMesh(32, 32)
V = FunctionSpace(mesh, "Lagrange", 2)

def bot(x):
    return x[1] < DOLFIN_EPS

u0 = Constant(20.0)
bc_bot = DirichletBC(V, u0, bot)

boundary_parts = MeshFunction("size_t", mesh, mesh.topology().dim()-1, 0)

boundary_parts.set_all(0) #marks whole cube as domain 0

class Top(SubDomain):
   def inside(self, x, on_boundary):
      return on_boundary and x[1] > 1.0 - DOLFIN_EPS
top = Top()
top.mark(boundary_parts, 1) #marks the top of the cube as 1

class Bot(SubDomain):
   def inside(self, x, on_boundary):
      return on_boundary and x[1] < DOLFIN_EPS
bottom = Bot()
bottom.mark(boundary_parts, 2) #marks the bottom of the cube as 2

ds=Measure('ds')[boundary_parts]

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

f = Constant(0.0)
g = Constant(-100.0) # in flux, negative

alpha = 10. #thermal diffusivity

a = Constant(alpha)*inner(grad(u), grad(v))*dx
L = f*v*dx - g*v*ds(1)


u = Function(V)
solve(a == L, u, bc_bot)


outflux = assemble(Constant(alpha)*grad(u)[1]*ds(2))

print('outflux = ', outflux)

I appreciate any advice on this! Thank you!

You can get rid of the warning with the following replacement:

#ds=Measure('ds')[boundary_parts]
ds=Measure('ds',subdomain_data=boundary_parts)

The fact that the flux at the bottom exactly matches the flux at the top is not surprising, since the exact solution just varies linearly from the top of the domain to the bottom. This solution is in your discrete space, so you will recover it exactly with Galerkin’s method. For some additional information on computing conservative fluxes on Dirichlet boundaries in more complicated scenarios, see the discussions here and here.

1 Like