]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Make the behavior of the previous patch optional to keep the ConvergenceTable functio...
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 18 Oct 2011 14:22:55 +0000 (14:22 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 18 Oct 2011 14:22:55 +0000 (14:22 +0000)
git-svn-id: https://svn.dealii.org/trunk@24632 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/doc/news/changes.h
deal.II/include/deal.II/base/table_handler.h
deal.II/source/base/table_handler.cc
tests/base/table_handler_04.cc

index e1c7bb66ef34f70fddfd17f9474ab7f8173ec3ff..30dea0c40e205500d24a7ba5bcc0115d24e790f3 100644 (file)
@@ -44,7 +44,7 @@ inconvenience this causes.
 <h3>Specific improvements</h3>
 
 <ol>
-<li> New: The TableHandler class now pads columns that have only been
+<li> New: The TableHandler class can now pad columns that have only been
 partially filled. See the documentation of the class for a description.
 <br>
 (Wolfgang Bangerth, 2011/10/18)
index 168ffb3a2a3edb3de85cd4ac9a96bf020091bb33..ebcbf754f7fced7f2a48c2e980d8a4d76063f940 100644 (file)
@@ -173,7 +173,7 @@ namespace internal
  * @endcode
  *
  *
- * <h3>Dealing with sparse data</h3>
+ * <h3>Dealing with sparse data: auto-fill mode</h3>
  *
  * 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
+ * <i>auto-fill mode</i>. 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 <code>add_value(key, value)</code>, we count the number of elements
  *   in the column corresponding to <code>key</code>. 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 <typename T>
     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;
 }
 
 
index 965cc85909fe27140a0dbd7ab46eb946d3765347..a4d8960d0ae5bea1ddf7aed2dfc84d6a274c6d70 100644 (file)
@@ -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)
 {
index a49a5b40b22c8c8b2102e78d7c357227f48711fd..2931b9a381dec6f678b47e35b91841da86fa3bad 100644 (file)
@@ -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" };
 

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.