Rheolef  7.1
an efficient C++ finite element environment
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 
26 namespace rheolef {
177 } // namespace rheolef
178 
179 #include "rheolef/csr.h"
180 #include "rheolef/solver_option.h"
181 
182 namespace rheolef {
183 
184 // =======================================================================
185 // solver_abstract_rep: an abstract interface for solvers
186 // =======================================================================
187 // forward declaration:
188 template <class T, class M> class solver_basic;
189 
190 template <class T, class M>
192 public:
193  typedef typename csr<T,M>::size_type size_type;
194  struct determinant_type;
195  explicit solver_abstract_rep (const solver_option& opt) : _opt(opt) {}
197  const solver_option& option() const { return _opt; }
198  virtual solver_abstract_rep<T,M>* clone() const;
199  virtual bool initialized() const { return false; }
200  virtual ~solver_abstract_rep () {}
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;
204  virtual void set_preconditioner (const solver_basic<T,M>&);
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:
210 protected:
212 };
213 // det = mantissa*base^exponent
214 template <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 // -----------------------------------------------------------------------------
222 template <class T, class M>
223 inline
226 {
227  typedef solver_abstract_rep<T,M> rep;
228  return new_macro (rep(*this));
229 }
230 template <class T, class M>
231 inline
232 vec<T,M>
234 {
235  error_macro (name() << ": undefined solve() member function"); return vec<T,M>();
236 }
237 template <class T, class M>
238 inline
239 vec<T,M>
241 {
242  error_macro (name() << ": undefined trans_solve() member function"); return vec<T,M>();
243 }
244 template <class T, class M>
245 inline
246 void
248 {
249  error_macro (name() << ": undefined set_preconditioner() member function");
250 }
251 template <class T, class M>
252 inline
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]
263 template <class T, class M = rheo_default_memory_model>
264 class solver_basic: public smart_pointer_clone<solver_abstract_rep<T,M> > {
265 public:
266 // typedefs:
267 
270  typedef typename rep::size_type size_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 // -----------------------------------------------------------------------
298 template <class T, class M>
299 inline
301  : base (new_macro(rep(solver_option())))
302 {
303 }
304 template <class T, class M>
305 inline
307  : base (solver_abstract_rep<T,M>::make_solver_ptr(a,opt))
308 {
309 }
310 template <class T, class M>
311 inline
312 void
314 {
315  if (base::data().initialized()) {
316  base::data().update_values (a);
317  } else {
319  }
320 }
321 template <class T, class M>
322 inline
323 const solver_option&
325 {
326  return base::data().option();
327 }
328 template <class T, class M>
329 inline
330 void
332 {
333  base::data().set_preconditioner (sa);
334 }
335 template <class T, class M>
336 inline
339 {
340  return base::data().det();
341 }
342 template <class T, class M>
343 inline
344 vec<T,M>
346 {
347  return base::data().solve (b);
348 }
349 template <class T, class M>
350 inline
351 vec<T,M>
353 {
354  return base::data().trans_solve (b);
355 }
356 template <class T, class M>
357 inline
358 bool
360 {
361  return base::data().initialized();
362 }
363 template <class T, class M>
364 inline
365 std::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
const solver_option & option() const
Definition: solver.h:197
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 ~solver_abstract_rep()
Definition: solver.h:200
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
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
solver_basic< Float > solver
Definition: solver.h:292
Expr1::float_type T
Definition: field_expr.h:261
This file is part of Rheolef.
void solve(tiny_matrix< T > &a, tiny_vector< size_t > &piv, const tiny_vector< T > &b, tiny_vector< T > &x)
Definition: tiny_lu.h:92
Expr1::memory_type M
Definition: vec_expr_v2.h:416