35 #ifndef MADNESS_LINALG_GMRES_H__INCLUDED
36 #define MADNESS_LINALG_GMRES_H__INCLUDED
69 virtual void action(
const T &in,
T &out)
const = 0;
101 template <
typename T,
typename real_type,
typename scalar_type>
123 virtual real_type
norm(
const T &)
const = 0;
129 virtual T &
scale(
T &,
const scalar_type &)
const = 0;
135 virtual T &
gaxpy(
T &x,
const scalar_type &
a,
const T &y,
136 const scalar_type &
b)
const = 0;
139 virtual scalar_type
inner(
const T &,
const T &)
const = 0;
151 static inline double real(
double x) {
return x; }
156 static inline double imag(
double x) {
return 0.0; }
159 template <
typename T,
int NDIM>
161 typename TensorTypeData<T>::float_scalar_type, T> {
188 for(i = 1; i <
NDIM; ++i) {
212 for(
int i = 0; i <
NDIM; ++i)
213 x[i] = a * x[i] + b * y[i];
223 ret =
conj(l[0]) * r[0];
224 for(
int i = 1; i <
NDIM; ++i)
225 ret +=
conj(l[i]) * r[i];
229 for(
int i = 1; i <
NDIM; ++i)
238 template <
typename T,
int NDIM>
240 typename TensorTypeData<T>::float_scalar_type, T> {
285 template <
typename T,
int VDIM,
int FDIM>
287 Vector<Function<T, FDIM>, VDIM>,
288 typename TensorTypeData<T>::float_scalar_type, T> {
304 real_type temp, ret =
vec[0].norm2();
306 for(
int i = 1; i < VDIM; ++i) {
307 temp =
vec[i].norm2();
315 const scalar_type &
c)
const {
317 for(
int i = 0; i < VDIM; ++i)
324 const scalar_type &
a,
326 const scalar_type &
b)
const {
328 for(
int i = 0; i < VDIM; ++i)
329 x[i].
gaxpy(a, y[i], b);
337 scalar_type ret = l[0].inner(r[0]);
338 for(
int i = 0; i < VDIM; ++i)
339 ret += l[i].
inner(r[i]);
345 for(
int i = 0; i < VDIM; ++i)
386 template <
typename T,
typename real_type,
typename scalar_type>
389 real_type &resid_thresh, real_type &update_thresh,
390 const bool outp =
false) {
396 Tensor<scalar_type> H(maxiters+1, maxiters);
397 Tensor<scalar_type> betae(maxiters+1);
398 Tensor<scalar_type> y, yold;
400 Tensor<real_type> sumsq;
401 real_type resid,
norm, updatenorm;
411 space.
gaxpy(r, -1.0, b, 1.0);
412 betae[0] = resid = space.
norm(r);
413 if(outp && world.
rank() == 0)
414 printf(
"itr rnk update_norm resid\n%.3d N/A N/A %.6e\n",
416 if(resid < resid_thresh) {
418 resid_thresh = resid;
422 space.
scale(r, 1.0 / resid);
431 for(i = 0; i < iter; ++i) {
432 H(i, iter-1) = space.
inner(V[i], r);
433 space.
gaxpy(r, 1.0, V[i], -H(i, iter-1));
435 H(iter, iter-1) = norm = space.
norm(r);
438 space.
scale(r, 1.0 / norm);
443 1.0e-12, y, s, rank, sumsq);
454 updatenorm = y.normf();
456 scalar_type temp = y[0] - yold[0];
458 for(i = 1; i < iter-1; ++i) {
459 temp = y[i] - yold[i];
460 updatenorm +=
real(temp)*
real(temp) +
463 updatenorm +=
real(y[iter-1]) *
real(y[iter-1]) +
465 updatenorm =
sqrt(updatenorm);
475 space.
gaxpy(x, 1.0, V[0], betae[0]);
477 space.
gaxpy(r, -1.0, b, 1.0);
478 resid_thresh = space.
norm(r);
479 update_thresh = updatenorm;
484 if(outp && world.
rank() == 0)
485 printf(
"%.3d N/A %.6e %.6e ** Zero Vector Encount" \
486 "ered **\n", iter, updatenorm, resid_thresh);
490 if(outp && world.
rank() == 0)
491 printf(
"%.3d %.3ld %.6e %.6e ** Zero Vector Encount" \
492 "ered **\n", iter, rank, updatenorm, resid);
496 if(outp && world.
rank() == 0) {
497 printf(
"%.3d %.3ld %.6e %.6e", iter, rank, updatenorm, resid);
499 printf(
" ** Questionable Progress **");
504 }
while(iter <= maxiters && resid > resid_thresh &&
505 updatenorm > update_thresh);
508 for(i = 0; i < iter; ++i) {
509 space.
gaxpy(x, 1.0, V[i], y[i]);
513 resid_thresh = resid;
514 update_thresh = updatenorm;
520 #endif // MADNESS_LINALG_GMRES_H__INCLUDED
TensorTypeData< T >::float_scalar_type real_type
Definition: gmres.h:291
virtual real_type norm(const T &) const =0
The norm of a vector.
virtual ~FunctionSpace()
Definition: gmres.h:249
virtual ~AbstractVectorSpace()
Definition: gmres.h:120
virtual Vector< scalar_type, NDIM > & scale(Vector< scalar_type, NDIM > &vec, const scalar_type &c) const
Scales the vector (in-place) by a constant .
Definition: gmres.h:200
VectorOfFunctionsSpace(World &world)
Definition: gmres.h:294
T norm(Vector< T, N > v)
Compute norm of a Vector.
Definition: array.h:447
World & world
The world.
Definition: gmres.h:109
double imag(double x)
Definition: complexfun.h:56
virtual scalar_type inner(const Function< scalar_type, NDIM > &l, const Function< scalar_type, NDIM > &r) const
The inner product between two vectors.
Definition: gmres.h:273
virtual scalar_type inner(const T &, const T &) const =0
The inner product between two vectors.
virtual Function< scalar_type, NDIM > & gaxpy(Function< scalar_type, NDIM > &x, const scalar_type &a, const Function< scalar_type, NDIM > &y, const scalar_type &b) const
Standard bilinear gaxpy .
Definition: gmres.h:264
const int NDIM
Definition: tdse1.cc:44
virtual void action(const T &in, T &out) const =0
The action of the operator.
A simple, fixed dimension Coordinate.
Definition: array.h:99
void gelss(const Tensor< T > &a, const Tensor< T > &b, double rcond, Tensor< T > &x, Tensor< typename Tensor< T >::scalar_type > &s, long &rank, Tensor< typename Tensor< T >::scalar_type > &sumsq)
Solve Ax = b for general A using the LAPACK *gelss routines.
Definition: lapack.cc:393
T scalar_type
Definition: gmres.h:168
virtual scalar_type inner(const Vector< scalar_type, NDIM > &l, const Vector< scalar_type, NDIM > &r) const
The inner product between two vectors.
Definition: gmres.h:217
virtual void destroy(Vector< Function< scalar_type, FDIM >, VDIM > &f) const
Any special instructions to be executed when a vector is no longer needed.
Definition: gmres.h:343
double V(const Vector< double, 3 > &r)
Definition: apps/ii/hatom_energy.cc:46
NDIM & f
Definition: mra.h:2179
static const bool iscplx
Definition: gmres.h:164
virtual scalar_type inner(const Vector< Function< scalar_type, FDIM >, VDIM > &l, const Vector< Function< scalar_type, FDIM >, VDIM > &r) const
The inner product between two vectors.
Definition: gmres.h:333
virtual ~Operator()
Definition: gmres.h:83
Function< T, NDIM > & scale(const Q q, bool fence=true)
Inplace, scale the function by a constant. No communication except for optional fence.
Definition: mra.h:896
VectorSpace(World &world)
Definition: gmres.h:170
Defines and implements most of Tensor.
virtual real_type norm(const Vector< scalar_type, NDIM > &vec) const
The norm of a vector.
Definition: gmres.h:175
T scalar_type
Definition: gmres.h:292
double norm2() const
Returns the 2-norm of the function ... global sum ... works in either basis.
Definition: mra.h:650
const T1 &f1 return GTEST_2_TUPLE_() T(f0, f1)
A vector space using MADNESS Vectors.
Definition: gmres.h:160
A vector space using MADNESS Vectors of MADNESS Functions.
Definition: gmres.h:286
Vector< T, 1 > vec(T x)
Your friendly neighborhood factory function.
Definition: array.h:456
void clear(bool fence=true)
Clears the function as if constructed uninitialized. Optional fence.
Definition: mra.h:799
T scalar_type
Definition: gmres.h:244
virtual Vector< Function< scalar_type, FDIM >, VDIM > & scale(Vector< Function< scalar_type, FDIM >, VDIM > &vec, const scalar_type &c) const
Scales the vector (in-place) by a constant .
Definition: gmres.h:313
Function< T, NDIM > copy(const Function< T, NDIM > &f, const std::shared_ptr< WorldDCPmapInterface< Key< NDIM > > > &pmap, bool fence=true)
Create a new copy of the function with different distribution and optional fence. ...
Definition: mra.h:1835
virtual T & scale(T &, const scalar_type &) const =0
Scales the vector (in-place) by a constant .
Prototypes for a partial interface from Tensor to LAPACK.
FLOAT a(int j, FLOAT z)
Definition: y1.cc:86
virtual Vector< scalar_type, NDIM > & gaxpy(Vector< scalar_type, NDIM > &x, const scalar_type &a, const Vector< scalar_type, NDIM > &y, const scalar_type &b) const
Standard bilinear gaxpy .
Definition: gmres.h:207
A vector space using MADNESS Functions.
Definition: gmres.h:239
A generic vector space which provides common operations needed by linear algebra routines (norm...
Definition: gmres.h:102
virtual Function< scalar_type, NDIM > & scale(Function< scalar_type, NDIM > &vec, const scalar_type &c) const
Scales the vector (in-place) by a constant .
Definition: gmres.h:257
AbstractVectorSpace(World &world)
Make a vector space.
Definition: gmres.h:118
tensorT sqrt(const tensorT &s, double tol=1e-8)
Computes matrix square root (not used any more?)
Definition: DFcode/moldft.cc:446
A parallel world with full functionality wrapping an MPI communicator.
Definition: worldfwd.h:416
A multiresolution adaptive numerical function.
Definition: derivative.h:61
TensorTypeData< T >::float_scalar_type real_type
Definition: gmres.h:243
ProcessID rank() const
Returns the process rank in this world (same as MPI_Comm_rank()))
Definition: worldfwd.h:526
Defines simple templates for printing to std::cout "a la Python".
double real(double x)
Definition: complexfun.h:52
void GMRES(const AbstractVectorSpace< T, real_type, scalar_type > &space, const Operator< T > &op, const T &b, T &x, int &maxiters, real_type &resid_thresh, real_type &update_thresh, const bool outp=false)
A GMRES solver routine for linear systems, .
Definition: gmres.h:387
virtual ~VectorOfFunctionsSpace()
Definition: gmres.h:298
FunctionSpace(World &world)
Definition: gmres.h:246
Function< T, NDIM > & gaxpy(const T &alpha, const Function< Q, NDIM > &other, const R &beta, bool fence=true)
Inplace, general bi-linear operation in wavelet basis. No communication except for optional fence...
Definition: mra.h:924
virtual real_type norm(const Function< scalar_type, NDIM > &vec) const
The norm of a vector.
Definition: gmres.h:251
virtual void destroy(Function< scalar_type, NDIM > &f) const
Any special instructions to be executed when a vector is no longer needed.
Definition: gmres.h:279
virtual ~VectorSpace()
Definition: gmres.h:173
virtual T & gaxpy(T &x, const scalar_type &a, const T &y, const scalar_type &b) const =0
Standard bilinear gaxpy .
Tensor< double > op(const Tensor< double > &x)
Definition: kain.cc:508
virtual real_type norm(const Vector< Function< scalar_type, FDIM >, VDIM > &vec) const
The norm of a vector.
Definition: gmres.h:300
TensorTypeData< T >::float_scalar_type real_type
Definition: gmres.h:167
A slice defines a sub-range or patch of a dimension.
Definition: slice.h:103
virtual void destroy(T &) const
Any special instructions to be executed when a vector is no longer needed.
Definition: gmres.h:145
T & applyOp(const T &in, T &out) const
Public access to the operator's action, returns out for convenience.
Definition: gmres.h:78
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces.
Definition: chem/atomutil.cc:45
A generic operator: takes in one T and produces another T.
Definition: gmres.h:62
const double c
Definition: gfit.cc:200
FLOAT b(int j, FLOAT z)
Definition: y1.cc:79
Traits class to specify support of numeric types.
Definition: type_data.h:56
virtual Vector< Function< scalar_type, FDIM >, VDIM > & gaxpy(Vector< Function< scalar_type, FDIM >, VDIM > &x, const scalar_type &a, const Vector< Function< scalar_type, FDIM >, VDIM > &y, const scalar_type &b) const
Standard bilinear gaxpy .
Definition: gmres.h:322
Function< T, NDIM > conj(const Function< T, NDIM > &f, bool fence=true)
Return the complex conjugate of the input function with the same distribution and optional fence...
Definition: mra.h:1879