SundanceTrapesoidQuadrature.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 /*
00044  * SundanceTrapesoidQuadrature.cpp
00045  *
00046  *  Created on: Jan 20, 2011
00047  *      Author: benk
00048  */
00049 
00050 #include "SundanceTrapesoidQuadrature.hpp"
00051 
00052 using namespace Sundance;
00053 
00054 TrapesoidQuadrature::TrapesoidQuadrature(int resolution) :
00055    QuadratureFamilyBase(1) , resolution_(resolution) {
00056   // this quadrature has always order 1 , the minimum number of points
00057   resolution_ = (resolution_<2) ? 2 : resolution_;
00058 }
00059 
00060 XMLObject TrapesoidQuadrature::toXML() const
00061 {
00062   XMLObject rtn("TrapesoidQuadrature");
00063   rtn.addAttribute("order", Teuchos::toString(order()));
00064   return rtn;
00065 }
00066 
00067 void TrapesoidQuadrature::getLineRule(
00068     Array<Point>& quadPoints,
00069     Array<double>& quadWeights) const {
00070 
00071   int nrVirInnerPoints = resolution_ - 1;
00072   double innerWeights = 1/((double)nrVirInnerPoints);
00073 
00074   int nrPoints = nrVirInnerPoints + 1;
00075   quadPoints.resize(nrPoints);
00076   quadWeights.resize(nrPoints);
00077 
00078   // create the first point the beginning
00079   quadPoints[0] = Point(0.0);
00080   quadWeights[0] = innerWeights/2.0;
00081 
00082   for (int tmp = 1 ; tmp < nrPoints-1 ; tmp++){
00083     quadPoints[tmp] = Point( (double)tmp/(double)(nrPoints-1) );
00084     quadWeights[tmp] = innerWeights;
00085   }
00086 
00087   // create the last point the end of the line
00088   quadPoints[nrPoints-1] = Point(1.0);
00089   quadWeights[nrPoints-1] = innerWeights/2.0;
00090 
00091 }
00092 
00093 
00094 void TrapesoidQuadrature::getTriangleRule(
00095     Array<Point>& quadPoints,
00096     Array<double>& quadWeights) const {
00097    // todo: implement this
00098   SUNDANCE_ERROR("Triangle rule not available for " << toXML());
00099 }
00100 
00101 
00102 void TrapesoidQuadrature::getQuadRule(
00103     Array<Point>& quadPoints,
00104     Array<double>& quadWeights) const {
00105 
00106   Array<Point> quadPointsLine;
00107   Array<double> quadWeightsLine;
00108   // get the line rule
00109     this->getLineRule( quadPointsLine, quadWeightsLine );
00110 
00111     int nrPointPerAxis = quadPointsLine.size();
00112     // we simply take the tensor product
00113     quadPoints.resize(nrPointPerAxis*nrPointPerAxis);
00114     quadWeights.resize(nrPointPerAxis*nrPointPerAxis);
00115 
00116     int pcount = 0;
00117     for (int ix = 0 ; ix < nrPointPerAxis ; ix ++){
00118       for (int iy = 0 ; iy < nrPointPerAxis ; iy ++){
00119         // here we take the tensor product of the
00120         quadPoints[pcount] = Point( quadPointsLine[ix][0] , quadPointsLine[iy][0] );
00121         quadWeights[pcount] = quadWeightsLine[ix] * quadWeightsLine[iy];
00122         pcount++;
00123       }
00124     }
00125 
00126 }
00127 
00128 
00129 void TrapesoidQuadrature::getTetRule(
00130     Array<Point>& quadPoints,
00131     Array<double>& quadWeights) const {
00132    // todo: implement this
00133    SUNDANCE_ERROR("Tet rule not available for " << toXML());
00134 }
00135 
00136 
00137 void TrapesoidQuadrature::getBrickRule(
00138     Array<Point>& quadPoints,
00139     Array<double>& quadWeights) const {
00140 
00141   Array<Point> quadPointsLine;
00142   Array<double> quadWeightsLine;
00143   // get the line rule
00144     getLineRule( quadPointsLine, quadWeightsLine );
00145 
00146     int nrPointPerAxis = quadPointsLine.size();
00147     // we simply take the tensor product
00148     quadPoints.resize(nrPointPerAxis*nrPointPerAxis*nrPointPerAxis);
00149     quadWeights.resize(nrPointPerAxis*nrPointPerAxis*nrPointPerAxis);
00150 
00151     int pcount = 0;
00152     for (int ix = 0 ; ix < nrPointPerAxis ; ix ++){
00153       for (int iy = 0 ; iy < nrPointPerAxis ; iy ++){
00154         for (int iz = 0 ; iz < nrPointPerAxis ; iz ++){
00155           // here we take the tensor product of the
00156           quadPoints[pcount] = Point( quadPointsLine[ix][0] , quadPointsLine[iy][0] , quadPointsLine[iz][0]);
00157           quadWeights[pcount] = quadWeightsLine[ix] * quadWeightsLine[iy] * quadWeightsLine[iz];
00158           pcount++;
00159         }
00160       }
00161     }
00162 }
00163 
00164 
00165 void TrapesoidQuadrature::getAdaptedWeights(
00166     const CellType& cellType, int cellDim,
00167     int cellLID, int facetIndex, const Mesh& mesh,
00168     const ParametrizedCurve& globalCurve,
00169     Array<Point>& quadPoints, Array<double>& quadWeights,
00170     bool &weightsChanged) const {
00171 
00172   weightsChanged = true; // todo: this not always might be true to save computations we might test if this is the case
00173   // get the weights from the mesh
00174   if (mesh.IsSpecialWeightValid() && mesh.hasSpecialWeight(cellDim, cellLID))
00175   {
00176       mesh.getSpecialWeight(cellDim, cellLID, quadWeights);
00177       //SUNDANCE_MSG3(verb, tabs << "GaussianQuadrature::getAdaptedWeights Found cached weights for cell LID " << cellLID)
00178       return;
00179   }
00180 
00181   // get the points
00182   if (quadPoints.size() <= 1) getPoints(cellType,  quadPoints, quadWeights);
00183 
00184   // we say that the cell is always cut by the curve so these weights will be used
00185   weightsChanged = true;
00186   Array<Point> tmpPoints = quadPoints;
00187 
00188     Array<int> celLIDs(1);
00189     celLIDs[0] = cellLID;
00190     // transform the ref points to real coordinates
00191   mesh.pushForward( cellDim, celLIDs, quadPoints, tmpPoints );
00192 
00193   quadWeights.resize(tmpPoints.size());
00194     // simple weight calculation, by just multiplying the weight by the integration factor(from the curve)
00195   for (int i=0 ; i < tmpPoints.size() ; i++){
00196     quadWeights[i] = quadWeights[i] * globalCurve.integrationParameter(tmpPoints[i]);
00197   }
00198 
00199   // store the weights in the mesh
00200   mesh.setSpecialWeight(cellDim, cellLID, quadWeights);
00201 }

Site Contact