OptiPack Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
OptiPack_UnconstrainedOptMeritFunc1D_def.hpp
Go to the documentation of this file.
1 /*
2 // @HEADER
3 // ***********************************************************************
4 //
5 // OptiPack: Collection of simple Thyra-based Optimization ANAs
6 // Copyright (2009) Sandia Corporation
7 //
8 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
9 // license for use of this work by or on behalf of the U.S. Government.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
39 //
40 // ***********************************************************************
41 // @HEADER
42 */
43 
44 #ifndef OPTIPACK_UNCONSTRAINED_OPT_MERIT_FUNC_1D_DEF_HPP
45 #define OPTIPACK_UNCONSTRAINED_OPT_MERIT_FUNC_1D_DEF_HPP
46 
47 
48 #include "OptiPack_Types.hpp"
50 #include "Thyra_ModelEvaluatorHelpers.hpp"
51 #include "Thyra_VectorStdOps.hpp"
53 #include "Teuchos_Assert.hpp"
54 
55 
56 namespace OptiPack {
57 
58 
59 // Constructor/Initializers/Accessors
60 
61 
62 template<typename Scalar>
64  : paramIndex_(-1),
65  responseIndex_(-1)
66 {}
67 
68 
69 template<typename Scalar>
71  const RCP<const Thyra::ModelEvaluator<Scalar> > &model,
72  const int paramIndex,
73  const int responseIndex
74  )
75 {
76 #ifdef TEUCHOS_DEBUG
77  model.assert_not_null();
78  TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE( paramIndex, 0, model->Np() );
79  TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE( responseIndex, 0, model->Ng() );
80 #endif
81  model_ = model;
82  paramIndex_ = paramIndex;
83  responseIndex_ = responseIndex;
84 }
85 
86 
87 template<typename Scalar>
89  const RCP<const LineSearchPointEvaluatorBase<Scalar> > &pointEvaluator,
90  const RCP<Thyra::VectorBase<Scalar> > &p,
91  const RCP<Thyra::VectorBase<Scalar> > &g_vec,
92  const RCP<Thyra::VectorBase<Scalar> > &g_grad_vec
93  )
94 {
95 #ifdef TEUCHOS_DEBUG
96  pointEvaluator.assert_not_null();
97  p.assert_not_null();
98  g_vec.assert_not_null();
99  // ToDo: Check that pointEvaluator, p, g_vec, and g_grad_vec are compatible!
100 #endif
101  pointEvaluator_ = pointEvaluator;
102  p_ = p;
103  g_vec_ = g_vec;
104  g_grad_vec_ = g_grad_vec; // Can be null and that is okay
105 }
106 
107 
108 // Overridden from MeritFunc1DBase
109 
110 
111 template<typename Scalar>
113 {
114  return !is_null(g_grad_vec_);
115 }
116 
117 
118 template<typename Scalar>
120  const ScalarMag &alpha, const Ptr<ScalarMag> &phi,
121  const Ptr<ScalarMag> &Dphi ) const
122 {
123  typedef Thyra::ModelEvaluatorBase MEB;
124  using Thyra::get_ele;
125  using Thyra::eval_g;
126  using Thyra::eval_g_DgDp;
127  pointEvaluator_->computePoint(alpha, p_.ptr());
128  if (!is_null(g_grad_vec_)) {
130  "Error, g_grad_vec has not been implemented yet!.");
131  }
132  else {
133 #ifdef TEUCHOS_DEBUG
134  TEUCHOS_ASSERT(is_null(Dphi));
135 #endif
136  eval_g( *model_, paramIndex_, *p_, responseIndex_, g_vec_.ptr() );
137  *phi = get_ele(*g_vec_, 0);
138  }
139 }
140 
141 
142 } // namespace OptiPack
143 
144 
145 #endif // OPTIPACK_UNCONSTRAINED_OPT_MERIT_FUNC_1D_DEF_HPP
UnconstrainedOptMeritFunc1D()
Construct with default parameters.
bool is_null(const boost::shared_ptr< T > &p)
void setModel(const RCP< const Thyra::ModelEvaluator< Scalar > > &model, const int paramIndex, const int responseIndex)
Set the model.
#define TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(index, lower_inclusive, upper_exclusive)
virtual void eval(const ScalarMag &alpha, const Ptr< ScalarMag > &phi, const Ptr< ScalarMag > &Dphi) const
void setEvaluationQuantities(const RCP< const LineSearchPointEvaluatorBase< Scalar > > &pointEvaluator, const RCP< Thyra::VectorBase< Scalar > > &p, const RCP< Thyra::VectorBase< Scalar > > &g_vec, const RCP< Thyra::VectorBase< Scalar > > &g_grad_vec)
Set the evaluation qualities.
#define TEUCHOS_TEST_FOR_EXCEPT_MSG(throw_exception_test, msg)
Base class interface for line search point updates.
#define TEUCHOS_ASSERT(assertion_test)