IFPACK  Development
 All Classes Files Functions Variables Enumerations Friends
ifp_parameters.cpp
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 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00038 //
00039 // ***********************************************************************
00040 //@HEADER
00041 */
00042 
00043 #include <Epetra_CombineMode.h>
00044 #include <ifp_parameters.h>
00045 
00046 #ifdef HAVE_TEUCHOS_EXTENDED
00047 #include <Teuchos_StrUtils.hpp>
00048 #endif
00049 
00050 namespace Ifpack {
00051 
00052 //----------------------------------------------------------------------------
00053 Teuchos::map<string,parameter>& key_map()
00054 {
00055   static Teuchos::map<string,parameter> ifpack_key_map;
00056   return( ifpack_key_map );
00057 }
00058 
00059 //----------------------------------------------------------------------------
00060 void initialize_string_map()
00061 {
00062   static bool already_initialized = false;
00063   if (already_initialized) {
00064     return;
00065   }
00066 
00067   Teuchos::map<string,parameter>& ifp_key_map = key_map();
00068 
00069   ifp_key_map["LEVEL_FILL"]    = level_fill;
00070   ifp_key_map["LEVEL_OVERLAP"] = level_overlap;
00071   ifp_key_map["ABSOLUTE_THRESHOLD"] = absolute_threshold;
00072   ifp_key_map["RELATIVE_THRESHOLD"] = relative_threshold;
00073   ifp_key_map["OVERLAP_MODE"] = overlap_mode;
00074   ifp_key_map["DROP_TOLERANCE"] = drop_tolerance;
00075   ifp_key_map["FILL_TOLERANCE"] = fill_tolerance;
00076   ifp_key_map["RELAX_VALUE"] = relax_value;
00077   ifp_key_map["USE_RECIPROCAL"] = use_reciprocal;
00078   ifp_key_map["NUM_STEPS"] = num_steps;
00079 
00080   already_initialized = true;
00081 }
00082 
00083 //----------------------------------------------------------------------------
00084 string upper_case(const string& s)
00085 {
00086 #ifdef HAVE_TEUCHOS_EXTENDED
00087   string upp = Teuchos::StrUtils::allCaps(s);
00088 #else
00089   string upp(s);
00090   for(unsigned i=0; i<upp.length(); ++i) {
00091     upp[i] = toupper(upp[i]);
00092   }
00093 #endif
00094 
00095   return(upp);
00096 }
00097 
00098 //----------------------------------------------------------------------------
00099 void set_parameters(const Teuchos::ParameterList& parameterlist,
00100                     param_struct& params,
00101                     bool cerr_warning_if_unused)
00102 {
00103   initialize_string_map();
00104 
00105   Teuchos::map<string,parameter>& ifp_key_map = key_map();
00106 
00107   Teuchos::ParameterList::ConstIterator
00108     pl_iter = parameterlist.begin(),
00109     pl_end  = parameterlist.end();
00110 
00111   for(; pl_iter != pl_end; ++pl_iter) {
00112     string name = upper_case((*pl_iter).first);
00113 
00114     const Teuchos::ParameterEntry& entry = (*pl_iter).second;
00115     bool entry_used = false;
00116 
00117     Teuchos::map<string,parameter>::iterator result = ifp_key_map.find(name);
00118     if (result != ifp_key_map.end()) {
00119       int dummy_int = -1;
00120       double dummy_double = -99.9;
00121       bool dummy_bool = false;
00122       Epetra_CombineMode dummy_mode = Add;
00123 
00124       parameter offset = (*result).second;
00125 
00126       if (entry.isType<double>()) {
00127         if (offset < FIRST_INT_PARAM) {
00128           params.double_params[offset] = entry.getValue(&dummy_double);
00129           entry_used = true;
00130         }
00131       }
00132       else if (entry.isType<int>()) {
00133         int int_val = entry.getValue(&dummy_int);
00134         if (offset >= FIRST_INT_PARAM && offset <= LAST_INT_PARAM) {
00135           params.int_params[offset-FIRST_INT_PARAM] = int_val;
00136           entry_used = true;
00137         }
00138         else if (offset == use_reciprocal) {
00139           params.use_reciprocal = int_val;
00140           entry_used = true;
00141         }
00142       }
00143       else if (entry.isType<bool>()) {
00144         params.use_reciprocal = entry.getValue(&dummy_bool);
00145         entry_used = true;
00146       }
00147       else if (entry.isType<Epetra_CombineMode>()) {
00148         params.overlap_mode = entry.getValue(&dummy_mode);
00149         entry_used = true;
00150       }
00151     }
00152 
00153     if (!entry_used && cerr_warning_if_unused) {
00154       cerr << "Ifpack set_parameters warning: '"<<name<<"' not used."<<endl;
00155     }
00156   }
00157 }
00158 
00159 } // namespace Ifpack
00160 
 All Classes Files Functions Variables Enumerations Friends