Go to the documentation of this file.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
00032
00033
00034
00035
00036
00037
00038
00039
00040
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 }
00163