# Implementing a two-sided boundary condition

In the complex plane the function arctan(y/x)=theta can be made continuous everywhere except on the positive x-axis, where it takes on the values theta=0 (on the upper side of the positive x-axis) and theta=2pi (on the lower side of the positive x-axis). This function is a solution to the Laplace equation Div(grad(theta))=0. Suppose we want to solve this equation on the unit circle with the positive x-axis removed. The Dirichlet boundary conditions would be
theta=0 (on the upper side of the positive x-axis) and theta=2
pi (on the lower side of the positive x-axis).
Is there some way that one can specify such two-sided boundary conditions in FEniCSx?

I just realized that this is an unfair question because the solution is singular at the origin. So can we change the question to be defined on an annulus excluding some region around the origin to avoid this singularity, but still containing the slit along the positive x-axis?

See for instance Setting multiple Dirichlet condition — FEniCSx tutorial

Thanks for the link. The link discusses how to impose two Dirichlet conditions on two distinct boundary components of the domain, but in the problem I am considering, the two Dirichlet conditions must be imposed on the same boundary component. The key here is that the boundary component is in the interior of the domain itself. So look at the following example

In this case, the slit in the interior is a boundary region. It can be thought of a limiting case of the following geometry

where the interior hole has been shrunk to a line. In the limiting case where the hole is a line, you want to impose a boundary condition on the top component of the hole and on the bottom component of the hole, but both components are the same line segment. So how do you do this?
In physical terms I can explain what I think needs to be done, but I don’t know how to do it in FEniCSx. First we triangulate the region so that the slit is the union of the edges of the triangles that border it. These triangles fall into two groups: triangles above the slit and triangles below the slit. Without the slit, each triangle above the slit will be connected to a corresponding triangle below the slit along their common edge. What must be done is then disconnect all of these triangles in the mesh, so that they are no longer considered to be contiguous. Once this has been done, the slit will now correspond to two distinct boundary components in the mesh: the ones bounding triangles above it, and the ones bounding triangles below it.
What must then be done in FEniCSx is to write code to select each of these two different boundary components. Then the link you provided can be used to impose the boundary conditions. So there are three unanswered questions here:

1. How does one mesh the rectangle so that no triangles traverse the slit above? They should only bound the slit along an edge.
2. How does one disconnect the triangles above the slit from the ones below it?
3. How does one select the two distinct boundary components in order to impose boundary conditions?

The closest thing I can think of is tutorial_lagrange_multipliers_interface
(disclaimer: I am the author of that)

Divide your rectangle in four parts:

1. to the left of the line (from top to bottom)
2. to the right of the line (from top to bottom)
3. above the line (from top to the line itself)
4. below the line (from the line to the bottom)

Define four unknowns in the four subdomains, and:

1. use a multiplier to have the solution match between subdomains 1, 3, 4 (vertical line orthogonal to the segment in your picture at the left-end point of the segment)
2. use another multiplier the enforce matching between subdomains 2, 3, 4
3. DO not use a multiplier at the interface between 3 and 4, so that the solution can effectively be discontinuous
4. apply a BC for the unknown in subdomain 3
5. apply a (different) BC for the unknown in subdomain 4

If you generate the mesh with gmsh (see e.g. Defining subdomains for different materials — FEniCSx tutorial ), and you have gmsh mark each of the four subdomains, that the mesh will be guaranteed to match at each interface.

Otherwise, a simpler solution would be, as in your second question, to disconnect triangles above/before the segment. However, I don’t know how to do that: it’s possible that gmsh allows to do that, but you would have to look that up in its documentation.

Your suggestion makes sense to me. I am also interested in the more general problem you solve in tutorial_lagrange_multipliers_interface but I am a beginner in all of this and it will take me time to digest it. Thanks for your help!