From: Guido Kanschat Date: Thu, 1 Jul 2010 21:47:24 +0000 (+0000) Subject: improve SolverSelector X-Git-Tag: v8.0.0~5862 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dc4db926033103220d8a68862909c8ab6be4a36a;p=dealii.git improve SolverSelector git-svn-id: https://svn.dealii.org/trunk@21441 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/lac/include/lac/solver_control.h b/deal.II/lac/include/lac/solver_control.h index b3f270a291..70a8832bf0 100644 --- a/deal.II/lac/include/lac/solver_control.h +++ b/deal.II/lac/include/lac/solver_control.h @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 by the deal.II authors +// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2010 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -56,6 +56,8 @@ class ParameterHandler; * could not be achieved or at least was not achieved within the given * maximal number of iterations. * + * + * @author Guido Kanschat */ class SolverControl : public Subscriptor { @@ -452,7 +454,9 @@ class SolverControl : public Subscriptor * of iterations is 20, the reduction factor is 1% und the tolerance * is 0.1%. The initial residual is 2.5. The process will break if 20 * iteration are comleted or the new residual is less then 2.5*1% or - * if it is less then 0.1%. + * if it is less then 0.1%. + * + * @author Guido Kanschat */ class ReductionControl : public SolverControl { @@ -469,6 +473,15 @@ class ReductionControl : public SolverControl const bool log_history = false, const bool log_result = true); + /** + * Assign a SolverControl object + * to ReductionControl. The + * result of the assignment will + * emulate SolverControl by + * setting #reduce to zero. + */ + ReductionControl& operator= (const SolverControl& c); + /** * Virtual destructor is needed * as there are virtual functions @@ -612,6 +625,15 @@ SolverControl::log_result () const } +inline +ReductionControl& +ReductionControl::operator= (const SolverControl& c) +{ + SolverControl::operator=(c); + set_reduction(0.); + return *this; +} + inline double ReductionControl::reduction () const diff --git a/deal.II/lac/include/lac/solver_selector.h b/deal.II/lac/include/lac/solver_selector.h index 3c5f581fe5..9459a8cb33 100644 --- a/deal.II/lac/include/lac/solver_selector.h +++ b/deal.II/lac/include/lac/solver_selector.h @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009 by the deal.II authors +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009, 2010 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -98,9 +98,19 @@ class SolverSelector : public Subscriptor public: /** + * Constructor, filling in + * default values + */ + SolverSelector (); + + /** + * @deprecated Use deafult + * constructor and select. + * * Constructor. Use the arguments * to initialize actual solver - * objects. + * objects. The VectorMemory + * argument is ignored. */ SolverSelector (const std::string &solvername, SolverControl &control, @@ -123,6 +133,13 @@ class SolverSelector : public Subscriptor VECTOR &x, const VECTOR &b, const Preconditioner &precond) const; + + /** + * Select a new solver. Note that + * all solver names used in this + * class are all lower case. + */ + void select(const std::string& name); /** * Set the additional data. For more @@ -172,26 +189,32 @@ class SolverSelector : public Subscriptor std::string, << "Solver " << arg1 << " does not exist. Use one of " << std::endl << get_solver_names()); - protected: /** - * Stores the Name of the solver. - */ - std::string solver_name; - - /** - * Stores the @p SolverControl that + * Stores the @p ReductionControl that * is needed in the constructor of - * each @p Solver class. + * each @p Solver class. This + * data member is public, so that + * it can easily be changed from + * its default values. If you + * create a SolverControl or + * ReductionControl object with + * the values needed, you can + * simply use solver.control + * = my_control to set the + * values here. + * + * This object is updated in + * solve(), thus declared mutable + * here. */ - SmartPointer > control; + mutable ReductionControl control; + protected: /** - * Stores the @p VectorMemory that - * is needed in the constructor of - * each @p Solver class. + * Stores the name of the solver. */ - SmartPointer,SolverSelector > vector_memory; - + std::string solver_name; + private: /** * Stores the additional data. @@ -223,13 +246,17 @@ class SolverSelector : public Subscriptor /* --------------------- Inline and template functions ------------------- */ +template +SolverSelector::SolverSelector() +{} + + template SolverSelector::SolverSelector(const std::string &solver_name, SolverControl &control, - VectorMemory &vector_memory) : + VectorMemory &) : solver_name(solver_name), - control(&control), - vector_memory(&vector_memory) + control(control) {} @@ -238,6 +265,15 @@ SolverSelector::~SolverSelector() {} +template +void +SolverSelector::select(const std::string& name) +{ + solver_name = name; +} + + + template template void @@ -246,33 +282,35 @@ SolverSelector::solve(const Matrix &A, const VECTOR &b, const Preconditioner &precond) const { + GrowingVectorMemory vector_memory; + if (solver_name=="richardson") { - SolverRichardson solver(*control,*vector_memory, + SolverRichardson solver(control,vector_memory, richardson_data); solver.solve(A,x,b,precond); } else if (solver_name=="cg") { - SolverCG solver(*control,*vector_memory, + SolverCG solver(control,vector_memory, cg_data); solver.solve(A,x,b,precond); } else if (solver_name=="bicgstab") { - SolverBicgstab solver(*control,*vector_memory, + SolverBicgstab solver(control,vector_memory, bicgstab_data); solver.solve(A,x,b,precond); } else if (solver_name=="gmres") { - SolverGMRES solver(*control,*vector_memory, + SolverGMRES solver(control,vector_memory, gmres_data); solver.solve(A,x,b,precond); } else if (solver_name=="fgmres") { - SolverFGMRES solver(*control,*vector_memory, + SolverFGMRES solver(control,vector_memory, fgmres_data); solver.solve(A,x,b,precond); }