Normal flux-like boundary conditions with non-constant normal vector

In the mixed-poisson example of Dolfinx demo, the way normal flux BCs (which is essential in this context) are imposed is by interpolating a position dependent function h(x) into the Hdiv-like space (e.g RT, BDM) and then passing it to the fem.dirichletbc with the corresponding dofs and Hdiv part of the mixed space.

Being specific, in the aforementioned example, only y direction value are set because the \vec{n} = [0, \pm 1]^T. Mathematically we generalise this by taking \vec{g}(\vec{x}, \vec{n}) = g_n(\vec{x}) \vec{n}(\vec{x}), with \vec{n}(\vec{x}) spatially dependent (think in curved boundary). We could think in programming a vectorial function like this to imporse the normal flux g_n given.

In legacy Fenics, I used to program that using a UserExpression, implementing the method eval_cell with x and ufc_cell as arguments (the latter contains information about the normal vector) full code

def eval_cell(self, values, x, ufc_cell):
        cell = df.Cell(self.mesh, ufc_cell.index)
        n = cell.normal(ufc_cell.local_facet)
        values[:] = self.g*n.array()[:self.mesh.geometric_dimension()]

Is there a way to do the same dolfinx?

See for instance:

The rationale for a more complicated structure is that DOLFINx supports curved elements, where the normal isn’t constant on each facet.

1 Like

Thanks a lot! It works! (I would never be able to come up with this piece of code by my own though ;))
By the way, cell_eval was a buggy thing in Legacy Fenics, it worked 10% of times (yes randomly) for normal traction imposition (elasticity Hdiv analogous to Darcy).

Hopefully this feature gets more streamlined over time (as more people use it, and I figure out a better interface).