I have a question about posing inflow boundary condition for transport equation: b dot grad(u)=f, with inflow boundary condition, i.e., I want to pose Dirichelet boundary condition in a subset of boundary which satisfies b dot n < 0, where n is the outer normal vector and b depends on coordinates, i.e., b=b(x,y). I tried to define it in the following sense:

bc = DirichletBC(V, dot(b, n)<0, ‘on_boundary’)

But it does not work, anyone can help me?
Thank you very much!

The following steps may be the right approach to take:

Assuming that you know \mathbf{b}(x, y), you should be able to find the coordinates on the boundary that satisfy \mathbf{b} \boldsymbol{\cdot} \mathbf{n} < 0 .

You will then need to use these coordinates to mark the part of the boundary that you want to impose your Dirichlet condition on. See, for example, this from legacy fenics or this from fenicsX.

Apply the Dirichlet condition to the part you marked for it.

Thank you for your reply!
I did not understand the idea of “mark”, could you give me a concrete example?
For example,

mesh = UnitSquareMesh(2, 2)
b = Expression((“x[0]”,“x[1]”), degree=2)

class BoundaryX0(SubDomain):
def inside(self, x, on_boundary):
return on_boundary and dot(n(x),b(x))<0

Then, how to define correctly ‘dot(n(x),b(x))’, how to get the normal vector at the boundary and mark the inflow part? Could you please help me to complete this code?

To get the outward point normal at the external boundary, use

n = FacetNormal(mesh)

A concrete example of applying Dirichlet boundary conditions on marked boundaries is given here.

Is it not the case that you can just find the coordinates on the boundary where you want to apply the Dirichlet boundary condition based on \mathbf{b}, which you know? Then, you can apply the Dirichlet boundary condition as normal by following the link above or any of the relevant demos such as the nonlinear Poisson demo. There may be a more elegant way to do this, but this seems like the simplest.