Skip to content

Commit

Permalink
Add nonlinear numerical setup update
Browse files Browse the repository at this point in the history
  • Loading branch information
JordiManyer committed Dec 28, 2023
1 parent e9e7c9a commit 0fcc986
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 9 deletions.
12 changes: 10 additions & 2 deletions src/BlockSolvers/BlockTriangularSolvers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ function Gridap.Algebra.numerical_setup!(ns::BlockTriangularSolverNS,mat::Abstra
solver = ns.solver
mat_blocks = blocks(mat)
block_caches = map(update_block_cache!,ns.block_caches,solver.blocks,mat_blocks)
map(numerical_setup!,ns.block_ns,diag(block_caches))
map(diag(solver.blocks),ns.block_ns,diag(block_caches)) do bi, nsi, ci
if is_nonlinear(bi)
numerical_setup!(nsi,ci)
end
end
return ns
end

Expand All @@ -102,7 +106,11 @@ function Gridap.Algebra.numerical_setup!(ns::BlockTriangularSolverNS,mat::Abstra
block_caches = map(CartesianIndices(solver.blocks)) do I
update_block_cache!(ns.block_caches[I],mat_blocks[I],vec_blocks[I[2]])
end
map(numerical_setup!,ns.block_ns,diag(block_caches),vec_blocks)
map(diag(solver.blocks),ns.block_ns,diag(block_caches),vec_blocks) do bi, nsi, ci, xi
if is_nonlinear(bi)
numerical_setup!(nsi,ci,xi)
end
end
return ns
end

Expand Down
7 changes: 7 additions & 0 deletions src/LinearSolvers/Krylov/CGSolvers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ end
function Gridap.Algebra.numerical_setup!(ns::CGNumericalSetup, A::AbstractMatrix)
numerical_setup!(ns.Pl_ns,A)
ns.A = A
return ns
end

function Gridap.Algebra.numerical_setup!(ns::CGNumericalSetup, A::AbstractMatrix, x::AbstractVector)
numerical_setup!(ns.Pl_ns,A,x)
ns.A = A
return ns
end

function Gridap.Algebra.solve!(x::AbstractVector,ns::CGNumericalSetup,b::AbstractVector)
Expand Down
10 changes: 10 additions & 0 deletions src/LinearSolvers/Krylov/FGMRESSolvers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ function Gridap.Algebra.numerical_setup!(ns::FGMRESNumericalSetup, A::AbstractMa
numerical_setup!(ns.Pl_ns,A)
end
ns.A = A
return ns
end

function Gridap.Algebra.numerical_setup!(ns::FGMRESNumericalSetup, A::AbstractMatrix, x::AbstractVector)
numerical_setup!(ns.Pr_ns,A,x)
if !isa(ns.Pl_ns,Nothing)
numerical_setup!(ns.Pl_ns,A,x)
end
ns.A = A
return ns
end

function Gridap.Algebra.solve!(x::AbstractVector,ns::FGMRESNumericalSetup,b::AbstractVector)
Expand Down
12 changes: 12 additions & 0 deletions src/LinearSolvers/Krylov/GMRESSolvers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ function Gridap.Algebra.numerical_setup!(ns::GMRESNumericalSetup, A::AbstractMat
numerical_setup!(ns.Pl_ns,A)
end
ns.A = A
return ns
end

function Gridap.Algebra.numerical_setup!(ns::GMRESNumericalSetup, A::AbstractMatrix, x::AbstractVector)
if !isa(ns.Pr_ns,Nothing)
numerical_setup!(ns.Pr_ns,A,x)
end
if !isa(ns.Pl_ns,Nothing)
numerical_setup!(ns.Pl_ns,A,x)
end
ns.A = A
return ns
end

function Gridap.Algebra.solve!(x::AbstractVector,ns::GMRESNumericalSetup,b::AbstractVector)
Expand Down
11 changes: 11 additions & 0 deletions src/LinearSolvers/Krylov/MINRESSolvers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ function Gridap.Algebra.numerical_setup!(ns::MINRESNumericalSetup, A::AbstractMa
ns.A = A
end

function Gridap.Algebra.numerical_setup!(ns::MINRESNumericalSetup, A::AbstractMatrix, x::AbstractVector)
if !isa(ns.Pr_ns,Nothing)
numerical_setup!(ns.Pr_ns,A,x)
end
if !isa(ns.Pl_ns,Nothing)
numerical_setup!(ns.Pl_ns,A,x)
end
ns.A = A
return ns
end

function Gridap.Algebra.solve!(x::AbstractVector,ns::MINRESNumericalSetup,b::AbstractVector)
solver, A, Pl, Pr, caches = ns.solver, ns.A, ns.Pl_ns, ns.Pr_ns, ns.caches
V, W, zr, zl, H, g, c, s = caches
Expand Down
2 changes: 1 addition & 1 deletion src/NonlinearSolvers/NewtonRaphsonSolver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function _solve_nr!(x,A,b,dx,ns,nls,op)
if !done
# Update jacobian and solver
jacobian!(A, op, x)
numerical_setup!(ns,A)
numerical_setup!(ns,A,x)
end

end
Expand Down
1 change: 1 addition & 0 deletions src/NonlinearSolvers/NonlinearSolvers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module NonlinearSolvers
using PartitionedArrays
using GridapDistributed

using GridapSolvers.SolverInterfaces
using GridapSolvers.MultilevelTools
using GridapSolvers.SolverInterfaces

Expand Down
7 changes: 1 addition & 6 deletions src/SolverInterfaces/GridapExtras.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@

# LinearSolvers that depend on the non-linear solution
"""

function Gridap.Algebra.numerical_setup!(ns::Gridap.Algebra.LinearSolver,A::AbstractMatrix,x::AbstractVector)
numerical_setup!(ns,A)
end
function allocate_solver_caches(ns::Gridap.Algebra.LinearSolver,args...;kwargs...)
@abstractmethod
end
"""

0 comments on commit 0fcc986

Please sign in to comment.