Rheolef  7.2
an efficient C++ finite element environment
 
Loading...
Searching...
No Matches
solver.h
Go to the documentation of this file.
1#ifndef _RHEOLEF_SOLVER_H
2#define _RHEOLEF_SOLVER_H
3//
4// This file is part of Rheolef.
5//
6// Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
7//
8// Rheolef is free software; you can redistribute it and/or modify
9// it under the terms of the GNU General Public License as published by
10// the Free Software Foundation; either version 2 of the License, or
11// (at your option) any later version.
12//
13// Rheolef is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17//
18// You should have received a copy of the GNU General Public License
19// along with Rheolef; if not, write to the Free Software
20// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21//
22// =========================================================================
23// AUTHOR: Pierre.Saramito@imag.fr
24// DATE: 4 march 2011
25
26namespace rheolef {
177} // namespace rheolef
178
179#include "rheolef/csr.h"
180#include "rheolef/solver_option.h"
181
182namespace rheolef {
183
184// =======================================================================
185// solver_abstract_rep: an abstract interface for solvers
186// =======================================================================
187// forward declaration:
188template <class T, class M> class solver_basic;
189
190template <class T, class M>
192public:
194 struct determinant_type;
195 explicit solver_abstract_rep (const solver_option& opt) : _opt(opt) {}
197 const solver_option& option() const { return _opt; }
199 virtual bool initialized() const { return false; }
201 virtual void update_values (const csr<T,M>& a) {}
202 virtual vec<T,M> solve (const vec<T,M>& b) const;
203 virtual vec<T,M> trans_solve (const vec<T,M>& b) const;
205 virtual determinant_type det() const;
206 virtual std::string name() const;
207// internals:
208 static solver_abstract_rep<T,M>* make_solver_ptr (const csr<T,M>& a, const solver_option& opt);
209// data:
210protected:
212};
213// det = mantissa*base^exponent
214template <class T, class M>
216 T mantissa, exponant, base;
217 determinant_type(): mantissa(0), exponant(0), base(10) {}
218};
219// -----------------------------------------------------------------------------
220// solver_abstract_rep inlined
221// -----------------------------------------------------------------------------
222template <class T, class M>
223inline
226{
227 typedef solver_abstract_rep<T,M> rep;
228 return new_macro (rep(*this));
229}
230template <class T, class M>
231inline
234{
235 error_macro (name() << ": undefined solve() member function"); return vec<T,M>();
236}
237template <class T, class M>
238inline
241{
242 error_macro (name() << ": undefined trans_solve() member function"); return vec<T,M>();
243}
244template <class T, class M>
245inline
246void
248{
249 error_macro (name() << ": undefined set_preconditioner() member function");
250}
251template <class T, class M>
252inline
255{
256 error_macro (name() << ": undefined det() member function");
257 return determinant_type();
258}
259// =======================================================================
260// the direct & iterative solver interface
261// =======================================================================
262// [verbatim_solver_basic]
263template <class T, class M = rheo_default_memory_model>
264class solver_basic: public smart_pointer_clone<solver_abstract_rep<T,M> > {
265public:
266// typedefs:
267
270 typedef typename rep::size_type size_type;
271 typedef typename rep::determinant_type determinant_type;
272
273// allocators:
274
276 explicit solver_basic (const csr<T,M>& a, const solver_option& opt = solver_option());
277 void update_values (const csr<T,M>& a);
278
279// accessors:
280
281 vec<T,M> trans_solve (const vec<T,M>& b) const;
282 vec<T,M> solve (const vec<T,M>& b) const;
284 const solver_option& option() const;
286 bool initialized() const;
287 std::string name() const;
288};
289// [verbatim_solver_basic]
290
291// [verbatim_solver]
293// [verbatim_solver]
294
295// -----------------------------------------------------------------------
296// solver_basic: inlined
297// -----------------------------------------------------------------------
298template <class T, class M>
299inline
301 : base (new_macro(rep(solver_option())))
302{
303}
304template <class T, class M>
305inline
307 : base (solver_abstract_rep<T,M>::make_solver_ptr(a,opt))
308{
309}
310template <class T, class M>
311inline
312void
314{
315 if (base::data().initialized()) {
316 base::data().update_values (a);
317 } else {
319 }
320}
321template <class T, class M>
322inline
323const solver_option&
325{
326 return base::data().option();
327}
328template <class T, class M>
329inline
330void
332{
333 base::data().set_preconditioner (sa);
334}
335template <class T, class M>
336inline
339{
340 return base::data().det();
341}
342template <class T, class M>
343inline
346{
347 return base::data().solve (b);
348}
349template <class T, class M>
350inline
353{
354 return base::data().trans_solve (b);
355}
356template <class T, class M>
357inline
358bool
360{
361 return base::data().initialized();
362}
363template <class T, class M>
364inline
365std::string
367{
368 return base::data().name();
369}
370
371} // namespace rheolef
372#endif // _RHEOLEF_SOLVER_H
see the csr page for the full documentation
Definition csr.h:317
virtual determinant_type det() const
Definition solver.h:254
virtual void set_preconditioner(const solver_basic< T, M > &)
Definition solver.h:247
virtual std::string name() const
Definition solver.cc:40
solver_abstract_rep(const solver_option &opt)
Definition solver.h:195
virtual vec< T, M > solve(const vec< T, M > &b) const
Definition solver.h:233
virtual vec< T, M > trans_solve(const vec< T, M > &b) const
Definition solver.h:240
const solver_option & option() const
Definition solver.h:197
csr< T, M >::size_type size_type
Definition solver.h:193
virtual void update_values(const csr< T, M > &a)
Definition solver.h:201
solver_abstract_rep(const solver_abstract_rep &x)
Definition solver.h:196
virtual bool initialized() const
Definition solver.h:199
virtual solver_abstract_rep< T, M > * clone() const
Definition solver.h:225
static solver_abstract_rep< T, M > * make_solver_ptr(const csr< T, M > &a, const solver_option &opt)
Definition solver.cc:49
rep::determinant_type determinant_type
Definition solver.h:271
void set_preconditioner(const solver_basic< T, M > &)
Definition solver.h:331
std::string name() const
Definition solver.h:366
determinant_type det() const
Definition solver.h:338
solver_basic(const csr< T, M > &a, const solver_option &opt=solver_option())
Definition solver.h:306
void update_values(const csr< T, M > &a)
Definition solver.h:313
vec< T, M > solve(const vec< T, M > &b) const
Definition solver.h:345
vec< T, M > trans_solve(const vec< T, M > &b) const
Definition solver.h:352
const solver_option & option() const
Definition solver.h:324
solver_abstract_rep< T, M > rep
Definition solver.h:268
rep::size_type size_type
Definition solver.h:270
smart_pointer_clone< rep > base
Definition solver.h:269
bool initialized() const
Definition solver.h:359
see the solver_option page for the full documentation
see the vec page for the full documentation
Definition vec.h:79
solver_basic< Float > solver
Definition solver.h:292
#define error_macro(message)
Definition dis_macros.h:49
Expr1::float_type T
Definition field_expr.h:230
This file is part of Rheolef.
Expr1::memory_type M