Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CG and GMRES Incompatible with Systems of PDEs #5

Closed
ChrisRackauckas opened this issue Jun 9, 2016 · 7 comments
Closed

CG and GMRES Incompatible with Systems of PDEs #5

ChrisRackauckas opened this issue Jun 9, 2016 · 7 comments

Comments

@ChrisRackauckas
Copy link
Member

CG and GMRES linear solvers only work on vectors and not matrices due to using dot. An issue has been opened at JuliaLinearAlgebra/IterativeSolvers.jl#73. I may need to implement my own CG/GMRES. Also related is a way to handle different diffusion constants (functions) with CG/GMRES

@lopezm94
Copy link

lopezm94 commented Jul 30, 2016

Do you mean when b is a matrix? For me the program stops because of KrylovSubspace (not dot), which would require some change in the internals.

julia> x = rand(20,20); A = rand(20,20); b = rand(20,20);

julia> cg(A,b)
ERROR: DimensionMismatch("dimensions must match")
 in promote_shape at ./operators.jl:211

julia> cg!(x,A,b)
ERROR: MethodError: `init!` has no method matching init!(::IterativeSolvers.KrylovSubspace{Float64,Array{Float64,2}}, ::Array{Float64,2})
Closest candidates are:
  init!{T}(::IterativeSolvers.KrylovSubspace{T,OpT}, ::Array{T,1})

@ChrisRackauckas ChrisRackauckas changed the title CG and GMRES Incompatible with Newest Version CG and GMRES Incompatible with Systems of PDEs Jul 30, 2016
@ChrisRackauckas
Copy link
Member Author

Yes, that's the error which stops it from working. Either cg needs to be changed in IterativeSolvers, or an alternative version needs to be implemented just for this.

@lopezm94
Copy link

I don't really know what the future plan for KrylovSubspace should be for handling matrices.

@jiahao

@ChrisRackauckas
Copy link
Member Author

ChrisRackauckas commented Jul 30, 2016

Now that I think about, if I'm not mistaken, this can just be done with a comprehension over the iterative solvers. For example, when solving AX=B with X a matrix, the values of X[i,:] only depend on B[i,:] (think about the way it multiplies). So actually this is just shorthand for n independent Ax=b problems, where the A happens to be the same each time. So a comprehension or loop over the columns with cg calls solves it.

(Would there be any efficiency gains by handling it somewhat similarly inside the cg loop? I can't see a reason why there would be)

Should there be type annotation on the b and x in cg then to clarify that it's for vectors? And would this wrapper for matrices be welcomed in IterativeSolvers.jl itself, or should I make it and keep it here?

@lopezm94
Copy link

lopezm94 commented Jul 30, 2016

Does the stopping criteria change for matrices? Yeah what you are saying could be done easily in a patch, but at the moment the pull request are merging slowly (might take some time).

@ChrisRackauckas
Copy link
Member Author

ChrisRackauckas commented Jul 30, 2016

I think the stopping criteria can be done either way. Theoretically there is none so it's just what's practical. In practice, by doing a loop over cg it will go until the tolerance is satisfied for each, whereas if it was implemented in the loop it could check the convergence of the whole B-AX in some suitable norm. By the Triangle Inequality the second form would be a weaker condition, though one could always adjust the tolerances to account for it.

However, in the case of PDEs it may be more practical to allow the different columns to have the errors/tolerances applied separately because they may differ vastly in their values (one case where this may come up is a PDE where the components are kept in the columns of X, but some substances have much higher values, and thus would dominate the norm allowing for a lot of error in the other values. This could be terrible in cases where relative tolerance dominates).

@ChrisRackauckas
Copy link
Member Author

It works. However, I wasn't able to use views, so it has some extra allocations. Noted in #33

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants