//---------------------------------------------------------------------------
// $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
* 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
* 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>
* Constructor.
*/
ConvergenceTable();
-
+
/**
* Rate in relation to the rows.
*/
*/
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
* 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,
/**
* 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
* 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
* 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
* 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
* 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
*/
void
evaluate_all_convergence_rates(const RateMode rate_mode);
-
+
/** @addtogroup Exceptions
* @{ */
-
+
/**
* Exception
*/
// $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
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;
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:
// 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:
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);
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:
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
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;
}
--- /dev/null
+//-----------------------------------------------------------------------------
+// $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());
+}