Ifpack2 Templated Preconditioning Package  Version 1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Ifpack2_BlockTriDiContainer_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_BLOCKTRIDICONTAINER_DECL_HPP
44 #define IFPACK2_BLOCKTRIDICONTAINER_DECL_HPP
45 
48 
49 #include "Ifpack2_config.h"
50 #include "Ifpack2_Container.hpp"
51 #include "Tpetra_MultiVector.hpp"
52 #include "Tpetra_Map.hpp"
53 #include "Tpetra_RowMatrix.hpp"
54 #include "Tpetra_BlockCrsMatrix_decl.hpp"
55 #include <type_traits>
56 #include <string>
57 
58 namespace Ifpack2 {
59 
107 
111  namespace BlockTriDiContainerDetails {
115  struct ImplNotAvailTag {};
116  struct ImplSimdTag {};
117  struct ImplSacadoTag {};
118 
119  template<typename T> struct ImplTag { typedef ImplNotAvailTag type; };
120  template<> struct ImplTag<float> { typedef ImplSimdTag type; };
121  template<> struct ImplTag<double> { typedef ImplSimdTag type; };
122  template<> struct ImplTag<std::complex<float> > { typedef ImplSimdTag type; };
123  template<> struct ImplTag<std::complex<double> > { typedef ImplSimdTag type; };
124 
126  template<typename MatrixType> struct ImplObject;
127  }
128 
132  template <typename MatrixType,
135 
141  template <typename MatrixType>
142  class BlockTriDiContainer<MatrixType,BlockTriDiContainerDetails::ImplSimdTag>
143  : public Container<MatrixType> {
145 
146  private:
152  typedef MatrixType matrix_type;
153 
155  typedef typename MatrixType::scalar_type scalar_type;
157  typedef typename Kokkos::ArithTraits<scalar_type>::magnitudeType magnitude_type;
159  typedef typename Container<MatrixType>::local_ordinal_type local_ordinal_type;
161  typedef typename Container<MatrixType>::global_ordinal_type global_ordinal_type;
163  typedef typename Container<MatrixType>::node_type node_type;
164 
165  typedef typename Container<MatrixType>::mv_type mv_type;
166  typedef typename Container<MatrixType>::map_type map_type;
167  typedef typename Container<MatrixType>::vector_type vector_type;
168  typedef typename Container<MatrixType>::import_type import_type;
169 
170  typedef typename Container<MatrixType>::HostView host_view_type;
171  typedef host_view_type HostView;
172  //typedef Tpetra::MultiVector<local_scalar_type, local_ordinal_type, global_ordinal_type, node_type> local_mv_type;
173  //typedef typename Kokkos::View<local_scalar_type**, Kokkos::HostSpace> HostViewLocal;
174 
175  typedef Tpetra::BlockCrsMatrix
176  <scalar_type,local_ordinal_type,global_ordinal_type,node_type> block_crs_matrix_type;
177 
184  typedef typename Container<MatrixType>::row_matrix_type row_matrix_type;
185 
186  static_assert (std::is_same<MatrixType, row_matrix_type>::value,
187  "Ifpack2::BlockTriDiContainer: MatrixType must be a Tpetra::RowMatrix specialization.");
189  public:
191 
192 
210  const Teuchos::RCP<const import_type>& importer,
211  bool pointIndexed);
212 
229  bool overlapCommAndComp = false, bool useSequentialMethod = false);
230 
232  ~BlockTriDiContainer () override;
233 
234  struct ComputeParameters {
241  magnitude_type addRadiallyToDiagonal = Kokkos::ArithTraits<magnitude_type>::zero();
242  };
243 
245  struct ApplyParameters {
248  bool zeroStartingSolution = false;
250  scalar_type dampingFactor = Kokkos::ArithTraits<scalar_type>::one();
253  int maxNumSweeps = 1;
263  magnitude_type tolerance = Kokkos::ArithTraits<magnitude_type>::zero();
271  int checkToleranceEvery = 1;
272  };
273 
275 
277 
279  void setParameters(const Teuchos::ParameterList& List) override;
280 
281  void clearBlocks() override;
282 
284 
286 
288  void initialize () override;
289 
291  void compute () override;
292 
293  // \brief Compute <tt>Y := D^{-1} (X - R*Y)</tt>.
294  void applyInverseJacobi (const mv_type& X, mv_type& Y,
295  scalar_type dampingFactor,
296  bool zeroStartingSolution = false,
297  int numSweeps = 1) const override;
298 
300  ComputeParameters createDefaultComputeParameters () const;
301 
313  void compute (const ComputeParameters& input);
314 
316  ApplyParameters createDefaultApplyParameters () const;
317 
324  int applyInverseJacobi (const mv_type& X, mv_type& Y,
325  const ApplyParameters& input) const;
326 
330  const magnitude_type getNorms0 () const;
331 
334  const magnitude_type getNormsFinal () const;
335 
338  void
339  apply (host_view_type X,
340  host_view_type Y,
341  int blockIndex,
343  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
344  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const override;
345 
348  void
349  weightedApply (host_view_type X,
350  host_view_type Y,
351  host_view_type W,
352  int blockIndex,
354  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
355  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const override;
356 
358 
360 
364  std::ostream& print (std::ostream& os) const override;
365 
367 
369 
371  std::string description () const override;
372 
374  void
375  describe (Teuchos::FancyOStream &out,
376  const Teuchos::EVerbosityLevel verbLevel =
378 
380 
382  static std::string getName();
383 
384  private:
387 
388  // hide details of impl using ImplObj; finally I understand why AMB did that way.
390 
391  // initialize distributed and local objects
392  void initInternal (const Teuchos::RCP<const row_matrix_type>& matrix,
394  const Teuchos::RCP<const import_type> &importer,
395  const bool overlapCommAndComp,
396  const bool useSeqMethod);
397 
398  void clearInternal();
399  };
400 
408  template <typename MatrixType>
409  class BlockTriDiContainer<MatrixType,BlockTriDiContainerDetails::ImplNotAvailTag>
410  : public Container<MatrixType> {
411  private:
412  typedef typename MatrixType::scalar_type scalar_type;
413  typedef typename Kokkos::ArithTraits<scalar_type>::magnitudeType magnitude_type;
414  typedef typename Container<MatrixType>::local_ordinal_type local_ordinal_type;
415  typedef typename Container<MatrixType>::global_ordinal_type global_ordinal_type;
416 
417  typedef typename Container<MatrixType>::mv_type mv_type;
418  typedef typename Container<MatrixType>::import_type import_type;
419 
420  typedef typename Container<MatrixType>::HostView host_view_type;
421  typedef typename Container<MatrixType>::row_matrix_type row_matrix_type;
422 
423  static_assert (std::is_same<MatrixType, row_matrix_type>::value,
424  "Ifpack2::BlockTriDiContainer: MatrixType must be a Tpetra::RowMatrix specialization.");
425  public:
426 
429  const Teuchos::RCP<const import_type>& importer,
430  bool pointIndexed)
431  : Container<MatrixType>(matrix, partitions, pointIndexed) {
432  TEUCHOS_TEST_FOR_EXCEPT_MSG(true, "Error: BlockTriDiContainer is not available for this scalar_type");
433  }
434 
435  void setParameters(const Teuchos::ParameterList& List) override {}
436  void clearBlocks() override {}
437 
438  void initialize () override {}
439  void compute () override {}
440  void applyInverseJacobi (const mv_type& X, mv_type& Y,
441  scalar_type dampingFactor,
442  bool zeroStartingSolution = false,
443  int numSweeps = 1) const override {}
444 
445  void
446  apply (host_view_type X,
447  host_view_type Y,
448  int blockIndex,
450  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
451  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const override {}
452 
453  void
454  weightedApply (host_view_type X,
455  host_view_type Y,
456  host_view_type W,
457  int blockIndex,
459  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
460  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const override {}
461 
462  std::ostream& print (std::ostream& os) const override {
463  return os << "Ifpack2::BlockTriDiContainer::ImplNotAvailTag";
464  }
465 
466  std::string description () const override {
467  return "Ifpack2::BlockTriDiContainer::ImplNotAvailTag";
468  }
469 
470  void
471  describe (Teuchos::FancyOStream &out,
472  const Teuchos::EVerbosityLevel verbLevel =
474  out << "Ifpack2::BlockTriDiContainer::ImplNotAvailTag";
475  }
476 
477  static std::string getName() {
478  return "Ifpack2::BlockTriDiContainer::ImplNotAvailTag";
479  }
480  };
481 
482 
483 } // namespace Ifpack2
484 
485 #endif // IFPACK2_BLOCKTRIDICONTAINER_DECL_HPP
Definition: Ifpack2_BlockTriDiContainer_decl.hpp:115
void compute() override
Extract the local diagonal blocks and prepare the solver.
Definition: Ifpack2_BlockTriDiContainer_decl.hpp:439
Store and solve local block tridiagonal linear problems.
Definition: Ifpack2_BlockTriDiContainer_decl.hpp:134
void initialize() override
Do all set-up operations that only require matrix structure.
Definition: Ifpack2_BlockTriDiContainer_decl.hpp:438
#define TEUCHOS_TEST_FOR_EXCEPT_MSG(throw_exception_test, msg)
forward declaration
Definition: Ifpack2_BlockTriDiContainer_decl.hpp:126
typename mv_type::dual_view_type::t_host HostView
Definition: Ifpack2_Container_decl.hpp:139
std::ostream & print(std::ostream &os) const override
Print basic information about the container to os.
Definition: Ifpack2_BlockTriDiContainer_decl.hpp:462
void setParameters(const Teuchos::ParameterList &List) override
Set parameters, if any.
Definition: Ifpack2_BlockTriDiContainer_decl.hpp:435
static const EVerbosityLevel verbLevel_default
Interface for creating and solving a set of local linear problems.
Definition: Ifpack2_Container_decl.hpp:112