File: smatrixd.h

package info (click to toggle)
arpack%2B%2B 2.3-10
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 4,556 kB
  • sloc: cpp: 16,612; sh: 8,819; ansic: 2,312; makefile: 258
file content (174 lines) | stat: -rw-r--r-- 2,843 bytes parent folder | download | duplicates (8)
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
169
170
171
172
173
174
/*
   ARPACK++ v1.2 2/20/2000
   c++ interface to ARPACK code.

   MODULE SMatrixD.h
   Class template for the 1-dimensional mass matrix
   on the interval [0,1].

   ARPACK Authors
      Richard Lehoucq
      Danny Sorensen
      Chao Yang
      Dept. of Computational & Applied Mathematics
      Rice University
      Houston, Texas
*/

#ifndef SMATRIXD_H
#define SMATRIXD_H

#include "matprod.h"
#include "blas1c.h"
#include "lapackc.h"

template<class ART>
class SymMatrixD: public MatrixWithProduct<ART> {

 private:

  ART  *Ad, *Adl, *Adu, *Adu2;
  int  *ipiv;
  int  decsize;

  void FactorDataDeallocate();

 public:

  void FactorM();

  void SolveM(ART* v);

  void MultMv(ART* v, ART* w);

  SymMatrixD(int nv);

  virtual ~SymMatrixD();

}; // SymMatrixD.


template<class ART>
inline void SymMatrixD<ART>::FactorDataDeallocate()
// Eliminates the data structure used on matrix factorization.

{

  delete[] Ad;
  delete[] Adl;
  delete[] Adu;
  delete[] Adu2;
  delete[] ipiv;

} // FactorDataDeallocate.


template<class ART>
void SymMatrixD<ART>::FactorM()
// Factors M.

{

  int  i, ierr;
  ART  h, r1, r2;

  const ART one  = 1.0;
  const ART four = 4.0;
  const ART six  = 6.0;

  if (decsize != this->ncols()) {
    decsize = this->ncols();
    FactorDataDeallocate();
    Ad   = new ART[this->ncols()];
    Adl  = new ART[this->ncols()];
    Adu  = new ART[this->ncols()];
    Adu2 = new ART[this->ncols()];
    ipiv = new int[this->ncols()];
  }

  h  = one/ART(this->ncols()+1);
  r2 = h/six;
  r1 = r2*four;

  for (i=0; i<this->ncols(); i++) {
    Ad[i]  = r1;
    Adl[i] = r2;
  }

  copy(this->ncols(), Adl, 1, Adu, 1);
  gttrf(this->ncols(), Adl, Ad, Adu, Adu2, ipiv, ierr);

} // FactorM.


template<class ART>
inline void SymMatrixD<ART>::SolveM(ART* v)
// Solves M*w = v. v is overwritten with vector w.

{

  int  ierr;
  char *type = "N";

  gttrs(type, this->ncols(), 1, Adl, Ad, Adu, Adu2, ipiv, v, this->ncols(), ierr);

} // SolveM.

template<class ART>
void SymMatrixD<ART>::MultMv(ART* v, ART* w)
//  Performs w <- M*v.

{

  int  j;
  ART  h;

  const ART one  = 1.0;
  const ART four = 4.0;
  const ART six  = 6.0;

  w[0] = four*v[0] + v[1];
  for (j=1; j<this->ncols()-1; j++) {
    w[j] = v[j-1] + four*v[j] + v[j+1];
  }
  w[this->ncols()-1] = v[this->ncols()-2] + four*v[this->ncols()-1];

  // Scaling the vector w by h.

  h = one / (ART(this->ncols()+1)*six);
  scal(this->ncols(), h, w, 1L);

  return;

} //  MultMv.


template<class ART>
inline SymMatrixD<ART>:: SymMatrixD(int nval): MatrixWithProduct<ART>(nval)
// Constructor.

{

  decsize = 0;
  Ad      = 0;
  Adl     = 0;
  Adu     = 0;
  Adu2    = 0;
  ipiv    = 0;

} // Constructor.


template<class ART>
inline SymMatrixD<ART>::~SymMatrixD()
// Destructor.

{

  FactorDataDeallocate();

} // Destructor.


#endif // SMATRIXD_H