Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_Sum.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_EVALUATOR_SUM_HPP
44 #define PANZER_EVALUATOR_SUM_HPP
45 
46 #include "Phalanx_Evaluator_Macros.hpp"
47 #include "Phalanx_MDField.hpp"
48 
50 
52 
53 namespace panzer {
54 
66 template<typename EvalT, typename Traits>
67 class Sum
68  :
69  public panzer::EvaluatorWithBaseImpl<Traits>,
70  public PHX::EvaluatorDerived<EvalT, Traits>
71 {
72  public:
73 
74  Sum(
75  const Teuchos::ParameterList& p);
76 
77  void
79  typename Traits::SetupData d,
81 
82  void
84  typename Traits::EvalData d);
85 
86  private:
87 
88  using ScalarT = typename EvalT::ScalarT;
89  static const int MAX_VALUES=20;
90 
91  PHX::MDField<ScalarT> sum;
92  // std::vector< PHX::MDField<const ScalarT> > values;
93  // std::vector<double> scalars;
94  PHX::MDField<const ScalarT> values[MAX_VALUES];
95  Kokkos::View<const double *,typename PHX::DevLayout<double>::type,PHX::Device> scalars;
96 
97  std::size_t cell_data_size;
98 
99 public:
100  template<unsigned int RANK>
101  struct PanzerSumTag{};
102 
103  template<unsigned int RANK>
104  KOKKOS_INLINE_FUNCTION
105  void operator() (PanzerSumTag<RANK>, const int &i) const;
106 
107 }; // end of class Sum
108 
109 
113 template<typename EvalT, typename TRAITS,typename Tag0,typename Tag1=void,typename Tag2=void>
115  public PHX::EvaluatorDerived<EvalT, TRAITS> {
116 public:
118  void evaluateFields(typename TRAITS::EvalData d);
119 private:
120  typedef typename EvalT::ScalarT ScalarT;
121 };
122 
123 template<typename EvalT, typename TRAITS,typename Tag0>
124 class SumStatic<EvalT,TRAITS,Tag0,void,void> : public panzer::EvaluatorWithBaseImpl<TRAITS>,
125  public PHX::EvaluatorDerived<EvalT, TRAITS> {
126 public:
128  void evaluateFields(typename TRAITS::EvalData d);
129 private:
130  typedef typename EvalT::ScalarT ScalarT;
131 
132  PHX::MDField<ScalarT,Tag0> sum;
133  std::vector< PHX::MDField<const ScalarT,Tag0> > values;
134 };
135 
136 template<typename EvalT, typename TRAITS,typename Tag0,typename Tag1>
137 class SumStatic<EvalT,TRAITS,Tag0,Tag1,void> : public panzer::EvaluatorWithBaseImpl<TRAITS>,
138  public PHX::EvaluatorDerived<EvalT, TRAITS> {
139 public:
141 
152  SumStatic(const std::vector<PHX::Tag<typename EvalT::ScalarT>> & inputs,
153  const std::vector<double> & scalar_values,
154  const PHX::Tag<typename EvalT::ScalarT> & output);
155  void postRegistrationSetup(typename TRAITS::SetupData d,
157  void evaluateFields(typename TRAITS::EvalData d);
158 
159  struct ScalarsTag {};
160  KOKKOS_INLINE_FUNCTION
161  void operator()(const ScalarsTag,const unsigned c) const;
162 
163  struct NoScalarsTag {};
164  KOKKOS_INLINE_FUNCTION
165  void operator()(const NoScalarsTag,const unsigned c) const;
166 
167 private:
168  typedef typename EvalT::ScalarT ScalarT;
169 
170  PHX::MDField<ScalarT,Tag0,Tag1> sum;
171  std::vector< PHX::MDField<const ScalarT,Tag0,Tag1> > values;
173 
174  // Functor members
176  enum {MAX_VALUES=20};
177  PHX::MDField<const ScalarT,Tag0,Tag1> current_value;
178  Kokkos::View<const ScalarT**,typename PHX::DevLayout<ScalarT>::type,PHX::Device> value_views[MAX_VALUES];
179  Kokkos::View<const double*,typename PHX::DevLayout<ScalarT>::type,PHX::Device> scalars;
181 
182  // this is used in the parallel kernel
183 };
184 
185 /*
186 template<typename EvalT, typename TRAITS,typename Tag0,typename Tag1,typename Tag2>
187 class SumStatic<EvalT,TRAITS,Tag0,Tag1,Tag2> : public panzer::EvaluatorWithBaseImpl<TRAITS>,
188  public PHX::EvaluatorDerived<EvalT, TRAITS> {
189 public:
190  SumStatic(const Teuchos::ParameterList& p);
191  void evaluateFields(typename TRAITS::EvalData d);
192 private:
193  typedef typename EvalT::ScalarT ScalarT;
194 
195  PHX::MDField<ScalarT,Tag0,Tag1,Tag2> sum;
196  std::vector< PHX::MDField<ScalarT,Tag0,Tag1,Tag2> > values;
197 };
198 */
199 
203 template<typename EvalT, typename TRAITS,typename Tag0,typename Tag1,typename Tag2>
205 buildStaticSumEvaluator(const std::string & sum_name,
206  const std::vector<std::string> & value_names,
207  const Teuchos::RCP<PHX::DataLayout> & data_layout);
208 
209 }
210 
211 #endif
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)
EvalT::ScalarT ScalarT
Definition: Panzer_Sum.hpp:120
static const int MAX_VALUES
Definition: Panzer_Sum.hpp:89
void postRegistrationSetup(typename Traits::SetupData d, PHX::FieldManager< Traits > &fm)
KOKKOS_INLINE_FUNCTION void operator()(PanzerSumTag< RANK >, const int &i) const
PHX::MDField< const ScalarT, Tag0, Tag1 > current_value
Definition: Panzer_Sum.hpp:177
SumStatic(const Teuchos::ParameterList &p)
std::vector< PHX::MDField< const ScalarT, Tag0 > > values
Definition: Panzer_Sum.hpp:133
Wrapper to PHX::EvaluatorWithBaseImpl that implements Panzer-specific helpers.
Kokkos::View< const double *, typename PHX::DevLayout< ScalarT >::type, PHX::Device > scalars
Definition: Panzer_Sum.hpp:179
PHX::MDField< ScalarT > sum
Definition: Panzer_Sum.hpp:91
PHX::MDField< ScalarT, Tag0, Tag1 > sum
Definition: Panzer_Sum.hpp:170
Kokkos::View< const double *, typename PHX::DevLayout< double >::type, PHX::Device > scalars
Definition: Panzer_Sum.hpp:95
void evaluateFields(typename Traits::EvalData d)
typename EvalT::ScalarT ScalarT
Definition: Panzer_Sum.hpp:88
std::size_t cell_data_size
Definition: Panzer_Sum.hpp:97
void evaluateFields(typename TRAITS::EvalData d)
std::vector< PHX::MDField< const ScalarT, Tag0, Tag1 > > values
Definition: Panzer_Sum.hpp:171
PHX::MDField< const ScalarT > values[MAX_VALUES]
Definition: Panzer_Sum.hpp:94