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