|
Thyra Package Browser (Single Doxygen Collection) Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // Thyra: Interfaces and Support for Abstract Numerical Algorithms 00005 // Copyright (2004) 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 Michael A. Heroux (maherou@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 // @HEADER 00028 00029 #ifndef THYRA_DIRECTIONAL_FINITE_DIFF_CALCULATOR_DECL_HPP 00030 #define THYRA_DIRECTIONAL_FINITE_DIFF_CALCULATOR_DECL_HPP 00031 00032 #include "Thyra_ModelEvaluator.hpp" 00033 #include "Teuchos_VerboseObject.hpp" 00034 #include "Teuchos_ParameterListAcceptor.hpp" 00035 #include "Teuchos_StandardMemberCompositionMacros.hpp" 00036 #include "Teuchos_StandardParameterEntryValidators.hpp" 00037 00038 00039 namespace Thyra { 00040 00041 00042 namespace DirectionalFiniteDiffCalculatorTypes { 00043 00044 00048 enum EFDMethodType { 00049 FD_ORDER_ONE 00050 ,FD_ORDER_TWO 00051 ,FD_ORDER_TWO_CENTRAL 00052 ,FD_ORDER_TWO_AUTO 00053 ,FD_ORDER_FOUR 00054 ,FD_ORDER_FOUR_CENTRAL 00055 ,FD_ORDER_FOUR_AUTO 00056 }; 00057 00058 00062 enum EFDStepSelectType { 00063 FD_STEP_ABSOLUTE 00064 ,FD_STEP_RELATIVE 00065 }; 00066 00067 00073 class SelectedDerivatives { 00074 public: 00076 SelectedDerivatives() {} 00078 SelectedDerivatives& supports( ModelEvaluatorBase::EOutArgsDfDp arg, int l ) 00079 { supports_DfDp_.push_back(l); return *this; } 00081 SelectedDerivatives& supports( ModelEvaluatorBase::EOutArgsDgDp arg, int j, int l ) 00082 { supports_DgDp_.push_back(std::pair<int,int>(j,l)); return *this; } 00083 // These should be private but I am too lazy to deal with the porting 00084 // issues of friends ... 00085 typedef std::list<int> supports_DfDp_t; 00086 typedef std::list<std::pair<int,int> > supports_DgDp_t; 00087 supports_DfDp_t supports_DfDp_; 00088 supports_DgDp_t supports_DgDp_; 00089 }; 00090 00091 00092 } // namespace DirectionalFiniteDiffCalculatorTypes 00093 00094 00116 template<class Scalar> 00117 class DirectionalFiniteDiffCalculator 00118 : public Teuchos::VerboseObject<DirectionalFiniteDiffCalculator<Scalar> >, 00119 public Teuchos::ParameterListAcceptor 00120 { 00121 public: 00122 00125 00127 typedef ScalarTraits<Scalar> ST; 00129 typedef typename ST::magnitudeType ScalarMag; 00131 typedef ScalarTraits<ScalarMag> SMT; 00133 typedef DirectionalFiniteDiffCalculatorTypes::EFDMethodType EFDMethodType; 00135 typedef DirectionalFiniteDiffCalculatorTypes::EFDStepSelectType EFDStepSelectType; 00137 typedef DirectionalFiniteDiffCalculatorTypes::SelectedDerivatives SelectedDerivatives; 00138 00140 00143 00145 STANDARD_MEMBER_COMPOSITION_MEMBERS( EFDMethodType, fd_method_type ); 00146 00148 STANDARD_MEMBER_COMPOSITION_MEMBERS( EFDStepSelectType, fd_step_select_type ); 00149 00156 STANDARD_MEMBER_COMPOSITION_MEMBERS( ScalarMag, fd_step_size ); 00157 00165 STANDARD_MEMBER_COMPOSITION_MEMBERS( ScalarMag, fd_step_size_min ); 00166 00168 DirectionalFiniteDiffCalculator( 00169 EFDMethodType fd_method_type = DirectionalFiniteDiffCalculatorTypes::FD_ORDER_FOUR_AUTO, 00170 EFDStepSelectType fd_step_select_type = DirectionalFiniteDiffCalculatorTypes::FD_STEP_ABSOLUTE, 00171 ScalarMag fd_step_size = -1.0, 00172 ScalarMag fd_step_size_min = -1.0 00173 ); 00174 00176 00179 00181 void setParameterList(RCP<ParameterList> const& paramList); 00183 RCP<ParameterList> getNonconstParameterList(); 00185 RCP<ParameterList> unsetParameterList(); 00187 RCP<const ParameterList> getParameterList() const; 00189 RCP<const ParameterList> getValidParameters() const; 00190 00192 00195 00203 ModelEvaluatorBase::OutArgs<Scalar> createOutArgs( 00204 const ModelEvaluator<Scalar> &model, 00205 const SelectedDerivatives &fdDerivatives 00206 ); 00207 00220 void calcVariations( 00221 const ModelEvaluator<Scalar> &model, 00222 const ModelEvaluatorBase::InArgs<Scalar> &basePoint, 00223 const ModelEvaluatorBase::InArgs<Scalar> &directions, 00224 const ModelEvaluatorBase::OutArgs<Scalar> &baseFunctionValues, 00225 const ModelEvaluatorBase::OutArgs<Scalar> &variations 00226 ) const; 00227 00230 void calcDerivatives( 00231 const ModelEvaluator<Scalar> &model, 00232 const ModelEvaluatorBase::InArgs<Scalar> &basePoint, 00233 const ModelEvaluatorBase::OutArgs<Scalar> &baseFunctionValues, 00234 const ModelEvaluatorBase::OutArgs<Scalar> &derivatives 00235 ) const; 00236 00238 00239 private: 00240 00241 RCP<ParameterList> paramList_; 00242 00243 // ////////////////////////////// 00244 // Private static data members 00245 00246 static const std::string FDMethod_name; 00247 static const RCP<Teuchos::StringToIntegralParameterEntryValidator<EFDMethodType> > 00248 fdMethodValidator; 00249 static const std::string FDMethod_default; 00250 00251 static const std::string FDStepSelectType_name; 00252 static const RCP<Teuchos::StringToIntegralParameterEntryValidator<EFDStepSelectType> > 00253 fdStepSelectTypeValidator; 00254 static const std::string FDStepSelectType_default; 00255 00256 static const std::string FDStepLength_name; 00257 static const double FDStepLength_default; 00258 00259 }; 00260 00261 00266 template<class Scalar> 00267 RCP<DirectionalFiniteDiffCalculator<Scalar> > 00268 directionalFiniteDiffCalculator( 00269 const RCP<ParameterList> ¶mList 00270 ) 00271 { 00272 RCP<DirectionalFiniteDiffCalculator<Scalar> > 00273 fdCalc = Teuchos::rcp(new DirectionalFiniteDiffCalculator<Scalar>()); 00274 fdCalc->setParameterList(paramList); 00275 return fdCalc; 00276 } 00277 00278 00279 } // namespace Thyra 00280 00281 00282 #endif // THYRA_DIRECTIONAL_FINITE_DIFF_CALCULATOR_DECL_HPP
1.7.4