AndersonMixer.h 1.59 KB
Newer Older
Francois Gygi committed
1 2
////////////////////////////////////////////////////////////////////////////////
//
Francois Gygi committed
3 4 5 6
// Copyright (c) 2008 The Regents of the University of California
//
// This file is part of Qbox
//
Francois Gygi committed
7 8
// Qbox is distributed under the terms of the GNU General Public License
// as published by the Free Software Foundation, either version 2 of
Francois Gygi committed
9 10 11 12 13 14
// the License, or (at your option) any later version.
// See the file COPYING in the root directory of this distribution
// or <http://www.gnu.org/licenses/>.
//
////////////////////////////////////////////////////////////////////////////////
//
Francois Gygi committed
15 16 17 18 19 20 21
// AndersonMixer.h
//
////////////////////////////////////////////////////////////////////////////////

#ifndef ANDERSONMIXER_H
#define ANDERSONMIXER_H

22
#include <vector>
Francois Gygi committed
23 24
#include <valarray>
#include <cassert>
25 26 27 28 29
#ifdef USE_MPI
#include <mpi.h>
#else
typedef int MPI_Comm;
#endif
Francois Gygi committed
30 31 32

class AndersonMixer
{
33 34 35 36 37 38 39
  // nmax is the dimension of the subspace of previous search directions
  // nmax=0: use simple mixing (no acceleration)
  // nmax=1: use one previous direction
  int     m_;                    // dimension of vectors
  int     nmax_;                 // maximum number of vectors (without current)
  int     n_;                    // number of vectors
  int     k_;                    // index of current vector
40 41 42
  const   MPI_Comm* const pcomm_;// pointer to relevant Context, null if local
  int     mype_;
  int     npes_;
43

44
  std::vector<std::valarray<double> > x_,f_;
Francois Gygi committed
45 46

  public:
47

48
  AndersonMixer(const int m, const int nmax, const MPI_Comm* const pcomm);
49
  void update(double* x, double* f, double* xbar, double* fbar);
Francois Gygi committed
50 51 52
  void restart(void);
};
#endif