ifp_parameters.cpp

Go to the documentation of this file.
00001 
00002 #include <Epetra_CombineMode.h>
00003 #include <ifp_parameters.h>
00004 
00005 #ifdef HAVE_TEUCHOS_EXTENDED
00006 #include <Teuchos_StrUtils.hpp>
00007 #endif
00008 
00009 namespace Ifpack {
00010 
00011 #ifdef HAVE_IFPACK_TEUCHOS
00012 //----------------------------------------------------------------------------
00013 Teuchos::map<string,parameter>& key_map()
00014 {
00015   static Teuchos::map<string,parameter> ifpack_key_map;
00016   return( ifpack_key_map );
00017 }
00018 
00019 //----------------------------------------------------------------------------
00020 void initialize_string_map()
00021 {
00022   static bool already_initialized = false;
00023   if (already_initialized) {
00024     return;
00025   }
00026 
00027   Teuchos::map<string,parameter>& ifp_key_map = key_map();
00028 
00029   ifp_key_map["LEVEL_FILL"]    = level_fill;
00030   ifp_key_map["LEVEL_OVERLAP"] = level_overlap;
00031   ifp_key_map["ABSOLUTE_THRESHOLD"] = absolute_threshold;
00032   ifp_key_map["RELATIVE_THRESHOLD"] = relative_threshold;
00033   ifp_key_map["OVERLAP_MODE"] = overlap_mode;
00034   ifp_key_map["DROP_TOLERANCE"] = drop_tolerance;
00035   ifp_key_map["FILL_TOLERANCE"] = fill_tolerance;
00036   ifp_key_map["RELAX_VALUE"] = relax_value;
00037   ifp_key_map["USE_RECIPROCAL"] = use_reciprocal;
00038   ifp_key_map["NUM_STEPS"] = num_steps;
00039 
00040   already_initialized = true;
00041 }
00042 
00043 //----------------------------------------------------------------------------
00044 string upper_case(const string& s)
00045 {
00046 #ifdef HAVE_TEUCHOS_EXTENDED
00047   string upp = Teuchos::StrUtils::allCaps(s);
00048 #else
00049   string upp(s);
00050   for(unsigned i=0; i<upp.length(); ++i) {
00051     upp[i] = toupper(upp[i]);
00052   }
00053 #endif
00054 
00055   return(upp);
00056 }
00057 
00058 //----------------------------------------------------------------------------
00059 void set_parameters(const Teuchos::ParameterList& parameterlist,
00060                     param_struct& params,
00061                     bool cerr_warning_if_unused)
00062 {
00063   initialize_string_map();
00064 
00065   Teuchos::map<string,parameter>& ifp_key_map = key_map();
00066 
00067   Teuchos::ParameterList::ConstIterator
00068     pl_iter = parameterlist.begin(),
00069     pl_end  = parameterlist.end();
00070 
00071   for(; pl_iter != pl_end; ++pl_iter) {
00072     string name = upper_case((*pl_iter).first);
00073 
00074     const Teuchos::ParameterEntry& entry = (*pl_iter).second;
00075     bool entry_used = false;
00076 
00077     Teuchos::map<string,parameter>::iterator result = ifp_key_map.find(name);
00078     if (result != ifp_key_map.end()) {
00079       int dummy_int = -1;
00080       double dummy_double = -99.9;
00081       bool dummy_bool = false;
00082       Epetra_CombineMode dummy_mode = Add;
00083 
00084       parameter offset = (*result).second;
00085 
00086       if (entry.isType<double>()) {
00087         if (offset < FIRST_INT_PARAM) {
00088           params.double_params[offset] = entry.getValue(&dummy_double);
00089           entry_used = true;
00090         }
00091       }
00092       else if (entry.isType<int>()) {
00093         int int_val = entry.getValue(&dummy_int);
00094         if (offset >= FIRST_INT_PARAM && offset <= LAST_INT_PARAM) {
00095           params.int_params[offset-FIRST_INT_PARAM] = int_val;
00096           entry_used = true;
00097         }
00098         else if (offset == use_reciprocal) {
00099           params.use_reciprocal = int_val;
00100           entry_used = true;
00101         }
00102       }
00103       else if (entry.isType<bool>()) {
00104         params.use_reciprocal = entry.getValue(&dummy_bool);
00105         entry_used = true;
00106       }
00107       else if (entry.isType<Epetra_CombineMode>()) {
00108         params.overlap_mode = entry.getValue(&dummy_mode);
00109         entry_used = true;
00110       }
00111     }
00112 
00113     if (!entry_used && cerr_warning_if_unused) {
00114       cerr << "Ifpack set_parameters warning: '"<<name<<"' not used."<<endl;
00115     }
00116   }
00117 }
00118 
00119 #endif //HAVE_IFPACK_TEUCHOS
00120 
00121 } // namespace Ifpack
00122 

Generated on Thu Sep 18 12:37:21 2008 for Ifpack Package Browser (Single Doxygen Collection) by doxygen 1.3.9.1