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 "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   // test if we need any kind of transformation
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       // first get the dofs values, which later will be transformed
00153         ghostView_->getElements(&(dofs[b][0]), dofs[b].size(), localValues[b]);
00154         // make transformation and fill the correct "localValues[b]" elements !!!! (if it is needed)
00155       // do the transformation for each function , ("nFuncs")
00156         // nNodes[b] is the total number for one function inside the chunk
00157       space_.getTransformation()->getDoFsWithTransformation(
00158           dofs[b] , functionIDs , b , nNodes[b] , nFuncs , cellDim, cellLID ,ghostView_ , localValues[b] );
00159    }
00160   }
00161   else  // if we do not need transformation then do the normal thing
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 

Site Contact