Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
StdMatrixKey.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File StdMatrixKey.cpp
4 //
5 // For more information, please see: http://www.nektar.info
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: Definition of StdMatrixKey
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
37 #include <boost/functional/hash.hpp>
39 
40 using namespace std;
41 
42 namespace Nektar
43 {
44  namespace StdRegions
45  {
46  StdMatrixKey::StdMatrixKey(const MatrixType matrixType,
47  const LibUtilities::ShapeType shapeType,
48  const StdExpansion &stdExpansion,
49  const ConstFactorMap &factorMap,
50  const VarCoeffMap &varCoeffMap,
51  LibUtilities::PointsType nodalType) :
52  m_shapeType(shapeType),
53  m_base(stdExpansion.GetBase()),
54  m_ncoeffs(stdExpansion.GetNcoeffs()),
55  m_matrixType(matrixType),
56  m_nodalPointsType(nodalType),
57  m_factors(factorMap),
58  m_varcoeffs(varCoeffMap),
59  m_varcoeff_hashes(varCoeffMap.size())
60  {
61  // Create hash
62  int i = 0;
63  for (VarCoeffMap::const_iterator x = varCoeffMap.begin(); x != varCoeffMap.end(); ++x)
64  {
65  m_varcoeff_hashes[i] = boost::hash_range(x->second.begin(), x->second.begin() + stdExpansion.GetTotPoints());
66  boost::hash_combine(m_varcoeff_hashes[i], (int)x->first);
67  i++;
68  }
69  }
70 
72  const StdRegions::MatrixType matrixType) :
73  m_shapeType(rhs.m_shapeType),
74  m_base(rhs.m_base),
75  m_ncoeffs(rhs.m_ncoeffs),
76  m_matrixType(matrixType),
77  m_nodalPointsType(rhs.m_nodalPointsType),
78  m_factors(rhs.m_factors),
79  m_varcoeffs(rhs.m_varcoeffs),
80  m_varcoeff_hashes(rhs.m_varcoeff_hashes)
81  {
82  }
83 
85  m_shapeType(rhs.m_shapeType),
86  m_base(rhs.m_base),
87  m_ncoeffs(rhs.m_ncoeffs),
88  m_matrixType(rhs.m_matrixType),
89  m_nodalPointsType(rhs.m_nodalPointsType),
90  m_factors(rhs.m_factors),
91  m_varcoeffs(rhs.m_varcoeffs),
92  m_varcoeff_hashes(rhs.m_varcoeff_hashes)
93  {
94  }
95 
96 
98  {
99  return (lhs.m_matrixType < rhs.m_matrixType);
100  }
101 
102  bool operator<(const StdMatrixKey &lhs, const StdMatrixKey &rhs)
103  {
104  if(lhs.m_matrixType < rhs.m_matrixType)
105  {
106  return true;
107  }
108 
109  if(lhs.m_matrixType > rhs.m_matrixType)
110  {
111  return false;
112  }
113 
114  if(lhs.m_ncoeffs < rhs.m_ncoeffs) // probably do not need this check since checking the m_base below?
115  {
116  return true;
117  }
118 
119  if(lhs.m_ncoeffs > rhs.m_ncoeffs)
120  {
121  return false;
122  }
123 
124  for(unsigned int i = 0; i < LibUtilities::ShapeTypeDimMap[lhs.m_shapeType]; ++i)
125  {
126  if(lhs.m_base[i].get() < rhs.m_base[i].get())
127  {
128  return true;
129  }
130 
131  if(lhs.m_base[i].get() > rhs.m_base[i].get())
132  {
133  return false;
134  }
135  }
136 
137  if(lhs.m_factors.size() < rhs.m_factors.size())
138  {
139  return true;
140  }
141  else if(lhs.m_factors.size() > rhs.m_factors.size())
142  {
143  return false;
144  }
145  else
146  {
147  ConstFactorMap::const_iterator x, y;
148  for(x = lhs.m_factors.begin(), y = rhs.m_factors.begin();
149  x != lhs.m_factors.end(); ++x, ++y)
150  {
151  if (x->second < y->second)
152  {
153  return true;
154  }
155  if (x->second > y->second)
156  {
157  return false;
158  }
159  }
160  }
161 
162  if(lhs.m_varcoeffs.size() < rhs.m_varcoeffs.size())
163  {
164  return true;
165  }
166 
167  if(lhs.m_varcoeffs.size() > rhs.m_varcoeffs.size())
168  {
169  return false;
170  }
171 
172  for (unsigned int i = 0; i < lhs.m_varcoeff_hashes.size(); ++i)
173  {
174  if(lhs.m_varcoeff_hashes[i] < rhs.m_varcoeff_hashes[i])
175  {
176  return true;
177  }
178  if(lhs.m_varcoeff_hashes[i] > rhs.m_varcoeff_hashes[i])
179  {
180  return false;
181  }
182  }
183 
185  {
186  return true;
187  }
188 
190  {
191  return false;
192  }
193 
194  return false;
195  }
196 
197  bool operator==(const StdMatrixKey &lhs, const StdMatrixKey &rhs)
198  {
199  if(lhs.m_matrixType != rhs.m_matrixType)
200  {
201  return false;
202  }
203 
204  if(lhs.m_ncoeffs != rhs.m_ncoeffs)
205  {
206  return false;
207  }
208 
209  for(unsigned int i = 0; i < LibUtilities::ShapeTypeDimMap[lhs.m_shapeType]; ++i)
210  {
211  if(lhs.m_base[i].get() != rhs.m_base[i].get())
212  {
213  return false;
214  }
215  }
216 
217  if(lhs.m_factors.size() != rhs.m_factors.size())
218  {
219  return false;
220  }
221  else
222  {
223  ConstFactorMap::const_iterator x, y;
224  for(x = lhs.m_factors.begin(), y = rhs.m_factors.begin();
225  x != lhs.m_factors.end(); ++x, ++y)
226  {
227  if (x->second != y->second)
228  {
229  return false;
230  }
231  }
232  }
233 
234  if(lhs.m_nodalPointsType != rhs.m_nodalPointsType)
235  {
236  return false;
237  }
238 
239  if(lhs.m_varcoeffs.size() != rhs.m_varcoeffs.size())
240  {
241  return false;
242  }
243 
244  for (unsigned int i = 0; i < lhs.m_varcoeff_hashes.size(); ++i)
245  {
246  if(lhs.m_varcoeff_hashes[i] != rhs.m_varcoeff_hashes[i])
247  {
248  return false;
249  }
250  }
251 
252  VarCoeffMap::const_iterator x;
253  for (x = lhs.m_varcoeffs.begin(); x != lhs.m_varcoeffs.end(); ++x)
254  {
255  VarCoeffMap::const_iterator y;
256  // Check var coeff is found
257  if ((y = rhs.m_varcoeffs.find(x->first)) == rhs.m_varcoeffs.end())
258  {
259  return false;
260  }
261 
262  if (x->second != y->second)
263  {
264  return false;
265  }
266  }
267  for (unsigned int i = 0; i < lhs.m_varcoeffs.size(); ++i)
268  {
269  if(lhs.m_varcoeff_hashes[i] != rhs.m_varcoeff_hashes[i])
270  {
271  return false;
272  }
273  }
274 
275  return true;
276  }
277 
278  std::ostream& operator<<(std::ostream& os, const StdMatrixKey& rhs)
279  {
280  os << "MatrixType: " << MatrixTypeMap[rhs.GetMatrixType()] << ", ShapeType: "
281  << LibUtilities::ShapeTypeMap[rhs.GetShapeType()] << ", Ncoeffs: " << rhs.GetNcoeffs()
282  << std::endl;
283 
284  if(rhs.GetConstFactors().size())
285  {
286  os << "Constants: " << endl;
287  ConstFactorMap::const_iterator x;
288  for(x = rhs.GetConstFactors().begin(); x != rhs.GetConstFactors().end(); ++x)
289  {
290  os << "\t value " << ConstFactorTypeMap[x->first] <<" : " << x->second << endl;
291  }
292  }
293  if(rhs.GetVarCoeffs().size())
294  {
295  os << "Variable coefficients: " << endl;
296  VarCoeffMap::const_iterator x;
297  unsigned int i = 0;
298  for (x = rhs.GetVarCoeffs().begin(); x != rhs.GetVarCoeffs().end(); ++x)
299  {
300  os << "\t Coeff defined: " << VarCoeffTypeMap[x->first] << endl;
301  os << "\t Hash: " << rhs.GetVarCoeffHashes()[i++] << endl;
302  }
303  }
304 
305  for(unsigned int i = 0; i < LibUtilities::ShapeTypeDimMap[rhs.GetShapeType()]; ++i)
306  {
307  os << rhs.GetBase()[i]->GetBasisKey();
308  }
309 
310  return os;
311  }
312  }
313 }
std::vector< std::size_t > GetVarCoeffHashes() const
Definition: StdMatrixKey.h:107
const ConstFactorMap & GetConstFactors() const
Definition: StdMatrixKey.h:142
const VarCoeffMap & GetVarCoeffs() const
Definition: StdMatrixKey.h:168
MatrixType GetMatrixType() const
Definition: StdMatrixKey.h:82
friend bool operator==(const StdMatrixKey &lhs, const StdMatrixKey &rhs)
std::ostream & operator<<(std::ostream &os, const IndexMapKey &rhs)
std::vector< std::size_t > m_varcoeff_hashes
Definition: StdMatrixKey.h:189
STL namespace.
LibUtilities::ShapeType GetShapeType() const
Definition: StdMatrixKey.h:87
std::map< ConstFactorType, NekDouble > ConstFactorMap
Definition: StdRegions.hpp:252
const char *const ConstFactorTypeMap[]
Definition: StdRegions.hpp:242
const char *const ShapeTypeMap[]
Definition: ShapeType.hpp:66
StandardMatrixTag & lhs
friend bool operator<(const StdMatrixKey &lhs, const StdMatrixKey &rhs)
Used for finding value given the key in NekManager.
LibUtilities::PointsType m_nodalPointsType
Definition: StdMatrixKey.h:184
int GetTotPoints() const
This function returns the total number of quadrature points used in the element.
Definition: StdExpansion.h:141
The base class for all shapes.
Definition: StdExpansion.h:69
std::map< StdRegions::VarCoeffType, Array< OneD, NekDouble > > VarCoeffMap
Definition: StdRegions.hpp:227
Array< OneD, const LibUtilities::BasisSharedPtr > m_base
Definition: StdMatrixKey.h:180
const char *const MatrixTypeMap[]
Definition: StdRegions.hpp:152
bool operator()(const StdMatrixKey &lhs, const StdMatrixKey &rhs) const
LibUtilities::ShapeType m_shapeType
Definition: StdMatrixKey.h:179
const char *const VarCoeffTypeMap[]
Definition: StdRegions.hpp:214
const Array< OneD, const LibUtilities::BasisSharedPtr > & GetBase() const
Definition: StdMatrixKey.h:102
const unsigned int ShapeTypeDimMap[SIZE_ShapeType]
Definition: ShapeType.hpp:81