Thyra Version of the Day
Thyra_DirectionalFiniteDiffCalculator_decl.hpp
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 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Roscoe A. Bartlett (bartlettra@ornl.gov) 
00038 // 
00039 // ***********************************************************************
00040 // @HEADER
00041 
00042 #ifndef THYRA_DIRECTIONAL_FINITE_DIFF_CALCULATOR_DECL_HPP
00043 #define THYRA_DIRECTIONAL_FINITE_DIFF_CALCULATOR_DECL_HPP
00044 
00045 #include "Thyra_ModelEvaluator.hpp"
00046 #include "Teuchos_VerboseObject.hpp"
00047 #include "Teuchos_ParameterListAcceptor.hpp"
00048 #include "Teuchos_StandardMemberCompositionMacros.hpp"
00049 #include "Teuchos_StandardParameterEntryValidators.hpp"
00050 
00051 
00052 namespace Thyra {
00053 
00054 
00055 namespace DirectionalFiniteDiffCalculatorTypes {
00056 
00057 
00061 enum EFDMethodType {
00062   FD_ORDER_ONE           
00063   ,FD_ORDER_TWO          
00064   ,FD_ORDER_TWO_CENTRAL  
00065   ,FD_ORDER_TWO_AUTO     
00066   ,FD_ORDER_FOUR         
00067   ,FD_ORDER_FOUR_CENTRAL 
00068   ,FD_ORDER_FOUR_AUTO    
00069 };
00070 
00071 
00075 enum EFDStepSelectType {
00076   FD_STEP_ABSOLUTE      
00077   ,FD_STEP_RELATIVE     
00078 };
00079 
00080 
00086 class SelectedDerivatives {
00087 public:
00089   SelectedDerivatives() {}
00091   SelectedDerivatives& supports( ModelEvaluatorBase::EOutArgsDfDp arg, int l )
00092     { supports_DfDp_.push_back(l); return *this; }
00094   SelectedDerivatives& supports( ModelEvaluatorBase::EOutArgsDgDp arg, int j, int l )
00095     { supports_DgDp_.push_back(std::pair<int,int>(j,l)); return *this; }
00096   // These should be private but I am too lazy to deal with the porting
00097   // issues of friends ...
00098   typedef std::list<int> supports_DfDp_t;
00099   typedef std::list<std::pair<int,int> > supports_DgDp_t;
00100   supports_DfDp_t supports_DfDp_;
00101   supports_DgDp_t supports_DgDp_;
00102 };
00103 
00104 
00105 } // namespace DirectionalFiniteDiffCalculatorTypes
00106 
00107 
00129 template<class Scalar>
00130 class DirectionalFiniteDiffCalculator
00131   : public Teuchos::VerboseObject<DirectionalFiniteDiffCalculator<Scalar> >,
00132     public Teuchos::ParameterListAcceptor
00133 {
00134 public:
00135   
00138 
00140   typedef ScalarTraits<Scalar> ST;
00142   typedef typename ST::magnitudeType ScalarMag;
00144   typedef ScalarTraits<ScalarMag> SMT;
00146   typedef DirectionalFiniteDiffCalculatorTypes::EFDMethodType EFDMethodType;
00148   typedef DirectionalFiniteDiffCalculatorTypes::EFDStepSelectType EFDStepSelectType;
00150   typedef DirectionalFiniteDiffCalculatorTypes::SelectedDerivatives SelectedDerivatives;
00151 
00153 
00156 
00158   STANDARD_MEMBER_COMPOSITION_MEMBERS( EFDMethodType, fd_method_type );
00159 
00161   STANDARD_MEMBER_COMPOSITION_MEMBERS( EFDStepSelectType, fd_step_select_type );
00162 
00169   STANDARD_MEMBER_COMPOSITION_MEMBERS( ScalarMag, fd_step_size );
00170 
00178   STANDARD_MEMBER_COMPOSITION_MEMBERS( ScalarMag, fd_step_size_min );
00179 
00181   DirectionalFiniteDiffCalculator(
00182     EFDMethodType fd_method_type = DirectionalFiniteDiffCalculatorTypes::FD_ORDER_FOUR_AUTO,
00183     EFDStepSelectType fd_step_select_type = DirectionalFiniteDiffCalculatorTypes::FD_STEP_ABSOLUTE,
00184     ScalarMag fd_step_size = -1.0,
00185     ScalarMag fd_step_size_min = -1.0
00186     );
00187 
00189 
00192 
00194   void setParameterList(RCP<ParameterList> const& paramList);
00196   RCP<ParameterList> getNonconstParameterList();
00198   RCP<ParameterList> unsetParameterList();
00200   RCP<const ParameterList> getParameterList() const;
00202   RCP<const ParameterList> getValidParameters() const;
00203 
00205 
00208 
00216   ModelEvaluatorBase::OutArgs<Scalar> createOutArgs(
00217     const ModelEvaluator<Scalar> &model,
00218     const SelectedDerivatives   &fdDerivatives
00219     );
00220 
00233   void calcVariations(
00234     const ModelEvaluator<Scalar> &model,
00235     const ModelEvaluatorBase::InArgs<Scalar> &basePoint,
00236     const ModelEvaluatorBase::InArgs<Scalar> &directions,
00237     const ModelEvaluatorBase::OutArgs<Scalar> &baseFunctionValues,
00238     const ModelEvaluatorBase::OutArgs<Scalar> &variations
00239     ) const;
00240 
00243   void calcDerivatives(
00244     const ModelEvaluator<Scalar> &model,
00245     const ModelEvaluatorBase::InArgs<Scalar> &basePoint,
00246     const ModelEvaluatorBase::OutArgs<Scalar> &baseFunctionValues,
00247     const ModelEvaluatorBase::OutArgs<Scalar> &derivatives
00248     ) const;
00249 
00251 
00252 private:
00253 
00254   RCP<ParameterList>  paramList_;
00255 
00256   // //////////////////////////////
00257   // Private static data members
00258 
00259   static const std::string FDMethod_name;
00260   static const RCP<Teuchos::StringToIntegralParameterEntryValidator<EFDMethodType> >
00261   fdMethodValidator;
00262   static const std::string FDMethod_default;
00263 
00264   static const std::string FDStepSelectType_name;
00265   static const RCP<Teuchos::StringToIntegralParameterEntryValidator<EFDStepSelectType> >
00266   fdStepSelectTypeValidator;
00267   static const std::string FDStepSelectType_default;
00268 
00269   static const std::string FDStepLength_name;
00270   static const double FDStepLength_default;
00271 
00272 };
00273 
00274 
00279 template<class Scalar>
00280 RCP<DirectionalFiniteDiffCalculator<Scalar> >
00281 directionalFiniteDiffCalculator(
00282   const RCP<ParameterList> &paramList
00283   )
00284 {
00285   RCP<DirectionalFiniteDiffCalculator<Scalar> >
00286     fdCalc = Teuchos::rcp(new DirectionalFiniteDiffCalculator<Scalar>());
00287   fdCalc->setParameterList(paramList);
00288   return fdCalc;
00289 }
00290 
00291 
00292 } // namespace Thyra
00293 
00294 
00295 #endif  // THYRA_DIRECTIONAL_FINITE_DIFF_CALCULATOR_DECL_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines