GMRes: number of iterations

More
5 years 3 weeks ago #2014 by gcdiwan
Dear NGSolve Developers,
Is there a way to output the number of iterations from GMRes to a variable?
Code:
solvers.GMRes(A=a.mat, pre=c, b=f.vec, tol=1e-6, printrates=True, x=u.vec)

While the above prints the output on the screen, I only want to copy the number of iterations needed. Something similar to matlab, perhaps..?
Code:
[x,flag,relres,iter,resvec] = gmres(A,b,...)

Thanks.
More
5 years 3 weeks ago #2015 by christopher
I'd like to change that sometime but right now you can only copy the function from the source file and implement it differently. Since the function is self contained it should be easy. It is located in your installation dir/lib/python/site-packages/ngsolve/krylovspace.py (or similar)

Best
Christopher
More
4 years 11 months ago #2182 by gcdiwan
Replied by gcdiwan on topic GMRes: number of iterations
Hi Christopher,

Thanks for your quick reply. Sorry I could not respond earlier but i implemented what you suggested and i guess it kinda works. However I am not sure if i understand what's happening.

Below are some numerical results from a simple FEM model for plane wave passing through a unit cube volume. So, I am trying to solve \Delta u + k^2 u = 0 in \Omega with
\frac{\partial u}{\partial n} + iku = g on \partial \Omega
with uexact = exp(ikx) and with k = 10, \Omega = [0,1]^3

I don't understand why for linear FEM, GMRES converges in 1 iteration whereas with quadratics it shows some sensible number of iterations. I have set the printrates=True and it does not print anything for linear elements (which is why iterations = 1 in all the cases for linear elements).

degree, nDoF, L2 err (l2 proj), l2 err - lDirect solve, l2 err-GMRES with multigrid prec, GMRES iter
1 66 0.228624493 0.255948445 0.255948445 1
1 351 0.03100829 0.172026925 0.172026925 1
1 1413 0.003531052 0.07137935 0.07137935 1
1 2310 0.001682436 0.056464976 0.056464976 1
1 5854 0.000783738 0.032836804 0.032836804 1
1 7913 0.000997578 0.030096036 0.030096036 1
2 353 0.053100103 0.194324956 0.194324956 18
2 2147 0.009796087 0.013547158 0.013547157 11
2 9667 0.000953166 0.00238158 0.00238158 9
2 16029 0.00089093 0.001506855 0.001506854 8
2 42637 0.000263694 0.000468488 0.000468488 7
2 57243 0.000237646 0.000370277 0.000370277 7


Any clue what i could be doing wrong?
Thanks
More
4 years 11 months ago #2183 by christopher
Can you attach your code?
More
4 years 11 months ago #2184 by lkogler
Replied by lkogler on topic GMRes: number of iterations
"degree, nDoF, L2 err (l2 proj), l2 err - lDirect solve, l2 err-GMRES with multigrid prec, GMRES iter"

It looks like you are using the multigrid preconditioner.

That means "real" geometric multigrid for the lowest order space only, plus a block-smoother to take care of the high order space. The low order system on the coarsest mesh is solved exactly.

So, with order=1 and without mesh refinement, the multigrid preconditioner is just the direct inverse and GMRes converges in one iteration.
More
4 years 11 months ago #2188 by gcdiwan
Replied by gcdiwan on topic GMRes: number of iterations

lkogler wrote: "degree, nDoF, L2 err (l2 proj), l2 err - lDirect solve, l2 err-GMRES with multigrid prec, GMRES iter"

It looks like you are using the multigrid preconditioner.

That means "real" geometric multigrid for the lowest order space only, plus a block-smoother to take care of the high order space. The low order system on the coarsest mesh is solved exactly.

So, with order=1 and without mesh refinement, the multigrid preconditioner is just the direct inverse and GMRes converges in one iteration.


Ok, that makes sense. Thank you.
Time to create page: 0.106 seconds