Thyra Version of the Day
Loading...
Searching...
No Matches
Thyra_DirectionalFiniteDiffCalculator_decl.hpp
1// @HEADER
2// ***********************************************************************
3//
4// Thyra: Interfaces and Support for Abstract Numerical Algorithms
5// Copyright (2004) Sandia Corporation
6//
7// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8// license for use of this work by or on behalf of the U.S. Government.
9//
10// Redistribution and use in source and binary forms, with or without
11// modification, are permitted provided that the following conditions are
12// met:
13//
14// 1. Redistributions of source code must retain the above copyright
15// notice, this list of conditions and the following disclaimer.
16//
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// 3. Neither the name of the Corporation nor the names of the
22// contributors may be used to endorse or promote products derived from
23// this software without specific prior written permission.
24//
25// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36//
37// Questions? Contact Roscoe A. Bartlett (bartlettra@ornl.gov)
38//
39// ***********************************************************************
40// @HEADER
41
42#ifndef THYRA_DIRECTIONAL_FINITE_DIFF_CALCULATOR_DECL_HPP
43#define THYRA_DIRECTIONAL_FINITE_DIFF_CALCULATOR_DECL_HPP
44
45#include "Thyra_ModelEvaluator.hpp"
46#include "Teuchos_VerboseObject.hpp"
47#include "Teuchos_ParameterListAcceptor.hpp"
49#include "Teuchos_StandardParameterEntryValidators.hpp"
50#include <list>
51
52namespace Thyra {
53
54
55namespace DirectionalFiniteDiffCalculatorTypes {
56
57
62 FD_ORDER_ONE
63 ,FD_ORDER_TWO
64 ,FD_ORDER_TWO_CENTRAL
65 ,FD_ORDER_TWO_AUTO
66 ,FD_ORDER_FOUR
67 ,FD_ORDER_FOUR_CENTRAL
68 ,FD_ORDER_FOUR_AUTO
69};
70
71
76 FD_STEP_ABSOLUTE
77 ,FD_STEP_RELATIVE
78};
79
80
87public:
92 { supports_DfDp_.push_back(l); return *this; }
95 { supports_DgDp_.push_back(std::pair<int,int>(j,l)); return *this; }
96 // These should be private but I am too lazy to deal with the porting
97 // issues of friends ...
98 typedef std::list<int> supports_DfDp_t;
99 typedef std::list<std::pair<int,int> > supports_DgDp_t;
100 supports_DfDp_t supports_DfDp_;
101 supports_DgDp_t supports_DgDp_;
102};
103
104
105} // namespace DirectionalFiniteDiffCalculatorTypes
106
107
129template<class Scalar>
131 : public Teuchos::VerboseObject<DirectionalFiniteDiffCalculator<Scalar> >,
133{
134public:
135
138
142 typedef typename ST::magnitudeType ScalarMag;
146 typedef DirectionalFiniteDiffCalculatorTypes::EFDMethodType EFDMethodType;
148 typedef DirectionalFiniteDiffCalculatorTypes::EFDStepSelectType EFDStepSelectType;
151
153
156
159
162
170
179
182 EFDMethodType fd_method_type = DirectionalFiniteDiffCalculatorTypes::FD_ORDER_FOUR_AUTO,
183 EFDStepSelectType fd_step_select_type = DirectionalFiniteDiffCalculatorTypes::FD_STEP_ABSOLUTE,
184 ScalarMag fd_step_size = -1.0,
185 ScalarMag fd_step_size_min = -1.0
186 );
187
189
192
194 void setParameterList(RCP<ParameterList> const& paramList);
203
205
208
217 const ModelEvaluator<Scalar> &model,
218 const SelectedDerivatives &fdDerivatives
219 );
220
233 void calcVariations(
234 const ModelEvaluator<Scalar> &model,
235 const ModelEvaluatorBase::InArgs<Scalar> &basePoint,
236 const ModelEvaluatorBase::InArgs<Scalar> &directions,
237 const ModelEvaluatorBase::OutArgs<Scalar> &baseFunctionValues,
239 ) const;
240
243 void calcDerivatives(
244 const ModelEvaluator<Scalar> &model,
245 const ModelEvaluatorBase::InArgs<Scalar> &basePoint,
246 const ModelEvaluatorBase::OutArgs<Scalar> &baseFunctionValues,
247 const ModelEvaluatorBase::OutArgs<Scalar> &derivatives
248 ) const;
249
251
252private:
253
254 RCP<ParameterList> paramList_;
255
256 // //////////////////////////////
257 // Private static data members
258
259 static const std::string& FDMethod_name();
260
262 fdMethodValidator();
263
264 static const std::string& FDMethod_default();
265
266 static const std::string& FDStepSelectType_name();
267
269 fdStepSelectTypeValidator();
270
271 static const std::string& FDStepSelectType_default();
272
273 static const std::string& FDStepLength_name();
274
275 static const double& FDStepLength_default();
276
277};
278
279
284template<class Scalar>
292
293
298template<class Scalar>
301 const RCP<ParameterList> &paramList
302 )
303{
306 fdCalc->setParameterList(paramList);
307 return fdCalc;
308}
309
310
311} // namespace Thyra
312
313
314#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.
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)
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)