Thyra Version of the Day
Loading...
Searching...
No Matches
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
20namespace Thyra {
21
22
23namespace 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
55public:
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
97template<class Scalar>
99 : public Teuchos::VerboseObject<DirectionalFiniteDiffCalculator<Scalar> >,
101{
102public:
103
106
110 typedef typename ST::magnitudeType ScalarMag;
114 typedef DirectionalFiniteDiffCalculatorTypes::EFDMethodType EFDMethodType;
116 typedef DirectionalFiniteDiffCalculatorTypes::EFDStepSelectType EFDStepSelectType;
119
121
124
127
130
138
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,
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
220private:
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
252template<class Scalar>
260
261
266template<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
Simple utility class used to select finite difference derivatives for OutArgs object.
SelectedDerivatives & supports(ModelEvaluatorBase::EOutArgsDgDp, int j, int l)
SelectedDerivatives & supports(ModelEvaluatorBase::EOutArgsDfDp, int l)
Utility class for computing directional finite differences of a model.
STANDARD_MEMBER_COMPOSITION_MEMBERS(ScalarMag, fd_step_size)
Pick the size of the finite difference step.
void setParameterList(RCP< ParameterList > const &paramList)
ModelEvaluatorBase::OutArgs< Scalar > createOutArgs(const ModelEvaluator< Scalar > &model, const SelectedDerivatives &fdDerivatives)
Create an augmented out args object for holding finite difference objects.
DirectionalFiniteDiffCalculatorTypes::EFDStepSelectType EFDStepSelectType
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.
STANDARD_MEMBER_COMPOSITION_MEMBERS(EFDStepSelectType, fd_step_select_type)
STANDARD_MEMBER_COMPOSITION_MEMBERS(EFDMethodType, fd_method_type)
RCP< DirectionalFiniteDiffCalculator< Scalar > > directionalFiniteDiffCalculator()
Nonmember constructor.
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..
DirectionalFiniteDiffCalculatorTypes::SelectedDerivatives SelectedDerivatives
STANDARD_MEMBER_COMPOSITION_MEMBERS(ScalarMag, fd_step_size_min)
Pick the minimum step size under which the finite difference product will not be computed.
RCP< DirectionalFiniteDiffCalculator< Scalar > > directionalFiniteDiffCalculator(const RCP< ParameterList > &paramList)
Nonmember constructor.
DirectionalFiniteDiffCalculatorTypes::EFDMethodType EFDMethodType
Concrete aggregate class for all input arguments computable by a ModelEvaluator subclass object.
Concrete aggregate class for all output arguments computable by a ModelEvaluator subclass object.
Pure abstract base interface for evaluating a stateless "model" that can be mapped into a number of d...
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)