SundanceLocalDOFMap.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 "SundanceOut.hpp"
00043 #include "PlayaTabs.hpp"
00044 #include "SundanceDOFMapBase.hpp"
00045 #include "SundanceLocalDOFMap.hpp"
00046 
00047 
00048 using namespace Sundance;
00049 using namespace Sundance;
00050 using namespace Sundance;
00051 using namespace Teuchos;
00052 
00053 
00054 using std::endl;
00055 using std::setw;
00056 
00057 
00058 LocalDOFMap::LocalDOFMap(int numBlocks, int verb)
00059   : verb_(verb),
00060     isUsed_(numBlocks),
00061     hasCells_(false),
00062     nLocalNodesPerChunk_(rcp(new Array<Array<int> >(numBlocks))),
00063     mapStruct_(rcp(new Array<RCP<const MapStructure> >(numBlocks))),
00064     localDOFs_(rcp(new Array<Array<Array<int> > >(numBlocks))),
00065     cellLID_(),
00066     activeCellDim_(-1),
00067     maxCellDim_(-1)
00068 {}
00069 
00070 int LocalDOFMap::nCells() const 
00071 {
00072   TEUCHOS_TEST_FOR_EXCEPTION(!hasCells(), std::runtime_error,
00073     "cells not valid when LocalDOFMap::nCells() called");
00074   return cellLID_->size();
00075 }
00076 
00077 void  LocalDOFMap::markAsUnused() 
00078 {
00079   for (int b=0; b<numBlocks(); b++) 
00080   {
00081     isUsed_[b] = 0;
00082   }
00083   hasCells_ = false;
00084 }
00085 
00086 
00087 bool  LocalDOFMap::isUnused() const 
00088 {
00089   for (int b=0; b<numBlocks(); b++) 
00090   {
00091     if (isUsed_[b]) return false;
00092   }
00093   return true;
00094 }
00095 
00096 void LocalDOFMap::verifyValidBlock(int b) const 
00097 {
00098   TEUCHOS_TEST_FOR_EXCEPTION(b < 0 || b>=numBlocks(), std::runtime_error,
00099     "block index " << b << " out of range [0," << numBlocks() << ")");
00100 }
00101 
00102 void LocalDOFMap::setCells(
00103   int activeCellDim, 
00104   int maxCellDim,
00105   const RCP<const Array<int> >& cellLID)
00106 {
00107   activeCellDim_ = activeCellDim;
00108   maxCellDim_ = maxCellDim_;
00109   cellLID_ = cellLID;
00110   hasCells_=true;
00111 }
00112 
00113 
00114 void LocalDOFMap::fillBlock(int b, const RCP<DOFMapBase>& globalMap,
00115   const Array<Set<int> >& requiredFuncs)
00116 {
00117   Tabs tab;
00118   verifyValidBlock(b);
00119 
00120   SUNDANCE_MSG2(verb_, tab << "getting local DOFs for block=" << b 
00121     << ", active cell dim="
00122     << activeCellDim_);
00123 
00124   mapStruct(b) = globalMap->getDOFsForCellBatch(
00125     activeCellDim_,
00126     *cellLID_,
00127     requiredFuncs[b],
00128     localDOFs(b),
00129     nLocalNodesPerChunk(b),
00130     verb_);
00131 }
00132 
00133 std::ostream& LocalDOFMap::print(std::ostream& os) const
00134 {
00135   Tabs tab0;
00136   bool noneAreUsed=true;
00137   for (int b=0;  b<numBlocks(); b++) 
00138   {
00139     if (isUsed(b)) {noneAreUsed = false; break;}
00140   }
00141   if (noneAreUsed)
00142   {
00143     os << std::endl << tab0 << "[empty local DOF map]";
00144   }
00145   else
00146   {
00147     os << std::endl << tab0 << "LocalDOFMap[" << std::endl;
00148     Tabs tab;
00149     os << tab << "num cells=" << cellLID_->size() << ", active cellDim="
00150        << activeCellDim_ << ", maxCellDim=" << maxCellDim_ << std::endl;
00151     os << tab << "num blocks=" << numBlocks() << std::endl << std::endl;
00152 
00153     for (int b=0; b<numBlocks(); b++)
00154     {
00155       Tabs tab1;
00156       os << tab1 << "block " << b << " of " << numBlocks()
00157          << *mapStruct(b) << std::endl;
00158       const Array<Array<int> >& dofs = localDOFs(b);
00159       int nChunks = mapStruct(b)->numBasisChunks();
00160       
00161       for (int c=0; c<cellLID_->size(); c++)
00162       {
00163         Tabs tab2;
00164         os << tab2 << "cell LID=" << (*cellLID_)[c] << std::endl;
00165         for (int chunk=0; chunk<nChunks; chunk++)
00166         {
00167           Tabs tab3;
00168           int nFuncs = mapStruct(b)->numFuncs(chunk);
00169           const Array<int>& funcs = mapStruct(b)->funcs(chunk);
00170           int nNodes = nLocalNodesPerChunk(b)[chunk];
00171           for (int f=0; f<nFuncs; f++)
00172           {
00173             os << tab3 << "fid=" << funcs[f] << " dofs=";
00174             int funcOffset = mapStruct(b)->indexForFuncID(funcs[f]);
00175             for (int n=0; n<nNodes; n++)
00176             {
00177               int dof = dofs[chunk][(c*nFuncs+funcOffset)*nNodes+n];
00178               os << setw(6) << dof;
00179               if (n < nNodes-1) os << ", ";
00180             }
00181             os << std::endl;
00182           }
00183         }
00184       }
00185       
00186     }
00187     os << tab0 << "] ### End LocalDOFMap" << std::endl;
00188   }
00189   return os;
00190 }

Site Contact