本文整理汇总了Python中dolfin.Function.vector()[lDG_dofs]方法的典型用法代码示例。如果您正苦于以下问题:Python Function.vector()[lDG_dofs]方法的具体用法?Python Function.vector()[lDG_dofs]怎么用?Python Function.vector()[lDG_dofs]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dolfin.Function
的用法示例。
在下文中一共展示了Function.vector()[lDG_dofs]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _evaluateLocalEstimator
# 需要导入模块: from dolfin import Function [as 别名]
# 或者: from dolfin.Function import vector()[lDG_dofs] [as 别名]
#.........这里部分代码省略.........
vertex_dof_map = V1.dofmap().vertex_to_dof_map(mesh)
# vertex_dof_map = vertex_to_dof_map(V1)
dof_list = vertex_dof_map.tolist()
# DG0 localisation
DG0 = FunctionSpace(mesh, 'DG', 0)
DG0_dofs = dict([(c.index(),DG0.dofmap().cell_dofs(c.index())[0]) for c in cells(mesh)])
dg0 = TestFunction(DG0)
# characteristic function of patch
xi_z = Function(DG0)
xi_coeffs = np.ndarray(DG0.dim())
# mesh data
h = CellSize(mesh)
n = FacetNormal(mesh)
cf = CellFunction('size_t', mesh)
# setup error estimator vector
eq_est = np.zeros(DG0.dim())
# setup global equilibrated flux vector
DG = VectorFunctionSpace(mesh, "DG", degree)
DG_dofmap = DG.dofmap()
# define form functions
tau = TrialFunction(DG)
v = TestFunction(DG)
# define global tau
tau_global = Function(DG)
tau_global.vector()[:] = 0.0
# iterate vertices
for vertex in vertices(mesh):
# get patch cell indices
vid = vertex.index()
patch_cid, FF_inner, FF_boundary = get_vertex_patch(vid, mesh, layers=1)
# set nodal base function
phi_coeffs[:] = 0
phi_coeffs[dof_list.index(vid)] = 1
phi_z.vector()[:] = phi_coeffs
# set characteristic function and mark patch
cf.set_all(0)
xi_coeffs[:] = 0
for cid in patch_cid:
xi_coeffs[DG0_dofs[int(cid)]] = 1
cf[int(cid)] = 1
xi_z.vector()[:] = xi_coeffs
# determine local dofs
lDG_cell_dofs = dict([(cid, DG_dofmap.cell_dofs(cid)) for cid in patch_cid])
lDG_dofs = [cd.tolist() for cd in lDG_cell_dofs.values()]
lDG_dofs = list(iter.chain(*lDG_dofs))
# print "\nlocal DG subspace has dimension", len(lDG_dofs), "degree", degree, "cells", len(patch_cid), patch_cid
# print "local DG_cell_dofs", lDG_cell_dofs
# print "local DG_dofs", lDG_dofs
# create patch measures
dx = Measure('dx')[cf]
dS = Measure('dS')[FF_inner]
# define forms
alpha = Constant(1 / epsilon) / h
a = inner(tau,v) * phi_z * dx(1) + alpha * div(tau) * div(v) * dx(1) + avg(alpha) * jump(tau,n) * jump(v,n) * dS(1)\
+ avg(alpha) * jump(xi_z * tau,n) * jump(v,n) * dS(2)
L = -alpha * (div(sigma_mu) + f) * div(v) * phi_z * dx(1)\
- avg(alpha) * jump(sigma_mu,n) * jump(v,n) * avg(phi_z)*dS(1)
# print "L2 f + div(sigma)", assemble((f + div(sigma)) * (f + div(sigma)) * dx(0))
# assemble forms
lhs = assemble(a, form_compiler_parameters={'quadrature_degree': quadrature_degree})
rhs = assemble(L, form_compiler_parameters={'quadrature_degree': quadrature_degree})
# convert DOLFIN representation to scipy sparse arrays
rows, cols, values = lhs.data()
lhsA = sps.csr_matrix((values, cols, rows)).tocoo()
# slice sparse matrix and solve linear problem
lhsA = coo_submatrix_pull(lhsA, lDG_dofs, lDG_dofs)
lx = spsolve(lhsA, rhs.array()[lDG_dofs])
# print ">>> local solution lx", type(lx), lx
local_tau = Function(DG)
local_tau.vector()[lDG_dofs] = lx
# print "div(tau)", assemble(inner(div(local_tau),div(local_tau))*dx(1))
# add up local fluxes
tau_global.vector()[lDG_dofs] += lx
# evaluate estimator
# maybe TODO: re-define measure dx
eq_est = assemble( inner(tau_global, tau_global) * dg0 * (dx(0)+dx(1)),\
form_compiler_parameters={'quadrature_degree': quadrature_degree})
# reorder according to cell ids
eq_est = eq_est[DG0_dofs.values()].array()
global_est = np.sqrt(np.sum(eq_est))
# eq_est_global = assemble( inner(tau_global, tau_global) * (dx(0)+dx(1)), form_compiler_parameters={'quadrature_degree': quadrature_degree} )
# global_est2 = np.sqrt(np.sum(eq_est_global))
return global_est, FlatVector(np.sqrt(eq_est))#, tau_global