SundanceMapStructure.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 "SundanceMapStructure.hpp"
00032 #include "PlayaTabs.hpp"
00033 #include "PlayaExceptions.hpp"
00034 #include "SundanceBasisDOFTopologyBase.hpp"
00035 #include "SundanceOut.hpp"
00036 
00037 
00038 namespace Sundance
00039 {
00040 using namespace Teuchos;
00041 using std::endl;
00042 using std::setw;
00043 
00044 MapStructure::MapStructure(int nTotalFuncs,
00045                            const Array<RCP<BasisDOFTopologyBase> >& bases,
00046                            const Array<Array<int> >& funcs)
00047 {
00048   init(nTotalFuncs, bases, funcs);
00049 }
00050 
00051 
00052 MapStructure::MapStructure(int nTotalFuncs,
00053                            const RCP<BasisDOFTopologyBase>& bases,
00054                            const Array<Array<int> >& funcs)
00055 {
00056   init(nTotalFuncs, replicate(bases, funcs.size()), funcs);
00057 }
00058 
00059 MapStructure::MapStructure(int nTotalFuncs,
00060                            const RCP<BasisDOFTopologyBase>& bases)
00061 {
00062   Array<int> f(nTotalFuncs);
00063   for (int i=0; i<nTotalFuncs; i++) f[i] = i;
00064   init(nTotalFuncs, tuple(bases), tuple(f));
00065 }
00066 
00067 
00068 
00069 void MapStructure::init(int nTotalFuncs,
00070                         const Array<RCP<BasisDOFTopologyBase> >& bases,
00071                         const Array<Array<int> >& funcs)
00072 {
00073   bases_ = bases;
00074   funcs_ = funcs;
00075   chunkForFuncID_.resize(nTotalFuncs);
00076   indexForFuncID_.resize(nTotalFuncs);
00077 
00078   TEUCHOS_TEST_FOR_EXCEPTION(bases.size() != funcs.size(), std::logic_error,
00079                      "mismatched number of basis chunks=" << bases.size()
00080                      << " and number of function chunks=" << funcs.size());
00081 
00082   for (int f=0; f<indexForFuncID_.size(); f++) 
00083     {
00084       indexForFuncID_[f] = -1;
00085       chunkForFuncID_[f] = -1;
00086     }
00087 
00088   for (int b=0; b<funcs_.size(); b++)
00089     {
00090       for (int f=0; f<funcs_[b].size(); f++)
00091         {
00092           int fid = funcs_[b][f];
00093           TEUCHOS_TEST_FOR_EXCEPTION(fid >= nTotalFuncs, std::logic_error,
00094                              "bad funcID=" << fid 
00095                              << ". nTotalFuncs=" << nTotalFuncs);
00096           indexForFuncID_[fid] = f;
00097           chunkForFuncID_[fid] = b;
00098         }
00099     }
00100 }
00101 
00102 int MapStructure::chunkForFuncID(int funcID) const 
00103 {
00104   int rtn = chunkForFuncID_[funcID];
00105   TEUCHOS_TEST_FOR_EXCEPTION(rtn < 0, std::logic_error,
00106                      "funcID=" << funcID << " not defined in map chunk."
00107                      " The functions defined there are " 
00108                      << funcs_ << ". The most likely cause of this error is "
00109                      "that you are trying to access a discrete function on "
00110                      "subdomain for which it is not defined.");
00111   return rtn;
00112 }
00113 
00114 int MapStructure::indexForFuncID(int funcID) const 
00115 {
00116   int rtn = indexForFuncID_[funcID];
00117   TEUCHOS_TEST_FOR_EXCEPTION(rtn < 0, std::logic_error,
00118                      "funcID=" << funcID << " not defined in map chunk."
00119                      " The functions defined there are " 
00120                      << funcs_ << ". The most likely cause of this error is "
00121                      "that you are trying to access a discrete function on "
00122                      "subdomain for which it is not defined.");
00123 
00124   return rtn;
00125 }
00126 
00127 
00128 std::ostream& MapStructure::print(std::ostream& os) const
00129 {
00130   Tabs tab;
00131   os << tab << "Map structure: nChunks=" << numBasisChunks() << std::endl;
00132   for (int c=0; c<numBasisChunks(); c++) 
00133   {
00134     Tabs tab1;
00135     os << tab1 << "chunk " << c << " funcIDs=" << funcs(c) << std::endl;
00136   }
00137   os << tab << "## end map structure" << std::endl;
00138   return os;
00139 }
00140 
00141 
00142 Array<RCP<BasisDOFTopologyBase> > replicate(
00143   const RCP<BasisDOFTopologyBase>& model,
00144   int n)
00145 {
00146   Array<RCP<BasisDOFTopologyBase> > rtn(n);
00147   for (int i=0; i<n; i++) rtn[i] = model;
00148   return rtn;
00149 }
00150 
00151 } // end namespace Sundance
00152 

Site Contact