]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Move a few functions from fe_tools.cc to namespace Utilities.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Mon, 19 Dec 2005 21:38:34 +0000 (21:38 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Mon, 19 Dec 2005 21:38:34 +0000 (21:38 +0000)
git-svn-id: https://svn.dealii.org/trunk@11885 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/utilities.h
deal.II/base/source/utilities.cc
deal.II/deal.II/source/fe/fe_tools.cc
deal.II/doc/news/changes.html

index 0f492d86f686e5d447f9b51661d62a60df9eb532..7b1d6349f3b75d07d4db52be4ce05dec9ecb035a 100644 (file)
@@ -16,6 +16,7 @@
 #include <base/config.h>
 
 #include <vector>
+#include <utility>
 #include <string>
 
 #ifdef DEAL_II_USE_PETSC
@@ -95,7 +96,33 @@ namespace Utilities
   break_text_into_lines (const std::string &original_text,
                          const unsigned int width);
 
-  
+
+                                  /**
+                                   * Teturn true if the given pattern
+                                   * string appears in the first
+                                   * position of the string.
+                                   */
+  bool
+  match_at_string_start (const std::string &name,
+                        const std::string &pattern);
+
+                                  /**
+                                   * Read a (signed) integer starting
+                                   * at the position in #name
+                                   * indicated by the second
+                                   * argument, and retun this integer
+                                   * as a pair together with how many
+                                   * characters it takes up in the
+                                   * string.
+                                   *
+                                   * If no integer can be read at the
+                                   * indicated position, return
+                                   * (-1,deal_II_numbers::invalid_unsigned_int)
+                                   */
+  std::pair<int, unsigned int>
+  get_integer_at_position (const std::string &name,
+                          const unsigned int position);
+    
                                    /**
                                     * Generate a random number from a
                                     * normalized Gaussian probability
index 5f1f620bddb2b061e90c034b9b016aef47acb61f..c1c499d7f0dbc905f1be106d06f19484c9b06d22 100644 (file)
@@ -236,6 +236,66 @@ namespace Utilities
     return lines;
   }
   
+
+
+  bool
+  match_at_string_start (const std::string &name,
+                        const std::string &pattern)
+  {
+    if (pattern.size() > name.size())
+      return false;
+
+    for (unsigned int i=0; i<pattern.size(); ++i)
+      if (pattern[i] != name[i])
+       return false;
+
+    return true;
+  }
+
+  
+
+  std::pair<int, unsigned int>
+  get_integer_at_position (const std::string &name,
+                          const unsigned int position)
+  {
+    Assert (position < name.size(), ExcInternalError());
+    
+    const std::string test_string (name.begin()+position,
+                                  name.end());
+    
+#ifdef HAVE_STD_STRINGSTREAM
+    std::istringstream str(test_string);
+#else
+    std::istrstream str(test_string.c_str());
+#endif
+
+    int i;
+    if (str >> i)
+      {
+                                        // compute the number of
+                                        // digits of i. assuming it
+                                        // is less than 6 is likely
+                                        // ok
+       if (i<10)
+         return std::make_pair (i, 1U);
+       else if (i<100)
+         return std::make_pair (i, 2U);
+       else if (i<1000)
+         return std::make_pair (i, 3U);
+       else if (i<10000)
+         return std::make_pair (i, 4U);
+       else if (i<100000)
+         return std::make_pair (i, 5U);
+       else
+         {
+           Assert (false, ExcNotImplemented());
+           return std::make_pair (-1, deal_II_numbers::invalid_unsigned_int);
+         }
+      }
+    else
+      return std::make_pair (-1, deal_II_numbers::invalid_unsigned_int);
+  }
+
   
 
   double
index 588c9ca2522bc05937d52b2283b380bf1bb2b742..f2d69ff5c3697bfb8868af672ef7e8ff67dec5c4 100644 (file)
@@ -15,6 +15,7 @@
 #include <base/quadrature_lib.h>
 #include <base/qprojector.h>
 #include <base/logstream.h>
+#include <base/utilities.h>
 #include <lac/full_matrix.h>
 #include <lac/householder.h>
 #include <lac/vector.h>
@@ -111,79 +112,6 @@ namespace
     interpolation_matrix = tmp;
   }
 
-                                  // return true if the given pattern
-                                  // string matches the given name at
-                                  // the first position of the string
-  inline
-  bool
-  match_at_string_start (const std::string &name,
-                        const std::string &pattern)
-  {
-    if (pattern.size() > name.size())
-      return false;
-
-    for (unsigned int i=0; i<pattern.size(); ++i)
-      if (pattern[i] != name[i])
-       return false;
-
-    return true;
-  }
-
-
-
-                                  // read an integer at the position
-                                  // in "name" indicated by the
-                                  // second argument, and retun this
-                                  // integer together with how many
-                                  // characters it takes in the
-                                  // string
-                                  //
-                                  // if no integer can be read at the
-                                  // indicated position, return
-                                  // (-1,-1)
-  inline
-  std::pair<int, unsigned int>
-  get_integer (const std::string &name,
-              const unsigned int position)
-  {
-    Assert (position < name.size(), ExcInternalError());
-    
-    const std::string test_string (name.begin()+position,
-                                  name.end());
-    
-#ifdef HAVE_STD_STRINGSTREAM
-    std::istringstream str(test_string);
-#else
-    std::istrstream str(test_string.c_str());
-#endif
-
-    int i;
-    if (str >> i)
-      {
-                                        // compute the number of
-                                        // digits of i. assuming it
-                                        // is less than 6 is likely
-                                        // ok
-       if (i<10)
-         return std::make_pair (i, 1U);
-       else if (i<100)
-         return std::make_pair (i, 2U);
-       else if (i<1000)
-         return std::make_pair (i, 3U);
-       else if (i<10000)
-         return std::make_pair (i, 4U);
-       else if (i<100000)
-         return std::make_pair (i, 5U);
-       else
-         {
-           Assert (false, ExcNotImplemented());
-           return std::make_pair (-1, deal_II_numbers::invalid_unsigned_int);
-         }
-      }
-    else
-      return std::make_pair (-1, deal_II_numbers::invalid_unsigned_int);
-  }
-
 
 
                                   // return how many characters
@@ -1343,7 +1271,7 @@ FETools::get_fe_from_name_aux (const std::string &name)
                                   // make sure we don't match FE_Q
                                   // when it's actually a
                                   // FE_Q_Hierarchic
-  if (match_at_string_start (name, std::string("FE_Q_Hierarchical")))
+  if (Utilities::match_at_string_start (name, std::string("FE_Q_Hierarchical")))
     {
       unsigned int position = std::string("FE_Q_Hierarchical").size();
                                       // as described in the
@@ -1364,7 +1292,8 @@ FETools::get_fe_from_name_aux (const std::string &name)
       ++position;
                                       // next thing is to parse the
                                       // degree of the finite element
-      const std::pair<int,unsigned int> tmp = get_integer (name, position);
+      const std::pair<int,unsigned int> tmp
+       = Utilities::get_integer_at_position (name, position);
       AssertThrow (tmp.first>=0, ExcInvalidFEName(name));
       position += tmp.second;
 
@@ -1383,13 +1312,16 @@ FETools::get_fe_from_name_aux (const std::string &name)
     }
                                   // check other possibilities in
                                   // exactly the same way
-  else if (match_at_string_start (name, std::string("FE_RaviartThomas")))
+  else if (Utilities::match_at_string_start (name, std::string("FE_RaviartThomas")))
     {
       unsigned int position = std::string("FE_RaviartThomas").size();
       position += match_dimension<dim> (name, position);
       AssertThrow (name[position] == '(', ExcInvalidFEName(name));
       ++position;
-      const std::pair<int,unsigned int> tmp = get_integer (name, position);
+
+      const std::pair<int,unsigned int> tmp
+       = Utilities::get_integer_at_position (name, position);
+
       AssertThrow (tmp.first>=0, ExcInvalidFEName(name));
       position += tmp.second;
       AssertThrow (name[position] == ')', ExcInvalidFEName(name));
@@ -1398,13 +1330,16 @@ FETools::get_fe_from_name_aux (const std::string &name)
                             (new FE_RaviartThomas<dim>(tmp.first)),
                             position);
     }
-  else if (match_at_string_start (name, std::string("FE_Nedelec")))
+  else if (Utilities::match_at_string_start (name, std::string("FE_Nedelec")))
     {
       unsigned int position = std::string("FE_Nedelec").size();
       position += match_dimension<dim> (name, position);
       AssertThrow (name[position] == '(', ExcInvalidFEName(name));
       ++position;
-      const std::pair<int,unsigned int> tmp = get_integer (name, position);
+
+      const std::pair<int,unsigned int> tmp
+       = Utilities::get_integer_at_position (name, position);
+      
       AssertThrow (tmp.first>=0, ExcInvalidFEName(name));
       position += tmp.second;
       AssertThrow (name[position] == ')', ExcInvalidFEName(name));
@@ -1413,13 +1348,16 @@ FETools::get_fe_from_name_aux (const std::string &name)
                             (new FE_Nedelec<dim>(tmp.first)),
                             position);
     }
-  else if (match_at_string_start (name, std::string("FE_DGPNonparametric")))
+  else if (Utilities::match_at_string_start (name, std::string("FE_DGPNonparametric")))
     {
       unsigned int position = std::string("FE_DGPNonparametric").size();
       position += match_dimension<dim> (name, position);
       AssertThrow (name[position] == '(', ExcInvalidFEName(name));
       ++position;
-      const std::pair<int,unsigned int> tmp = get_integer (name, position);
+
+      const std::pair<int,unsigned int> tmp
+       = Utilities::get_integer_at_position (name, position);
+      
       AssertThrow (tmp.first>=0, ExcInvalidFEName(name));
       position += tmp.second;
       AssertThrow (name[position] == ')', ExcInvalidFEName(name));
@@ -1428,13 +1366,16 @@ FETools::get_fe_from_name_aux (const std::string &name)
                             (new FE_DGPNonparametric<dim>(tmp.first)),
                             position);
     }
-  else if (match_at_string_start (name, std::string("FE_DGP")))
+  else if (Utilities::match_at_string_start (name, std::string("FE_DGP")))
     {
       unsigned int position = std::string("FE_DGP").size();
       position += match_dimension<dim> (name, position);
       AssertThrow (name[position] == '(', ExcInvalidFEName(name));
       ++position;
-      const std::pair<int,unsigned int> tmp = get_integer (name, position);
+
+      const std::pair<int,unsigned int> tmp
+       = Utilities::get_integer_at_position (name, position);
+      
       AssertThrow (tmp.first>=0, ExcInvalidFEName(name));
       position += tmp.second;
       AssertThrow (name[position] == ')', ExcInvalidFEName(name));
@@ -1442,13 +1383,16 @@ FETools::get_fe_from_name_aux (const std::string &name)
       return std::make_pair (static_cast<FiniteElement<dim>*>(new FE_DGP<dim>(tmp.first)),
                             position);
     }
-  else if (match_at_string_start (name, std::string("FE_DGQ")))
+  else if (Utilities::match_at_string_start (name, std::string("FE_DGQ")))
     {
       unsigned int position = std::string("FE_DGQ").size();
       position += match_dimension<dim> (name, position);
       AssertThrow (name[position] == '(', ExcInvalidFEName(name));
       ++position;
-      const std::pair<int,unsigned int> tmp = get_integer (name, position);
+
+      const std::pair<int,unsigned int> tmp
+       = Utilities::get_integer_at_position (name, position);
+      
       AssertThrow (tmp.first>=0, ExcInvalidFEName(name));
       position += tmp.second;
       AssertThrow (name[position] == ')', ExcInvalidFEName(name));
@@ -1456,13 +1400,16 @@ FETools::get_fe_from_name_aux (const std::string &name)
       return std::make_pair (static_cast<FiniteElement<dim>*> (new FE_DGQ<dim>(tmp.first)),
                             position);
     }
-  else if (match_at_string_start (name, std::string("FE_Q")))
+  else if (Utilities::match_at_string_start (name, std::string("FE_Q")))
     {
       unsigned int position = std::string("FE_Q").size();
       position += match_dimension<dim> (name, position);
       AssertThrow (name[position] == '(', ExcInvalidFEName(name));
       ++position;
-      const std::pair<int,unsigned int> tmp = get_integer (name, position);
+
+      const std::pair<int,unsigned int> tmp
+       = Utilities::get_integer_at_position (name, position);
+      
       AssertThrow (tmp.first>=0, ExcInvalidFEName(name));
       position += tmp.second;
       AssertThrow (name[position] == ')', ExcInvalidFEName(name));
@@ -1478,7 +1425,7 @@ FETools::get_fe_from_name_aux (const std::string &name)
                                     // have to figure out what the
                                     // base elements are. this can
                                     // only be done recursively
-    if (match_at_string_start (name, std::string("FESystem")))
+    if (Utilities::match_at_string_start (name, std::string("FESystem")))
       {
        unsigned int position = std::string("FESystem").size();
        position += match_dimension<dim> (name, position);
@@ -1531,8 +1478,10 @@ FETools::get_fe_from_name_aux (const std::string &name)
                                                     // and read this
                                                     // multiplicity
                    ++position;
-                   const std::pair<int,unsigned int> tmp = get_integer (name,
-                                                                        position);
+
+                   const std::pair<int,unsigned int> tmp
+                     = Utilities::get_integer_at_position (name, position);
+                   
                    AssertThrow (tmp.first>=0, ExcInvalidFEName(name));
                    position += tmp.second;
                    base_multiplicities.push_back (tmp.first);
index 7731b131a8755261620a99a4dbf2c961b4278baf..8fc34c6c7749ba013a61e9e7b527204e70c7d99a 100644 (file)
@@ -150,6 +150,14 @@ inconvenience this causes.
 <h3>base</h3>
 
 <ol>
+  <li> <p>
+       New: There are new functions
+       <code>Utilities::match_at_string_start</code> and 
+       <code>Utilities::get_integer_at_position</code>.
+       <br>
+       (WB 2005/12/19)
+       </p>
+
   <li> <p>
        Fixed: The computation of <code>HMIN</code> and
        <code>HMAX</code> in <code

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.