我成功地在由GMSH生成的网格上建立了一个非常简单的扩散问题,包括源面(连续体)和汇聚面(侧壁,顶部)。
from fipy import *
mesh = Gmsh2D('''Point(1) = {0, 0, 0, 1.0};
Point(2) = {12, 0, 0, 0.1};
Point(3) = {12, 16, 0, 0.1};
Point(4) = {15, 16, 0, 0.1};
Point(5) = {15, 100, 0, 1.0};
Point(6) = {0, 100, 0, 1.0};
Line(1) = {1, 2};
Line(2) = {2, 3};
Line(3) = {3, 4};
Line(4) = {4, 5};
Line(5) = {5, 6};
Line(6) = {6, 1};
Line Loop(1) = {1, 2, 3, 4, 5, 6};
Plane Surface(1) = {1};
Physical Line("continuum") = {5};
Physical Line("sidewall") = {2};
Physical Line("top") = {3};
Physical Surface("domain") = {1};
''')
c = CellVariable(name='concentration', mesh=mesh, value=0.)
c.faceGrad.constrain([-0.05 * c.harmonicFaceValue], mesh.physicalFaces["sidewall"])
c.faceGrad.constrain([0.05 * c.harmonicFaceValue], mesh.physicalFaces["top"])
c.constrain(1., mesh.physicalFaces["continuum"])
dim = 1.
D = 1.
dt = 50 * dim**2 / (2 * D)
steps = 100
eq = TransientTerm() == DiffusionTerm(coeff=D)
viewer = Viewer(vars=(c, c.grad), datamin=0., datamax=1.)
for step in range(steps):
eq.solve(var=c, dt=dt)
viewer.plot()
TSVViewer(vars=(c, c.grad)).plot(filename="conc.tsv")
raw_input('Press any key...')
计算按预期工作,但是我想在GMSH中设置的物理面上访问渐变。我知道我可以使用c.faceGrad
获得人脸的渐变,并使用mesh.physicalFaces['sidewall']
获得代表物理人脸的遮罩。为了获得包含在物理面部中的面部的梯度,我希望使用像c.faceGrad[mesh.physicalFaces['sidewall']]
这样的索引。但是,这不会产生期望的结果。是否可以在physicalFaces
指定的位置访问FaceVariable?
答案 0 :(得分:1)
请记住,c.faceGrad
的形状为(2, 22009)
,因此当mesh.physicalFaces['sidewall']
的形状为(22009,)
时,掩码对第二个索引进行操作。所以,尝试
c.faceGrad[:, mesh.physicalFaces['sidewall']]
并使用正确的形状
np.array(c.faceGrad[:, mesh.physicalFaces['sidewall']]).shape
即(2, 160)
。