SundanceBasisFamily.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 "SundanceBasisFamily.hpp"
00032 #include "SundanceUnknownFunction.hpp"
00033 #include "SundanceTestFunction.hpp"
00034 #include "SundanceDiscreteFunction.hpp"
00035 #include "SundanceUnknownFunctionData.hpp"
00036 #include "SundanceTestFunctionData.hpp"
00037 #include "SundanceDiscreteFunctionData.hpp"
00038 #include "SundanceLagrange.hpp"
00039 #include "SundanceEdgeLocalizedBasis.hpp"
00040 
00041 
00042 using namespace Sundance;
00043 using namespace Teuchos;
00044 
00045 
00046 
00047 
00048 
00049 int BasisFamily::order() const 
00050 {
00051   return ptr()->order();
00052 }
00053 
00054 int BasisFamily::dim() const 
00055 {
00056   return ptr()->dim();
00057 }
00058 
00059 bool BasisFamily::operator==(const BasisFamily& other) const
00060 {
00061   return !(*this < other || other < *this);
00062 }
00063 
00064 int BasisFamily::size(const Array<BasisFamily>& b)
00065 {
00066   int rtn = 0;
00067   for (int i=0; i<b.size(); i++) rtn += b[i].dim();
00068   return rtn;
00069 }
00070 
00071 int BasisFamily::nReferenceDOFsWithFacets(const CellType& maximalCellType,
00072             const CellType& cellType) const 
00073 {
00074   return ptr()->nReferenceDOFsWithFacets(maximalCellType, cellType);
00075 }
00076 
00077 int BasisFamily::nReferenceDOFsWithoutFacets(const CellType& maximalCellType,
00078                const CellType& cellType) const 
00079 {
00080   return ptr()->nReferenceDOFsWithoutFacets(maximalCellType, cellType);
00081 }
00082 
00083 BasisFamily BasisFamily::getBasis(const RCP<const CommonFuncDataStub>& funcData)
00084 {
00085   /* First try to process assuming the input is an unknown function */
00086   const UnknownFunctionData* u 
00087     = dynamic_cast<const UnknownFunctionData*>(funcData.get());
00088   if (u != 0)
00089     {
00090       return u->basis()[0];
00091     }
00092 
00093   /* Next try to process assuming the input is a test function */
00094   const TestFunctionData* t 
00095     = dynamic_cast<const TestFunctionData*>(funcData.get());
00096   if (t != 0)
00097     {
00098       return t->basis()[0];
00099     }
00100 
00101 
00102   /* Next try to process assuming the input is a discrete function */
00103   const DiscreteFunctionData* d
00104     = dynamic_cast<const DiscreteFunctionData*>(funcData.get());
00105   if (d != 0)
00106     {
00107       return d->discreteSpace().basis()[0];
00108     }
00109 
00110   TEST_FOR_EXCEPTION(u==0 && t==0 && d==0, RuntimeError,
00111          "BasisFamily::getBasis() argument is not a recognized "
00112          "type of function data");
00113   return BasisFamily();
00114   
00115 }
00116 
00117 
00118 
00119 RCP<BasisDOFTopologyBase> BasisFamily::getBasisTopology(const RCP<const CommonFuncDataStub>& funcData)
00120 {
00121   BasisFamily b = getBasis(funcData);
00122   TEST_FOR_EXCEPT(b.ptr().get()==0);
00123 
00124   return rcp_dynamic_cast<BasisDOFTopologyBase>(b.ptr());
00125 }
00126 
00127 
00128 void BasisFamily::getConstrainsForHNDoF( const int indexInParent,
00129            const int maxCellDim,
00130            const int maxNrChild,
00131            const int facetDim,
00132            const int facetIndex,
00133            const int nodeIndex,
00134            Array<int>& localDoFs,
00135            Array<int>& parentFacetDim,
00136            Array<int>& parentFacetIndex,
00137            Array<int>& parentFacetNode,
00138            Array<double>& coefs
00139            ) const
00140 {
00141   Tabs tab;
00142   int verb = 4;
00143   SUNDANCE_MSG3( verb ,tab << "BasisFamily::getConstrainsForHNDoF IN: indexInParent:" << indexInParent
00144      << "  maxCellDim:" << maxCellDim << " maxNrChild:" << maxNrChild
00145      << " facetDim:" << facetDim << "  facetIndex:" << facetIndex << " nodeIndex:" << nodeIndex);
00146   ptr()->getConstrainsForHNDoF( indexInParent, maxCellDim ,
00147         maxNrChild , facetDim, facetIndex, nodeIndex, localDoFs, parentFacetDim ,
00148         parentFacetIndex , parentFacetNode , coefs );
00149   SUNDANCE_MSG3( verb , tab << "BasisFamily::getConstrainsForHNDoF OUT: localDoFs:" << localDoFs
00150      << " coefs:" << coefs);
00151   SUNDANCE_MSG3( verb , tab << "BasisFamily::getConstrainsForHNDoF OUT: parentFacetDim:" << parentFacetDim );
00152   SUNDANCE_MSG3( verb , tab << "BasisFamily::getConstrainsForHNDoF OUT: parentFacetIndex:" << parentFacetIndex );
00153   SUNDANCE_MSG3( verb , tab << "BasisFamily::getConstrainsForHNDoF OUT: parentFacetNode:" << parentFacetNode );
00154 }
00155 
00156 
00157 void BasisFamily::refEval(
00158         const CellType& cellType,
00159         const Array<Point>& pts,
00160         const SpatialDerivSpecifier& deriv,
00161         Array<Array<Array<double> > >& result,
00162         int verbosity) const
00163 {
00164   using std::setw;
00165   Tabs tab;
00166   SUNDANCE_MSG3(verbosity, tab << "evaluating basis " << *this 
00167     << " with spatial derivative " << deriv);
00168   ptr()->refEval(cellType, pts, deriv, result, verbosity);
00169   std::string f = deriv.toString()+ "[phi_n]";
00170 
00171   if (verbosity >= 4)
00172     {
00173       Tabs tab1;
00174       for (int q=0; q<pts.size(); q++)
00175   {
00176     Tabs tab2;
00177     Out::os() << tab1 << "evaluation point = " << pts[q] << std::endl;
00178     Out::os() << tab2 << setw(5) << "n";
00179     int nComps = result.size();
00180     if (nComps == 1)
00181       {
00182         Out::os() << setw(20) <<  f << std::endl;
00183       }
00184     else
00185       {
00186         for (int d=0; d<nComps; d++)
00187     {
00188       std::string fd = f + "[" + Teuchos::toString(d) + "]";
00189       Out::os() << setw(20) <<  fd;
00190     }
00191         Out::os() << std::endl;
00192       }
00193     for (int n=0; n<result[0][q].size(); n++)
00194       {
00195         Out::os() << tab2 << setw(5) << n;
00196         for (int d=0; d<nComps; d++)
00197     {
00198       Out::os() << setw(20) <<  result[d][q][n];
00199     }
00200         Out::os() << std::endl;
00201       }
00202   }
00203     }
00204 }
00205 
00206 
00207 namespace Sundance
00208 {
00209 
00210   Array<std::pair<int, int> > 
00211   vectorDimStructure(const Array<BasisFamily>& basis)
00212   {
00213     Array<std::pair<int, int> > rtn;
00214     for (int i=0; i<basis.size(); i++) 
00215       {
00216   rtn.append(std::pair<int, int>(basis[i].tensorOrder(), basis[i].dim()));
00217       }
00218     return rtn;
00219   }
00220 
00221 
00222   Array<std::pair<int, int> > vectorDimStructure(const BasisFamily& basis)
00223   {
00224     return vectorDimStructure(tuple(basis));
00225   }
00226 
00227   bool basisRestrictableToBoundary(const BasisFamily& b)
00228   {
00229     const Lagrange* lag = dynamic_cast<const Lagrange*>(b.ptr().get());
00230     const EdgeLocalizedBasis* elb = dynamic_cast<const EdgeLocalizedBasis*>(b.ptr().get());
00231     return lag != 0 || elb != 0;
00232   }
00233 
00234 }

Site Contact