Nektar++
GlobalLinSysKey.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File GlobalLinSysKey.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 GlobalLinSysKey
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
35 
37 
38 using namespace std;
39 
40 namespace Nektar
41 {
42  namespace MultiRegions
43  {
44  /**
45  * @class GlobalLinSysKey
46  *
47  * This class represents a global linear system and is in essence a
48  * wrapper around a global matrix key, augmenting it with a specific
49  * solution type from GlobalSysSolnType. Each constructor accepts a
50  * MatrixType, describing the matrix to be constructed, a
51  * AssemblyMap, defining the mapping from the local elemental
52  * expansions to a global system, and a GlobalSysSolnType, defining the
53  * type of solution (e.g. full matrix, static condenstation). Some
54  * constructors include additional parameters for customising the
55  * global operator matrix.
56  */
57 
58  GlobalLinSysKey::GlobalLinSysKey(const StdRegions::MatrixType matrixType,
59  const AssemblyMapSharedPtr &locToGloMap,
60  const StdRegions::ConstFactorMap &factors,
61  const StdRegions::VarCoeffMap &varCoeffs,
62  const VarFactorsMap &varFactors) :
63  GlobalMatrixKey(matrixType, locToGloMap, factors, varCoeffs),
64  m_solnType(locToGloMap->GetGlobalSysSolnType()),
65  m_varFactors(varFactors),
66  m_varFactors_hashes(varFactors.size())
67  {
68  // Create hash
69  int i = 0;
70  for (VarFactorsMap::const_iterator x = varFactors.begin();
71  x != varFactors.end(); ++x)
72  {
73  m_varFactors_hashes[i] = boost::hash_range(x->second.begin(),
74  x->second.begin() + x->second.num_elements());
75  boost::hash_combine(m_varFactors_hashes[i], (int)x->first);
76  i++;
77  }
78  }
79 
80 
81  /**
82  * @param key Existing key to duplicate.
83  */
85  GlobalMatrixKey(key),
89  {
90  }
91 
92 
93  /**
94  *
95  */
97  {
98  }
99 
100 
101  /**
102  * Compares two GlobalLinSysKeys by comparing their solution types and
103  * matrix keys.
104  * @param lhs First operand.
105  * @param rhs Second operand.
106  * @returns true if the first operand is considered less than the
107  * second operand.
108  */
110  {
111  if(lhs.m_solnType < rhs.m_solnType)
112  {
113  return true;
114  }
115 
116  if(lhs.m_solnType > rhs.m_solnType)
117  {
118  return false;
119  }
120 
121  if(lhs.m_varFactors.size() < rhs.m_varFactors.size())
122  {
123  return true;
124  }
125 
126  if(lhs.m_varFactors.size() > rhs.m_varFactors.size())
127  {
128  return false;
129  }
130 
131  for (unsigned int i = 0; i < lhs.m_varFactors_hashes.size(); ++i)
132  {
133  if(lhs.m_varFactors_hashes[i] < rhs.m_varFactors_hashes[i])
134  {
135  return true;
136  }
137  if(lhs.m_varFactors_hashes[i] > rhs.m_varFactors_hashes[i])
138  {
139  return false;
140  }
141  }
142 
143  return (*dynamic_cast<const GlobalMatrixKey*>(&lhs)
144  < *dynamic_cast<const GlobalMatrixKey*>(&rhs));
145  }
146 
147 
148  /**
149  * Writes the vital statistics of a global linear system to a stream.
150  * @param os Output stream.
151  * @param rhs GlobalLinSys object to use.
152  * @returns Reference to the output stream \a os.
153  */
154  std::ostream& operator<<(std::ostream& os, const GlobalLinSysKey& rhs)
155  {
156  os << "MatrixType: " << StdRegions::MatrixTypeMap[rhs.GetMatrixType()] << ", ShapeType: "
158  << std::endl;
159  os << "Solution Type: "
160  << GlobalSysSolnTypeMap[rhs.GetGlobalSysSolnType()] << endl;
161  os << "Number of constants: " << rhs.GetNConstFactors() << endl;
162  for (auto &x : rhs.GetConstFactors())
163  {
164  os << " Constant " << StdRegions::ConstFactorTypeMap[x.first]
165  << ": " << x.second << endl;
166  }
167  os << "Number of variable coefficients: "
168  << rhs.GetNVarCoeffs() << endl;
169 
170  os << "Number of variable factors : "
171  << rhs.GetNVarFactors() << endl;
172 
173  return os;
174  }
175  }
176 }
std::size_t hash_range(Iter first, Iter last)
Definition: HashUtils.hpp:69
std::vector< std::size_t > m_varFactors_hashes
GlobalSysSolnType m_solnType
Store the solution type associated with the linear system. This may be none, full matrix...
const StdRegions::ConstFactorMap & GetConstFactors() const
Returns all the constants.
friend bool operator<(const GlobalLinSysKey &lhs, const GlobalLinSysKey &rhs)
Less-than operator for GlobalLinSysKey comparison.
STL namespace.
void hash_combine(std::size_t &seed)
Definition: HashUtils.hpp:46
std::map< ConstFactorType, NekDouble > ConstFactorMap
Definition: StdRegions.hpp:294
const char *const ConstFactorTypeMap[]
Definition: StdRegions.hpp:282
const char *const ShapeTypeMap[]
Definition: ShapeType.hpp:67
StandardMatrixTag & lhs
std::shared_ptr< AssemblyMap > AssemblyMapSharedPtr
Definition: AssemblyMap.h:52
const char *const GlobalSysSolnTypeMap[]
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
GlobalLinSysKey(const StdRegions::MatrixType matrixType, const AssemblyMapSharedPtr &locToGloMap=NullAssemblyMapSharedPtr, const StdRegions::ConstFactorMap &factors=StdRegions::NullConstFactorMap, const StdRegions::VarCoeffMap &varCoeffs=StdRegions::NullVarCoeffMap, const VarFactorsMap &varFactos=NullVarFactorsMap)
const char *const MatrixTypeMap[]
Definition: StdRegions.hpp:149
LibUtilities::ShapeType GetShapeType() const
Return the expansion type associated with key.
Describe a linear system.
Describes a matrix with ordering defined by a local to global map.
int GetNConstFactors() const
Returns the number of constants defined for this matrix.
GlobalSysSolnType GetGlobalSysSolnType() const
Return the associated solution type.
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs
std::map< StdRegions::ConstFactorType, Array< OneD, NekDouble > > VarFactorsMap