43 #ifndef PANZER_SUM_IMPL_HPP
44 #define PANZER_SUM_IMPL_HPP
53 template<
typename EvalT,
typename Traits>
58 std::string sum_name = p.
get<std::string>(
"Sum Name");
64 TEUCHOS_ASSERT(static_cast<int>(value_names->size()) < MAX_VALUES);
67 auto local_scalars = Kokkos::View<double *,typename PHX::DevLayout<double>::type,PHX::Device>(
"scalars",value_names->size());
74 for (std::size_t i=0; i < value_names->size(); ++i)
75 local_scalars(i) = scalars_v[i];
78 for (std::size_t i=0; i < value_names->size(); ++i)
79 local_scalars(i) = 1.0;
82 scalars = local_scalars;
84 sum = PHX::MDField<ScalarT>(sum_name, data_layout);
86 this->addEvaluatedField(sum);
88 for (std::size_t i=0; i < value_names->size(); ++i) {
89 values[i] = PHX::MDField<const ScalarT>( (*value_names)[i], data_layout);
90 this->addDependentField(values[i]);
100 std::string n =
"Sum Evaluator";
105 template<
typename EvalT,
typename Traits>
112 cell_data_size = sum.size() / sum.fieldTag().dataLayout().extent(0);
117 template<
typename EvalT,
typename TRAITS>
118 template<
unsigned int RANK>
119 KOKKOS_INLINE_FUNCTION
121 auto num_vals = scalars.extent(0);
126 for (std::size_t iv = 0; iv < num_vals; ++iv)
127 sum(i) += scalars(iv)*(values[iv](i));
131 const size_t dim_1 = sum.extent(1);
132 for (std::size_t j = 0; j < dim_1; ++j)
133 for (std::size_t iv = 0; iv < num_vals; ++iv)
134 sum(i,j) += scalars(iv)*(values[iv](i,j));
138 const size_t dim_1 = sum.extent(1),dim_2 = sum.extent(2);
139 for (std::size_t j = 0; j < dim_1; ++j)
140 for (std::size_t k = 0; k < dim_2; ++k)
141 for (std::size_t iv = 0; iv < num_vals; ++iv)
142 sum(i,j,k) += scalars(iv)*(values[iv](i,j,k));
146 const size_t dim_1 = sum.extent(1),dim_2 = sum.extent(2),dim_3 = sum.extent(3);
147 for (std::size_t j = 0; j < dim_1; ++j)
148 for (std::size_t k = 0; k < dim_2; ++k)
149 for (std::size_t l = 0; l < dim_3; ++l)
150 for (std::size_t iv = 0; iv < num_vals; ++iv)
151 sum(i,j,k,l) += scalars(iv)*(values[iv](i,j,k,l));
155 const size_t dim_1 = sum.extent(1),dim_2 = sum.extent(2),dim_3 = sum.extent(3),dim_4 = sum.extent(4);
156 for (std::size_t j = 0; j < dim_1; ++j)
157 for (std::size_t k = 0; k < dim_2; ++k)
158 for (std::size_t l = 0; l < dim_3; ++l)
159 for (std::size_t m = 0; m < dim_4; ++m)
160 for (std::size_t iv = 0; iv < num_vals; ++iv)
161 sum(i,j,k,l,m) += scalars(iv)*(values[iv](i,j,k,l,m));
165 const size_t dim_1 = sum.extent(1),dim_2 = sum.extent(2),dim_3 = sum.extent(3),dim_4 = sum.extent(4),dim_5 = sum.extent(5);
166 for (std::size_t j = 0; j < dim_1; ++j)
167 for (std::size_t k = 0; k < dim_2; ++k)
168 for (std::size_t l = 0; l < dim_3; ++l)
169 for (std::size_t m = 0; m < dim_4; ++m)
170 for (std::size_t n = 0; n < dim_5; ++n)
171 for (std::size_t iv = 0; iv < num_vals; ++iv)
172 sum(i,j,k,l,m,n) += scalars(iv)*(values[iv](i,j,k,l,m,n));
177 template<
typename EvalT,
typename Traits>
186 size_t rank = sum.rank();
187 const size_t length = sum.extent(0);
190 Kokkos::parallel_for(Kokkos::RangePolicy<
PanzerSumTag<1> >(0, length), *
this);
194 Kokkos::parallel_for(Kokkos::RangePolicy<
PanzerSumTag<2> >(0, length), *
this);
198 Kokkos::parallel_for(Kokkos::RangePolicy<
PanzerSumTag<3> >(0, length), *
this);
202 Kokkos::parallel_for(Kokkos::RangePolicy<
PanzerSumTag<4> >(0, length), *
this);
206 Kokkos::parallel_for(Kokkos::RangePolicy<
PanzerSumTag<5> >(0, length), *
this);
210 Kokkos::parallel_for(Kokkos::RangePolicy<
PanzerSumTag<6> >(0, length), *
this);
221 template<
typename EvalT,
typename TRAITS,
typename Tag0>
225 std::string sum_name = p.
get<std::string>(
"Sum Name");
234 sum = PHX::MDField<ScalarT,Tag0>(sum_name, data_layout);
236 this->addEvaluatedField(sum);
238 values.resize(value_names->size());
239 for (std::size_t i=0; i < value_names->size(); ++i) {
240 values[i] = PHX::MDField<const ScalarT,Tag0>( (*value_names)[i], data_layout);
241 this->addDependentField(values[i]);
244 std::string n =
"SumStatic Rank 1 Evaluator";
250 template<
typename EvalT,
typename TRAITS,
typename Tag0>
255 for (std::size_t i = 0; i < sum.extent(0); ++i)
256 for (std::size_t d = 0; d < values.size(); ++d)
257 sum(i) += (values[d])(i);
263 template<
typename EvalT,
typename TRAITS,
typename Tag0,
typename Tag1>
267 std::string sum_name = p.
get<std::string>(
"Sum Name");
282 Kokkos::View<double*,typename PHX::DevLayout<double>::type,PHX::Device> scalars_nc
283 = Kokkos::View<double*,typename PHX::DevLayout<double>::type,PHX::Device>(
"scalars",scalar_values->size());
285 for(std::size_t i=0;i<scalar_values->size();i++)
286 scalars_nc(i) = (*scalar_values)[i];
288 scalars = scalars_nc;
297 sum = PHX::MDField<ScalarT,Tag0,Tag1>(sum_name, data_layout);
299 this->addEvaluatedField(sum);
301 values.resize(value_names->size());
302 for (std::size_t i=0; i < value_names->size(); ++i) {
303 values[i] = PHX::MDField<const ScalarT,Tag0,Tag1>( (*value_names)[i], data_layout);
304 this->addDependentField(values[i]);
306 numValues = value_names->size();
309 std::string n =
"SumStatic Rank 2 Evaluator";
315 template<
typename EvalT,
typename TRAITS,
typename Tag0,
typename Tag1>
317 SumStatic(
const std::vector<PHX::Tag<typename EvalT::ScalarT>> & inputs,
318 const std::vector<double> & scalar_values,
319 const PHX::Tag<typename EvalT::ScalarT> & output)
324 if(scalars.size()==0) {
330 Kokkos::View<double*,typename PHX::DevLayout<double>::type,PHX::Device> scalars_nc
331 = Kokkos::View<double*,typename PHX::DevLayout<double>::type,PHX::Device>(
"scalars",scalar_values.size());
333 for(std::size_t i=0;i<scalar_values.size();i++)
334 scalars_nc(i) = scalar_values[i];
336 scalars = scalars_nc;
343 this->addEvaluatedField(sum);
345 values.resize(inputs.size());
346 for (std::size_t i=0; i < inputs.size(); ++i) {
347 values[i] = inputs[i];
348 this->addDependentField(values[i]);
351 numValues = inputs.size();
353 std::string n =
"SumStatic Rank 2 Evaluator";
359 template<
typename EvalT,
typename TRAITS,
typename Tag0,
typename Tag1>
364 for (std::size_t i=0; i < values.size(); ++i)
365 value_views[i] = values[i].get_static_view();
370 template<
typename EvalT,
typename TRAITS,
typename Tag0,
typename Tag1>
378 Kokkos::parallel_for(Kokkos::RangePolicy<PHX::Device,ScalarsTag>(0,sum.extent(0)), *
this);
380 Kokkos::parallel_for(Kokkos::RangePolicy<PHX::Device,NoScalarsTag>(0,sum.extent(0)), *
this);
385 template<
typename EvalT,
typename TRAITS,
typename Tag0,
typename Tag1>
386 KOKKOS_INLINE_FUNCTION
390 for (
int i=0;i<numValues;i++) {
391 for (
int j = 0; j < sum.extent_int(1); ++j)
392 sum(c,j) += scalars(i)*value_views[i](c,j);
398 template<
typename EvalT,
typename TRAITS,
typename Tag0,
typename Tag1>
399 KOKKOS_INLINE_FUNCTION
403 for (
int i=0;i<numValues;i++) {
404 for (
int j = 0; j < sum.extent_int(1); ++j)
405 sum(c,j) += value_views[i](c,j);
462 template<
typename EvalT,
typename TRAITS,
typename Tag0,
typename Tag1,
typename Tag2>
465 const std::vector<std::string> & value_names,
469 p.
set<std::string>(
"Sum Name",sum_name);
Teuchos::RCP< PHX::Evaluator< TRAITS > > buildStaticSumEvaluator(const std::string &sum_name, const std::vector< std::string > &value_names, const Teuchos::RCP< PHX::DataLayout > &data_layout)
Sum(const Teuchos::ParameterList &p)
T & get(const std::string &name, T def_value)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void postRegistrationSetup(typename Traits::SetupData d, PHX::FieldManager< Traits > &fm)
KOKKOS_INLINE_FUNCTION void operator()(PanzerSumTag< RANK >, const int &i) const
SumStatic(const Teuchos::ParameterList &p)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void evaluateFields(typename Traits::EvalData d)
typename EvalT::ScalarT ScalarT
bool isType(const std::string &name) const
void evaluateFields(typename TRAITS::EvalData d)
#define TEUCHOS_ASSERT(assertion_test)