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