NLPInterfacePack_CalcFiniteDiffProdSetOptions.cpp

00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
00005 //                  Copyright (2003) 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 Roscoe A. Bartlett (rabartl@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #include <assert.h>
00030 #include <math.h>
00031 
00032 #include "NLPInterfacePack_CalcFiniteDiffProdSetOptions.hpp"
00033 #include "Teuchos_TestForException.hpp"
00034 
00035 // Define the options
00036 namespace {
00037 
00038   const int local_num_options = 6;
00039 
00040   enum local_EOptions {
00041     FD_METHOD_ORDER
00042     ,FD_STEP_SELECT
00043     ,FD_STEP_SIZE
00044     ,FD_STEP_SIZE_MIN
00045     ,FD_STEP_SIZE_F
00046     ,FD_STEP_SIZE_C
00047   };
00048 
00049   const char* local_SOptions[local_num_options] = {
00050     "fd_method_order"
00051     ,"fd_step_select"
00052     ,"fd_step_size"
00053     ,"fd_step_size_min"
00054     ,"fd_step_size_f"
00055     ,"fd_step_size_c"
00056   };
00057 
00058 }
00059 
00060 namespace NLPInterfacePack {
00061 
00062 CalcFiniteDiffProdSetOptions::CalcFiniteDiffProdSetOptions(
00063   CalcFiniteDiffProd* target
00064   ,const char opt_grp_name[]
00065   )
00066   :OptionsFromStreamPack::SetOptionsFromStreamNode(opt_grp_name,local_num_options,local_SOptions)
00067   ,OptionsFromStreamPack::SetOptionsToTargetBase<CalcFiniteDiffProd>(target)
00068 {}
00069 
00070 void CalcFiniteDiffProdSetOptions::setOption(
00071   int option_num, const std::string& option_value )
00072 {
00073   typedef CalcFiniteDiffProd target_t;
00074   switch( (local_EOptions)option_num ) {
00075       case FD_METHOD_ORDER:
00076     {
00077       const std::string &option = option_value.c_str();
00078       if( option == "FD_ORDER_ONE" )
00079         target().fd_method_order( target_t::FD_ORDER_ONE );
00080       else if( option == "FD_ORDER_TWO" )
00081         target().fd_method_order( target_t::FD_ORDER_TWO );
00082       else if( option == "FD_ORDER_TWO_CENTRAL" )
00083         target().fd_method_order( target_t::FD_ORDER_TWO_CENTRAL );
00084       else if( option == "FD_ORDER_TWO_AUTO" )
00085         target().fd_method_order( target_t::FD_ORDER_TWO_AUTO );
00086       else if( option == "FD_ORDER_FOUR" )
00087         target().fd_method_order( target_t::FD_ORDER_FOUR );
00088       else if( option == "FD_ORDER_FOUR_CENTRAL" )
00089         target().fd_method_order( target_t::FD_ORDER_FOUR_CENTRAL );
00090       else if( option == "FD_ORDER_FOUR_AUTO" )
00091         target().fd_method_order( target_t::FD_ORDER_FOUR_AUTO );
00092       else
00093         TEST_FOR_EXCEPTION(
00094           true, std::invalid_argument
00095           ,"CalcFiniteDiffProdSetOptions::setOption(...) : Error, incorrect value for "
00096           "\"fd_method_order\".  Only the options FD_ORDER_ONE, FD_ORDER_TWO, "
00097           "FD_ORDER_TWO_CENTRAL, FD_ORDER_TWO_AUTO, FD_ORDER_FOUR, FD_ORDER_FOUR_CENTRAL "
00098           "and FD_ORDER_FOUR_AUTO are available" );
00099       break;
00100     }
00101       case FD_STEP_SELECT:
00102     {
00103       const std::string &option = option_value.c_str();
00104       if( option == "FD_STEP_ABSOLUTE" )
00105         target().fd_step_select( target_t::FD_STEP_ABSOLUTE );
00106       else if( option == "FD_STEP_RELATIVE" )
00107         target().fd_step_select( target_t::FD_STEP_RELATIVE );
00108       else
00109         TEST_FOR_EXCEPTION(
00110           true, std::invalid_argument
00111           ,"CalcFiniteDiffProdSetOptions::setOption(...) : Error, incorrect value for "
00112           "\"fd_step_select\".  Only the options are available" );
00113       break;
00114     }
00115       case FD_STEP_SIZE:
00116       target().fd_step_size(std::atof(option_value.c_str()));
00117       break;
00118       case FD_STEP_SIZE_MIN:
00119       target().fd_step_size_min(std::atof(option_value.c_str()));
00120       break;
00121       case FD_STEP_SIZE_F:
00122       target().fd_step_size_f(std::atof(option_value.c_str()));
00123       break;
00124       case FD_STEP_SIZE_C:
00125       target().fd_step_size_c(std::atof(option_value.c_str()));
00126       break;
00127     default:
00128       TEST_FOR_EXCEPT(true);  // Local error only?
00129   }
00130 }
00131 
00132 } // end namespace NLPInterfacePack

Generated on Tue Jul 13 09:29:12 2010 for NLPInterfacePack: C++ Interfaces and Implementation for Non-Linear Programs by  doxygen 1.4.7