Ifpack2 Templated Preconditioning Package Version 1.0
Loading...
Searching...
No Matches
Ifpack2_Details_getParamTryingTypes.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_DETAILS_GETPARAMTRYINGTYPES_HPP
11#define IFPACK2_DETAILS_GETPARAMTRYINGTYPES_HPP
12
13#include "Ifpack2_config.h"
14#include "Teuchos_TypeNameTraits.hpp"
15#include "Teuchos_ParameterList.hpp"
16
17namespace Ifpack2 {
18namespace Details {
19
20template<class ... CandidateTypes>
21struct GetParamTryingTypes {
22 template<class ResultType>
23 static void
24 get (ResultType& result,
25 const Teuchos::ParameterEntry& ent,
26 const std::string& paramName,
27 const char prefix[]);
28};
29
30template<>
31struct GetParamTryingTypes<> {
32 template<class ResultType>
33 static void
34 get (ResultType& /* result */,
35 const Teuchos::ParameterEntry& /* ent */,
36 const std::string& paramName,
37 const char prefix[])
38 {
39 using Teuchos::TypeNameTraits;
40 TEUCHOS_TEST_FOR_EXCEPTION
41 (true, std::invalid_argument, prefix << "\"" << paramName
42 << "\" parameter exists in input ParameterList, but does not "
43 "have the right type. The proper type is "
44 << TypeNameTraits<ResultType>::name () << ".");
45 }
46};
47
48template<class First, class ... Rest>
49struct GetParamTryingTypes<First, Rest...> {
50 template<class ResultType>
51 static void
52 get (ResultType& result,
53 const Teuchos::ParameterEntry& ent,
54 const std::string& paramName,
55 const char prefix[])
56 {
57 if (ent.template isType<First> ()) {
58 result = static_cast<ResultType> (Teuchos::getValue<First> (ent));
59 }
60 else {
61 using rest_type = GetParamTryingTypes<Rest...>;
62 rest_type::template get<ResultType> (result, ent, paramName, prefix);
63 }
64 }
65};
66
67template<class ResultType, class ... CandidateTypes>
68void
69getParamTryingTypes (ResultType& result,
70 const Teuchos::ParameterList& params,
71 const std::string& paramName,
72 const char prefix[])
73{
74 using Teuchos::ParameterEntry;
75 const ParameterEntry* ent = params.getEntryPtr (paramName);
76 if (ent != nullptr) {
77 using impl_type = GetParamTryingTypes<CandidateTypes...>;
78 impl_type::template get<ResultType> (result, *ent, paramName, prefix);
79 }
80}
81
82} // namespace Details
83} // namespace Ifpack2
84
85#endif // IFPACK2_DETAILS_GETPARAMTRYINGTYPES_HPP
Preconditioners and smoothers for Tpetra sparse matrices.
Definition Ifpack2_AdditiveSchwarz_decl.hpp:41