本文整理匯總了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)
#.........這裏部分代碼省略.........