Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_Product_impl.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Panzer: A partial differential equation assembly
5 // engine for strongly coupled complex multiphysics systems
6 // Copyright (2011) Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Roger P. Pawlowski (rppawlo@sandia.gov) and
39 // Eric C. Cyr (eccyr@sandia.gov)
40 // ***********************************************************************
41 // @HEADER
42 
43 #ifndef PANZER_PRODUCT_IMPL_HPP
44 #define PANZER_PRODUCT_IMPL_HPP
45 
46 #include <cstddef>
47 #include <string>
48 #include <vector>
49 
50 namespace panzer {
51 
52 //**********************************************************************
53 template<typename EvalT, typename Traits>
56  const Teuchos::ParameterList& p)
57  : scaling(1.0)
58 {
59  std::string product_name = p.get<std::string>("Product Name");
61  p.get<Teuchos::RCP<std::vector<std::string> > >("Values Names");
62  Teuchos::RCP<PHX::DataLayout> data_layout =
63  p.get< Teuchos::RCP<PHX::DataLayout> >("Data Layout");
64 
65  if(p.isType<double>("Scaling"))
66  scaling = p.get<double>("Scaling");
67 
68  product = PHX::MDField<ScalarT>(product_name, data_layout);
69 
70  this->addEvaluatedField(product);
71 
72  values.resize(value_names->size());
73  for (std::size_t i=0; i < value_names->size(); ++i) {
74  values[i] = PHX::MDField<const ScalarT>( (*value_names)[i], data_layout);
75  this->addDependentField(values[i]);
76  }
77 
78  std::string n = "Product Evaluator";
79  this->setName(n);
80 }
81 
82 
83 template<int RANK, typename Scalar>
85 
86  const PHX::MDField<Scalar> base_;
87  const PHX::MDField<const Scalar> source_;
88 
89  V_MultiplyFunctor(PHX::MDField<Scalar>& base, const PHX::MDField<const Scalar>& source)
90  : base_(base),source_(source) {}
91 
92  KOKKOS_INLINE_FUNCTION
93  void operator() (const PHX::index_t & ind1) const
94  {
95  using idx_t = PHX::index_t;
96 
97  if (RANK == 1){
98  base_(ind1) = base_(ind1)*source_(ind1);
99  }
100  else if (RANK == 2){
101  for (idx_t ind2=0; ind2 < static_cast<idx_t>(base_.extent(1)); ind2++)
102  base_(ind1,ind2) = base_(ind1,ind2)*source_(ind1,ind2);
103  }
104  else if (RANK == 3){
105  for (idx_t ind2=0; ind2 < static_cast<idx_t>(base_.extent(1)); ind2++)
106  for (idx_t ind3=0; ind3 < static_cast<idx_t>(base_.extent(2)); ind3++)
107  base_(ind1,ind2,ind3) = base_(ind1,ind2,ind3)*source_(ind1,ind2,ind3);
108  }
109  else if (RANK == 4){
110  for (idx_t ind2=0; ind2 < static_cast<idx_t>(base_.extent(1)); ind2++)
111  for (idx_t ind3=0; ind3 < static_cast<idx_t>(base_.extent(2)); ind3++)
112  for (idx_t ind4=0; ind4 < static_cast<idx_t>(base_.extent(3)); ind4++)
113  base_(ind1,ind2,ind3,ind4) = base_(ind1,ind2,ind3,ind4)*source_(ind1,ind2,ind3,ind4);
114  }
115  else if (RANK == 5){
116  for (idx_t ind2=0; ind2 < static_cast<idx_t>(base_.extent(1)); ind2++)
117  for (idx_t ind3=0; ind3 < static_cast<idx_t>(base_.extent(2)); ind3++)
118  for (idx_t ind4=0; ind4 < static_cast<idx_t>(base_.extent(3)); ind4++)
119  for (idx_t ind5=0; ind5 < static_cast<idx_t>(base_.extent(4)); ind5++)
120  base_(ind1,ind2,ind3,ind4,ind5) = base_(ind1,ind2,ind3,ind4,ind5)*source_(ind1,ind2,ind3,ind4,ind5);
121  }
122  else if (RANK == 6){
123  for (idx_t ind2=0; ind2 < static_cast<idx_t>(base_.extent(1)); ind2++)
124  for (idx_t ind3=0; ind3 < static_cast<idx_t>(base_.extent(2)); ind3++)
125  for (idx_t ind4=0; ind4 < static_cast<idx_t>(base_.extent(3)); ind4++)
126  for (idx_t ind5=0; ind5 < static_cast<idx_t>(base_.extent(4)); ind5++)
127  for (idx_t ind6=0; ind6 < static_cast<idx_t>(base_.extent(5)); ind6++)
128  base_(ind1,ind2,ind3,ind4,ind5,ind6) = base_(ind1,ind2,ind3,ind4,ind5,ind6)*source_(ind1,ind2,ind3,ind4,ind5,ind6);
129  }
130  else if (RANK == 7){
131  for (idx_t ind2=0; ind2 < static_cast<idx_t>(base_.extent(1)); ind2++)
132  for (idx_t ind3=0; ind3 < static_cast<idx_t>(base_.extent(2)); ind3++)
133  for (idx_t ind4=0; ind4 < static_cast<idx_t>(base_.extent(3)); ind4++)
134  for (idx_t ind5=0; ind5 < static_cast<idx_t>(base_.extent(4)); ind5++)
135  for (idx_t ind6=0; ind6 < static_cast<idx_t>(base_.extent(5)); ind6++)
136  for (idx_t ind7=0; ind7 < static_cast<idx_t>(base_.extent(6)); ind7++)
137  base_(ind1,ind2,ind3,ind4,ind5,ind6,ind7) = base_(ind1,ind2,ind3,ind4,ind5,ind6,ind7)*source_(ind1,ind2,ind3,ind4,ind5,ind6,ind7);
138  }
139  }
140 };
141 
142 //**********************************************************************
143 template<typename EvalT, typename Traits>
144 void
147  typename Traits::EvalData /* workset */)
148 {
149  product.deep_copy(ScalarT(scaling));
150 
151  for (std::size_t i = 0; i < values.size(); ++i) {
152  const auto length = product.extent(0);
153  if (product.rank() == 1){
154  Kokkos::parallel_for( length, V_MultiplyFunctor<1,ScalarT>(product,values[i]) );
155  }
156  else if (product.rank() == 2){
157  Kokkos::parallel_for( length, V_MultiplyFunctor<2,ScalarT>(product,values[i]) );
158  }
159  else if (product.rank() == 3){
160  Kokkos::parallel_for( length, V_MultiplyFunctor<3,ScalarT>(product,values[i]) );
161  }
162  else if (product.rank() == 4){
163  Kokkos::parallel_for( length, V_MultiplyFunctor<4,ScalarT>(product,values[i]) );
164  }
165  else if (product.rank() == 5){
166  Kokkos::parallel_for( length, V_MultiplyFunctor<5,ScalarT>(product,values[i]) );
167  }
168  else if (product.rank() == 6){
169  Kokkos::parallel_for( length, V_MultiplyFunctor<6,ScalarT>(product,values[i]) );
170  }
171  else if (product.rank() == 7){
172  Kokkos::parallel_for( length, V_MultiplyFunctor<7,ScalarT>(product,values[i]) );
173  }
174  }
175 }
176 
177 //**********************************************************************
178 
179 }
180 
181 #endif
KOKKOS_INLINE_FUNCTION void operator()(const PHX::index_t &ind1) const
T & get(const std::string &name, T def_value)
const PHX::MDField< Scalar > base_
Product(const Teuchos::ParameterList &p)
V_MultiplyFunctor(PHX::MDField< Scalar > &base, const PHX::MDField< const Scalar > &source)
const PHX::MDField< const Scalar > source_
PHX::MDField< ScalarT > product
bool isType(const std::string &name) const
std::vector< PHX::MDField< const ScalarT > > values
typename EvalT::ScalarT ScalarT
void evaluateFields(typename Traits::EvalData d)