Ifpack2 Templated Preconditioning Package  Version 1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Ifpack2_ContainerFactory_def.hpp
1 // @HEADER
2 // *****************************************************************************
3 // Ifpack2: Templated Object-Oriented Algebraic Preconditioner Package
4 //
5 // Copyright 2009 NTESS and the Ifpack2 contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef IFPACK2_CONTAINERFACTORY_DEF_H
11 #define IFPACK2_CONTAINERFACTORY_DEF_H
12 
14 #include "Ifpack2_TriDiContainer.hpp"
15 #include "Ifpack2_DenseContainer.hpp"
16 #include "Ifpack2_SparseContainer.hpp"
17 #include "Ifpack2_BandedContainer.hpp"
18 #include "Ifpack2_BlockTriDiContainer.hpp"
19 #include "Ifpack2_ILUT.hpp"
20 #include "Teuchos_ArrayView.hpp"
21 
22 #include <sstream>
23 
24 namespace Ifpack2 {
25 
26 template <typename MatrixType>
27 void ContainerFactory<MatrixType>::
28  registerDefaults() {
29  registerContainer<Ifpack2::TriDiContainer<MatrixType, scalar_type>>("TriDi");
30  registerContainer<Ifpack2::DenseContainer<MatrixType, scalar_type>>("Dense");
31  registerContainer<Ifpack2::BandedContainer<MatrixType, scalar_type>>("Banded");
32  registerContainer<SparseContainer<MatrixType, ILUT<MatrixType>>>("SparseILUT");
33 #ifdef HAVE_IFPACK2_AMESOS2
34  registerContainer<SparseContainer<MatrixType, Details::Amesos2Wrapper<MatrixType>>>("SparseAmesos");
35  registerContainer<SparseContainer<MatrixType, Details::Amesos2Wrapper<MatrixType>>>("SparseAmesos2");
36 #endif
37 #ifdef HAVE_IFPACK2_EXPERIMENTAL_KOKKOSKERNELS_FEATURES
38  registerContainer<Ifpack2::BlockTriDiContainer<MatrixType>>("BlockTriDi");
39 #endif
40  registeredDefaults = true;
41 }
42 
43 template <typename MatrixType>
44 template <typename ContainerType>
46  registerContainer(std::string containerType) {
47  // overwrite any existing registration with the same name
48  table[containerType] = Teuchos::rcp(new Details::ContainerFactoryEntry<MatrixType, ContainerType>());
49 }
50 
51 template <typename MatrixType>
54  build(std::string containerType,
57  const Teuchos::RCP<const import_type> importer,
58  bool pointIndexed) {
59  if (!registeredDefaults) {
60  registerDefaults();
61  }
62 // In the case that Amesos2 isn't enabled, provide a better error message than the generic one
63 #ifndef HAVE_IFPACK2_AMESOS2
64  if (containerType == "SparseAmesos" || containerType == "SparseAmesos2") {
65  throw std::invalid_argument(
66  "Container type SparseAmesos (aka SparseAmesos2) was requested but Amesos2 isn't enabled.\n"
67  "Add the CMake option \"-D Trilinos_ENABLE_Amesos2=ON\" to enable it.");
68  }
69 #endif
70  if (containerType == "BlockTriDi" && pointIndexed) {
71  throw std::runtime_error("Ifpack2::BlockTriDi does not support decoupled blocks or split rows.\n");
72  }
73  auto it = table.find(containerType);
74  if (it == table.end()) {
75  std::ostringstream oss;
76  oss << "Container type \"" << containerType << "\" not registered.\n";
77  oss << "Call ContainerFactory<MatrixType>::registerContainer<ContainerType>(containerName) first.\n";
78  oss << "Currently registered Container types: ";
79  for (auto r : table) {
80  oss << '\"' << r.first << "\" ";
81  }
82  // remove the single trailing space from final message
83  auto str = oss.str();
84  str = str.substr(0, str.length() - 1);
85  throw std::invalid_argument(str);
86  }
87  return it->second->build(A, localRows, importer, pointIndexed);
88 }
89 
90 template <typename MatrixType>
92  deregisterContainer(std::string containerType) {
93  auto it = table.find(containerType);
94  if (it != table.end()) {
95  table.erase(it);
96  }
97 }
98 
99 // Definitions of static data
100 
101 template <typename MatrixType>
102 std::map<std::string, Teuchos::RCP<Details::ContainerFactoryEntryBase<MatrixType>>> ContainerFactory<MatrixType>::table;
103 
104 template <typename MatrixType>
105 bool ContainerFactory<MatrixType>::registeredDefaults; // this will initially be false
106 
107 } // namespace Ifpack2
108 
109 #define IFPACK2_CONTAINERFACTORY_INSTANT(S, LO, GO, N) \
110  template struct Ifpack2::ContainerFactory<Tpetra::RowMatrix<S, LO, GO, N>>;
111 
112 #endif // IFPACK2_DETAILS_CONTAINERFACTORY_H
static void registerContainer(std::string containerType)
Registers a specialization of Ifpack2::Container by binding a key (string) to it. ...
Definition: Ifpack2_ContainerFactory_def.hpp:46
A static &quot;factory&quot; that provides a way to register and construct arbitrary Ifpack2::Container subclas...
Definition: Ifpack2_ContainerFactory_decl.hpp:77
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
static void deregisterContainer(std::string containerType)
Registers a specialization of Ifpack2::Container by binding a key (string) to it. ...
Definition: Ifpack2_ContainerFactory_def.hpp:92
static Teuchos::RCP< BaseContainer > build(std::string containerType, const Teuchos::RCP< const MatrixType > &A, const Teuchos::Array< Teuchos::Array< local_ordinal_type >> &partitions, const Teuchos::RCP< const import_type > importer, bool pointIndexed)
Build a specialization of Ifpack2::Container given a key that has been registered.
Definition: Ifpack2_ContainerFactory_def.hpp:54
Ifpack2::ContainerFactory class declaration.