]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
New class by Ralf Schulz.
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 29 Oct 2003 15:40:05 +0000 (15:40 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 29 Oct 2003 15:40:05 +0000 (15:40 +0000)
git-svn-id: https://svn.dealii.org/trunk@8171 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/quadrature_selector.h [new file with mode: 0644]
deal.II/base/source/quadrature_selector.cc [new file with mode: 0644]
deal.II/doc/news/c-4-0.html

diff --git a/deal.II/base/include/base/quadrature_selector.h b/deal.II/base/include/base/quadrature_selector.h
new file mode 100644 (file)
index 0000000..2214c39
--- /dev/null
@@ -0,0 +1,100 @@
+//----------------------------  quadrature_selector.h  ---------------------------
+//    $Id$
+//    Version: $Name$
+//
+//    Copyright (C) 2003 by the deal authors
+//
+//    This file is subject to QPL and may not be  distributed
+//    without copyright and license information. Please refer
+//    to the file deal.II/doc/license.html for the  text  and
+//    further information on this license.
+//
+//----------------------------  quadrature_selector.h  ---------------------------
+
+#ifndef __deal2__quadrature_selector_h
+#define __deal2__quadrature_selector_h
+
+
+#include <base/quadrature.h>
+#include <base/exceptions.h>
+
+
+/**
+ * This class implements the quadrature rule passed to its constructor
+ * as a string. Supported quadratures are @ref{QGauss} (of all
+ * orders), @ref{QMidpoint}, @ref{QMilne}, @ref{QSimpson},
+ * @ref{QTrapez} and @ref{QWeddle}.
+ *
+ * This class is useful if you want to use flexible quadrature rules,
+ * that are read from a parameter file (see @ref{ParameterHandler} for
+ * this).
+ * 
+ * @author Ralf Schulz, 2003
+ */
+
+template<int dim>
+class QuadratureSelector : public Quadrature<dim>
+{
+  public:
+                                    /**
+                                     * Constructor. Takes the name of
+                                     * the quadrature rule (one of
+                                     * "gauss", "milne", "weddle",
+                                     * etc) and, if it iss "gauss",
+                                     * the order of the quadrature
+                                     * rule as argument.
+                                     */
+    QuadratureSelector (const std::string &s,
+                       const unsigned int order=0);
+
+                                    /**
+                                     * This function returns all
+                                     * possible names for quadratures
+                                     * as a list separated by @p{|},
+                                     * so that you can use it for the
+                                     * definition of parameter files
+                                     * (see @ref{ParameterHandler} for
+                                     * details).
+                                     */
+    static std::string get_quadrature_names();
+    
+                                    /**
+                                     * Exception
+                                     */
+    DeclException1 (ExcInvalidQGaussOrder,
+                   int,
+                   << "You tried to generate QGauss with an invalid order of "
+                   << arg1 << " (must be >= 2)");
+                                    /**
+                                     * Exception
+                                     */
+    DeclException2 (ExcInvalidOrder,
+                   std::string,
+                   unsigned int,
+                   << "You tried to generate a " << arg1
+                   << " object; no order is needed (" << arg2
+                   << " was given as parameter)");
+                                    /**
+                                     * Exception
+                                     */
+    DeclException1 (ExcInvalidQuadrature,
+                   std::string,
+                   << arg1
+                   << " is not a valid quadrature name for a quadrature rule");
+
+  private:
+                                    /**
+                                     * This static function creates a
+                                     * quadrature object according to
+                                     * the name given as a string,
+                                     * and the appropriate order (if
+                                     * the name is "gauss"). It is
+                                     * called from the constructor.
+                                     */
+    static
+    Quadrature<dim>
+    create_quadrature (const std::string &s,
+                      const unsigned int order);
+};
+
+#endif
diff --git a/deal.II/base/source/quadrature_selector.cc b/deal.II/base/source/quadrature_selector.cc
new file mode 100644 (file)
index 0000000..8b51d9e
--- /dev/null
@@ -0,0 +1,83 @@
+//----------------------------  quadrature_selector.cc  ---------------------------
+//    $Id$
+//    Version: $Name$
+//
+//    Copyright (C) 2003 by the deal authors
+//
+//    This file is subject to QPL and may not be  distributed
+//    without copyright and license information. Please refer
+//    to the file deal.II/doc/license.html for the  text  and
+//    further information on this license.
+//
+//----------------------------  quadrature_selector.cc  ---------------------------
+
+
+#include <base/quadrature_selector.h>
+#include <base/quadrature_lib.h>
+
+
+template <int dim>
+Quadrature<dim>
+QuadratureSelector<dim>::
+create_quadrature (const std::string &s,
+                  const unsigned int order)
+{
+  if(s == "gauss")
+    {
+      AssertThrow(order >= 2, ExcInvalidQGaussOrder(order));
+      switch(order)
+       {
+         case  2: return QGauss2<dim>();
+         case  3: return QGauss3<dim>();
+         case  4: return QGauss4<dim>();
+         case  5: return QGauss5<dim>();
+         case  6: return QGauss6<dim>();
+         case  7: return QGauss7<dim>();
+         default: return QGauss<dim>(order);
+       }
+    }
+  else
+    {
+      AssertThrow(order == 0, ExcInvalidOrder(s, order));
+
+      if (s == "midpoint")        return QMidpoint<dim>();
+      else if (s == "milne")      return QMilne<dim>();
+      else if (s == "simpson")    return QSimpson<dim>();
+      else if (s == "trapez")     return QTrapez<dim>();
+      else if (s == "weddle")     return QWeddle<dim>();
+    }
+
+                                  // we didn't find this name
+  AssertThrow (false, ExcInvalidQuadrature(s));
+                                  // return something to suppress
+                                  // stupid warnings by some
+                                  // compilers
+  return QGauss2<dim>();
+}
+
+
+
+template <int dim>
+QuadratureSelector<dim>::QuadratureSelector (const std::string &s,
+                                            const unsigned int order)
+               :
+               Quadrature<dim> (create_quadrature(s, order).get_points(),
+                                create_quadrature(s, order).get_weights())
+{ 
+}
+
+
+
+template <int dim>
+std::string
+QuadratureSelector<dim>::get_quadrature_names()
+{
+  return std::string("gauss|midpoint|milne|simpson|trapez|weddle");
+}
+
+
+
+// explicit instantiations
+template class QuadratureSelector<1>;
+template class QuadratureSelector<2>;
+template class QuadratureSelector<3>;
index 3b9814d2816ede6062f26f1cafe819c012358a4b..7910f9710283e7ea63b2ab422aa966982a96daa0 100644 (file)
@@ -172,6 +172,14 @@ contributor's names are abbreviated by WB (Wolfgang Bangerth), GK
 <h3>base</h3>
 
 <ol>
+  <li> <p> New: There is now a class <code
+       class="class">QuadratureSelector</code> that allows to select a
+       quadrature formula based on a string argument and possibly a
+       number indicating the order of the formula.
+       <br>
+       (Ralf B. Schulz 2002/10/29)
+       </p>
+
   <li> <p> Fixed: The constructor of the <code class="class">QGauss</code> class
        computed positions and weights of quadrature points in long double accuracy.
        However, on machines where long double is the same as double, it therefore
@@ -289,7 +297,7 @@ contributor's names are abbreviated by WB (Wolfgang Bangerth), GK
 <ol>
   <li> <p>
        Changed: The <code
-<        class="member">SolutionTransfer::interpolate</code>      
+       <class="member">SolutionTransfer::interpolate</code>      
        <br>
        (Brent Bailey, WB 2003/10/22 and RH 2003/10/24)
        </p>

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.