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

Site Contact