Boundary condition for a wild object

Hello everybody,

as you can see I have to handle a wild non-convex domain.
Sorry for the bad drawing, but I hope it is clear that I have several boundary conditions. 2 neumann conditions and 2 dirichlet conditions.

How can I implement these boundary conditions in Fenics?
I have problems with the special area and I haven’t done this thing with a xdmf-file. I created the domain with the Polygonfunction.

solution

As all of them are lines you can use subdomains to mark a mesh function, as shown here:

Thank you for your tip. That definitely sounds doable :slight_smile:

Hello dokken,

may I asked you something again?

# Randbedingungen-----------------------------------------------------------
class Left(SubDomain):
    def inside(self, x, on_boundary):
        return (between(x[1], (-1.0, 1.0)) and between(x[0], (4.0, -4.0)))

class Right(SubDomain):
    def inside(self, x, on_boundary):
        #return near(x[1], 1.0)
        return ((between(x[1], (2.0, 2.0)) and between(x[0], (1.0, 3.0))) and (between(x[2], (0.1, 0.0)) and between(x[1], (2.0, 2.0))) and (between(x[3], (2.0, 0.0)) and between(x[2], (0.1, 0.0))) and (between(x[4], (5.0, -3.0)) and between(x[3], (2.0, 0.0))))

class Bottom(SubDomain):
    def inside(self, x, on_boundary):
        return (between(x[1], (5.0, -3.0)) and between(x[0], (4.0, -4.0)))

class Top(SubDomain):
    def inside(self, x, on_boundary):
        return (between(x[1], (1.0, 3.0)) and between(x[0], (-1.0, 1.0)))

# Initialize sub-domain instances
left = Left()
top = Top()
right = Right()
bottom = Bottom()

# Initialize mesh function for boundary domains
boundaries = MeshFunction("size_t", mesh, mesh.topology().dim()-1, 0)
left.mark(boundaries, 1)
top.mark(boundaries, 2)
right.mark(boundaries, 3)
bottom.mark(boundaries, 4)

# Define Dirichlet boundary conditions at top and bottom boundaries
bc2 = DirichletBC(V, 0.0, boundaries, 2)
bc4 = DirichletBC(V, 0.0, boundaries, 4)

# TEST BC-----------------------------------------------------------------
# Pin down one corner to get rid of constant mode:
#bc = DirichletBC(V,Constant(0.0),
#                  "near(x[0],0) && near(x[1],0)","pointwise")

# Take a look at the solution:
#solve(lhs(res)==rhs(res),uh, bc)
#-------------------------------------------------------------------------

solve(lhs(res)==rhs(res),uh, [bc2, bc4])

from matplotlib import pyplot as plt
plot(uh)
plt.show()
plt.savefig("solution.png")

I believe the right BC is wrong. This is the warning
IndexError: index 2 is out of bounds for axis 0 with size 2

Is it because of the first line from x_0 to x_1?
Do you please know a similar example. I really don’t get it.

Greetings

x[0],x[1],x[2] represents the x,y and z coordinate. If you are using a 2D mesh, you only have x[0] and x[1]. These functions are called for many coordinates, giving rise to an array of Booleans

I understand. Thanks a lot for your great help.

Now I am getting
*** Warning: Found no facets matching domain for boundary condition.

In an another post where somebody was asking about this warning you wrote

This means that your on_boundary function always returns False.
I tested your if test, and it does not mark anything.
You could test this by creating a facetfunction that can be visualized in Paraview:

I should probably try that too.

1 Like