SundanceGaussianQuadrature.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 #include "SundanceGaussianQuadrature.hpp"
00043 #include "SundanceGauss1D.hpp"
00044 #include "SundanceTriangleQuadrature.hpp"
00045 #include "SundanceQuadQuadrature.hpp"
00046 #include "SundanceTetQuadrature.hpp"
00047 #include "SundanceBrickQuadrature.hpp"
00048 
00049 using namespace Sundance;
00050 using namespace Teuchos;
00051 
00052 GaussianQuadrature::GaussianQuadrature(int order)
00053   : QuadratureFamilyBase(order)
00054 {
00055   
00056 }
00057 
00058 XMLObject GaussianQuadrature::toXML() const 
00059 {
00060   XMLObject rtn("GaussianQuadrature");
00061   rtn.addAttribute("order", Teuchos::toString(order()));
00062   return rtn;
00063 }
00064 
00065 
00066 
00067 void GaussianQuadrature::getLineRule(Array<Point>& quadPoints,
00068                                      Array<double>& quadWeights) const 
00069 {
00070   int p = order() + 1;
00071   p = p + (p%2);
00072   int n = p/2;
00073       
00074   quadPoints.resize(n);
00075   quadWeights.resize(n);
00076       
00077   Gauss1D q1(n, 0.0, 1.0);
00078       
00079   for (int i=0; i<n; i++)
00080     {
00081       quadWeights[i] = q1.weights()[i];
00082       quadPoints[i] = Point(q1.nodes()[i]);
00083     }
00084 }
00085 
00086 void GaussianQuadrature::getTriangleRule(Array<Point>& quadPoints,
00087                                           Array<double>& quadWeights) const 
00088 {
00089   Array<double> x;
00090   Array<double> y;
00091   Array<double> w;
00092       
00093   TriangleQuadrature::getPoints(order(), w, x, y);
00094   quadPoints.resize(w.length());
00095   quadWeights.resize(w.length());
00096   for (int i=0; i<w.length(); i++)
00097     {
00098       quadWeights[i] = 0.5*w[i];
00099       quadPoints[i] = Point(x[i], y[i]);
00100     }  
00101 }
00102 
00103 void GaussianQuadrature::getQuadRule(Array<Point>& quadPoints,
00104                                           Array<double>& quadWeights) const
00105 {
00106   Array<double> x;
00107   Array<double> y;
00108   Array<double> w;
00109 
00110   QuadQuadrature::getPoints(order(), w, x, y);
00111   quadPoints.resize(w.length());
00112   quadWeights.resize(w.length());
00113   for (int i=0; i<w.length(); i++)
00114     {
00115       quadWeights[i] = w[i];
00116       quadPoints[i] = Point(x[i], y[i]);
00117     }
00118 }
00119 
00120 void GaussianQuadrature::getTetRule(Array<Point>& quadPoints,
00121                                     Array<double>& quadWeights) const 
00122 {
00123   Array<double> x;
00124   Array<double> y;
00125   Array<double> z;
00126   Array<double> w;
00127       
00128   TetQuadrature::getPoints(order(), w, x, y, z);
00129   quadPoints.resize(w.length());
00130   quadWeights.resize(w.length());
00131   for (int i=0; i<w.length(); i++)
00132     {
00133       quadWeights[i] = w[i]/6.0;
00134       quadPoints[i] = Point(x[i], y[i], z[i]);
00135     }  
00136 }
00137 
00138 void GaussianQuadrature::getBrickRule(Array<Point>& quadPoints,
00139                                     Array<double>& quadWeights) const
00140 {
00141   Array<double> x;
00142   Array<double> y;
00143   Array<double> z;
00144   Array<double> w;
00145 
00146   BrickQuadrature::getPoints(order(), w, x, y, z);
00147   quadPoints.resize(w.length());
00148   quadWeights.resize(w.length());
00149   for (int i=0; i<w.length(); i++)
00150     {
00151       quadWeights[i] = w[i];
00152       quadPoints[i] = Point(x[i], y[i], z[i]);
00153     }
00154 }
00155 
00156 void GaussianQuadrature::getAdaptedWeights(const CellType& cellType ,
00157                          int cellDim,
00158                                          int celLID ,
00159                                        int facetIndex ,
00160                                          const Mesh& mesh ,
00161                                          const ParametrizedCurve& globalCurve ,
00162                                          Array<Point>& quadPoints ,
00163                                          Array<double>& quadWeights ,
00164                                          bool &isCut) const {
00165 
00166   isCut = true; // todo: this not always might be true to save computations we might test if this is the case
00167   if (mesh.IsSpecialWeightValid() && mesh.hasSpecialWeight(cellDim, celLID))
00168   {
00169     mesh.getSpecialWeight(cellDim, celLID, quadWeights);
00170     //SUNDANCE_MSG3(verb, tabs << "GaussianQuadrature::getAdaptedWeights Found cached weights for cell LID " << cellLID)
00171     return;
00172   }
00173 
00174   // if we have no quad points then get them
00175   if (quadPoints.size() <= 1) getPoints(cellType,  quadPoints, quadWeights);
00176 
00177   // we say that the cell is always cut by the curve so these weights will be used
00178   isCut = true;
00179   Array<Point> tmpPoints = quadPoints;
00180 
00181     Array<int> celLIDs(1);
00182     celLIDs[0] = celLID;
00183     // transform the ref points to real coordinates
00184   mesh.pushForward( cellDim, celLIDs, quadPoints, tmpPoints );
00185 
00186   quadWeights.resize(tmpPoints.size());
00187     // simple weight calculation
00188   for (int i=0 ; i < tmpPoints.size() ; i++){
00189     quadWeights[i] = quadWeights[i] * globalCurve.integrationParameter(tmpPoints[i]);
00190   }
00191 
00192   // store the weights in the mesh
00193   mesh.setSpecialWeight(cellDim, celLID, quadWeights);
00194 /*
00195   Array<Point> vertices;
00196     Array<int>  nodeLIDs;
00197     Array<int>  orient;
00198     int testcount = 1;
00199 
00200     // Get coordinates
00201     mesh.getFacetArray(cellDim, celLID, 0, nodeLIDs, orient);
00202 
00203     vertices.resize(nodeLIDs.size());
00204     for (int i=0; i<nodeLIDs.size(); i++) {
00205       vertices[i] = mesh.nodePosition(nodeLIDs[i]);
00206       SUNDANCE_MSG5(6, "Points [" << testcount << "/" << i << "] " << vertices[i]);
00207       testcount++;
00208     }*/
00209 }

Site Contact