指定 "L" 形几何体的自定义 Fipy 边界条件
Specifying a custom Fipy boundary condition of an "L" shaped geometry
我想用以下代码定义的 "L-shape" 几何体求解热扩散问题:
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)")
现在我想将 "Top" 和 "Right" 边界定义为 Dirichlet 边界,常数值为 1 和 0。我想定义 "Inner" 和 "Right"作为通量等于 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' object has no attribute 'Front'" 错误。我怎样才能解决这个问题?非常感谢。
the docstring for Gmsh2D
中演示了 Gmsh 定义的单元格和面孔的使用。具体来说,您需要:
mesh.physicalFaces["Front"]
等,应该在您的 Gmsh 脚本中定义为 Physical Line
,而不是 Physical Surface
.
我想用以下代码定义的 "L-shape" 几何体求解热扩散问题:
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)")
现在我想将 "Top" 和 "Right" 边界定义为 Dirichlet 边界,常数值为 1 和 0。我想定义 "Inner" 和 "Right"作为通量等于 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' object has no attribute 'Front'" 错误。我怎样才能解决这个问题?非常感谢。
the docstring for Gmsh2D
中演示了 Gmsh 定义的单元格和面孔的使用。具体来说,您需要:
mesh.physicalFaces["Front"]
等,应该在您的 Gmsh 脚本中定义为 Physical Line
,而不是 Physical Surface
.