SundanceExprFieldWrapper.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 "SundanceExprFieldWrapper.hpp"
00043 #include "SundanceOut.hpp"
00044 #include "PlayaTabs.hpp"
00045 #include "SundanceDiscreteFunction.hpp"
00046 #include "SundanceLagrange.hpp"
00047 #include "SundanceEdgeLocalizedBasis.hpp"
00048 #include "SundanceDiscreteFuncElement.hpp"
00049 #include "SundanceHNDoFMapBase.hpp"
00050 
00051 using namespace Sundance;
00052 using namespace Teuchos;
00053 using namespace Playa;
00054 
00055 
00056 ExprFieldWrapper::ExprFieldWrapper(const Expr& expr)
00057   : expr_(expr),
00058     df_(),
00059     discreteSpace_(),
00060     //map_(),
00061     indices_(),
00062     Expr_size_(1),
00063     isPointData_(true)
00064 {
00065   int index = 0;
00066   Expr_size_ = expr.size();
00067   // Now it is independent of the size of the size of the Expression
00068   for(index = 0 ; index < Expr_size_ ; index++)
00069   {
00070     const DiscreteFunction* df
00071       = dynamic_cast<const DiscreteFunction*>(expr[index].ptr().get());
00072     const DiscreteFuncElement* dfe
00073       = dynamic_cast<const DiscreteFuncElement*>(expr[index].ptr().get());
00074     if (df != 0)
00075     {
00076       discreteSpace_ = df->discreteSpace();
00077       //map_ = df->map();
00078       indices_.append(tuple(0));
00079       BasisFamily basis = discreteSpace_.basis()[0];
00080       const Lagrange* lagr = dynamic_cast<const Lagrange*>(basis.ptr().get());
00081       if (lagr != 0 && lagr->order()==0) isPointData_ = false;
00082       const EdgeLocalizedBasis* elb = dynamic_cast<const EdgeLocalizedBasis*>(basis.ptr().get());
00083       if (elb!=0) isPointData_ = false;
00084       df_ = df->data();
00085     }
00086     else if (dfe != 0)
00087     {
00088       const DiscreteFunctionData* f = DiscreteFunctionData::getData(dfe);
00089 
00090       TEUCHOS_TEST_FOR_EXCEPTION(f == 0, std::runtime_error,
00091         "ExprFieldWrapper ctor argument "
00092         << expr << " is not a discrete function");
00093       discreteSpace_ = f->discreteSpace();
00094       //map_ = f->map();
00095       indices_.append(tuple(dfe->myIndex()));
00096       BasisFamily basis = discreteSpace_.basis()[indices_[index][0]];
00097       const Lagrange* lagr = dynamic_cast<const Lagrange*>(basis.ptr().get());
00098       if (lagr != 0 && lagr->order()==0) isPointData_ = false;      
00099       const EdgeLocalizedBasis* elb = dynamic_cast<const EdgeLocalizedBasis*>(basis.ptr().get());
00100       if (elb!=0) isPointData_ = false;
00101 
00102       df_ = f;
00103           
00104     }
00105     else
00106     {
00107       TEUCHOS_TEST_FOR_EXCEPTION(df == 0 && dfe == 0, std::runtime_error,
00108         "ExprFieldWrapper ctor argument is not a discrete "
00109         "function");
00110     }
00111   }
00112 }
00113 
00114 
00115 double ExprFieldWrapper::getData(int cellDim, int cellID, int elem) const
00116 {
00117   Array<int> dofs;
00118 
00119   discreteSpace_.map()->getDOFsForCell(cellDim, cellID, indices_[elem][0] , dofs); //indecies[elem][0] should be OK!
00120 
00121   //cout << "Arguments ExprFieldWrapper::getData " << cellDim << "," << cellID << "," << elem << " DoFs:" << dofs <<std::endl;
00122   //cout << "indices_[elem][0]:" << indices_[elem][0] << std::endl;
00123 
00124   // This exception is not needed since the first value must be the nodal value
00125   //TEUCHOS_TEST_FOR_EXCEPTION(dofs.size() > 1, std::runtime_error,
00126   //  "too many DOFs found in ExprFieldWrapper::getData()");
00127 
00128   // in case of hanging node the "dofs[0]" will be negative, in this case treate this case
00129   // in case of general basis function this should not be changed, when there are nodal values
00130   // Todo: if we do not have nodal values then we should do some extra things ...
00131   if ( dofs[0] < 0)
00132   {
00133     const HNDoFMapBase* HNMap
00134           = dynamic_cast<const HNDoFMapBase*>((discreteSpace_.map()).get());
00135     if (HNMap != 0 ){
00136         Array<double> coefs;
00137         double sum = 0.0;
00138       HNMap->getDOFsForHNCell( cellDim, cellID, indices_[elem][0] ,  dofs , coefs );
00139       for (int jj = 0 ; jj < dofs.size() ; jj++)
00140       {
00141         sum += coefs[jj] * df_->ghostView()->getElement(dofs[jj]); //sum up the contributions
00142       }
00143       // return the contribution of the global DoFs
00144       return sum;
00145       //return 1.0;
00146     }
00147     else
00148     {
00149     return 1.0;
00150     }
00151   }
00152   else
00153   {
00154     return df_->ghostView()->getElement(dofs[0]);
00155   }
00156 }
00157 
00158 
00159 bool ExprFieldWrapper::isDefined(int cellDim, int cellID, int elem) const
00160 {
00161   // this works only for the first
00162   RCP<const Set<int> > allowedFuncs 
00163     = discreteSpace_.map()->allowedFuncsOnCellBatch(cellDim, tuple(cellID));
00164 
00165   //cout << "Arguments ExprFieldWrapper::isDefined" << cellDim << "," << cellID << "," << elem << std::endl;
00166 
00167   return allowedFuncs->contains(indices_[elem][0]);
00168 }

Site Contact