10#ifndef IFPACK2_DETAILS_FACTORY_DEF_HPP
11#define IFPACK2_DETAILS_FACTORY_DEF_HPP
13#include "Ifpack2_Factory.hpp"
15#include "Ifpack2_Details_OneLevelFactory.hpp"
16#include "Ifpack2_AdditiveSchwarz.hpp"
17#if defined(HAVE_IFPACK2_EXPERIMENTAL) && defined(HAVE_IFPACK2_SUPPORTGRAPH)
18#include "Ifpack2_SupportGraph.hpp"
24template <
class SC,
class LO,
class GO,
class NT>
25Teuchos::RCP<typename Factory<SC, LO, GO, NT>::prec_type>
26Factory<SC, LO, GO, NT>::
27 create(
const std::string& precType,
28 const Teuchos::RCP<const row_matrix_type>& matrix,
35 std::string precTypeUpper = canonicalize(precType);
37 if (precTypeUpper ==
"SCHWARZ") {
52 prec = rcp(
new AdditiveSchwarz<row_matrix_type>(matrix, overlap));
53 }
else if (precTypeUpper ==
"KRYLOV") {
54 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
55 "The \"KRYLOV\" preconditioner option has "
56 "been deprecated and removed. If you want a Krylov solver, use the "
59#if defined(HAVE_IFPACK2_EXPERIMENTAL) && defined(HAVE_IFPACK2_SUPPORTGRAPH)
60 else if (precTypeUpper ==
"SUPPORTGRAPH") {
61 prec = rcp(
new SupportGraph<row_matrix_type>(matrix));
66 Details::OneLevelFactory<row_matrix_type> factory;
67 prec = factory.create(precType, matrix);
68 }
catch (std::invalid_argument&) {
69 TEUCHOS_TEST_FOR_EXCEPTION(
70 true, std::invalid_argument,
71 "Ifpack2::Factory::create: "
72 "Invalid preconditioner type \""
73 << precType <<
"\".");
79template <
class SC,
class LO,
class GO,
class NT>
80Teuchos::RCP<typename Factory<SC, LO, GO, NT>::prec_type>
81Factory<SC, LO, GO, NT>::
82 create(
const std::string& precType,
83 const Teuchos::RCP<const row_matrix_type>& matrix) {
89 std::string precTypeUpper(precType);
90 if (precTypeUpper.size() > 0) {
91 for (
size_t k = 0; k < precTypeUpper.size(); ++k) {
92 precTypeUpper[k] = ::toupper(precTypeUpper[k]);
96 if (precTypeUpper ==
"SCHWARZ") {
118 prec = rcp(
new AdditiveSchwarz<row_matrix_type>(matrix));
119 }
else if (precTypeUpper ==
"KRYLOV") {
120 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
121 "The \"KRYLOV\" preconditioner option has "
122 "been deprecated and removed. If you want a Krylov solver, use the "
125#if defined(HAVE_IFPACK2_EXPERIMENTAL) && defined(HAVE_IFPACK2_SUPPORTGRAPH)
126 else if (precTypeUpper ==
"SUPPORTGRAPH") {
127 prec = rcp(
new SupportGraph<row_matrix_type>(matrix));
131 bool success =
false;
132 std::ostringstream err;
134 Details::OneLevelFactory<row_matrix_type> factory;
135 prec = factory.create(precType, matrix);
137 }
catch (std::invalid_argument& e) {
138 err <<
"Ifpack2::Factory::create: Invalid preconditioner type \""
139 << precType <<
"\". More information for Ifpack2 developers: "
142 TEUCHOS_TEST_FOR_EXCEPTION(!success, std::invalid_argument, err.str());
145 TEUCHOS_TEST_FOR_EXCEPTION(
146 prec.is_null(), std::logic_error,
147 "Ifpack2::Factory::create: "
148 "Return value is null right before return. This should never happen. "
149 "Please report this bug to the Ifpack2 developers.");
153template <
class SC,
class LO,
class GO,
class NT>
154Teuchos::RCP<typename Factory<SC, LO, GO, NT>::prec_type>
155Factory<SC, LO, GO, NT>::
156 create(
const std::string& precType,
157 const Teuchos::RCP<const row_matrix_type>& matrix,
158 const Teuchos::RCP<const coord_type>& coordinates) {
164 std::string precTypeUpper(precType);
165 if (precTypeUpper.size() > 0) {
166 for (
size_t k = 0; k < precTypeUpper.size(); ++k) {
167 precTypeUpper[k] = ::toupper(precTypeUpper[k]);
171 if (precTypeUpper ==
"SCHWARZ") {
193 prec = rcp(
new AdditiveSchwarz<row_matrix_type>(matrix, coordinates));
195 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
196 "Using stream-based RILUK with RCB partitioning on "
197 "coordinates associated with matrix rows is currently "
198 "enabled only with Additive Schwarz preconditioner "
199 "and RILUK as a subdomain solver.");
202 TEUCHOS_TEST_FOR_EXCEPTION(
203 prec.is_null(), std::logic_error,
204 "Ifpack2::Factory::create: "
205 "Return value is null right before return. This should never happen. "
206 "Please report this bug to the Ifpack2 developers.");
210template <
class SC,
class LO,
class GO,
class NT>
211std::vector<std::string>
212Factory<SC, LO, GO, NT>::
213 getSupportedNames()
const {
214 Details::OneLevelFactory<row_matrix_type> factory;
215 std::vector<std::string> supportedNames = factory.getSupportedNames();
216 supportedNames.push_back(
"SCHWARZ");
217#if defined(HAVE_IFPACK2_EXPERIMENTAL) && defined(HAVE_IFPACK2_SUPPORTGRAPH)
218 supportedNames.push_back(
"SUPPORTGRAPH");
220 return supportedNames;
223template <
class SC,
class LO,
class GO,
class NT>
224bool Factory<SC, LO, GO, NT>::
225 isSupported(
const std::string& precType) {
227 std::string precTypeUpper = canonicalize(precType);
229 std::vector<std::string> supportedNames = getSupportedNames();
230 auto it = std::find(std::begin(supportedNames), std::end(supportedNames), precTypeUpper);
231 return it != std::end(supportedNames);
237#define IFPACK2_DETAILS_FACTORY_INSTANT(S, LO, GO, N) \
238 template class Ifpack2::Details::Factory<S, LO, GO, N>;
File for utility functions.
Ifpack2 implementation details.
Preconditioners and smoothers for Tpetra sparse matrices.
Definition Ifpack2_AdditiveSchwarz_decl.hpp:40