]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Bugfix: Allow to call ConvergenceTable::evaluate_convergence_rates multiple times
authormaier <maier@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 8 Apr 2013 13:55:10 +0000 (13:55 +0000)
committermaier <maier@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 8 Apr 2013 13:55:10 +0000 (13:55 +0000)
The corresponding methods will now just update missing entries in the
corresponding rows instead of insisting that a row must be empty...

git-svn-id: https://svn.dealii.org/trunk@29217 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/doc/news/changes.h
deal.II/source/base/convergence_table.cc

index ae9c06b683956dad2cb3e22b891327f0a2091209..0d7ec5d70a10f2bead45577194670ceb6ced086f 100644 (file)
@@ -87,6 +87,12 @@ this function.
 <a name="specific"></a>
 <h3>Specific improvements</h3>
 
+<li> Fixed: It is now possible to call ConvergenceTable::evaluate_convergence_rates
+multiple times.
+<br>
+(Matthias Maier, 2013/04/08)
+</li>
+
 <ol>
 <li> Fixed: GridTools::distort_random (previously called Triangulation::distort_random)
 had a bug where points were only ever moved in <i>positive</i> coordinate
index 7443c212c77ac4a06bdd0a6c54c6a1b4dbe92d60..eb668c53f0a4417493507cb9e49b0ebf73c7975d 100644 (file)
@@ -2,7 +2,7 @@
 //    $Id$
 //    Version: $Name$
 //
-//    Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2011, 2012 by the deal.II authors
+//    Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2011, 2012, 2013 by the deal.II authors
 //
 //    This file is subject to QPL and may not be  distributed
 //    without copyright and license information. Please refer
@@ -30,20 +30,19 @@ void ConvergenceTable::evaluate_convergence_rates(const std::string &data_column
   Assert(columns.count(reference_column_key),
          ExcColumnNotExistent(reference_column_key));
 
-  if (rate_mode==none)
+  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
+  // 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;
+  std::string rate_key = data_column_key;
 
-  const unsigned int n=entries.size();
-  const unsigned int n_ref=ref_entries.size();
+  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);
@@ -55,46 +54,69 @@ void ConvergenceTable::evaluate_convergence_rates(const std::string &data_column
       ref_values[i] = ref_entries[i].get_numeric_value();
     }
 
+  unsigned int no_rate_entries = 0;
+
   switch (rate_mode)
     {
     case none:
       break;
     case reduction_rate:
-      rate_key+="red.rate";
-      Assert(columns.count(rate_key)==0, ExcRateColumnAlreadyExists(rate_key));
-      // no value available for the
-      // 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] *
-                  ref_values[i]/ref_values[i-1]);
+      rate_key += "red.rate";
+      no_rate_entries = columns[rate_key].entries.size();
+      // Calculate all missing rate values:
+      for (unsigned int i = no_rate_entries; i<n; ++i)
+        {
+          if(i == 0)
+            {
+              // no value available for the first row
+              add_value(rate_key, std::string("-"));
+            }
+          else
+            {
+              add_value(rate_key, values[i-1]/values[i] *
+                        ref_values[i]/ref_values[i-1]);
+            }
+        }
       break;
     case reduction_rate_log2:
-      rate_key+="red.rate";
-      Assert(columns.count(rate_key)==0, ExcRateColumnAlreadyExists(rate_key));
-      // no value available for the
-      // first row
-      add_value(rate_key, std::string("-"));
-      for (unsigned int i=1; i<n; ++i)
-        add_value(rate_key, 2*std::log(std::fabs(values[i-1]/values[i])) /
-                  std::log(std::fabs(ref_values[i]/ref_values[i-1])));
+      rate_key += "red.rate";
+      no_rate_entries = columns[rate_key].entries.size();
+      // Calculate all missing rate values:
+      for (unsigned int i = no_rate_entries; i<n; ++i)
+        {
+          if(i == 0)
+            {
+              // no value available for the first row
+              add_value(rate_key, std::string("-"));
+            }
+          else
+            {
+              add_value(rate_key, 2*std::log(std::fabs(values[i-1]/values[i])) /
+                        std::log(std::fabs(ref_values[i]/ref_values[i-1])));
+            }
+        }
       break;
     default:
-      Assert(false, ExcNotImplemented());
+      AssertThrow(false, ExcNotImplemented());
     }
 
   Assert(columns.count(rate_key), ExcInternalError());
-  columns[rate_key].flag=1;
+  columns[rate_key].flag = 1;
   set_precision(rate_key, 2);
 
-  std::string superkey=data_column_key;
+  std::string superkey = data_column_key;
   if (!supercolumns.count(superkey))
     {
       add_column_to_supercolumn(data_column_key, superkey);
       set_tex_supercaption(superkey, columns[data_column_key].tex_caption);
     }
 
-  add_column_to_supercolumn(rate_key, superkey);
+  // only add rate_key to the supercolumn once
+  if(no_rate_entries == 0)
+    {
+      add_column_to_supercolumn(rate_key, superkey);
+    }
+
 }
 
 
@@ -105,9 +127,8 @@ ConvergenceTable::evaluate_convergence_rates(const std::string &data_column_key,
 {
   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
+  // 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;
@@ -119,6 +140,8 @@ ConvergenceTable::evaluate_convergence_rates(const std::string &data_column_key,
   for (unsigned int i=0; i<n; ++i)
     values[i] = entries[i].get_numeric_value();
 
+  unsigned int no_rate_entries = 0;
+
   switch (rate_mode)
     {
     case none:
@@ -126,26 +149,42 @@ ConvergenceTable::evaluate_convergence_rates(const std::string &data_column_key,
 
     case reduction_rate:
       rate_key+="red.rate";
-      Assert(columns.count(rate_key)==0, ExcRateColumnAlreadyExists(rate_key));
-      // no value available for the
-      // 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]);
+      no_rate_entries = columns[rate_key].entries.size();
+      // Calculate all missing rate values:
+      for (unsigned int i = no_rate_entries; i<n; ++i)
+        {
+          if(i == 0)
+            {
+              // no value available for the first row
+              add_value(rate_key, std::string("-"));
+            }
+          else
+            {
+              add_value(rate_key, values[i-1]/values[i]);
+            }
+        }
       break;
 
     case reduction_rate_log2:
       rate_key+="red.rate.log2";
-      Assert(columns.count(rate_key)==0, ExcRateColumnAlreadyExists(rate_key));
-      // no value available for the
-      // first row
-      add_value(rate_key, std::string("-"));
-      for (unsigned int i=1; i<n; ++i)
-        add_value(rate_key, std::log(std::fabs(values[i-1]/values[i]))/std::log(2.0));
+      no_rate_entries = columns[rate_key].entries.size();
+      // Calculate all missing rate values:
+      for (unsigned int i = no_rate_entries; i<n; ++i)
+        {
+          if(i == 0)
+            {
+              // no value available for the first row
+              add_value(rate_key, std::string("-"));
+            }
+          else
+            {
+              add_value(rate_key, std::log(std::fabs(values[i-1]/values[i]))/std::log(2.0));
+            }
+        }
       break;
 
     default:
-      Assert(false, ExcNotImplemented());
+      AssertThrow(false, ExcNotImplemented());
     }
 
   Assert(columns.count(rate_key), ExcInternalError());
@@ -154,15 +193,19 @@ ConvergenceTable::evaluate_convergence_rates(const std::string &data_column_key,
 
   // set the superkey equal to the key
   std::string superkey=data_column_key;
-  // and set the tex caption of the supercolumn
-  // to the tex caption of the data_column.
+  // and set the tex caption of the supercolumn to the tex caption of the
+  // data_column.
   if (!supercolumns.count(superkey))
     {
       add_column_to_supercolumn(data_column_key, superkey);
       set_tex_supercaption(superkey, columns[data_column_key].tex_caption);
     }
 
-  add_column_to_supercolumn(rate_key, superkey);
+  // only add rate_key to the supercolumn once
+  if(no_rate_entries == 0)
+    {
+      add_column_to_supercolumn(rate_key, superkey);
+    }
 }
 
 

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.