Exemple #1
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 #2
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 #3
0
	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])

# Plot solution
u, p = w.split()
Exemple #4
0
    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
solver.solve(problem, w.vector())

# Report timings
list_timings(TimingClear_clear, [TimingType_wall, TimingType_user])

# Plot solution
u, p = w.split()
size = MPI.size(mesh.mpi_comm())
rank = MPI.rank(mesh.mpi_comm())
pyplot.figure()
pyplot.subplot(2, 1, 1)
plot(u, title="velocity")
    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

    # Update boundary conditions
    inflow.t = t
Exemple #6
0
    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

    # Update boundary conditions
    inflow.t = t
    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
solver.solve(problem, w.vector())

# Report timings
list_timings(TimingClear.clear, [TimingType.wall, TimingType.user])

# Plot solution
u, p = w.split()
size = MPI.size(mesh.mpi_comm())
rank = MPI.rank(mesh.mpi_comm())
pyplot.figure()
pyplot.subplot(2, 1, 1)
plot(u, title="velocity")