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
37using namespace std;
38
39namespace Nektar
40{
41namespace 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 */
57 const AssemblyMapSharedPtr &locToGloMap,
59 const StdRegions::VarCoeffMap &varCoeffs,
60 const VarFactorsMap &varFactors)
61 : GlobalMatrixKey(matrixType, locToGloMap, factors, varCoeffs),
62 m_solnType(eNoSolnType), m_varFactors(varFactors),
63 m_varFactors_hashes(varFactors.size())
64{
65 // Create hash
66 int i = 0;
67 for (VarFactorsMap::const_iterator x = varFactors.begin();
68 x != varFactors.end(); ++x)
69 {
71 x->second.begin(), x->second.begin() + x->second.size());
73 i++;
74 }
75
76 // Check AssemblyMapSharedPtr == Null
77 if (locToGloMap != NullAssemblyMapSharedPtr)
78 {
79 m_solnType = locToGloMap->GetGlobalSysSolnType();
80 }
81}
82
83/**
84 * @param key Existing key to duplicate.
85 */
87 : GlobalMatrixKey(key), m_solnType(key.m_solnType),
88 m_varFactors(key.m_varFactors),
89 m_varFactors_hashes(key.m_varFactors_hashes)
90{
91}
92
93/**
94 *
95 */
97{
98}
99
100/**
101 * Compares two GlobalLinSysKeys by comparing their solution types and
102 * matrix keys.
103 * @param lhs First operand.
104 * @param rhs Second operand.
105 * @returns true if the first operand is considered less than the
106 * second operand.
107 */
108bool operator<(const GlobalLinSysKey &lhs, const GlobalLinSysKey &rhs)
109{
110 if (lhs.m_solnType < rhs.m_solnType)
111 {
112 return true;
113 }
114
115 if (lhs.m_solnType > rhs.m_solnType)
116 {
117 return false;
118 }
119
120 if (lhs.m_varFactors.size() < rhs.m_varFactors.size())
121 {
122 return true;
123 }
124
125 if (lhs.m_varFactors.size() > rhs.m_varFactors.size())
126 {
127 return false;
128 }
129
130 for (unsigned int i = 0; i < lhs.m_varFactors_hashes.size(); ++i)
131 {
132 if (lhs.m_varFactors_hashes[i] < rhs.m_varFactors_hashes[i])
133 {
134 return true;
135 }
136 if (lhs.m_varFactors_hashes[i] > rhs.m_varFactors_hashes[i])
137 {
138 return false;
139 }
140 }
141
142 return (*dynamic_cast<const GlobalMatrixKey *>(&lhs) <
143 *dynamic_cast<const GlobalMatrixKey *>(&rhs));
144}
145
146/**
147 * Writes the vital statistics of a global linear system to a stream.
148 * @param os Output stream.
149 * @param rhs GlobalLinSys object to use.
150 * @returns Reference to the output stream \a os.
151 */
152std::ostream &operator<<(std::ostream &os, const GlobalLinSysKey &rhs)
153{
154 os << "MatrixType: " << StdRegions::MatrixTypeMap[rhs.GetMatrixType()]
155 << ", ShapeType: " << LibUtilities::ShapeTypeMap[rhs.GetShapeType()]
156 << std::endl;
157 os << "Solution Type: " << GlobalSysSolnTypeMap[rhs.GetGlobalSysSolnType()]
158 << endl;
159 os << "Number of constants: " << rhs.GetNConstFactors() << endl;
160 for (auto &x : rhs.GetConstFactors())
161 {
162 os << " Constant " << StdRegions::ConstFactorTypeMap[x.first] << ": "
163 << x.second << endl;
164 }
165 os << "Number of variable coefficients: " << rhs.GetNVarCoeffs() << endl;
166
167 os << "Number of variable factors : " << rhs.GetNVarFactors() << endl;
168
169 return os;
170}
171} // namespace MultiRegions
172} // 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:79
std::ostream & operator<<(std::ostream &os, const GlobalLinSysKey &rhs)
Writes information about the object to a given stream.
@ eNoSolnType
No Solution type specified.
static AssemblyMapSharedPtr NullAssemblyMapSharedPtr
Definition: AssemblyMap.h:53
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:52
const char *const ConstFactorTypeMap[]
Definition: StdRegions.hpp:391
const char *const MatrixTypeMap[]
Definition: StdRegions.hpp:145
std::map< ConstFactorType, NekDouble > ConstFactorMap
Definition: StdRegions.hpp:408
std::map< StdRegions::VarCoeffType, VarCoeffEntry > VarCoeffMap
Definition: StdRegions.hpp:352
StdRegions::ConstFactorMap factors
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
std::size_t hash_range(Iter first, Iter last)
Definition: HashUtils.hpp:68
void hash_combine(std::size_t &seed)
Definition: HashUtils.hpp:46