From e77ccf875bc1a7d7ee172e42feef800cb3a9facc Mon Sep 17 00:00:00 2001 From: wolf Date: Wed, 29 Oct 2003 15:40:05 +0000 Subject: [PATCH] New class by Ralf Schulz. git-svn-id: https://svn.dealii.org/trunk@8171 0785d39b-7218-0410-832d-ea1e28bc413d --- .../base/include/base/quadrature_selector.h | 100 ++++++++++++++++++ deal.II/base/source/quadrature_selector.cc | 83 +++++++++++++++ deal.II/doc/news/c-4-0.html | 10 +- 3 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 deal.II/base/include/base/quadrature_selector.h create mode 100644 deal.II/base/source/quadrature_selector.cc diff --git a/deal.II/base/include/base/quadrature_selector.h b/deal.II/base/include/base/quadrature_selector.h new file mode 100644 index 0000000000..2214c39fec --- /dev/null +++ b/deal.II/base/include/base/quadrature_selector.h @@ -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 +#include + + +/** + * 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 +class QuadratureSelector : public Quadrature +{ + 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 + 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 index 0000000000..8b51d9ec0d --- /dev/null +++ b/deal.II/base/source/quadrature_selector.cc @@ -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 +#include + + +template +Quadrature +QuadratureSelector:: +create_quadrature (const std::string &s, + const unsigned int order) +{ + if(s == "gauss") + { + AssertThrow(order >= 2, ExcInvalidQGaussOrder(order)); + switch(order) + { + case 2: return QGauss2(); + case 3: return QGauss3(); + case 4: return QGauss4(); + case 5: return QGauss5(); + case 6: return QGauss6(); + case 7: return QGauss7(); + default: return QGauss(order); + } + } + else + { + AssertThrow(order == 0, ExcInvalidOrder(s, order)); + + if (s == "midpoint") return QMidpoint(); + else if (s == "milne") return QMilne(); + else if (s == "simpson") return QSimpson(); + else if (s == "trapez") return QTrapez(); + else if (s == "weddle") return QWeddle(); + } + + // we didn't find this name + AssertThrow (false, ExcInvalidQuadrature(s)); + // return something to suppress + // stupid warnings by some + // compilers + return QGauss2(); +} + + + +template +QuadratureSelector::QuadratureSelector (const std::string &s, + const unsigned int order) + : + Quadrature (create_quadrature(s, order).get_points(), + create_quadrature(s, order).get_weights()) +{ +} + + + +template +std::string +QuadratureSelector::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>; diff --git a/deal.II/doc/news/c-4-0.html b/deal.II/doc/news/c-4-0.html index 3b9814d281..7910f97102 100644 --- a/deal.II/doc/news/c-4-0.html +++ b/deal.II/doc/news/c-4-0.html @@ -172,6 +172,14 @@ contributor's names are abbreviated by WB (Wolfgang Bangerth), GK

base

    +
  1. New: There is now a class QuadratureSelector that allows to select a + quadrature formula based on a string argument and possibly a + number indicating the order of the formula. +
    + (Ralf B. Schulz 2002/10/29) +

    +
  2. Fixed: The constructor of the QGauss 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

    1. Changed: The SolutionTransfer::interpolate + SolutionTransfer::interpolate
      (Brent Bailey, WB 2003/10/22 and RH 2003/10/24)

      -- 2.39.5