]> https://gitweb.dealii.org/ - dealii.git/commitdiff
improve SolverSelector
authorGuido Kanschat <dr.guido.kanschat@gmail.com>
Thu, 1 Jul 2010 21:47:24 +0000 (21:47 +0000)
committerGuido Kanschat <dr.guido.kanschat@gmail.com>
Thu, 1 Jul 2010 21:47:24 +0000 (21:47 +0000)
git-svn-id: https://svn.dealii.org/trunk@21441 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/lac/include/lac/solver_control.h
deal.II/lac/include/lac/solver_selector.h

index b3f270a291d7357d12094a4d87935c8bd5322702..70a8832bf0f440e6550e09539c1b70a18b65694f 100644 (file)
@@ -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.
  * </ul>
+ *
+ * @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
index 3c5f581fe556eb5470af9552c9e5913799eda874..9459a8cb3314101173debc9c75212f0356945b43 100644 (file)
@@ -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 <tt>solver.control
+                                     * = my_control</tt> to set the
+                                     * values here.
+                                     *
+                                     * This object is updated in
+                                     * solve(), thus declared mutable
+                                     * here.
                                      */
-    SmartPointer<SolverControl,SolverSelector<VECTOR> > 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<VectorMemory<VECTOR>,SolverSelector<VECTOR> > vector_memory;
-
+    std::string solver_name;
+    
   private:
                                     /**
                                      * Stores the additional data.
@@ -223,13 +246,17 @@ class SolverSelector : public Subscriptor
 /* --------------------- Inline and template functions ------------------- */
 
 
+template <class VECTOR>
+SolverSelector<VECTOR>::SolverSelector()
+{}
+
+
 template <class VECTOR>
 SolverSelector<VECTOR>::SolverSelector(const std::string    &solver_name,
                                       SolverControl        &control,
-                                      VectorMemory<VECTOR> &vector_memory) :
+                                      VectorMemory<VECTOR> &) :
                solver_name(solver_name),
-               control(&control),
-               vector_memory(&vector_memory)
+               control(control)
 {}
 
 
@@ -238,6 +265,15 @@ SolverSelector<VECTOR>::~SolverSelector()
 {}
 
 
+template <class VECTOR>
+void
+SolverSelector<VECTOR>::select(const std::string& name)
+{
+  solver_name = name;
+}
+
+
+
 template <class VECTOR>
 template<class Matrix, class Preconditioner>
 void
@@ -246,33 +282,35 @@ SolverSelector<VECTOR>::solve(const Matrix &A,
                              const VECTOR &b,
                              const Preconditioner &precond) const
 {
+  GrowingVectorMemory<VECTOR> vector_memory;
+  
   if (solver_name=="richardson")
     {
-      SolverRichardson<VECTOR> solver(*control,*vector_memory,
+      SolverRichardson<VECTOR> solver(control,vector_memory,
                                      richardson_data);
       solver.solve(A,x,b,precond);
     }       
   else if (solver_name=="cg")
     {
-      SolverCG<VECTOR> solver(*control,*vector_memory,
+      SolverCG<VECTOR> solver(control,vector_memory,
                              cg_data);
       solver.solve(A,x,b,precond);
     }
   else if (solver_name=="bicgstab")
     {
-      SolverBicgstab<VECTOR> solver(*control,*vector_memory,
+      SolverBicgstab<VECTOR> solver(control,vector_memory,
                                    bicgstab_data);
       solver.solve(A,x,b,precond);
     }
   else if (solver_name=="gmres")
     {
-      SolverGMRES<VECTOR> solver(*control,*vector_memory,
+      SolverGMRES<VECTOR> solver(control,vector_memory,
                                 gmres_data);
       solver.solve(A,x,b,precond);
     }
   else if (solver_name=="fgmres")
     {
-      SolverFGMRES<VECTOR> solver(*control,*vector_memory,
+      SolverFGMRES<VECTOR> solver(control,vector_memory,
                                  fgmres_data);
       solver.solve(A,x,b,precond);
     }

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.