AndersonMixer.h 1.24 KB
Newer Older
Francois Gygi committed
1 2 3 4 5
////////////////////////////////////////////////////////////////////////////////
//
// AndersonMixer.h
//
////////////////////////////////////////////////////////////////////////////////
6
// $Id: AndersonMixer.h,v 1.3 2004-12-18 23:23:27 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
21 22
  double  theta_max_; // maximum extrapolation
  double  theta_nc_;  // negative curvature value
Francois Gygi committed
23
 
24 25
  valarray<double> flast_;       // last residual
  bool extrapolate_;             // state variable
Francois Gygi committed
26 27

  public:
28 29

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