1
1
2
+ function default_nullspace (A)
3
+ T = eltype (A)
4
+ [ones (T,size (A,2 ))]
5
+ end
6
+
7
+ function default_nullspace (A:: PSparseMatrix )
8
+ col_partition = partition (axes (A,2 ))
9
+ T = eltype (A)
10
+ [ pones (T,col_partition) ]
11
+ end
12
+
2
13
function aggregate (A,diagA= dense_diag (A);epsilon)
3
14
# TODO It assumes CSC format for the moment
4
15
@@ -744,7 +755,7 @@ function dofs_to_node(dofs, block_size)
744
755
end
745
756
746
757
function amg_level_params_linear_elasticity (block_size;
747
- pre_smoother = additive_schwarz (gauss_seidel (;iters = 1 );iters = 1 ),
758
+ pre_smoother = p -> additive_schwarz (p;local_solver = q -> gauss_seidel (q;iterations = 1 ),iterations = 1 ),
748
759
coarsening = smoothed_aggregation_with_block_size (;approximate_omega = lambda_generic,
749
760
tentative_prolongator = tentative_prolongator_with_block_size, block_size = block_size),
750
761
cycle = v_cycle,
@@ -756,7 +767,7 @@ function amg_level_params_linear_elasticity(block_size;
756
767
end
757
768
758
769
function amg_level_params (;
759
- pre_smoother = additive_schwarz (gauss_seidel (;iters = 1 );iters = 1 ),
770
+ pre_smoother = p -> additive_schwarz (p;local_solver = q -> gauss_seidel (q;iterations = 1 ),iterations = 1 ),
760
771
coarsening = smoothed_aggregation (;),
761
772
cycle = v_cycle,
762
773
pos_smoother = pre_smoother,
@@ -774,23 +785,24 @@ end
774
785
775
786
function amg_coarse_params (;
776
787
# TODO more resonable defaults?
777
- coarse_solver = lu_solver () ,
788
+ coarse_solver = LinearAlgebra_lu ,
778
789
coarse_size = 10 ,
779
790
)
780
791
coarse_params = (;coarse_solver,coarse_size)
781
792
coarse_params
782
793
end
783
794
784
- function amg (;
795
+ function amg (p ;
785
796
fine_params= amg_fine_params (),
786
797
coarse_params= amg_coarse_params (),)
787
798
amg_params = (;fine_params,coarse_params)
788
- setup (x,O,b,options) = amg_setup (x,O,b,nullspace (options),amg_params)
789
- update! = amg_update!
790
- solve! = amg_solve!
791
- finalize! = amg_finalize!
792
- uses_nullspace = Val (true )
793
- linear_solver (;setup,update!,solve!,finalize!,uses_nullspace)
799
+
800
+ x = solution (p)
801
+ b = rhs (p)
802
+ A = matrix (p)
803
+ B = nullspace (p)
804
+ setup = amg_setup (x,A,b,B,amg_params)
805
+ linear_solver (amg_update!,amg_step!,p,setup)
794
806
end
795
807
796
808
function amg_setup (x,A,b,:: Nothing ,amg_params)
@@ -807,8 +819,8 @@ function amg_setup(x,A,b,B,amg_params)
807
819
return nothing
808
820
end
809
821
(;pre_smoother,pos_smoother,coarsening,cycle) = fine_level
810
- pre_setup = setup ( pre_smoother, x,A,b)
811
- pos_setup = setup ( pos_smoother, x,A,b)
822
+ pre_setup = pre_smoother ( linear_problem ( x,A,b) )
823
+ pos_setup = pos_smoother ( linear_problem ( x,A,b) )
812
824
coarsen, _ = coarsening
813
825
Ac,Bc,R,P,Ac_setup = coarsen (A,B)
814
826
nc = size (Ac,1 )
@@ -830,28 +842,29 @@ function amg_setup(x,A,b,B,amg_params)
830
842
end
831
843
n_fine_levels = count (i-> i!= = nothing ,fine_levels)
832
844
nlevels = n_fine_levels+ 1
833
- coarse_solver_setup = setup ( coarse_solver, x,A,b)
845
+ coarse_solver_setup = coarse_solver ( linear_problem ( x,A,b) )
834
846
coarse_level = (;coarse_solver_setup)
835
847
(;nlevels,fine_levels,coarse_level,amg_params)
836
848
end
837
849
838
- function amg_solve ! (x,setup,b,options )
850
+ function amg_step ! (x,setup,b,phase = :start ;kwargs ... )
839
851
level= 1
840
852
amg_cycle! (x,setup,b,level)
841
- x
853
+ phase= :stop
854
+ x,setup,phase
842
855
end
843
856
844
857
function amg_cycle! (x,setup,b,level)
845
858
amg_params = setup. amg_params
846
859
if level == setup. nlevels
847
860
coarse_solver_setup = setup. coarse_level. coarse_solver_setup
848
- return solve ! (x,coarse_solver_setup,b)
861
+ return smooth ! (x,coarse_solver_setup,b)
849
862
end
850
863
level_params = amg_params. fine_params[level]
851
864
level_setup = setup. fine_levels[level]
852
865
(;cycle) = level_params
853
866
(;R,P,r,rc,rc2,e,ec,ec2,A,Ac,pre_setup,pos_setup) = level_setup
854
- solve ! (x,pre_setup,b)
867
+ smooth ! (x,pre_setup,b)
855
868
mul! (r,A,x)
856
869
r .= b .- r
857
870
mul! (rc2,R,r)
@@ -861,16 +874,16 @@ function amg_cycle!(x,setup,b,level)
861
874
ec2 .= ec
862
875
mul! (e,P,ec2)
863
876
x .+ = e
864
- solve ! (x,pos_setup,b)
877
+ smooth ! (x,pos_setup,b)
865
878
x
866
879
end
867
880
868
- function amg_statistics (P:: Preconditioner )
881
+ function amg_statistics (P)
869
882
# Taken from: An Introduction to Algebraic Multigrid, R. D. Falgout, April 25, 2006
870
883
# Grid complexity is the total number of grid points on all grids divided by the number
871
884
# of grid points on the fine grid. Operator complexity is the total number of nonzeroes in the linear operators
872
885
# on all grids divided by the number of nonzeroes in the fine grid operator
873
- setup = P. solver_setup
886
+ setup = P. workspace
874
887
nlevels = setup. nlevels
875
888
level_rows = zeros (Int,nlevels)
876
889
level_nnz = zeros (Int,nlevels)
909
922
amg_cycle! (args... )
910
923
end
911
924
912
- function amg_update! (setup,A,options )
925
+ function amg_update! (setup,A)
913
926
amg_params = setup. amg_params
914
927
nlevels = setup. nlevels
915
928
for level in 1 : (nlevels- 1 )
@@ -918,13 +931,13 @@ function amg_update!(setup,A,options)
918
931
(;coarsening) = level_params
919
932
_, coarsen! = coarsening
920
933
(;R,P,A,Ac,Ac_setup,pre_setup,pos_setup) = level_setup
921
- update! (pre_setup,A)
922
- update! (pos_setup,A)
934
+ update (pre_setup,matrix = A)
935
+ update (pos_setup,matrix = A)
923
936
coarsen! (A,Ac,R,P,Ac_setup)
924
937
A = Ac
925
938
end
926
939
coarse_solver_setup = setup. coarse_level. coarse_solver_setup
927
- update! (coarse_solver_setup,A)
940
+ update (coarse_solver_setup,matrix = A)
928
941
setup
929
942
end
930
943
0 commit comments