Intrepid
http://trilinos.sandia.gov/packages/docs/r10.12/packages/intrepid/src/Discretization/Integration/Intrepid_CubaturePolylibDef.hpp
Go to the documentation of this file.
00001 // @HEADER
00002 // ************************************************************************
00003 //
00004 //                           Intrepid Package
00005 //                 Copyright (2007) Sandia Corporation
00006 //
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Pavel Bochev  (pbboche@sandia.gov)
00038 //                    Denis Ridzal  (dridzal@sandia.gov), or
00039 //                    Kara Peterson (kjpeter@sandia.gov)
00040 //
00041 // ************************************************************************
00042 // @HEADER
00043 
00049 namespace Intrepid {
00050 
00051 template <class Scalar, class ArrayPoint, class ArrayWeight>
00052 CubaturePolylib<Scalar,ArrayPoint,ArrayWeight>::CubaturePolylib(int degree, EIntrepidPLPoly poly_type, Scalar alpha, Scalar beta) {
00053   TEUCHOS_TEST_FOR_EXCEPTION((degree < 0),
00054                      std::out_of_range,
00055                      ">>> ERROR (CubaturePolylib): No cubature rule implemented for the desired polynomial degree.");
00056   degree_    = degree;
00057   dimension_ = 1;
00058   poly_type_ = poly_type;
00059   alpha_     = alpha;
00060   beta_      = beta;
00061 } // end constructor
00062 
00063 
00064 
00065 template <class Scalar, class ArrayPoint, class ArrayWeight>
00066 const char* CubaturePolylib<Scalar,ArrayPoint,ArrayWeight>::getName() const {
00067   return cubature_name_;
00068 } // end getName
00069 
00070 
00071 
00072 template <class Scalar, class ArrayPoint, class ArrayWeight>
00073 int CubaturePolylib<Scalar,ArrayPoint,ArrayWeight>::getDimension() const {
00074   return dimension_;
00075 } // end dimension
00076 
00077 
00078 
00079 template <class Scalar, class ArrayPoint, class ArrayWeight>
00080 int CubaturePolylib<Scalar,ArrayPoint,ArrayWeight>::getNumPoints() const {
00081   int np = 0;
00082   switch (poly_type_) {
00083     case PL_GAUSS:
00084       np = (degree_+(int)2)/(int)2;
00085       break;
00086     case PL_GAUSS_RADAU_LEFT:
00087     case PL_GAUSS_RADAU_RIGHT:
00088       if (degree_ == 0)
00089         np = 2;
00090       else
00091         np = (degree_+(int)3)/(int)2;
00092       break;
00093     case PL_GAUSS_LOBATTO:
00094       np = (degree_+(int)4)/(int)2;
00095       break;
00096     default:
00097       TEUCHOS_TEST_FOR_EXCEPTION((1),
00098                          std::invalid_argument,
00099                          ">>> ERROR (CubaturePolylib): Unknown point type argument.");
00100   }
00101   return np;
00102 } // end getNumPoints
00103 
00104 
00105 
00106 template <class Scalar, class ArrayPoint, class ArrayWeight>
00107 void CubaturePolylib<Scalar,ArrayPoint,ArrayWeight>::getAccuracy(std::vector<int> & accuracy) const {
00108   accuracy.assign(1, degree_);
00109 } // end getAccuracy
00110 
00111 
00112 
00113 template <class Scalar, class ArrayPoint, class ArrayWeight>
00114 const char* CubaturePolylib<Scalar,ArrayPoint,ArrayWeight>::cubature_name_ = "INTREPID_CUBATURE_POLYLIB";
00115 
00116 
00117 
00118 template <class Scalar, class ArrayPoint, class ArrayWeight>
00119 void CubaturePolylib<Scalar,ArrayPoint,ArrayWeight>::getCubature(ArrayPoint & cubPoints, ArrayWeight & cubWeights) const {
00120   int numCubPoints = getNumPoints();
00121   int cellDim      = getDimension();
00122   // check size of cubPoints and cubWeights
00123   TEUCHOS_TEST_FOR_EXCEPTION( ( ( (int)cubPoints.size() < numCubPoints*cellDim ) || ( (int)cubWeights.size() < numCubPoints ) ),
00124                       std::out_of_range,
00125                       ">>> ERROR (CubatureDirect): Insufficient space allocated for cubature points or weights.");
00126 
00127   // temporary storage
00128   FieldContainer<Scalar> z(numCubPoints);
00129   FieldContainer<Scalar> w(numCubPoints);
00130 
00131   // run Polylib routines
00132   switch (poly_type_) {
00133     case PL_GAUSS:
00134       IntrepidPolylib::zwgj(&z[0], &w[0], numCubPoints, alpha_, beta_);
00135       break;
00136     case PL_GAUSS_RADAU_LEFT:
00137       IntrepidPolylib::zwgrjm(&z[0], &w[0], numCubPoints, alpha_, beta_);
00138       break;
00139     case PL_GAUSS_RADAU_RIGHT:
00140       IntrepidPolylib::zwgrjp(&z[0], &w[0], numCubPoints, alpha_, beta_);
00141       break;
00142     case PL_GAUSS_LOBATTO:
00143       IntrepidPolylib::zwglj(&z[0], &w[0], numCubPoints, alpha_, beta_);
00144       break;
00145     default:
00146       TEUCHOS_TEST_FOR_EXCEPTION((1),
00147                          std::invalid_argument,
00148                          ">>> ERROR (CubaturePolylib): Unknown point type argument.");
00149   }
00150 
00151   // fill input arrays
00152   for (int pointId = 0; pointId < numCubPoints; pointId++) {
00153     for (int dim = 0; dim < cellDim; dim++) {
00154       cubPoints(pointId,dim) = z[pointId];
00155     }
00156     cubWeights(pointId) = w[pointId];
00157   }
00158 } // end getCubature
00159 
00160 
00161 } // end namespace Intrepid