SundanceRaviartThomas.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 "SundanceRaviartThomas.hpp"
00043 #include "SundancePoint.hpp"
00044 #include "SundanceCellType.hpp"
00045 #include "SundanceSpatialDerivSpecifier.hpp"
00046 #include "PlayaExceptions.hpp"
00047 #include "SundanceTypeUtils.hpp"
00048 #include "SundanceObjectWithVerbosity.hpp"
00049 #include "SundanceOut.hpp"
00050 #include "SundanceADReal.hpp"
00051 
00052 using namespace Sundance;
00053 using namespace Teuchos;
00054 
00055 
00056 RaviartThomas::RaviartThomas(int spatialDim)
00057   : HDivVectorBasis(spatialDim)
00058 {}
00059 
00060 bool RaviartThomas::supportsCellTypePair(
00061   const CellType& maximalCellType,
00062   const CellType& cellType
00063   ) const
00064 {
00065   switch(maximalCellType)
00066   {
00067     case TriangleCell:
00068       switch(cellType)
00069       {
00070         case TriangleCell:
00071         case LineCell:
00072         case PointCell:
00073           return true;
00074         default:
00075           return false;
00076       }
00077     case TetCell:
00078       switch(cellType)
00079       {
00080         case TetCell:
00081         case TriangleCell:
00082         case LineCell:
00083         case PointCell:
00084           return true;
00085         default:
00086           return false;
00087       }
00088     default:
00089       return false;
00090   }
00091 }
00092 
00093 std::string RaviartThomas::description() const 
00094 {
00095   return "RaviartThomas()";
00096 }
00097 
00098 int RaviartThomas::nReferenceDOFsWithoutFacets(
00099   const CellType& maximalCellType,
00100   const CellType& cellType
00101   ) const
00102 {
00103   if (dimension(cellType) == dimension(maximalCellType)-1)
00104   {
00105     return 1;
00106   }
00107   else
00108   {
00109     return 0;
00110   }
00111 }
00112 
00113 void RaviartThomas::getReferenceDOFs(
00114   const CellType& maximalCellType,
00115   const CellType& cellType,
00116   Array<Array<Array<int> > >& dofs) const 
00117 {
00118   switch(cellType)
00119   {
00120     case PointCell:
00121       dofs.resize(1);
00122       dofs[0] = tuple(Array<int>());
00123       return;
00124     case LineCell:
00125       dofs.resize(2);
00126       dofs[0] = tuple(Array<int>());
00127       dofs[1] = tuple<Array<int> >(tuple(0));
00128       return;
00129     case TriangleCell:
00130       dofs.resize(3);
00131       dofs[0] = tuple(Array<int>());
00132       dofs[1] = tuple<Array<int> >(tuple(0), tuple(1), tuple(2));
00133       dofs[2] = tuple(Array<int>());
00134       return;
00135     case TetCell:
00136       dofs.resize(4);
00137       dofs[0] = tuple(Array<int>());
00138       dofs[1] = tuple<Array<int> >(tuple(0), tuple(1), tuple(2), tuple(3));
00139       dofs[2] = tuple(Array<int>());
00140       dofs[3] = tuple(Array<int>());
00141       return;
00142     default:
00143       TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "Cell type "
00144         << cellType << " not implemented in RaviartThomas basis");
00145   }
00146 }
00147 
00148 
00149 
00150 bool RaviartThomas::lessThan(const BasisDOFTopologyBase* other) const 
00151 {
00152   if (typeLessThan(this, other)) return true;
00153   if (typeLessThan(other, this)) return false;
00154 
00155   return false;
00156 }
00157 
00158 
00159 void RaviartThomas::refEval(
00160   const CellType& cellType,
00161   const Array<Point>& pts,
00162   const SpatialDerivSpecifier& sds,
00163   Array<Array<Array<double> > >& result,
00164   int verbosity) const
00165 {
00166   const MultiIndex& deriv = sds.mi();
00167   switch(cellType) {
00168     case PointCell:
00169     {
00170       TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "evaluation of RaviartThomas elements for PointCell not supported");
00171     }
00172     break;
00173     case LineCell:
00174     {
00175       result.resize(1);
00176       result[0].resize(pts.length());
00177       Array<ADReal> tmp;
00178       tmp.resize(2);
00179       for (int i=0;i<pts.length();i++) {
00180         ADReal x = ADReal( pts[i][0] , 0 , 1 );
00181         ADReal one(1.0,1);
00182         result[0][i].resize(2);
00183         tmp[0] = one - x;
00184         tmp[1] = x;
00185         if (deriv.order()==0) {
00186           for (int j=0;j<tmp.length();j++) {
00187             result[0][i][j] = tmp[j].value();
00188           }
00189         }
00190         else {
00191           for (int j=0;j<tmp.length();j++) {
00192             result[0][i][j] = tmp[j].gradient()[deriv.firstOrderDirection()];
00193           }
00194         }
00195       }
00196     }
00197     break;
00198     case TriangleCell:
00199     {
00200       result.resize(2);
00201       result[0].resize(pts.length());
00202       result[1].resize(pts.length());
00203       Array<ADReal> tmp0;
00204       Array<ADReal> tmp1;
00205       tmp0.resize(3);
00206       tmp1.resize(3);
00207       for (int i=0;i<pts.length();i++) {
00208         ADReal x = ADReal(pts[i][0],0,2);
00209         ADReal y = ADReal(pts[i][1],1,2);
00210         ADReal one(1.0,2);
00211         ADReal rt2(std::sqrt(2.0),2);
00212         result[0][i].resize(3);
00213         result[1][i].resize(3);
00214         tmp0[0] = x;
00215         tmp1[0] = y - one;
00216         tmp0[1] = rt2 * x;
00217         tmp1[1] = rt2 * y;
00218         tmp0[2] = x - one;
00219         tmp1[2] = y;
00220         if (deriv.order()==0) {
00221           for (int j=0;j<tmp0.length();j++) {
00222             result[0][i][j] = tmp0[j].value();
00223             result[1][i][j] = tmp1[j].value();
00224           }
00225         }
00226         else {
00227           for (int j=0;j<tmp0.length();j++) {
00228             result[0][i][j] = tmp0[j].gradient()[deriv.firstOrderDirection()];
00229             result[1][i][j] = tmp1[j].gradient()[deriv.firstOrderDirection()];
00230           }
00231         }
00232       }
00233     }
00234     break;
00235     case TetCell:
00236     {
00237       TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "evaluation of RaviartThomas elements for TetCell not supported");
00238     }
00239     break;
00240     default:
00241       TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "evaluation of RaviartThomas elements unknown cell type");
00242       break;
00243   }
00244 
00245   return;
00246 }
00247 
00248 
00249 void RaviartThomas::print(std::ostream& os) const 
00250 {
00251   os << "RaviartThomas(" << dim() << ")";
00252 }

Site Contact