From: bangerth Date: Wed, 19 Oct 2011 08:37:52 +0000 (+0000) Subject: Switch off auto fill mode before computing convergence rates. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=20cfdd73a43c17e5d9c0e75e717085902ec72cc6;p=dealii-svn.git Switch off auto fill mode before computing convergence rates. git-svn-id: https://svn.dealii.org/trunk@24639 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/include/deal.II/base/convergence_table.h b/deal.II/include/deal.II/base/convergence_table.h index c623873d4d..66f65106db 100644 --- a/deal.II/include/deal.II/base/convergence_table.h +++ b/deal.II/include/deal.II/base/convergence_table.h @@ -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 L2-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. *
    *
  1. call evaluate_convergence_rates() for all wanted columns *
  2. 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. *
@@ -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 data_column_key + * 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 @@ -108,25 +108,34 @@ class ConvergenceTable: public TableHandler * the set_tex_supercaption (...) 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 data_column_key + * data column data_column_key * 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 key + * Omit this column key * (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 n cells or + * Example: + * Columns like n cells or * n dofs 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 rate_mode. 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 n cells or + * Example: + * Columns like n cells or * n dofs 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 */ diff --git a/deal.II/source/base/convergence_table.cc b/deal.II/source/base/convergence_table.cc index 017c6c48ed..ceb48abf24 100644 --- a/deal.II/source/base/convergence_table.cc +++ b/deal.II/source/base/convergence_table.cc @@ -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 &entries=columns[data_column_key].entries; std::vector &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 values(n); std::vector ref_values(n_ref); - + for (unsigned int i=0; i &entries = columns[data_column_key].entries; std::string rate_key=data_column_key+"..."; const unsigned int n=entries.size(); - + std::vector values(n); for (unsigned int i=0; i::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 index 0000000000..8628e7d6aa --- /dev/null +++ b/tests/base/convergence_table_03.cc @@ -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 +#include +#include +#include + +#include +#include +#include +#include + + +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 index 0000000000..b03eb2df56 --- /dev/null +++ b/tests/base/convergence_table_03/cmp/generic @@ -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