Python 指定";的自定义Fipy边界条件;L";形状几何

Python 指定";的自定义Fipy边界条件;L";形状几何,python,mesh,fipy,Python,Mesh,Fipy,我想用“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;

我想用“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。我想把“内部”和“右侧”定义为通量等于0的Neumann边界。我应该如何设置约束?我用过:

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'”错误。我怎样才能解决这个问题?非常感谢。

中演示了Gmsh定义的单元格和面的使用。具体而言,您需要:

mesh.physicalFaces[“前”]

等等,应该在Gmsh脚本中将其定义为
物理线,而不是
物理表面

我发现在这种特定情况下可以直接定义边界条件:
X,Y=mesh.faceCenters#doctest:+Gmsh phi.constraint(1,其中=(X==2))phi.constraint(1,其中=(Y==2))phi.constraint(-1,其中=(X==0))phi.constraint(-1,其中=((X<1)和(Y==1))
@Cjdkwq:当然,您总是可以参数化定义边界。FiPy也允许您使用来自Gmsh的信息。