朱莉娅语言FEniCS周期边界条件

时间:2018-10-29 14:50:53

标签: julia conditional-statements boundary fenics

我想在FEniCS中为Julia语言应用周期性边界条件,但是我发现的所有示例都是C ++或Python。如何使用Julia创建周期性边界条件?似乎很困难,因为Julia没有上课。 这是一个最小的示例:

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)

1 个答案:

答案 0 :(得分:0)

我查看了组成FEniCS的朱莉亚代码,在fenics页面上的周期性边界条件的示例以及一些关于fenics的旧python代码,这启发了我编写此代码:

    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"))

该解决方案并不是最佳解决方案,因为它只能在python中完成整个工作,但我认为我将不得不忍受它。