SundanceQuadratureFamily.cpp
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 #include "SundanceQuadratureFamily.hpp"
00044 #include "PlayaTabs.hpp"
00045 
00046 using namespace Sundance;
00047 using namespace Teuchos;
00048 using Playa::Handle;
00049 using Playa::Handleable;
00050 using std::ios_base;
00051 using std::setw;
00052 using std::endl;
00053 using std::setprecision;
00054 
00055 int QuadratureFamily::getNumPoints( const CellType & cellType ) const
00056 {
00057   const QuadratureFamilyBase* q 
00058     = dynamic_cast<const QuadratureFamilyBase*>(ptr().get());
00059   return q->getNumPoints( cellType );
00060 }
00061 
00062 void QuadratureFamily::getPoints(const CellType& cellType, 
00063                                  Array<Point>& quadPoints,
00064                                  Array<double>& quadWeights) const 
00065 {
00066   const QuadratureFamilyBase* q 
00067     = dynamic_cast<const QuadratureFamilyBase*>(ptr().get());
00068   
00069   TEUCHOS_TEST_FOR_EXCEPTION(q==0, std::logic_error, 
00070                      "QuadratureFamilyStub pointer" << toXML().toString() 
00071                      << " could not be cast to a QuadratureFamilyBase ptr");
00072                      
00073   q->getPoints(cellType, quadPoints, quadWeights);
00074 }
00075 
00076 void QuadratureFamily::getAdaptedWeights(const CellType& cellType ,
00077                              int cellDim,
00078                                int celLID ,
00079                              int facetIndex ,
00080                                  const Mesh& mesh ,
00081                                  const ParametrizedCurve& globalCurve ,
00082                                  Array<Point>& quadPoints ,
00083                                  Array<double>& quadWeights ,
00084                                  bool& isCut) const
00085 {
00086 
00087   const QuadratureFamilyBase* q
00088    = dynamic_cast<const QuadratureFamilyBase*>(ptr().get());
00089 
00090   TEUCHOS_TEST_FOR_EXCEPTION(q==0, std::logic_error,
00091                      "QuadratureFamilyStub pointer" << toXML().toString()
00092                       << " could not be cast to a QuadratureFamilyBase ptr");
00093 
00094   q->getAdaptedWeights(cellType, cellDim , celLID , facetIndex ,
00095       mesh , globalCurve , quadPoints, quadWeights , isCut);
00096 
00097 }
00098 
00099 XMLObject QuadratureFamily::toXML() const 
00100 {
00101   return ptr()->toXML();
00102 }
00103 
00104 int QuadratureFamily::order() const 
00105 {
00106   return ptr()->order();
00107 }
00108 
00109 
00110 
00111 void QuadratureFamily::getFacetPoints(const CellType& cellType, 
00112                                       int facetDim,
00113                                       int facetIndex,
00114                                       Array<Point>& quadPoints,
00115                                       Array<double>& quadWeights) const
00116 {
00117   switch(cellType)
00118     {
00119     case LineCell:
00120       getLineFacetQuad(facetDim, facetIndex, quadPoints, quadWeights);
00121       break;
00122     case TriangleCell:
00123       getTriangleFacetQuad(facetDim, facetIndex, quadPoints, quadWeights);
00124       break;
00125     case QuadCell:
00126       getQuadFacetQuad(facetDim, facetIndex, quadPoints, quadWeights);
00127       break;
00128     case TetCell:
00129       getTetFacetQuad(facetDim, facetIndex, quadPoints, quadWeights);
00130       break;
00131     case BrickCell:
00132       getBrickFacetQuad(facetDim, facetIndex, quadPoints, quadWeights);
00133       break;
00134     default:
00135       TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error,
00136                          "getFacetPoints() not implemented for cell type "
00137                          << cellType);
00138     }
00139 }
00140 
00141 
00142 void QuadratureFamily::getLineFacetQuad(int facetDim,
00143                                         int facetIndex,
00144                                         Array<Point>& quadPoints,
00145                                         Array<double>& quadWeights) const
00146 {
00147   TEUCHOS_TEST_FOR_EXCEPTION(facetDim > 0, std::runtime_error,
00148                      "Invalid facet dimension " << facetDim 
00149                      << " in getLineFacetQuad()");
00150   TEUCHOS_TEST_FOR_EXCEPTION(facetIndex < 0 || facetIndex > 1, std::runtime_error,
00151                      "Invalid facet index " << facetIndex  
00152                      << " in getLineFacetQuad()");
00153 
00154   quadPoints.resize(1);
00155   quadWeights.resize(1);
00156   quadWeights[0] = 1.0;  
00157   quadPoints[0] = Point((double) facetIndex);
00158 }
00159 
00160 
00161 
00162 
00163 void QuadratureFamily::getTriangleFacetQuad(int facetDim,
00164                                             int facetIndex,
00165                                             Array<Point>& quadPoints,
00166                                             Array<double>& quadWeights) const
00167 {
00168   TEUCHOS_TEST_FOR_EXCEPTION(facetDim > 1, std::runtime_error,
00169                      "Invalid facet dimension " << facetDim 
00170                      << " in getTriangleFacetQuad()");
00171   TEUCHOS_TEST_FOR_EXCEPTION(facetIndex < 0 || facetIndex > 2, std::runtime_error,
00172                      "Invalid facet index " << facetIndex  
00173                      << " in getTriangleFacetQuad()");
00174   if (facetDim==1)
00175     {
00176       Array<Point> facetPts;
00177       Array<double> facetWts;
00178       getPoints(LineCell, facetPts, facetWts);
00179       quadPoints.resize(facetPts.size());
00180       quadWeights.resize(facetWts.size());
00181       for (int i=0; i<facetPts.size(); i++)
00182         {
00183           if (facetIndex==2)
00184             {
00185               quadPoints[i] = Point(facetPts[i][0], 0.0);
00186               quadWeights[i] = facetWts[i];
00187             }
00188           else if (facetIndex==0)
00189             {
00190               quadPoints[i] = Point(1.0-facetPts[i][0], facetPts[i][0]);
00191               quadWeights[i] = facetWts[i];
00192             }
00193           else
00194             {
00195               quadPoints[i] = Point(0.0, facetPts[i][0]);
00196               quadWeights[i] = facetWts[i];
00197             }
00198         }
00199     }
00200   else
00201     {
00202       quadPoints.resize(1);
00203       quadWeights.resize(1);
00204       quadWeights[0] = 1.0;  
00205       if (facetIndex==0) quadPoints[0] = Point(0.0, 0.0);
00206       else if (facetIndex==1) quadPoints[0] = Point(1.0, 0.0);
00207       else quadPoints[0] = Point(0.0, 1.0);
00208     }
00209 }
00210 
00211 void QuadratureFamily::getQuadFacetQuad(int facetDim,
00212                            int facetIndex,
00213                            Array<Point>& quadPoints,
00214                            Array<double>& quadWeights) const {
00215 
00216     TEUCHOS_TEST_FOR_EXCEPTION(facetDim > 1, std::runtime_error,
00217                        "Invalid facet dimension " << facetDim
00218                        << " in getQuadFacetQuad()");
00219 
00220     TEUCHOS_TEST_FOR_EXCEPTION(facetIndex < 0 || facetIndex > 3, std::runtime_error,
00221                        "Invalid facet index " << facetIndex
00222                        << " in getQuadFacetQuad()");
00223     if (facetDim==1)
00224       {
00225         Array<Point> facetPts;
00226         Array<double> facetWts;
00227         getPoints(LineCell, facetPts, facetWts);
00228         quadPoints.resize(facetPts.size());
00229         quadWeights.resize(facetWts.size());
00230         for (int i=0; i<facetPts.size(); i++)
00231           {
00232             if (facetIndex==0) // the 4 edges of the Quad
00233               {               // Numbering is important, if Edge Numbering in QuadCell changes, change this as well
00234                 quadPoints[i] = Point(facetPts[i][0], 0.0);
00235                 quadWeights[i] = facetWts[i];
00236               }
00237             else if (facetIndex==1)
00238               {
00239                 quadPoints[i] = Point(0.0 , facetPts[i][0]);
00240                 quadWeights[i] = facetWts[i];
00241               }
00242             else if (facetIndex==2)
00243               {
00244                 quadPoints[i] = Point(1.0, facetPts[i][0]);
00245                 quadWeights[i] = facetWts[i];
00246               }
00247             else
00248               {
00249                 quadPoints[i] = Point(facetPts[i][0], 1.0);
00250                 quadWeights[i] = facetWts[i];
00251               }
00252           }
00253       }
00254     else
00255       {
00256         quadPoints.resize(1);
00257         quadWeights.resize(1);
00258         quadWeights[0] = 1.0;
00259         if (facetIndex==0) quadPoints[0] = Point(0.0, 0.0);
00260         else if (facetIndex==1) quadPoints[0] = Point(1.0, 0.0);
00261         else if (facetIndex==2) quadPoints[0] = Point(0.0, 1.0);
00262         else quadPoints[0] = Point(1.0, 1.0);
00263       }
00264 }
00265 
00266 void QuadratureFamily::getTetFacetQuad(int facetDim,
00267                                        int facetIndex,
00268                                        Array<Point>& quadPoints,
00269                                        Array<double>& quadWeights) const
00270 {
00271   TEUCHOS_TEST_FOR_EXCEPTION(facetDim > 2, std::runtime_error,
00272                      "Invalid facet dimension " << facetDim 
00273                      << " in getTetFacetQuad()");
00274   TEUCHOS_TEST_FOR_EXCEPTION(facetIndex < 0 || facetIndex > 4, std::runtime_error,
00275                      "Invalid facet index " << facetIndex  
00276                      << " in getTetFacetQuad()");
00277   if (facetDim==2)
00278     {
00279       Array<Point> facetPts;
00280       Array<double> facetWts;
00281       getPoints(TriangleCell, facetPts, facetWts);
00282       quadPoints.resize(facetPts.size());
00283       quadWeights.resize(facetWts.size());
00284       for (int i=0; i<facetPts.size(); i++)
00285         {
00286           double s = facetPts[i][0];
00287           double t = facetPts[i][1];
00288           double x,y,z;
00289           if (facetIndex==2) 
00290             {
00291               x = s;
00292               y = 0.0;
00293               z = t;
00294             }
00295           else if (facetIndex==0) 
00296             {
00297               x = 1.0-s-t;
00298               y = s;
00299               z = t;
00300             }
00301           else if (facetIndex==1) 
00302             {
00303               x = 0.0;
00304               y = t;
00305               z = s;
00306             }
00307           else
00308             {
00309               x = s;
00310               y = 1.0-s-t;
00311               z = 0.0;
00312             }
00313           quadPoints[i] = Point(x, y, z);
00314     if (facetIndex != 1)
00315       quadWeights[i] = facetWts[i];
00316     else 
00317       quadWeights[i] = facetWts[i] * sqrt(3.0);
00318 
00319         }
00320     }
00321   else if (facetDim==0)
00322     {
00323       quadPoints.resize(1);
00324       quadWeights.resize(1);
00325       quadWeights[0] = 1.0;  
00326       if (facetIndex==0) quadPoints[0] = Point(0.0, 0.0, 0.0);
00327       else if (facetIndex==1) quadPoints[0] = Point(1.0, 0.0, 0.0);
00328       else if (facetIndex==2) quadPoints[0] = Point(0.0, 1.0, 0.0);
00329       else quadPoints[0] = Point(0.0, 0.0, 1.0);
00330     }
00331   TEUCHOS_TEST_FOR_EXCEPT(facetDim==1);
00332 }
00333 
00334 
00335 void QuadratureFamily::getBrickFacetQuad(int facetDim,
00336                                        int facetIndex,
00337                                        Array<Point>& quadPoints,
00338                                        Array<double>& quadWeights) const
00339 {
00340   TEUCHOS_TEST_FOR_EXCEPTION(facetDim > 2, std::runtime_error,
00341                      "Invalid facet dimension " << facetDim
00342                      << " in getBrickFacetQuad()");
00343   if (facetDim==2)
00344     {
00345     TEUCHOS_TEST_FOR_EXCEPTION(facetIndex < 0 || facetIndex > 5, std::runtime_error,
00346                         "Invalid facet index " << facetIndex
00347                         << " in getBrickFacetQuad()");
00348       Array<Point> facetPts;
00349       Array<double> facetWts;
00350       getPoints(QuadCell, facetPts, facetWts);
00351       quadPoints.resize(facetPts.size());
00352       quadWeights.resize(facetWts.size());
00353       for (int i=0; i<facetPts.size(); i++)
00354         {
00355           if (facetIndex==0) // the 6 faces of the Brick
00356             {// Numbering is important, if Edge Numbering in BrickCell changes, change this as well
00357               quadPoints[i] = Point(facetPts[i][0], facetPts[i][1] , 0.0);
00358               quadWeights[i] = facetWts[i];
00359             }
00360           else if (facetIndex==1)
00361             {
00362               quadPoints[i] = Point(facetPts[i][0], 0.0 , facetPts[i][1] );
00363               quadWeights[i] = facetWts[i];
00364             }
00365           else if (facetIndex==2)
00366             {
00367               quadPoints[i] = Point( 0.0 , facetPts[i][0] , facetPts[i][1] );
00368               quadWeights[i] = facetWts[i];
00369             }
00370           else if (facetIndex==3)
00371             {
00372               quadPoints[i] = Point( 1.0 , facetPts[i][0] , facetPts[i][1] );
00373               quadWeights[i] = facetWts[i];
00374             }
00375           else if (facetIndex==4)
00376             {
00377               quadPoints[i] = Point( facetPts[i][0] , 1.0 , facetPts[i][1] );
00378               quadWeights[i] = facetWts[i];
00379             }
00380           else
00381             {
00382               quadPoints[i] = Point( facetPts[i][0] , facetPts[i][1] , 1.0 );
00383               quadWeights[i] = facetWts[i];
00384             }
00385 
00386         }
00387     }
00388   else if (facetDim==1)
00389      {
00390     TEUCHOS_TEST_FOR_EXCEPTION(facetIndex < 0 || facetIndex > 11, std::runtime_error,
00391                         "Invalid facet index " << facetIndex
00392                         << " in getBrickFacetQuad()");
00393       Array<Point> facetPts;
00394       Array<double> facetWts;
00395       getPoints(LineCell, facetPts, facetWts);
00396       quadPoints.resize(facetPts.size());
00397       quadWeights.resize(facetWts.size());
00398       for (int i=0; i<facetPts.size(); i++)
00399         {
00400           if (facetIndex==0) // the 6 faces of the Brick
00401             {// Numbering is important, if Edge Numbering in BrickCell changes, change this as well
00402               quadPoints[i] = Point(facetPts[i][0], 0.0 , 0.0);  quadWeights[i] = facetWts[i];
00403             }
00404           else if (facetIndex==1)
00405           { quadPoints[i] = Point( 0.0 , facetPts[i][0], 0.0 ); quadWeights[i] = facetWts[i]; }
00406           else if (facetIndex==2)
00407           { quadPoints[i] = Point( 0.0 , 0.0 , facetPts[i][0]); quadWeights[i] = facetWts[i]; }
00408           else if (facetIndex==3)
00409           { quadPoints[i] = Point( 1.0 , facetPts[i][0] , 0.0 ); quadWeights[i] = facetWts[i]; }
00410           else if (facetIndex==4)
00411           { quadPoints[i] = Point( 1.0 , 0.0 , facetPts[i][0] ); quadWeights[i] = facetWts[i]; }
00412           else if (facetIndex==5)
00413           { quadPoints[i] = Point( facetPts[i][0] , 1.0 , 0.0 ); quadWeights[i] = facetWts[i]; }
00414           else if (facetIndex==6)
00415           { quadPoints[i] = Point( 0.0 , 1.0 , facetPts[i][0]); quadWeights[i] = facetWts[i]; }
00416           else if (facetIndex==7)
00417           { quadPoints[i] = Point( 1.0 , 1.0 , facetPts[i][0]); quadWeights[i] = facetWts[i]; }
00418           else if (facetIndex==8)
00419           { quadPoints[i] = Point( facetPts[i][0] , 0.0 , 1.0); quadWeights[i] = facetWts[i]; }
00420           else if (facetIndex==9)
00421           { quadPoints[i] = Point( 0.0 , facetPts[i][0] , 1.0); quadWeights[i] = facetWts[i]; }
00422           else if (facetIndex==10)
00423           { quadPoints[i] = Point( 1.0 , facetPts[i][0] , 1.0); quadWeights[i] = facetWts[i]; }
00424           else
00425           { quadPoints[i] = Point( facetPts[i][0] , 1.0 , 1.0); quadWeights[i] = facetWts[i]; }
00426         }
00427      }
00428   else if (facetDim==0)
00429     {
00430       quadPoints.resize(1);
00431       quadWeights.resize(1);
00432       quadWeights[0] = 1.0;
00433       if (facetIndex==0) quadPoints[0] = Point(0.0, 0.0 , 0.0);
00434       else if (facetIndex==1) quadPoints[0] = Point(1.0, 0.0, 0.0);
00435       else if (facetIndex==2) quadPoints[0] = Point(0.0, 1.0, 0.0);
00436       else if (facetIndex==3) quadPoints[0] = Point(1.0, 1.0, 0.0);
00437       else if (facetIndex==4) quadPoints[0] = Point(0.0, 0.0, 1.0);
00438       else if (facetIndex==5) quadPoints[0] = Point(1.0, 0.0, 1.0);
00439       else if (facetIndex==6) quadPoints[0] = Point(0.0, 1.0, 1.0);
00440       else quadPoints[0] = Point(1.0, 1.0, 1.0);
00441     }
00442 }
00443 
00444 
00445 namespace Sundance
00446 {
00447 void printQuad(std::ostream& os, 
00448   const Array<Point>& pts, const Array<double>& wgts)
00449 {
00450   Tabs tab(0);
00451   static Array<string> names = tuple<string>("x", "y", "z");
00452   TEUCHOS_TEST_FOR_EXCEPT(pts.size() != wgts.size());
00453   
00454   TEUCHOS_TEST_FOR_EXCEPT(pts.size() < 1);
00455 
00456   int dim = pts[0].dim();
00457 
00458   int prec=10;
00459   int w = prec+5;
00460   ios_base::fmtflags oldFlags = os.flags();
00461   os.setf(ios_base::internal);    
00462   os.setf(ios_base::showpoint);
00463 
00464   os << tab << setw(5) << "i" << setw(w) << "w";;
00465   
00466   for (int i=0; i<pts[0].dim(); i++)
00467   {
00468     os << setw(w) << names[i] ;
00469   }
00470   os << std::endl;
00471   os.setf(ios_base::right);    
00472   for (int i=0; i<pts.size(); i++)
00473   {
00474     os << tab << setw(5) << i << setw(w) << setprecision(prec) << wgts[i];
00475     for (int d=0; d<dim; d++)
00476     {
00477       os << setw(w) << setprecision(prec) << pts[i][d];
00478     }
00479     os << std::endl;
00480   }
00481   os.flags(oldFlags);
00482 }
00483 }

Site Contact