Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: Definition of StdMatrixKey
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
37 #include <boost/functional/hash.hpp>
39 
40 namespace Nektar
41 {
42  namespace StdRegions
43  {
45  const LibUtilities::ShapeType shapeType,
46  const StdExpansion &stdExpansion,
47  const ConstFactorMap &factorMap,
48  const VarCoeffMap &varCoeffMap,
49  LibUtilities::PointsType nodalType) :
50  m_shapeType(shapeType),
51  m_base(stdExpansion.GetBase()),
52  m_ncoeffs(stdExpansion.GetNcoeffs()),
53  m_matrixType(matrixType),
54  m_nodalPointsType(nodalType),
55  m_factors(factorMap),
56  m_varcoeffs(varCoeffMap),
57  m_varcoeff_hashes(varCoeffMap.size())
58  {
59  // Create hash
60  int i = 0;
61  for (VarCoeffMap::const_iterator x = varCoeffMap.begin(); x != varCoeffMap.end(); ++x)
62  {
63  m_varcoeff_hashes[i] = boost::hash_range(x->second.begin(), x->second.begin() + stdExpansion.GetTotPoints());
64  boost::hash_combine(m_varcoeff_hashes[i], (int)x->first);
65  i++;
66  }
67  }
68 
70  const StdRegions::MatrixType matrixType) :
71  m_shapeType(rhs.m_shapeType),
72  m_base(rhs.m_base),
73  m_ncoeffs(rhs.m_ncoeffs),
74  m_matrixType(matrixType),
75  m_nodalPointsType(rhs.m_nodalPointsType),
76  m_factors(rhs.m_factors),
77  m_varcoeffs(rhs.m_varcoeffs),
78  m_varcoeff_hashes(rhs.m_varcoeff_hashes)
79  {
80  }
81 
83  m_shapeType(rhs.m_shapeType),
84  m_base(rhs.m_base),
85  m_ncoeffs(rhs.m_ncoeffs),
86  m_matrixType(rhs.m_matrixType),
87  m_nodalPointsType(rhs.m_nodalPointsType),
88  m_factors(rhs.m_factors),
89  m_varcoeffs(rhs.m_varcoeffs),
90  m_varcoeff_hashes(rhs.m_varcoeff_hashes)
91  {
92  }
93 
94 
96  {
97  return (lhs.m_matrixType < rhs.m_matrixType);
98  }
99 
100  bool operator<(const StdMatrixKey &lhs, const StdMatrixKey &rhs)
101  {
102  if(lhs.m_matrixType < rhs.m_matrixType)
103  {
104  return true;
105  }
106 
107  if(lhs.m_matrixType > rhs.m_matrixType)
108  {
109  return false;
110  }
111 
112  if(lhs.m_ncoeffs < rhs.m_ncoeffs) // probably do not need this check since checking the m_base below?
113  {
114  return true;
115  }
116 
117  if(lhs.m_ncoeffs > rhs.m_ncoeffs)
118  {
119  return false;
120  }
121 
122  for(unsigned int i = 0; i < LibUtilities::ShapeTypeDimMap[lhs.m_shapeType]; ++i)
123  {
124  if(lhs.m_base[i].get() < rhs.m_base[i].get())
125  {
126  return true;
127  }
128 
129  if(lhs.m_base[i].get() > rhs.m_base[i].get())
130  {
131  return false;
132  }
133  }
134 
135  if(lhs.m_factors.size() < rhs.m_factors.size())
136  {
137  return true;
138  }
139  else if(lhs.m_factors.size() > rhs.m_factors.size())
140  {
141  return false;
142  }
143  else
144  {
145  ConstFactorMap::const_iterator x, y;
146  for(x = lhs.m_factors.begin(), y = rhs.m_factors.begin();
147  x != lhs.m_factors.end(); ++x, ++y)
148  {
149  if (x->second < y->second)
150  {
151  return true;
152  }
153  if (x->second > y->second)
154  {
155  return false;
156  }
157  }
158  }
159 
160  if(lhs.m_varcoeffs.size() < rhs.m_varcoeffs.size())
161  {
162  return true;
163  }
164 
165  if(lhs.m_varcoeffs.size() > rhs.m_varcoeffs.size())
166  {
167  return false;
168  }
169 
170  for (unsigned int i = 0; i < lhs.m_varcoeff_hashes.size(); ++i)
171  {
172  if(lhs.m_varcoeff_hashes[i] < rhs.m_varcoeff_hashes[i])
173  {
174  return true;
175  }
176  if(lhs.m_varcoeff_hashes[i] > rhs.m_varcoeff_hashes[i])
177  {
178  return false;
179  }
180  }
181 
183  {
184  return true;
185  }
186 
188  {
189  return false;
190  }
191 
192  return false;
193  }
194 
195  bool operator==(const StdMatrixKey &lhs, const StdMatrixKey &rhs)
196  {
197  if(lhs.m_matrixType != rhs.m_matrixType)
198  {
199  return false;
200  }
201 
202  if(lhs.m_ncoeffs != rhs.m_ncoeffs)
203  {
204  return false;
205  }
206 
207  for(unsigned int i = 0; i < LibUtilities::ShapeTypeDimMap[lhs.m_shapeType]; ++i)
208  {
209  if(lhs.m_base[i].get() != rhs.m_base[i].get())
210  {
211  return false;
212  }
213  }
214 
215  if(lhs.m_factors.size() != rhs.m_factors.size())
216  {
217  return false;
218  }
219  else
220  {
221  ConstFactorMap::const_iterator x, y;
222  for(x = lhs.m_factors.begin(), y = rhs.m_factors.begin();
223  x != lhs.m_factors.end(); ++x, ++y)
224  {
225  if (x->second != y->second)
226  {
227  return false;
228  }
229  }
230  }
231 
232  if(lhs.m_nodalPointsType != rhs.m_nodalPointsType)
233  {
234  return false;
235  }
236 
237  if(lhs.m_varcoeffs.size() != rhs.m_varcoeffs.size())
238  {
239  return false;
240  }
241 
242  for (unsigned int i = 0; i < lhs.m_varcoeff_hashes.size(); ++i)
243  {
244  if(lhs.m_varcoeff_hashes[i] != rhs.m_varcoeff_hashes[i])
245  {
246  return false;
247  }
248  }
249 
250  VarCoeffMap::const_iterator x;
251  for (x = lhs.m_varcoeffs.begin(); x != lhs.m_varcoeffs.end(); ++x)
252  {
253  VarCoeffMap::const_iterator y;
254  // Check var coeff is found
255  if ((y = rhs.m_varcoeffs.find(x->first)) == rhs.m_varcoeffs.end())
256  {
257  return false;
258  }
259 
260  if (x->second != y->second)
261  {
262  return false;
263  }
264  }
265  for (unsigned int i = 0; i < lhs.m_varcoeffs.size(); ++i)
266  {
267  if(lhs.m_varcoeff_hashes[i] != rhs.m_varcoeff_hashes[i])
268  {
269  return false;
270  }
271  }
272 
273  return true;
274  }
275 
276  std::ostream& operator<<(std::ostream& os, const StdMatrixKey& rhs)
277  {
278  os << "MatrixType: " << MatrixTypeMap[rhs.GetMatrixType()] << ", ShapeType: "
279  << LibUtilities::ShapeTypeMap[rhs.GetShapeType()] << ", Ncoeffs: " << rhs.GetNcoeffs()
280  << std::endl;
281 
282  if(rhs.GetConstFactors().size())
283  {
284  os << "Constants: " << endl;
285  ConstFactorMap::const_iterator x;
286  for(x = rhs.GetConstFactors().begin(); x != rhs.GetConstFactors().end(); ++x)
287  {
288  os << "\t value " << ConstFactorTypeMap[x->first] <<" : " << x->second << endl;
289  }
290  }
291  if(rhs.GetVarCoeffs().size())
292  {
293  os << "Variable coefficients: " << endl;
294  VarCoeffMap::const_iterator x;
295  unsigned int i = 0;
296  for (x = rhs.GetVarCoeffs().begin(); x != rhs.GetVarCoeffs().end(); ++x)
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; i < LibUtilities::ShapeTypeDimMap[rhs.GetShapeType()]; ++i)
304  {
305  os << rhs.GetBase()[i]->GetBasisKey();
306  }
307 
308  return os;
309  }
310  }
311 }