]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Added clear_current_row() to TableHandler in case the current time step is rejected. 664/head
authorFahad Alrashed <fahad@keylock.net>
Sat, 14 Mar 2015 04:39:14 +0000 (07:39 +0300)
committerFahad Alrashed <fahad@keylock.net>
Sat, 14 Mar 2015 04:39:14 +0000 (07:39 +0300)
include/deal.II/base/table_handler.h
source/base/table_handler.cc
tests/base/table_handler_13.cc
tests/base/table_handler_13.output

index a5970683930dbd723d30c00440b2e09c25a6f44e..02c86f98fb988f894cd2f6a124c93a506022140d 100644 (file)
@@ -461,9 +461,16 @@ public:
   void clear ();
 
   /**
-   * Read or write the data of this object to or from a stream for the purpose
-   * of serialization.
-   */
+  * Remove all values added at the current row. This is useful when,
+  * for example, a time-step is rejected and all data recorded about
+  * it needs to be discarded.
+  */
+  void clear_current_row ();
+
+  /**
+  * Read or write the data of this object to or from a stream for the purpose
+  * of serialization.
+  */
   template <class Archive>
   void serialize(Archive &ar, const unsigned int version);
 
index a3de0f38f4b27c1e39077049f774e6d7439b9a96..fa49131bf0b2c55f8b71580557a13f7bdf4e41e1 100644 (file)
@@ -730,4 +730,20 @@ void TableHandler::get_selected_columns(std::vector<std::string> &sel_columns) c
 }
 
 
+void TableHandler::clear_current_row ()
+{
+  // Figure out what is the currect (max) length of the columns
+  // so that we "shave" one off.
+  unsigned long n = 0;
+  for (std::map< std::string, Column >::iterator p = columns.begin(); p != columns.end(); ++p)
+    n = std::max(n, p->second.entries.size());
+
+  // shave the top most element
+  if (n != 0)
+    for (std::map< std::string, Column >::iterator p = columns.begin(); p != columns.end(); ++p)
+      if (p->second.entries.size() == n)
+        p->second.entries.pop_back();
+}
+
+
 DEAL_II_NAMESPACE_CLOSE
index 591c1f1c3ab284c2079f0e3687b63fdb0b0f2dad..db379420b89249c639fe0afac0e173e4b84dafc9 100644 (file)
@@ -51,8 +51,19 @@ int main ()
   // now again fill row 4 partially
   table.add_value(keys[0], 1);
 
+  // now clear the partial row above
+  table.clear_current_row();
+
   // produce output. hope that row 4 is
   // completely padded
   table.write_text(deallog.get_file_stream(),
                    TableHandler::org_mode_table);
+
+  // now again fill row 4 partially
+  table.add_value(keys[0], 1);
+
+  // produce output. hope that we get 3 rows
+  table.write_text(deallog.get_file_stream(),
+                   TableHandler::org_mode_table);
+
 }
index 22555388a391975f3b4cedd049b99ee9f5429ef7..69b4eb580fac050246b3aad97b7d748cc6a654af 100644 (file)
@@ -1,6 +1,10 @@
 
 | key1 | key2 | key3 | 
-| 0 | 0   | "" | 
-| 1 | 0   | "" | 
-| 2 | 113 | a  | 
-| 1 | 0   | "" | 
+| 0    | 0    | ""   | 
+| 1    | 0    | ""   | 
+| 2    | 113  | a    | 
+| key1 | key2 | key3 | 
+| 0    | 0    | ""   | 
+| 1    | 0    | ""   | 
+| 2    | 113  | a    | 
+| 1    | 0    | ""   | 

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.