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 // @HEADER
2 // *****************************************************************************
3 // Stokhos Package
4 //
5 // Copyright 2009 NTESS and the Stokhos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 /*
11  * Copyright 2008-2009 NVIDIA Corporation
12  *
13  * Licensed under the Apache License, Version 2.0 (the "License");
14  * you may not use this file except in compliance with the License.
15  * You may obtain a copy of the License at
16  *
17  * http://www.apache.org/licenses/LICENSE-2.0
18  *
19  * Unless required by applicable law or agreed to in writing, software
20  * distributed under the License is distributed on an "AS IS" BASIS,
21  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22  * See the License for the specific language governing permissions and
23  * limitations under the License.
24  */
25 
31 #pragma once
32 
33 #include <cusp/detail/config.h>
34 
35 #include <vector> // TODO replace with host_vector
36 #include <cusp/linear_operator.h>
37 
38 #include <cusp/coo_matrix.h>
39 #include <cusp/csr_matrix.h>
40 #include <cusp/hyb_matrix.h>
41 #include <cusp/block_multilevel.h>
44 
45 #include <cusp/detail/spectral_radius.h>
46 #include <cusp/detail/block_lu.h>
47 
48 namespace cusp
49 {
50 namespace precond
51 {
52 namespace aggregation
53 {
54 
60 template <typename IndexType, typename ValueType, typename MemorySpace>
61 struct amg_container {};
62 
63 template <typename IndexType, typename ValueType>
64 struct amg_container<IndexType,ValueType,cusp::host_memory>
65 {
66  // use CSR on host
67  typedef typename cusp::csr_matrix<IndexType,ValueType,cusp::host_memory> setup_type;
68  typedef typename cusp::csr_matrix<IndexType,ValueType,cusp::host_memory> solve_type;
69 };
70 
71 template <typename IndexType, typename ValueType>
72 struct amg_container<IndexType,ValueType,cusp::device_memory>
73 {
74  // use COO on device
75 // typedef typename cusp::coo_matrix<IndexType,ValueType,cusp::device_memory> setup_type;
76 // typedef typename cusp::hyb_matrix<IndexType,ValueType,cusp::device_memory> solve_type;
77  typedef typename cusp::csr_matrix<IndexType,ValueType,cusp::device_memory> setup_type;
78  typedef typename cusp::csr_matrix<IndexType,ValueType,cusp::device_memory> solve_type;
79 
80 };
81 
82 template<typename MatrixType>
83 struct sa_level
84 {
85  typedef typename MatrixType::index_type IndexType;
87  typedef typename MatrixType::memory_space MemorySpace;
88 
89  MatrixType A_; // matrix
90  cusp::array1d<IndexType,MemorySpace> aggregates; // aggregates
91  cusp::array1d<ValueType,MemorySpace> B; // near-nullspace candidates
92 
94 
95  sa_level() {}
96 
97  template<typename SA_Level_Type>
98  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) {}
99 };
100 
101 
106 //typename SmootherType = cusp::relaxation::block_polynomial<ValueType,MemorySpace>
107 template <typename IndexType, typename ValueType, typename MemorySpace,
108  typename SmootherType,
110 class block_smoothed_aggregation : public cusp::block_multilevel< typename amg_container<IndexType,ValueType,MemorySpace>::solve_type, SmootherType, SolverType>
111 {
112 
116 
117 public:
118 
121  std::vector< sa_level<SetupMatrixType> > sa_levels;
122 
123  template <typename MatrixType>
124  block_smoothed_aggregation(const MatrixType& A, const IndexType numRHS, const ValueType theta=0);
125 
126  template <typename MatrixType, typename ArrayType>
127  block_smoothed_aggregation(const MatrixType& A, const ArrayType& B, const IndexType numRHS, const ValueType theta=0);
128 
129  template <typename MemorySpace2,typename SmootherType2,typename SolverType2>
131 
132 protected:
133 
134  template <typename MatrixType, typename ArrayType>
135  void init(const MatrixType& A, const ArrayType& B);
136 
137  void extend_hierarchy(void);
138 };
142 } // end namespace aggregation
143 } // end namespace precond
144 } // end namespace cusp
145 
146 #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