source: src/solver/givens.hpp@ d24c2f

Last change on this file since d24c2f was 48b662, checked in by Olaf Lenz <olenz@…>, 14 years ago

Moved files in scafacos_fcs one level up.

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

  • Property mode set to 100644
File size: 1.3 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{
24private:
25 void Compute();
26};
27
28template<class T>
29void Givens<T>::Compute()
30{
31 int n = this->Size();
32 vmg_float c,s,t;
33
34 for (int i=0; i<n-1; i++)
35 for (int j=i+1; j<n; j++)
36 if (fabs(this->Mat(j,i)) > DBL_EPSILON) {
37
38 t = 1.0 / sqrt(this->Mat(i,i)*this->Mat(i,i) + this->Mat(j,i)*this->Mat(j,i));
39 s = t * this->Mat(j,i);
40 c = t * this->Mat(i,i);
41
42 for (int k=i; k<n; k++) {
43
44 t = c * this->Mat(i,k) + s * this->Mat(j,k);
45
46 if (k != i)
47 this->Mat(j,k) = c * this->Mat(j,k) - s * this->Mat(i,k);
48
49 this->Mat(i,k) = t;
50
51 }
52
53 t = c * this->Rhs(i) + s * this->Rhs(j);
54
55 this->Rhs(j) = c * this->Rhs(j) - s * this->Rhs(i);
56
57 this->Rhs(i) = t;
58
59 this->Mat(j,i) = 0.0;
60
61 }
62
63 for (int i=n-1; i>=0; i--) {
64
65 for (int j=i+1; j<n; j++)
66 this->Rhs(i) -= this->Mat(i,j) * this->Sol(j);
67
68 this->Sol(i) = this->Rhs(i) / this->Mat(i,i);
69
70 }
71}
72
73}
74
75#endif /* GIVENS_HPP_ */
Note: See TracBrowser for help on using the repository browser.