Ifpack Package Browser (Single Doxygen Collection)
Development
src
ifp_parameters.cpp
Go to the documentation of this file.
1
/*@HEADER
2
// ***********************************************************************
3
//
4
// Ifpack: Object-Oriented Algebraic Preconditioner Package
5
// Copyright (2002) 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
#include <Epetra_CombineMode.h>
44
#include <
ifp_parameters.h
>
45
46
#ifdef HAVE_TEUCHOS_EXTENDED
47
#include <Teuchos_StrUtils.hpp>
48
#endif
49
50
namespace
Ifpack
{
51
52
//----------------------------------------------------------------------------
53
Teuchos::map<std::string,parameter>
&
key_map
()
54
{
55
static
Teuchos::map<std::string,parameter>
ifpack_key_map;
56
return
( ifpack_key_map );
57
}
58
59
//----------------------------------------------------------------------------
60
void
initialize_string_map
()
61
{
62
static
bool
already_initialized =
false
;
63
if
(already_initialized) {
64
return
;
65
}
66
67
Teuchos::map<std::string,parameter>
& ifp_key_map =
key_map
();
68
69
ifp_key_map[
"LEVEL_FILL"
] =
level_fill
;
70
ifp_key_map[
"LEVEL_OVERLAP"
] =
level_overlap
;
71
ifp_key_map[
"ABSOLUTE_THRESHOLD"
] =
absolute_threshold
;
72
ifp_key_map[
"RELATIVE_THRESHOLD"
] =
relative_threshold
;
73
ifp_key_map[
"OVERLAP_MODE"
] =
overlap_mode
;
74
ifp_key_map[
"DROP_TOLERANCE"
] =
drop_tolerance
;
75
ifp_key_map[
"FILL_TOLERANCE"
] =
fill_tolerance
;
76
ifp_key_map[
"RELAX_VALUE"
] =
relax_value
;
77
ifp_key_map[
"USE_RECIPROCAL"
] =
use_reciprocal
;
78
ifp_key_map[
"NUM_STEPS"
] =
num_steps
;
79
80
already_initialized =
true
;
81
}
82
83
//----------------------------------------------------------------------------
84
std::string
upper_case
(
const
std::string& s)
85
{
86
#ifdef HAVE_TEUCHOS_EXTENDED
87
std::string upp =
Teuchos::StrUtils::allCaps
(s);
88
#else
89
std::string upp(s);
90
for
(
unsigned
i=0; i<upp.length(); ++i) {
91
upp[i] = toupper(upp[i]);
92
}
93
#endif
94
95
return
(upp);
96
}
97
98
//----------------------------------------------------------------------------
99
void
set_parameters
(
const
Teuchos::ParameterList
& parameterlist,
100
param_struct
& params,
101
bool
cerr_warning_if_unused)
102
{
103
using
std::cerr;
104
using
std::endl;
105
106
initialize_string_map
();
107
108
Teuchos::map<std::string,parameter>
& ifp_key_map =
key_map
();
109
110
Teuchos::ParameterList::ConstIterator
111
pl_iter = parameterlist.
begin
(),
112
pl_end = parameterlist.
end
();
113
114
for
(; pl_iter != pl_end; ++pl_iter) {
115
std::string name =
upper_case
((*pl_iter).first);
116
117
const
Teuchos::ParameterEntry
& entry = (*pl_iter).second;
118
bool
entry_used =
false
;
119
120
Teuchos::map<std::string,parameter>::iterator
result = ifp_key_map.find(name);
121
if
(result != ifp_key_map.end()) {
122
int
dummy_int = -1;
123
double
dummy_double = -99.9;
124
bool
dummy_bool =
false
;
125
Epetra_CombineMode
dummy_mode =
Add
;
126
127
parameter
offset = (*result).second;
128
129
if
(entry.
isType
<
double
>()) {
130
if
(offset <
FIRST_INT_PARAM
) {
131
params.
double_params
[offset] = entry.
getValue
(&dummy_double);
132
entry_used =
true
;
133
}
134
}
135
else
if
(entry.
isType
<
int
>()) {
136
int
int_val = entry.
getValue
(&dummy_int);
137
if
(offset >=
FIRST_INT_PARAM
&& offset <=
LAST_INT_PARAM
) {
138
params.
int_params
[offset-
FIRST_INT_PARAM
] = int_val;
139
entry_used =
true
;
140
}
141
else
if
(offset ==
use_reciprocal
) {
142
params.
use_reciprocal
= int_val;
143
entry_used =
true
;
144
}
145
}
146
else
if
(entry.
isType
<
bool
>()) {
147
params.
use_reciprocal
= entry.
getValue
(&dummy_bool);
148
entry_used =
true
;
149
}
150
else
if
(entry.
isType
<
Epetra_CombineMode
>()) {
151
params.
overlap_mode
= entry.
getValue
(&dummy_mode);
152
entry_used =
true
;
153
}
154
}
155
156
if
(!entry_used && cerr_warning_if_unused) {
157
cerr <<
"Ifpack set_parameters warning: '"
<<name<<
"' not used."
<<endl;
158
}
159
}
160
}
161
162
}
// namespace Ifpack
163
Teuchos::StrUtils::allCaps
static std::string allCaps(const std::string &str)
Ifpack::use_reciprocal
Definition:
ifp_parameters.h:74
Ifpack::overlap_mode
Definition:
ifp_parameters.h:75
Ifpack::key_map
Teuchos::map< std::string, parameter > & key_map()
Definition:
ifp_parameters.cpp:53
Teuchos::FilteredIterator
Add
Add
Ifpack::param_struct::double_params
double double_params[FIRST_INT_PARAM]
Definition:
ifp_parameters.h:84
Ifpack::level_overlap
Definition:
ifp_parameters.h:70
LAST_INT_PARAM
#define LAST_INT_PARAM
Definition:
ifp_parameters.h:79
Teuchos::ParameterList::end
ConstIterator end() const
Ifpack::drop_tolerance
Definition:
ifp_parameters.h:61
Ifpack::absolute_threshold
Definition:
ifp_parameters.h:59
Teuchos::map
Ifpack::param_struct::int_params
int int_params[LAST_INT_PARAM-FIRST_INT_PARAM+1]
Definition:
ifp_parameters.h:83
Ifpack::param_struct::overlap_mode
Epetra_CombineMode overlap_mode
Definition:
ifp_parameters.h:86
Ifpack::relax_value
Definition:
ifp_parameters.h:63
Teuchos::ParameterEntry::isType
bool isType() const
ifp_parameters.h
Teuchos::ParameterEntry::getValue
T & getValue(const ParameterEntry &entry)
Ifpack::upper_case
std::string upper_case(const std::string &s)
Definition:
ifp_parameters.cpp:84
Ifpack::initialize_string_map
void initialize_string_map()
Definition:
ifp_parameters.cpp:60
Epetra_CombineMode
Epetra_CombineMode
Ifpack
Definition:
ifp_parameters.cpp:50
Ifpack::level_fill
Definition:
ifp_parameters.h:69
Ifpack::param_struct
Definition:
ifp_parameters.h:82
Ifpack::parameter
parameter
Definition:
ifp_parameters.h:57
Ifpack::num_steps
Definition:
ifp_parameters.h:71
Ifpack::set_parameters
void set_parameters(const Teuchos::ParameterList ¶meterlist, param_struct ¶ms, bool cerr_warning_if_unused)
Definition:
ifp_parameters.cpp:99
Teuchos::ParameterList
Ifpack::param_struct::use_reciprocal
bool use_reciprocal
Definition:
ifp_parameters.h:85
Ifpack::fill_tolerance
Definition:
ifp_parameters.h:62
FIRST_INT_PARAM
#define FIRST_INT_PARAM
Definition:
ifp_parameters.h:78
Teuchos::ParameterEntry
Teuchos::ParameterList::begin
ConstIterator begin() const
Ifpack::relative_threshold
Definition:
ifp_parameters.h:60
Generated by
1.8.16