本文整理汇总了Python中Problem.Problem.exact_solution方法的典型用法代码示例。如果您正苦于以下问题:Python Problem.exact_solution方法的具体用法?Python Problem.exact_solution怎么用?Python Problem.exact_solution使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Problem.Problem
的用法示例。
在下文中一共展示了Problem.exact_solution方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test
# 需要导入模块: from Problem import Problem [as 别名]
# 或者: from Problem.Problem import exact_solution [as 别名]
def test(i, solver, choice, problem):
xtol = 1E-12
N = 2**i
mesh = UnitSquareMesh(N, N, 'crossed')
n_cells = mesh.num_cells()
n_obtuse_cells = len(obtuse_cells(mesh))
if problem == "point":
A = array([1.0, 0.0])
point_distance = Problem(MyPoint(A))
elif problem == "line":
A = array([0., 0.])
B = array([1., 0.])
point_distance = Problem(Segment(A, B))
if solver == "Q1":
# set up the linear problem
V = FunctionSpace(mesh, "CG", 1)
u = Function(V)
u_exact = Function(V)
fixed_dofs = []
point_distance.init(u, fixed_dofs)
point_distance.exact_solution(u_exact)
solver1 = Geometric(V)
start = clock()
n_sweeps = solver1.solve(u, fixed_dofs, xtol=xtol)
stop = clock() - start
l1 = assemble(abs(u - u_exact)*dx)
l2 = assemble((u - u_exact)**2*dx)
# set up the quadratic problem
W = FunctionSpace(mesh, "CG", 2)
v = interpolate(u, W)
v_exact = Function(W)
fixed_dofs = []
point_distance.init(v, fixed_dofs)
point_distance.exact_solution(v_exact)
solver2 = Quadratic(W, choice)
start = clock()
n_sweeps = solver2.solve(v, fixed_dofs, xtol=xtol, order_vector=v.vector())
stop = clock() - start
if solver == "Q2":
# set up the linear problem
V = FunctionSpace(mesh, "CG", 1)
u = Function(V)
u_exact = Function(V)
fixed_dofs = []
point_distance.init(u, fixed_dofs)
point_distance.exact_solution(u_exact)
solver1 = Geometric(V)
n_sweeps = solver1.solve(u, fixed_dofs, xtol=xtol)
# set up the quadratic problem
W = FunctionSpace(mesh, "CG", 2)
v = interpolate(u, W)
xxx = Function(W)
xxx.vector()[:] = v.vector().array()
v_exact = Function(W)
Fixed_dofs = []
point_distance.init(v, Fixed_dofs)
point_distance.exact_solution(v_exact)
#print fixed_dofs
#for i in range(W.dim()):
# print i, xxx.vector()[i], v.vector()[i],
# if i in fixed_dofs:
# print "<--"
# else:
# print
solver2 = Quad(W, choice)
start = clock()
n_sweeps = solver2.solve(v, Fixed_dofs, xtol=xtol)
stop = clock() - start
if solver == "Q3":
# set up the quadratic problem
W = FunctionSpace(mesh, "CG", 2)
v = Function(W)
v_exact = Function(W)
fixed_dofs = []
point_distance.init(v, fixed_dofs)
point_distance.exact_solution(v_exact)
solver2 = QuadraticRatic(W, choice)
start = clock()
n_sweeps = solver2.solve(v, fixed_dofs, xtol=xtol)
stop = clock() - start
if solver == "Q4":
# set up the linear problem
V = FunctionSpace(mesh, "CG", 1)
#.........这里部分代码省略.........