|
MoochoPack : Framework for Large-Scale Optimization Algorithms
Version of the Day
|
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 "MoochoPack_DecompositionSystemStateStepBuilderStd.hpp" 00043 00044 // NLP Stuff 00045 00046 #include "NLPInterfacePack_NLPSecondOrder.hpp" 00047 #include "NLPInterfacePack_NLPDirect.hpp" 00048 #include "NLPInterfacePack_NLPVarReductPerm.hpp" 00049 #include "NLPInterfacePack_NLPDirectTester.hpp" 00050 #include "NLPInterfacePack_NLPDirectTesterSetOptions.hpp" 00051 00052 // Basis system and direct sparse solvers 00053 00054 #include "AbstractLinAlgPack_BasisSystemTester.hpp" 00055 #include "AbstractLinAlgPack_BasisSystemTesterSetOptions.hpp" 00056 #ifndef MOOCHO_NO_BASIS_PERM_DIRECT_SOLVERS 00057 #include "ConstrainedOptPack_DecompositionSystemVarReductPermStd.hpp" 00058 #endif 00059 00060 // Range/null decomposition 00061 00062 #include "AbstractLinAlgPack_MatrixSymIdent.hpp" 00063 #include "MoochoPack_DecompositionSystemHandlerVarReductPerm_Strategy.hpp" 00064 #include "MoochoPack_DecompositionSystemHandlerStd_Strategy.hpp" 00065 #include "ConstrainedOptPack_DecompositionSystemTester.hpp" 00066 #include "ConstrainedOptPack_DecompositionSystemTesterSetOptions.hpp" 00067 #include "ConstrainedOptPack_DecompositionSystemCoordinate.hpp" 00068 #include "ConstrainedOptPack_DecompositionSystemOrthogonal.hpp" 00069 00070 // Iteration quantities 00071 00072 #include "ConstrainedOptPack_MatrixIdentConcatStd.hpp" // Y, Z 00073 #include "AbstractLinAlgPack_MatrixSymOpNonsing.hpp" 00074 00075 // Eval new point 00076 00077 #include "MoochoPack_EvalNewPointStd_StepSetOptions.hpp" 00078 #include "MoochoPack_EvalNewPointTailoredApproach_StepSetOptions.hpp" 00079 #include "MoochoPack_EvalNewPointTailoredApproachCoordinate_Step.hpp" 00080 #include "MoochoPack_EvalNewPointTailoredApproachOrthogonal_Step.hpp" 00081 00082 // Other classes 00083 00084 #include "MoochoPack_NLPAlgoState.hpp" 00085 #include "MoochoPack_NewDecompositionSelectionStd_Strategy.hpp" 00086 #include "ConstrainedOptPack_VariableBoundsTesterSetOptions.hpp" 00087 #include "NLPInterfacePack_CalcFiniteDiffProdSetOptions.hpp" 00088 #include "NLPInterfacePack_NLPFirstDerivTester.hpp" 00089 #include "NLPInterfacePack_NLPFirstDerivTesterSetOptions.hpp" 00090 00091 // Common utilities 00092 #include "OptionsFromStreamPack_StringToIntMap.hpp" 00093 #include "OptionsFromStreamPack_StringToBool.hpp" 00094 #include "OptionsFromStreamPack_OptionsFromStream.hpp" 00095 #include "Teuchos_Assert.hpp" 00096 #include "Teuchos_dyn_cast.hpp" 00097 00098 namespace { 00099 const int DEFAULT_MAX_DOF_QUASI_NEWTON_DENSE = 200; 00100 } // end namespace 00101 00102 namespace MoochoPack { 00103 00104 // 00105 // Here is where we define the default values for the algorithm. These 00106 // should agree with what are in the Moocho.opt.NLPAlgoConfigMamaJama file. 00107 // 00108 DecompositionSystemStateStepBuilderStd::SOptionValues::SOptionValues() 00109 :null_space_matrix_type_(NULL_SPACE_MATRIX_AUTO) 00110 ,range_space_matrix_type_(RANGE_SPACE_MATRIX_AUTO) 00111 ,max_dof_quasi_newton_dense_(-1) 00112 {} 00113 00114 DecompositionSystemStateStepBuilderStd::DecompositionSystemStateStepBuilderStd() 00115 {} 00116 00117 void DecompositionSystemStateStepBuilderStd::set_options( const options_ptr_t& options ) 00118 { 00119 options_ = options; 00120 } 00121 00122 const DecompositionSystemStateStepBuilderStd::options_ptr_t& 00123 DecompositionSystemStateStepBuilderStd::get_options() const 00124 { 00125 return options_; 00126 } 00127 00128 void DecompositionSystemStateStepBuilderStd::process_nlp_and_options( 00129 std::ostream *trase_out 00130 ,NLP &nlp 00131 ,NLPFirstOrder **nlp_foi 00132 ,NLPSecondOrder **nlp_soi 00133 ,NLPDirect **nlp_fod 00134 ,bool *tailored_approach 00135 ) 00136 { 00137 00138 // 00139 // Probe the NLP interfaces 00140 // 00141 00142 // Get the dimensions of the NLP 00143 const size_type 00144 n = nlp.n(), 00145 m = nlp.m(), 00146 r = m, // ToDo: Compute this for real! 00147 dof = n - r; 00148 00149 if(trase_out) 00150 *trase_out << "\n*** Probing the NLP object for supported interfaces ...\n"; 00151 00152 // Determine which NLP interface is supported 00153 *nlp_foi = dynamic_cast<NLPFirstOrder*>(&nlp); 00154 *nlp_soi = dynamic_cast<NLPSecondOrder*>(&nlp); 00155 *nlp_fod = dynamic_cast<NLPDirect*>(&nlp); 00156 *tailored_approach = false; 00157 if( *nlp_foi ) { 00158 if(trase_out) 00159 *trase_out << "\nDetected that NLP object supports the NLPFirstOrder interface!\n"; 00160 *tailored_approach = false; 00161 } 00162 else if( *nlp_fod ) { 00163 if(trase_out) 00164 *trase_out << "\nDetected that NLP object supports the NLPDirect interface!\n"; 00165 *tailored_approach = true; 00166 } 00167 else { 00168 TEUCHOS_TEST_FOR_EXCEPTION( 00169 true, std::logic_error 00170 ,"NLPAlgoConfigMamaJama::config_algo_cntr(...) : Error, " 00171 "the NLP object of type \'" << typeName(nlp) << 00172 "\' does not support the NLPFirstOrder or NLPDirect " 00173 "interfaces!" ); 00174 } 00175 if( *nlp_soi ) { 00176 if(trase_out) 00177 *trase_out << "\nDetected that NLP object also supports the NLPSecondOrder interface!\n"; 00178 } 00179 00180 // 00181 // Process the options 00182 // 00183 00184 // Readin the options 00185 if(options_.get()) { 00186 readin_options( *options_, &uov_, trase_out ); 00187 } 00188 else { 00189 if(trase_out) { 00190 *trase_out 00191 << "\n*** Warning, no OptionsFromStream object was set so a default set" 00192 " of options will be used!\n"; 00193 } 00194 } 00195 00196 // Set default 00197 if( uov_.max_dof_quasi_newton_dense_ < 0 ) 00198 cov_.max_dof_quasi_newton_dense_ = DEFAULT_MAX_DOF_QUASI_NEWTON_DENSE; 00199 else 00200 cov_.max_dof_quasi_newton_dense_ = uov_.max_dof_quasi_newton_dense_; 00201 00202 // Decide what type of range-space matrix to use 00203 if( r && uov_.range_space_matrix_type_ == RANGE_SPACE_MATRIX_AUTO ) { 00204 const bool use_orth = (dof*dof/r) <= cov_.max_dof_quasi_newton_dense_*cov_.max_dof_quasi_newton_dense_; 00205 if(trase_out) 00206 *trase_out 00207 << "\nrange_space_matrix == AUTO:" 00208 << "\n(n-r)^2/r = (" << dof << ")^2/r = " << (dof*dof/r) 00209 << ( use_orth ? " <= " : " > " ) << "max_dof_quasi_newton_dense^2 = (" 00210 << cov_.max_dof_quasi_newton_dense_ << ")^2 = " 00211 << cov_.max_dof_quasi_newton_dense_*cov_.max_dof_quasi_newton_dense_ 00212 << ( use_orth 00213 ? "\nsetting range_space_matrix = ORTHOGONAL\n" 00214 : "\nsetting range_space_matrix = COORDINATE\n" ); 00215 cov_.range_space_matrix_type_ = 00216 ( use_orth 00217 ? RANGE_SPACE_MATRIX_ORTHOGONAL 00218 : RANGE_SPACE_MATRIX_COORDINATE ); 00219 } 00220 00221 // Set the default options that where not already set yet 00222 set_default_options(uov_,&cov_,trase_out); 00223 00224 } 00225 00226 void DecompositionSystemStateStepBuilderStd::create_decomp_sys( 00227 std::ostream *trase_out 00228 ,NLP &nlp 00229 ,NLPFirstOrder *nlp_foi 00230 ,NLPSecondOrder *nlp_soi 00231 ,NLPDirect *nlp_fod 00232 ,bool tailored_approach 00233 ,Teuchos::RCP<DecompositionSystem> *decomp_sys 00234 ) 00235 { 00236 namespace mmp = MemMngPack; 00237 using Teuchos::RCP; 00238 00239 const size_type 00240 m = nlp.m(); 00241 00242 if( m == 0 ) { 00243 *decomp_sys = Teuchos::null; 00244 return; 00245 } 00246 00247 RCP<BasisSystem> basis_sys = Teuchos::null; 00248 if(!tailored_approach) { 00249 // Set the default basis system if one is not set 00250 basis_sys = nlp_foi->basis_sys(); 00251 if( basis_sys.get() == NULL ) { 00252 TEUCHOS_TEST_FOR_EXCEPTION( 00253 true, std::logic_error 00254 ,"\nA basis system object was not specified by the NLPFirstOrder object of type \'" 00255 << typeName(nlp) << "\' and we can not build a rSQP algorithm without one!" ); 00256 00257 } 00258 // Create the testing object for the basis system and set it up. 00259 RCP<BasisSystemTester> 00260 basis_sys_tester = Teuchos::rcp(new BasisSystemTester()); 00261 if(options_.get()) { 00262 BasisSystemTesterSetOptions 00263 opt_setter(basis_sys_tester.get()); 00264 opt_setter.set_options(*options_); 00265 } 00266 // Determine what type of null space matrix to use 00267 DecompositionSystemVarReduct::EExplicitImplicit 00268 D_imp; 00269 switch( cov_.null_space_matrix_type_ ) { 00270 case NULL_SPACE_MATRIX_AUTO: 00271 D_imp = DecompositionSystemVarReduct::MAT_IMP_AUTO; 00272 break; 00273 case NULL_SPACE_MATRIX_EXPLICIT: 00274 D_imp = DecompositionSystemVarReduct::MAT_IMP_EXPLICIT; 00275 break; 00276 case NULL_SPACE_MATRIX_IMPLICIT: 00277 D_imp = DecompositionSystemVarReduct::MAT_IMP_IMPLICIT; 00278 break; 00279 default: 00280 TEUCHOS_TEST_FOR_EXCEPT(true); 00281 } 00282 #ifndef MOOCHO_NO_BASIS_PERM_DIRECT_SOLVERS 00283 // See if the basis system object supports basis permutations 00284 basis_sys_perm_ = Teuchos::rcp_dynamic_cast<BasisSystemPerm>(basis_sys); 00285 #endif 00286 // Create the DecompositionSystem implementation object 00287 typedef RCP<DecompositionSystemVarReductImp> decomp_sys_imp_ptr_t; 00288 decomp_sys_imp_ptr_t decomp_sys_imp; 00289 switch( cov_.range_space_matrix_type_ ) { 00290 case RANGE_SPACE_MATRIX_COORDINATE: 00291 decomp_sys_imp 00292 = Teuchos::rcp(new DecompositionSystemCoordinate( 00293 nlp.space_x() 00294 ,nlp.space_c() 00295 ,basis_sys // Will have basis_sys_->var_dep().size() == 0 if permutation 00296 ,basis_sys_tester 00297 ,D_imp 00298 ) ); 00299 break; 00300 case RANGE_SPACE_MATRIX_ORTHOGONAL: { 00301 decomp_sys_imp 00302 = Teuchos::rcp(new DecompositionSystemOrthogonal( 00303 nlp.space_x() 00304 ,nlp.space_c() 00305 ,basis_sys // Will have basis_sys_->var_dep().size() == 0 if permutation 00306 ,basis_sys_tester 00307 ) ); 00308 break; 00309 } 00310 default: 00311 TEUCHOS_TEST_FOR_EXCEPT(true); // only a local error 00312 } 00313 #ifndef MOOCHO_NO_BASIS_PERM_DIRECT_SOLVERS 00314 // Create the actual DecompositionSystem object being used 00315 if( basis_sys_perm_.get() != NULL ) { 00316 if(trase_out) 00317 *trase_out 00318 << "\nThe BasisSystem object with concreate type \'" << typeName(*basis_sys) 00319 << "\' supports the BasisSystemPerm interface.\n" 00320 << "Using DecompositionSystemVarReductPermStd to support basis permutations ...\n"; 00321 *decomp_sys = Teuchos::rcp( 00322 new DecompositionSystemVarReductPermStd( 00323 decomp_sys_imp 00324 ,basis_sys_perm_ 00325 ,false // basis_selected 00326 ,D_imp 00327 ) ); 00328 } 00329 else { 00330 #endif 00331 if(trase_out) 00332 *trase_out 00333 << "\nThe BasisSystem object with concreate type \'" << typeName(*basis_sys) 00334 << "\' does not support the BasisSystemPerm interface.\n" 00335 << "Using " << typeName(*decomp_sys_imp) << " with a fixed basis ...\n"; 00336 decomp_sys_imp->initialize( 00337 nlp.space_x() 00338 ,nlp.space_c() 00339 ,basis_sys // Must already be ready to go with a basis selection! 00340 ); 00341 *decomp_sys = decomp_sys_imp; 00342 } 00343 #ifndef MOOCHO_NO_BASIS_PERM_DIRECT_SOLVERS 00344 } 00345 #endif 00346 } 00347 00348 void DecompositionSystemStateStepBuilderStd::add_iter_quantities( 00349 std::ostream *trase_out 00350 ,NLP &nlp 00351 ,NLPFirstOrder *nlp_foi 00352 ,NLPSecondOrder *nlp_soi 00353 ,NLPDirect *nlp_fod 00354 ,bool tailored_approach 00355 ,const Teuchos::RCP<DecompositionSystem> &decomp_sys 00356 ,const Teuchos::RCP<NLPAlgoState> &state 00357 ) 00358 { 00359 namespace mmp = MemMngPack; 00360 using Teuchos::dyn_cast; 00361 00362 const size_type 00363 n = nlp.n(), 00364 m = nlp.m(); 00365 00366 if( tailored_approach ) { 00367 // NLPDirect 00368 TEUCHOS_TEST_FOR_EXCEPT( !( nlp_fod->con_undecomp().size() == 0 ) ); 00369 // ToDo: Add the necessary iteration quantities when con_undecomp().size() > 0 is supported! 00370 } 00371 else { 00372 // NLPFirstOrder 00373 if(m) 00374 state->set_iter_quant( 00375 Gc_name 00376 ,Teuchos::rcp( 00377 new IterQuantityAccessContiguous<MatrixOp>( 00378 1 00379 ,Gc_name 00380 ,nlp_foi->factory_Gc() 00381 ) 00382 ) 00383 ); 00384 if(nlp_soi) 00385 state->set_iter_quant( 00386 HL_name 00387 ,Teuchos::rcp( 00388 new IterQuantityAccessContiguous<MatrixSymOp>( 00389 1 00390 ,HL_name 00391 ,nlp_soi->factory_HL() 00392 ) 00393 ) 00394 ); 00395 } 00396 00397 // 00398 // Set the algorithm specific matrix objects 00399 // 00400 00401 // Add range/null decomposition matrices 00402 00403 if( m ) { 00404 if(tailored_approach) { 00405 // Z 00406 state->set_iter_quant( 00407 Z_name 00408 ,Teuchos::rcp( 00409 new IterQuantityAccessContiguous<MatrixOp>( 00410 1 00411 ,Z_name 00412 ,Teuchos::rcp(new Teuchos::AbstractFactoryStd<MatrixOp,MatrixIdentConcatStd>) 00413 ) 00414 ) 00415 ); 00416 // Y 00417 state->set_iter_quant( 00418 Y_name 00419 ,Teuchos::rcp( 00420 new IterQuantityAccessContiguous<MatrixOp>( 00421 1 00422 ,Y_name 00423 ,Teuchos::rcp(new Teuchos::AbstractFactoryStd<MatrixOp,MatrixIdentConcatStd>) 00424 ) 00425 ) 00426 ); 00427 // ToDo: Add matrix iq object for Uz 00428 // ToDo: Add matrix iq object for Uy 00429 } 00430 else { 00431 if( n > m ) { 00432 // Z 00433 state->set_iter_quant( 00434 Z_name 00435 ,Teuchos::rcp( 00436 new IterQuantityAccessContiguous<MatrixOp>( 00437 1 00438 ,Z_name 00439 ,decomp_sys->factory_Z() 00440 ) 00441 ) 00442 ); 00443 // Y 00444 state->set_iter_quant( 00445 Y_name 00446 ,Teuchos::rcp( 00447 new IterQuantityAccessContiguous<MatrixOp>( 00448 1 00449 ,Y_name 00450 ,decomp_sys->factory_Y() 00451 ) 00452 ) 00453 ); 00454 // R 00455 state->set_iter_quant( 00456 R_name 00457 ,Teuchos::rcp( 00458 new IterQuantityAccessContiguous<MatrixOpNonsing>( 00459 1 00460 ,R_name 00461 ,decomp_sys->factory_R() 00462 ) 00463 ) 00464 ); 00465 // Uz 00466 state->set_iter_quant( 00467 Uz_name 00468 ,Teuchos::rcp( 00469 new IterQuantityAccessContiguous<MatrixOp>( 00470 1 00471 ,Uz_name 00472 ,decomp_sys->factory_Uz() 00473 ) 00474 ) 00475 ); 00476 // Uy 00477 state->set_iter_quant( 00478 Uy_name 00479 ,Teuchos::rcp( 00480 new IterQuantityAccessContiguous<MatrixOp>( 00481 1 00482 ,Uy_name 00483 ,decomp_sys->factory_Uy() 00484 ) 00485 ) 00486 ); 00487 } 00488 else { 00489 // Y 00490 state->set_iter_quant( 00491 Y_name 00492 ,Teuchos::rcp( 00493 new IterQuantityAccessContiguous<MatrixOp>( 00494 1 00495 ,Y_name 00496 ,Teuchos::rcp(new Teuchos::AbstractFactoryStd<MatrixOp,MatrixSymIdent>()) 00497 ) 00498 ) 00499 ); 00500 // R 00501 state->set_iter_quant( 00502 R_name 00503 ,Teuchos::rcp( 00504 new IterQuantityAccessContiguous<MatrixOpNonsing>( 00505 1 00506 ,R_name 00507 ,dyn_cast<NLPFirstOrder>(nlp).basis_sys()->factory_C() 00508 ) 00509 ) 00510 ); 00511 } 00512 } 00513 } 00514 else { 00515 // Z 00516 state->set_iter_quant( 00517 Z_name 00518 ,Teuchos::rcp( 00519 new IterQuantityAccessContiguous<MatrixOp>( 00520 1 00521 ,Z_name 00522 ,Teuchos::rcp(new Teuchos::AbstractFactoryStd<MatrixOp,MatrixSymIdent>()) 00523 ) 00524 ) 00525 ); 00526 } 00527 00528 } 00529 00530 void DecompositionSystemStateStepBuilderStd::create_eval_new_point( 00531 std::ostream *trase_out 00532 ,NLP &nlp 00533 ,NLPFirstOrder *nlp_foi 00534 ,NLPSecondOrder *nlp_soi 00535 ,NLPDirect *nlp_fod 00536 ,bool tailored_approach 00537 ,const Teuchos::RCP<DecompositionSystem> &decomp_sys 00538 ,Teuchos::RCP<IterationPack::AlgorithmStep> *eval_new_point_step 00539 ,Teuchos::RCP<CalcFiniteDiffProd> *calc_fd_prod 00540 ,Teuchos::RCP<VariableBoundsTester> *bounds_tester 00541 ,Teuchos::RCP<NewDecompositionSelection_Strategy> *new_decomp_selection_strategy 00542 ) 00543 { 00544 namespace mmp = MemMngPack; 00545 using Teuchos::RCP; 00546 00547 const size_type 00548 m = nlp.m(), 00549 nb = nlp.num_bounded_x(); 00550 00551 typedef RCP<DecompositionSystemHandler_Strategy> decomp_sys_handler_ptr_t; 00552 decomp_sys_handler_ptr_t decomp_sys_handler = Teuchos::null; 00553 #ifndef MOOCHO_NO_BASIS_PERM_DIRECT_SOLVERS 00554 typedef RCP<DecompositionSystemHandlerSelectNew_Strategy> decomp_sys_handler_select_new_ptr_t; 00555 decomp_sys_handler_select_new_ptr_t decomp_sys_handler_select_new = Teuchos::null; 00556 #endif 00557 00558 // Create the variable bounds testing object. 00559 if(nb) { // has variable bounds? 00560 const value_type var_bounds_warning_tol = 1e-10; 00561 const value_type var_bounds_error_tol = 1e-5; 00562 *bounds_tester = Teuchos::rcp( 00563 new VariableBoundsTester( 00564 var_bounds_warning_tol // default warning tolerance 00565 ,var_bounds_error_tol // default error tolerance 00566 ) ); 00567 if(options_.get()) { 00568 ConstrainedOptPack::VariableBoundsTesterSetOptions 00569 options_setter( bounds_tester->get() ); 00570 options_setter.set_options(*options_); 00571 } 00572 } 00573 00574 // Create the finite difference class 00575 *calc_fd_prod = Teuchos::rcp(new CalcFiniteDiffProd()); 00576 if(options_.get()) { 00577 ConstrainedOptPack::CalcFiniteDiffProdSetOptions 00578 options_setter( calc_fd_prod->get() ); 00579 options_setter.set_options(*options_); 00580 } 00581 00582 if( m ) { 00583 00584 // Decomposition system handler 00585 if( nlp_foi ) { 00586 #ifndef MOOCHO_NO_BASIS_PERM_DIRECT_SOLVERS 00587 if( basis_sys_perm_.get() ) 00588 decomp_sys_handler = decomp_sys_handler_select_new 00589 = Teuchos::rcp( new DecompositionSystemHandlerVarReductPerm_Strategy ); 00590 else 00591 #endif 00592 decomp_sys_handler = Teuchos::rcp( new DecompositionSystemHandlerStd_Strategy ); 00593 } 00594 00595 #ifndef MOOCHO_NO_BASIS_PERM_DIRECT_SOLVERS 00596 // NewDecompositionSelectionStd_Strategy 00597 if( decomp_sys_handler_select_new.get() ) { 00598 *new_decomp_selection_strategy = Teuchos::rcp( 00599 new NewDecompositionSelectionStd_Strategy(decomp_sys_handler_select_new) 00600 ); 00601 } 00602 #else 00603 *new_decomp_selection_strategy = Teuchos::null; 00604 #endif 00605 00606 } 00607 else { 00608 decomp_sys_handler = Teuchos::null; 00609 *new_decomp_selection_strategy = Teuchos::null; 00610 } 00611 00612 // 00613 // EvalNewPoint_Step 00614 // 00615 00616 // Create the step object 00617 if( tailored_approach ) { 00618 // create and setup the derivative tester 00619 typedef Teuchos::RCP<NLPDirectTester> deriv_tester_ptr_t; 00620 deriv_tester_ptr_t 00621 deriv_tester = Teuchos::rcp( 00622 new NLPDirectTester( 00623 *calc_fd_prod 00624 ,NLPDirectTester::FD_DIRECTIONAL // Gf testing 00625 ,NLPDirectTester::FD_DIRECTIONAL // -Inv(C)*N testing 00626 ) ); 00627 if(options_.get()) { 00628 NLPInterfacePack::NLPDirectTesterSetOptions 00629 options_setter(deriv_tester.get()); 00630 options_setter.set_options(*options_); 00631 } 00632 // create the step 00633 typedef Teuchos::RCP<EvalNewPointTailoredApproach_Step> _eval_new_point_step_ptr_t; 00634 _eval_new_point_step_ptr_t 00635 _eval_new_point_step = Teuchos::null; 00636 switch( cov_.range_space_matrix_type_ ) { 00637 case RANGE_SPACE_MATRIX_COORDINATE: 00638 _eval_new_point_step 00639 = Teuchos::rcp(new EvalNewPointTailoredApproachCoordinate_Step(deriv_tester,*bounds_tester)); 00640 break; 00641 case RANGE_SPACE_MATRIX_ORTHOGONAL: 00642 _eval_new_point_step 00643 = Teuchos::rcp(new EvalNewPointTailoredApproachOrthogonal_Step(deriv_tester,*bounds_tester) ); 00644 break; 00645 default: 00646 TEUCHOS_TEST_FOR_EXCEPT(true); // only a local error 00647 } 00648 if(options_.get()) { 00649 EvalNewPointTailoredApproach_StepSetOptions 00650 options_setter(_eval_new_point_step.get()); 00651 options_setter.set_options(*options_); 00652 } 00653 *eval_new_point_step = _eval_new_point_step; 00654 } 00655 else { 00656 // create and setup the derivative tester 00657 typedef Teuchos::RCP<NLPFirstDerivTester> deriv_tester_ptr_t; 00658 deriv_tester_ptr_t 00659 deriv_tester = Teuchos::rcp( 00660 new NLPFirstDerivTester( 00661 *calc_fd_prod 00662 ,NLPFirstDerivTester::FD_DIRECTIONAL 00663 ) ); 00664 if(options_.get()) { 00665 NLPInterfacePack::NLPFirstDerivTesterSetOptions 00666 options_setter(deriv_tester.get()); 00667 options_setter.set_options(*options_); 00668 } 00669 // create and setup the decomposition system tester 00670 typedef Teuchos::RCP<DecompositionSystemTester> decomp_sys_tester_ptr_t; 00671 decomp_sys_tester_ptr_t 00672 decomp_sys_tester = Teuchos::rcp( new DecompositionSystemTester() ); 00673 if(options_.get()) { 00674 DecompositionSystemTesterSetOptions 00675 options_setter(decomp_sys_tester.get()); 00676 options_setter.set_options(*options_); 00677 } 00678 Teuchos::RCP<EvalNewPointStd_Step> 00679 _eval_new_point_step = Teuchos::rcp( 00680 new EvalNewPointStd_Step( 00681 decomp_sys_handler 00682 ,deriv_tester 00683 ,*bounds_tester 00684 ,decomp_sys_tester 00685 ) ); 00686 if(options_.get()) { 00687 EvalNewPointStd_StepSetOptions 00688 options_setter(_eval_new_point_step.get()); 00689 options_setter.set_options(*options_); 00690 } 00691 *eval_new_point_step = _eval_new_point_step; 00692 } 00693 } 00694 00695 // static 00696 00697 void DecompositionSystemStateStepBuilderStd::readin_options( 00698 const OptionsFromStreamPack::OptionsFromStream& options 00699 ,SOptionValues *ov, std::ostream* trase_out 00700 ) 00701 { 00702 namespace ofsp = OptionsFromStreamPack; 00703 using ofsp::OptionsFromStream; 00704 typedef OptionsFromStream::options_group_t options_group_t; 00705 using ofsp::StringToIntMap; 00706 using ofsp::StringToBool; 00707 00708 TEUCHOS_TEST_FOR_EXCEPT( !( ov ) ); // only a local class error 00709 00710 const std::string opt_grp_name = "DecompositionSystemStateStepBuilderStd"; 00711 const OptionsFromStream::options_group_t optgrp = options.options_group( opt_grp_name ); 00712 if( OptionsFromStream::options_group_exists( optgrp ) ) { 00713 00714 const int num_opts = 3; 00715 enum EBuilder { 00716 NULL_SPACE_MATRIX 00717 ,RANGE_SPACE_MATRIX 00718 ,MAX_DOF_QUASI_NEWTON_DENSE 00719 }; 00720 const char* SBuilder[num_opts] = { 00721 "null_space_matrix" 00722 ,"range_space_matrix" 00723 ,"max_dof_quasi_newton_dense" 00724 }; 00725 StringToIntMap map( opt_grp_name, num_opts, SBuilder ); 00726 00727 options_group_t::const_iterator itr = optgrp.begin(); 00728 for( ; itr != optgrp.end(); ++itr ) { 00729 switch( (EBuilder)map( ofsp::option_name(itr) ) ) { 00730 case NULL_SPACE_MATRIX: 00731 { 00732 const std::string &opt_val = ofsp::option_value(itr); 00733 if( opt_val == "EXPLICIT" ) { 00734 ov->null_space_matrix_type_ = NULL_SPACE_MATRIX_EXPLICIT; 00735 } else if( opt_val == "IMPLICIT" ) { 00736 ov->null_space_matrix_type_ = NULL_SPACE_MATRIX_IMPLICIT; 00737 } else if( opt_val == "AUTO" ) { 00738 ov->null_space_matrix_type_ = NULL_SPACE_MATRIX_AUTO; 00739 } else { 00740 TEUCHOS_TEST_FOR_EXCEPTION( 00741 true, std::invalid_argument 00742 ,"NLPAlgoConfigMamaJama::readin_options(...) : " 00743 "Error, incorrect value for \"null_space_matrix\" " 00744 ", Only the options for Z of EXPLICIT, IMPLICIT" 00745 ", and AUTO are avalible." ); 00746 } 00747 break; 00748 } 00749 case RANGE_SPACE_MATRIX: 00750 { 00751 const std::string &opt_val = ofsp::option_value(itr); 00752 if( opt_val == "COORDINATE" ) 00753 ov->range_space_matrix_type_ = RANGE_SPACE_MATRIX_COORDINATE; 00754 else if( opt_val == "ORTHOGONAL" ) 00755 ov->range_space_matrix_type_ = RANGE_SPACE_MATRIX_ORTHOGONAL; 00756 else if( opt_val == "AUTO" ) 00757 ov->range_space_matrix_type_ = RANGE_SPACE_MATRIX_AUTO; 00758 else 00759 TEUCHOS_TEST_FOR_EXCEPTION( 00760 true, std::invalid_argument 00761 ,"NLPAlgoConfigMamaJama::readin_options(...) : " 00762 "Error, incorrect value for \"range_space_matrix\" " 00763 ", Only the options for Z of COORDINATE," 00764 ", ORTHOGONAL and AUTO are avalible." ); 00765 break; 00766 } 00767 case MAX_DOF_QUASI_NEWTON_DENSE: 00768 ov->max_dof_quasi_newton_dense_ = std::atoi( ofsp::option_value(itr).c_str() ); 00769 break; 00770 default: 00771 TEUCHOS_TEST_FOR_EXCEPT(true); // this would be a local programming error only. 00772 } 00773 } 00774 } 00775 else { 00776 if(trase_out) 00777 *trase_out 00778 << "\n\n*** Warning! The options group \"DecompositionSystemStateStepBuilderStd\" was not found.\n" 00779 << "Using a default set of options instead ... \n"; 00780 } 00781 } 00782 00783 void DecompositionSystemStateStepBuilderStd::set_default_options( 00784 const SOptionValues& uov 00785 ,SOptionValues *cov 00786 ,std::ostream* trase_out 00787 ) 00788 { 00789 00790 TEUCHOS_TEST_FOR_EXCEPT( !( cov ) ); 00791 00792 if(trase_out) 00793 *trase_out 00794 << "\n*** Setting option defaults for options not set by the user or determined some other way ...\n"; 00795 00796 if( cov->null_space_matrix_type_ == NULL_SPACE_MATRIX_AUTO && uov.null_space_matrix_type_ == NULL_SPACE_MATRIX_AUTO ) { 00797 if(trase_out) 00798 *trase_out 00799 << "\nnull_space_matrix_type == AUTO: Let the algorithm deside as it goes along\n"; 00800 } 00801 else if(cov->null_space_matrix_type_ == NULL_SPACE_MATRIX_AUTO) { 00802 cov->null_space_matrix_type_ = uov.null_space_matrix_type_; 00803 } 00804 if( cov->range_space_matrix_type_ == RANGE_SPACE_MATRIX_AUTO && uov.range_space_matrix_type_ == RANGE_SPACE_MATRIX_AUTO ) { 00805 if(trase_out) 00806 *trase_out 00807 << "\nrange_space_matrix_type == AUTO: Let the algorithm deside as it goes along\n"; 00808 } 00809 else if(cov->range_space_matrix_type_ == RANGE_SPACE_MATRIX_AUTO) { 00810 cov->range_space_matrix_type_ = uov.range_space_matrix_type_; 00811 } 00812 if( cov->max_dof_quasi_newton_dense_ < 0 && uov.max_dof_quasi_newton_dense_ < 0 ) { 00813 if(trase_out) 00814 *trase_out 00815 << "\nmax_dof_quasi_newton_dense < 0 : setting max_dof_quasi_newton_dense = "<<DEFAULT_MAX_DOF_QUASI_NEWTON_DENSE<<"\n"; 00816 cov->max_dof_quasi_newton_dense_ = DEFAULT_MAX_DOF_QUASI_NEWTON_DENSE; 00817 } 00818 else if(cov->max_dof_quasi_newton_dense_ < 0) { 00819 cov->max_dof_quasi_newton_dense_ = uov.max_dof_quasi_newton_dense_; 00820 } 00821 if(trase_out) 00822 *trase_out 00823 << "\n*** End setting default options\n"; 00824 } 00825 00826 } // end class MoochoPack
1.7.6.1