SundanceDiscreteFunctionData.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 "SundanceDiscreteFunctionData.hpp"
00032 #include "SundanceOut.hpp"
00033 #include "SundanceTabs.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 "TSFVectorImpl.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   TEST_FOR_EXCEPTION(dfe==0, RuntimeError, "null argument to DiscreteFunctionData::getData()");
00082   RCP<const DiscreteFunctionData> rtn 
00083     = rcp_dynamic_cast<const DiscreteFunctionData>(dfe->commonData());
00084   TEST_FOR_EXCEPTION(rtn.get()==0, RuntimeError, 
00085     "cast to DiscreteFunctionData* failed for "
00086     "discrete function element " << dfe->toXML());
00087   return rtn.get();
00088 }
00089 
00090 void DiscreteFunctionData::setVector(const Vector<double>& vec) 
00091 {
00092   ghostsAreValid_ = false;
00093   vector_ = vec;
00094 }
00095 
00096 void DiscreteFunctionData::updateGhosts() const
00097 {
00098   if (!ghostsAreValid_)
00099   {
00100     space_.importGhosts(vector_, ghostView_);
00101     ghostsAreValid_ = true;
00102   }
00103 }
00104 
00105 
00106 RCP<const MapStructure> DiscreteFunctionData
00107 ::getLocalValues(int cellDim, 
00108   const Array<int>& cellLID,
00109   Array<Array<double> >& localValues) const 
00110 {
00111   Tabs tab;
00112 
00113   if (Evaluator::classVerbosity() > 3)
00114   {
00115     Out::os() << tab << "getting DF local values" << std::endl;
00116   }
00117   updateGhosts();
00118 
00119   const RCP<DOFMapBase>& map = space_.map();
00120   static Array<Array<int> > dofs;
00121   Array<int> nNodes;
00122 
00123   RCP<const Set<int> > requestedFuncs = map->allowedFuncsOnCellBatch(cellDim,
00124     cellLID);
00125 
00126   RCP<const MapStructure> s = map->getDOFsForCellBatch(cellDim, cellLID,
00127     *requestedFuncs,
00128     dofs, nNodes, Evaluator::classVerbosity());
00129   localValues.resize(s->numBasisChunks());
00130   // test if we need any kind of transformation
00131 
00132   if  (space_.getTransformation()->validTransformation())
00133   {
00134    SUNDANCE_OUT( Evaluator::classVerbosity() > 3 , "DiscreteFunctionData::getLocalValues() VALID TRAFO FOUND ... ")
00135    for (int b=0; b<nNodes.size(); b++)
00136    {
00137       int nFuncs = s->numFuncs(b);
00138       Array<int> functionIDs = s->funcs(b);
00139       localValues[b].resize(nFuncs*nNodes[b]*cellLID.size());
00140 
00141       // first get the dofs values, which later will be transformed
00142         ghostView_->getElements(&(dofs[b][0]), dofs[b].size(), localValues[b]);
00143         // make transformation and fill the correct "localValues[b]" elements !!!! (if it is needed)
00144       // do the transformation for each function , ("nFuncs")
00145         // nNodes[b] is the total number for one function inside the chunk
00146       space_.getTransformation()->getDoFsWithTransformation(
00147           dofs[b] , functionIDs , b , nNodes[b] , nFuncs , cellDim, cellLID ,ghostView_ , localValues[b] );
00148    }
00149   }
00150   else  // if we do not need transformation then do the normal thing
00151   {
00152     SUNDANCE_OUT( Evaluator::classVerbosity() > 3 , "DiscreteFunctionData::getLocalValues() NO VALID TRAFO ... ")
00153     for (int b=0; b<nNodes.size(); b++)
00154     {
00155       int nFuncs = s->numFuncs(b);
00156       localValues[b].resize(nFuncs*nNodes[b]*cellLID.size());
00157         ghostView_->getElements(&(dofs[b][0]), dofs[b].size(), localValues[b]);
00158     }
00159   }
00160 
00161   return s;
00162 }
00163 
00164 
00165 

Site Contact