Nektar++
GlobalLinSys.h
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: GlobalLinSys.h
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: GlobalLinSys header
32//
33///////////////////////////////////////////////////////////////////////////////
34#ifndef NEKTAR_LIB_MULTIREGIONS_GLOBALLINSYS_H
35#define NEKTAR_LIB_MULTIREGIONS_GLOBALLINSYS_H
36
42
43namespace Nektar
44{
45namespace MultiRegions
46{
47// Forward declarations
48class ExpList;
49class GlobalLinSys;
50class Preconditioner;
51
52/// Pointer to a GlobalLinSys object.
53typedef std::shared_ptr<GlobalLinSys> GlobalLinSysSharedPtr;
54/// Mapping between GlobalLinSys objects and their associated keys.
55typedef std::map<GlobalLinSysKey, GlobalLinSysSharedPtr> GlobalLinSysMap;
56/// Pointer to a GlobalLinSys/key map.
57typedef std::shared_ptr<GlobalLinSysMap> GlobalLinSysMapShPtr;
58
59// Forward declaration
60typedef std::shared_ptr<Preconditioner> PreconditionerSharedPtr;
61
62/// Datatype of the NekFactory used to instantiate classes derived from
63/// the EquationSystem class.
65 std::string, GlobalLinSys, const GlobalLinSysKey &,
66 const std::weak_ptr<ExpList> &, const std::shared_ptr<AssemblyMap> &>
69
70/// A global linear system.
71class GlobalLinSys : public std::enable_shared_from_this<GlobalLinSys>
72{
73public:
74 /// Constructor for full direct matrix solve.
76 const GlobalLinSysKey &pKey, const std::weak_ptr<ExpList> &pExpList,
77 const std::shared_ptr<AssemblyMap> &pLocToGloMap);
78
80 virtual ~GlobalLinSys()
81 {
82 }
83
84 /// Returns the key associated with the system.
85 const inline GlobalLinSysKey &GetKey(void) const;
86
87 // Returns the local matrix associated with the system
88 const inline std::weak_ptr<ExpList> &GetLocMat(void) const;
89
90 inline void InitObject();
91 inline void Initialise(const std::shared_ptr<AssemblyMap> &pLocToGloMap);
92
93 /// Solve the linear system for given input and output vectors
94 /// using a specified local to global map.
96 inline void Solve(
98 const AssemblyMapSharedPtr &locToGloMap,
100
101 /// Returns a shared pointer to the current object.
102 std::shared_ptr<GlobalLinSys> GetSharedThisPtr()
103 {
104 return shared_from_this();
105 }
106
107 inline int GetNumBlocks();
108 inline DNekScalMatSharedPtr GetBlock(unsigned int n);
109 inline void DropBlock(unsigned int n);
110 inline DNekScalBlkMatSharedPtr GetStaticCondBlock(unsigned int n);
111 inline void DropStaticCondBlock(unsigned int n);
112
113 /// Solve the linear system for given input and output vectors.
114 inline void SolveLinearSystem(const int pNumRows,
115 const Array<OneD, const NekDouble> &pInput,
116 Array<OneD, NekDouble> &pOutput,
117 const AssemblyMapSharedPtr &locToGloMap,
118 const int pNumDir = 0);
119
120protected:
121 /// Key associated with this linear system.
123 /// Local Matrix System
124 const std::weak_ptr<ExpList> m_expList;
125 /// Robin boundary info
126 const std::map<int, RobinBCInfoSharedPtr> m_robinBCInfo;
127 // Provide verbose output
129
130 /// Solve a linear system based on mapping.
131 virtual void v_Solve(const Array<OneD, const NekDouble> &in,
133 const AssemblyMapSharedPtr &locToGloMap,
134 const Array<OneD, const NekDouble> &dirForcing =
136
137 /// Solve a basic matrix system.
138 virtual void v_SolveLinearSystem(const int pNumRows,
139 const Array<OneD, const NekDouble> &pInput,
140 Array<OneD, NekDouble> &pOutput,
141 const AssemblyMapSharedPtr &locToGloMap,
142 const int pNumDir) = 0;
143
144 virtual void v_InitObject();
145 virtual void v_Initialise(const std::shared_ptr<AssemblyMap> &pLocToGloMap);
146
147 virtual int v_GetNumBlocks();
148 virtual DNekScalMatSharedPtr v_GetBlock(unsigned int n);
149 virtual void v_DropBlock(unsigned int n);
150 virtual DNekScalBlkMatSharedPtr v_GetStaticCondBlock(unsigned int n);
151 virtual void v_DropStaticCondBlock(unsigned int n);
152
154
155private:
157
158 static std::string lookupIds[];
159 static std::string def;
160};
161
162/**
163 *
164 */
165const inline GlobalLinSysKey &GlobalLinSys::GetKey(void) const
166{
167 return m_linSysKey;
168}
169
170/**
171 *
172 */
173const inline std::weak_ptr<ExpList> &GlobalLinSys::GetLocMat(void) const
174{
175 return m_expList;
176}
177
178/**
179 *
180 */
183 const AssemblyMapSharedPtr &locToGloMap,
184 const Array<OneD, const NekDouble> &dirForcing)
185{
186 v_Solve(in, out, locToGloMap, dirForcing);
187}
188
189/**
190 *
191 */
193 const int pNumRows, const Array<OneD, const NekDouble> &pInput,
194 Array<OneD, NekDouble> &pOutput, const AssemblyMapSharedPtr &locToGloMap,
195 const int pNumDir)
196{
197 v_SolveLinearSystem(pNumRows, pInput, pOutput, locToGloMap, pNumDir);
198}
199
201{
202 v_InitObject();
203}
204
206 const std::shared_ptr<AssemblyMap> &pLocToGloMap)
207{
208 v_Initialise(pLocToGloMap);
209}
210
212{
213 return v_GetBlock(n);
214}
215
216inline void GlobalLinSys::DropBlock(unsigned int n)
217{
218 return v_DropBlock(n);
219}
220
222{
223 return v_GetStaticCondBlock(n);
224}
225
226inline void GlobalLinSys::DropStaticCondBlock(unsigned int n)
227{
228 return v_DropStaticCondBlock(n);
229}
230
232{
233 return v_GetNumBlocks();
234}
235} // namespace MultiRegions
236} // namespace Nektar
237
238#endif
#define MULTI_REGIONS_EXPORT
Provides a generic Factory class.
Definition: NekFactory.hpp:105
A global linear system.
Definition: GlobalLinSys.h:72
virtual void v_SolveLinearSystem(const int pNumRows, const Array< OneD, const NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const AssemblyMapSharedPtr &locToGloMap, const int pNumDir)=0
Solve a basic matrix system.
virtual int v_GetNumBlocks()
Get the number of blocks in this system.
const std::weak_ptr< ExpList > m_expList
Local Matrix System.
Definition: GlobalLinSys.h:124
void DropStaticCondBlock(unsigned int n)
Definition: GlobalLinSys.h:226
static std::string lookupIds[]
Definition: GlobalLinSys.h:158
LocalRegions::MatrixKey GetBlockMatrixKey(unsigned int n)
std::shared_ptr< GlobalLinSys > GetSharedThisPtr()
Returns a shared pointer to the current object.
Definition: GlobalLinSys.h:102
const GlobalLinSysKey & GetKey(void) const
Returns the key associated with the system.
Definition: GlobalLinSys.h:165
const std::map< int, RobinBCInfoSharedPtr > m_robinBCInfo
Robin boundary info.
Definition: GlobalLinSys.h:126
virtual void v_Solve(const Array< OneD, const NekDouble > &in, Array< OneD, NekDouble > &out, const AssemblyMapSharedPtr &locToGloMap, const Array< OneD, const NekDouble > &dirForcing=NullNekDouble1DArray)=0
Solve a linear system based on mapping.
GlobalLinSys(const GlobalLinSysKey &pKey, const std::weak_ptr< ExpList > &pExpList, const std::shared_ptr< AssemblyMap > &pLocToGloMap)
Constructor for full direct matrix solve.
void Solve(const Array< OneD, const NekDouble > &in, Array< OneD, NekDouble > &out, const AssemblyMapSharedPtr &locToGloMap, const Array< OneD, const NekDouble > &dirForcing=NullNekDouble1DArray)
Solve the linear system for given input and output vectors using a specified local to global map.
Definition: GlobalLinSys.h:181
void SolveLinearSystem(const int pNumRows, const Array< OneD, const NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const AssemblyMapSharedPtr &locToGloMap, const int pNumDir=0)
Solve the linear system for given input and output vectors.
Definition: GlobalLinSys.h:192
const GlobalLinSysKey m_linSysKey
Key associated with this linear system.
Definition: GlobalLinSys.h:122
virtual DNekScalMatSharedPtr v_GetBlock(unsigned int n)
Retrieves the block matrix from n-th expansion using the matrix key provided by the m_linSysKey.
DNekScalMatSharedPtr GetBlock(unsigned int n)
Definition: GlobalLinSys.h:211
virtual void v_DropBlock(unsigned int n)
Releases the local block matrix from NekManager of n-th expansion using the matrix key provided by th...
const std::weak_ptr< ExpList > & GetLocMat(void) const
Definition: GlobalLinSys.h:173
PreconditionerSharedPtr CreatePrecon(AssemblyMapSharedPtr asmMap)
Create a preconditioner object from the parameters defined in the supplied assembly map.
virtual DNekScalBlkMatSharedPtr v_GetStaticCondBlock(unsigned int n)
Retrieves a the static condensation block matrices from n-th expansion using the matrix key provided ...
virtual void v_Initialise(const std::shared_ptr< AssemblyMap > &pLocToGloMap)
virtual void v_DropStaticCondBlock(unsigned int n)
Releases the static condensation block matrices from NekManager of n-th expansion using the matrix ke...
void Initialise(const std::shared_ptr< AssemblyMap > &pLocToGloMap)
Definition: GlobalLinSys.h:205
DNekScalBlkMatSharedPtr GetStaticCondBlock(unsigned int n)
Definition: GlobalLinSys.h:221
void DropBlock(unsigned int n)
Definition: GlobalLinSys.h:216
LibUtilities::NekFactory< std::string, GlobalLinSys, const GlobalLinSysKey &, const std::weak_ptr< ExpList > &, const std::shared_ptr< AssemblyMap > & > GlobalLinSysFactory
Datatype of the NekFactory used to instantiate classes derived from the EquationSystem class.
Definition: GlobalLinSys.h:67
std::shared_ptr< GlobalLinSys > GlobalLinSysSharedPtr
Pointer to a GlobalLinSys object.
Definition: GlobalLinSys.h:53
std::map< GlobalLinSysKey, GlobalLinSysSharedPtr > GlobalLinSysMap
Mapping between GlobalLinSys objects and their associated keys.
Definition: GlobalLinSys.h:55
GlobalLinSysFactory & GetGlobalLinSysFactory()
std::shared_ptr< Preconditioner > PreconditionerSharedPtr
Definition: GlobalLinSys.h:60
std::shared_ptr< AssemblyMap > AssemblyMapSharedPtr
Definition: AssemblyMap.h:52
std::shared_ptr< GlobalLinSysMap > GlobalLinSysMapShPtr
Pointer to a GlobalLinSys/key map.
Definition: GlobalLinSys.h:57
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
std::shared_ptr< DNekScalMat > DNekScalMatSharedPtr
std::shared_ptr< DNekScalBlkMat > DNekScalBlkMatSharedPtr
Definition: NekTypeDefs.hpp:79
static Array< OneD, NekDouble > NullNekDouble1DArray