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), m_base(stdExpansion.GetBase()),
52  m_ncoeffs(stdExpansion.GetNcoeffs()), m_matrixType(matrixType),
53  m_nodalPointsType(nodalType), m_factors(factorMap),
54  m_varcoeffs(varCoeffMap), m_varcoeff_hashes(varCoeffMap.size())
55 {
56  // Create hash
57  int i = 0;
58  for (auto &x : varCoeffMap)
59  {
60  m_varcoeff_hashes[i] = hash_range(x.second.GetValue().begin(),
61  x.second.GetValue().begin() +
62  stdExpansion.GetTotPoints());
63  hash_combine(m_varcoeff_hashes[i], (int)x.first);
64  i++;
65  }
66 }
67 
69  const StdRegions::MatrixType matrixType)
70  : m_shapeType(rhs.m_shapeType), m_base(rhs.m_base),
71  m_ncoeffs(rhs.m_ncoeffs), m_matrixType(matrixType),
72  m_nodalPointsType(rhs.m_nodalPointsType), m_factors(rhs.m_factors),
73  m_varcoeffs(rhs.m_varcoeffs), m_varcoeff_hashes(rhs.m_varcoeff_hashes)
74 {
75 }
76 
78  : m_shapeType(rhs.m_shapeType), m_base(rhs.m_base),
79  m_ncoeffs(rhs.m_ncoeffs), m_matrixType(rhs.m_matrixType),
80  m_nodalPointsType(rhs.m_nodalPointsType), m_factors(rhs.m_factors),
81  m_varcoeffs(rhs.m_varcoeffs), m_varcoeff_hashes(rhs.m_varcoeff_hashes)
82 {
83 }
84 
86  const StdMatrixKey &rhs) const
87 {
88  return (lhs.m_matrixType < rhs.m_matrixType);
89 }
90 
91 bool operator<(const StdMatrixKey &lhs, const StdMatrixKey &rhs)
92 {
93  if (lhs.m_matrixType < rhs.m_matrixType)
94  {
95  return true;
96  }
97 
98  if (lhs.m_matrixType > rhs.m_matrixType)
99  {
100  return false;
101  }
102 
103  if (lhs.m_ncoeffs < rhs.m_ncoeffs) // probably do not need this check since
104  // checking the m_base below?
105  {
106  return true;
107  }
108 
109  if (lhs.m_ncoeffs > rhs.m_ncoeffs)
110  {
111  return false;
112  }
113 
116  {
117  return true;
118  }
119 
122  {
123  return false;
124  }
125 
126  for (unsigned int i = 0; i < LibUtilities::ShapeTypeDimMap[lhs.m_shapeType];
127  ++i)
128  {
129  if (lhs.m_base[i].get() < rhs.m_base[i].get())
130  {
131  return true;
132  }
133 
134  if (lhs.m_base[i].get() > rhs.m_base[i].get())
135  {
136  return false;
137  }
138  }
139 
140  if (lhs.m_factors.size() < rhs.m_factors.size())
141  {
142  return true;
143  }
144  else if (lhs.m_factors.size() > rhs.m_factors.size())
145  {
146  return false;
147  }
148  else
149  {
150  for (auto x = lhs.m_factors.begin(), y = rhs.m_factors.begin();
151  x != lhs.m_factors.end(); ++x, ++y)
152  {
153  if (x->second < y->second)
154  {
155  return true;
156  }
157  if (x->second > y->second)
158  {
159  return false;
160  }
161  }
162  }
163 
164  if (lhs.m_varcoeffs.size() < rhs.m_varcoeffs.size())
165  {
166  return true;
167  }
168 
169  if (lhs.m_varcoeffs.size() > rhs.m_varcoeffs.size())
170  {
171  return false;
172  }
173 
174  for (unsigned int i = 0; i < lhs.m_varcoeff_hashes.size(); ++i)
175  {
176  if (lhs.m_varcoeff_hashes[i] < rhs.m_varcoeff_hashes[i])
177  {
178  return true;
179  }
180  if (lhs.m_varcoeff_hashes[i] > rhs.m_varcoeff_hashes[i])
181  {
182  return false;
183  }
184  }
185 
186  if (lhs.m_nodalPointsType < rhs.m_nodalPointsType)
187  {
188  return true;
189  }
190 
191  if (lhs.m_nodalPointsType > rhs.m_nodalPointsType)
192  {
193  return false;
194  }
195 
196  return false;
197 }
198 
199 bool operator==(const StdMatrixKey &lhs, const StdMatrixKey &rhs)
200 {
201  if (lhs.m_matrixType != rhs.m_matrixType)
202  {
203  return false;
204  }
205 
206  if (lhs.m_ncoeffs != rhs.m_ncoeffs)
207  {
208  return false;
209  }
210 
211  for (unsigned int i = 0; i < LibUtilities::ShapeTypeDimMap[lhs.m_shapeType];
212  ++i)
213  {
214  if (lhs.m_base[i].get() != rhs.m_base[i].get())
215  {
216  return false;
217  }
218  }
219 
220  if (lhs.m_factors.size() != rhs.m_factors.size())
221  {
222  return false;
223  }
224  else
225  {
226  return lhs.m_factors.size() == rhs.m_factors.size() &&
227  std::equal(lhs.m_factors.begin(), lhs.m_factors.end(),
228  rhs.m_factors.begin());
229  }
230 
231  if (lhs.m_nodalPointsType != rhs.m_nodalPointsType)
232  {
233  return false;
234  }
235 
236  if (lhs.m_varcoeffs.size() != rhs.m_varcoeffs.size())
237  {
238  return false;
239  }
240 
241  for (unsigned int i = 0; i < lhs.m_varcoeff_hashes.size(); ++i)
242  {
243  if (lhs.m_varcoeff_hashes[i] != rhs.m_varcoeff_hashes[i])
244  {
245  return false;
246  }
247  }
248 
249  for (auto &x : lhs.m_varcoeffs)
250  {
251  auto y = rhs.m_varcoeffs.find(x.first);
252  // Check var coeff is found
253  if (y == rhs.m_varcoeffs.end())
254  {
255  return false;
256  }
257 
258  if (x.second.GetValue() != y->second.GetValue())
259  {
260  return false;
261  }
262  }
263  for (unsigned int i = 0; i < lhs.m_varcoeffs.size(); ++i)
264  {
265  if (lhs.m_varcoeff_hashes[i] != rhs.m_varcoeff_hashes[i])
266  {
267  return false;
268  }
269  }
270 
271  return true;
272 }
273 
274 std::ostream &operator<<(std::ostream &os, const StdMatrixKey &rhs)
275 {
276  os << "MatrixType: " << MatrixTypeMap[rhs.GetMatrixType()]
277  << ", ShapeType: " << LibUtilities::ShapeTypeMap[rhs.GetShapeType()]
278  << ", Ncoeffs: " << rhs.GetNcoeffs() << std::endl;
279 
280  if (rhs.GetConstFactors().size())
281  {
282  os << "Constants: " << endl;
283  for (auto &x : rhs.GetConstFactors())
284  {
285  os << "\t value " << ConstFactorTypeMap[x.first] << " : "
286  << x.second << endl;
287  }
288  }
289  if (rhs.GetVarCoeffs().size())
290  {
291  os << "Variable coefficients: " << endl;
292  unsigned int i = 0;
293  for (auto &x : rhs.GetVarCoeffs())
294  {
295  os << "\t Coeff defined: " << VarCoeffTypeMap[x.first] << endl;
296  os << "\t Hash: " << rhs.GetVarCoeffHashes()[i++] << endl;
297  }
298  }
299 
300  for (unsigned int i = 0;
302  {
303  os << rhs.GetBase()[i]->GetBasisKey();
304  }
305 
306  return os;
307 }
308 } // namespace StdRegions
309 } // namespace Nektar
The base class for all shapes.
Definition: StdExpansion.h:71
int GetTotPoints() const
This function returns the total number of quadrature points used in the element.
Definition: StdExpansion.h:140
const ConstFactorMap & GetConstFactors() const
Definition: StdMatrixKey.h:140
friend bool operator<(const StdMatrixKey &lhs, const StdMatrixKey &rhs)
Used for finding value given the key in NekManager.
const Array< OneD, const LibUtilities::BasisSharedPtr > & GetBase() const
Definition: StdMatrixKey.h:105
std::vector< std::size_t > GetVarCoeffHashes() const
Definition: StdMatrixKey.h:111
LibUtilities::ShapeType GetShapeType() const
Definition: StdMatrixKey.h:90
LibUtilities::PointsType m_nodalPointsType
Definition: StdMatrixKey.h:187
const VarCoeffMap & GetVarCoeffs() const
Definition: StdMatrixKey.h:171
Array< OneD, const LibUtilities::BasisSharedPtr > m_base
Definition: StdMatrixKey.h:183
MatrixType GetMatrixType() const
Definition: StdMatrixKey.h:85
friend bool operator==(const StdMatrixKey &lhs, const StdMatrixKey &rhs)
LibUtilities::ShapeType m_shapeType
Definition: StdMatrixKey.h:182
std::vector< std::size_t > m_varcoeff_hashes
Definition: StdMatrixKey.h:192
const char *const ShapeTypeMap[SIZE_ShapeType]
Definition: ShapeType.hpp:79
constexpr unsigned int ShapeTypeDimMap[SIZE_ShapeType]
Definition: ShapeType.hpp:85
const char *const VarCoeffTypeMap[]
Definition: StdRegions.hpp:232
const char *const ConstFactorTypeMap[]
Definition: StdRegions.hpp:382
std::ostream & operator<<(std::ostream &os, const StdMatrixKey &rhs)
const char *const MatrixTypeMap[]
Definition: StdRegions.hpp:143
std::map< ConstFactorType, NekDouble > ConstFactorMap
Definition: StdRegions.hpp:399
std::map< StdRegions::VarCoeffType, VarCoeffEntry > VarCoeffMap
Definition: StdRegions.hpp:343
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
std::size_t hash_range(Iter first, Iter last)
Definition: HashUtils.hpp:68
void hash_combine(std::size_t &seed)
Definition: HashUtils.hpp:46
bool operator()(const StdMatrixKey &lhs, const StdMatrixKey &rhs) const