44 #ifndef GLOBIPACK_TEST_LAGR_POLY_MERIT_FUNC_1D_DEF_HPP 45 #define GLOBIPACK_TEST_LAGR_POLY_MERIT_FUNC_1D_DEF_HPP 49 #include "Teuchos_ScalarTraits.hpp" 50 #include "Teuchos_Assert.hpp" 56 template<
typename Scalar>
58 const ArrayView<const Scalar> &alpha,
59 const ArrayView<const Scalar> &phi
61 : alpha_(alpha), phi_(phi)
63 TEUCHOS_ASSERT_EQUALITY(alpha.size(), phi.size());
70 template<
typename Scalar>
77 template<
typename Scalar>
79 const Scalar &alpha,
const Ptr<Scalar> &phi_out,
80 const Ptr<Scalar> &Dphi_out
84 typedef Teuchos::ScalarTraits<Scalar> ST;
86 const int n = alpha_.size();
88 Scalar phi = ST::zero();
89 Scalar Dphi = ST::zero();
91 for (
int k = 0; k < n; ++k) {
93 if (!is_null(phi_out)) {
95 Scalar Lp_k = ST::one();
96 for (
int i = 0; i < n; ++i) {
98 Lp_k *= (alpha-alpha_[i])/(alpha_[k]-alpha_[i]);
102 phi += phi_[k] * Lp_k;
106 if (!is_null(Dphi_out)) {
108 Scalar DLp_k = ST::zero();
109 for (
int j = 0; j < n; ++j) {
111 Scalar DLp_k_j_prod = ST::one();
112 for (
int i = 0; i < n; ++i) {
114 DLp_k_j_prod *= (alpha-alpha_[i])/(alpha_[k]-alpha_[i]);
117 DLp_k += DLp_k_j_prod / (alpha_[k]-alpha_[j]);
121 Dphi += phi_[k] * DLp_k;
127 if (!is_null(phi_out)) {
131 if (!is_null(Dphi_out)) {
141 #endif // GLOBIPACK_TEST_LAGR_POLY_MERIT_FUNC_1D_DEF_HPP
TestLagrPolyMeritFunc1D(const ArrayView< const Scalar > &alpha, const ArrayView< const Scalar > &phi)
Constructor.
virtual bool supportsDerivEvals() const
virtual void eval(const Scalar &alpha, const Ptr< Scalar > &phi, const Ptr< Scalar > &Dphi) const