SundanceDiscreteFunctionData.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 "SundanceDiscreteFunctionData.hpp"
00043 #include "SundanceOut.hpp"
00044 #include "PlayaTabs.hpp"
00045 #include "SundanceMaximalCellFilter.hpp"
00046 #include "SundanceCellFilter.hpp"
00047 #include "SundanceCellSet.hpp"
00048 #include "SundanceSubtypeEvaluator.hpp"
00049 
00050 
00051 #ifndef HAVE_TEUCHOS_EXPLICIT_INSTANTIATION
00052 #include "PlayaVectorImpl.hpp"
00053 #endif
00054 
00055 
00056 using namespace Sundance;
00057 using namespace Teuchos;
00058 
00059 
00060 
00061 
00062 DiscreteFunctionData::DiscreteFunctionData(const DiscreteSpace& space)
00063   : DiscreteFuncDataStub(), 
00064     space_(space),
00065     vector_(space_.createVector()),
00066     ghostView_(),
00067     ghostsAreValid_(false)
00068 {}
00069 
00070 DiscreteFunctionData::DiscreteFunctionData(const DiscreteSpace& space, 
00071   const double& constantValue)
00072   : DiscreteFuncDataStub(), 
00073     space_(space),
00074     vector_(space_.createVector()),
00075     ghostView_(),
00076     ghostsAreValid_(false)
00077 {
00078   vector_.setToConstant(constantValue);
00079 }
00080 
00081 DiscreteFunctionData::DiscreteFunctionData(const DiscreteSpace& space, 
00082   const Vector<double>& vector)
00083   : DiscreteFuncDataStub(), 
00084     space_(space),
00085     vector_(vector),
00086     ghostView_(),
00087     ghostsAreValid_(false)
00088 {}
00089 
00090 const DiscreteFunctionData* DiscreteFunctionData::getData(const DiscreteFuncElement* dfe)
00091 {
00092   TEUCHOS_TEST_FOR_EXCEPTION(dfe==0, std::runtime_error, "null argument to DiscreteFunctionData::getData()");
00093   RCP<const DiscreteFunctionData> rtn 
00094     = rcp_dynamic_cast<const DiscreteFunctionData>(dfe->commonData());
00095   TEUCHOS_TEST_FOR_EXCEPTION(rtn.get()==0, std::runtime_error, 
00096     "cast to DiscreteFunctionData* failed for "
00097     "discrete function element " << dfe->toXML());
00098   return rtn.get();
00099 }
00100 
00101 DiscreteFunctionData* DiscreteFunctionData::getData(DiscreteFuncElement* dfe)
00102 {
00103   TEUCHOS_TEST_FOR_EXCEPTION(dfe==0, std::runtime_error, "null argument to DiscreteFunctionData::getData()");
00104   DiscreteFunctionData* rtn 
00105     = dynamic_cast<DiscreteFunctionData*>(dfe->commonData());
00106   TEUCHOS_TEST_FOR_EXCEPTION(rtn==0, std::runtime_error, 
00107     "cast to DiscreteFunctionData* failed for "
00108     "discrete function element " << dfe->toXML());
00109   return rtn;
00110 }
00111 
00112 void DiscreteFunctionData::setVector(const Vector<double>& vec) 
00113 {
00114   ghostsAreValid_ = false;
00115   vector_ = vec;
00116 }
00117 
00118 void DiscreteFunctionData::updateGhosts() const
00119 {
00120   if (!ghostsAreValid_)
00121   {
00122     space_.importGhosts(vector_, ghostView_);
00123     ghostsAreValid_ = true;
00124   }
00125 }
00126 
00127 
00128 RCP<const MapStructure> DiscreteFunctionData
00129 ::getLocalValues(int cellDim, 
00130   const Array<int>& cellLID,
00131   Array<Array<double> >& localValues) const 
00132 {
00133   Tabs tab;
00134 
00135   if (Evaluator::classVerbosity() > 3)
00136   {
00137     Out::os() << tab << "getting DF local values" << std::endl;
00138   }
00139   updateGhosts();
00140 
00141   const RCP<DOFMapBase>& map = space_.map();
00142   Array<Array<int> > dofs;
00143   Array<int> nNodes;
00144 
00145   RCP<const Set<int> > requestedFuncs = map->allowedFuncsOnCellBatch(cellDim,
00146     cellLID);
00147 
00148   RCP<const MapStructure> s = map->getDOFsForCellBatch(cellDim, cellLID,
00149     *requestedFuncs,
00150     dofs, nNodes, Evaluator::classVerbosity());
00151   localValues.resize(s->numBasisChunks());
00152   // test if we need any kind of transformation
00153 
00154   if  (space_.getTransformation()->validTransformation())
00155   {
00156    SUNDANCE_OUT( Evaluator::classVerbosity() > 3 , "DiscreteFunctionData::getLocalValues() VALID TRAFO FOUND ... ")
00157    for (int b=0; b<nNodes.size(); b++)
00158    {
00159       int nFuncs = s->numFuncs(b);
00160       Array<int> functionIDs = s->funcs(b);
00161       localValues[b].resize(nFuncs*nNodes[b]*cellLID.size());
00162 
00163       // first get the dofs values, which later will be transformed
00164         ghostView_->getElements(&(dofs[b][0]), dofs[b].size(), localValues[b]);
00165         // make transformation and fill the correct "localValues[b]" elements !!!! (if it is needed)
00166       // do the transformation for each function , ("nFuncs")
00167         // nNodes[b] is the total number for one function inside the chunk
00168       space_.getTransformation()->getDoFsWithTransformation(
00169           dofs[b] , functionIDs , b , nNodes[b] , nFuncs , cellDim, cellLID ,ghostView_ , localValues[b] );
00170    }
00171   }
00172   else  // if we do not need transformation then do the normal thing
00173   {
00174     SUNDANCE_OUT( Evaluator::classVerbosity() > 3 , "DiscreteFunctionData::getLocalValues() NO VALID TRAFO ... ")
00175     for (int b=0; b<nNodes.size(); b++)
00176     {
00177       int nFuncs = s->numFuncs(b);
00178       localValues[b].resize(nFuncs*nNodes[b]*cellLID.size());
00179         ghostView_->getElements(&(dofs[b][0]), dofs[b].size(), localValues[b]);
00180     }
00181   }
00182 
00183   return s;
00184 }
00185 
00186 
00187 

Site Contact