AndersonMixer.h 1.04 KB
Newer Older
Francois Gygi committed
1 2 3 4 5
////////////////////////////////////////////////////////////////////////////////
//
// AndersonMixer.h
//
////////////////////////////////////////////////////////////////////////////////
6
// $Id: AndersonMixer.h,v 1.2 2004-12-10 01:04:06 fgygi Exp $
Francois Gygi committed
7 8 9 10 11 12 13 14 15 16 17 18

#ifndef ANDERSONMIXER_H
#define ANDERSONMIXER_H

#include <valarray>
#include <cassert>
using namespace std;

#include "Context.h"

class AndersonMixer
{
19 20
  int     n_;                    // size of vectors
  const   Context* const pctxt_; // pointer to relevant Context, null if local
Francois Gygi committed
21 22
  double  theta_max_;
 
23 24
  valarray<double> flast_;       // last residual
  bool extrapolate_;             // state variable
Francois Gygi committed
25 26

  public:
27 28 29

  AndersonMixer(const int n, const Context* const pctxt) :
    n_(n), pctxt_(pctxt), extrapolate_(false), theta_max_(2.0)
Francois Gygi committed
30 31 32 33 34 35 36 37 38 39 40
  {
    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; }
  double theta_max(void) const { return theta_max_; }
};
#endif