Exemplo n.º 1
0
def create_pcd_problem(F, bcs, J, J_pc, w, nu, boundary_markers, pcd_variant):
    W = w.function_space()

    # Artificial BC for PCD preconditioner
    if pcd_variant == "BRM1":
        bc_pcd = DirichletBC(W.sub(1), 0.0, boundary_markers, 1)
    elif pcd_variant == "BRM2":
        bc_pcd = DirichletBC(W.sub(1), 0.0, boundary_markers, 2)

    # Arguments and coefficients of the form
    u, p = TrialFunctions(W)
    v, q = TestFunctions(W)
    # FIXME: Which split is correct? Both work but one might use
    # restrict_as_ufc_function
    u_, p_ = split(w)
    #u_, p_ = w.split()

    # PCD operators
    mp = Constant(1.0/nu)*p*q*dx
    kp = Constant(1.0/nu)*dot(grad(p), u_)*q*dx
    ap = inner(grad(p), grad(q))*dx
    if pcd_variant == "BRM2":
        n = FacetNormal(W.mesh())
        ds = Measure("ds", subdomain_data=boundary_markers)
        kp -= Constant(1.0/nu)*dot(u_, n)*p*q*ds(1)
        #kp -= Constant(1.0/nu)*dot(u_, n)*p*q*ds(0)  # TODO: Is this beneficial?

    # Collect forms in PCD assembler
    pcd_assembler = PCDAssembler(J, F, bcs, J_pc, ap=ap, kp=kp, mp=mp, bcs_pcd=bc_pcd)

    # Create nonlinear problem
    problem = PCDNonlinearProblem(pcd_assembler)

    return problem
Exemplo n.º 2
0
	f = Constant((0.0,0.0,0.0))
	L = inner(f,v)*dx

# PCD operators
	mp = Constant(1.0/nu)*p*q*dx
	kp = Constant(1.0/nu)*dot(grad(p), u_)*q*dx
	ap = inner(grad(p), grad(q))*dx
	if args.pcd_variant == "BRM2":
    		n = FacetNormal(mesh)
    		ds = Measure("ds", subdomain_data=boundary_markers)
    		kp -= Constant(1.0/nu)*dot(u_, n)*p*q*ds(1)
    #kp -= Constant(1.0/nu)*dot(u_, n)*p*q*ds(0)  # TODO: Is this beneficial?
#SystemAssembler(F, L, [bc0, bc1])
# Collect forms to define nonlinear problem
	pcd_assembler = PCDAssembler(F, L, [bc0, bc1], ap=ap, kp=kp, mp=mp, bcs_pcd=bc_pcd)
	problem = PCDNonlinearProblem(pcd_assembler)
#problem = PCDLinearProblem(pcd_assembler)

# Set up linear solver (GMRES with right preconditioning using Schur fact)
	linear_solver = PCDKrylovSolver(comm=mesh.mpi_comm())
	linear_solver.parameters["relative_tolerance"] = 1e-10
	PETScOptions.set("ksp_monitor")
	PETScOptions.set("ksp_gmres_restart", 150)

# Set up subsolvers
	PETScOptions.set("fieldsplit_p_pc_python_type", "fenapack.PCDPC_" + args.pcd_variant)

	PETScOptions.set("fieldsplit_u_ksp_type", "richardson")
	PETScOptions.set("fieldsplit_u_ksp_max_it", 1)
	PETScOptions.set("fieldsplit_u_pc_type", "hypre")
	PETScOptions.set("fieldsplit_u_pc_hypre_type", "boomeramg")