11 #ifndef PANZER_SUM_IMPL_HPP
12 #define PANZER_SUM_IMPL_HPP
21 template<
typename EvalT,
typename Traits>
26 std::string sum_name = p.
get<std::string>(
"Sum Name");
32 TEUCHOS_ASSERT(static_cast<int>(value_names->size()) < MAX_VALUES);
35 auto local_scalars = PHX::View<double *>(
"scalars",value_names->size());
36 auto local_scalars_host = Kokkos::create_mirror_view(local_scalars);
43 for (std::size_t i=0; i < value_names->size(); ++i)
44 local_scalars_host(i) = scalars_v[i];
47 for (std::size_t i=0; i < value_names->size(); ++i)
48 local_scalars_host(i) = 1.0;
50 Kokkos::deep_copy(local_scalars,local_scalars_host);
52 scalars = local_scalars;
56 this->addEvaluatedField(sum);
58 for (std::size_t i=0; i < value_names->size(); ++i) {
60 this->addDependentField(values[i]);
70 std::string n =
"Sum Evaluator";
75 template<
typename EvalT,
typename Traits>
82 cell_data_size = sum.size() / sum.fieldTag().dataLayout().extent(0);
87 template<
typename EvalT,
typename TRAITS>
88 template<
unsigned int RANK>
89 KOKKOS_INLINE_FUNCTION
91 auto num_vals = scalars.extent(0);
96 for (std::size_t iv = 0; iv < num_vals; ++iv)
97 sum(i) += scalars(iv)*(values[iv](i));
101 const size_t dim_1 = sum.extent(1);
102 for (std::size_t j = 0; j < dim_1; ++j)
103 for (std::size_t iv = 0; iv < num_vals; ++iv)
104 sum(i,j) += scalars(iv)*(values[iv](i,j));
108 const size_t dim_1 = sum.extent(1),dim_2 = sum.extent(2);
109 for (std::size_t j = 0; j < dim_1; ++j)
110 for (std::size_t k = 0; k < dim_2; ++k)
111 for (std::size_t iv = 0; iv < num_vals; ++iv)
112 sum(i,j,k) += scalars(iv)*(values[iv](i,j,k));
116 const size_t dim_1 = sum.extent(1),dim_2 = sum.extent(2),dim_3 = sum.extent(3);
117 for (std::size_t j = 0; j < dim_1; ++j)
118 for (std::size_t k = 0; k < dim_2; ++k)
119 for (std::size_t l = 0; l < dim_3; ++l)
120 for (std::size_t iv = 0; iv < num_vals; ++iv)
121 sum(i,j,k,l) += scalars(iv)*(values[iv](i,j,k,l));
125 const size_t dim_1 = sum.extent(1),dim_2 = sum.extent(2),dim_3 = sum.extent(3),dim_4 = sum.extent(4);
126 for (std::size_t j = 0; j < dim_1; ++j)
127 for (std::size_t k = 0; k < dim_2; ++k)
128 for (std::size_t l = 0; l < dim_3; ++l)
129 for (std::size_t m = 0; m < dim_4; ++m)
130 for (std::size_t iv = 0; iv < num_vals; ++iv)
131 sum(i,j,k,l,m) += scalars(iv)*(values[iv](i,j,k,l,m));
135 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);
136 for (std::size_t j = 0; j < dim_1; ++j)
137 for (std::size_t k = 0; k < dim_2; ++k)
138 for (std::size_t l = 0; l < dim_3; ++l)
139 for (std::size_t m = 0; m < dim_4; ++m)
140 for (std::size_t n = 0; n < dim_5; ++n)
141 for (std::size_t iv = 0; iv < num_vals; ++iv)
142 sum(i,j,k,l,m,n) += scalars(iv)*(values[iv](i,j,k,l,m,n));
147 template<
typename EvalT,
typename Traits>
156 size_t rank = sum.rank();
157 const size_t length = sum.extent(0);
160 Kokkos::parallel_for(Kokkos::RangePolicy<
PanzerSumTag<1> >(0, length), *
this);
164 Kokkos::parallel_for(Kokkos::RangePolicy<
PanzerSumTag<2> >(0, length), *
this);
168 Kokkos::parallel_for(Kokkos::RangePolicy<
PanzerSumTag<3> >(0, length), *
this);
172 Kokkos::parallel_for(Kokkos::RangePolicy<
PanzerSumTag<4> >(0, length), *
this);
176 Kokkos::parallel_for(Kokkos::RangePolicy<
PanzerSumTag<5> >(0, length), *
this);
180 Kokkos::parallel_for(Kokkos::RangePolicy<
PanzerSumTag<6> >(0, length), *
this);
195 template<
typename EvalT,
typename TRAITS,
typename Tag0>
199 std::string sum_name = p.
get<std::string>(
"Sum Name");
210 this->addEvaluatedField(sum);
212 values.resize(value_names->size());
213 for (std::size_t i=0; i < value_names->size(); ++i) {
215 this->addDependentField(values[i]);
218 std::string n =
"SumStatic Rank 1 Evaluator";
224 template<
typename EvalT,
typename TRAITS,
typename Tag0>
229 for (std::size_t i = 0; i < sum.extent(0); ++i)
230 for (std::size_t d = 0; d < values.size(); ++d)
231 sum(i) += (values[d])(i);
237 template<
typename EvalT,
typename TRAITS,
typename Tag0,
typename Tag1>
241 std::string sum_name = p.
get<std::string>(
"Sum Name");
256 PHX::View<double*> scalars_nc = PHX::View<double*>(
"scalars",scalar_values->size());
258 for(std::size_t i=0;i<scalar_values->size();i++)
259 scalars_nc(i) = (*scalar_values)[i];
261 scalars = scalars_nc;
272 this->addEvaluatedField(sum);
274 values.resize(value_names->size());
275 for (std::size_t i=0; i < value_names->size(); ++i) {
277 this->addDependentField(values[i]);
279 numValues = value_names->size();
282 std::string n =
"SumStatic Rank 2 Evaluator";
288 template<
typename EvalT,
typename TRAITS,
typename Tag0,
typename Tag1>
291 const std::vector<double> & scalar_values,
297 if(scalars.size()==0) {
303 PHX::View<double*> scalars_nc = PHX::View<double*>(
"scalars",scalar_values.size());
305 for(std::size_t i=0;i<scalar_values.size();i++)
306 scalars_nc(i) = scalar_values[i];
308 scalars = scalars_nc;
315 this->addEvaluatedField(sum);
317 values.resize(inputs.size());
318 for (std::size_t i=0; i < inputs.size(); ++i) {
319 values[i] = inputs[i];
320 this->addDependentField(values[i]);
323 numValues = inputs.size();
325 std::string n =
"SumStatic Rank 2 Evaluator";
331 template<
typename EvalT,
typename TRAITS,
typename Tag0,
typename Tag1>
336 for (std::size_t i=0; i < values.size(); ++i)
337 value_views[i] = values[i].get_static_view();
342 template<
typename EvalT,
typename TRAITS,
typename Tag0,
typename Tag1>
350 Kokkos::parallel_for(Kokkos::RangePolicy<PHX::Device,ScalarsTag>(0,sum.extent(0)), *
this);
352 Kokkos::parallel_for(Kokkos::RangePolicy<PHX::Device,NoScalarsTag>(0,sum.extent(0)), *
this);
357 template<
typename EvalT,
typename TRAITS,
typename Tag0,
typename Tag1>
358 KOKKOS_INLINE_FUNCTION
362 for (
int i=0;i<numValues;i++) {
363 for (
int j = 0; j < sum.extent_int(1); ++j)
364 sum(c,j) += scalars(i)*value_views[i](c,j);
370 template<
typename EvalT,
typename TRAITS,
typename Tag0,
typename Tag1>
371 KOKKOS_INLINE_FUNCTION
375 for (
int i=0;i<numValues;i++) {
376 for (
int j = 0; j < sum.extent_int(1); ++j)
377 sum(c,j) += value_views[i](c,j);
434 template<
typename EvalT,
typename TRAITS,
typename Tag0,
typename Tag1,
typename Tag2>
437 const std::vector<std::string> & value_names,
441 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)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void postRegistrationSetup(typename Traits::SetupData d, PHX::FieldManager< Traits > &fm)
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
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)
virtual void postRegistrationSetup(typename Traits::SetupData d, PHX::FieldManager< Traits > &vm)=0
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)