指定“L”形几何图形的自定义边界条件

2024-10-16 20:50:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用“L形”几何体解决热扩散问题,定义如下:

from fipy import CellVariable, Gmsh2D, TransientTerm, DiffusionTerm
from fipy import Matplotlib2DViewer, Viewer
from fipy.tools import numerix

cellSize_1 = 0.05
mesh = Gmsh2D('''
              cellSize = %(cellSize_1)g;
              Point(1) = {0, 0, 0, cellSize};
              Point(2) = {0, 5, 0, cellSize};
              Point(3) = {1, 5, 0, cellSize};
              Point(4) = {1, 1, 0, cellSize};
              Point(5) = {4, 1, 0, cellSize};
              Point(6) = {4, 0, 0, cellSize};
              Line(7) = {1, 2};
              Line(8) = {2, 3};
              Line(9) = {3, 4};
              Line(10) = {4, 5};
              Line(11) = {5, 6};
              Line(12) = {6, 1};
              Physical Surface("Top") = {8};
              Physical Surface("Inner") = {9, 10};
              Physical Surface("Right") = {11};
              Physical Surface("Inner") = {12, 7};
              Line Loop(13) = {7, 8, 9, 10, 11, 12};
              Plane Surface(14) = {13};
              ''' % locals()) # doctest: +GMSH

# Using this mesh, we can construct a solution variable

phi = CellVariable(name = "solution variable",
                   mesh = mesh,
                   value = 0.) # doctest: +GMSH

# We can now create a Viewer to see the mesh

viewer = None
from builtins import input
if __name__ == '__main__':
    try:
        viewer = Viewer(vars=phi, datamin=-1, datamax=3)
        viewer.plotMesh()

    except:
        print("Unable to create a viewer for an irregular mesh (try "+
              "Matplotlib2DViewer or MayaviViewer)")

现在我想把“顶部”和“右侧”边界定义为Dirichlet边界,常数为1和0。把“内部”和“右侧”定义为Neumann边界,通量为0。我该如何设置约束?我用过:

phi.constrain(1, where = mesh.Front)
phi.constrain(0, where = mesh.Top)
phi.faceGrad.constrain(0 * mesh.faceNormals, where = mesh.Inner)
phi.faceGrad.constrain(0 * mesh.faceNormals, where = mesh.Outter)

但我得到的只是“AttributeError:'Gmsh2D'对象没有属性'Front'”错误。我怎样才能解决这个问题?非常感谢


Tags: fromimport定义linewheresurfaceviewerpoint