Nektar++
Loading...
Searching...
No Matches
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
39using namespace std;
40
41namespace Nektar::StdRegions
42{
43
45 const LibUtilities::ShapeType shapeType,
46 const StdExpansion &stdExpansion,
47 const ConstFactorMap &factorMap,
48 const VarCoeffMap &varCoeffMap,
49 const VarFactorsMap &varFactorsMap,
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_varfactors(varFactorsMap), m_varcoeffs(varCoeffMap),
55 m_varfactor_hashes(varFactorsMap.size()),
56 m_varcoeff_hashes(varCoeffMap.size())
57{
58 // Create hash
59 int i = 0;
60 for (auto &x : varCoeffMap)
61 {
62 m_varcoeff_hashes[i] = hash_range(x.second.GetValue().begin(),
63 x.second.GetValue().begin() +
64 stdExpansion.GetTotPoints());
65 hash_combine(m_varcoeff_hashes[i], (int)x.first);
66 i++;
67 }
68
69 i = 0;
70 for (auto &x : varFactorsMap)
71 {
72 m_varfactor_hashes[i] = hash_range(x.second.begin(), x.second.end());
73 hash_combine(m_varfactor_hashes[i], (int)x.first);
74 i++;
75 }
76}
77
79 const StdRegions::MatrixType matrixType)
80 : m_shapeType(rhs.m_shapeType), m_base(rhs.m_base),
81 m_ncoeffs(rhs.m_ncoeffs), m_matrixType(matrixType),
82 m_nodalPointsType(rhs.m_nodalPointsType), m_factors(rhs.m_factors),
83 m_varfactors(rhs.m_varfactors), m_varcoeffs(rhs.m_varcoeffs),
84 m_varfactor_hashes(rhs.m_varfactor_hashes),
85 m_varcoeff_hashes(rhs.m_varcoeff_hashes)
86{
87}
88
90 : m_shapeType(rhs.m_shapeType), m_base(rhs.m_base),
91 m_ncoeffs(rhs.m_ncoeffs), m_matrixType(rhs.m_matrixType),
92 m_nodalPointsType(rhs.m_nodalPointsType), m_factors(rhs.m_factors),
93 m_varfactors(rhs.m_varfactors), m_varcoeffs(rhs.m_varcoeffs),
94 m_varfactor_hashes(rhs.m_varfactor_hashes),
95 m_varcoeff_hashes(rhs.m_varcoeff_hashes)
96{
97}
98
100 const StdMatrixKey &rhs) const
101{
102 return (lhs.m_matrixType < rhs.m_matrixType);
103}
104
106{
107 return StdMatrixKey(inKey);
108}
109
110bool operator<(const StdMatrixKey &lhs, const StdMatrixKey &rhs)
111{
112 if (lhs.m_matrixType < rhs.m_matrixType)
113 {
114 return true;
115 }
116
117 if (lhs.m_matrixType > rhs.m_matrixType)
118 {
119 return false;
120 }
121
122 if (lhs.m_ncoeffs < rhs.m_ncoeffs) // probably do not need this check since
123 // checking the m_base below?
124 {
125 return true;
126 }
127
128 if (lhs.m_ncoeffs > rhs.m_ncoeffs)
129 {
130 return false;
131 }
132
135 {
136 return true;
137 }
138
141 {
142 return false;
143 }
144
145 for (unsigned int i = 0; i < LibUtilities::ShapeTypeDimMap[lhs.m_shapeType];
146 ++i)
147 {
148 if (lhs.m_base[i].get() < rhs.m_base[i].get())
149 {
150 return true;
151 }
152
153 if (lhs.m_base[i].get() > rhs.m_base[i].get())
154 {
155 return false;
156 }
157 }
158
159 if (lhs.m_factors.size() < rhs.m_factors.size())
160 {
161 return true;
162 }
163 else if (lhs.m_factors.size() > rhs.m_factors.size())
164 {
165 return false;
166 }
167 else
168 {
169 for (auto x = lhs.m_factors.begin(), y = rhs.m_factors.begin();
170 x != lhs.m_factors.end(); ++x, ++y)
171 {
172 if (x->second < y->second)
173 {
174 return true;
175 }
176 if (x->second > y->second)
177 {
178 return false;
179 }
180 }
181 }
182
183 if (lhs.m_varfactors.size() < rhs.m_varfactors.size())
184 {
185 return true;
186 }
187
188 if (lhs.m_varfactors.size() > rhs.m_varfactors.size())
189 {
190 return false;
191 }
192
193 for (unsigned int i = 0; i < lhs.m_varfactor_hashes.size(); ++i)
194 {
195 if (lhs.m_varfactor_hashes[i] < rhs.m_varfactor_hashes[i])
196 {
197 return true;
198 }
199 if (lhs.m_varfactor_hashes[i] > rhs.m_varfactor_hashes[i])
200 {
201 return false;
202 }
203 }
204
205 if (lhs.m_varcoeffs.size() < rhs.m_varcoeffs.size())
206 {
207 return true;
208 }
209
210 if (lhs.m_varcoeffs.size() > rhs.m_varcoeffs.size())
211 {
212 return false;
213 }
214
215 for (unsigned int i = 0; i < lhs.m_varcoeff_hashes.size(); ++i)
216 {
217 if (lhs.m_varcoeff_hashes[i] < rhs.m_varcoeff_hashes[i])
218 {
219 return true;
220 }
221 if (lhs.m_varcoeff_hashes[i] > rhs.m_varcoeff_hashes[i])
222 {
223 return false;
224 }
225 }
226
228 {
229 return true;
230 }
231
233 {
234 return false;
235 }
236
237 return false;
238}
239
240bool operator==(const StdMatrixKey &lhs, const StdMatrixKey &rhs)
241{
242 if (lhs.m_matrixType != rhs.m_matrixType)
243 {
244 return false;
245 }
246
247 if (lhs.m_ncoeffs != rhs.m_ncoeffs)
248 {
249 return false;
250 }
251
252 for (unsigned int i = 0; i < LibUtilities::ShapeTypeDimMap[lhs.m_shapeType];
253 ++i)
254 {
255 if (lhs.m_base[i].get() != rhs.m_base[i].get())
256 {
257 return false;
258 }
259 }
260
261 if (lhs.m_factors.size() != rhs.m_factors.size())
262 {
263 return false;
264 }
265
266 if (!std::equal(lhs.m_factors.begin(), lhs.m_factors.end(),
267 rhs.m_factors.begin()))
268 {
269 return false;
270 }
271
273 {
274 return false;
275 }
276
277 if (lhs.m_varcoeffs.size() != rhs.m_varcoeffs.size())
278 {
279 return false;
280 }
281
282 if (lhs.m_varfactors.size() != rhs.m_varfactors.size())
283 {
284 return false;
285 }
286
287 for (unsigned int i = 0; i < lhs.m_varfactor_hashes.size(); ++i)
288 {
289 if (lhs.m_varfactor_hashes[i] != rhs.m_varfactor_hashes[i])
290 {
291 return false;
292 }
293 }
294
295 for (unsigned int i = 0; i < lhs.m_varcoeff_hashes.size(); ++i)
296 {
297 if (lhs.m_varcoeff_hashes[i] != rhs.m_varcoeff_hashes[i])
298 {
299 return false;
300 }
301 }
302
303 for (auto &x : lhs.m_varcoeffs)
304 {
305 auto y = rhs.m_varcoeffs.find(x.first);
306 // Check var coeff is found
307 if (y == rhs.m_varcoeffs.end())
308 {
309 return false;
310 }
311
312 if (x.second.GetValue() != y->second.GetValue())
313 {
314 return false;
315 }
316 }
317
318 for (unsigned int i = 0; i < lhs.m_varcoeffs.size(); ++i)
319 {
320 if (lhs.m_varcoeff_hashes[i] != rhs.m_varcoeff_hashes[i])
321 {
322 return false;
323 }
324 }
325
326 return true;
327}
328
329std::ostream &operator<<(std::ostream &os, const StdMatrixKey &rhs)
330{
331 os << "MatrixType: " << MatrixTypeMap[rhs.GetMatrixType()]
332 << ", ShapeType: " << LibUtilities::ShapeTypeMap[rhs.GetShapeType()]
333 << ", Ncoeffs: " << rhs.GetNcoeffs() << std::endl;
334
335 if (rhs.GetConstFactors().size())
336 {
337 os << "Constants: " << endl;
338 for (auto &x : rhs.GetConstFactors())
339 {
340 os << "\t value " << ConstFactorTypeMap[x.first] << " : "
341 << x.second << endl;
342 }
343 }
344 if (rhs.GetVarCoeffs().size())
345 {
346 os << "Variable coefficients: " << endl;
347 unsigned int i = 0;
348 for (auto &x : rhs.GetVarCoeffs())
349 {
350 os << "\t Coeff defined: " << VarCoeffTypeMap[x.first] << endl;
351 os << "\t Hash: " << rhs.GetVarCoeffHashes()[i++] << endl;
352 }
353 }
354
355 for (unsigned int i = 0;
357 {
358 os << rhs.GetBase()[i]->GetBasisKey();
359 }
360
361 return os;
362}
363} // namespace Nektar::StdRegions
The base class for all shapes.
int GetTotPoints() const
This function returns the total number of quadrature points used in the element.
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
LibUtilities::ShapeType GetShapeType() const
LibUtilities::PointsType m_nodalPointsType
StdMatrixKey operator=(const StdMatrixKey &inKey)
Array< OneD, const LibUtilities::BasisSharedPtr > m_base
const VarCoeffMap & GetVarCoeffs() const
MatrixType GetMatrixType() const
const ConstFactorMap & GetConstFactors() const
friend bool operator==(const StdMatrixKey &lhs, const StdMatrixKey &rhs)
std::vector< std::size_t > m_varfactor_hashes
LibUtilities::ShapeType m_shapeType
std::vector< std::size_t > GetVarCoeffHashes() const
std::vector< std::size_t > m_varcoeff_hashes
const char *const ShapeTypeMap[SIZE_ShapeType]
Definition ShapeType.hpp:81
constexpr unsigned int ShapeTypeDimMap[SIZE_ShapeType]
Definition ShapeType.hpp:87
std::map< StdRegions::ConstFactorType, Array< OneD, NekDouble > > VarFactorsMap
const char *const VarCoeffTypeMap[]
const char *const ConstFactorTypeMap[]
std::ostream & operator<<(std::ostream &os, const StdMatrixKey &rhs)
const char *const MatrixTypeMap[]
std::map< ConstFactorType, NekDouble > ConstFactorMap
std::map< StdRegions::VarCoeffType, VarCoeffEntry > VarCoeffMap
std::size_t hash_range(Iter first, Iter last)
Definition HashUtils.hpp:64
void hash_combine(std::size_t &seed)
Definition HashUtils.hpp:44
STL namespace.
bool operator()(const StdMatrixKey &lhs, const StdMatrixKey &rhs) const