我成功地建立了一个非常简单的扩散问题,包括在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?你知道吗
记住
c.faceGrad
具有形状(2, 22009)
,因此掩码在第二个索引上操作,因为mesh.physicalFaces['sidewall']
的形状是(22009,)
。所以,试试看c.faceGrad[:, mesh.physicalFaces['sidewall']]
要获得正确的形状,请使用
np.array(c.faceGrad[:, mesh.physicalFaces['sidewall']]).shape
也就是
(2, 160)
。你知道吗相关问题 更多 >
编程相关推荐