Ifpack2 Templated Preconditioning Package  Version 1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Ifpack2_SparseContainer_decl.hpp
Go to the documentation of this file.
1 /*@HEADER
2 // ***********************************************************************
3 //
4 // Ifpack2: Templated Object-Oriented Algebraic Preconditioner Package
5 // Copyright (2009) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 //@HEADER
41 */
42 
43 #ifndef IFPACK2_SPARSECONTAINER_DECL_HPP
44 #define IFPACK2_SPARSECONTAINER_DECL_HPP
45 
48 
49 #include "Ifpack2_Container.hpp"
51 #include "Tpetra_MultiVector.hpp"
52 #include "Tpetra_Map.hpp"
53 #include "Tpetra_RowMatrix.hpp"
54 #include "Tpetra_CrsMatrix.hpp"
56 #include "Ifpack2_ILUT_decl.hpp"
57 #include <vector>
58 #ifdef HAVE_IFPACK2_AMESOS2
59 #include "Ifpack2_Details_Amesos2Wrapper.hpp"
60 #endif
61 
62 namespace Ifpack2 {
63 
133 template<typename MatrixType, typename InverseType>
135 : public ContainerImpl<MatrixType, typename InverseType::scalar_type>
136 {
137 
139 
140 private:
147  using matrix_type = MatrixType;
153  using inverse_type = InverseType;
154 
155  using typename Container<MatrixType>::SC;
156  using typename Container<MatrixType>::LO;
157  using typename Container<MatrixType>::GO;
158  using typename Container<MatrixType>::NO;
159 
160  using typename Container<MatrixType>::mv_type;
161  using typename Container<MatrixType>::map_type;
162  using typename Container<MatrixType>::vector_type;
163  using typename Container<MatrixType>::import_type;
164 
165  using InverseScalar = typename InverseType::scalar_type;
166  using InverseLocalOrdinal = typename InverseType::local_ordinal_type;
167  using InverseGlobalOrdinal = typename InverseType::global_ordinal_type;
168  using InverseNode = typename InverseType::node_type;
169 
170  using typename ContainerImpl<MatrixType, InverseScalar>::block_crs_matrix_type;
171 
172  using inverse_mv_type = Tpetra::MultiVector<InverseScalar, InverseLocalOrdinal, InverseGlobalOrdinal, InverseNode>;
173  using InverseCrs = Tpetra::CrsMatrix<InverseScalar, InverseLocalOrdinal, InverseGlobalOrdinal, InverseNode>;
174  using InverseMap = typename Tpetra::Map<InverseLocalOrdinal, InverseGlobalOrdinal, InverseNode>;
175  using InverseGraph = typename InverseCrs::crs_graph_type;
176  using typename Container<MatrixType>::HostView;
177  using typename Container<MatrixType>::ConstHostView;
178  using HostViewInverse = typename inverse_mv_type::dual_view_type::t_host;
179 
180  static_assert(std::is_same<MatrixType,
181  Tpetra::RowMatrix<SC, LO, GO, NO>>::value, "Ifpack2::SparseContainer: Please use MatrixType = Tpetra::RowMatrix.");
182 
191  using typename Container<MatrixType>::row_matrix_type;
193 
194 public:
196 
197 
209  const Teuchos::Array<Teuchos::Array<LO> >& partitions,
210  const Teuchos::RCP<const import_type>& importer,
211  bool pointIndexed);
212 
214  virtual ~SparseContainer();
215 
217 
219 
221  virtual void setParameters(const Teuchos::ParameterList& List);
222 
224 
226 
228  virtual void initialize();
229 
231  virtual void compute ();
232 
236  void clearBlocks ();
237 
239  virtual void
240  apply (ConstHostView X,
241  HostView Y,
242  int blockIndex,
244  SC alpha = Teuchos::ScalarTraits<SC>::one(),
245  SC beta = Teuchos::ScalarTraits<SC>::zero()) const;
246 
248  virtual void
249  weightedApply (ConstHostView X,
250  HostView Y,
251  ConstHostView W,
252  int blockIndex,
254  SC alpha = Teuchos::ScalarTraits<SC>::one(),
255  SC beta = Teuchos::ScalarTraits<SC>::zero()) const;
256 
258 
260 
264  virtual std::ostream& print(std::ostream& os) const;
265 
267 
269 
271  virtual std::string description () const;
272 
274  virtual void
276  const Teuchos::EVerbosityLevel verbLevel =
279 
281  static std::string getName();
282 
283 private:
284 
287 
289  void extract ();
290  void extractGraph ();
291  void extractValues ();
292 
304  void
305  solveBlockMV(const inverse_mv_type& X,
306  inverse_mv_type& Y,
307  int blockIndex,
308  Teuchos::ETransp mode,
309  InverseScalar alpha,
310  InverseScalar beta) const;
311 
313  std::vector<Teuchos::RCP<InverseCrs>> diagBlocks_;
314 
316  mutable std::vector<inverse_mv_type> invX;
318  mutable std::vector<inverse_mv_type> invY;
319 
327  mutable Teuchos::Array<Teuchos::RCP<InverseType>> Inverses_;
330 
331 
334 };
335 
336 }// namespace Ifpack2
337 
338 #endif // IFPACK2_SPARSECONTAINER_HPP
static std::string getName()
Get the name of this container type for Details::constructContainer()
Definition: Ifpack2_SparseContainer_def.hpp:946
SparseContainer(const Teuchos::RCP< const row_matrix_type > &matrix, const Teuchos::Array< Teuchos::Array< LO > > &partitions, const Teuchos::RCP< const import_type > &importer, bool pointIndexed)
Constructor.
Definition: Ifpack2_SparseContainer_def.hpp:60
Store and solve a local sparse linear problem.
Definition: Ifpack2_SparseContainer_decl.hpp:134
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to the given FancyOStream.
Definition: Ifpack2_SparseContainer_def.hpp:491
The implementation of the numerical features of Container (Jacobi, Gauss-Seidel, SGS). This class allows a custom scalar type (LocalScalarType) to be used for storing blocks and solving the block systems. Hiding this template parameter from the Container interface simplifies the BlockRelaxation and ContainerFactory classes.
Definition: Ifpack2_Container_decl.hpp:343
virtual void initialize()
Do all set-up operations that only require matrix structure.
Definition: Ifpack2_SparseContainer_def.hpp:86
virtual std::ostream & print(std::ostream &os) const
Print information about this object to the given output stream.
Definition: Ifpack2_SparseContainer_def.hpp:454
Declaration and definition of the Ifpack2::Details::MultiVectorLocalGatherScatter class...
virtual std::string description() const
A one-line description of this object.
Definition: Ifpack2_SparseContainer_def.hpp:464
typename mv_type::dual_view_type::t_host HostView
Definition: Ifpack2_Container_decl.hpp:139
virtual void apply(ConstHostView X, HostView Y, int blockIndex, Teuchos::ETransp mode=Teuchos::NO_TRANS, SC alpha=Teuchos::ScalarTraits< SC >::one(), SC beta=Teuchos::ScalarTraits< SC >::zero()) const
Compute Y := alpha * M^{-1} X + beta*Y.
Definition: Ifpack2_SparseContainer_def.hpp:180
static const EVerbosityLevel verbLevel_default
virtual void weightedApply(ConstHostView X, HostView Y, ConstHostView W, int blockIndex, Teuchos::ETransp mode=Teuchos::NO_TRANS, SC alpha=Teuchos::ScalarTraits< SC >::one(), SC beta=Teuchos::ScalarTraits< SC >::zero()) const
Compute Y := alpha * diag(D) * M^{-1} (diag(D) * X) + beta*Y.
Definition: Ifpack2_SparseContainer_def.hpp:304
virtual ~SparseContainer()
Destructor (declared virtual for memory safety of derived classes).
Definition: Ifpack2_SparseContainer_def.hpp:75
virtual void setParameters(const Teuchos::ParameterList &List)
Set all necessary parameters.
Definition: Ifpack2_SparseContainer_def.hpp:79
virtual void compute()
Initialize and compute all blocks.
Definition: Ifpack2_SparseContainer_def.hpp:118
Declaration of ILUT preconditioner.
void clearBlocks()
Definition: Ifpack2_SparseContainer_def.hpp:142