Applying a period mesh in a non-regular geometry

Hello,
Please find a part of my code where I apply periodic boundary condition.

coord = mesh.coordinates()
xmax = max(coord[:,0]); xmin = min(coord[:,0])
ymax = max(coord[:,1]); ymin = min(coord[:,1])

def inside_2D(x, on_boundary):
        return bool(on_boundary and (dolfin.near(x[0], xmin, self.tol) or dolfin.near(x[1], ymin, self.tol)) and not (dolfin.near(x[0], xmax, self.tol) or dolfin.near(x[1], ymax, self.tol)))

def map_2D(self, x, y):
        # Vertex
        if  (dolfin.near(x[0], xmax, self.tol) \
        and  dolfin.near(x[1], ymax, self.tol))\
        or  (dolfin.near(x[0], xmax, self.tol) \
        and  dolfin.near(x[1], ymin, self.tol))\
        or  (dolfin.near(x[0], xmin, self.tol) \
        and  dolfin.near(x[1], ymax, self.tol)):
            y[0] = xmin
            y[1] = ymin
        # Edges
        elif dolfin.near(x[0], xmax, self.tol):
            y[0] = self.xmin
            y[1] = x[1]
        elif dolfin.near(x[1], ymax, self.tol):
            y[0] = x[0]
            y[1] = ymin
        else:
            y[0] = -1.
            y[1] = -1.

But, the problem is that I can’t apply this to a geometry like the following (as the left and the right boundaries are not along the y-axis), unless I can find the left and right boundary vertices. Well, I already know the vertices as I have created the mesh, but how can I find them directly in Dolfin?


Thanks in advance!

In DOLFIN, you would need to use the parametric expression of your boundary to map from one boundary to the other. i.e. if the line can be described as y=Ax+b you would have to check

    def inside_2D(x, on_boundary):
        return bool(on_boundary and dolfin.near(x[1], A*x[0] + b))

and then create the maps based on the location of each boundary. (i.e. if on a single line do something, if on a curve map with something else).

If you want better support for such geometries, I would suggest using my library, dolfinx_mpc, where you can send in marked facets from GMSH as input to be a certain periodic surface, and give it a corresponding geometrical mapping function.

Thanks a lot! It seems a good solution. But if I don’t use dolfinx_mpc, is there any way to find the parameters if the line y=Ax+b from DOLFIN?

You have generated the mesh, so it should be easy to compute if you know the two corners.

Of course, but what if I’m given a geometry which I don’t know the corners? I want to make my code more general.
Thanks

Thrn you would need to use dolfinx and mesh information. Both DOLFIN and DOLFINx will require a mapping function map(x) that maps the coordinates of one boundary to the other. This function will be specific to each mesh (up to some constants, as described above)

1 Like