From: guido Date: Mon, 28 Jun 1999 15:19:27 +0000 (+0000) Subject: MG works on locally refined meshes, needs improvement and cleaning, error in tests... X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=570b758541388eeda4ada2c8f3363e20d91d36b5;p=dealii-svn.git MG works on locally refined meshes, needs improvement and cleaning, error in tests/deal.II/mg is ok git-svn-id: https://svn.dealii.org/trunk@1487 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/tests/deal.II/helmholtz1.th b/tests/deal.II/helmholtz1.th index 5abed88b92..99fc58809a 100644 --- a/tests/deal.II/helmholtz1.th +++ b/tests/deal.II/helmholtz1.th @@ -50,7 +50,7 @@ Helmholtz::build_all(MATRIX& A, double u = fe.shape_value(j,k); elmat(i,j) += fe.JxW(k) * - (1.*u*v + du*dv) + (0.1*u*v + du*dv) ; } } diff --git a/tests/deal.II/helmholtz1mg.th b/tests/deal.II/helmholtz1mg.th index 450e0a4b5e..11d952711e 100644 --- a/tests/deal.II/helmholtz1mg.th +++ b/tests/deal.II/helmholtz1mg.th @@ -46,7 +46,7 @@ Helmholtz::build_mgmatrix(MGMatrix& A, double u = fe.shape_value(j,k); elmat(i,j) += fe.JxW(k) * - (1.*u*v + du*dv) + (0.1*u*v + du*dv) ; } } diff --git a/tests/deal.II/mg.cc b/tests/deal.II/mg.cc index 356fdfbfd3..d1c38f74fd 100644 --- a/tests/deal.II/mg.cc +++ b/tests/deal.II/mg.cc @@ -41,13 +41,13 @@ class MGSmootherLAC public MGSmootherBase { private: - SmartPointer > >matrices; + SmartPointer > >matrices; public: - MGSmootherLAC(MGMatrix >&); + MGSmootherLAC(MGMatrix >&); virtual void smooth (const unsigned int level, - Vector &u, - const Vector &rhs) const; + Vector &u, + const Vector &rhs) const; }; @@ -107,7 +107,7 @@ main() u = 0.; vector mgstruct(tr.n_levels()); - MGMatrix > mgA(0,tr.n_levels()-1); + MGMatrix > mgA(0,tr.n_levels()-1); for (unsigned int i=0;i > cgmem; - SolverCG, Vector > cgsolver(cgcontrol, cgmem); - PreconditionIdentity > cgprec; - MGCoarseGridLACIteration, Vector >, - SparseMatrix, PreconditionIdentity > > + PrimitiveVectorMemory > cgmem; + SolverCG, Vector > cgsolver(cgcontrol, cgmem); + PreconditionIdentity > cgprec; + MGCoarseGridLACIteration, Vector >, + SparseMatrix, PreconditionIdentity > > coarse(cgsolver, mgA[0], cgprec); MGSmootherLAC smoother(mgA); @@ -149,21 +149,21 @@ RHSFunction::operator() (const Point&) const return 1.; } -MGSmootherLAC::MGSmootherLAC(MGMatrix >& matrix) +MGSmootherLAC::MGSmootherLAC(MGMatrix >& matrix) : matrices(&matrix) {} void MGSmootherLAC::smooth (const unsigned int level, - Vector &u, - const Vector &rhs) const + Vector &u, + const Vector &rhs) const { - SolverControl control(1,1.e-300,false,false); - PrimitiveVectorMemory > mem; - SolverRichardson , Vector > rich(control, mem); - PreconditionRelaxation , Vector > - prec((*matrices)[level], &SparseMatrix ::template precondition_SSOR, 1.); + SolverControl control(2,1.e-300,false,false); + PrimitiveVectorMemory > mem; + SolverRichardson , Vector > rich(control, mem); + PreconditionRelaxation , Vector > + prec((*matrices)[level], &SparseMatrix ::template precondition_SSOR, 1.); rich.solve((*matrices)[level], u, rhs, prec); } diff --git a/tests/lac/Makefile b/tests/lac/Makefile index ac8fcdb906..138b42e782 100644 --- a/tests/lac/Makefile +++ b/tests/lac/Makefile @@ -148,7 +148,7 @@ veryclean: clean # Automatic generation of dependencies ############################################################ -all-cc-files = $(solver-cc-files) $(mgbase-cc-files) $(mg-cc-files) $(benchmark-cc-files) +all-cc-files = $(wildcard *.cc) Make.depend: $(all-cc-files) @echo =====Dependecies=== Make.depend diff --git a/tests/lac/mg.cc b/tests/lac/mg.cc index c667839d0b..0cba014f42 100644 --- a/tests/lac/mg.cc +++ b/tests/lac/mg.cc @@ -18,7 +18,7 @@ #include #define TYPE long double -#define ACCURACY 1.e-18 +#define ACCURACY 1.e-20 template void print_vector(ostream& s, const VECTOR& v) @@ -44,16 +44,16 @@ class FDMG /** * Pointer to the level matrices. */ - SmartPointer > >matrices; + SmartPointer > >matrices; public: - FDMG(unsigned int maxlevel, MGMatrix >& matrices, + FDMG(unsigned int maxlevel, MGMatrix >& matrices, FDMGTransfer& transfer); - virtual void level_residual (unsigned int level, - Vector& dst, - const Vector& src, - const Vector& rhs); + virtual void level_vmult (unsigned int level, + Vector& dst, + const Vector& src, + const Vector& rhs); void copy_to_mg(const Vector& rhs); void copy_from_mg(Vector& lsg); @@ -64,19 +64,19 @@ class MGSmootherLAC public MGSmootherBase { private: - SmartPointer > >matrices; + SmartPointer > >matrices; public: - MGSmootherLAC(MGMatrix >&); + MGSmootherLAC(MGMatrix >&); virtual void smooth (const unsigned int level, - Vector &u, - const Vector &rhs) const; + Vector &u, + const Vector &rhs) const; }; -typedef MGCoarseGridLACIteration , Vector >, -SparseMatrix, /*PreconditionRelaxation ,*/ - PreconditionIdentity > > +typedef MGCoarseGridLACIteration , Vector >, +SparseMatrix, /*PreconditionRelaxation ,*/ + PreconditionIdentity > > Coarse; @@ -86,7 +86,7 @@ main() deallog.attach(logfile); PrimitiveVectorMemory > mem; - SolverControl control(100, ACCURACY, true); + SolverControl control(10000, ACCURACY); const unsigned int base = 3; const unsigned int maxlevel = 8; @@ -97,9 +97,9 @@ main() FDMGTransfer transfer(maxsize, maxsize, maxlevel); // coarse grid solver - PrimitiveVectorMemory > cgmem; + PrimitiveVectorMemory > cgmem; ReductionControl cgcontrol(100, 1.e-30, 1.e-2, false, false); - SolverCG , Vector > cgcg(cgcontrol,cgmem); + SolverCG , Vector > cgcg(cgcontrol,cgmem); for (unsigned int level = 0; level <= maxlevel; ++level) @@ -113,7 +113,7 @@ main() // Make matrix vector structure(maxlevel+1); - MGMatrix > A(minlevel,maxlevel); + MGMatrix > A(minlevel,maxlevel); FDMatrix testproblem(size, size); @@ -131,9 +131,9 @@ main() FDMG multigrid(level, A, transfer); -// PreconditionRelaxation , Vector > - PreconditionIdentity > - cgprec;//(A[minlevel], &SparseMatrix ::template precondition_SSOR, 1.2); +// PreconditionRelaxation , Vector > + PreconditionIdentity > + cgprec;//(A[minlevel], &SparseMatrix ::template precondition_SSOR, 1.2); Coarse coarsegrid(cgcg, A[minlevel], cgprec); @@ -143,8 +143,8 @@ main() PreconditionMG > precondition(multigrid, smoother, smoother, coarsegrid); -// SolverRichardson , Vector > solver(control, mem); - SolverCG , Vector > solver(control, mem); +// SolverRichardson , Vector > solver(control, mem); + SolverCG , Vector > solver(control, mem); Vector u(dim); Vector f(dim); @@ -157,7 +157,7 @@ main() } } -FDMG::FDMG(unsigned int maxlevel, MGMatrix >& matrices, +FDMG::FDMG(unsigned int maxlevel, MGMatrix >& matrices, FDMGTransfer& transfer) : MGBase(transfer, 0, maxlevel), @@ -172,12 +172,12 @@ FDMG::FDMG(unsigned int maxlevel, MGMatrix >& matrices, void -FDMG::level_residual (unsigned int level, - Vector& dst, - const Vector& src, - const Vector& rhs) +FDMG::level_vmult (unsigned int level, + Vector& dst, + const Vector& src, + const Vector&) { - (*matrices)[level].residual(dst, src, rhs); + (*matrices)[level].vmult(dst, src); } void @@ -193,7 +193,7 @@ FDMG::copy_from_mg(Vector& v) } -MGSmootherLAC::MGSmootherLAC(MGMatrix >& matrix) +MGSmootherLAC::MGSmootherLAC(MGMatrix >& matrix) : matrices(&matrix) {} @@ -201,14 +201,14 @@ MGSmootherLAC::MGSmootherLAC(MGMatrix >& matrix) void MGSmootherLAC::smooth (const unsigned int level, - Vector &u, - const Vector &rhs) const + Vector &u, + const Vector &rhs) const { SolverControl control(1,1.e-300,false,false); - PrimitiveVectorMemory > mem; - SolverRichardson , Vector > rich(control, mem); - PreconditionRelaxation , Vector > - prec((*matrices)[level], &SparseMatrix ::template precondition_SSOR, 1.); + PrimitiveVectorMemory > mem; + SolverRichardson , Vector > rich(control, mem); + PreconditionRelaxation , Vector > + prec((*matrices)[level], &SparseMatrix ::template precondition_SSOR, 1.); rich.solve((*matrices)[level], u, rhs, prec); } diff --git a/tests/lac/mgbase.cc b/tests/lac/mgbase.cc index 59d7287ba2..8a47cd22a0 100644 --- a/tests/lac/mgbase.cc +++ b/tests/lac/mgbase.cc @@ -10,11 +10,11 @@ class TransferTest public MGTransferBase { virtual void prolongate(unsigned l, - Vector& dst, - const Vector& src) const; + Vector& dst, + const Vector& src) const; virtual void restrict(unsigned l, - Vector& dst, - const Vector& src) const; + Vector& dst, + const Vector& src) const; friend class MGBase; }; @@ -24,8 +24,8 @@ class SmoothTest { public: virtual void smooth (const unsigned int level, - Vector &u, - const Vector& rhs) const; + Vector &u, + const Vector& rhs) const; }; class MGCoarseGridTest @@ -34,8 +34,8 @@ class MGCoarseGridTest { public: virtual void operator () (unsigned int level, - Vector& dst, - const Vector& src) const ; + Vector& dst, + const Vector& src) const ; }; @@ -48,7 +48,7 @@ class MGTest public: MGTest(TransferTest& t, SmoothTest& sm, MGCoarseGridTest& cs) - : MGBase(t, 9, 3), + : MGBase(t, 3, 9), smoother(sm), solver(cs) { @@ -59,10 +59,10 @@ class MGTest } } - virtual void level_residual(unsigned level, - Vector& dst, - const Vector& src, - const Vector& rhs); + virtual void level_vmult(unsigned level, + Vector& dst, + const Vector& src, + const Vector& rhs); void doit() { @@ -83,41 +83,41 @@ main() void TransferTest::prolongate(unsigned l, - Vector&, - const Vector&) const + Vector&, + const Vector&) const { cout << "Prolongating " << l-1 << " to " << l << endl; } void TransferTest::restrict(unsigned l, - Vector&, - const Vector&) const + Vector&, + const Vector&) const { cout << "Restricting " << l << " to " << l-1 << endl; } void SmoothTest::smooth (const unsigned int level, - Vector &, - const Vector&) const + Vector &, + const Vector&) const { cout << "Smoothing on " << level << endl; } void -MGTest::level_residual(unsigned l, - Vector&, - const Vector&, - const Vector&) +MGTest::level_vmult(unsigned l, + Vector&, + const Vector&, + const Vector&) { cout << "Residual on " << l << endl; } void MGCoarseGridTest::operator() (unsigned int level, - Vector&, - const Vector&) const + Vector&, + const Vector&) const { cout << "Solving on " << level << endl; } diff --git a/tests/lac/solver.cc b/tests/lac/solver.cc index 62d6bcd842..b4f7d9a096 100644 --- a/tests/lac/solver.cc +++ b/tests/lac/solver.cc @@ -4,6 +4,7 @@ #include #include +#include #include "testmatrix.h" #include #include @@ -32,13 +33,13 @@ main() deallog.attach(logfile); PrimitiveVectorMemory > mem; - SolverControl control(100, 1.e-5, true); + SolverControl control(50, 1.e-5, true); SolverCG , Vector > cg(control, mem); SolverGMRES , Vector > gmres(control, mem,20); SolverBicgstab , Vector > bicgstab(control, mem); SolverRichardson , Vector > rich(control, mem); - for (unsigned int size=10; size <= 10; size *= 10) + for (unsigned int size=4; size <= 40; size *= 3) { deallog << "Size " << size << endl; @@ -61,6 +62,18 @@ main() Vector f(dim); Vector u(dim); + Vector res(dim); + + f = 1.; + u = 1.; + + A.residual(res,u,f); + A.SOR(res); + res.add(1.,u); + A.SOR_step(u,f); + res.add(-1.,u); + + deallog << "SOR-diff:" << res*res << endl; deallog.push("no"); diff --git a/tests/lac/testmatrix.cc b/tests/lac/testmatrix.cc index 5100cbe8d7..ac7840fb1a 100644 --- a/tests/lac/testmatrix.cc +++ b/tests/lac/testmatrix.cc @@ -118,7 +118,7 @@ FDMGTransfer::FDMGTransfer(unsigned int nx, unsigned int ny, void FDMGTransfer::build_matrix(unsigned int nx, unsigned int ny, - SparseMatrixStruct& structure, SparseMatrix& matrix) + SparseMatrixStruct& structure, SparseMatrix& matrix) { structure.reinit((nx-1)*(ny-1),(2*nx-1)*(2*ny-1),9); @@ -210,8 +210,8 @@ FDMGTransfer::build_matrix(unsigned int nx, unsigned int ny, void FDMGTransfer::prolongate (const unsigned int to_level, - Vector &dst, - const Vector &src) const + Vector &dst, + const Vector &src) const { Assert((to_level>0) && (to_level<=matrices.size()), ExcIndexRange(to_level, 0, matrices.size()+1)); @@ -222,8 +222,8 @@ FDMGTransfer::prolongate (const unsigned int to_level, void FDMGTransfer::restrict (const unsigned int from_level, - Vector &dst, - const Vector &src) const + Vector &dst, + const Vector &src) const { Assert((from_level>0) && (from_level<=matrices.size()), ExcIndexRange(from_level, 0, matrices.size()+1)); diff --git a/tests/lac/testmatrix.h b/tests/lac/testmatrix.h index 8099555fee..13e9ebf7be 100644 --- a/tests/lac/testmatrix.h +++ b/tests/lac/testmatrix.h @@ -66,16 +66,16 @@ class FDMGTransfer * function in #MGTranferBase#. */ virtual void prolongate (const unsigned int to_level, - Vector &dst, - const Vector &src) const; + Vector &dst, + const Vector &src) const; /** * Implementation of abstract * function in #MGTranferBase#. */ virtual void restrict (const unsigned int from_level, - Vector &dst, - const Vector &src) const; + Vector &dst, + const Vector &src) const; /** * Exception. @@ -91,7 +91,7 @@ class FDMGTransfer /** * Prolongation matrices. */ - vector > matrices; + vector > matrices; /** * Matrix generator. @@ -101,5 +101,5 @@ class FDMGTransfer * fine to coarse (#vmult#). */ void build_matrix(unsigned int nx, unsigned int ny, - SparseMatrixStruct&, SparseMatrix&); + SparseMatrixStruct&, SparseMatrix&); };