Nektar++
GlobalMatrixKey.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: GlobalMatrixKey.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 GlobalMatrixKey
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
36 
37 using namespace std;
38 
39 namespace Nektar
40 {
41 namespace MultiRegions
42 {
43 GlobalMatrixKey::GlobalMatrixKey(const StdRegions::MatrixType matrixType,
44  const AssemblyMapSharedPtr &locToGloMap,
45  const StdRegions::ConstFactorMap &factors,
46  const StdRegions::VarCoeffMap &varCoeffs)
47  : m_matrixType(matrixType), m_shapeType(LibUtilities::eNoShapeType),
48  m_constFactors(factors), m_varCoeffs(varCoeffs),
49  m_locToGloMap(locToGloMap)
50 {
51 }
52 
54  const LibUtilities::ShapeType shapeType)
55  : m_matrixType(key.m_matrixType), m_shapeType(shapeType),
56  m_constFactors(key.m_constFactors), m_varCoeffs(key.m_varCoeffs),
57  m_locToGloMap(key.m_locToGloMap)
58 {
59 }
60 
62  : m_matrixType(key.m_matrixType), m_shapeType(key.m_shapeType),
63  m_constFactors(key.m_constFactors), m_varCoeffs(key.m_varCoeffs),
64  m_locToGloMap(key.m_locToGloMap)
65 {
66 }
67 
69 {
70 }
71 
72 bool operator<(const GlobalMatrixKey &lhs, const GlobalMatrixKey &rhs)
73 {
74  if (lhs.m_matrixType < rhs.m_matrixType)
75  {
76  return true;
77  }
78 
79  if (lhs.m_matrixType > rhs.m_matrixType)
80  {
81  return false;
82  }
83 
84  if (lhs.m_shapeType < rhs.m_shapeType)
85  {
86  return true;
87  }
88 
89  if (lhs.m_shapeType > rhs.m_shapeType)
90  {
91  return false;
92  }
93 
94  if (lhs.m_constFactors.size() < rhs.m_constFactors.size())
95  {
96  return true;
97  }
98  else if (lhs.m_constFactors.size() > rhs.m_constFactors.size())
99  {
100  return false;
101  }
102  else
103  {
104  StdRegions::ConstFactorMap::const_iterator x, y;
105  for (x = lhs.m_constFactors.begin(), y = rhs.m_constFactors.begin();
106  x != lhs.m_constFactors.end(); ++x, ++y)
107  {
108  if (x->second < y->second)
109  {
110  return true;
111  }
112  if (x->second > y->second)
113  {
114  return false;
115  }
116  }
117  }
118 
119  if (lhs.m_varCoeffs.size() < rhs.m_varCoeffs.size())
120  {
121  return true;
122  }
123  else if (lhs.m_varCoeffs.size() > rhs.m_varCoeffs.size())
124  {
125  return false;
126  }
127  else
128  {
129  StdRegions::VarCoeffMap::const_iterator x, y;
130  for (x = lhs.m_varCoeffs.begin(), y = rhs.m_varCoeffs.begin();
131  x != lhs.m_varCoeffs.end(); ++x, ++y)
132  {
133  if (x->second.GetHash() < y->second.GetHash())
134  {
135  return true;
136  }
137  if (x->second.GetHash() > y->second.GetHash())
138  {
139  return false;
140  }
141  }
142  }
143 
144  if (!rhs.m_locToGloMap.lock().get())
145  {
146  return false;
147  }
148  else if (!lhs.m_locToGloMap.lock().get() && rhs.m_locToGloMap.lock().get())
149  {
150  return true;
151  }
152  if (lhs.m_locToGloMap.lock()->GetHash() <
153  rhs.m_locToGloMap.lock()->GetHash())
154  {
155  return true;
156  }
157 
158  return false;
159 }
160 
161 std::ostream &operator<<(std::ostream &os, const GlobalMatrixKey &rhs)
162 {
163  os << "MatrixType: " << rhs.GetMatrixType() << endl;
164  os << "Number of constants: " << rhs.GetNConstFactors() << endl;
165  for (auto &x : rhs.GetConstFactors())
166  {
167  os << " Constant " << StdRegions::ConstFactorTypeMap[x.first] << ": "
168  << x.second << endl;
169  }
170  os << "Number of variable coefficients: " << rhs.GetNVarCoeffs() << endl;
171 
172  return os;
173 }
174 } // namespace MultiRegions
175 } // namespace Nektar
Describes a matrix with ordering defined by a local to global map.
const StdRegions::ConstFactorMap & GetConstFactors() const
Returns all the constants.
int GetNConstFactors() const
Returns the number of constants defined for this matrix.
std::weak_ptr< AssemblyMap > m_locToGloMap
Pointer to the local to global mapping.
StdRegions::MatrixType GetMatrixType() const
Return the matrix type.
LibUtilities::ShapeType m_shapeType
Stores the expansion/shape type that the matrix is to be based on.
GlobalMatrixKey()
Default constructor.
StdRegions::ConstFactorMap m_constFactors
StdRegions::MatrixType m_matrixType
Stores the matrix type based on the enum StdRegions::MatrixType.
std::ostream & operator<<(std::ostream &os, const GlobalLinSysKey &rhs)
Writes information about the object to a given stream.
bool operator<(const GlobalLinSysKey &lhs, const GlobalLinSysKey &rhs)
std::shared_ptr< AssemblyMap > AssemblyMapSharedPtr
Definition: AssemblyMap.h:51
const char *const ConstFactorTypeMap[]
Definition: StdRegions.hpp:382
std::map< ConstFactorType, NekDouble > ConstFactorMap
Definition: StdRegions.hpp:399
std::map< StdRegions::VarCoeffType, VarCoeffEntry > VarCoeffMap
Definition: StdRegions.hpp:343
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2