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   // First implementation ...
00155 
00156   // we say that the cell is always cut by the curve so these weights will be used
00157   isCut = true;
00158   Array<Point> tmpPoints = quadPoints;
00159 
00160     Array<int> celLIDs(1);
00161     celLIDs[0] = celLID;
00162     // transform the ref points to real coordinates
00163   mesh.pushForward( cellDim, celLIDs, quadPoints, tmpPoints );
00164 
00165   quadWeights.resize(tmpPoints.size());
00166     // simple weight calculation
00167   for (int i=0 ; i < tmpPoints.size() ; i++){
00168     quadWeights[i] = quadWeights[i] * globalCurve.integrationParameter(tmpPoints[i]);
00169   }
00170 
00171 /*
00172   Array<Point> vertices;
00173     Array<int>  nodeLIDs;
00174     Array<int>  orient;
00175     int testcount = 1;
00176 
00177     // Get coordinates
00178     mesh.getFacetArray(cellDim, celLID, 0, nodeLIDs, orient);
00179 
00180     vertices.resize(nodeLIDs.size());
00181     for (int i=0; i<nodeLIDs.size(); i++) {
00182       vertices[i] = mesh.nodePosition(nodeLIDs[i]);
00183       SUNDANCE_MSG5(6, "Points [" << testcount << "/" << i << "] " << vertices[i]);
00184       testcount++;
00185     }*/
00186 }

Site Contact