How to solve variational problem by iteration methods

Hello everyone!
I’m a new one to use the iteration method to solve the electromagnetic variational problem, and I have no idea on how to get the needed parameters and their proper values, and preconditions by the function PETScKrylovSolver or KrylovSolver. Can anyone tell me where I can find these answers?

I would start by listing what you have available.
For instance, by using IPython I can list the available methods and preconditioners

In [1]: from dolfin import *                                                                                                                                                                                   

In [2]: list_krylov_solver_methods()                                                                                                                                                                           
Krylov method  |  Description                                 
bicgstab       |  Biconjugate gradient stabilized method      
cg             |  Conjugate gradient method                   
default        |  default Krylov method                       
gmres          |  Generalized minimal residual method         
minres         |  Minimal residual method                     
richardson     |  Richardson method                           
tfqmr          |  Transpose-free quasi-minimal residual method

In [3]: list_krylov_solver_preconditioners()                                                                                                                                                                   
Preconditioner   |  Description                               
amg              |  Algebraic multigrid                       
default          |  default preconditioner                    
hypre_amg        |  Hypre algebraic multigrid (BoomerAMG)     
hypre_euclid     |  Hypre parallel incomplete LU factorization
hypre_parasails  |  Hypre parallel sparse approximate inverse 
icc              |  Incomplete Cholesky factorization         
ilu              |  Incomplete LU factorization               
jacobi           |  Jacobi iteration                          
none             |  No preconditioner                         
petsc_amg        |  PETSc algebraic multigrid                 
sor              |  Successive over-relaxation     

You can read about these methods at:
KSP: Linear System Solvers — PETSc 3.14.1 documentation and their corresponding references.
For instance, checking out “CG” preconditioner: KSPCG — PETSc 3.18.2 documentation

1 Like

By the way, how could I check the parameters that can be set for each iteration method?

You need to look at the individual method’s documentation.
They can be set to the solver as shown in:
Bitbucket which shows how this is done for the fieldsplit pc: PCFIELDSPLIT — PETSc v3.18.2-329-ge16a4cb45b2 documentation

For instance, I want to choose the “ilu” as the preconditioner and the “cg” as the iteration method. I’ve learned the algorithm theoretically, but I still don’t have any idea on how to set these parameters when coding because I don’t know the parameter name, so where can I find the name?

What do you mean?
As you can see, you can get the “cg” iteration method by adding “cg” as an argument to the PETScKrylovSolver, i.e.

solver = PETScKrylovSolver("cg")

similarly, you can add the preconditioner "ilu" as the second argument

solver = PETScKrylovSolver("cg", "ilu")
1 Like

Actually, I’m trying to solve the equation in the from of “(B-rC)w=Bv” based on the ‘cg’ iteration method with the preconditioner ‘ilu’. In the equation, B is a 307724 * 307724 PETScMatrix, and the corresponding code is:

import dolfin as df

D = df.PETScMatrix(B.mat() - C.mat() * r[j])
solver = df.PETScKrylovSolver("cg", "ilu")
solver.parameters["absolute_tolerance"] = 1e-17
solver.parameters["maximum_iterations"] = 10000

After running the code, it reminded me an error shown in the figure.

So I’m thinking whether there is some parameters are set incorrectly or some other parameters like ‘Relaxation factor’ are missed to be set. So I wonder to know all Solver.parameters that should be set in such occasion.
Thanks ahead!