Loading...
Searching...
No Matches
solver.h
Go to the documentation of this file.
#ifndef _RHEOLEF_SOLVER_H
#define _RHEOLEF_SOLVER_H
//
// This file is part of Rheolef.
//
// Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
//
// Rheolef is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// Rheolef is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Rheolef; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// =========================================================================
// AUTHOR: Pierre.Saramito@imag.fr
// DATE: 4 march 2011
namespace rheolef {
} // namespace rheolef
#include "rheolef/csr.h"
#include "rheolef/solver_option.h"
namespace rheolef {
// =======================================================================
// solver_abstract_rep: an abstract interface for solvers
// =======================================================================
// forward declaration:
template <class T, class M> class solver_basic;
template <class T, class M>
class solver_abstract_rep {
public:
typedef typename csr<T,M>::size_type size_type;
struct determinant_type;
explicit solver_abstract_rep (const solver_option& opt) : _opt(opt) {}
solver_abstract_rep (const solver_abstract_rep& x) : _opt(x._opt) {}
const solver_option& option() const { return _opt; }
virtual solver_abstract_rep<T,M>* clone() const;
virtual bool initialized() const { return false; }
virtual ~solver_abstract_rep () {}
virtual void update_values (const csr<T,M>& a) {}
virtual vec<T,M> solve (const vec<T,M>& b) const;
virtual vec<T,M> trans_solve (const vec<T,M>& b) const;
virtual void set_preconditioner (const solver_basic<T,M>&);
virtual determinant_type det() const;
virtual std::string name() const;
// internals:
static solver_abstract_rep<T,M>* make_solver_ptr (const csr<T,M>& a, const solver_option& opt);
// data:
protected:
mutable solver_option _opt;
};
// det = mantissa*base^exponent
template <class T, class M>
struct solver_abstract_rep<T,M>::determinant_type {
T mantissa, exponant, base;
determinant_type(): mantissa(0), exponant(0), base(10) {}
};
// -----------------------------------------------------------------------------
// solver_abstract_rep inlined
// -----------------------------------------------------------------------------
template <class T, class M>
inline
solver_abstract_rep<T,M>*
solver_abstract_rep<T,M>::clone() const
{
typedef solver_abstract_rep<T,M> rep;
return new_macro (rep(*this));
}
template <class T, class M>
inline
vec<T,M>
solver_abstract_rep<T,M>::solve (const vec<T,M>& b) const
{
error_macro (name() << ": undefined solve() member function"); return vec<T,M>();
}
template <class T, class M>
inline
vec<T,M>
solver_abstract_rep<T,M>::trans_solve (const vec<T,M>& b) const
{
error_macro (name() << ": undefined trans_solve() member function"); return vec<T,M>();
}
template <class T, class M>
inline
void
solver_abstract_rep<T,M>::set_preconditioner (const solver_basic<T,M>&)
{
error_macro (name() << ": undefined set_preconditioner() member function");
}
template <class T, class M>
inline
typename solver_abstract_rep<T,M>::determinant_type
solver_abstract_rep<T,M>::det() const
{
error_macro (name() << ": undefined det() member function");
return determinant_type();
}
// =======================================================================
// the direct & iterative solver interface
// =======================================================================
// [verbatim_solver_basic]
template <class T, class M = rheo_default_memory_model>
class solver_basic: public smart_pointer_clone<solver_abstract_rep<T,M> > {
public:
// typedefs:
typedef solver_abstract_rep<T,M> rep;
typedef smart_pointer_clone<rep> base;
typedef typename rep::size_type size_type;
typedef typename rep::determinant_type determinant_type;
// allocators:
solver_basic ();
explicit solver_basic (const csr<T,M>& a, const solver_option& opt = solver_option());
void update_values (const csr<T,M>& a);
// accessors:
vec<T,M> trans_solve (const vec<T,M>& b) const;
vec<T,M> solve (const vec<T,M>& b) const;
determinant_type det() const;
const solver_option& option() const;
void set_preconditioner (const solver_basic<T,M>&);
bool initialized() const;
std::string name() const;
};
// [verbatim_solver_basic]
// [verbatim_solver]
typedef solver_basic<Float> solver;
// [verbatim_solver]
// -----------------------------------------------------------------------
// solver_basic: inlined
// -----------------------------------------------------------------------
template <class T, class M>
inline
solver_basic<T,M>::solver_basic ()
: base (new_macro(rep(solver_option())))
{
}
template <class T, class M>
inline
solver_basic<T,M>::solver_basic (const csr<T,M>& a, const solver_option& opt)
: base (solver_abstract_rep<T,M>::make_solver_ptr(a,opt))
{
}
template <class T, class M>
inline
void
solver_basic<T,M>::update_values (const csr<T,M>& a)
{
if (base::data().initialized()) {
base::data().update_values (a);
} else {
solver_basic<T,M>::base::operator= (solver_abstract_rep<T,M>::make_solver_ptr(a,solver_option()));
}
}
template <class T, class M>
inline
const solver_option&
solver_basic<T,M>::option() const
{
return base::data().option();
}
template <class T, class M>
inline
void
solver_basic<T,M>::set_preconditioner (const solver_basic<T,M>& sa)
{
base::data().set_preconditioner (sa);
}
template <class T, class M>
inline
typename solver_basic<T,M>::determinant_type
solver_basic<T,M>::det() const
{
return base::data().det();
}
template <class T, class M>
inline
vec<T,M>
solver_basic<T,M>::solve (const vec<T,M>& b) const
{
return base::data().solve (b);
}
template <class T, class M>
inline
vec<T,M>
solver_basic<T,M>::trans_solve (const vec<T,M>& b) const
{
return base::data().trans_solve (b);
}
template <class T, class M>
inline
bool
solver_basic<T,M>::initialized() const
{
return base::data().initialized();
}
template <class T, class M>
inline
std::string
solver_basic<T,M>::name() const
{
return base::data().name();
}
} // namespace rheolef
#endif // _RHEOLEF_SOLVER_H
rheolef::csr
see the csr page for the full documentation
Definition csr.h:317
rheolef::smart_pointer_clone
Definition smart_pointer.h:370
rheolef::solver_abstract_rep
Definition solver.h:191
rheolef::solver_abstract_rep::det
virtual determinant_type det() const
Definition solver.h:254
rheolef::solver_abstract_rep::set_preconditioner
virtual void set_preconditioner(const solver_basic< T, M > &)
Definition solver.h:247
rheolef::solver_abstract_rep::name
virtual std::string name() const
Definition solver.cc:40
rheolef::solver_abstract_rep::_opt
solver_option _opt
Definition solver.h:211
rheolef::solver_abstract_rep::solver_abstract_rep
solver_abstract_rep(const solver_option &opt)
Definition solver.h:195
rheolef::solver_abstract_rep::~solver_abstract_rep
virtual ~solver_abstract_rep()
Definition solver.h:200
rheolef::solver_abstract_rep::solve
virtual vec< T, M > solve(const vec< T, M > &b) const
Definition solver.h:233
rheolef::solver_abstract_rep::trans_solve
virtual vec< T, M > trans_solve(const vec< T, M > &b) const
Definition solver.h:240
rheolef::solver_abstract_rep::option
const solver_option & option() const
Definition solver.h:197
rheolef::solver_abstract_rep::size_type
csr< T, M >::size_type size_type
Definition solver.h:193
rheolef::solver_abstract_rep::update_values
virtual void update_values(const csr< T, M > &a)
Definition solver.h:201
rheolef::solver_abstract_rep::solver_abstract_rep
solver_abstract_rep(const solver_abstract_rep &x)
Definition solver.h:196
rheolef::solver_abstract_rep::initialized
virtual bool initialized() const
Definition solver.h:199
rheolef::solver_abstract_rep::clone
virtual solver_abstract_rep< T, M > * clone() const
Definition solver.h:225
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
Definition solver.h:264
rheolef::solver_basic::determinant_type
rep::determinant_type determinant_type
Definition solver.h:271
rheolef::solver_basic::set_preconditioner
void set_preconditioner(const solver_basic< T, M > &)
Definition solver.h:331
rheolef::solver_basic::name
std::string name() const
Definition solver.h:366
rheolef::solver_basic::det
determinant_type det() const
Definition solver.h:338
rheolef::solver_basic::solver_basic
solver_basic(const csr< T, M > &a, const solver_option &opt=solver_option())
Definition solver.h:306
rheolef::solver_basic::update_values
void update_values(const csr< T, M > &a)
Definition solver.h:313
rheolef::solver_basic::solve
vec< T, M > solve(const vec< T, M > &b) const
Definition solver.h:345
rheolef::solver_basic::trans_solve
vec< T, M > trans_solve(const vec< T, M > &b) const
Definition solver.h:352
rheolef::solver_basic::option
const solver_option & option() const
Definition solver.h:324
rheolef::solver_basic::rep
solver_abstract_rep< T, M > rep
Definition solver.h:268
rheolef::solver_basic::size_type
rep::size_type size_type
Definition solver.h:270
rheolef::solver_basic::base
smart_pointer_clone< rep > base
Definition solver.h:269
rheolef::solver_basic::solver_basic
solver_basic()
Definition solver.h:300
rheolef::solver_basic::initialized
bool initialized() const
Definition solver.h:359
rheolef::solver_option
see the solver_option page for the full documentation
Definition solver_option.h:155
rheolef::vec
see the vec page for the full documentation
Definition vec.h:79
rheolef::solver
solver_basic< Float > solver
Definition solver.h:292
error_macro
#define error_macro(message)
Definition dis_macros.h:49
T
Expr1::float_type T
Definition field_expr.h:230
rheolef
This file is part of Rheolef.
Definition compiler_eigen.h:39
rheolef::solver_abstract_rep::determinant_type
Definition solver.h:215
rheolef::solver_abstract_rep::determinant_type::base
T base
Definition solver.h:216
rheolef::solver_abstract_rep::determinant_type::determinant_type
determinant_type()
Definition solver.h:217
M
Expr1::memory_type M
Definition vec_expr_v2.h:416