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

Site Contact