|
IFPACK Development
|
00001 /*@HEADER 00002 // *********************************************************************** 00003 // 00004 // Ifpack: Object-Oriented Algebraic Preconditioner Package 00005 // Copyright (2002) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 // USA 00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 //@HEADER 00028 */ 00029 00030 #include <Epetra_CombineMode.h> 00031 #include <ifp_parameters.h> 00032 00033 #ifdef HAVE_TEUCHOS_EXTENDED 00034 #include <Teuchos_StrUtils.hpp> 00035 #endif 00036 00037 namespace Ifpack { 00038 00039 //---------------------------------------------------------------------------- 00040 Teuchos::map<string,parameter>& key_map() 00041 { 00042 static Teuchos::map<string,parameter> ifpack_key_map; 00043 return( ifpack_key_map ); 00044 } 00045 00046 //---------------------------------------------------------------------------- 00047 void initialize_string_map() 00048 { 00049 static bool already_initialized = false; 00050 if (already_initialized) { 00051 return; 00052 } 00053 00054 Teuchos::map<string,parameter>& ifp_key_map = key_map(); 00055 00056 ifp_key_map["LEVEL_FILL"] = level_fill; 00057 ifp_key_map["LEVEL_OVERLAP"] = level_overlap; 00058 ifp_key_map["ABSOLUTE_THRESHOLD"] = absolute_threshold; 00059 ifp_key_map["RELATIVE_THRESHOLD"] = relative_threshold; 00060 ifp_key_map["OVERLAP_MODE"] = overlap_mode; 00061 ifp_key_map["DROP_TOLERANCE"] = drop_tolerance; 00062 ifp_key_map["FILL_TOLERANCE"] = fill_tolerance; 00063 ifp_key_map["RELAX_VALUE"] = relax_value; 00064 ifp_key_map["USE_RECIPROCAL"] = use_reciprocal; 00065 ifp_key_map["NUM_STEPS"] = num_steps; 00066 00067 already_initialized = true; 00068 } 00069 00070 //---------------------------------------------------------------------------- 00071 string upper_case(const string& s) 00072 { 00073 #ifdef HAVE_TEUCHOS_EXTENDED 00074 string upp = Teuchos::StrUtils::allCaps(s); 00075 #else 00076 string upp(s); 00077 for(unsigned i=0; i<upp.length(); ++i) { 00078 upp[i] = toupper(upp[i]); 00079 } 00080 #endif 00081 00082 return(upp); 00083 } 00084 00085 //---------------------------------------------------------------------------- 00086 void set_parameters(const Teuchos::ParameterList& parameterlist, 00087 param_struct& params, 00088 bool cerr_warning_if_unused) 00089 { 00090 initialize_string_map(); 00091 00092 Teuchos::map<string,parameter>& ifp_key_map = key_map(); 00093 00094 Teuchos::ParameterList::ConstIterator 00095 pl_iter = parameterlist.begin(), 00096 pl_end = parameterlist.end(); 00097 00098 for(; pl_iter != pl_end; ++pl_iter) { 00099 string name = upper_case((*pl_iter).first); 00100 00101 const Teuchos::ParameterEntry& entry = (*pl_iter).second; 00102 bool entry_used = false; 00103 00104 Teuchos::map<string,parameter>::iterator result = ifp_key_map.find(name); 00105 if (result != ifp_key_map.end()) { 00106 int dummy_int = -1; 00107 double dummy_double = -99.9; 00108 bool dummy_bool = false; 00109 Epetra_CombineMode dummy_mode = Add; 00110 00111 parameter offset = (*result).second; 00112 00113 if (entry.isType<double>()) { 00114 if (offset < FIRST_INT_PARAM) { 00115 params.double_params[offset] = entry.getValue(&dummy_double); 00116 entry_used = true; 00117 } 00118 } 00119 else if (entry.isType<int>()) { 00120 int int_val = entry.getValue(&dummy_int); 00121 if (offset >= FIRST_INT_PARAM && offset <= LAST_INT_PARAM) { 00122 params.int_params[offset-FIRST_INT_PARAM] = int_val; 00123 entry_used = true; 00124 } 00125 else if (offset == use_reciprocal) { 00126 params.use_reciprocal = int_val; 00127 entry_used = true; 00128 } 00129 } 00130 else if (entry.isType<bool>()) { 00131 params.use_reciprocal = entry.getValue(&dummy_bool); 00132 entry_used = true; 00133 } 00134 else if (entry.isType<Epetra_CombineMode>()) { 00135 params.overlap_mode = entry.getValue(&dummy_mode); 00136 entry_used = true; 00137 } 00138 } 00139 00140 if (!entry_used && cerr_warning_if_unused) { 00141 cerr << "Ifpack set_parameters warning: '"<<name<<"' not used."<<endl; 00142 } 00143 } 00144 } 00145 00146 } // namespace Ifpack 00147
1.7.4