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 //
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"
48 #include "Teuchos_StandardMemberCompositionMacros.hpp"
49 #include "Teuchos_StandardParameterEntryValidators.hpp"
50 #include <list>
51 
52 namespace Thyra {
53 
54 
55 namespace 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 
87 public:
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 
129 template<class Scalar>
131  : public Teuchos::VerboseObject<DirectionalFiniteDiffCalculator<Scalar> >,
133 {
134 public:
135 
138 
142  typedef typename ST::magnitudeType ScalarMag;
146  typedef DirectionalFiniteDiffCalculatorTypes::EFDMethodType EFDMethodType;
148  typedef DirectionalFiniteDiffCalculatorTypes::EFDStepSelectType EFDStepSelectType;
151 
153 
156 
159 
162 
170 
178  STANDARD_MEMBER_COMPOSITION_MEMBERS( ScalarMag, fd_step_size_min );
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,
238  const ModelEvaluatorBase::OutArgs<Scalar> &variations
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 
252 private:
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 
284 template<class Scalar>
287 {
290  return fdCalc;
291 }
292 
293 
298 template<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
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...