【问题标题】:Julia language FEniCS periodic boundary conditionJulia 语言 FEniCS 周期性边界条件
【发布时间】:2019-04-02 12:51:18
【问题描述】:

我想在 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)

【问题讨论】:

  • 你看FEniCS.jl了吗?
  • 是的,这是我添加并正在使用的包。它在测试文件夹中有一些教程,但没有一个使用周期性边界条件。这就是为什么我不知道如何使用它。他们的第一个例子也有一个错误:它说 [code]u_D = Expression("1+x[0]*x[0]+2*x[1]*x[1]", degree=2)[ \code] 应该是 [code]@pyimport fenics u_D = Expression(fenics.Expression("1+x[0]*x[0]+2*x[1]*x[1]", degree=2)) [\code]

标签: julia conditional-statements boundary fenics


【解决方案1】:

我查看了组成 FEniCS 的 julia 代码,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 中完成了所有的事情,但我想我将不得不忍受它。

【讨论】:

    猜你喜欢
    • 2023-03-10
    • 2016-06-24
    • 2016-10-30
    • 2015-10-29
    • 2020-06-14
    • 2020-02-12
    • 2016-11-19
    • 2016-09-06
    • 2020-03-19
    相关资源
    最近更新 更多