Precond_Ssor.cxx
1 // Copyright (C) 2003-2009 Marc DuruflĂ©
2 //
3 // This file is part of the linear-algebra library Seldon,
4 // http://seldon.sourceforge.net/.
5 //
6 // Seldon is free software; you can redistribute it and/or modify it under the
7 // terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 2.1 of the License, or (at your option)
9 // any later version.
10 //
11 // Seldon is distributed in the hope that it will be useful, but WITHOUT ANY
12 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
14 // more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with Seldon. If not, see http://www.gnu.org/licenses/.
18 
19 
20 #ifndef SELDON_FILE_PRECOND_SSOR_CXX
21 
22 namespace Seldon
23 {
24 
26  template<class T>
28  {
29  nb_iter = 1; omega = 1;
30  symmetric_precond = true;
31  }
32 
33 
35  template<class T>
37  {
38  return symmetric_precond;
39  }
40 
41 
44  template<class T>
46  {
47  symmetric_precond = true;
48  }
49 
50 
53  template<class T>
55  {
56  symmetric_precond = false;
57  }
58 
59 
61  template<class T>
63  ::SetParameterRelaxation(const typename ClassComplexType<T>::Treal& param)
64  {
65  omega = param;
66  }
67 
68 
70  template<class T>
72  {
73  nb_iter = nb_iterations;
74  }
75 
76 
78  template<class T>
80  {
81  const SorPreconditioner<T>& prec_sor = dynamic_cast<const SorPreconditioner<T>& >(prec);
82  symmetric_precond = prec_sor.symmetric_precond;
83  nb_iter = prec_sor.nb_iter;
84  omega = prec_sor.omega;
85  }
86 
87 
88 #ifdef SELDON_WITH_VIRTUAL
89  template<class T> template<class T0>
92  ::SolveGen(const SeldonTranspose& trans, const VirtualMatrix<T>& A,
93  const Vector<T0>& r, Vector<T0>& z, bool init)
94  {
95  if (init)
96  z.Zero();
97 
98  int stage = 0;
99  if (!symmetric_precond)
100  {
101  if (trans.NoTrans())
102  stage = 2;
103  else
104  stage = 3;
105  }
106 
107  A.ApplySor(trans, z, r, omega, nb_iter, stage);
108  }
109 
110 
112  template<class T>
114  ::Solve(const VirtualMatrix<T>& A, const Vector<T>& r, Vector<T>& z, bool init)
115  {
116  if (init)
117  z.Zero();
118 
119  if (symmetric_precond)
120  A.ApplySor(SeldonNoTrans, z, r, omega, nb_iter, 0);
121  else
122  A.ApplySor(SeldonNoTrans, z, r, omega, nb_iter, 2);
123 
124  }
125 
126 
128  template<class T>
130  ::TransSolve(const VirtualMatrix<T>& A, const Vector<T>& r, Vector<T>& z, bool init)
131  {
132  if (init)
133  z.Zero();
134 
135  if (symmetric_precond)
136  A.ApplySor(SeldonTrans, z, r, omega, nb_iter, 0);
137  else
138  A.ApplySor(SeldonTrans, z, r, omega, nb_iter, 3);
139  }
140 
141 
143  template<class T>
145  ::Solve(const VirtualMatrix<T>& A, const Vector<T>& r, Vector<T>& z)
146  {
147  Solve(A, r, z, true);
148  }
149 
150 
152  template<class T>
154  ::TransSolve(const VirtualMatrix<T>& A, const Vector<T>& r, Vector<T>& z)
155  {
156  TransSolve(A, r, z, true);
157  }
158 #else
159 
161  template<class T> template<class Vector1, class Matrix1>
163  Solve(const Matrix1& A, const Vector1& r, Vector1& z, bool init_guess_null)
164  {
165  if (init_guess_null)
166  z.Zero();
167 
168  if (symmetric_precond)
169  SOR(A, z, r, omega, nb_iter, 0);
170  else
171  SOR(A, z, r, omega, nb_iter, 2);
172  }
173 
174 
176  template<class T> template<class Vector1, class Matrix1>
178  TransSolve(const Matrix1& A, const Vector1& r,
179  Vector1& z, bool init_guess_null)
180  {
181  if (init_guess_null)
182  z.Zero();
183 
184  if (symmetric_precond)
185  SOR(SeldonTrans, A, z, r, omega, nb_iter, 0);
186  else
187  SOR(SeldonTrans, A, z, r, omega, nb_iter, 3);
188 
189  }
190 
191 #endif
192 
193 }
194 
195 #define SELDON_FILE_PRECOND_SSOR_CXX
196 #endif
Seldon::SeldonTranspose
Definition: MatrixFlag.hxx:32
Seldon::SorPreconditioner::SetNumberIterations
void SetNumberIterations(int nb_iterations)
sets the number of SOR sweeps to perform when calling Solve/TransSolve
Definition: Precond_Ssor.cxx:71
Seldon::Vector
Definition: SeldonHeader.hxx:207
Seldon::SorPreconditioner::InitUnSymmetricPreconditioning
void InitUnSymmetricPreconditioning()
if called, forward sweep is applied when calling Solve backward sweep is applied when calling TransSo...
Definition: Precond_Ssor.cxx:54
Seldon::SorPreconditioner::InitSymmetricPreconditioning
void InitSymmetricPreconditioning()
if called forward and backward sweep will be applied such that the preconditioning is symmetric
Definition: Precond_Ssor.cxx:45
Seldon::SorPreconditioner::symmetric_precond
bool symmetric_precond
true for Symmetric relaxation
Definition: Precond_Ssor.hxx:29
Seldon::SorPreconditioner::Solve
void Solve(const Matrix1 &A, const Vector1 &r, Vector1 &z, bool init_guess_null=true)
Solves M z = r.
Definition: Precond_Ssor.cxx:163
Seldon::SorPreconditioner::SorPreconditioner
SorPreconditioner()
Default constructor.
Definition: Precond_Ssor.cxx:27
Seldon::SorPreconditioner::nb_iter
int nb_iter
number of iterations
Definition: Precond_Ssor.hxx:30
Seldon::SorPreconditioner::SetParameterRelaxation
void SetParameterRelaxation(const typename ClassComplexType< T >::Treal &param)
sets the relaxation parameter omega
Definition: Precond_Ssor.cxx:63
Seldon::SorPreconditioner::omega
ClassComplexType< T >::Treal omega
relaxation parameter
Definition: Precond_Ssor.hxx:31
Seldon::SorPreconditioner::TransSolve
void TransSolve(const Matrix1 &A, const Vector1 &r, Vector1 &z, bool init_guess_null=true)
Solves M^t z = r.
Definition: Precond_Ssor.cxx:178
Seldon
Seldon namespace.
Definition: Array.cxx:24
Seldon::SorPreconditioner
Definition: Precond_Ssor.hxx:26
Seldon::VirtualMatrix
Abstract base class for all matrices.
Definition: Matrix_Base.hxx:42
Seldon::SorPreconditioner::CopyParameter
void CopyParameter(const Preconditioner_Base< T > &)
copies the parameters of another sor preconditioning
Definition: Precond_Ssor.cxx:79
Seldon::Preconditioner_Base
Base class for preconditioners.
Definition: Iterative.hxx:26
Seldon::SorPreconditioner::IsSymmetric
bool IsSymmetric() const
returns true if symmetric sor is used
Definition: Precond_Ssor.cxx:36