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) {
90  PHX::MDField<const ScalarT,Cell,IP> tmp_field(*name, p.get< Teuchos::RCP<panzer::IntegrationRule> >("IR")->dl_scalar);
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  for (index_t cell = 0; cell < workset.num_cells; ++cell) {
123 
124  for (std::size_t qp = 0; qp < num_qp; ++qp) {
125  ScalarT current= multiplier * scalar(cell,qp);
126  for (typename std::vector<PHX::MDField<const ScalarT,Cell,IP> >::iterator field = field_multipliers.begin();
127  field != field_multipliers.end(); ++field)
128  current *= (*field)(cell,qp);
129 
130  // take first quad point value
131  if(qp==0)
132  extreme(cell) = current;
133 
134  // take largest value in the cell
135  if(use_max)
136  extreme(cell) = extreme(cell)<current ? current : extreme(cell);
137  else // use_min
138  extreme(cell) = extreme(cell)>current ? current : extreme(cell);
139  }
140  }
141 }
142 
143 //**********************************************************************
144 template<typename EvalT, typename TRAITS>
147 {
149  p->set<std::string>("Extreme Name", "?");
150  p->set<std::string>("Field Name", "?");
151 
153  p->set("IR", ir);
154  p->set<bool>("Use Max", true);
155  p->set<double>("Multiplier", 1.0);
156 
158  p->set("Field Multipliers", fms);
159  return p;
160 }
161 
162 //**********************************************************************
163 
164 }
165 
166 #endif
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)
typename EvalT::ScalarT ScalarT
CellExtreme(const Teuchos::ParameterList &p)
std::vector< PHX::MDField< const ScalarT, Cell, IP > > field_multipliers
std::vector< std::string >::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_