SundanceGaussianQuadrature.cpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                              Sundance
00005 //                 Copyright (2005) Sandia Corporation
00006 // 
00007 // Copyright (year first published) Sandia Corporation.  Under the terms 
00008 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government 
00009 // retains certain rights in this software.
00010 // 
00011 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //  
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //                                                                                 
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA                                                                                
00025 // Questions? Contact Kevin Long (krlong@sandia.gov), 
00026 // Sandia National Laboratories, Livermore, California, USA
00027 // 
00028 // ************************************************************************
00029 /* @HEADER@ */
00030 
00031 #include "SundanceGaussianQuadrature.hpp"
00032 #include "SundanceGauss1D.hpp"
00033 #include "SundanceTriangleQuadrature.hpp"
00034 #include "SundanceQuadQuadrature.hpp"
00035 #include "SundanceTetQuadrature.hpp"
00036 #include "SundanceBrickQuadrature.hpp"
00037 
00038 using namespace Sundance;
00039 using namespace Teuchos;
00040 
00041 GaussianQuadrature::GaussianQuadrature(int order)
00042   : QuadratureFamilyBase(order)
00043 {
00044   
00045 }
00046 
00047 XMLObject GaussianQuadrature::toXML() const 
00048 {
00049   XMLObject rtn("GaussianQuadrature");
00050   rtn.addAttribute("order", Teuchos::toString(order()));
00051   return rtn;
00052 }
00053 
00054 
00055 
00056 void GaussianQuadrature::getLineRule(Array<Point>& quadPoints,
00057                                      Array<double>& quadWeights) const 
00058 {
00059   int p = order() + 1;
00060   p = p + (p%2);
00061   int n = p/2;
00062       
00063   quadPoints.resize(n);
00064   quadWeights.resize(n);
00065       
00066   Gauss1D q1(n, 0.0, 1.0);
00067       
00068   for (int i=0; i<n; i++)
00069     {
00070       quadWeights[i] = q1.weights()[i];
00071       quadPoints[i] = Point(q1.nodes()[i]);
00072     }
00073 }
00074 
00075 void GaussianQuadrature::getTriangleRule(Array<Point>& quadPoints,
00076                                           Array<double>& quadWeights) const 
00077 {
00078   Array<double> x;
00079   Array<double> y;
00080   Array<double> w;
00081       
00082   TriangleQuadrature::getPoints(order(), w, x, y);
00083   quadPoints.resize(w.length());
00084   quadWeights.resize(w.length());
00085   for (int i=0; i<w.length(); i++)
00086     {
00087       quadWeights[i] = 0.5*w[i];
00088       quadPoints[i] = Point(x[i], y[i]);
00089     }  
00090 }
00091 
00092 void GaussianQuadrature::getQuadRule(Array<Point>& quadPoints,
00093                                           Array<double>& quadWeights) const
00094 {
00095   Array<double> x;
00096   Array<double> y;
00097   Array<double> w;
00098 
00099   QuadQuadrature::getPoints(order(), w, x, y);
00100   quadPoints.resize(w.length());
00101   quadWeights.resize(w.length());
00102   for (int i=0; i<w.length(); i++)
00103     {
00104       quadWeights[i] = w[i];
00105       quadPoints[i] = Point(x[i], y[i]);
00106     }
00107 }
00108 
00109 void GaussianQuadrature::getTetRule(Array<Point>& quadPoints,
00110                                     Array<double>& quadWeights) const 
00111 {
00112   Array<double> x;
00113   Array<double> y;
00114   Array<double> z;
00115   Array<double> w;
00116       
00117   TetQuadrature::getPoints(order(), w, x, y, z);
00118   quadPoints.resize(w.length());
00119   quadWeights.resize(w.length());
00120   for (int i=0; i<w.length(); i++)
00121     {
00122       quadWeights[i] = w[i]/6.0;
00123       quadPoints[i] = Point(x[i], y[i], z[i]);
00124     }  
00125 }
00126 
00127 void GaussianQuadrature::getBrickRule(Array<Point>& quadPoints,
00128                                     Array<double>& quadWeights) const
00129 {
00130   Array<double> x;
00131   Array<double> y;
00132   Array<double> z;
00133   Array<double> w;
00134 
00135   BrickQuadrature::getPoints(order(), w, x, y, z);
00136   quadPoints.resize(w.length());
00137   quadWeights.resize(w.length());
00138   for (int i=0; i<w.length(); i++)
00139     {
00140       quadWeights[i] = w[i];
00141       quadPoints[i] = Point(x[i], y[i], z[i]);
00142     }
00143 }
00144 
00145 void GaussianQuadrature::getAdaptedWeights(const CellType& cellType ,
00146                          int cellDim,
00147                                          int celLID ,
00148                                        int facetIndex ,
00149                                          const Mesh& mesh ,
00150                                          const ParametrizedCurve& globalCurve ,
00151                                          Array<Point>& quadPoints ,
00152                                          Array<double>& quadWeights ,
00153                                          bool &isCut) const {
00154 
00155   isCut = true; // todo: this not always might be true to save computations we might test if this is the case
00156   if (mesh.IsSpecialWeightValid() && mesh.hasSpecialWeight(cellDim, celLID))
00157   {
00158     mesh.getSpecialWeight(cellDim, celLID, quadWeights);
00159     //SUNDANCE_MSG3(verb, tabs << "GaussianQuadrature::getAdaptedWeights Found cached weights for cell LID " << cellLID)
00160     return;
00161   }
00162 
00163   // if we have no quad points then get them
00164   if (quadPoints.size() <= 1) getPoints(cellType,  quadPoints, quadWeights);
00165 
00166   // we say that the cell is always cut by the curve so these weights will be used
00167   isCut = true;
00168   Array<Point> tmpPoints = quadPoints;
00169 
00170     Array<int> celLIDs(1);
00171     celLIDs[0] = celLID;
00172     // transform the ref points to real coordinates
00173   mesh.pushForward( cellDim, celLIDs, quadPoints, tmpPoints );
00174 
00175   quadWeights.resize(tmpPoints.size());
00176     // simple weight calculation
00177   for (int i=0 ; i < tmpPoints.size() ; i++){
00178     quadWeights[i] = quadWeights[i] * globalCurve.integrationParameter(tmpPoints[i]);
00179   }
00180 
00181   // store the weights in the mesh
00182   mesh.setSpecialWeight(cellDim, celLID, quadWeights);
00183 /*
00184   Array<Point> vertices;
00185     Array<int>  nodeLIDs;
00186     Array<int>  orient;
00187     int testcount = 1;
00188 
00189     // Get coordinates
00190     mesh.getFacetArray(cellDim, celLID, 0, nodeLIDs, orient);
00191 
00192     vertices.resize(nodeLIDs.size());
00193     for (int i=0; i<nodeLIDs.size(); i++) {
00194       vertices[i] = mesh.nodePosition(nodeLIDs[i]);
00195       SUNDANCE_MSG5(6, "Points [" << testcount << "/" << i << "] " << vertices[i]);
00196       testcount++;
00197     }*/
00198 }

Site Contact