11#ifndef PANZER_EXPR_EVAL_IMPL_HPP
12#define PANZER_EXPR_EVAL_IMPL_HPP
26 static KOKKOS_FORCEINLINE_FUNCTION
27 T
apply(
bool cond, T
const& left, T
const& right) {
28 return cond ? left : right;
33 static KOKKOS_FORCEINLINE_FUNCTION
34 bool apply(
bool left,
bool right) {
40 static KOKKOS_FORCEINLINE_FUNCTION
41 bool apply(
bool left,
bool right) {
48 static KOKKOS_FORCEINLINE_FUNCTION
49 bool apply(T
const& left, T
const& right) {
56 static KOKKOS_FORCEINLINE_FUNCTION
57 bool apply(T
const& left, T
const& right) {
64 static KOKKOS_FORCEINLINE_FUNCTION
65 bool apply(T
const& left, T
const& right) {
72 static KOKKOS_FORCEINLINE_FUNCTION
73 bool apply(T
const& left, T
const& right) {
80 static KOKKOS_FORCEINLINE_FUNCTION
81 bool apply(T
const& left, T
const& right) {
88 static KOKKOS_FORCEINLINE_FUNCTION
89 T
apply(T
const& left, T
const& right) {
96 static KOKKOS_FORCEINLINE_FUNCTION
97 T
apply(T
const& left, T
const& right) {
103 template <
typename T>
104 static KOKKOS_FORCEINLINE_FUNCTION
105 T
apply(T
const& left, T
const& right) {
111 template <
typename T>
112 static KOKKOS_FORCEINLINE_FUNCTION
113 T
apply(T
const& left, T
const& right) {
119 template <
typename T>
120 static KOKKOS_FORCEINLINE_FUNCTION
121 T
apply(T
const& left, T
const& right) {
123 return pow(left, right);
128 template <
typename T>
129 static KOKKOS_FORCEINLINE_FUNCTION
136template <
typename Indexed,
size_t IterationRank,
size_t IndexedRank = Indexed::rank>
139template <
typename ViewType>
141 template <
typename Integral>
142 static KOKKOS_FORCEINLINE_FUNCTION
143 typename ViewType::reference_type
index(ViewType
const& x, Integral) {
return x(); }
146template <
typename ViewType>
148 template <
typename Integral>
149 static KOKKOS_FORCEINLINE_FUNCTION
150 typename ViewType::reference_type
index(ViewType
const& x, Integral i) {
return x(i); }
153template <
typename ViewType>
155 template <
typename Integral>
156 static KOKKOS_FORCEINLINE_FUNCTION
157 typename ViewType::reference_type
index(ViewType
const& x, Integral, Integral) {
return x(); }
160template <
typename ViewType>
162 template <
typename Integral>
163 static KOKKOS_FORCEINLINE_FUNCTION
164 typename ViewType::reference_type
index(ViewType
const& x, Integral i, Integral) {
return x(i); }
167template <
typename ViewType>
169 template <
typename Integral>
170 static KOKKOS_FORCEINLINE_FUNCTION
171 typename ViewType::reference_type
index(ViewType
const& x, Integral i, Integral j) {
return x(i, j); }
175template <
typename T,
typename ... TS>
180 static constexpr size_t value = T::rank;
183template <
typename T,
typename ... TS>
190template <
typename A,
typename B>
192 static constexpr size_t a_rank = A::rank;
193 static constexpr size_t b_rank = B::rank;
199template <
typename C,
typename A,
typename B>
201 static constexpr size_t a_rank = A::rank;
202 static constexpr size_t b_rank = B::rank;
203 static constexpr size_t c_rank = C::rank;
210template <
typename Op,
typename Result,
typename Left,
typename Right,
size_t Rank = Result::rank>
213template <
typename Op,
typename Result,
typename Left,
typename Right>
220 KOKKOS_INLINE_FUNCTION
222 result_() = Op::apply(left_(), right_());
225 left_ = Teuchos::any_cast<Left>(left);
226 right_ = Teuchos::any_cast<Right>(right);
227 result_ =
NonConstResult(Kokkos::ViewAllocateWithoutInitializing(name));
228 Kokkos::parallel_for(name, Kokkos::RangePolicy<execution_space>(0, 1), *
this);
233template <
typename Op,
typename Result,
typename Left,
typename Right>
240 KOKKOS_INLINE_FUNCTION
241 void operator()(
typename execution_space::size_type i)
const {
248 left_ = Teuchos::any_cast<Left>(left);
249 right_ = Teuchos::any_cast<Right>(right);
250 auto extent_0 = std::max(left_.extent(0), right_.extent(0));
251 result_ =
NonConstResult(Kokkos::ViewAllocateWithoutInitializing(name), extent_0);
252 Kokkos::parallel_for(name, Kokkos::RangePolicy<execution_space>(0, extent_0), *
this);
257template <
typename Op,
typename Result,
typename Left,
typename Right>
264 KOKKOS_INLINE_FUNCTION
265 void operator()(
typename execution_space::size_type i,
typename execution_space::size_type j)
const {
272 left_ = Teuchos::any_cast<Left>(left);
273 right_ = Teuchos::any_cast<Right>(right);
274 auto extent_0 = std::max(left_.extent(0), right_.extent(0));
275 auto extent_1 = std::max(left_.extent(1), right_.extent(1));
276 result_ =
NonConstResult(Kokkos::ViewAllocateWithoutInitializing(name), extent_0, extent_1);
277 using policy_type = Kokkos::MDRangePolicy<execution_space, Kokkos::Rank<2>>;
278 Kokkos::parallel_for(name, policy_type({0, 0}, {extent_0, extent_1}), *
this);
283template <typename Cond, typename Left, typename Right, size_t Rank = MaxRank<Cond, Left, Right>::value>
286template <
typename Cond,
typename Left,
typename Right>
295 KOKKOS_INLINE_FUNCTION
296 void operator()(
typename execution_space::size_type i)
const {
302 TernaryFunctor(std::string
const& name, Teuchos::any&
result, Teuchos::any& cond, Teuchos::any& left, Teuchos::any& right) {
303 cond_ = Teuchos::any_cast<Cond>(cond);
304 left_ = Teuchos::any_cast<Left>(left);
305 right_ = Teuchos::any_cast<Right>(right);
307 std::max(cond_.extent(0),
308 std::max(left_.extent(0), right_.extent(0)));
309 result_ =
NonConstResult(Kokkos::ViewAllocateWithoutInitializing(name), extent_0);
310 Kokkos::parallel_for(name, Kokkos::RangePolicy<execution_space>(0, extent_0), *
this);
315template <
typename Cond,
typename Left,
typename Right>
324 KOKKOS_INLINE_FUNCTION
325 void operator()(
typename execution_space::size_type i,
typename execution_space::size_type j)
const {
331 TernaryFunctor(std::string
const& name, Teuchos::any&
result, Teuchos::any& cond, Teuchos::any& left, Teuchos::any& right) {
332 cond_ = Teuchos::any_cast<Cond>(cond);
333 left_ = Teuchos::any_cast<Left>(left);
334 right_ = Teuchos::any_cast<Right>(right);
336 std::max(cond_.extent(0),
337 std::max(left_.extent(0), right_.extent(0)));
339 std::max(cond_.extent(1),
340 std::max(left_.extent(1), right_.extent(1)));
341 result_ =
NonConstResult(Kokkos::ViewAllocateWithoutInitializing(name), extent_0, extent_1);
342 using policy_type = Kokkos::MDRangePolicy<execution_space, Kokkos::Rank<2>>;
343 Kokkos::parallel_for(name, policy_type({0, 0}, {extent_0, extent_1}), *
this);
348template <
typename DT,
typename ... VP>
354template <
typename DT,
typename ... VP>
357 auto host_view = Kokkos::create_mirror_view(view);
359 Kokkos::deep_copy(view, host_view);
363template <
typename DT,
typename ... VP>
366 auto host_view = Kokkos::create_mirror_view(view);
368 Kokkos::deep_copy(view, host_view);
371 this->inspect_arg(symbol_map[name], a, b);
374template <
typename DT,
typename ... VP>
376 symbol_map[name] = value;
379template <
typename DT,
typename ... VP>
382 auto host_view = Kokkos::create_mirror_view(view);
384 Kokkos::deep_copy(view, host_view);
387 this->inspect_arg(
result, a, b);
390template <
typename DT,
typename ... VP>
405 TEUCHOS_TEST_FOR_EXCEPTION(
true, Teuchos::ParserFail,
406 "value is of illegal type " << arg.typeName() <<
", view type is "
411template <
typename DT,
typename ... VP>
418template <
typename DT,
typename ... VP>
426template <
typename DT,
typename ... VP>
434template <
typename DT,
typename ... VP>
441template <
typename DT,
typename ... VP>
461template <
typename DT,
typename ... VP>
483template <
typename DT,
typename ... VP>
505template <
typename DT,
typename ... VP>
525template <
typename Op,
typename Result,
size_t Rank = Result::rank>
528template <
typename Op,
typename Result>
534 KOKKOS_INLINE_FUNCTION
535 void operator()(
typename execution_space::size_type i)
const {
536 result_() = Op::apply(right_());
539 right_ = Teuchos::any_cast<Result>(right);
540 result_ =
NonConstResult(Kokkos::ViewAllocateWithoutInitializing(name));
541 Kokkos::parallel_for(name, Kokkos::RangePolicy<execution_space>(0, 1), *
this);
546template <
typename Op,
typename Result>
552 KOKKOS_INLINE_FUNCTION
553 void operator()(
typename execution_space::size_type i)
const {
554 result_(i) = Op::apply(right_(i));
557 right_ = Teuchos::any_cast<Result>(right);
558 auto extent_0 = right_.extent(0);
559 result_ =
NonConstResult(Kokkos::ViewAllocateWithoutInitializing(name), extent_0);
560 Kokkos::parallel_for(name, Kokkos::RangePolicy<execution_space>(0, extent_0), *
this);
565template <
typename Op,
typename Result>
571 KOKKOS_INLINE_FUNCTION
572 void operator()(
typename execution_space::size_type i,
typename execution_space::size_type j)
const {
573 result_(i, j) = Op::apply(right_(i, j));
576 right_ = Teuchos::any_cast<Result>(right);
577 auto extent_0 = right_.extent(0);
578 auto extent_1 = right_.extent(1);
579 result_ =
NonConstResult(Kokkos::ViewAllocateWithoutInitializing(name), extent_0, extent_1);
580 using policy_type = Kokkos::MDRangePolicy<execution_space, Kokkos::Rank<2>>;
581 Kokkos::parallel_for(name, policy_type({0, 0}, {extent_0, extent_1}), *
this);
586template <
typename DT,
typename ... VP>
591template <
typename DT,
typename ... VP>
597 template <
typename T>
598 static KOKKOS_FORCEINLINE_FUNCTION
606 template <
typename T>
607 static KOKKOS_FORCEINLINE_FUNCTION
615 template <
typename T>
616 static KOKKOS_FORCEINLINE_FUNCTION
624 template <
typename T>
625 static KOKKOS_FORCEINLINE_FUNCTION
633 template <
typename T>
634 static KOKKOS_FORCEINLINE_FUNCTION
642 template <
typename T>
643 static KOKKOS_FORCEINLINE_FUNCTION
651 template <
typename T>
652 static KOKKOS_FORCEINLINE_FUNCTION
659template <
typename Op,
typename EvalType>
661 void operator()(std::string
const& name, Teuchos::any&
result, std::vector<Teuchos::any>& rhs)
const {
662 auto& right = rhs.at(0);
663 using single_type =
typename EvalType::const_single_view_type;
664 using many_type =
typename EvalType::const_view_type;
665 if (right.type() ==
typeid(single_type)) {
667 }
else if (right.type() ==
typeid(many_type)) {
670 TEUCHOS_TEST_FOR_EXCEPTION(
true, Teuchos::ParserFail,
671 "Unexpected type " << right.typeName() <<
" passed to UnaryFunction \"" << name <<
"\"\n");
676template <
typename DT,
typename ... VP>
678 using eval_type =
Eval<DT, VP ...>;
Declares the panzer::Expr::Eval templated class.
PHX::MDField< ScalarT, panzer::Cell, panzer::IP > result
A field that will be used to build up the result of the integral we're performing.
Base class for panzer::Expr::Eval, does everything that is independent of the Kokkos::View template p...
std::function< void(std::string const &name, Teuchos::any &, std::vector< Teuchos::any > &rhs)> Function
The type of user-defined functions which are callable in the math language.
void set(std::string const &name, Function const &value)
Registers an EvalBase::Function, binding it to a name and making it callable.
Interprets mathematical expressions in a string and evaluates them using Kokkos::View objects as valu...
Kokkos::View< scalar_type, VP ... > single_view_type
One scalar (same for all evaluation points)
Kokkos::View< typename RebindDataType< view_data_type, bool const >::type, VP ... > const_bool_view_type
One boolean for each evaluation point, read-only.
typename original_view_type::non_const_value_type scalar_type
The scalar type.
Kokkos::View< bool const, VP ... > const_single_bool_view_type
One boolean (same for all evaluation points), read-only.
void many_many_binary_op(BinaryOpCode code, Teuchos::any &result, Teuchos::any &left, Teuchos::any &right) override
void single_single_ternary_op(Teuchos::any &result, Teuchos::any &cond, Teuchos::any &left, Teuchos::any &right) override
void many_neg_op(Teuchos::any &result, Teuchos::any &right) override
void make_constant(Teuchos::any &result, double const &value) override
void single_single_binary_op(BinaryOpCode code, Teuchos::any &result, Teuchos::any &left, Teuchos::any &right) override
void single_many_binary_op(BinaryOpCode code, Teuchos::any &result, Teuchos::any &left, Teuchos::any &right) override
void many_many_ternary_op(Teuchos::any &result, Teuchos::any &cond, Teuchos::any &left, Teuchos::any &right) override
void set(std::string const &name, bool value)
Assign a boolean value to a variable symbol.
void inspect_arg(Teuchos::any const &arg, bool &is_many, bool &is_bool) override
void many_single_ternary_op(Teuchos::any &result, Teuchos::any &cond, Teuchos::any &left, Teuchos::any &right) override
Kokkos::View< typename RebindDataType< view_data_type, scalar_type const >::type, VP ... > const_view_type
One scalar for each evaluation point, read-only.
void single_neg_op(Teuchos::any &result, Teuchos::any &right) override
Kokkos::View< scalar_type const, VP ... > const_single_view_type
One scalar (same for all evaluation points), read-only.
void single_many_ternary_op(Teuchos::any &result, Teuchos::any &cond, Teuchos::any &left, Teuchos::any &right) override
Kokkos::View< bool, VP ... > single_bool_view_type
One boolean (same for all evaluation points)
void many_single_binary_op(BinaryOpCode code, Teuchos::any &result, Teuchos::any &left, Teuchos::any &right) override
void set_cmath_functions(Eval< DT, VP ... > &eval)
Add support for functions such as sqrt(), sin(), and cos()
BinaryOpCode
Denotes the native binary operators in the Teuchos::MathExpr language.
typename Result::execution_space execution_space
typename RebindViewType< Result, typename Result::non_const_value_type >::type NonConstResult
BinaryFunctor(std::string const &name, Teuchos::any &result, Teuchos::any &left, Teuchos::any &right)
KOKKOS_INLINE_FUNCTION void operator()(typename execution_space::size_type) const
typename RebindViewType< Result, typename Result::non_const_value_type >::type NonConstResult
BinaryFunctor(std::string const &name, Teuchos::any &result, Teuchos::any &left, Teuchos::any &right)
KOKKOS_INLINE_FUNCTION void operator()(typename execution_space::size_type i) const
typename Result::execution_space execution_space
BinaryFunctor(std::string const &name, Teuchos::any &result, Teuchos::any &left, Teuchos::any &right)
typename Result::execution_space execution_space
typename RebindViewType< Result, typename Result::non_const_value_type >::type NonConstResult
KOKKOS_INLINE_FUNCTION void operator()(typename execution_space::size_type i, typename execution_space::size_type j) const
static KOKKOS_FORCEINLINE_FUNCTION ViewType::reference_type index(ViewType const &x, Integral)
static KOKKOS_FORCEINLINE_FUNCTION ViewType::reference_type index(ViewType const &x, Integral i)
static KOKKOS_FORCEINLINE_FUNCTION ViewType::reference_type index(ViewType const &x, Integral, Integral)
static KOKKOS_FORCEINLINE_FUNCTION ViewType::reference_type index(ViewType const &x, Integral i, Integral)
static KOKKOS_FORCEINLINE_FUNCTION ViewType::reference_type index(ViewType const &x, Integral i, Integral j)
static constexpr size_t right_value
static constexpr size_t value
static constexpr size_t left_value
Builds on RebindDataType, but acts directly on a Kokkos::View type.
typename RebindViewType< biggest_type, typename biggest_type::non_const_value_type >::type type
static constexpr size_t a_rank
typename std::conditional<(b_rank > a_rank), B, A >::type biggest_type
static constexpr size_t b_rank
typename RebindViewType< biggest_type, typename biggest_type::const_value_type >::type const_type
static KOKKOS_FORCEINLINE_FUNCTION T apply(T const &right)
static KOKKOS_FORCEINLINE_FUNCTION T apply(T const &left, T const &right)
static KOKKOS_FORCEINLINE_FUNCTION bool apply(bool left, bool right)
static KOKKOS_FORCEINLINE_FUNCTION T apply(T const &right)
static KOKKOS_FORCEINLINE_FUNCTION T apply(T const &left, T const &right)
static KOKKOS_FORCEINLINE_FUNCTION bool apply(T const &left, T const &right)
static KOKKOS_FORCEINLINE_FUNCTION T apply(T const &right)
static KOKKOS_FORCEINLINE_FUNCTION bool apply(T const &left, T const &right)
static KOKKOS_FORCEINLINE_FUNCTION bool apply(T const &left, T const &right)
static KOKKOS_FORCEINLINE_FUNCTION bool apply(T const &left, T const &right)
static KOKKOS_FORCEINLINE_FUNCTION bool apply(T const &left, T const &right)
static KOKKOS_FORCEINLINE_FUNCTION T apply(T const &right)
static KOKKOS_FORCEINLINE_FUNCTION T apply(T const &left, T const &right)
static KOKKOS_FORCEINLINE_FUNCTION T apply(T const &right)
static KOKKOS_FORCEINLINE_FUNCTION bool apply(bool left, bool right)
static KOKKOS_FORCEINLINE_FUNCTION T apply(T const &left, T const &right)
static KOKKOS_FORCEINLINE_FUNCTION T apply(T const &right)
static KOKKOS_FORCEINLINE_FUNCTION T apply(T const &right)
static KOKKOS_FORCEINLINE_FUNCTION T apply(T const &left, T const &right)
static KOKKOS_FORCEINLINE_FUNCTION T apply(T const &right)
static KOKKOS_FORCEINLINE_FUNCTION T apply(bool cond, T const &left, T const &right)
typename Result::execution_space execution_space
KOKKOS_INLINE_FUNCTION void operator()(typename execution_space::size_type i) const
typename TernaryResultType< Cond, Left, Right >::type Result
TernaryFunctor(std::string const &name, Teuchos::any &result, Teuchos::any &cond, Teuchos::any &left, Teuchos::any &right)
typename TernaryResultType< Cond, Left, Right >::non_const_type NonConstResult
TernaryFunctor(std::string const &name, Teuchos::any &result, Teuchos::any &cond, Teuchos::any &left, Teuchos::any &right)
typename TernaryResultType< Cond, Left, Right >::type Result
typename TernaryResultType< Cond, Left, Right >::non_const_type NonConstResult
KOKKOS_INLINE_FUNCTION void operator()(typename execution_space::size_type i, typename execution_space::size_type j) const
typename Result::execution_space execution_space
typename std::conditional<(b_rank > a_rank), B, A >::type biggest_ab_type
static constexpr size_t a_rank
static constexpr size_t c_rank
typename RebindViewType< biggest_type, typename A::const_value_type >::type type
static constexpr size_t b_rank
typename std::conditional<(c_rank > biggest_ab_type::rank), C, biggest_ab_type >::type biggest_type
typename RebindViewType< biggest_type, typename A::non_const_value_type >::type non_const_type
void operator()(std::string const &name, Teuchos::any &result, std::vector< Teuchos::any > &rhs) const
typename RebindViewType< Result, typename Result::non_const_value_type >::type NonConstResult
UnaryFunctor(std::string const &name, Teuchos::any &result, Teuchos::any &right)
typename Result::execution_space execution_space
KOKKOS_INLINE_FUNCTION void operator()(typename execution_space::size_type i) const
typename RebindViewType< Result, typename Result::non_const_value_type >::type NonConstResult
typename Result::execution_space execution_space
UnaryFunctor(std::string const &name, Teuchos::any &result, Teuchos::any &right)
KOKKOS_INLINE_FUNCTION void operator()(typename execution_space::size_type i) const
KOKKOS_INLINE_FUNCTION void operator()(typename execution_space::size_type i, typename execution_space::size_type j) const
typename RebindViewType< Result, typename Result::non_const_value_type >::type NonConstResult
typename Result::execution_space execution_space
UnaryFunctor(std::string const &name, Teuchos::any &result, Teuchos::any &right)