Panzer  Version of the Day
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 PHX_EVALUATOR_CTOR(CellExtreme,p) : quad_index(-1)
57 {
58  Teuchos::RCP<Teuchos::ParameterList> valid_params = this->getValidParameters();
59  p.validateParameters(*valid_params);
60 
61  // setup default value
62  use_max = true;
63  if(p.isType<bool>("Use Max"))
64  use_max = p.get<bool>("Use Max");
65 
66  Teuchos::RCP<panzer::IntegrationRule> ir = p.get< Teuchos::RCP<panzer::IntegrationRule> >("IR");
67  quad_order = ir->cubature_degree;
68 
69  Teuchos::RCP<PHX::DataLayout> dl_cell = Teuchos::rcp(new PHX::MDALayout<Cell>(ir->dl_scalar->dimension(0)));
70  extreme = PHX::MDField<ScalarT>( p.get<std::string>("Extreme Name"), dl_cell);
71  scalar = PHX::MDField<const ScalarT,Cell,IP>( p.get<std::string>("Field Name"), ir->dl_scalar);
72 
73  this->addEvaluatedField(extreme);
74  this->addDependentField(scalar);
75 
76  multiplier = 1.0;
77  if(p.isType<double>("Multiplier"))
78  multiplier = p.get<double>("Multiplier");
79 
80  if (p.isType<Teuchos::RCP<const std::vector<std::string> > >("Field Multipliers")) {
81  const std::vector<std::string>& field_multiplier_names =
82  *(p.get<Teuchos::RCP<const std::vector<std::string> > >("Field Multipliers"));
83 
84  for (std::vector<std::string>::const_iterator name =
85  field_multiplier_names.begin();
86  name != field_multiplier_names.end(); ++name) {
87  PHX::MDField<const ScalarT,Cell,IP> tmp_field(*name, p.get< Teuchos::RCP<panzer::IntegrationRule> >("IR")->dl_scalar);
88  field_multipliers.push_back(tmp_field);
89  }
90  }
91 
92  for (typename std::vector<PHX::MDField<const ScalarT,Cell,IP> >::iterator field = field_multipliers.begin();
93  field != field_multipliers.end(); ++field)
94  this->addDependentField(*field);
95 
96  std::string n = "CellExtreme: " + extreme.fieldTag().name();
97  this->setName(n);
98 }
99 
100 //**********************************************************************
101 PHX_POST_REGISTRATION_SETUP(CellExtreme,sd,fm)
102 {
103  this->utils.setFieldData(extreme,fm);
104  this->utils.setFieldData(scalar,fm);
105 
106  for (typename std::vector<PHX::MDField<const ScalarT,Cell,IP> >::iterator field = field_multipliers.begin();
107  field != field_multipliers.end(); ++field)
108  this->utils.setFieldData(*field,fm);
109 
110  num_qp = scalar.dimension(1);
111 
112  quad_index = panzer::getIntegrationRuleIndex(quad_order,(*sd.worksets_)[0], this->wda);
113 }
114 
115 //**********************************************************************
116 PHX_EVALUATE_FIELDS(CellExtreme,workset)
117 {
118  for (index_t cell = 0; cell < workset.num_cells; ++cell) {
119 
120  for (std::size_t qp = 0; qp < num_qp; ++qp) {
121  ScalarT current= multiplier * scalar(cell,qp);
122  for (typename std::vector<PHX::MDField<const ScalarT,Cell,IP> >::iterator field = field_multipliers.begin();
123  field != field_multipliers.end(); ++field)
124  current *= (*field)(cell,qp);
125 
126  // take first quad point value
127  if(qp==0)
128  extreme(cell) = current;
129 
130  // take largest value in the cell
131  if(use_max)
132  extreme(cell) = extreme(cell)<current ? current : extreme(cell);
133  else // use_min
134  extreme(cell) = extreme(cell)>current ? current : extreme(cell);
135  }
136  }
137 }
138 
139 //**********************************************************************
140 template<typename EvalT, typename TRAITS>
141 Teuchos::RCP<Teuchos::ParameterList>
143 {
144  Teuchos::RCP<Teuchos::ParameterList> p = Teuchos::rcp(new Teuchos::ParameterList);
145  p->set<std::string>("Extreme Name", "?");
146  p->set<std::string>("Field Name", "?");
147 
148  Teuchos::RCP<panzer::IntegrationRule> ir;
149  p->set("IR", ir);
150  p->set<bool>("Use Max", true);
151  p->set<double>("Multiplier", 1.0);
152 
153  Teuchos::RCP<const std::vector<std::string> > fms;
154  p->set("Field Multipliers", fms);
155  return p;
156 }
157 
158 //**********************************************************************
159 
160 }
161 
162 #endif
std::size_t num_qp
PHX::MDField< ScalarT > vector
Teuchos::RCP< Teuchos::ParameterList > getValidParameters() const
std::size_t quad_index
PHX_EVALUATOR_CTOR(BasisValues_Evaluator, p)
PHX::MDField< const ScalarT, Cell, IP > field
double multiplier
PHX::MDField< const ScalarT, Cell, IP > scalar
PHX_EVALUATE_FIELDS(BasisValues_Evaluator, workset)
std::vector< std::string >::size_type getIntegrationRuleIndex(int ir_degree, panzer::Workset &workset, WorksetDetailsAccessor &wda)
std::vector< PHX::MDField< const ScalarT, Cell, IP > > field_multipliers
PHX::MDField< ScalarT > extreme
PHX_POST_REGISTRATION_SETUP(BasisValues_Evaluator, sd, fm)