MoochoPack : Framework for Large-Scale Optimization Algorithms  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
MoochoPack_EvalNewPointStd_StepSetOptions.cpp
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
5 // Copyright (2003) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #include <assert.h>
43 
44 #include "MoochoPack_EvalNewPointStd_StepSetOptions.hpp"
45 #include "OptionsFromStreamPack_StringToBool.hpp"
46 #include "Teuchos_Assert.hpp"
47 
48 // Define the options
49 namespace {
50 
51  const int local_num_options = 3;
52 
53  enum local_EOptions {
54  FD_DERIV_TESTING
55  ,DECOMP_SYS_TESTING
56  ,DECOMP_SYS_TESTING_PRINT_LEVEL
57  };
58 
59  const char* local_SOptions[local_num_options] = {
60  "fd_deriv_testing"
61  ,"decomp_sys_testing"
62  ,"decomp_sys_testing_print_level"
63  };
64 
65 }
66 
67 namespace MoochoPack {
68 
69 EvalNewPointStd_StepSetOptions::EvalNewPointStd_StepSetOptions(
70  EvalNewPointStd_Step* target
71  , const char opt_grp_name[] )
72  : OptionsFromStreamPack::SetOptionsFromStreamNode(
73  opt_grp_name, local_num_options, local_SOptions )
74  , OptionsFromStreamPack::SetOptionsToTargetBase<
75  EvalNewPointStd_Step >( target )
76 {}
77 
78 void EvalNewPointStd_StepSetOptions::setOption(
79  int option_num, const std::string& option_value )
80 {
81  using OptionsFromStreamPack::StringToBool;
82 
83  typedef EvalNewPointStd_Step target_t;
84  switch( (local_EOptions)option_num ) {
85  case FD_DERIV_TESTING:
86  {
87  const std::string &option = option_value.c_str();
88  if( option == "FD_DEFAULT" )
89  target().fd_deriv_testing( target_t::FD_DEFAULT );
90  else if( option == "FD_TEST" )
91  target().fd_deriv_testing( target_t::FD_TEST );
92  else if( option == "FD_NO_TEST" )
93  target().fd_deriv_testing( target_t::FD_NO_TEST );
94  else
96  true, std::invalid_argument
97  ,"Error, incorrect value for "
98  "\"fd_deriv_testing\". Only the options "
99  "FD_DEFAULT, FD_TEST, and FD_NO_TEST "
100  "are available" );
101  break;
102  }
103  case DECOMP_SYS_TESTING:
104  {
105  const std::string &option = option_value.c_str();
106  if( option == "DST_DEFAULT" )
107  target().decomp_sys_testing( DecompositionSystemHandler_Strategy::DST_DEFAULT );
108  else if( option == "DST_TEST" )
109  target().decomp_sys_testing( DecompositionSystemHandler_Strategy::DST_TEST );
110  else if( option == "DST_NO_TEST" )
111  target().decomp_sys_testing( DecompositionSystemHandler_Strategy::DST_NO_TEST );
112  else
114  true, std::invalid_argument
115  ,"Error, incorrect value for "
116  "\"decomp_sys_testing\". Only the options "
117  "DST_DEFAULT, DST_TEST, and DST_NO_TEST "
118  "are available" );
119  break;
120  }
121  case DECOMP_SYS_TESTING_PRINT_LEVEL:
122  {
123  const std::string &option = option_value.c_str();
124  if( option == "DSPL_USE_GLOBAL" )
125  target().decomp_sys_testing_print_level( DecompositionSystemHandler_Strategy::DSPL_USE_GLOBAL);
126  else if( option == "DSPL_LEAVE_DEFAULT" )
127  target().decomp_sys_testing_print_level( DecompositionSystemHandler_Strategy::DSPL_LEAVE_DEFAULT);
128  else
130  true, std::invalid_argument
131  ,"Error, incorrect value for "
132  "\"decomp_sys_testing_print_level\". Only the options "
133  "DSPL_USE_GLOBAL and DSPL_LEAVE_DEFAULT are available" );
134  break;
135  }
136  default:
137  TEUCHOS_TEST_FOR_EXCEPT(true); // Local error only?
138  }
139 }
140 
141 } // end namespace MoochoPack
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)