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