|
GlobiPack Package Browser (Single Doxygen Collection) Version of the Day
|
00001 /* 00002 // @HEADER 00003 // *********************************************************************** 00004 // 00005 // GlobiPack: Collection of Scalar 1D globalizaton utilities 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 GLOBIPACK_TEST_LAGR_POLY_MERIT_FUNC_1D_DEF_HPP 00032 #define GLOBIPACK_TEST_LAGR_POLY_MERIT_FUNC_1D_DEF_HPP 00033 00034 00035 #include "GlobiPack_TestLagrPolyMeritFunc1D_decl.hpp" 00036 #include "Teuchos_ScalarTraits.hpp" 00037 #include "Teuchos_Assert.hpp" 00038 00039 00040 namespace GlobiPack { 00041 00042 00043 template<typename Scalar> 00044 TestLagrPolyMeritFunc1D<Scalar>::TestLagrPolyMeritFunc1D( 00045 const ArrayView<const Scalar> &alpha, 00046 const ArrayView<const Scalar> &phi 00047 ) 00048 : alpha_(alpha), phi_(phi) 00049 { 00050 TEUCHOS_ASSERT_EQUALITY(alpha.size(), phi.size()); 00051 } 00052 00053 00054 // Overridden from MeritFunc1DBase 00055 00056 00057 template<typename Scalar> 00058 bool TestLagrPolyMeritFunc1D<Scalar>::supportsDerivEvals() const 00059 { 00060 return true; 00061 } 00062 00063 00064 template<typename Scalar> 00065 void TestLagrPolyMeritFunc1D<Scalar>::eval( 00066 const Scalar &alpha, const Ptr<Scalar> &phi_out, 00067 const Ptr<Scalar> &Dphi_out 00068 ) const 00069 { 00070 00071 typedef Teuchos::ScalarTraits<Scalar> ST; 00072 00073 const int n = alpha_.size(); 00074 00075 Scalar phi = ST::zero(); 00076 Scalar Dphi = ST::zero(); 00077 00078 for (int k = 0; k < n; ++k) { 00079 00080 if (!is_null(phi_out)) { 00081 00082 Scalar Lp_k = ST::one(); 00083 for (int i = 0; i < n; ++i) { 00084 if (i!=k) { 00085 Lp_k *= (alpha-alpha_[i])/(alpha_[k]-alpha_[i]); 00086 } 00087 } 00088 00089 phi += phi_[k] * Lp_k; 00090 00091 } 00092 00093 if (!is_null(Dphi_out)) { 00094 00095 Scalar DLp_k = ST::zero(); 00096 for (int j = 0; j < n; ++j) { 00097 if (j!=k) { 00098 Scalar DLp_k_j_prod = ST::one(); 00099 for (int i = 0; i < n; ++i) { 00100 if (i!=k && i!=j) { 00101 DLp_k_j_prod *= (alpha-alpha_[i])/(alpha_[k]-alpha_[i]); 00102 } 00103 } 00104 DLp_k += DLp_k_j_prod / (alpha_[k]-alpha_[j]); 00105 } 00106 } 00107 00108 Dphi += phi_[k] * DLp_k; 00109 00110 } 00111 00112 } 00113 00114 if (!is_null(phi_out)) { 00115 *phi_out = phi; 00116 } 00117 00118 if (!is_null(Dphi_out)) { 00119 *Dphi_out = Dphi; 00120 } 00121 00122 } 00123 00124 00125 } // namespace GlobiPack 00126 00127 00128 #endif // GLOBIPACK_TEST_LAGR_POLY_MERIT_FUNC_1D_DEF_HPP
1.7.4