Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_CellExtreme_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_CellExtreme_impl_hpp__
44 #define __Panzer_CellExtreme_impl_hpp__
45 
46 #include <limits>
47 
48 #include "Intrepid2_FunctionSpaceTools.hpp"
51 #include "Phalanx_DataLayout_MDALayout.hpp"
52 
53 namespace panzer {
54 
55 //**********************************************************************
56 template<typename EvalT, typename Traits>
59  const Teuchos::ParameterList& p) : quad_index(0)
60 {
62  p.validateParameters(*valid_params);
63 
64  // setup default value
65  use_max = true;
66  if(p.isType<bool>("Use Max"))
67  use_max = p.get<bool>("Use Max");
68 
70  quad_order = ir->cubature_degree;
71 
72  Teuchos::RCP<PHX::DataLayout> dl_cell = Teuchos::rcp(new PHX::MDALayout<Cell>(ir->dl_scalar->extent(0)));
73  extreme = PHX::MDField<ScalarT>( p.get<std::string>("Extreme Name"), dl_cell);
74  scalar = PHX::MDField<const ScalarT,Cell,IP>( p.get<std::string>("Field Name"), ir->dl_scalar);
75 
76  this->addEvaluatedField(extreme);
77  this->addDependentField(scalar);
78 
79  multiplier = 1.0;
80  if(p.isType<double>("Multiplier"))
81  multiplier = p.get<double>("Multiplier");
82 
83  if (p.isType<Teuchos::RCP<const std::vector<std::string> > >("Field Multipliers")) {
84  const std::vector<std::string>& field_multiplier_names =
85  *(p.get<Teuchos::RCP<const std::vector<std::string> > >("Field Multipliers"));
86 
87  for (std::vector<std::string>::const_iterator name =
88  field_multiplier_names.begin();
89  name != field_multiplier_names.end(); ++name) {
91  field_multipliers.push_back(tmp_field);
92  }
93  }
94 
95  for (typename std::vector<PHX::MDField<const ScalarT,Cell,IP> >::iterator field = field_multipliers.begin();
96  field != field_multipliers.end(); ++field)
97  this->addDependentField(*field);
98 
99  std::string n = "CellExtreme: " + extreme.fieldTag().name();
100  this->setName(n);
101 }
102 
103 //**********************************************************************
104 template<typename EvalT, typename Traits>
105 void
108  typename Traits::SetupData sd,
109  PHX::FieldManager<Traits>& /* fm */)
110 {
111  num_qp = scalar.extent(1);
112  quad_index = panzer::getIntegrationRuleIndex(quad_order,(*sd.worksets_)[0], this->wda);
113 }
114 
115 //**********************************************************************
116 template<typename EvalT, typename Traits>
117 void
120  typename Traits::EvalData workset)
121 {
122  double mult = this->multiplier;
123  std::size_t num_pt = this->num_qp;
124  bool extreme_max = this->use_max;
125  auto scalar_view = scalar.get_view();
126  auto extreme_view = extreme.get_view();
127 
128  // compute field weighted with multipliers
129  PHX::View<ScalarT**> mult_field("Multiplied Field", workset.num_cells, scalar.extent(1));
130 
131  // initialize to scalar value
132  Kokkos::parallel_for("Initialize Muliplier Field", workset.num_cells, KOKKOS_LAMBDA( const int cell) {
133  for (std::size_t qp = 0; qp < num_pt; ++qp) {
134  mult_field(cell, qp) = mult * scalar_view(cell, qp);
135  }
136  });
137 
138  // multiply by field values
139  for (std::size_t field_num = 0; field_num < field_multipliers.size(); ++field_num)
140  {
141  auto field = field_multipliers[field_num];
142  Kokkos::parallel_for("CellExtreme: Multiply Fields", workset.num_cells, KOKKOS_LAMBDA( const int cell) {
143  for (std::size_t qp = 0; qp < num_pt; ++qp) {
144  mult_field(cell, qp) *= field(cell, qp);
145  }
146  });
147  }
148 
149  // take extreme over points in each cell
150  Kokkos::parallel_for ("CellExtreme", workset.num_cells, KOKKOS_LAMBDA( const int cell) {
151  for (std::size_t qp = 0; qp < num_pt; ++qp) {
152  auto current = mult_field(cell, qp);
153 
154  // take first point
155  if (qp == 0)
156  extreme_view(cell) = current;
157 
158  // take largest value in the cell
159  if(extreme_max)
160  extreme_view(cell) = extreme_view(cell)<current ? current : extreme_view(cell);
161  else // use_min
162  extreme_view(cell) = extreme_view(cell)>current ? current : extreme_view(cell);
163  }
164  });
165 }
166 
167 //**********************************************************************
168 template<typename EvalT, typename TRAITS>
171 {
173  p->set<std::string>("Extreme Name", "?");
174  p->set<std::string>("Field Name", "?");
175 
177  p->set("IR", ir);
178  p->set<bool>("Use Max", true);
179  p->set<double>("Multiplier", 1.0);
180 
182  p->set("Field Multipliers", fms);
183  return p;
184 }
185 
186 //**********************************************************************
187 
188 }
189 
190 #endif
int num_cells
DEPRECATED - use: numCells()
void evaluateFields(typename Traits::EvalData d)
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)
CellExtreme(const Teuchos::ParameterList &p)
std::vector< PHX::MDField< const ScalarT, Cell, IP > > field_multipliers
std::vector< int >::size_type getIntegrationRuleIndex(int ir_degree, const panzer::Workset &workset, WorksetDetailsAccessor &wda)
Teuchos::RCP< Teuchos::ParameterList > getValidParameters() const
double multiplier
The scalar multiplier out in front of the integral ( ).
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void postRegistrationSetup(typename Traits::SetupData d, PHX::FieldManager< Traits > &fm)
PHX::MDField< ScalarT > extreme
void validateParameters(ParameterList const &validParamList, int const depth=1000, EValidateUsed const validateUsed=VALIDATE_USED_ENABLED, EValidateDefaults const validateDefaults=VALIDATE_DEFAULTS_ENABLED) const
PHX::MDField< ScalarT, panzer::Cell, panzer::BASIS > field
A field to which we&#39;ll contribute, or in which we&#39;ll store, the result of computing this integral...
bool isType(const std::string &name) const
PHX::MDField< const ScalarT, Cell, IP > scalar
Teuchos::RCP< const std::vector< panzer::Workset > > worksets_