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