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

Site Contact