NLPInterfacePack: C++ Interfaces and Implementation for Non-Linear Programs Version of the Day
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 // 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 Roscoe A. Bartlett (rabartl@sandia.gov) 
00038 // 
00039 // ***********************************************************************
00040 // @HEADER
00041 
00042 #include <assert.h>
00043 #include <math.h>
00044 
00045 #include "NLPInterfacePack_CalcFiniteDiffProdSetOptions.hpp"
00046 #include "Teuchos_Assert.hpp"
00047 
00048 // Define the options
00049 namespace {
00050 
00051   const int local_num_options = 6;
00052 
00053   enum local_EOptions {
00054     FD_METHOD_ORDER
00055     ,FD_STEP_SELECT
00056     ,FD_STEP_SIZE
00057     ,FD_STEP_SIZE_MIN
00058     ,FD_STEP_SIZE_F
00059     ,FD_STEP_SIZE_C
00060   };
00061 
00062   const char* local_SOptions[local_num_options] = {
00063     "fd_method_order"
00064     ,"fd_step_select"
00065     ,"fd_step_size"
00066     ,"fd_step_size_min"
00067     ,"fd_step_size_f"
00068     ,"fd_step_size_c"
00069   };
00070 
00071 }
00072 
00073 namespace NLPInterfacePack {
00074 
00075 CalcFiniteDiffProdSetOptions::CalcFiniteDiffProdSetOptions(
00076   CalcFiniteDiffProd* target
00077   ,const char opt_grp_name[]
00078   )
00079   :OptionsFromStreamPack::SetOptionsFromStreamNode(opt_grp_name,local_num_options,local_SOptions)
00080   ,OptionsFromStreamPack::SetOptionsToTargetBase<CalcFiniteDiffProd>(target)
00081 {}
00082 
00083 void CalcFiniteDiffProdSetOptions::setOption(
00084   int option_num, const std::string& option_value )
00085 {
00086   typedef CalcFiniteDiffProd target_t;
00087   switch( (local_EOptions)option_num ) {
00088       case FD_METHOD_ORDER:
00089     {
00090       const std::string &option = option_value.c_str();
00091       if( option == "FD_ORDER_ONE" )
00092         target().fd_method_order( target_t::FD_ORDER_ONE );
00093       else if( option == "FD_ORDER_TWO" )
00094         target().fd_method_order( target_t::FD_ORDER_TWO );
00095       else if( option == "FD_ORDER_TWO_CENTRAL" )
00096         target().fd_method_order( target_t::FD_ORDER_TWO_CENTRAL );
00097       else if( option == "FD_ORDER_TWO_AUTO" )
00098         target().fd_method_order( target_t::FD_ORDER_TWO_AUTO );
00099       else if( option == "FD_ORDER_FOUR" )
00100         target().fd_method_order( target_t::FD_ORDER_FOUR );
00101       else if( option == "FD_ORDER_FOUR_CENTRAL" )
00102         target().fd_method_order( target_t::FD_ORDER_FOUR_CENTRAL );
00103       else if( option == "FD_ORDER_FOUR_AUTO" )
00104         target().fd_method_order( target_t::FD_ORDER_FOUR_AUTO );
00105       else
00106         TEUCHOS_TEST_FOR_EXCEPTION(
00107           true, std::invalid_argument
00108           ,"CalcFiniteDiffProdSetOptions::setOption(...) : Error, incorrect value for "
00109           "\"fd_method_order\".  Only the options FD_ORDER_ONE, FD_ORDER_TWO, "
00110           "FD_ORDER_TWO_CENTRAL, FD_ORDER_TWO_AUTO, FD_ORDER_FOUR, FD_ORDER_FOUR_CENTRAL "
00111           "and FD_ORDER_FOUR_AUTO are available" );
00112       break;
00113     }
00114       case FD_STEP_SELECT:
00115     {
00116       const std::string &option = option_value.c_str();
00117       if( option == "FD_STEP_ABSOLUTE" )
00118         target().fd_step_select( target_t::FD_STEP_ABSOLUTE );
00119       else if( option == "FD_STEP_RELATIVE" )
00120         target().fd_step_select( target_t::FD_STEP_RELATIVE );
00121       else
00122         TEUCHOS_TEST_FOR_EXCEPTION(
00123           true, std::invalid_argument
00124           ,"CalcFiniteDiffProdSetOptions::setOption(...) : Error, incorrect value for "
00125           "\"fd_step_select\".  Only the options are available" );
00126       break;
00127     }
00128       case FD_STEP_SIZE:
00129       target().fd_step_size(std::atof(option_value.c_str()));
00130       break;
00131       case FD_STEP_SIZE_MIN:
00132       target().fd_step_size_min(std::atof(option_value.c_str()));
00133       break;
00134       case FD_STEP_SIZE_F:
00135       target().fd_step_size_f(std::atof(option_value.c_str()));
00136       break;
00137       case FD_STEP_SIZE_C:
00138       target().fd_step_size_c(std::atof(option_value.c_str()));
00139       break;
00140     default:
00141       TEUCHOS_TEST_FOR_EXCEPT(true);  // Local error only?
00142   }
00143 }
00144 
00145 } // end namespace NLPInterfacePack
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends