SundanceGaussLobattoQuadrature.hpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                             Sundance
00005 //                 Copyright 2011 Sandia Corporation
00006 // 
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00008 // the U.S. Government retains certain rights in this software.
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 Kevin Long (kevin.long@ttu.edu)
00038 // 
00039 
00040 /* @HEADER@ */
00041 
00042 
00043 /*
00044  * SundanceGaussLobattoQuadrature.hpp
00045  *
00046  *  Created on: Jan 20, 2011
00047  *      Author: benk
00048  */
00049 
00050 #ifndef SUNDANCEGAUSSLOBATTOQUADRATURE_HPP_
00051 #define SUNDANCEGAUSSLOBATTOQUADRATURE_HPP_
00052 
00053 #include "SundanceDefs.hpp"
00054 #include "PlayaTabs.hpp"
00055 #include "SundanceQuadratureFamilyBase.hpp"
00056 
00057 namespace Sundance {
00058 
00059 class GaussLobattoQuadrature : public QuadratureFamilyBase {
00060 
00061 public:
00062 
00063   /** In this case the */
00064   GaussLobattoQuadrature(int order);
00065 
00066   /** */
00067   virtual ~GaussLobattoQuadrature()
00068   {;}
00069 
00070   /** */
00071   virtual XMLObject toXML() const;
00072 
00073   /** Describable interface */
00074   virtual std::string description() const
00075   {
00076     return "GaussLobattoQuadrature[order=" + Teuchos::toString(order()) + "]";
00077   }
00078 
00079   /* handleable boilerplate */
00080   GET_RCP(QuadratureFamilyStub);
00081 
00082 protected:
00083   /** compute a rule for the reference line cell */
00084   virtual void getLineRule(Array<Point>& quadPointsL,
00085       Array<double>& quadWeights) const;
00086 
00087   /** compute a rule for the reference triangle cell */
00088   virtual void getTriangleRule(Array<Point>& quadPoints,
00089       Array<double>& quadWeights) const;
00090 
00091   /** compute a rule for the reference quad cell */
00092   virtual void getQuadRule(Array<Point>& quadPoints,
00093       Array<double>& quadWeights) const;
00094 
00095   /** compute a rule for the reference tet cell */
00096   virtual void getTetRule(Array<Point>& quadPoints,
00097       Array<double>& quadWeights) const ;
00098 
00099   /** compute a rule for the reference brick cell */
00100   virtual void getBrickRule(Array<Point>& quadPoints,
00101       Array<double>& quadWeights) const;
00102 
00103   /**
00104    * Compute adapted weights according to curve
00105    *
00106    * @param cellType
00107    * @param cellDim
00108    * @param cellLID
00109    * @param facetIndex
00110    * @param mesh
00111    * @param globalCurve
00112    * @param quadPoints
00113    * @param quadWeights
00114    * @param changedWeights
00115    */
00116   virtual void getAdaptedWeights(const CellType& cellType, int cellDim,
00117       int cellLID, int facetIndex, const Mesh& mesh,
00118       const ParametrizedCurve& globalCurve,
00119       Array<Point>& quadPoints, Array<double>& quadWeights,
00120       bool &weightsChanged) const;
00121 
00122   /** Get the weights for one quad */
00123   virtual void getAdaptedQuadWeights(int cellLID, const Mesh& mesh,
00124       const ParametrizedCurve& globalCurve, Array<Point>& quadPoints,
00125       Array<double>& quadWeights, bool& weightsChanged) const;
00126 
00127   /** Get the weights for one quad knowing that the curve is a 2D polygon */
00128   virtual void getAdaptedQuadWeights_polygon(int cellLID, const Mesh& mesh,
00129       const ParametrizedCurve& globalCurve, Array<Point>& quadPoints,
00130       Array<double>& quadWeights, bool& weightsChanged) const;
00131 
00132   /** Get the weights for one quad knowing that the curve is a 3D surface */
00133   virtual void getAdaptedQuadWeights_surf(int cellLID, const Mesh& mesh,
00134       const ParametrizedCurve& globalCurve, Array<Point>& quadPoints,
00135       Array<double>& quadWeights, bool& weightsChanged) const;
00136 
00137 private:
00138 
00139   /** get the triangle quadrature points for the adaptive integration*/
00140   void getTriangleQuadPoints(Array<Point>& pnt , Array<double>& weight ) const;
00141 
00142   /**
00143    * @param i , the i-th point
00144    * @param pnt 1D points where we interpolate
00145    * @param x the position where we evaluate */
00146   inline double evalLagrangePol(int i , Array<Point>& pnt , double x) const{
00147     int m = pnt.size();
00148     double p = 1.0;
00149     for (int j = 0 ; (j <= i-1)&&(j<m) ; j++){
00150      p = p *( x - pnt[j][0] )/(pnt[i][0] - pnt[j][0]);
00151     }
00152     for (int j = i+1 ; j < m ; j++){
00153      p = p *( x - pnt[j][0] )/(pnt[i][0] - pnt[j][0]);
00154     }
00155       return p;
00156   }
00157 
00158   /** this function applies quadrature to the Lagrange functions <br>
00159    * all the coordinates are in the reference coordinates */
00160   inline void makeInterpolantQuad( double px, double py, double ofx, double ofy,
00161                                int nr1DPoints , int nr2DPoints ,
00162                                Array<Point>& linePoints ,
00163                                Array<Point>& quadPoints ,
00164                                Array<double>& pointWeights ,
00165                                Array<double>& weightsOut ,
00166                                double areFakt ) const {
00167     int xi,yi;
00168     double xc,yc, intR , valTmp , valBasisX , valBasisY ;
00169 
00170         //SUNDANCE_MSG3(verb_, "px="<<px<<",py="<<py<<",ofx="<<ofx<<",ofy="<<ofy <<
00171         //    " , nr2DPoints:" << nr2DPoints << " , pointWeights.size():" <<
00172         //    pointWeights.size() << " , areFakt:" << areFakt);
00173 
00174     // if the area of integration is not significant then just return
00175     if ( fabs(ofx*ofy) < 1e-14 ) {
00176       //SUNDANCE_MSG3(verb_, "return");
00177       return;
00178     }
00179 
00180     for (int i = 0 ; i < nr2DPoints ; i++){
00181       // we should add the integration values, and we not set the values //weightsOut[i] = 0.0;
00182       yi = i % nr1DPoints; xi = i / nr1DPoints; intR = 0.0;
00183       // for each quadrature point
00184       for (int q = 0 ; q < pointWeights.size() ; q++){
00185         xc = px + quadPoints[q][0]*ofx;
00186         yc = py + quadPoints[q][1]*ofy;
00187         valBasisX = evalLagrangePol(xi , linePoints , xc);
00188         valBasisY = evalLagrangePol(yi , linePoints , yc);
00189         valTmp = pointWeights[q] * ( valBasisX *  valBasisY);
00190         intR = intR + valTmp;
00191         //SUNDANCE_MSG3(verb_, "i="<<i<< " , valBasisX=" << valBasisX  << " , valBasisY=" << valBasisY << " , valBasis="
00192         //    << valBasisX*valBasisY <<" , val=" << valTmp*::fabs(ofx*ofy/areFakt) );
00193         //SUNDANCE_MSG3(verb_, "i="<<i<<",xi="<<xi<<",yi="<<yi<<",q="<<q<<",xc="<<xc<<",yc="<<yc<<
00194         //    ",pointWeights[q]=" << pointWeights[q]);
00195       }
00196       intR = intR * ::fabs(ofx*ofy/areFakt);
00197       weightsOut[i] = weightsOut[i] + intR;
00198     }
00199   }
00200 
00201 
00202   /** this function applies quadrature to the Lagrange functions <br>
00203    * all the coordinates are in the reference coordinates */
00204   inline void makeInterpolantBrick(int nr1DPoints , int nr3DPoints ,
00205                                Array<Point>& linePoints ,
00206                                Array<Point>& quadPoints ,
00207                                Array<double>& pointWeights ,
00208                                Array<double>& weightsOut ,
00209                                double areFakt ) const {
00210     int xi,yi,zi;
00211     double xc,yc,zc, intR , valTmp , valBasisX , valBasisY , valBasisZ;
00212 
00213     for (int i = 0 ; i < nr3DPoints ; i++){
00214       zi = i/(nr1DPoints*nr1DPoints); yi = (i%(nr1DPoints*nr1DPoints)) / nr1DPoints;
00215       xi = (i%(nr1DPoints*nr1DPoints)) % nr1DPoints; intR = 0.0;
00216       // for each quadrature point
00217       for (int q = 0 ; q < pointWeights.size() ; q++){
00218         xc = quadPoints[q][0]; yc = quadPoints[q][1]; zc = quadPoints[q][2];
00219         valBasisX = evalLagrangePol(xi , linePoints , xc);
00220         valBasisY = evalLagrangePol(yi , linePoints , yc);
00221         valBasisZ = evalLagrangePol(zi , linePoints , zc);
00222         valTmp = pointWeights[q] * ( valBasisX * valBasisY * valBasisZ );
00223         intR = intR + valTmp;
00224         //SUNDANCE_MSG3(4, "i="<<i<< " , valBasisX=" << valBasisX  << " , valBasisY=" << valBasisY << " , valBasisZ=" << valBasisZ <<
00225         //    " , valBasis=" << valBasisX*valBasisY <<" , val=" << valTmp );
00226         //SUNDANCE_MSG3(4, "i="<<i<<",xi="<<xi<<",yi="<<yi<<",q="<<q<<",xc="<<xc<<",yc="<<yc<<",zc="<<zc<<
00227         //    ",pointWeights["<<q<<"]=" << pointWeights[q]);
00228       }
00229       intR = intR * areFakt ;
00230       weightsOut[i] = weightsOut[i] + intR;
00231     }
00232   }
00233 
00234 
00235 
00236   /** nr of points in 1D, the rest should be tensor product */
00237   int nrPointin1D_;
00238 
00239   /** the verbosity of the object*/
00240   int verb_;
00241 
00242   static const int quadsEdgesPoints[4][2];
00243 
00244   /** qvasi information for the 3D cut-cell integral*/
00245   static const int edge3DProjection[12];
00246 };
00247 
00248 }
00249 
00250 #endif /* SUNDANCEGAUSSLOBATTOQUADRATURE_HPP_ */

Site Contact