00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 #include "SundanceDiscreteFunctionData.hpp"
00032 #include "SundanceOut.hpp"
00033 #include "PlayaTabs.hpp"
00034 #include "SundanceMaximalCellFilter.hpp"
00035 #include "SundanceCellFilter.hpp"
00036 #include "SundanceCellSet.hpp"
00037 #include "SundanceSubtypeEvaluator.hpp"
00038 
00039 
00040 #ifndef HAVE_TEUCHOS_EXPLICIT_INSTANTIATION
00041 #include "PlayaVectorImpl.hpp"
00042 #endif
00043 
00044 
00045 using namespace Sundance;
00046 using namespace Teuchos;
00047 
00048 
00049 
00050 
00051 DiscreteFunctionData::DiscreteFunctionData(const DiscreteSpace& space)
00052   : DiscreteFuncDataStub(), 
00053     space_(space),
00054     vector_(space_.createVector()),
00055     ghostView_(),
00056     ghostsAreValid_(false)
00057 {}
00058 
00059 DiscreteFunctionData::DiscreteFunctionData(const DiscreteSpace& space, 
00060   const double& constantValue)
00061   : DiscreteFuncDataStub(), 
00062     space_(space),
00063     vector_(space_.createVector()),
00064     ghostView_(),
00065     ghostsAreValid_(false)
00066 {
00067   vector_.setToConstant(constantValue);
00068 }
00069 
00070 DiscreteFunctionData::DiscreteFunctionData(const DiscreteSpace& space, 
00071   const Vector<double>& vector)
00072   : DiscreteFuncDataStub(), 
00073     space_(space),
00074     vector_(vector),
00075     ghostView_(),
00076     ghostsAreValid_(false)
00077 {}
00078 
00079 const DiscreteFunctionData* DiscreteFunctionData::getData(const DiscreteFuncElement* dfe)
00080 {
00081   TEUCHOS_TEST_FOR_EXCEPTION(dfe==0, std::runtime_error, "null argument to DiscreteFunctionData::getData()");
00082   RCP<const DiscreteFunctionData> rtn 
00083     = rcp_dynamic_cast<const DiscreteFunctionData>(dfe->commonData());
00084   TEUCHOS_TEST_FOR_EXCEPTION(rtn.get()==0, std::runtime_error, 
00085     "cast to DiscreteFunctionData* failed for "
00086     "discrete function element " << dfe->toXML());
00087   return rtn.get();
00088 }
00089 
00090 DiscreteFunctionData* DiscreteFunctionData::getData(DiscreteFuncElement* dfe)
00091 {
00092   TEUCHOS_TEST_FOR_EXCEPTION(dfe==0, std::runtime_error, "null argument to DiscreteFunctionData::getData()");
00093   DiscreteFunctionData* rtn 
00094     = dynamic_cast<DiscreteFunctionData*>(dfe->commonData());
00095   TEUCHOS_TEST_FOR_EXCEPTION(rtn==0, std::runtime_error, 
00096     "cast to DiscreteFunctionData* failed for "
00097     "discrete function element " << dfe->toXML());
00098   return rtn;
00099 }
00100 
00101 void DiscreteFunctionData::setVector(const Vector<double>& vec) 
00102 {
00103   ghostsAreValid_ = false;
00104   vector_ = vec;
00105 }
00106 
00107 void DiscreteFunctionData::updateGhosts() const
00108 {
00109   if (!ghostsAreValid_)
00110   {
00111     space_.importGhosts(vector_, ghostView_);
00112     ghostsAreValid_ = true;
00113   }
00114 }
00115 
00116 
00117 RCP<const MapStructure> DiscreteFunctionData
00118 ::getLocalValues(int cellDim, 
00119   const Array<int>& cellLID,
00120   Array<Array<double> >& localValues) const 
00121 {
00122   Tabs tab;
00123 
00124   if (Evaluator::classVerbosity() > 3)
00125   {
00126     Out::os() << tab << "getting DF local values" << std::endl;
00127   }
00128   updateGhosts();
00129 
00130   const RCP<DOFMapBase>& map = space_.map();
00131   Array<Array<int> > dofs;
00132   Array<int> nNodes;
00133 
00134   RCP<const Set<int> > requestedFuncs = map->allowedFuncsOnCellBatch(cellDim,
00135     cellLID);
00136 
00137   RCP<const MapStructure> s = map->getDOFsForCellBatch(cellDim, cellLID,
00138     *requestedFuncs,
00139     dofs, nNodes, Evaluator::classVerbosity());
00140   localValues.resize(s->numBasisChunks());
00141   
00142 
00143   if  (space_.getTransformation()->validTransformation())
00144   {
00145    SUNDANCE_OUT( Evaluator::classVerbosity() > 3 , "DiscreteFunctionData::getLocalValues() VALID TRAFO FOUND ... ")
00146    for (int b=0; b<nNodes.size(); b++)
00147    {
00148       int nFuncs = s->numFuncs(b);
00149       Array<int> functionIDs = s->funcs(b);
00150       localValues[b].resize(nFuncs*nNodes[b]*cellLID.size());
00151 
00152       
00153         ghostView_->getElements(&(dofs[b][0]), dofs[b].size(), localValues[b]);
00154         
00155       
00156         
00157       space_.getTransformation()->getDoFsWithTransformation(
00158           dofs[b] , functionIDs , b , nNodes[b] , nFuncs , cellDim, cellLID ,ghostView_ , localValues[b] );
00159    }
00160   }
00161   else  
00162   {
00163     SUNDANCE_OUT( Evaluator::classVerbosity() > 3 , "DiscreteFunctionData::getLocalValues() NO VALID TRAFO ... ")
00164     for (int b=0; b<nNodes.size(); b++)
00165     {
00166       int nFuncs = s->numFuncs(b);
00167       localValues[b].resize(nFuncs*nNodes[b]*cellLID.size());
00168         ghostView_->getElements(&(dofs[b][0]), dofs[b].size(), localValues[b]);
00169     }
00170   }
00171 
00172   return s;
00173 }
00174 
00175 
00176