Thyra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_DirectionalFiniteDiffCalculator_decl.hpp
1 // @HEADER
2 // *****************************************************************************
3 // Thyra: Interfaces and Support for Abstract Numerical Algorithms
4 //
5 // Copyright 2004 NTESS and the Thyra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef THYRA_DIRECTIONAL_FINITE_DIFF_CALCULATOR_DECL_HPP
11 #define THYRA_DIRECTIONAL_FINITE_DIFF_CALCULATOR_DECL_HPP
12 
13 #include "Thyra_ModelEvaluator.hpp"
14 #include "Teuchos_VerboseObject.hpp"
15 #include "Teuchos_ParameterListAcceptor.hpp"
16 #include "Teuchos_StandardMemberCompositionMacros.hpp"
17 #include "Teuchos_StandardParameterEntryValidators.hpp"
18 #include <list>
19 
20 namespace Thyra {
21 
22 
23 namespace DirectionalFiniteDiffCalculatorTypes {
24 
25 
30  FD_ORDER_ONE
31  ,FD_ORDER_TWO
32  ,FD_ORDER_TWO_CENTRAL
33  ,FD_ORDER_TWO_AUTO
34  ,FD_ORDER_FOUR
35  ,FD_ORDER_FOUR_CENTRAL
36  ,FD_ORDER_FOUR_AUTO
37 };
38 
39 
44  FD_STEP_ABSOLUTE
45  ,FD_STEP_RELATIVE
46 };
47 
48 
55 public:
60  { supports_DfDp_.push_back(l); return *this; }
63  { supports_DgDp_.push_back(std::pair<int,int>(j,l)); return *this; }
64  // These should be private but I am too lazy to deal with the porting
65  // issues of friends ...
66  typedef std::list<int> supports_DfDp_t;
67  typedef std::list<std::pair<int,int> > supports_DgDp_t;
68  supports_DfDp_t supports_DfDp_;
69  supports_DgDp_t supports_DgDp_;
70 };
71 
72 
73 } // namespace DirectionalFiniteDiffCalculatorTypes
74 
75 
97 template<class Scalar>
99  : public Teuchos::VerboseObject<DirectionalFiniteDiffCalculator<Scalar> >,
101 {
102 public:
103 
106 
110  typedef typename ST::magnitudeType ScalarMag;
114  typedef DirectionalFiniteDiffCalculatorTypes::EFDMethodType EFDMethodType;
116  typedef DirectionalFiniteDiffCalculatorTypes::EFDStepSelectType EFDStepSelectType;
119 
121 
124 
127 
130 
138 
146  STANDARD_MEMBER_COMPOSITION_MEMBERS( ScalarMag, fd_step_size_min );
147 
150  EFDMethodType fd_method_type = DirectionalFiniteDiffCalculatorTypes::FD_ORDER_FOUR_AUTO,
151  EFDStepSelectType fd_step_select_type = DirectionalFiniteDiffCalculatorTypes::FD_STEP_ABSOLUTE,
152  ScalarMag fd_step_size = -1.0,
153  ScalarMag fd_step_size_min = -1.0
154  );
155 
157 
160 
162  void setParameterList(RCP<ParameterList> const& paramList);
171 
173 
176 
185  const ModelEvaluator<Scalar> &model,
186  const SelectedDerivatives &fdDerivatives
187  );
188 
201  void calcVariations(
202  const ModelEvaluator<Scalar> &model,
203  const ModelEvaluatorBase::InArgs<Scalar> &basePoint,
204  const ModelEvaluatorBase::InArgs<Scalar> &directions,
205  const ModelEvaluatorBase::OutArgs<Scalar> &baseFunctionValues,
206  const ModelEvaluatorBase::OutArgs<Scalar> &variations
207  ) const;
208 
211  void calcDerivatives(
212  const ModelEvaluator<Scalar> &model,
213  const ModelEvaluatorBase::InArgs<Scalar> &basePoint,
214  const ModelEvaluatorBase::OutArgs<Scalar> &baseFunctionValues,
215  const ModelEvaluatorBase::OutArgs<Scalar> &derivatives
216  ) const;
217 
219 
220 private:
221 
222  RCP<ParameterList> paramList_;
223 
224  // //////////////////////////////
225  // Private static data members
226 
227  static const std::string& FDMethod_name();
228 
230  fdMethodValidator();
231 
232  static const std::string& FDMethod_default();
233 
234  static const std::string& FDStepSelectType_name();
235 
237  fdStepSelectTypeValidator();
238 
239  static const std::string& FDStepSelectType_default();
240 
241  static const std::string& FDStepLength_name();
242 
243  static const double& FDStepLength_default();
244 
245 };
246 
247 
252 template<class Scalar>
255 {
258  return fdCalc;
259 }
260 
261 
266 template<class Scalar>
269  const RCP<ParameterList> &paramList
270  )
271 {
274  fdCalc->setParameterList(paramList);
275  return fdCalc;
276 }
277 
278 
279 } // namespace Thyra
280 
281 
282 #endif // THYRA_DIRECTIONAL_FINITE_DIFF_CALCULATOR_DECL_HPP
ModelEvaluatorBase::OutArgs< Scalar > createOutArgs(const ModelEvaluator< Scalar > &model, const SelectedDerivatives &fdDerivatives)
Create an augmented out args object for holding finite difference objects.
Pure abstract base interface for evaluating a stateless &quot;model&quot; that can be mapped into a number of d...
Simple utility class used to select finite difference derivatives for OutArgs object.
void setParameterList(RCP< ParameterList > const &paramList)
DirectionalFiniteDiffCalculatorTypes::EFDStepSelectType EFDStepSelectType
Concrete aggregate class for all output arguments computable by a ModelEvaluator subclass object...
DirectionalFiniteDiffCalculatorTypes::EFDMethodType EFDMethodType
void calcVariations(const ModelEvaluator< Scalar > &model, const ModelEvaluatorBase::InArgs< Scalar > &basePoint, const ModelEvaluatorBase::InArgs< Scalar > &directions, const ModelEvaluatorBase::OutArgs< Scalar > &baseFunctionValues, const ModelEvaluatorBase::OutArgs< Scalar > &variations) const
Compute variations using directional finite differences..
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
RCP< DirectionalFiniteDiffCalculator< Scalar > > directionalFiniteDiffCalculator()
Nonmember constructor.
SelectedDerivatives & supports(ModelEvaluatorBase::EOutArgsDgDp, int j, int l)
void calcDerivatives(const ModelEvaluator< Scalar > &model, const ModelEvaluatorBase::InArgs< Scalar > &basePoint, const ModelEvaluatorBase::OutArgs< Scalar > &baseFunctionValues, const ModelEvaluatorBase::OutArgs< Scalar > &derivatives) const
Compute entire derivative objects using finite differences.
DirectionalFiniteDiffCalculatorTypes::SelectedDerivatives SelectedDerivatives
DirectionalFiniteDiffCalculator(EFDMethodType fd_method_type=DirectionalFiniteDiffCalculatorTypes::FD_ORDER_FOUR_AUTO, EFDStepSelectType fd_step_select_type=DirectionalFiniteDiffCalculatorTypes::FD_STEP_ABSOLUTE, ScalarMag fd_step_size=-1.0, ScalarMag fd_step_size_min=-1.0)
SelectedDerivatives & supports(ModelEvaluatorBase::EOutArgsDfDp, int l)
RCP< DirectionalFiniteDiffCalculator< Scalar > > directionalFiniteDiffCalculator(const RCP< ParameterList > &paramList)
Nonmember constructor.
STANDARD_MEMBER_COMPOSITION_MEMBERS(EFDMethodType, fd_method_type)
Utility class for computing directional finite differences of a model.
Concrete aggregate class for all input arguments computable by a ModelEvaluator subclass object...