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