Exemple #1
0
def create_pcd_solver(comm, pcd_variant, ls, mumps_debug=False):
    prefix = "NS_"

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

    # Set up subsolvers
    PETScOptions.set(prefix + "fieldsplit_p_pc_python_type",
                     "fenapack.PCDRPC_" + pcd_variant)
    if ls == "iterative":
        PETScOptions.set(prefix + "fieldsplit_u_ksp_type", "richardson")
        PETScOptions.set(prefix + "fieldsplit_u_ksp_max_it", 1)
        PETScOptions.set(prefix + "fieldsplit_u_pc_type", "hypre")
        PETScOptions.set(prefix + "fieldsplit_u_pc_hypre_type", "boomeramg")
        # PETScOptions.set(prefix+"fieldsplit_u_pc_hypre_boomeramg_P_max", 4)
        # PETScOptions.set(prefix+"fieldsplit_u_pc_hypre_boomeramg_agg_nl", 1)
        # PETScOptions.set(prefix+"fieldsplit_u_pc_hypre_boomeramg_agg_num_paths", 2)
        # PETScOptions.set(prefix+"fieldsplit_u_pc_hypre_boomeramg_coarsen_type", "HMIS")
        # PETScOptions.set(prefix+"fieldsplit_u_pc_hypre_boomeramg_interp_type", "ext+i")
        # PETScOptions.set(prefix+"fieldsplit_u_pc_hypre_boomeramg_no_CF")

        PETScOptions.set(prefix + "fieldsplit_p_PCD_Rp_ksp_type", "richardson")
        PETScOptions.set(prefix + "fieldsplit_p_PCD_Rp_ksp_max_it", 1)
        PETScOptions.set(prefix + "fieldsplit_p_PCD_Rp_pc_type",
                         "hypre")  # "gamg"
        PETScOptions.set(prefix + "fieldsplit_p_PCD_Rp_pc_hypre_type",
                         "boomeramg")

        PETScOptions.set(prefix + "fieldsplit_p_PCD_Ap_ksp_type", "richardson")
        PETScOptions.set(prefix + "fieldsplit_p_PCD_Ap_ksp_max_it", 1)
        PETScOptions.set(prefix + "fieldsplit_p_PCD_Ap_pc_type",
                         "hypre")  # "gamg"
        PETScOptions.set(prefix + "fieldsplit_p_PCD_Ap_pc_hypre_type",
                         "boomeramg")

        PETScOptions.set(prefix + "fieldsplit_p_PCD_Mp_ksp_type", "chebyshev")
        PETScOptions.set(prefix + "fieldsplit_p_PCD_Mp_ksp_max_it", 5)
        PETScOptions.set(
            prefix + "fieldsplit_p_PCD_Mp_ksp_chebyshev_eigenvalues",
            "0.5, 2.0")
        PETScOptions.set(prefix + "fieldsplit_p_PCD_Mp_pc_type", "jacobi")
    elif ls == "direct":
        # Debugging MUMPS
        if mumps_debug:
            PETScOptions.set(prefix + "fieldsplit_u_mat_mumps_icntl_4", 2)
            PETScOptions.set(prefix + "fieldsplit_p_PCD_Ap_mat_mumps_icntl_4",
                             2)
            PETScOptions.set(prefix + "fieldsplit_p_PCD_Mp_mat_mumps_icntl_4",
                             2)
    else:
        assert False

    # Apply options
    linear_solver.set_from_options()

    return linear_solver
Exemple #2
0
def create_pcd_solver(comm, pcd_variant, ls, mumps_debug=False):
    prefix = ""

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

    # Set up subsolvers
    PETScOptions.set(prefix + "fieldsplit_p_pc_python_type",
                     "fenapack.PCDRPC_" + pcd_variant)
    if ls == "iterative":
        PETScOptions.set(prefix + "fieldsplit_u_ksp_type", "richardson")
        PETScOptions.set(prefix + "fieldsplit_u_ksp_max_it", 1)
        PETScOptions.set(prefix + "fieldsplit_u_pc_type", "hypre")
        PETScOptions.set(prefix + "fieldsplit_u_pc_hypre_type", "boomeramg")

        PETScOptions.set(prefix + "fieldsplit_p_PCD_Rp_ksp_type", "richardson")
        PETScOptions.set(prefix + "fieldsplit_p_PCD_Rp_ksp_max_it", 1)
        PETScOptions.set(prefix + "fieldsplit_p_PCD_Rp_pc_type", "hypre")
        PETScOptions.set(prefix + "fieldsplit_p_PCD_Rp_pc_hypre_type",
                         "boomeramg")

        PETScOptions.set(prefix + "fieldsplit_p_PCD_Ap_ksp_type", "richardson")
        PETScOptions.set(prefix + "fieldsplit_p_PCD_Ap_ksp_max_it", 1)
        PETScOptions.set(prefix + "fieldsplit_p_PCD_Ap_pc_type", "hypre")
        PETScOptions.set(prefix + "fieldsplit_p_PCD_Ap_pc_hypre_type",
                         "boomeramg")

        PETScOptions.set(prefix + "fieldsplit_p_PCD_Mp_ksp_type", "chebyshev")
        PETScOptions.set(prefix + "fieldsplit_p_PCD_Mp_ksp_max_it", 5)
        PETScOptions.set(
            prefix + "fieldsplit_p_PCD_Mp_ksp_chebyshev_eigenvalues",
            "0.5, 2.0")
        # CHANGE #0: The above estimate is valid only for P1 pressure.
        #            Increase upper bound for higher OPA!
        PETScOptions.set(prefix + "fieldsplit_p_PCD_Mp_pc_type", "jacobi")
    elif ls == "direct":
        # Debugging MUMPS
        if mumps_debug:
            PETScOptions.set(prefix + "fieldsplit_u_mat_mumps_icntl_4", 2)
            PETScOptions.set(prefix + "fieldsplit_p_PCD_Ap_mat_mumps_icntl_4",
                             2)
            PETScOptions.set(prefix + "fieldsplit_p_PCD_Mp_mat_mumps_icntl_4",
                             2)
    else:
        assert False

    # Apply options
    linear_solver.set_from_options()

    return linear_solver
Exemple #3
0
def create_solver(comm, pcd_variant, ls, mumps_debug=False):
    prefix = "s" + get_random_string() + "_"

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

    # Set up subsolvers
    PETScOptions.set(prefix + "fieldsplit_p_pc_python_type",
                     "fenapack.PCDPC_" + pcd_variant)
    if ls == "iterative":
        PETScOptions.set(prefix + "fieldsplit_u_ksp_type", "richardson")
        PETScOptions.set(prefix + "fieldsplit_u_ksp_max_it", 1)
        PETScOptions.set(prefix + "fieldsplit_u_pc_type", "hypre")
        PETScOptions.set(prefix + "fieldsplit_u_pc_hypre_type", "boomeramg")
        PETScOptions.set(prefix + "fieldsplit_p_PCD_Ap_ksp_type", "richardson")
        PETScOptions.set(prefix + "fieldsplit_p_PCD_Ap_ksp_max_it", 2)
        PETScOptions.set(prefix + "fieldsplit_p_PCD_Ap_pc_type", "hypre")
        PETScOptions.set(prefix + "fieldsplit_p_PCD_Ap_pc_hypre_type",
                         "boomeramg")
        PETScOptions.set(prefix + "fieldsplit_p_PCD_Mp_ksp_type", "chebyshev")
        PETScOptions.set(prefix + "fieldsplit_p_PCD_Mp_ksp_max_it", 5)
        PETScOptions.set(
            prefix + "fieldsplit_p_PCD_Mp_ksp_chebyshev_eigenvalues",
            "0.5, 2.0")
        PETScOptions.set(prefix + "fieldsplit_p_PCD_Mp_pc_type", "jacobi")
    elif ls == "direct":
        # Debugging MUMPS
        if mumps_debug:
            PETScOptions.set(prefix + "fieldsplit_u_mat_mumps_icntl_4", 2)
            PETScOptions.set(prefix + "fieldsplit_p_PCD_Ap_mat_mumps_icntl_4",
                             2)
            PETScOptions.set(prefix + "fieldsplit_p_PCD_Mp_mat_mumps_icntl_4",
                             2)
    else:
        assert False

    # Apply options
    linear_solver.set_from_options()

    # Set up nonlinear solver
    solver = PCDNewtonSolver(linear_solver)
    solver.parameters["relative_tolerance"] = 1e-5

    return solver
Exemple #4
0
def create_dummy_solver_and_problem():
    mesh = UnitSquareMesh(3, 3)
    class Gamma1(SubDomain):
        def inside(self, x, on_boundary):
            return on_boundary and near(x[0], 0.0)
    P2 = VectorElement("Lagrange", mesh.ufl_cell(), 2)
    P1 = FiniteElement("Lagrange", mesh.ufl_cell(), 1)
    W = FunctionSpace(mesh, P2*P1)
    ff = MeshFunction('size_t', W.mesh(), W.mesh().topology().dim()-1)
    ff.set_all(0)
    Gamma1().mark(ff, 1)
    w = Function(W)
    F, bcs, J, J_pc = create_forms(w, ff, 1.0, 1.0, "newton", "direct")
    problem = create_pcd_problem(F, bcs, J, J_pc, w, 1.0, ff, "BRM1")
    solver = PCDKrylovSolver(comm=mesh.mpi_comm())
    solver.set_options_prefix("s"+get_random_string()+"_")
    A = PETScMatrix(solver.mpi_comm())
    problem.J(A, w.vector())
    solver.set_operators(A, A)
    return solver, problem
Exemple #5
0
def create_dummy_solver_and_problem():
    mesh = UnitSquareMesh(3, 3)
    class Gamma1(SubDomain):
        def inside(self, x, on_boundary):
            return on_boundary and near(x[0], 0.0)
    P2 = VectorElement("Lagrange", mesh.ufl_cell(), 2)
    P1 = FiniteElement("Lagrange", mesh.ufl_cell(), 1)
    W = FunctionSpace(mesh, P2*P1)
    ff = MeshFunction('size_t', W.mesh(), W.mesh().topology().dim()-1)
    ff.set_all(0)
    Gamma1().mark(ff, 1)
    w = Function(W)
    F, bcs, J, J_pc = create_forms(w, ff, 1.0, 1.0, "newton", "direct")
    problem = create_pcd_problem(F, bcs, J, J_pc, w, 1.0, ff, "BRM1")
    solver = PCDKrylovSolver(comm=mesh.mpi_comm())
    solver.set_options_prefix("s"+get_random_string()+"_")
    A = PETScMatrix(solver.ksp().comm.tompi4py())
    problem.J(A, w.vector())
    solver.set_operators(A, A)
    return solver, problem
Exemple #6
0
def create_solver(comm, pcd_variant, ls, mumps_debug=False):
    prefix = "s" + get_random_string() + "_"

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

    # Set up subsolvers
    PETScOptions.set(prefix+"fieldsplit_p_pc_python_type", "fenapack.PCDPC_" + pcd_variant)
    if ls == "iterative":
        PETScOptions.set(prefix+"fieldsplit_u_ksp_type", "richardson")
        PETScOptions.set(prefix+"fieldsplit_u_ksp_max_it", 1)
        PETScOptions.set(prefix+"fieldsplit_u_pc_type", "hypre")
        PETScOptions.set(prefix+"fieldsplit_u_pc_hypre_type", "boomeramg")
        PETScOptions.set(prefix+"fieldsplit_p_PCD_Ap_ksp_type", "richardson")
        PETScOptions.set(prefix+"fieldsplit_p_PCD_Ap_ksp_max_it", 2)
        PETScOptions.set(prefix+"fieldsplit_p_PCD_Ap_pc_type", "hypre")
        PETScOptions.set(prefix+"fieldsplit_p_PCD_Ap_pc_hypre_type", "boomeramg")
        PETScOptions.set(prefix+"fieldsplit_p_PCD_Mp_ksp_type", "chebyshev")
        PETScOptions.set(prefix+"fieldsplit_p_PCD_Mp_ksp_max_it", 5)
        PETScOptions.set(prefix+"fieldsplit_p_PCD_Mp_ksp_chebyshev_eigenvalues", "0.5, 2.0")
        PETScOptions.set(prefix+"fieldsplit_p_PCD_Mp_pc_type", "jacobi")
    elif ls == "direct":
        # Debugging MUMPS
        if mumps_debug:
            PETScOptions.set(prefix+"fieldsplit_u_mat_mumps_icntl_4", 2)
            PETScOptions.set(prefix+"fieldsplit_p_PCD_Ap_mat_mumps_icntl_4", 2)
            PETScOptions.set(prefix+"fieldsplit_p_PCD_Mp_mat_mumps_icntl_4", 2)
    else:
        assert False

    # Apply options
    linear_solver.set_from_options()

    # Set up nonlinear solver
    solver = PCDNewtonSolver(linear_solver)
    solver.parameters["relative_tolerance"] = 1e-5

    return solver
Exemple #7
0
	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")
	PETScOptions.set("fieldsplit_p_PCD_Ap_ksp_type", "gmres")
	PETScOptions.set("fieldsplit_p_PCD_Ap_ksp_max_it", 2)
	PETScOptions.set("fieldsplit_p_PCD_Ap_pc_type", "hypre")
	PETScOptions.set("fieldsplit_p_PCD_Ap_pc_hypre_type", "boomeramg")
ap = inner(grad(p), grad(q))*dx
if args.pcd_variant == "BRM2":
    n = FacetNormal(mesh)
    ds = Measure("ds", subdomain_data=boundary_markers)
    # TODO: What about the reaction term? Does it appear here?
    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 to define nonlinear problem
pcd_assembler = PCDAssembler(J, F, [bc0, bc1],
                             J_pc, ap=ap, kp=kp, mp=mp, mu=mu, bcs_pcd=bc_pcd)
assert pcd_assembler.get_pcd_form("gp").phantom # pressure grad obtained from J
problem = PCDNonlinearProblem(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-6
#PETScOptions.set("ksp_monitor")
PETScOptions.set("ksp_gmres_restart", 150)

# Set up subsolvers
PETScOptions.set("fieldsplit_p_pc_python_type", "fenapack.PCDRPC_" + args.pcd_variant)
if args.ls == "iterative":
    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")
    PETScOptions.set("fieldsplit_p_PCD_Rp_ksp_type", "richardson")
    PETScOptions.set("fieldsplit_p_PCD_Rp_ksp_max_it", 1)
    PETScOptions.set("fieldsplit_p_PCD_Rp_pc_type", "hypre")
    PETScOptions.set("fieldsplit_p_PCD_Rp_pc_hypre_type", "boomeramg")