juliaconditional-statementsboundaryfenics

Julia language FEniCS periodic boundary condition


I would like to apply a periodic boundary condition in FEniCS for Julia language but all examples I have found are in either C++ or Python. How to create a periodic boundary condition using Julia? It seems difficult because Julia does not have classes. here is a minimal example:

using FEniCS

using PyCall

length=2.2

height=0.41

channel = Rectangle(Point([0.0, 0.0]), Point([length, height]))

domain = channel

mesh = generate_mesh(domain, 64)

# insert function here for PeriodicBoundarycondition

Q = FunctionSpace(mesh, "P", 1,constrained_domain=#the function that i am looking for)

Solution

  • I looked at the julia code that makes up FEniCS, the example of periodic boundary condition on the fenics page, and some of my old python codes for fenics and it inspired me to write this:

        using FEniCS
    using PyCall
    @pyimport fenics
    py"""
    from dolfin import *
    from mshr import *
    length=2.2
    
    height=0.41
    channel = Rectangle(Point([0.0, 0.0]), Point([length, height]))
    
    domain = channel
    
    mesh = generate_mesh(domain, 64)
    subdomains = MeshFunction("size_t", mesh, 1)
    subdomains.set_all(0)
    class Wall(SubDomain):
        def inside(self,x,on_boundary):
            return (near(x[1],height) or near(x[1],height)) and on_boundary
    wall=Wall()
    class PeriodicBoundary(SubDomain):
    
        # Left boundary is "target domain" G
        def inside(self, x, on_boundary):
            return bool(x[0] < DOLFIN_EPS and x[0] > -DOLFIN_EPS and on_boundary)
    
        # Map right boundary (H) to left boundary (G)
        def map(self, x, y):
            y[0] = x[0] - length
            y[1] = x[1]
    pbc=PeriodicBoundary()
    """
    Q=FunctionSpace(fenics.VectorFunctionSpace(py"mesh", "P", 1,constrained_domain=py"pbc"))
    

    the solution is not optimal as it just does the entire thing in python but I think I will have to live with it.