33 #ifndef __H__UG__LIB_DISC__OPERATOR__LINEAR_OPERATOR__GMRES__
34 #define __H__UG__LIB_DISC__OPERATOR__LINEAR_OPERATOR__GMRES__
63 template <
typename TVector>
92 virtual const char*
name()
const {
return "GMRES";}
108 UG_THROW(
"GMRES: Inadequate storage format of Vectors.");
124 std::vector<SmartPtr<vector_type> > v(
m_restart+1);
125 std::vector<std::vector<number> > h(
m_restart+1);
138 if(v[0].invalid()) v[0] = x.clone_without_values();
143 UG_LOG(
"GMRES: Cannot apply preconditioner to b-A*x0.\n");
155 UG_THROW(
"GMRES: Cannot convert v0 to consistent vector.");
162 oldNorm = gamma[0] = v[0]->norm();
165 *v[0] *= 1./gamma[0];
174 if(v[j+1].invalid()) v[j+1] = x.clone_without_values();
178 UG_THROW(
"GMRES: Cannot convert v["<<j+1<<
"] to consistent vector.");
187 UG_LOG(
"GMRES: Cannot apply preconditioner to A*v["<<j<<
"].\n");
199 UG_THROW(
"GMRES: Cannot convert v0 to consistent vector.");
201 UG_THROW(
"GMRES: Cannot convert v["<<j<<
"] to consistent vector.");
208 for(
size_t i = 0; i <= j; ++i)
211 h[i][j] =
VecProd(*v[j+1], *v[i]);
218 h[j+1][j] = v[j+1]->norm();
221 for(
size_t i = 0; i < j; ++i)
223 const number hij = h[i][j];
224 const number hi1j = h[i+1][j];
226 h[i][j] = c[i+1]*hij +
s[i+1]*hi1j;
227 h[i+1][j] =
s[i+1]*hij - c[i+1]*hi1j;
231 const number alpha = sqrt(h[j][j]*h[j][j] + h[j+1][j]*h[j+1][j]);
234 s[j+1] = h[j+1][j] /
alpha;
235 c[j+1] = h[j][j] /
alpha;
239 gamma[j+1] =
s[j+1]*gamma[j];
240 gamma[j] = c[j+1]*gamma[j];
244 UG_LOG(
"% GMRES "<<std::setw(4) <<j+1<<
": "
245 << gamma[j+1] <<
" " << gamma[j+1] / oldNorm);
246 UG_LOG(
" (in Precond-Norm) \n");
247 oldNorm = gamma[j+1];
254 *v[j+1] *= 1./(h[j+1][j]);
258 for(
size_t i = numIter; ; --i){
259 for(
size_t j = i+1; j <= numIter; ++j)
260 gamma[i] -= h[i][j] * gamma[j];
285 std::stringstream ss;
286 ss <<
"GMRes ( restart = " <<
m_restart <<
")\n";
316 s =
" (No Preconditioner) ";
346 for(
size_t i = 0; i < a.size(); ++i)
Definition: smart_pointer.h:108
the GMREs method as a solver for linear operators
Definition: gmres.h:66
void remove_postprocess_corr(SmartPtr< IPProcessVector< vector_type > > p)
removes a post-process for the iterates
Definition: gmres.h:298
virtual std::string config_string() const
returns information about configuration parameters
Definition: gmres.h:283
TVector vector_type
Vector type.
Definition: gmres.h:69
number VecProd(vector_type &a, vector_type &b)
computes the vector product
Definition: gmres.h:355
virtual bool apply_return_defect(vector_type &x, vector_type &b)
Definition: gmres.h:103
size_t m_restart
restart parameter
Definition: gmres.h:322
void prepare_conv_check()
prepares the output of the convergence check
Definition: gmres.h:305
virtual const char * name() const
name of solver
Definition: gmres.h:92
GMRES(size_t restart, SmartPtr< ILinearIterator< vector_type > > spPrecond, SmartPtr< IConvergenceCheck< vector_type > > spConvCheck)
constructor setting the preconditioner and the convergence check
Definition: gmres.h:85
void add_postprocess_corr(SmartPtr< IPProcessVector< vector_type > > p)
adds a post-process for the iterates
Definition: gmres.h:292
virtual bool supports_parallel() const
returns if parallel solving is supported
Definition: gmres.h:95
PProcessChain< vector_type > m_corr_post_process
postprocessor for the correction in the iterations
Definition: gmres.h:330
GMRES(size_t restart)
default constructor
Definition: gmres.h:82
IPreconditionedLinearOperatorInverse< vector_type > base_type
Base type.
Definition: gmres.h:72
SmartPtr< ILinearIterator< X, X > > preconditioner()
Definition: preconditioned_linear_operator_inverse.h:118
bool VecScaleAppend(vector_type &a, vector_type &b, number s)
adds a scaled vector to a second one
Definition: gmres.h:333
Definition: convergence_check.h:72
describes a linear iterator
Definition: linear_iterator.h:81
ConstSmartPtr< IConvergenceCheck< X > > convergence_check() const
returns the convergence check
Definition: linear_operator_inverse.h:202
SmartPtr< ILinearOperator< Y, X > > linear_operator()
returns the current Operator this Inverse Operator is initialized for
Definition: linear_operator_inverse.h:227
interface for pre- and postprocess functions
Definition: pprocess.h:59
describes an inverse linear mapping X->X
Definition: preconditioned_linear_operator_inverse.h:63
virtual bool apply(TVector &x, const TVector &b)
Definition: preconditioned_linear_operator_inverse.h:152
SmartPtr< ILinearIterator< X, X > > preconditioner()
Definition: preconditioned_linear_operator_inverse.h:118
std::string config_string_preconditioner_convergence_check() const
returns config information of convergence check and preconditioner
Definition: preconditioned_linear_operator_inverse.h:200
void add(SmartPtr< p_process_type > p)
adds an operation at the end of the chain
Definition: pprocess.h:96
void apply(vector_type &v)
performs all the operations
Definition: pprocess.h:86
void remove(SmartPtr< p_process_type > p)
removes an operation from the chain
Definition: pprocess.h:108
void write_debug(const vector_type &vec, const char *filename)
writing debug output for a vector (if debug writer set)
Definition: debug_writer.h:293
TVector vector_type
type of vector
Definition: debug_writer.h:269
@ PST_CONSISTENT
Definition: parallel_storage_type.h:68
@ PST_UNIQUE
Definition: parallel_storage_type.h:70
@ PST_ADDITIVE
Definition: parallel_storage_type.h:69
#define UG_THROW(msg)
Definition: error.h:57
#define UG_LOG(msg)
Definition: log.h:367
double number
Definition: types.h:124
void VecScaleAdd(vector_t &vOut, typename vector_t::value_type s1, const vector_t &v1, typename vector_t::value_type s2, const vector_t &v2)
Scales two Vectors, adds them and returns the sum in a third vector.
Definition: math_vector_functions_common_impl.hpp:265
bool resize(size_t newRows, size_t newCols)