Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions src/Commons/SolverOptions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ using Gridap
using GridapDistributed
using GridapPETSc
using GridapPETSc.PETSC
using PartitionedArrays

using Gridap.Algebra
using MPI
Expand Down Expand Up @@ -49,6 +50,12 @@ function petsc_options_airfoil()
-pres_ksp_type cg -pres_pc_type gamg -pres_ksp_rtol 1.e-2 -pres_ksp_converged_reason -ksp_atol 0.0"
end

# Wrap the VMS NumericalSetup to allow specialized methods that omit
# garbage collection at every time step.
struct VMSPETScNS{T} <: NumericalSetup
ns::PETScLinearSolverNS{T}
end

"""
create_PETSc_setup(M::AbstractMatrix,ksp_setup::Function)

Expand All @@ -59,32 +66,45 @@ function create_PETSc_setup(M::AbstractMatrix,ksp_setup::Function)
ss = symbolic_setup(solver, M)
ns = numerical_setup(ss, M)
# @check_error_code GridapPETSc.PETSC.KSPView(ns.ksp[],C_NULL)
return ns
return VMSPETScNS(ns)
end

function Algebra.numerical_setup!(ns::PETScLinearSolverNS,A::AbstractMatrix)
function Algebra.numerical_setup!(vmsns::VMSPETScNS, A::AbstractMatrix)
ns = vmsns.ns
ns.A = A
println("convert")
@time ns.B = convert(PETScMatrix,A)
@check_error_code PETSC.KSPSetOperators(ns.ksp[],ns.B.mat[],ns.B.mat[])

# @time @check_error_code PETSC.KSPSetUp(ns.ksp[])
ns
return ns
end

function Algebra.solve!(x::PETScVector,ns::PETScLinearSolverNS,b::AbstractVector)
# Copy of the Gridap function, needed to pass the custom VMSPETScNS
function Algebra.solve!(x::PartitionedArrays.PVector,vmsns::VMSPETScNS,b::PartitionedArrays.PVector)
ns = vmsns.ns
X = similar(b,(axes(ns.A)[2],))
B = similar(b,(axes(ns.A)[2],))
copy!(X,x)
copy!(B,b)
Y = convert(PETScVector,X)
solve!(Y,vmsns,B)
copy!(x,Y)
x
end

function Algebra.solve!(x::PETScVector,vmsns::VMSPETScNS,b::AbstractVector)
# if MPI.Initialized()
# if petsc_gc && (x.comm != MPI.COMM_SELF)
# # gridap_petsc_gc() # Do garbage collection of PETSc objects
# end
# end

ns = vmsns.ns

B = convert(PETScVector,b)
solve!(x,ns,B)
x
return x
end



end
2 changes: 0 additions & 2 deletions src/SegregatedVMSSolver.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
module SegregatedVMSSolver

__precompile__(false)

include(joinpath("Commons","SolverOptions.jl"))
include(joinpath("Commons","Interfaces.jl"))

Expand Down