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