本文整理汇总了Python中dolfin.Mesh.coordinates()[:,d]方法的典型用法代码示例。如果您正苦于以下问题:Python Mesh.coordinates()[:,d]方法的具体用法?Python Mesh.coordinates()[:,d]怎么用?Python Mesh.coordinates()[:,d]使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dolfin.Mesh
的用法示例。
在下文中一共展示了Mesh.coordinates()[:,d]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: symmetrize
# 需要导入模块: from dolfin import Mesh [as 别名]
# 或者: from dolfin.Mesh import coordinates()[:,d] [as 别名]
def symmetrize(u, d, sym):
""" Symmetrize function u. """
if len(d) == 3:
# three dimensions -> cycle XYZ
return cyclic3D(u)
elif len(d) >= 4:
# four dimensions -> rotations in 2D
return rotational(u, d[-1])
nrm = np.linalg.norm(u.vector())
V = u.function_space()
mesh = Mesh(V.mesh())
# test if domain is symmetric using function equal 0 inside, 1 on boundary
# extrapolation will force large values if not symmetric since the flipped
# domain is different
bc = DirichletBC(V, 1, DomainBoundary())
test = Function(V)
bc.apply(test.vector())
if len(d) == 2:
# two dimensions given: swap dimensions
mesh.coordinates()[:, d] = mesh.coordinates()[:, d[::-1]]
else:
# one dimension given: reflect
mesh.coordinates()[:, d[0]] *= -1
# FIXME functionspace takes a long time to construct, maybe copy?
W = FunctionSpace(mesh, 'CG', 1)
try:
# testing
test = interpolate(Function(W, test.vector()), V)
# max-min should be around 1 if domain was symmetric
# may be slightly above due to boundary approximation
assert max(test.vector()) - min(test.vector()) < 1.1
v = interpolate(Function(W, u.vector()), V)
if sym:
# symmetric
pr = project(u+v)
else:
# antisymmetric
pr = project(u-v)
# small solution norm most likely means that symmetrization gives
# trivial function
assert np.linalg.norm(pr.vector())/nrm > 0.01
return pr
except:
# symmetrization failed for some reason
print "Symmetrization " + str(d) + " failed!"
return u