42 #include "MoochoPack_DecompositionSystemStateStepBuilderStd.hpp" 46 #include "NLPInterfacePack_NLPSecondOrder.hpp" 47 #include "NLPInterfacePack_NLPDirect.hpp" 48 #include "NLPInterfacePack_NLPVarReductPerm.hpp" 49 #include "NLPInterfacePack_NLPDirectTester.hpp" 50 #include "NLPInterfacePack_NLPDirectTesterSetOptions.hpp" 54 #include "AbstractLinAlgPack_BasisSystemTester.hpp" 55 #include "AbstractLinAlgPack_BasisSystemTesterSetOptions.hpp" 56 #ifndef MOOCHO_NO_BASIS_PERM_DIRECT_SOLVERS 57 #include "ConstrainedOptPack_DecompositionSystemVarReductPermStd.hpp" 62 #include "AbstractLinAlgPack_MatrixSymIdent.hpp" 63 #include "MoochoPack_DecompositionSystemHandlerVarReductPerm_Strategy.hpp" 64 #include "MoochoPack_DecompositionSystemHandlerStd_Strategy.hpp" 65 #include "ConstrainedOptPack_DecompositionSystemTester.hpp" 66 #include "ConstrainedOptPack_DecompositionSystemTesterSetOptions.hpp" 67 #include "ConstrainedOptPack_DecompositionSystemCoordinate.hpp" 68 #include "ConstrainedOptPack_DecompositionSystemOrthogonal.hpp" 72 #include "ConstrainedOptPack_MatrixIdentConcatStd.hpp" 73 #include "AbstractLinAlgPack_MatrixSymOpNonsing.hpp" 77 #include "MoochoPack_EvalNewPointStd_StepSetOptions.hpp" 78 #include "MoochoPack_EvalNewPointTailoredApproach_StepSetOptions.hpp" 79 #include "MoochoPack_EvalNewPointTailoredApproachCoordinate_Step.hpp" 80 #include "MoochoPack_EvalNewPointTailoredApproachOrthogonal_Step.hpp" 84 #include "MoochoPack_NLPAlgoState.hpp" 85 #include "MoochoPack_NewDecompositionSelectionStd_Strategy.hpp" 86 #include "ConstrainedOptPack_VariableBoundsTesterSetOptions.hpp" 87 #include "NLPInterfacePack_CalcFiniteDiffProdSetOptions.hpp" 88 #include "NLPInterfacePack_NLPFirstDerivTester.hpp" 89 #include "NLPInterfacePack_NLPFirstDerivTesterSetOptions.hpp" 92 #include "OptionsFromStreamPack_StringToIntMap.hpp" 93 #include "OptionsFromStreamPack_StringToBool.hpp" 94 #include "OptionsFromStreamPack_OptionsFromStream.hpp" 95 #include "Teuchos_Assert.hpp" 96 #include "Teuchos_dyn_cast.hpp" 99 const int DEFAULT_MAX_DOF_QUASI_NEWTON_DENSE = 200;
108 DecompositionSystemStateStepBuilderStd::SOptionValues::SOptionValues()
109 :null_space_matrix_type_(NULL_SPACE_MATRIX_AUTO)
110 ,range_space_matrix_type_(RANGE_SPACE_MATRIX_AUTO)
111 ,max_dof_quasi_newton_dense_(-1)
129 std::ostream *trase_out
131 ,NLPFirstOrder **nlp_foi
132 ,NLPSecondOrder **nlp_soi
134 ,
bool *tailored_approach
150 *trase_out <<
"\n*** Probing the NLP object for supported interfaces ...\n";
153 *nlp_foi =
dynamic_cast<NLPFirstOrder*
>(&nlp);
154 *nlp_soi =
dynamic_cast<NLPSecondOrder*
>(&nlp);
155 *nlp_fod =
dynamic_cast<NLPDirect*
>(&nlp);
156 *tailored_approach =
false;
159 *trase_out <<
"\nDetected that NLP object supports the NLPFirstOrder interface!\n";
160 *tailored_approach =
false;
162 else if( *nlp_fod ) {
164 *trase_out <<
"\nDetected that NLP object supports the NLPDirect interface!\n";
165 *tailored_approach =
true;
168 TEUCHOS_TEST_FOR_EXCEPTION(
169 true, std::logic_error
170 ,
"NLPAlgoConfigMamaJama::config_algo_cntr(...) : Error, " 171 "the NLP object of type \'" << typeName(nlp) <<
172 "\' does not support the NLPFirstOrder or NLPDirect " 177 *trase_out <<
"\nDetected that NLP object also supports the NLPSecondOrder interface!\n";
186 readin_options( *options_, &uov_, trase_out );
191 <<
"\n*** Warning, no OptionsFromStream object was set so a default set" 192 " of options will be used!\n";
197 if( uov_.max_dof_quasi_newton_dense_ < 0 )
198 cov_.max_dof_quasi_newton_dense_ = DEFAULT_MAX_DOF_QUASI_NEWTON_DENSE;
200 cov_.max_dof_quasi_newton_dense_ = uov_.max_dof_quasi_newton_dense_;
203 if( r && uov_.range_space_matrix_type_ == RANGE_SPACE_MATRIX_AUTO ) {
204 const bool use_orth = (dof*dof/r) <= cov_.max_dof_quasi_newton_dense_*cov_.max_dof_quasi_newton_dense_;
207 <<
"\nrange_space_matrix == AUTO:" 208 <<
"\n(n-r)^2/r = (" << dof <<
")^2/r = " << (dof*dof/r)
209 << ( use_orth ?
" <= " :
" > " ) <<
"max_dof_quasi_newton_dense^2 = (" 210 << cov_.max_dof_quasi_newton_dense_ <<
")^2 = " 211 << cov_.max_dof_quasi_newton_dense_*cov_.max_dof_quasi_newton_dense_
213 ?
"\nsetting range_space_matrix = ORTHOGONAL\n" 214 :
"\nsetting range_space_matrix = COORDINATE\n" );
215 cov_.range_space_matrix_type_ =
217 ? RANGE_SPACE_MATRIX_ORTHOGONAL
218 : RANGE_SPACE_MATRIX_COORDINATE );
222 set_default_options(uov_,&cov_,trase_out);
227 std::ostream *trase_out
229 ,NLPFirstOrder *nlp_foi
230 ,NLPSecondOrder *nlp_soi
232 ,
bool tailored_approach
233 ,Teuchos::RCP<DecompositionSystem> *decomp_sys
243 *decomp_sys = Teuchos::null;
247 RCP<BasisSystem> basis_sys = Teuchos::null;
248 if(!tailored_approach) {
250 basis_sys = nlp_foi->basis_sys();
251 if( basis_sys.get() == NULL ) {
252 TEUCHOS_TEST_FOR_EXCEPTION(
253 true, std::logic_error
254 ,
"\nA basis system object was not specified by the NLPFirstOrder object of type \'" 255 << typeName(nlp) <<
"\' and we can not build a rSQP algorithm without one!" );
259 RCP<BasisSystemTester>
260 basis_sys_tester = Teuchos::rcp(
new BasisSystemTester());
262 BasisSystemTesterSetOptions
263 opt_setter(basis_sys_tester.get());
264 opt_setter.set_options(*options_);
267 DecompositionSystemVarReduct::EExplicitImplicit
269 switch( cov_.null_space_matrix_type_ ) {
270 case NULL_SPACE_MATRIX_AUTO:
271 D_imp = DecompositionSystemVarReduct::MAT_IMP_AUTO;
273 case NULL_SPACE_MATRIX_EXPLICIT:
274 D_imp = DecompositionSystemVarReduct::MAT_IMP_EXPLICIT;
276 case NULL_SPACE_MATRIX_IMPLICIT:
277 D_imp = DecompositionSystemVarReduct::MAT_IMP_IMPLICIT;
280 TEUCHOS_TEST_FOR_EXCEPT(
true);
282 #ifndef MOOCHO_NO_BASIS_PERM_DIRECT_SOLVERS 284 basis_sys_perm_ = Teuchos::rcp_dynamic_cast<BasisSystemPerm>(basis_sys);
287 typedef RCP<DecompositionSystemVarReductImp> decomp_sys_imp_ptr_t;
288 decomp_sys_imp_ptr_t decomp_sys_imp;
289 switch( cov_.range_space_matrix_type_ ) {
290 case RANGE_SPACE_MATRIX_COORDINATE:
292 = Teuchos::rcp(
new DecompositionSystemCoordinate(
300 case RANGE_SPACE_MATRIX_ORTHOGONAL: {
302 = Teuchos::rcp(
new DecompositionSystemOrthogonal(
311 TEUCHOS_TEST_FOR_EXCEPT(
true);
313 #ifndef MOOCHO_NO_BASIS_PERM_DIRECT_SOLVERS 315 if( basis_sys_perm_.get() != NULL ) {
318 <<
"\nThe BasisSystem object with concreate type \'" << typeName(*basis_sys)
319 <<
"\' supports the BasisSystemPerm interface.\n" 320 <<
"Using DecompositionSystemVarReductPermStd to support basis permutations ...\n";
321 *decomp_sys = Teuchos::rcp(
322 new DecompositionSystemVarReductPermStd(
333 <<
"\nThe BasisSystem object with concreate type \'" << typeName(*basis_sys)
334 <<
"\' does not support the BasisSystemPerm interface.\n" 335 <<
"Using " << typeName(*decomp_sys_imp) <<
" with a fixed basis ...\n";
336 decomp_sys_imp->initialize(
341 *decomp_sys = decomp_sys_imp;
343 #ifndef MOOCHO_NO_BASIS_PERM_DIRECT_SOLVERS 349 std::ostream *trase_out
351 ,NLPFirstOrder *nlp_foi
352 ,NLPSecondOrder *nlp_soi
354 ,
bool tailored_approach
355 ,
const Teuchos::RCP<DecompositionSystem> &decomp_sys
356 ,
const Teuchos::RCP<NLPAlgoState> &state
360 using Teuchos::dyn_cast;
366 if( tailored_approach ) {
368 TEUCHOS_TEST_FOR_EXCEPT( !( nlp_fod->con_undecomp().size() == 0 ) );
374 state->set_iter_quant(
377 new IterQuantityAccessContiguous<MatrixOp>(
380 ,nlp_foi->factory_Gc()
385 state->set_iter_quant(
388 new IterQuantityAccessContiguous<MatrixSymOp>(
391 ,nlp_soi->factory_HL()
404 if(tailored_approach) {
406 state->set_iter_quant(
409 new IterQuantityAccessContiguous<MatrixOp>(
412 ,Teuchos::rcp(
new Teuchos::AbstractFactoryStd<MatrixOp,MatrixIdentConcatStd>)
417 state->set_iter_quant(
420 new IterQuantityAccessContiguous<MatrixOp>(
423 ,Teuchos::rcp(
new Teuchos::AbstractFactoryStd<MatrixOp,MatrixIdentConcatStd>)
433 state->set_iter_quant(
436 new IterQuantityAccessContiguous<MatrixOp>(
439 ,decomp_sys->factory_Z()
444 state->set_iter_quant(
447 new IterQuantityAccessContiguous<MatrixOp>(
450 ,decomp_sys->factory_Y()
455 state->set_iter_quant(
458 new IterQuantityAccessContiguous<MatrixOpNonsing>(
461 ,decomp_sys->factory_R()
466 state->set_iter_quant(
469 new IterQuantityAccessContiguous<MatrixOp>(
472 ,decomp_sys->factory_Uz()
477 state->set_iter_quant(
480 new IterQuantityAccessContiguous<MatrixOp>(
483 ,decomp_sys->factory_Uy()
490 state->set_iter_quant(
493 new IterQuantityAccessContiguous<MatrixOp>(
496 ,Teuchos::rcp(
new Teuchos::AbstractFactoryStd<MatrixOp,MatrixSymIdent>())
501 state->set_iter_quant(
504 new IterQuantityAccessContiguous<MatrixOpNonsing>(
507 ,dyn_cast<NLPFirstOrder>(nlp).basis_sys()->factory_C()
516 state->set_iter_quant(
519 new IterQuantityAccessContiguous<MatrixOp>(
522 ,Teuchos::rcp(
new Teuchos::AbstractFactoryStd<MatrixOp,MatrixSymIdent>())
531 std::ostream *trase_out
533 ,NLPFirstOrder *nlp_foi
534 ,NLPSecondOrder *nlp_soi
536 ,
bool tailored_approach
537 ,
const Teuchos::RCP<DecompositionSystem> &decomp_sys
538 ,Teuchos::RCP<IterationPack::AlgorithmStep> *eval_new_point_step
539 ,Teuchos::RCP<CalcFiniteDiffProd> *calc_fd_prod
540 ,Teuchos::RCP<VariableBoundsTester> *bounds_tester
541 ,Teuchos::RCP<NewDecompositionSelection_Strategy> *new_decomp_selection_strategy
549 nb = nlp.num_bounded_x();
551 typedef RCP<DecompositionSystemHandler_Strategy> decomp_sys_handler_ptr_t;
552 decomp_sys_handler_ptr_t decomp_sys_handler = Teuchos::null;
553 #ifndef MOOCHO_NO_BASIS_PERM_DIRECT_SOLVERS 554 typedef RCP<DecompositionSystemHandlerSelectNew_Strategy> decomp_sys_handler_select_new_ptr_t;
555 decomp_sys_handler_select_new_ptr_t decomp_sys_handler_select_new = Teuchos::null;
560 const value_type var_bounds_warning_tol = 1e-10;
561 const value_type var_bounds_error_tol = 1e-5;
562 *bounds_tester = Teuchos::rcp(
563 new VariableBoundsTester(
564 var_bounds_warning_tol
565 ,var_bounds_error_tol
569 options_setter( bounds_tester->get() );
575 *calc_fd_prod = Teuchos::rcp(
new CalcFiniteDiffProd());
577 ConstrainedOptPack::CalcFiniteDiffProdSetOptions
578 options_setter( calc_fd_prod->get() );
579 options_setter.set_options(*options_);
586 #ifndef MOOCHO_NO_BASIS_PERM_DIRECT_SOLVERS 587 if( basis_sys_perm_.get() )
588 decomp_sys_handler = decomp_sys_handler_select_new
595 #ifndef MOOCHO_NO_BASIS_PERM_DIRECT_SOLVERS 597 if( decomp_sys_handler_select_new.get() ) {
598 *new_decomp_selection_strategy = Teuchos::rcp(
603 *new_decomp_selection_strategy = Teuchos::null;
608 decomp_sys_handler = Teuchos::null;
609 *new_decomp_selection_strategy = Teuchos::null;
617 if( tailored_approach ) {
619 typedef Teuchos::RCP<NLPDirectTester> deriv_tester_ptr_t;
621 deriv_tester = Teuchos::rcp(
624 ,NLPDirectTester::FD_DIRECTIONAL
625 ,NLPDirectTester::FD_DIRECTIONAL
629 options_setter(deriv_tester.get());
633 typedef Teuchos::RCP<EvalNewPointTailoredApproach_Step> _eval_new_point_step_ptr_t;
634 _eval_new_point_step_ptr_t
635 _eval_new_point_step = Teuchos::null;
636 switch( cov_.range_space_matrix_type_ ) {
637 case RANGE_SPACE_MATRIX_COORDINATE:
641 case RANGE_SPACE_MATRIX_ORTHOGONAL:
646 TEUCHOS_TEST_FOR_EXCEPT(
true);
650 options_setter(_eval_new_point_step.get());
653 *eval_new_point_step = _eval_new_point_step;
657 typedef Teuchos::RCP<NLPFirstDerivTester> deriv_tester_ptr_t;
659 deriv_tester = Teuchos::rcp(
660 new NLPFirstDerivTester(
662 ,NLPFirstDerivTester::FD_DIRECTIONAL
666 options_setter(deriv_tester.get());
670 typedef Teuchos::RCP<DecompositionSystemTester> decomp_sys_tester_ptr_t;
671 decomp_sys_tester_ptr_t
672 decomp_sys_tester = Teuchos::rcp(
new DecompositionSystemTester() );
674 DecompositionSystemTesterSetOptions
675 options_setter(decomp_sys_tester.get());
676 options_setter.set_options(*options_);
678 Teuchos::RCP<EvalNewPointStd_Step>
679 _eval_new_point_step = Teuchos::rcp(
687 EvalNewPointStd_StepSetOptions
688 options_setter(_eval_new_point_step.get());
689 options_setter.set_options(*options_);
691 *eval_new_point_step = _eval_new_point_step;
697 void DecompositionSystemStateStepBuilderStd::readin_options(
703 using ofsp::OptionsFromStream;
704 typedef OptionsFromStream::options_group_t options_group_t;
705 using ofsp::StringToIntMap;
706 using ofsp::StringToBool;
708 TEUCHOS_TEST_FOR_EXCEPT( !( ov ) );
710 const std::string opt_grp_name =
"DecompositionSystemStateStepBuilderStd";
711 const OptionsFromStream::options_group_t optgrp = options.
options_group( opt_grp_name );
712 if( OptionsFromStream::options_group_exists( optgrp ) ) {
714 const int num_opts = 3;
718 ,MAX_DOF_QUASI_NEWTON_DENSE
720 const char* SBuilder[num_opts] = {
722 ,
"range_space_matrix" 723 ,
"max_dof_quasi_newton_dense" 725 StringToIntMap map( opt_grp_name, num_opts, SBuilder );
727 options_group_t::const_iterator itr = optgrp.begin();
728 for( ; itr != optgrp.end(); ++itr ) {
729 switch( (EBuilder)map( ofsp::option_name(itr) ) ) {
730 case NULL_SPACE_MATRIX:
732 const std::string &opt_val = ofsp::option_value(itr);
733 if( opt_val ==
"EXPLICIT" ) {
734 ov->null_space_matrix_type_ = NULL_SPACE_MATRIX_EXPLICIT;
735 }
else if( opt_val ==
"IMPLICIT" ) {
736 ov->null_space_matrix_type_ = NULL_SPACE_MATRIX_IMPLICIT;
737 }
else if( opt_val ==
"AUTO" ) {
738 ov->null_space_matrix_type_ = NULL_SPACE_MATRIX_AUTO;
740 TEUCHOS_TEST_FOR_EXCEPTION(
741 true, std::invalid_argument
742 ,
"NLPAlgoConfigMamaJama::readin_options(...) : " 743 "Error, incorrect value for \"null_space_matrix\" " 744 ", Only the options for Z of EXPLICIT, IMPLICIT" 745 ", and AUTO are avalible." );
749 case RANGE_SPACE_MATRIX:
751 const std::string &opt_val = ofsp::option_value(itr);
752 if( opt_val ==
"COORDINATE" )
753 ov->range_space_matrix_type_ = RANGE_SPACE_MATRIX_COORDINATE;
754 else if( opt_val ==
"ORTHOGONAL" )
755 ov->range_space_matrix_type_ = RANGE_SPACE_MATRIX_ORTHOGONAL;
756 else if( opt_val ==
"AUTO" )
757 ov->range_space_matrix_type_ = RANGE_SPACE_MATRIX_AUTO;
759 TEUCHOS_TEST_FOR_EXCEPTION(
760 true, std::invalid_argument
761 ,
"NLPAlgoConfigMamaJama::readin_options(...) : " 762 "Error, incorrect value for \"range_space_matrix\" " 763 ", Only the options for Z of COORDINATE," 764 ", ORTHOGONAL and AUTO are avalible." );
767 case MAX_DOF_QUASI_NEWTON_DENSE:
768 ov->max_dof_quasi_newton_dense_ = std::atoi( ofsp::option_value(itr).c_str() );
771 TEUCHOS_TEST_FOR_EXCEPT(
true);
778 <<
"\n\n*** Warning! The options group \"DecompositionSystemStateStepBuilderStd\" was not found.\n" 779 <<
"Using a default set of options instead ... \n";
783 void DecompositionSystemStateStepBuilderStd::set_default_options(
786 ,std::ostream* trase_out
790 TEUCHOS_TEST_FOR_EXCEPT( !( cov ) );
794 <<
"\n*** Setting option defaults for options not set by the user or determined some other way ...\n";
796 if( cov->null_space_matrix_type_ == NULL_SPACE_MATRIX_AUTO && uov.null_space_matrix_type_ == NULL_SPACE_MATRIX_AUTO ) {
799 <<
"\nnull_space_matrix_type == AUTO: Let the algorithm deside as it goes along\n";
801 else if(cov->null_space_matrix_type_ == NULL_SPACE_MATRIX_AUTO) {
802 cov->null_space_matrix_type_ = uov.null_space_matrix_type_;
804 if( cov->range_space_matrix_type_ == RANGE_SPACE_MATRIX_AUTO && uov.range_space_matrix_type_ == RANGE_SPACE_MATRIX_AUTO ) {
807 <<
"\nrange_space_matrix_type == AUTO: Let the algorithm deside as it goes along\n";
809 else if(cov->range_space_matrix_type_ == RANGE_SPACE_MATRIX_AUTO) {
810 cov->range_space_matrix_type_ = uov.range_space_matrix_type_;
812 if( cov->max_dof_quasi_newton_dense_ < 0 && uov.max_dof_quasi_newton_dense_ < 0 ) {
815 <<
"\nmax_dof_quasi_newton_dense < 0 : setting max_dof_quasi_newton_dense = "<<DEFAULT_MAX_DOF_QUASI_NEWTON_DENSE<<
"\n";
816 cov->max_dof_quasi_newton_dense_ = DEFAULT_MAX_DOF_QUASI_NEWTON_DENSE;
818 else if(cov->max_dof_quasi_newton_dense_ < 0) {
819 cov->max_dof_quasi_newton_dense_ = uov.max_dof_quasi_newton_dense_;
823 <<
"\n*** End setting default options\n";
void process_nlp_and_options(std::ostream *trase_out, NLP &nlp, NLPFirstOrder **nlp_foi, NLPSecondOrder **nlp_soi, NLPDirect **nlp_fod, bool *tailored_approach)
Process the NLP and process the options passed in from set_options(). Postconditions: ...
void create_eval_new_point(std::ostream *trase_out, NLP &nlp, NLPFirstOrder *nlp_foi, NLPSecondOrder *nlp_soi, NLPDirect *nlp_fod, bool tailored_approach, const Teuchos::RCP< DecompositionSystem > &decomp_sys, Teuchos::RCP< IterationPack::AlgorithmStep > *eval_new_point_step, Teuchos::RCP< CalcFiniteDiffProd > *calc_fd_prod, Teuchos::RCP< VariableBoundsTester > *bounds_tester, Teuchos::RCP< NewDecompositionSelection_Strategy > *new_decomp_selection_strategy)
Create the EvalNewPoint step object and allocated objects.
Subclass for selecting and updating the range/null space decomposition using the DecompositionSystemV...
void set_options(const OptionsFromStream &options)
Subclass for updating the range/null space decomposition using the base DecompositionSystem interface...
Implements "orthogonal" decompostion for "Tailored Appraoch".
void add_iter_quantities(std::ostream *trase_out, NLP &nlp, NLPFirstOrder *nlp_foi, NLPSecondOrder *nlp_soi, NLPDirect *nlp_fod, bool tailored_approach, const Teuchos::RCP< DecompositionSystem > &decomp_sys, const Teuchos::RCP< NLPAlgoState > &state)
Add the common iteration quantities to the state object.
const options_ptr_t & get_options() const
DecompositionSystemStateStepBuilderStd()
Set options for EvalNewPointTailoredApproach_Step from an OptionsFromStream object.
Just force the decomposition system object to select a new decomposition and let everyone else fend f...
void create_decomp_sys(std::ostream *trase_out, NLP &nlp, NLPFirstOrder *nlp_foi, NLPSecondOrder *nlp_soi, NLPDirect *nlp_fod, bool tailored_approach, Teuchos::RCP< DecompositionSystem > *decomp_sys)
Create the decomposition system object.
Implements "coordinate" decompostion for "Tailored Appraoch".
Standard new point evaluation step class.
options_group_t options_group(const std::string &options_group_name)
Teuchos::RCP< const OptionsFromStreamPack::OptionsFromStream > options_ptr_t
void set_options(const options_ptr_t &options)
Set the options that will be used to configure the algorithmic objects.