]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix issue 28.
authorMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Fri, 10 May 2013 15:47:24 +0000 (15:47 +0000)
committerMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Fri, 10 May 2013 15:47:24 +0000 (15:47 +0000)
git-svn-id: https://svn.dealii.org/trunk@29496 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_01.cc
tests/base/convergence_table_04.cc [new file with mode: 0644]
tests/base/convergence_table_04/cmp/generic [new file with mode: 0644]

index df3bed1a508f41f1414b77cc7c9c8a7c0cd2199c..3e6e069bb952a2da0458ddce8d291c05696bb6b0 100644 (file)
@@ -73,75 +73,59 @@ public:
      */
     none,
     /**
-     * Quotient of values in
-     * the previous row and in
-     * this row.
+     * Quotient of values in the previous row and in this row.
      */
     reduction_rate,
     /**
-     * Logarithm of
-     * #reduction_rate to the
-     * base 2 representing the
-     * order of convergence
-     * when halving the grid
-     * size, e.g. from h to
-     * h/2.
+     * Logarithm of #reduction_rate to the base 2 representing the order of
+     * convergence when halving the grid size, e.g. from h to h/2.
      */
     reduction_rate_log2
   };
 
   /**
-   * Evaluates the convergence rates of the
-   * 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
-   * table entries of the
-   * data column and the reference data column
-   * is a number, i.e. double, float,
-   * (unsigned) int, and so on.
+   * Evaluates the convergence rates of the 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 table entries of the data column and the reference data
+   * column is a number, i.e. double, float, (unsigned) int, and so on.
    *
-   * The new rate column and the data column
-   * will be merged to a supercolumn. The
-   * tex caption of the supercolumn will be
-   * (by default) the same as the one of the
-   * data column. This may be changed by using
-   * the <tt>set_tex_supercaption (...)</tt> function
-   * of the base class TableHandler.
+   * As this class has no information on the space dimension upon which the
+   * reference column vs. the value column is based upon, it needs to be
+   * passed as last argument to this method. The default dimension is two.
+   *
+   * The new rate column and the data column will be merged to a
+   * supercolumn. The tex caption of the supercolumn will be (by default) the
+   * same as the one of the data column. This may be changed by using the
+   * <tt>set_tex_supercaption (...)</tt> function of the base class
+   * TableHandler.
    *
    * This method behaves in the following way:
    *
-   * If RateMode is reduction_rate, then the computed
-   * output is
+   * If RateMode is reduction_rate, then the computed 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
-   * computed output is
+   * 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}|}
+   * dim \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
-   * produce the rate $r$ as a result.
+   * 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.
+   * @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,
                               const std::string &reference_column_key,
-                              const RateMode     rate_mode);
+                              const RateMode     rate_mode,
+                              const unsigned int dim = 2);
 
 
   /**
index eb668c53f0a4417493507cb9e49b0ebf73c7975d..0fdf15a8383b97dba139ea1a72057056e80b5c12 100644 (file)
@@ -23,7 +23,8 @@ ConvergenceTable::ConvergenceTable()
 
 void ConvergenceTable::evaluate_convergence_rates(const std::string &data_column_key,
                                                   const std::string &reference_column_key,
-                                                  const RateMode     rate_mode)
+                                                  const RateMode     rate_mode,
+                                                  const unsigned int dim)
 {
   Assert(columns.count(data_column_key),
          ExcColumnNotExistent(data_column_key));
@@ -91,7 +92,7 @@ void ConvergenceTable::evaluate_convergence_rates(const std::string &data_column
             }
           else
             {
-              add_value(rate_key, 2*std::log(std::fabs(values[i-1]/values[i])) /
+              add_value(rate_key, dim*std::log(std::fabs(values[i-1]/values[i])) /
                         std::log(std::fabs(ref_values[i]/ref_values[i-1])));
             }
         }
index 88d58e8a85e7ced4bc093c8750aa345167f201a6..b290d202f7ef348ac004eba92cd89ba3a0cf55e3 100644 (file)
@@ -22,7 +22,8 @@
 #include <fstream>
 #include <string>
 
-// test the method evaluate_convergence_rates with argument reference_column_key, 
+// test the method evaluate_convergence_rates with argument
+// reference_column_key, assuming data coming from 2d
 
 int main ()
 {
diff --git a/tests/base/convergence_table_04.cc b/tests/base/convergence_table_04.cc
new file mode 100644 (file)
index 0000000..277bd1f
--- /dev/null
@@ -0,0 +1,104 @@
+//-----------------------------------------------------------------------------
+//    $Id$
+//    Version: $Name$ 
+//
+//    Copyright (C) 2010 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.
+//
+//-----------------------------------------------------------------------------
+
+#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>
+
+// test the method evaluate_convergence_rates with argument
+// reference_column_key and data from various dimension where the reference
+// data must be scaled by dimension
+
+int main ()
+{
+  std::ofstream logfile("convergence_table_04/output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+  ConvergenceTable table_1;
+  ConvergenceTable table_2;
+  ConvergenceTable table_3;
+
+  deallog.push("1d");
+  table_1.add_value("n_cells", 16);
+  table_1.add_value("error", 4.841e-04);
+  table_1.add_value("n_cells", 24);
+  table_1.add_value("error", 1.446e-04);
+  table_1.add_value("n_cells", 32);
+  table_1.add_value("error", 6.120e-05);
+  table_1.add_value("n_cells", 48);
+  table_1.add_value("error", 1.817e-05);
+  table_1.add_value("n_cells", 64);
+  table_1.add_value("error", 7.672e-06);
+  table_1.add_value("n_cells", 96);
+  table_1.add_value("error", 2.274e-06);
+  table_1.add_value("n_cells", 128);
+  table_1.add_value("error", 9.597e-07); 
+  table_1.set_scientific("error", true);
+  //table_1.evaluate_convergence_rates("error", "n_cells", ConvergenceTable::reduction_rate);
+  table_1.evaluate_convergence_rates("error", "n_cells", ConvergenceTable::reduction_rate_log2, 1);
+  table_1.write_text(deallog.get_file_stream());
+  deallog.pop();
+
+  deallog.push("2d");
+  table_2.add_value("n_cells", 64);
+  table_2.add_value("error", 7.755e-03);
+  table_2.add_value("n_cells", 144);
+  table_2.add_value("error", 2.326e-03);
+  table_2.add_value("n_cells", 256);
+  table_2.add_value("error", 9.969e-04);
+  table_2.add_value("n_cells", 576);
+  table_2.add_value("error", 2.987e-04);
+  table_2.add_value("n_cells", 1024);
+  table_2.add_value("error", 1.265e-04);
+  table_2.add_value("n_cells", 2304);
+  table_2.add_value("error", 3.759e-05);
+  table_2.add_value("n_cells", 4096);
+  table_2.add_value("error", 1.587e-05);
+  table_2.set_scientific("error", true);
+  //table_2.evaluate_convergence_rates("error", "n_cells", ConvergenceTable::reduction_rate);
+  table_2.evaluate_convergence_rates("error", "n_cells", ConvergenceTable::reduction_rate_log2, 2);
+  table_2.write_text(deallog.get_file_stream());
+  deallog.pop();
+
+  deallog.push("3d");
+  table_3.add_value("n_cells", 512);
+  table_3.add_value("error", 5.791e-02);
+  table_3.add_value("n_cells", 1728);
+  table_3.add_value("error", 2.624e-02);
+  table_3.add_value("n_cells", 4096);
+  table_3.add_value("error", 1.480e-02);
+  table_3.add_value("n_cells", 13824);
+  table_3.add_value("error", 6.587e-03);
+  table_3.add_value("n_cells", 32768);
+  table_3.add_value("error", 3.708e-03);
+  table_3.add_value("n_cells", 110592);
+  table_3.add_value("error", 1.649e-03);
+  table_3.add_value("n_cells", 262144);
+  table_3.add_value("error", 9.275e-04);
+  table_3.set_scientific("error", true);
+  //table_3.evaluate_convergence_rates("error", "n_cells", ConvergenceTable::reduction_rate);
+  table_3.evaluate_convergence_rates("error", "n_cells", ConvergenceTable::reduction_rate_log2, 3);
+  table_3.write_text(deallog.get_file_stream());
+  deallog.pop();
+
+
+}
diff --git a/tests/base/convergence_table_04/cmp/generic b/tests/base/convergence_table_04/cmp/generic
new file mode 100644 (file)
index 0000000..d9bff07
--- /dev/null
@@ -0,0 +1,25 @@
+
+n_cells      error      
+16      4.8410e-04 -    
+24      1.4460e-04 2.98 
+32      6.1200e-05 2.99 
+48      1.8170e-05 3.00 
+64      7.6720e-06 3.00 
+96      2.2740e-06 3.00 
+128     9.5970e-07 3.00 
+n_cells      error      
+64      7.7550e-03 -    
+144     2.3260e-03 2.97 
+256     9.9690e-04 2.95 
+576     2.9870e-04 2.97 
+1024    1.2650e-04 2.99 
+2304    3.7590e-05 2.99 
+4096    1.5870e-05 3.00 
+n_cells      error      
+512     5.7910e-02 -    
+1728    2.6240e-02 1.95 
+4096    1.4800e-02 1.99 
+13824   6.5870e-03 2.00 
+32768   3.7080e-03 2.00 
+110592  1.6490e-03 2.00 
+262144  9.2750e-04 2.00 

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.