@@ -3,6 +3,7 @@ using Gridap
33using GridapDistributed
44using GridapPETSc
55using GridapPETSc. PETSC
6+ using PartitionedArrays
67
78using Gridap. Algebra
89using MPI
@@ -49,6 +50,14 @@ function petsc_options_airfoil()
4950 -pres_ksp_type cg -pres_pc_type gamg -pres_ksp_rtol 1.e-2 -pres_ksp_converged_reason -ksp_atol 0.0"
5051end
5152
53+
54+ # Wrap the VMS NumericalSetup to allow specialized methods that omit
55+ # garbage collection at every time step.
56+ struct VMSPETScNS{T} <: NumericalSetup
57+ ns:: PETScLinearSolverNS{T}
58+ end
59+
60+
5261"""
5362 create_PETSc_setup(M::AbstractMatrix,ksp_setup::Function)
5463
@@ -59,32 +68,45 @@ function create_PETSc_setup(M::AbstractMatrix,ksp_setup::Function)
5968 ss = symbolic_setup (solver, M)
6069 ns = numerical_setup (ss, M)
6170 # @check_error_code GridapPETSc.PETSC.KSPView(ns.ksp[],C_NULL)
62- return ns
71+ return VMSPETScNS (ns)
6372end
6473
65- function Algebra. numerical_setup! (ns:: PETScLinearSolverNS ,A:: AbstractMatrix )
74+ function Algebra. numerical_setup! (vmsns:: VMSPETScNS ,A:: AbstractMatrix )
75+ ns = vmsns. ns
6676 ns. A = A
6777 println (" convert" )
6878 @time ns. B = convert (PETScMatrix,A)
6979 @check_error_code PETSC. KSPSetOperators (ns. ksp[],ns. B. mat[],ns. B. mat[])
7080
7181 # @time @check_error_code PETSC.KSPSetUp(ns.ksp[])
72- ns
82+ return ns
7383end
7484
75- function Algebra. solve! (x:: PETScVector ,ns:: PETScLinearSolverNS ,b:: AbstractVector )
85+ function Algebra. solve! (x:: PartitionedArrays.PVector ,vmsns:: VMSPETScNS ,b:: PartitionedArrays.PVector )
86+ ns = vmsns. ns
87+ X = similar (b,(axes (ns. A)[2 ],))
88+ B = similar (b,(axes (ns. A)[2 ],))
89+ copy! (X,x)
90+ copy! (B,b)
91+ Y = convert (PETScVector,X)
92+ solve! (Y,vmsns,B)
93+ copy! (x,Y)
94+ x
95+ end
7696
97+ function Algebra. solve! (x:: PETScVector ,vmsns:: VMSPETScNS ,b:: AbstractVector )
7798 # if MPI.Initialized()
7899 # if petsc_gc && (x.comm != MPI.COMM_SELF)
79100 # # gridap_petsc_gc() # Do garbage collection of PETSc objects
80101 # end
81102 # end
82103
104+ ns = vmsns. ns
105+
83106 B = convert (PETScVector,b)
84107 solve! (x,ns,B)
85108 x
109+ return x
86110end
87111
88-
89-
90112end
0 commit comments