Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 4
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
Ejemplo n.º 5
0
	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")
	PETScOptions.set("fieldsplit_p_PCD_Mp_ksp_type", "gmres")
	PETScOptions.set("fieldsplit_p_PCD_Mp_ksp_max_it", 5)
	#PETScOptions.set("fieldsplit_p_PCD_Mp_ksp_chebyshev_eigenvalues", "0.5, 2.0")
#PETScOptions.set("fieldsplit_p_PCD_Mp_ksp_chebyshev_esteig", "1,0,0,1")  # FIXME: What does it do?
	PETScOptions.set("fieldsplit_p_PCD_Mp_pc_type", "hypre")
	PETScOptions.set("fieldsplit_p_PCD_Mp_pc_hypre_type", "boomeramg")

# Apply options
	linear_solver.set_from_options()

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

# Solve problem
	solver.solve(problem, w.vector())
	
	assign(u_c,w.sub(0))
	diff = (u_c.vector().get_local() - u_.vector().get_local())
	picard_error = np.linalg.norm(diff, ord = np.Inf)
	assign(u_,w.sub(0))
	print ('error', picard_error, ' iter = ', picard_iter)
# Report timings
#list_timings(TimingClear.clear, [TimingType.wall, TimingType.user])
    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")
    PETScOptions.set("fieldsplit_p_PCD_Mp_ksp_type", "chebyshev")
    PETScOptions.set("fieldsplit_p_PCD_Mp_ksp_max_it", 5)
    PETScOptions.set("fieldsplit_p_PCD_Mp_ksp_chebyshev_eigenvalues", "0.5, 2.0")
    #PETScOptions.set("fieldsplit_p_PCD_Mp_ksp_chebyshev_esteig", "1,0,0,1")  # FIXME: What does it do?
    PETScOptions.set("fieldsplit_p_PCD_Mp_pc_type", "jacobi")
elif args.ls == "direct" and args.mumps_debug:
    # Debugging MUMPS
    PETScOptions.set("fieldsplit_u_mat_mumps_icntl_4", 2)
    PETScOptions.set("fieldsplit_p_PCD_Ap_mat_mumps_icntl_4", 2)
    PETScOptions.set("fieldsplit_p_PCD_Mp_mat_mumps_icntl_4", 2)

# Apply options
linear_solver.set_from_options()

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

# Solve problem
t = 0.0
time_iters = 0
krylov_iters = 0
solution_time = 0.0
while t < args.t_end and not near(t, args.t_end, 0.1*args.dt):
    # Move to current time level
    t += args.dt
    time_iters += 1