Ifpack Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 //----------------------------------------------------------------------------
54 {
55  static Teuchos::map<std::string,parameter> ifpack_key_map;
56  return( ifpack_key_map );
57 }
58 
59 //----------------------------------------------------------------------------
61 {
62  static bool already_initialized = false;
63  if (already_initialized) {
64  return;
65  }
66 
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 
107 
109 
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 
ConstIterator end() const
int int_params[LAST_INT_PARAM-FIRST_INT_PARAM+1]
double double_params[FIRST_INT_PARAM]
static std::string allCaps(const std::string &str)
#define FIRST_INT_PARAM
Teuchos::map< std::string, parameter > & key_map()
Epetra_CombineMode overlap_mode
#define LAST_INT_PARAM
ConstIterator begin() const
T & getValue(const ParameterEntry &entry)
Ifpack: a function class to define Ifpack preconditioners.
Definition: Ifpack.h:138
Epetra_CombineMode
void set_parameters(const Teuchos::ParameterList &parameterlist, param_struct &params, bool cerr_warning_if_unused)
void initialize_string_map()
std::string upper_case(const std::string &s)