1 #ifndef VERTEXCFD_UTILS_SMOOTHABS_HPP
2 #define VERTEXCFD_UTILS_SMOOTHABS_HPP
4 #include "VertexCFD_Utils_Constants.hpp"
5 #include "VertexCFD_Utils_TypeTraits.hpp"
8 #include <Sacado_Fad_Exp_Expression.hpp>
9 #include <Sacado_Fad_Exp_ExpressionTraits.hpp>
18 template<
typename T,
typename ExprSpec>
25 :
public Sacado::Fad::Exp::Expr<
26 SmoothAbsOp<T, Sacado::Fad::Exp::ExprSpecDefault>>
29 using ExprT =
typename std::remove_cv<T>::type;
30 using value_type =
typename ExprT::value_type;
31 using scalar_type =
typename ExprT::scalar_type;
32 using expr_spec_type = Sacado::Fad::Exp::ExprSpecDefault;
34 SACADO_INLINE_FUNCTION
explicit SmoothAbsOp(
const T& x,
double tol)
40 SACADO_INLINE_FUNCTION
int size()
const {
return x_.size(); }
42 SACADO_INLINE_FUNCTION
bool hasFastAccess()
const
44 return x_.hasFastAccess();
47 SACADO_INLINE_FUNCTION value_type val()
const
59 return 0.5 * (x_.val() * x_.val() / tol_ + tol_);
63 SACADO_INLINE_FUNCTION value_type dx(
int i)
const
71 return value_type(-x_.dx(i));
75 return x_.dx(i) * x_.val() / tol_;
79 SACADO_INLINE_FUNCTION value_type fastAccessDx(
int i)
const
83 return x_.fastAccessDx(i);
87 return value_type(-x_.fastAccessDx(i));
91 return x_.fastAccessDx(i) * x_.val() / tol_;
102 SACADO_INLINE_FUNCTION
103 typename std::enable_if<std::is_trivial<T>::value, T>::type
104 abs(
const T x,
const double tol)
116 return 0.5 * (x * x / tol + tol);
120 using Sacado::Fad::Exp::Expr;
124 SACADO_INLINE_FUNCTION
125 SmoothAbsOp<typename Expr<T>::derived_type,
typename T::expr_spec_type>
126 abs(
const Expr<T>& x,
const double tol)
129 = SmoothAbsOp<typename Expr<T>::derived_type,
typename T::expr_spec_type>;
130 return expr_t(x.derived(), tol);
150 template<
typename T,
typename E>
153 static const unsigned value = ExprLevel<T>::value;
156 template<
typename T,
typename E>
159 static const unsigned value =
true;
165 template<
typename T,
typename E>
168 static const unsigned value =
true;
171 template<
typename T,
typename E>
174 using type =
typename BaseExprType<T>::type;
177 template<
typename T,
typename E>
180 static const bool value
181 = IsSimdType<typename SmoothAbsOp<T, E>::scalar_type>::value;
184 template<
typename T,
typename E>
190 template<
typename T,
typename E>
198 #endif // end VERTEXCFD_UTILS_SMOOTHABS_HPP