source: src/solver/givens.hpp@ 759a6a

Last change on this file since 759a6a was ac6d04, checked in by Julian Iseringhausen <isering@…>, 14 years ago

Merge recent changes of the vmg library into ScaFaCos.

Includes a fix for the communication problems on Jugene.

git-svn-id: https://svn.version.fz-juelich.de/scafacos/trunk@1666 5161e1c8-67bf-11de-9fd5-51895aff932f

  • Property mode set to 100644
File size: 1.4 KB
Line 
1/**
2 * @file givens.hpp
3 * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
4 * @date Mon Apr 18 13:10:15 2011
5 *
6 * @brief Solves system of linear equations using Givens rotations.
7 * Compare to Meister, Numerik lineare Gleichungssysteme.
8 *
9 */
10
11#ifndef GIVENS_HPP_
12#define GIVENS_HPP_
13
14#include <cfloat>
15
16#include "solver/solver.hpp"
17
18namespace VMG
19{
20
21template<class T>
22class Givens : public T
23{
24public:
25 Givens() :
26 T()
27 {}
28
29 Givens(int size) :
30 T(size)
31 {}
32
33protected:
34 void Compute();
35};
36
37template<class T>
38void Givens<T>::Compute()
39{
40 int n = this->Size();
41 vmg_float c,s,t;
42
43 for (int i=0; i<n-1; i++)
44 for (int j=i+1; j<n; j++)
45 if (fabs(this->Mat(j,i)) > DBL_EPSILON) {
46
47 t = 1.0 / sqrt(this->Mat(i,i)*this->Mat(i,i) + this->Mat(j,i)*this->Mat(j,i));
48 s = t * this->Mat(j,i);
49 c = t * this->Mat(i,i);
50
51 for (int k=i; k<n; k++) {
52
53 t = c * this->Mat(i,k) + s * this->Mat(j,k);
54
55 if (k != i)
56 this->Mat(j,k) = c * this->Mat(j,k) - s * this->Mat(i,k);
57
58 this->Mat(i,k) = t;
59
60 }
61
62 t = c * this->Rhs(i) + s * this->Rhs(j);
63
64 this->Rhs(j) = c * this->Rhs(j) - s * this->Rhs(i);
65
66 this->Rhs(i) = t;
67
68 this->Mat(j,i) = 0.0;
69
70 }
71
72 for (int i=n-1; i>=0; i--) {
73
74 for (int j=i+1; j<n; j++)
75 this->Rhs(i) -= this->Mat(i,j) * this->Sol(j);
76
77 this->Sol(i) = this->Rhs(i) / this->Mat(i,i);
78
79 }
80}
81
82}
83
84#endif /* GIVENS_HPP_ */
Note: See TracBrowser for help on using the repository browser.