OptiPack Package Browser (Single Doxygen Collection) Version of the Day
OptiPack_DefaultPolyLineSearchPointEvaluator.hpp
Go to the documentation of this file.
00001 /*
00002 // @HEADER
00003 // ***********************************************************************
00004 // 
00005 //    OptiPack: Collection of simple Thyra-based Optimization ANAs
00006 //                 Copyright (2009) Sandia Corporation
00007 // 
00008 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00009 // license for use of this work by or on behalf of the U.S. Government.
00010 // 
00011 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 // 
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 // 
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA
00025 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00026 // 
00027 // ***********************************************************************
00028 // @HEADER
00029 */
00030 
00031 #ifndef OPTIPACK_DEFAULT_POLY_LINE_SEARCH_POINT_EVALUATOR_HPP
00032 #define OPTIPACK_DEFAULT_POLY_LINE_SEARCH_POINT_EVALUATOR_HPP
00033 
00034 
00035 #include "OptiPack_LineSearchPointEvaluatorBase.hpp"
00036 #include "Thyra_VectorStdOps.hpp"
00037 
00038 
00039 namespace OptiPack {
00040 
00041 
00055 template<typename Scalar>
00056 class DefaultPolyLineSearchPointEvaluator : public LineSearchPointEvaluatorBase<Scalar>
00057 {
00058 public:
00059 
00061   typedef typename ScalarTraits<Scalar>::magnitudeType ScalarMag;
00062 
00065 
00067   DefaultPolyLineSearchPointEvaluator();
00068   
00070   void initialize(const ArrayView<const RCP<const Thyra::VectorBase<Scalar> > > &vecs);
00071 
00073 
00076 
00078   virtual void computePoint( const ScalarMag &alpha,
00079     const Ptr<Thyra::VectorBase<Scalar> > &p
00080     ) const;
00081 
00083 
00084 private:
00085 
00086   Array<RCP<const Thyra::VectorBase<Scalar> > > vecs_;
00087 
00088 };
00089 
00090 
00095 template<typename Scalar>
00096 const RCP<DefaultPolyLineSearchPointEvaluator<Scalar> >
00097 defaultPolyLineSearchPointEvaluator()
00098 {
00099   return Teuchos::rcp(new DefaultPolyLineSearchPointEvaluator<Scalar>);
00100 }
00101 
00102 
00103 //
00104 // Implementations
00105 //
00106 
00107 
00108 // Constructors/intializers/accessors
00109 
00110 
00111 template<typename Scalar>
00112 DefaultPolyLineSearchPointEvaluator<Scalar>::DefaultPolyLineSearchPointEvaluator()
00113 {}
00114   
00115 
00116 template<typename Scalar>
00117 void DefaultPolyLineSearchPointEvaluator<Scalar>::initialize(
00118   const ArrayView<const RCP<const Thyra::VectorBase<Scalar> > > &vecs
00119   )
00120 {
00121 #ifdef TEUCHOS_DEBUG
00122   TEUCHOS_ASSERT(vecs.size());
00123 #endif
00124   vecs_ = vecs;
00125 }
00126 
00127 
00128 // Overridden from LineSearchPointEvaluatorBase
00129 
00130 
00131 template<typename Scalar>
00132 void DefaultPolyLineSearchPointEvaluator<Scalar>::computePoint( const ScalarMag &alpha,
00133   const Ptr<Thyra::VectorBase<Scalar> > &p
00134   ) const
00135 {
00136   typedef ScalarTraits<Scalar> ST;
00137   using Teuchos::as;
00138   using Thyra::V_V;
00139   using Thyra::Vp_StV;
00140   V_V( p, *vecs_[0] );
00141   if (alpha != ST::zero()) {
00142     ScalarMag alpha_i = alpha;
00143     const int n = vecs_.size();
00144     for (int i = 1; i < n; ++i, alpha_i *= alpha) {
00145       Vp_StV(p, alpha_i, *vecs_[i]); 
00146     }
00147   }
00148 }
00149 
00150 
00151 } // namespace OptiPack
00152 
00153 
00154 #endif // OPTIPACK_DEFAULT_POLY_LINE_SEARCH_POINT_EVALUATOR_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends