From aabda92c485dd07f7e65c0c69120e275a6061491 Mon Sep 17 00:00:00 2001 From: bangerth Date: Tue, 18 Oct 2011 14:22:55 +0000 Subject: [PATCH] Make the behavior of the previous patch optional to keep the ConvergenceTable function happy. git-svn-id: https://svn.dealii.org/trunk@24632 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/doc/news/changes.h | 2 +- deal.II/include/deal.II/base/table_handler.h | 49 ++++++++++++++------ deal.II/source/base/table_handler.cc | 9 ++++ tests/base/table_handler_04.cc | 1 + 4 files changed, 46 insertions(+), 15 deletions(-) diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index e1c7bb66ef..30dea0c40e 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -44,7 +44,7 @@ inconvenience this causes.

Specific improvements

    -
  1. New: The TableHandler class now pads columns that have only been +
  2. New: The TableHandler class can now pad columns that have only been partially filled. See the documentation of the class for a description.
    (Wolfgang Bangerth, 2011/10/18) diff --git a/deal.II/include/deal.II/base/table_handler.h b/deal.II/include/deal.II/base/table_handler.h index 168ffb3a2a..ebcbf754f7 100644 --- a/deal.II/include/deal.II/base/table_handler.h +++ b/deal.II/include/deal.II/base/table_handler.h @@ -173,7 +173,7 @@ namespace internal * @endcode * * - *

    Dealing with sparse data

    + *

    Dealing with sparse data: auto-fill mode

    * * When generating output, TableHandler expects that all columns have the exact * same number of elements in it so that the result is in fact a table. This @@ -182,13 +182,18 @@ namespace internal * you want to do. For example, it could be that the function that computes the * nonlinear residual is only called every few time steps; or, a function computing * statistics of the mesh is only called whenever the mesh is in fact refined. - * * In these cases, the add_value() function will be called less often for some * columns and the column would therefore have fewer elements; furthermore, these * elements would not be aligned with the rows that contain the other data elements * that were produced during this iteration. + * An entirely different scenario is that the table is filled and at a later time + * we use the data in there to compute the elements of other rows; the ConvergenceTable + * class does something like this. * - * To avoid this problem, we use the following algorithm: + * To support both scenarios, the TableHandler class has a property called + * auto-fill mode. By default, auto-fill mode is off, but it can be + * enabled by calling set_auto_fill_mode(). If auto-fill mode is enabled + * we use the following algorithm: * - When calling add_value(key, value), we count the number of elements * in the column corresponding to key. Let's call this number $m$. * - We also determine the maximal number of elements in the other columns; call @@ -239,6 +244,12 @@ class TableHandler template void add_value (const std::string &key, const T value); + + /** + * Switch auto-fill mode on or off. See the general documentation + * of this class for a description of what auto-fill mode does. + */ + void set_auto_fill_mode (const bool state); /** * Creates a supercolumn (if not @@ -515,7 +526,7 @@ class TableHandler * fixed point notation. */ bool scientific; - + /** * Flag that may be used by * derived classes for @@ -609,6 +620,11 @@ class TableHandler * The label of the table. */ std::string tex_table_label; + + /** + * Flag indicating whether auto-fill mode should be used. + */ + bool auto_fill_mode; }; @@ -781,15 +797,18 @@ void TableHandler::add_value (const std::string &key, column_order.push_back(key); } - // follow the algorithm given in the introduction to this class - // of padding columns as necessary - unsigned int n = 0; - for (std::map< std::string, Column >::iterator p = columns.begin(); p != columns.end(); ++p) - n = (n >= p->second.entries.size() ? n : p->second.entries.size()); + if (auto_fill_mode == true) + { + // follow the algorithm given in the introduction to this class + // of padding columns as necessary + unsigned int n = 0; + for (std::map< std::string, Column >::iterator p = columns.begin(); p != columns.end(); ++p) + n = (n >= p->second.entries.size() ? n : p->second.entries.size()); + + while (columns[key].entries.size()+1 < n) + columns[key].entries.push_back (internal::TableEntry(T())); + } - while (columns[key].entries.size()+1 < n) - columns[key].entries.push_back (internal::TableEntry(T())); - // now push the value given to this function columns[key].entries.push_back (internal::TableEntry(value)); } @@ -803,7 +822,8 @@ TableHandler::Column::serialize(Archive & ar, { ar & entries & tex_caption & tex_format & precision - & scientific & flag; + & scientific + & flag; } @@ -816,7 +836,8 @@ TableHandler::serialize(Archive & ar, ar & column_order & columns & supercolumns & tex_supercaptions & tex_table_caption - & tex_table_label; + & tex_table_label + & auto_fill_mode; } diff --git a/deal.II/source/base/table_handler.cc b/deal.II/source/base/table_handler.cc index 965cc85909..a4d8960d0a 100644 --- a/deal.II/source/base/table_handler.cc +++ b/deal.II/source/base/table_handler.cc @@ -53,10 +53,19 @@ TableHandler::Column::Column() TableHandler::TableHandler() +: +auto_fill_mode (false) {} +void +TableHandler::set_auto_fill_mode (const bool state) +{ + auto_fill_mode = state; +} + + void TableHandler::add_column_to_supercolumn (const std::string &key, const std::string &superkey) { diff --git a/tests/base/table_handler_04.cc b/tests/base/table_handler_04.cc index a49a5b40b2..2931b9a381 100644 --- a/tests/base/table_handler_04.cc +++ b/tests/base/table_handler_04.cc @@ -33,6 +33,7 @@ int main () deallog.threshold_double(1.e-10); TableHandler table; + table.set_auto_fill_mode (true); std::string keys[3] = { "key1", "key2", "key3" }; -- 2.39.5