Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
block_smoothed_aggregation.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008-2009 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 
26 #include <vector> // TODO replace with host_vector
27 #include <cusp/linear_operator.h>
28 
29 #include <cusp/coo_matrix.h>
30 #include <cusp/csr_matrix.h>
31 #include <cusp/hyb_matrix.h>
32 #include <cusp/block_multilevel.h>
35 
36 #include <cusp/detail/spectral_radius.h>
37 #include <cusp/detail/block_lu.h>
38 
39 namespace cusp
40 {
41 namespace precond
42 {
43 namespace aggregation
44 {
45 
51 template <typename IndexType, typename ValueType, typename MemorySpace>
52 struct amg_container {};
53 
54 template <typename IndexType, typename ValueType>
55 struct amg_container<IndexType,ValueType,cusp::host_memory>
56 {
57  // use CSR on host
58  typedef typename cusp::csr_matrix<IndexType,ValueType,cusp::host_memory> setup_type;
59  typedef typename cusp::csr_matrix<IndexType,ValueType,cusp::host_memory> solve_type;
60 };
61 
62 template <typename IndexType, typename ValueType>
63 struct amg_container<IndexType,ValueType,cusp::device_memory>
64 {
65  // use COO on device
66 // typedef typename cusp::coo_matrix<IndexType,ValueType,cusp::device_memory> setup_type;
67 // typedef typename cusp::hyb_matrix<IndexType,ValueType,cusp::device_memory> solve_type;
68  typedef typename cusp::csr_matrix<IndexType,ValueType,cusp::device_memory> setup_type;
69  typedef typename cusp::csr_matrix<IndexType,ValueType,cusp::device_memory> solve_type;
70 
71 };
72 
73 template<typename MatrixType>
74 struct sa_level
75 {
76  typedef typename MatrixType::index_type IndexType;
78  typedef typename MatrixType::memory_space MemorySpace;
79 
80  MatrixType A_; // matrix
81  cusp::array1d<IndexType,MemorySpace> aggregates; // aggregates
82  cusp::array1d<ValueType,MemorySpace> B; // near-nullspace candidates
83 
85 
86  sa_level() {}
87 
88  template<typename SA_Level_Type>
89  sa_level(const SA_Level_Type& sa_level) : A_(sa_level.A_), aggregates(sa_level.aggregates), B(sa_level.B), rho_DinvA(sa_level.rho_DinvA) {}
90 };
91 
92 
97 //typename SmootherType = cusp::relaxation::block_polynomial<ValueType,MemorySpace>
98 template <typename IndexType, typename ValueType, typename MemorySpace,
99  typename SmootherType,
101 class block_smoothed_aggregation : public cusp::block_multilevel< typename amg_container<IndexType,ValueType,MemorySpace>::solve_type, SmootherType, SolverType>
102 {
103 
107 
108 public:
109 
112  std::vector< sa_level<SetupMatrixType> > sa_levels;
113 
114  template <typename MatrixType>
115  block_smoothed_aggregation(const MatrixType& A, const IndexType numRHS, const ValueType theta=0);
116 
117  template <typename MatrixType, typename ArrayType>
118  block_smoothed_aggregation(const MatrixType& A, const ArrayType& B, const IndexType numRHS, const ValueType theta=0);
119 
120  template <typename MemorySpace2,typename SmootherType2,typename SolverType2>
122 
123 protected:
124 
125  template <typename MatrixType, typename ArrayType>
126  void init(const MatrixType& A, const ArrayType& B);
127 
128  void extend_hierarchy(void);
129 };
133 } // end namespace aggregation
134 } // end namespace precond
135 } // end namespace cusp
136 
137 #include <cusp/precond/block_smoothed_aggregation.inl>
amg_container< IndexType, ValueType, MemorySpace >::solve_type SolveMatrixType
cusp::block_multilevel< SolveMatrixType, SmootherType, SolverType > Parent
block_smoothed_aggregation(const MatrixType &A, const IndexType numRHS, const ValueType theta=0)
cusp::array1d< ValueType, MemorySpace > B
void init(const MatrixType &A, const ArrayType &B)
amg_container< IndexType, ValueType, MemorySpace >::setup_type SetupMatrixType
cusp::array1d< IndexType, MemorySpace > aggregates