AndersonMixer.h 1.22 KB
Newer Older
Francois Gygi committed
1 2 3 4 5
////////////////////////////////////////////////////////////////////////////////
//
// AndersonMixer.h
//
////////////////////////////////////////////////////////////////////////////////
6
// $Id: AndersonMixer.h,v 1.4 2007-03-17 01:14:00 fgygi Exp $
Francois Gygi committed
7 8 9 10 11 12 13 14 15 16

#ifndef ANDERSONMIXER_H
#define ANDERSONMIXER_H

#include <valarray>
#include <cassert>
#include "Context.h"

class AndersonMixer
{
17 18
  int     n_;                    // size of vectors
  const   Context* const pctxt_; // pointer to relevant Context, null if local
19 20
  double  theta_max_; // maximum extrapolation
  double  theta_nc_;  // negative curvature value
Francois Gygi committed
21
 
22
  std::valarray<double> flast_;       // last residual
23
  bool extrapolate_;             // state variable
Francois Gygi committed
24 25

  public:
26 27

  AndersonMixer(const int n, const Context* const pctxt) :
28
    n_(n), pctxt_(pctxt), extrapolate_(false), theta_max_(2.0), theta_nc_(0.0)
Francois Gygi committed
29 30 31 32 33 34 35 36
  {
    assert( n > 0 );
    flast_.resize(n);
  }

  void update(const double* f, double* theta, double* fbar);
  void restart(void);
  void set_theta_max(double theta_max) { theta_max_ = theta_max; }
37
  void set_theta_nc(double theta_nc) { theta_nc_ = theta_nc; }
Francois Gygi committed
38
  double theta_max(void) const { return theta_max_; }
39
  double theta_nc(void) const { return theta_nc_; }
Francois Gygi committed
40 41
};
#endif