MoochoPack : Framework for Large-Scale Optimization Algorithms Version of the Day
MoochoPack_EvalNewPointTailoredApproachOrthogonal_Step.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 "MoochoPack_EvalNewPointTailoredApproachOrthogonal_Step.hpp"
00030 #include "ConstrainedOptPack_MatrixIdentConcatStd.hpp"
00031 #include "NLPInterfacePack_NLPDirect.hpp"
00032 #include "AbstractLinAlgPack_MatrixComposite.hpp"
00033 #include "AbstractLinAlgPack_MatrixSymOpNonsing.hpp"
00034 #include "AbstractLinAlgPack_MatrixSymInitDiag.hpp"
00035 #include "AbstractLinAlgPack_VectorSpace.hpp"
00036 #include "AbstractLinAlgPack_VectorStdOps.hpp"
00037 #include "AbstractLinAlgPack_MatrixOpOut.hpp"
00038 #include "AbstractLinAlgPack_AssertOp.hpp"
00039 #include "AbstractLinAlgPack_LinAlgOpPack.hpp"
00040 #include "Teuchos_dyn_cast.hpp"
00041 #include "Teuchos_TestForException.hpp"
00042 
00043 namespace MoochoPack {
00044 
00045 EvalNewPointTailoredApproachOrthogonal_Step::EvalNewPointTailoredApproachOrthogonal_Step(
00046   const deriv_tester_ptr_t                &deriv_tester
00047   ,const bounds_tester_ptr_t              &bounds_tester
00048   ,EFDDerivTesting                        fd_deriv_testing
00049   )
00050   :EvalNewPointTailoredApproach_Step(deriv_tester,bounds_tester,fd_deriv_testing)
00051 {}
00052 
00053 // protected
00054 
00055 void EvalNewPointTailoredApproachOrthogonal_Step::uninitialize_Y_Uy(
00056   MatrixOp         *Y
00057   ,MatrixOp        *Uy
00058   )
00059 {
00060   using Teuchos::dyn_cast;
00061 
00062   MatrixIdentConcatStd
00063     *Y_orth = Y ? &dyn_cast<MatrixIdentConcatStd>(*Y)  : NULL;
00064   MatrixComposite
00065     *Uy_cpst = Uy ? &dyn_cast<MatrixComposite>(*Uy) : NULL;     
00066 
00067   if(Y_orth)
00068     Y_orth->set_uninitialized();
00069   TEST_FOR_EXCEPT( !( Uy_cpst == NULL ) ); // ToDo: Implement for undecomposed equalities
00070 }
00071 
00072 void EvalNewPointTailoredApproachOrthogonal_Step::calc_py_Y_Uy(
00073   const NLPDirect       &nlp
00074   ,const D_ptr_t        &D
00075   ,VectorMutable        *py
00076   ,MatrixOp             *Y
00077   ,MatrixOp             *Uy
00078   ,EJournalOutputLevel  olevel
00079   ,std::ostream         &out
00080   )
00081 {
00082   namespace rcp = MemMngPack;
00083   using Teuchos::dyn_cast;
00084   using LinAlgOpPack::syrk;
00085 
00086   const size_type
00087     n = nlp.n(),
00088     r = nlp.r();
00089   const Range1D
00090     var_dep(1,r),
00091     var_indep(r+1,n),
00092     con_decomp   = nlp.con_decomp(),
00093     con_undecomp = nlp.con_undecomp();
00094 
00095   //
00096   // Get pointers to concreate matrices
00097   //
00098   
00099   MatrixIdentConcatStd
00100     *Y_orth = Y ? &dyn_cast<MatrixIdentConcatStd>(*Y)  : NULL;
00101   MatrixComposite
00102     *Uy_cpst = Uy ? &dyn_cast<MatrixComposite>(*Uy) : NULL;     
00103 
00104   //
00105   // Initialize the matrices
00106   //
00107 
00108   // Y
00109   if(Y_orth) {
00110     D_ptr_t  D_ptr = D;
00111 //    if(mat_rel == MATRICES_INDEP_IMPS) {
00112 //      D_ptr = D->clone();
00113 //      TEST_FOR_EXCEPTION(
00114 //        D_ptr.get() == NULL, std::logic_error
00115 //        ,"DecompositionSystemOrthogonal::update_decomp(...) : Error, "
00116 //        "The matrix class used for the direct sensitivity matrix D = inv(C)*N of type \'"
00117 //        << typeName(*D) << "\' must return return.get() != NULL from the clone() method "
00118 //        "since mat_rel == MATRICES_INDEP_IMPS!" );
00119 //    }
00120     Y_orth->initialize(
00121       nlp.space_x()                                     // space_cols
00122       ,nlp.space_x()->sub_space(var_dep)->clone()       // space_rows
00123       ,MatrixIdentConcatStd::BOTTOM                     // top_or_bottom
00124       ,-1.0                                             // alpha
00125       ,D_ptr                                            // D_ptr
00126       ,BLAS_Cpp::trans                                  // D_trans
00127       );
00128   }
00129 
00130   // S
00131   if(S_ptr_.get() == NULL) {
00132     S_ptr_ = nlp.factory_S()->create();
00133   }
00134   // S = I + (D)'*(D')'
00135   dyn_cast<MatrixSymInitDiag>(*S_ptr_).init_identity(D->space_rows());
00136   syrk(*D,BLAS_Cpp::trans,1.0,1.0,S_ptr_.get());
00137 
00138   TEST_FOR_EXCEPT( !( Uy_cpst == NULL ) ); // ToDo: Implement for undecomposed equalities
00139 
00140   recalc_py(*D,py,olevel,out);
00141 
00142 }
00143 
00144 void EvalNewPointTailoredApproachOrthogonal_Step::recalc_py(
00145   const MatrixOp           &D
00146   ,VectorMutable           *py
00147   ,EJournalOutputLevel     olevel
00148   ,std::ostream            &out
00149   )
00150 {
00151   using BLAS_Cpp::no_trans;
00152   using BLAS_Cpp::trans;
00153   using AbstractLinAlgPack::Vp_StMtV;
00154   using AbstractLinAlgPack::V_InvMtV;
00155   using LinAlgOpPack::V_MtV;
00156 
00157   const MatrixSymOpNonsing   &S = *S_ptr_;
00158 
00159   VectorSpace::vec_mut_ptr_t               // ToDo: make workspace!
00160     tIa = D.space_rows().create_member(),
00161     tIb = D.space_rows().create_member();
00162   //
00163   // py = -inv(R)*c
00164   // py = -((I - D*inv(S)*D')*inv(C))*c
00165   //    = -(I - D*inv(S)*D')*(-py)
00166   //    = py - D*inv(S)*D'*py
00167   //
00168   // =>
00169   //
00170   // tIa  = D'*py
00171   // tIb  = inv(S)*tIa
00172   // py   += -D*tIb
00173   //
00174   V_MtV( tIa.get(), D, trans, *py );              // tIa  = D'*py
00175   V_InvMtV( tIb.get(), S, no_trans, *tIa );       // tIb  = inv(S)*tIa
00176   Vp_StMtV( py, -1.0, D, no_trans, *tIb );        // py   += -D*tIb
00177 }
00178 
00179 void EvalNewPointTailoredApproachOrthogonal_Step::print_calc_py_Y_Uy(
00180   std::ostream& out, const std::string& L
00181   ) const
00182 {
00183   out
00184     << L << "*** Orthogonal decomposition\n"
00185     << L << "py = inv(I + D*D') * py <: space_range\n"
00186     << L << "Y = [ I ; -D' ] <: space_x|space_range\n"
00187     << L << "Uy = ???\n"
00188     ;
00189 }
00190 
00191 } // end namespace MoochoPack 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends