]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Switch off auto fill mode before computing convergence rates.
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 19 Oct 2011 08:37:52 +0000 (08:37 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 19 Oct 2011 08:37:52 +0000 (08:37 +0000)
git-svn-id: https://svn.dealii.org/trunk@24639 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/include/deal.II/base/convergence_table.h
deal.II/source/base/convergence_table.cc
tests/base/convergence_table_03.cc [new file with mode: 0644]
tests/base/convergence_table_03/cmp/generic [new file with mode: 0644]

index c623873d4dc127f5d657d6b60d9e97f08d703f45..66f65106db854f8e0e79831f082d577e8f849bde 100644 (file)
@@ -1,7 +1,7 @@
 //---------------------------------------------------------------------------
 //    $Id$
 //
-//    Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2008 by the deal.II authors
+//    Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2008, 2011 by the deal.II authors
 //
 //    This file is subject to QPL and may not be  distributed
 //    without copyright and license information. Please refer
@@ -25,8 +25,8 @@ DEAL_II_NAMESPACE_OPEN
  * cg-method, or some evaluated <i>L<sup>2</sup></i>-errors of
  * discrete solutions, etc, and evaluates convergence rates or orders.
  *
- * The already implemented #RateMode's are #reduction_rate, 
- * where the convergence rate is the quotient of two following rows, and 
+ * The already implemented #RateMode's are #reduction_rate,
+ * where the convergence rate is the quotient of two following rows, and
  * #reduction_rate_log2, that evaluates the order of convergence.
  * These standard evaluations are useful for global refinement, for local refinement
  * this may not be an appropriate method, as the convergence rates should be
@@ -39,12 +39,12 @@ DEAL_II_NAMESPACE_OPEN
  * functions evaluate_convergence_rates() and evaluate_all_convergence_rates()
  * may be called (even multiply).
  *
- * There are two possibilities of how to evaluate the convergence rates of multiple 
+ * There are two possibilities of how to evaluate the convergence rates of multiple
  * columns in the same RateMode.
  * <ol>
  * <li> call evaluate_convergence_rates() for all wanted columns
  * <li> call omit_column_from_convergence_rate_evaluation() for all
- * NOT wanted columns and then 
+ * NOT wanted columns and then
  * evaluate_all_convergence_rates() to evaluate the convergence rates of all columns
  * that are not signed to be omitted.
  * </ol>
@@ -62,7 +62,7 @@ class ConvergenceTable: public TableHandler
                                      * Constructor.
                                      */
     ConvergenceTable();
-    
+
                                     /**
                                      * Rate in relation to the rows.
                                      */
@@ -88,10 +88,10 @@ class ConvergenceTable: public TableHandler
                                            */
          reduction_rate_log2
     };
-    
+
                                     /**
                                      * Evaluates the convergence rates of the
-                                     * data column <tt>data_column_key</tt> 
+                                     * data column <tt>data_column_key</tt>
                                      * due to the #RateMode in relation to
                                      * the reference column <tt>reference_column_key</tt>.
                                      * Be sure that the value types of the
@@ -108,25 +108,34 @@ class ConvergenceTable: public TableHandler
                                      * the <tt>set_tex_supercaption (...)</tt> function
                                      * of the base class TableHandler.
                                      *
-                                     * This method behaves in the following way: 
-                                     * 
+                                     * This method behaves in the following way:
+                                     *
                                      * If RateMode is reduction_rate, then the computed
-                                     * output is 
+                                     * output is
                                      * $ \frac{e_{n-1}/k_{n-1}}{e_n/k_n} $.
                                      *
                                      * Where $k$ is the reference column.
                                      *
-                                     * If RateMode is reduction_rate_log2, then the 
+                                     * If RateMode is reduction_rate_log2, then the
                                      * computed output is
                                      * $
-                                     * 2\frac{\log |e_{n-1}/e_{n}|}{\log |k_n/k_{n-1}|} 
+                                     * 2\frac{\log |e_{n-1}/e_{n}|}{\log |k_n/k_{n-1}|}
                                      * $.
                                      *
-                                     * This is useful, for example, if we use as 
-                                     * reference key the number of degrees of freedom. 
-                                     * Assuming that the error is proportional to 
-                                     * $ C (1/\sqrt{k})^r $, then this method will 
+                                     * This is useful, for example, if we use as
+                                     * reference key the number of degrees of freedom.
+                                     * Assuming that the error is proportional to
+                                     * $ C (1/\sqrt{k})^r $, then this method will
                                      * produce the rate $r$ as a result.
+                                     *
+                                     * @note Since this function adds columns
+                                     * to the table after several rows have
+                                     * already been filled, it switches off
+                                     * the auto fill mode of the TableHandler
+                                     * base class. If you intend to add
+                                     * further data with auto fill, you will
+                                     * have to re-enable it after calling
+                                     * this function.
                                      */
     void
     evaluate_convergence_rates (const std::string &data_column_key,
@@ -136,7 +145,7 @@ class ConvergenceTable: public TableHandler
 
                                     /**
                                      * Evaluates the convergence rates of the
-                                     * data column <tt>data_column_key</tt> 
+                                     * data column <tt>data_column_key</tt>
                                      * due to the #RateMode.
                                      * Be sure that the value types of the
                                      * table entries of the data column
@@ -150,16 +159,25 @@ class ConvergenceTable: public TableHandler
                                      * data column. This may be changed by using
                                      * the set_tex_supercaption() function
                                      * of the base class TableHandler.
+                                     *
+                                     * @note Since this function adds columns
+                                     * to the table after several rows have
+                                     * already been filled, it switches off
+                                     * the auto fill mode of the TableHandler
+                                     * base class. If you intend to add
+                                     * further data with auto fill, you will
+                                     * have to re-enable it after calling
+                                     * this function.
                                      */
     void
-    evaluate_convergence_rates (const std::string &data_column_key, 
+    evaluate_convergence_rates (const std::string &data_column_key,
                                 const RateMode     rate_mode);
 
                                     /**
-                                     * Omit this column <tt>key</tt> 
+                                     * Omit this column <tt>key</tt>
                                      * (not supercolumn!) from the
                                      * evaluation of the convergence rates
-                                     * of `all' columns (see the following 
+                                     * of `all' columns (see the following
                                      * two functions).
                                      *
                                      * The Column::flag==1 is reserved for
@@ -188,8 +206,8 @@ class ConvergenceTable: public TableHandler
                                      * evaluate_convergence_rates()
                                      * for each column separately.
                                      *
-                                     * Example: 
-                                     * Columns like <tt>n cells</tt> or 
+                                     * Example:
+                                     * Columns like <tt>n cells</tt> or
                                      * <tt>n dofs</tt> columns may be wanted
                                      * to be omitted in the evaluation
                                      * of the convergence rates. Hence they
@@ -204,7 +222,7 @@ class ConvergenceTable: public TableHandler
                                      * Evaluates convergence rates
                                      * due to the <tt>rate_mode</tt>. This
                                      * function evaluates the rates of
-                                     * ALL columns except of the 
+                                     * ALL columns except of the
                                      * columns that are to be omitted
                                      * (see previous function)
                                      * and execpt of the columns that are
@@ -216,8 +234,8 @@ class ConvergenceTable: public TableHandler
                                      * evaluate_convergence_rates()
                                      * for each column seperately.
                                      *
-                                     * Example: 
-                                     * Columns like <tt>n cells</tt> or 
+                                     * Example:
+                                     * Columns like <tt>n cells</tt> or
                                      * <tt>n dofs</tt> columns may be wanted
                                      * to be omitted in the evaluation
                                      * of the convergence rates. Hence they
@@ -226,10 +244,10 @@ class ConvergenceTable: public TableHandler
                                      */
     void
     evaluate_all_convergence_rates(const RateMode rate_mode);
-    
+
                                     /** @addtogroup Exceptions
                                      * @{ */
-    
+
                                     /**
                                      * Exception
                                      */
index 017c6c48ed6c2e6ff217cc08943b8a089a57fcd8..ceb48abf2429e05c38cffd640954e014ac1811b8 100644 (file)
@@ -2,7 +2,7 @@
 //    $Id$
 //    Version: $Name$
 //
-//    Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007 by the deal.II authors
+//    Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2011 by the deal.II authors
 //
 //    This file is subject to QPL and may not be  distributed
 //    without copyright and license information. Please refer
@@ -29,10 +29,15 @@ void ConvergenceTable::evaluate_convergence_rates(const std::string &data_column
         ExcColumnNotExistent(data_column_key));
   Assert(columns.count(reference_column_key),
         ExcColumnNotExistent(reference_column_key));
+
   if (rate_mode==none)
     return;
+
+                                  // reset the auto fill mode flag since we
+                                  // are going to fill columns from the top
+                                  // that don't yet exist
+  set_auto_fill_mode (false);
+
   std::vector<internal::TableEntry> &entries=columns[data_column_key].entries;
   std::vector<internal::TableEntry> &ref_entries=columns[reference_column_key].entries;
   std::string rate_key=data_column_key;
@@ -40,16 +45,16 @@ void ConvergenceTable::evaluate_convergence_rates(const std::string &data_column
   const unsigned int n=entries.size();
   const unsigned int n_ref=ref_entries.size();
   Assert(n == n_ref, ExcDimensionMismatch(n, n_ref));
-  
+
   std::vector<double> values(n);
   std::vector<double> ref_values(n_ref);
-  
+
   for (unsigned int i=0; i<n; ++i)
     {
       values[i]     = entries[i].get_numeric_value();
       ref_values[i] = ref_entries[i].get_numeric_value();
     }
-  
+
   switch (rate_mode)
     {
       case none:
@@ -61,7 +66,7 @@ void ConvergenceTable::evaluate_convergence_rates(const std::string &data_column
                                             // first row
            add_value(rate_key, std::string("-"));
            for (unsigned int i=1; i<n; ++i)
-               add_value(rate_key, values[i-1]/values[i] * 
+               add_value(rate_key, values[i-1]/values[i] *
                                    ref_values[i]/ref_values[i-1]);
            break;
       case reduction_rate_log2:
@@ -75,10 +80,10 @@ void ConvergenceTable::evaluate_convergence_rates(const std::string &data_column
                          std::log(std::fabs(ref_values[i]/ref_values[i-1])));
            break;
       default:
-           Assert(false, ExcNotImplemented());  
+           Assert(false, ExcNotImplemented());
     }
 
-  Assert(columns.count(rate_key), ExcInternalError());  
+  Assert(columns.count(rate_key), ExcInternalError());
   columns[rate_key].flag=1;
   set_precision(rate_key, 2);
 
@@ -99,16 +104,21 @@ ConvergenceTable::evaluate_convergence_rates(const std::string &data_column_key,
                                              const RateMode     rate_mode)
 {
   Assert(columns.count(data_column_key), ExcColumnNotExistent(data_column_key));
-  
+
+                                  // reset the auto fill mode flag since we
+                                  // are going to fill columns from the top
+                                  // that don't yet exist
+  set_auto_fill_mode (false);
+
   std::vector<internal::TableEntry> &entries = columns[data_column_key].entries;
   std::string rate_key=data_column_key+"...";
 
   const unsigned int n=entries.size();
-  
+
   std::vector<double> values(n);
   for (unsigned int i=0; i<n; ++i)
     values[i] = entries[i].get_numeric_value();
-  
+
   switch (rate_mode)
     {
       case none:
@@ -135,13 +145,13 @@ ConvergenceTable::evaluate_convergence_rates(const std::string &data_column_key,
            break;
 
       default:
-           ExcNotImplemented();  
+           ExcNotImplemented();
     }
 
-  Assert(columns.count(rate_key), ExcInternalError());  
+  Assert(columns.count(rate_key), ExcInternalError());
   columns[rate_key].flag=1;
   set_precision(rate_key, 2);
-  
+
                                   // set the superkey equal to the key
   std::string superkey=data_column_key;
                                   // and set the tex caption of the supercolumn
@@ -161,7 +171,7 @@ void
 ConvergenceTable::omit_column_from_convergence_rate_evaluation(const std::string &key)
 {
   Assert(columns.count(key), ExcColumnNotExistent(key));
-  
+
   const std::map<std::string, Column>::iterator col_iter=columns.find(key);
   col_iter->second.flag=1;
 }
diff --git a/tests/base/convergence_table_03.cc b/tests/base/convergence_table_03.cc
new file mode 100644 (file)
index 0000000..8628e7d
--- /dev/null
@@ -0,0 +1,51 @@
+//-----------------------------------------------------------------------------
+//    $Id$
+//    Version: $Name$
+//
+//    Copyright (C) 2010, 2011 by the deal.II authors
+//
+//    This file is subject to QPL and may not be  distributed
+//    without copyright and license information. Please refer
+//    to the file deal.II/doc/license.html for the  text  and
+//    further information on this license.
+//
+//-----------------------------------------------------------------------------
+
+// like _02, but with auto fill mode set on the underlying table
+
+#include "../tests.h"
+#include <deal.II/base/data_out_base.h>
+#include <deal.II/base/table_handler.h>
+#include <deal.II/base/convergence_table.h>
+#include <deal.II/base/logstream.h>
+
+#include <vector>
+#include <iomanip>
+#include <fstream>
+#include <string>
+
+
+int main ()
+{
+  std::ofstream logfile("convergence_table_03/output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+  ConvergenceTable table;
+  table.set_auto_fill_mode (true);
+
+  for (unsigned int i=1; i<=4; ++i)
+  {
+    table.add_value("error", 1./sqrt(i));
+    table.add_value("error2", std::pow(1./sqrt(i),2.));
+    table.add_value("error3", std::pow(1./sqrt(i),3.));
+    table.add_value("error4", std::pow(1./sqrt(i),4.));
+    table.add_value("key", i);
+  }
+  table.omit_column_from_convergence_rate_evaluation ( "key" );
+  table.evaluate_all_convergence_rates("key", ConvergenceTable::reduction_rate_log2);
+
+                                 // output
+  table.write_text(deallog.get_file_stream());
+}
diff --git a/tests/base/convergence_table_03/cmp/generic b/tests/base/convergence_table_03/cmp/generic
new file mode 100644 (file)
index 0000000..b03eb2d
--- /dev/null
@@ -0,0 +1,6 @@
+
+error  error2 error3 error4  key   
+1.0000 -      1.0000 -      1.0000 -    1.0000 -    1 
+0.7071 1.00   0.5000 2.00   0.3536 3.00 0.2500 4.00 2 
+0.5774 1.00   0.3333 2.00   0.1925 3.00 0.1111 4.00 3 
+0.5000 1.00   0.2500 2.00   0.1250 3.00 0.0625 4.00 4 

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.