From 869c378dbe265bb8fd4a4fb588edc7cb3269e50e Mon Sep 17 00:00:00 2001 From: kronbichler Date: Fri, 10 May 2013 15:47:24 +0000 Subject: [PATCH] Fix issue 28. git-svn-id: https://svn.dealii.org/trunk@29496 0785d39b-7218-0410-832d-ea1e28bc413d --- .../include/deal.II/base/convergence_table.h | 74 +++++-------- deal.II/source/base/convergence_table.cc | 5 +- tests/base/convergence_table_01.cc | 3 +- tests/base/convergence_table_04.cc | 104 ++++++++++++++++++ tests/base/convergence_table_04/cmp/generic | 25 +++++ 5 files changed, 163 insertions(+), 48 deletions(-) create mode 100644 tests/base/convergence_table_04.cc create mode 100644 tests/base/convergence_table_04/cmp/generic diff --git a/deal.II/include/deal.II/base/convergence_table.h b/deal.II/include/deal.II/base/convergence_table.h index df3bed1a50..3e6e069bb9 100644 --- a/deal.II/include/deal.II/base/convergence_table.h +++ b/deal.II/include/deal.II/base/convergence_table.h @@ -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 data_column_key - * due to the #RateMode in relation to - * the reference column reference_column_key. - * 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 + * data_column_key due to the #RateMode in relation to the + * reference column reference_column_key. 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 set_tex_supercaption (...) 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 + * set_tex_supercaption (...) 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); /** diff --git a/deal.II/source/base/convergence_table.cc b/deal.II/source/base/convergence_table.cc index eb668c53f0..0fdf15a838 100644 --- a/deal.II/source/base/convergence_table.cc +++ b/deal.II/source/base/convergence_table.cc @@ -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]))); } } diff --git a/tests/base/convergence_table_01.cc b/tests/base/convergence_table_01.cc index 88d58e8a85..b290d202f7 100644 --- a/tests/base/convergence_table_01.cc +++ b/tests/base/convergence_table_01.cc @@ -22,7 +22,8 @@ #include #include -// 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 index 0000000000..277bd1fed0 --- /dev/null +++ b/tests/base/convergence_table_04.cc @@ -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 +#include +#include +#include + +#include +#include +#include +#include + +// 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 index 0000000000..d9bff0796f --- /dev/null +++ b/tests/base/convergence_table_04/cmp/generic @@ -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 -- 2.39.5