43#ifndef RTOPPACK_RTOP_T_HELPERS_DEF_HPP
44#define RTOPPACK_RTOP_T_HELPERS_DEF_HPP
47#include "RTOpPack_RTOpTHelpers_decl.hpp"
58template<
class ConcreteReductObj>
61 std::ostringstream oss;
63 <<
"RTOpPack::DefaultReductTarget<"
64 <<TypeNameTraits<ConcreteReductObj>::name()<<
">"
65 <<
"{concreteReductObj="<<concreteReductObj_<<
"}";
74void RTOpPack::validate_apply_op(
75 const RTOpT<Scalar> &op,
76 const int allowed_num_sub_vecs,
77 const int allowed_num_targ_sub_vecs,
78 const bool expect_reduct_obj,
79 const ArrayView<
const ConstSubVectorView<Scalar> > &sub_vecs,
80 const ArrayView<
const SubVectorView<Scalar> > &targ_sub_vecs,
81 const Ptr<const ReductTarget> &reduct_obj
87 const int num_sub_vecs = sub_vecs.size();
88 const int num_targ_sub_vecs = targ_sub_vecs.size();
90 const std::string op_name_str =
"op.name() = " + op.op_name();
92 if (allowed_num_sub_vecs >= 0) {
93 TEUCHOS_TEST_FOR_EXCEPTION( allowed_num_sub_vecs != as<int>(sub_vecs.size()),
95 op_name_str<<
": Error, sub_vecs.size()="<<sub_vecs.size()
96 <<
" != allowed_num_sub_vecs="<<allowed_num_sub_vecs<<
"!" );
99 if (allowed_num_targ_sub_vecs >= 0) {
100 TEUCHOS_TEST_FOR_EXCEPTION( allowed_num_targ_sub_vecs != as<int>(targ_sub_vecs.size()),
102 op_name_str<<
": Error, targ_sub_vecs.size()="<<targ_sub_vecs.size()
103 <<
" != allowed_num_targ_sub_vecs="<<allowed_num_targ_sub_vecs<<
"!" );
106 TEUCHOS_TEST_FOR_EXCEPTION( sub_vecs.size() == 0 && targ_sub_vecs.size() == 0,
108 op_name_str<<
": Error, apply_op(...) must be passed some vectors!"
111 const index_type subDim =
112 (sub_vecs.size() ? sub_vecs[0].subDim() : targ_sub_vecs[0].subDim());
114 const index_type globalOffset =
115 (sub_vecs.size() ? sub_vecs[0].globalOffset() : targ_sub_vecs[0].globalOffset());
117 for (
int k = 0; k < num_sub_vecs; ++k ) {
118 TEUCHOS_TEST_FOR_EXCEPTION(
119 sub_vecs[k].subDim() != subDim || sub_vecs[k].globalOffset() != globalOffset,
121 op_name_str<<
": Error, sub_vec["<<k<<
"] "
122 "(subDim="<<sub_vecs[k].subDim()<<
",globalOffset="<<sub_vecs[k].globalOffset()<<
")"
123 " is not compatible with (subDim="<<subDim<<
",globalOffset="<<globalOffset<<
")!"
127 for (
int k = 0; k < num_targ_sub_vecs; ++k ) {
128 TEUCHOS_TEST_FOR_EXCEPTION(
129 targ_sub_vecs[k].subDim() != subDim || targ_sub_vecs[k].globalOffset() != globalOffset,
131 op_name_str<<
": Error, sub_vec["<<k<<
"] "
132 "(subDim="<<targ_sub_vecs[k].subDim()<<
",globalOffset="<<targ_sub_vecs[k].globalOffset()<<
")"
133 " is not compatible with (subDim="<<subDim<<
",globalOffset="<<globalOffset<<
")!"
137 if (expect_reduct_obj) {
139 TEUCHOS_TEST_FOR_EXCEPTION( is_null(reduct_obj),
140 IncompatibleReductObj,
141 op_name_str<<
": Error, expected a reduction target object!"
144 const RCP<ReductTarget> dummy_reduct_obj = op.reduct_obj_create();
154 const ReductTarget& reduct_obj_thing = *reduct_obj;
155 const std::type_info& reduct_obj_type =
typeid (reduct_obj_thing);
156 ReductTarget& dummy_reduct_obj_thing = *dummy_reduct_obj;
157 const std::type_info& dummy_reduct_obj_type =
typeid (dummy_reduct_obj_thing);
159 TEUCHOS_TEST_FOR_EXCEPTION( reduct_obj_type != dummy_reduct_obj_type,
160 IncompatibleReductObj,
161 op_name_str<<
": Error, the type of the input reduct_obj = "
162 <<Teuchos::demangleName(reduct_obj_type.name())<<
" is not equal to"
163 " the expected type "<<Teuchos::demangleName(dummy_reduct_obj_type.name())
178#define RTOPPACK_RTOPT_HELPERS_DEFAULTREDUCTTARGET_INSTANT(SCALAR) \
180 template std::string DefaultReductTarget<SCALAR >::description() const;
183#define RTOPPACK_RTOPT_HELPERS_INSTANT_SCALAR(SCALAR) \
185 RTOPPACK_RTOPT_HELPERS_DEFAULTREDUCTTARGET_INSTANT(SCALAR) \
187 RTOPPACK_RTOPT_HELPERS_DEFAULTREDUCTTARGET_INSTANT(ScalarIndex<SCALAR >) \
189 RTOPPACK_RTOPT_HELPERS_DEFAULTREDUCTTARGET_INSTANT(SubVectorView<SCALAR >) \
191 template void validate_apply_op<SCALAR >( \
192 const RTOpT<SCALAR > &op, \
193 const int allowed_num_sub_vecs, \
194 const int allowed_num_targ_sub_vecs, \
195 const bool expect_reduct_obj, \
196 const ArrayView<const ConstSubVectorView<SCALAR > > &sub_vecs, \
197 const ArrayView<const SubVectorView<SCALAR > > &targ_sub_vecs, \
198 const Ptr<const ReductTarget> &reduct_obj \
std::string description() const