00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
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 }
00152