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