Fork me on GitHub
 All Classes Files Functions Variables Groups Pages
smoothed_aggregation.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008-2014 NVIDIA Corporation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
22 #pragma once
23 
24 #include <cusp/detail/config.h>
25 #include <cusp/detail/multilevel.h>
26 
27 #include <cusp/array1d.h>
28 #include <cusp/complex.h>
29 #include <cusp/precond/aggregation/detail/sa_view_traits.h>
30 
31 #include <thrust/execution_policy.h>
32 #include <thrust/detail/use_default.h>
33 
34 #include <vector> // TODO replace with host_vector
35 
36 namespace cusp
37 {
38 namespace precond
39 {
40 namespace aggregation
41 {
42 
43 /* \cond */
44 template<typename MatrixType>
45 struct sa_level
46 {
47  public:
48 
49  typedef typename MatrixType::index_type IndexType;
50  typedef typename MatrixType::value_type ValueType;
51  typedef typename MatrixType::memory_space MemorySpace;
52  typedef typename cusp::norm_type<ValueType>::type NormType;
53 
54  MatrixType A_; // matrix
55  MatrixType T; // matrix
56  cusp::array1d<IndexType,MemorySpace> aggregates; // aggregates
57  cusp::array1d<ValueType,MemorySpace> B; // near-nullspace candidates
58 
59  size_t num_iters;
60  NormType rho_DinvA;
61 
62  sa_level(void) : num_iters(1), rho_DinvA(0) {}
63 
64  template<typename SALevelType>
65  sa_level(const SALevelType& L)
66  : A_(L.A_),
67  aggregates(L.aggregates),
68  B(L.B),
69  num_iters(L.num_iters),
70  rho_DinvA(L.rho_DinvA)
71  {}
72 };
73 /* \endcond */
74 
154 template <typename IndexType,
155  typename ValueType,
156  typename MemorySpace,
157  typename SmootherType = thrust::use_default,
158  typename SolverType = thrust::use_default,
159  typename Format = thrust::use_default>
161  public cusp::multilevel<IndexType,ValueType,MemorySpace,Format,SmootherType,SolverType>::container
162 {
163  private:
164 
165  typedef typename detail::select_sa_matrix_type<IndexType,ValueType,MemorySpace>::type SetupMatrixType;
166  typedef typename cusp::multilevel<IndexType,ValueType,MemorySpace,Format,SmootherType,SolverType>::container ML;
167 
168  public:
169 
170  /* \cond */
171  std::vector< sa_level<SetupMatrixType> > sa_levels;
172  /* \endcond */
173 
177  smoothed_aggregation(void) : ML() {};
178 
183  template <typename MatrixType>
184  smoothed_aggregation(const MatrixType& A);
185 
192  template <typename MatrixType,typename ArrayType>
193  smoothed_aggregation(const MatrixType& A, const ArrayType& B,
194  typename thrust::detail::enable_if_convertible<typename ArrayType::format,cusp::array1d_format>::type* = 0);
195 
201  template <typename MemorySpace2,typename SmootherType2,typename SolverType2,typename Format2>
203 
210  template <typename MatrixType>
211  void initialize(const MatrixType& A);
212 
221  template <typename MatrixType, typename ArrayType>
222  void initialize(const MatrixType& A, const ArrayType& B,
223  typename thrust::detail::enable_if_convertible<typename MatrixType::format,cusp::known_format>::type* = 0);
224 
225  /* \cond */
226  template <typename DerivedPolicy, typename MatrixType>
227  void initialize(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
228  const MatrixType& A);
229 
230  template <typename DerivedPolicy, typename MatrixType, typename ArrayType>
231  void initialize(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
232  const MatrixType& A, const ArrayType& B);
233  /* \endcond */
234 
235 protected:
236 
237  /* \cond */
238  template <typename DerivedPolicy, typename MatrixType>
239  void extend_hierarchy(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
240  const MatrixType& A);
241  /* \endcond */
242 };
246 } // end namespace aggregation
247 } // end namespace precond
248 } // end namespace cusp
249 
250 #include <cusp/precond/aggregation/detail/smoothed_aggregation.inl>
251 
The array1d class is a 1D vector container that may contain elements stored in "host" or "device" mem...
Definition: array1d.h:98
Complex numbers.
Algebraic multigrid preconditoner based on smoothed aggregation.
1D array of elements that may reside in "host" or "device" memory space