sparse_solver.hh
Go to the documentation of this file.
1 /* -*- mia-c++ -*-
2  *
3  * This file is part of MIA - a toolbox for medical image analysis
4  * Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
5  *
6  * MIA is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with MIA; if not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 #ifndef mia_core_sparse_solver_hh
22 #define mia_core_sparse_solver_hh
23 
24 
25 #include <mia/core/product_base.hh>
26 #include <mia/core/traits.hh>
27 
29 
42 template <typename F>
43 class TSparseSolver : public CProductBase{
44 public:
46  typedef F Field;
47 
49  typedef F plugin_data;
50 
53 
56 
58  static const char * const type_descr;
59 
61  typedef typename Field::iterator field_iterator;
62 
64  typedef typename Field::const_iterator const_field_iterator;
65 
67  typedef typename Field::value_type value_type;
68 
76  class A_mult_x: public CProductBase {
77  public:
79  typedef F plugin_data;
80 
83 
85  static const char * const type_descr;
86 
88  A_mult_x():m_size(dimsize_type()){};
89 
91  A_mult_x(const dimsize_type& size):m_size(size){};
92 
94  virtual ~A_mult_x() {};
95 
105  virtual value_type operator () (const_field_iterator ix) const = 0;
106 
110  virtual int get_boundary_size() const = 0;
111 
116  dimsize_type get_size() const {
117  return m_size;
118  }
119  private:
120  dimsize_type m_size;
121 
122  };
123 
124  virtual ~TSparseSolver() {};
125 
126 
134  virtual int solve(const Field& rhs, Field& x, const A_mult_x& mult) const = 0;
135 };
136 
137 template <typename F>
138 const char * const TSparseSolver<F>::type_descr = "sparsesolver";
139 
140 
141 template <typename F>
142 const char * const TSparseSolver<F>::A_mult_x::type_descr = "amultx";
143 
144 
154 template <typename F>
155 struct multiply {
162  static void apply(F& MIA_PARAM_UNUSED(result),
163  const typename TSparseSolver<F>::A_mult_x& MIA_PARAM_UNUSED(A), const F& MIA_PARAM_UNUSED(x)) {
164  static_assert(sizeof(F)==0, "This operation needs to be specialized");
165  }
166 };
167 
168 
177 template <typename F>
178 F operator * (const typename TSparseSolver<F>::A_mult_x& A, const F& x)
179 {
180  F result(x.get_size());
181  multiply<F>::apply(result, A, x);
182  return result;
183 }
184 
185 
187 
188 #endif
Field::value_type value_type
type of the values stored in Field
A class that implements the multiplication of a cell of the matrix A with the field x...
static const char *const type_descr
plugin type component of plugin path descriptor
virtual int solve(const Field &rhs, Field &x, const A_mult_x &mult) const =0
static const char *const type_descr
plugin type component of plugin path descriptor
Field::iterator field_iterator
type of the field random access iterator
dim_traits< F >::dimsize_type dimsize_type
typeef of the dimension type
Class template to implement a matrix - field multiplication.
virtual ~TSparseSolver()
solver for sparse systems of equations
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
TSparseSolver< F > plugin_type
helper for the plug-in handling
Field::const_iterator const_field_iterator
type of the field random access const_iterator
F operator*(const typename TSparseSolver< F >::A_mult_x &A, const F &x)
A_mult_x(const dimsize_type &size)
virtual int get_boundary_size() const =0
F Field
typedef for the field the solver works on
A trait to obtaine information about of dimensions of a class.
Definition: traits.hh:36
The base class for all plug-in created object.
Definition: product_base.hh:40
F plugin_data
helper typedef for the plug-in handling
static void apply(F &result, const typename TSparseSolver< F >::A_mult_x &A, const F &x)
A_mult_x plugin_type
helper typedef for the plug-in handling
virtual value_type operator()(const_field_iterator ix) const =0
dimsize_type get_size() const
F plugin_data
helper typedef for the plug-in handling
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36