Sacado Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
Sacado_Fad_GeneralFadTestingHelpers.hpp
Go to the documentation of this file.
1// @HEADER
2// ***********************************************************************
3//
4// Sacado Package
5// Copyright (2006) Sandia Corporation
6//
7// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8// the U.S. Government retains certain rights in this software.
9//
10// This library is free software; you can redistribute it and/or modify
11// it under the terms of the GNU Lesser General Public License as
12// published by the Free Software Foundation; either version 2.1 of the
13// License, or (at your option) any later version.
14//
15// This library is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18// Lesser General Public License for more details.
19//
20// You should have received a copy of the GNU Lesser General Public
21// License along with this library; if not, write to the Free Software
22// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
23// USA
24// Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
25// (etphipp@sandia.gov).
26//
27// ***********************************************************************
28//
29// @HEADER
30
31#ifndef SACADO_FAD_GENERALFADTESTINGHELPERS_HPP
32
33#include "Sacado_ConfigDefs.h"
34#ifdef HAVE_SACADO_TEUCHOSCORE
35
36#define SACADO_FAD_GENERALFADTESTINGHELPERS_HPP
37
38namespace Sacado {
39 namespace Fad {
40 // relErrFadImpl version for non-Fad types
41 template <typename T1, typename T2>
42 typename std::enable_if<
44 typename Teuchos::ScalarTraits< typename std::common_type<T1,T2>::type >::magnitudeType
45 >::type
46 relErrFadImpl(const T1& v1, const T2& v2) { return Teuchos::relErr(v1,v2); }
47
48 // relErrFadImpl version for Fad types
49 template <typename T1, typename T2>
50 typename std::enable_if<
52 typename Teuchos::ScalarTraits<
53 typename std::common_type< typename ScalarType<T1>::type, typename ScalarType<T2>::type >::type
54 >::magnitudeType
55 >::type
56 relErrFadImpl(const T1& v1, const T2& v2)
57 {
58 typedef typename Teuchos::ScalarTraits<typename std::common_type< typename ScalarType<T1>::type, typename ScalarType<T2>::type >::type>::magnitudeType magnitudeType;
59 magnitudeType maxRelErr = relErrFadImpl(v1.val(), v2.val());
60 for (int i=0; i<v1.size(); ++i) {
61 magnitudeType tmpRelErr = relErrFadImpl(v1.dx(i), v2.dx(i));
62 if (tmpRelErr >= maxRelErr)
63 maxRelErr = tmpRelErr;
64 }
65 return maxRelErr;
66 }
67 }
68}
69
70namespace Teuchos {
71 template <typename T1, typename T2>
72 struct TestRelErr<T1,T2,
73 typename std::enable_if<Sacado::IsExpr<T1>::value ||
74 Sacado::IsExpr<T2>::value >::type >
75 {
76 typedef typename Sacado::ScalarType<T1>::type scalarType1;
77 typedef typename Sacado::ScalarType<T2>::type scalarType2;
78 typedef typename std::common_type<scalarType1,scalarType2>::type scalarType;
79 typedef typename Teuchos::ScalarTraits<scalarType>::magnitudeType magnitudeType;
80 static bool eval(
81 const std::string &v1_name,
82 const T1 &vv1,
83 const std::string &v2_name,
84 const T2 &vv2,
85 const std::string &maxRelErr_error_name,
86 const magnitudeType &maxRelErr_error,
87 const std::string &maxRelErr_warning_name,
88 const magnitudeType &maxRelErr_warning,
89 const Ptr<std::ostream> &out
90 )
91 {
92 using std::endl;
93 typedef Teuchos::ScalarTraits<magnitudeType> SMT;
94 typename Sacado::BaseExprType<T1>::type v1(vv1);
95 typename Sacado::BaseExprType<T2>::type v2(vv2);
96 const magnitudeType rel_err = Sacado::Fad::relErrFadImpl( v1, v2);
97 const bool success = ( !SMT::isnaninf(rel_err) && !SMT::isnaninf(maxRelErr_error)
98 && rel_err <= maxRelErr_error );
99 if (!is_null(out)) {
100 *out
101 << endl
102 << "Check: rel_err(" << v1_name << ", " << v2_name << ")\n"
103 << " = rel_err(" << v1 << ", " << v2 << ") "
104 << "= " << rel_err << endl
105 << " <= " << maxRelErr_error_name
106 << " = " << maxRelErr_error << " : " << Teuchos::passfail(success) << endl;
107 if( success && rel_err >= maxRelErr_warning ) {
108 *out
109 << "Warning! rel_err(" << v1_name << ", " << v2_name << ")\n"
110 << " = rel_err(" << v1 << ", " << v2 << ") "
111 << "= " << rel_err << endl
112 << " >= " << maxRelErr_warning_name
113 << " = " << maxRelErr_warning << "!\n";
114 }
115 }
116 return success;
117 }
118 };
119}
120
121#define TEUCHOS_TEST_FLOATING_NOT_EQUALITY( v1, v2, tol, out, success ) \
122 { \
123 const bool l_result = Teuchos::testRelErr( \
124 #v1, v1, #v2, v2, "tol", tol, "tol", tol, Teuchos::outArg(out) ); \
125 if (l_result) (success) = false; \
126 }
127
128#endif
129
130#endif
#define T1(r, f)
#define T2(r, f)
Fad specializations for Teuchos::BLAS wrappers.
static const bool value