Nektar++
Loading...
Searching...
No Matches
NekLinSysIterGMRES.h
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: NekLinSysIterGMRES.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// License for the specific language governing rights and limitations under
14// Permission is hereby granted, free of charge, to any person obtaining a
15// copy of this software and associated documentation files (the "Software"),
16// to deal in the Software without restriction, including without limitation
17// the rights to use, copy, modify, merge, publish, distribute, sublicense,
18// and/or sell copies of the Software, and to permit persons to whom the
19// Software is furnished to do so, subject to the following conditions:
20//
21// The above copyright notice and this permission notice shall be included
22// in all copies or substantial portions of the Software.
23//
24// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30// DEALINGS IN THE SOFTWARE.
31//
32// Description: NekLinSysIterGMRES header
33//
34///////////////////////////////////////////////////////////////////////////////
35
36#ifndef NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_NEK_LINSYS_ITERAT_GMRES_H
37#define NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_NEK_LINSYS_ITERAT_GMRES_H
38
40#include <deque>
41
43{
44/// A global linear system.
46
48{
49public:
50 /// Support creation through MemoryManager.
52
55 const LibUtilities::CommSharedPtr &vRowComm, const int nDimen,
56 const NekSysKey &pKey)
57 {
60 pSession, vRowComm, nDimen, pKey);
61 p->InitObject();
62 return p;
63 }
64
65 static std::string className;
66
69 const LibUtilities::CommSharedPtr &vRowComm, const int nDimen,
70 const NekSysKey &pKey = NekSysKey());
72
77
78 /**
79 * @brief Data exported from GMRES for use by the Newton hook-step solver.
80 * The data stored here correspond to the most recently completed GMRES
81 * restart block.
82 */
84 {
85 /// True if hook step data is usable.
86 bool valid = false;
87 /// Current Krylov subspace dimension, number of done Arnoldi sweeps
88 int nswp = 0;
89 /// Dimension of the system; length of each Krylov vector
90 int nGlobal = 0;
91 /// Offset to the non-Dirichlet part of the vector;
92 /// active size is nGlobal - nDir
93 int nDir = 0;
94 /// Initial residual norm beta used in || beta e_1 - H y ||_2
96
97 /// Arnoldi basis vectors V_0,...,V_m;
98 /// contains nswp + 1 vectors of length nGlobal.
100 /// Arnoldi Hessenberg matrix stored by columns: H[col][row].
101 /// H size is (nswp + 1) x nswp.
103 /// Unconstrained reduced GMRES solution y of size nswp.
105 };
106
107 /**
108 * @brief Enable or disable export of GMRES Arnoldi data for the hook-step
109 * nonlinear solver.
110 * @param flag If true, GMRES exports hook-step data.
111 * @return LIB_UTILITIES_EXPORT
112 */
114 {
115 m_ExportHookData = flag;
116 }
117
118 /**
119 * @brief Get the Hook Data object.
120 * Check if GMRESHookData::valid before using the data.
121 *
122 * @return LIB_UTILITIES_EXPORT const&
123 */
125 {
126 return m_HookData;
127 }
128
130 {
132 }
133
138
141 {
142 Array<OneD, NekDouble> tmpIn(in.size(), 0.0);
143 Vmath::Vcopy(in.size(), in, 1, tmpIn, 1);
144 m_operator.DoNekSysPrecon(tmpIn, out);
145 }
146
147protected:
148 // This is maximum gmres restart iteration
150
151 // This is maximum bandwidth of Hessenburg matrix
152 // if use truncted Gmres(m)
154
155 // This is the maximum number of solution vectors that can be stored
156 // For example, in gmres, it is the max number of Krylov space
157 // search directions can be stored
158 // It determines the max storage usage
160
162
166
167 // True, if GMRES data needs to be exported to compute the hook step
168 bool m_ExportHookData = false;
169 // Hook step data needed to compute the hook step
171
172 void v_InitObject() override;
173
174 int v_SolveSystem(const int nGlobal,
175 const Array<OneD, const NekDouble> &pInput,
176 Array<OneD, NekDouble> &pOutput, const int nDir) override;
177
178 void v_DoIterate(const int nGlobal, const Array<OneD, NekDouble> &rhs,
179 Array<OneD, NekDouble> &x, const int nDir, NekDouble &err,
180 int &iter) override;
181
182private:
183 /// Actual iterative solve-GMRES
184 int DoGMRES(const int pNumRows, const Array<OneD, const NekDouble> &pInput,
185 Array<OneD, NekDouble> &pOutput, const int pNumDir);
186
187 /// Actual iterative gmres solver for one restart
188 NekDouble DoGmresRestart(const unsigned int nrestart, const bool truncted,
189 const int nGlobal,
190 const Array<OneD, const NekDouble> &pInput,
191 Array<OneD, NekDouble> &pOutput, const int nDir);
192
193 // Arnoldi process
194 void DoArnoldi(const int starttem, const int endtem, const int nGlobal,
195 const int nDir, Array<OneD, NekDouble> &w,
196 // V[nd] current search direction
198 // V[nd+1] new search direction
200 // One line of Hessenburg matrix
202
203 // QR fatorization through Givens rotation
204 void DoGivensRotation(const int starttem, const int endtem,
208
209 // Backward calculation to calculate coeficients
210 // of least square problem
211 // To notice, Hessenburg's columnns and rows are reverse
212 void DoBackward(const int number, Array<OneD, Array<OneD, NekDouble>> &A,
215
216 static std::string lookupIds[];
217 static std::string def;
218
219 // Hessenburg matrix
221 // Hesseburg matrix after rotation
223 // Total search directions
226 std::deque<Array<OneD, NekDouble>> m_delta;
227
230};
231} // namespace Nektar::LibUtilities
232
233#endif
#define LIB_UTILITIES_EXPORT
int v_SolveSystem(const int nGlobal, const Array< OneD, const NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const int nDir) override
void DoGivensRotation(const int starttem, const int endtem, Array< OneD, NekDouble > &c, Array< OneD, NekDouble > &s, Array< OneD, NekDouble > &h, Array< OneD, NekDouble > &eta)
Array< OneD, Array< OneD, NekDouble > > m_Z_total
int DoGMRES(const int pNumRows, const Array< OneD, const NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const int pNumDir)
Actual iterative solve-GMRES.
NekDouble DoGmresRestart(const unsigned int nrestart, const bool truncted, const int nGlobal, const Array< OneD, const NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const int nDir)
Actual iterative gmres solver for one restart.
void DoBackward(const int number, Array< OneD, Array< OneD, NekDouble > > &A, const Array< OneD, const NekDouble > &b, Array< OneD, NekDouble > &y)
Array< OneD, Array< OneD, NekDouble > > m_V_total
Array< OneD, Array< OneD, NekDouble > > m_Upper
void EnableHookStepExport(bool flag)
Enable or disable export of GMRES Arnoldi data for the hook-step nonlinear solver.
Array< OneD, Array< OneD, NekDouble > > m_hes
void ApplyRightPrecon(const Array< OneD, const NekDouble > &in, Array< OneD, NekDouble > &out)
const GMRESHookData & GetHookData() const
Get the Hook Data object. Check if GMRESHookData::valid before using the data.
void DoArnoldi(const int starttem, const int endtem, const int nGlobal, const int nDir, Array< OneD, NekDouble > &w, Array< OneD, NekDouble > &V1, Array< OneD, NekDouble > &V2, Array< OneD, NekDouble > &h)
static NekLinSysIterSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession, const LibUtilities::CommSharedPtr &vRowComm, const int nDimen, const NekSysKey &pKey)
void v_DoIterate(const int nGlobal, const Array< OneD, NekDouble > &rhs, Array< OneD, NekDouble > &x, const int nDir, NekDouble &err, int &iter) override
std::deque< Array< OneD, NekDouble > > m_delta
NekSysOperators m_operator
Definition NekSys.h:306
void DoNekSysPrecon(InArrayType &inarray, OutArrayType &outarray, const bool &flag=false) const
Definition NekSys.h:155
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
std::shared_ptr< NekLinSysIter > NekLinSysIterSharedPtr
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition Comm.h:55
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition Vmath.hpp:825
Data exported from GMRES for use by the Newton hook-step solver. The data stored here correspond to t...
NekDouble beta
Initial residual norm beta used in || beta e_1 - H y ||_2.
Array< OneD, Array< OneD, NekDouble > > V
Arnoldi basis vectors V_0,...,V_m; contains nswp + 1 vectors of length nGlobal.
Array< OneD, Array< OneD, NekDouble > > H
Arnoldi Hessenberg matrix stored by columns: H[col][row]. H size is (nswp + 1) x nswp.
Array< OneD, NekDouble > yNewton
Unconstrained reduced GMRES solution y of size nswp.
int nGlobal
Dimension of the system; length of each Krylov vector.
int nDir
Offset to the non-Dirichlet part of the vector; active size is nGlobal - nDir.
int nswp
Current Krylov subspace dimension, number of done Arnoldi sweeps.