BFGS_Precond.h 4.45 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  crystal growth group                                                  ==
// ==                                                                        ==
// ==  Stiftung caesar                                                       ==
// ==  Ludwig-Erhard-Allee 2                                                 ==
// ==  53175 Bonn                                                            ==
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  http://www.caesar.de/cg/AMDiS                                         ==
// ==                                                                        ==
// ============================================================================

/** \file BFGS_Precond.h */

#ifndef AMDIS_BFGS_PRECONDITIONER_H
#define AMDIS_BFGS_PRECONDITIONER_H

#include "Parameters.h"
#include "Preconditioner.h"
#include "QN_Precond.h"

namespace AMDiS
{

  template<typename T> class DOFVector;
  template<typename T> class OEMSolver;

  // ============================================================================
  // ===== class BFGS_Vectors ===================================================
  // ============================================================================

  // Auxiliar class por storing pairs of DOFVectors and their scalar products.
  class BFGS_Vectors
  {
  public:
    MEMORY_MANAGED(BFGS_Vectors);

    /** \brief
     * Constructor.
     */
  BFGS_Vectors(const FiniteElemSpace *fe_space)
    : s(fe_space, "BFGS->s"), y(fe_space, "BFGS->y")
      {};

    inline void setVectors(DOFVector<double> *s_, DOFVector<double> *y_,
			   double sy_=0.0)
    {
      s = *s_;
      y = *y_;

      if (!sy_)
	sy = s * y;
      else
	sy = sy_;

      return;
    };

  private:
    DOFVector<double> s, y;
    double sy;

    friend class BFGS_Precond;
  };

  // ============================================================================
  // ===== class BFGS_Precond ===================================================
  // ============================================================================

  /**
   * \ingroup Solver
   *
   * \brief
   * BFGS preconditioner.
   */
  class BFGS_Precond : public PreconditionerScal
  {
  public:
    MEMORY_MANAGED(BFGS_Precond);

    /** \brief
     * Creator class used in the PreconditionerMap.
     */
    class Creator : public PreconditionerScalCreator
    {
    public:
      MEMORY_MANAGED(Creator);

      /** \brief
       * Creates a new BFGS Preconditioner.
       */
      PreconditionerScal *create()
      {
	return NEW BFGS_Precond(size, row);
      };
    };

    /** \brief
     * Constructor.
     */
  BFGS_Precond(int size_ = 1, int row_ = 0) : PreconditionerScal(size_, row_) {
      k = 0;
      
      m = 2 * Global::getGeo(WORLD);
      GET_PARAMETER(1, "preconditioner->max. number of pairs", "%d", &m);
      m = std::max(0, std::min(m, 32));
    };
    
    /** \brief
     * Destructor.
     */
    virtual ~BFGS_Precond() {};

    /** \brief
     * realisation of Preconditioner::init
     */
    inline void init()
    {
      FUNCNAME("BFGS_Precond::init()");
      TEST_EXIT(matrix[row])("no matrix\n");
    };

    /** \brief
     * realisation of Preconditioner::precon
     */
    void precon(DOFVector<double> *vec);

    /** \brief
     * realisation of Preconditioner::exit
     */
    inline void exit() {};


    /* ----- Specific functions ----- */

    /** \brief
     * add pair of vectors
     */
    void addPair(DOFVector<double> *s, DOFVector<double> *y, double sy = 0.0);

  protected:

    /** \brief
     * list of pairs
     */
    std::deque<BFGS_Vectors> pairsVec;

    /** \brief
     * maximal number of pairs
     */
    int m;

    /** \brief
     * actual number of pairs
     */
    int k;
  };

}

#endif // AMDIS_BFGS_PRECONDITIONER_H