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

Site Contact