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;
271  typedef typename rep::determinant_type determinant_type;
272 
273 // allocators:
274 
275  solver_basic ();
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;
283  determinant_type det() 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
rheolef::solver_abstract_rep::solver_abstract_rep
solver_abstract_rep(const solver_abstract_rep &x)
Definition: solver.h:196
rheolef::solver_abstract_rep::determinant_type::determinant_type
determinant_type()
Definition: solver.h:217
rheolef::solver_basic::size_type
rep::size_type size_type
Definition: solver.h:270
rheolef::solver_basic::initialized
bool initialized() const
Definition: solver.h:359
rheolef::solver_basic::update_values
void update_values(const csr< T, M > &a)
Definition: solver.h:313
rheolef::solver_basic
Definition: solver.h:188
rheolef::solver_abstract_rep::make_solver_ptr
static solver_abstract_rep< T, M > * make_solver_ptr(const csr< T, M > &a, const solver_option &opt)
Definition: solver.cc:49
rheolef::solver_basic::determinant_type
rep::determinant_type determinant_type
Definition: solver.h:271
rheolef::solver_abstract_rep::determinant_type::mantissa
T mantissa
Definition: solver.h:216
rheolef::solver_basic::solver_basic
solver_basic()
Definition: solver.h:300
rheolef::vec
see the vec page for the full documentation
Definition: vec.h:79
rheolef::solver_abstract_rep::determinant_type
Definition: solver.h:215
rheolef::solver_basic::rep
solver_abstract_rep< T, M > rep
Definition: solver.h:268
rheolef::solver_abstract_rep::solve
virtual vec< T, M > solve(const vec< T, M > &b) const
Definition: solver.h:233
rheolef::solver_basic::name
std::string name() const
Definition: solver.h:366
rheolef::solver
solver_basic< Float > solver
Definition: solver.h:292
rheolef::solver_abstract_rep
Definition: solver.h:191
rheolef::solver_abstract_rep::initialized
virtual bool initialized() const
Definition: solver.h:199
rheolef::solver_basic::trans_solve
vec< T, M > trans_solve(const vec< T, M > &b) const
Definition: solver.h:352
rheolef::solver_abstract_rep::option
const solver_option & option() const
Definition: solver.h:197
rheolef::solver_abstract_rep::~solver_abstract_rep
virtual ~solver_abstract_rep()
Definition: solver.h:200
rheolef::solver_abstract_rep::trans_solve
virtual vec< T, M > trans_solve(const vec< T, M > &b) const
Definition: solver.h:240
a
Definition: diffusion_isotropic.h:25
rheolef::solver_abstract_rep::update_values
virtual void update_values(const csr< T, M > &a)
Definition: solver.h:201
rheolef::solver_abstract_rep::det
virtual determinant_type det() const
Definition: solver.h:254
rheolef::solver_abstract_rep::name
virtual std::string name() const
Definition: solver.cc:40
rheolef::smart_pointer_clone
Definition: smart_pointer.h:370
rheolef::csr
see the csr page for the full documentation
Definition: asr.h:31
rheolef::solver_basic::set_preconditioner
void set_preconditioner(const solver_basic< T, M > &)
Definition: solver.h:331
rheolef
This file is part of Rheolef.
Definition: compiler_eigen.h:37
error_macro
#define error_macro(message)
Definition: dis_macros.h:49
rheolef::solver_abstract_rep::size_type
csr< T, M >::size_type size_type
Definition: solver.h:193
rheolef::solve
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
rheolef::solver_abstract_rep::clone
virtual solver_abstract_rep< T, M > * clone() const
Definition: solver.h:225
rheolef::solver_abstract_rep::_opt
solver_option _opt
Definition: solver.h:211
rheolef::solver_basic::option
const solver_option & option() const
Definition: solver.h:324
rheolef::solver_abstract_rep::solver_abstract_rep
solver_abstract_rep(const solver_option &opt)
Definition: solver.h:195
mkgeo_ball.b
b
Definition: mkgeo_ball.sh:152
rheolef::solver_basic::base
smart_pointer_clone< rep > base
Definition: solver.h:269
rheolef::solver_abstract_rep::set_preconditioner
virtual void set_preconditioner(const solver_basic< T, M > &)
Definition: solver.h:247
rheolef::solver_basic::det
determinant_type det() const
Definition: solver.h:338
mkgeo_contraction.name
name
Definition: mkgeo_contraction.sh:133
M
Expr1::memory_type M
Definition: vec_expr_v2.h:385
rheolef::solver_basic::solve
vec< T, M > solve(const vec< T, M > &b) const
Definition: solver.h:345
T
Expr1::float_type T
Definition: field_expr.h:218
rheolef::solver_option
see the solver_option page for the full documentation
Definition: solver_option.h:155