Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_CellAverage_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_CellAverage_impl_hpp__
44 #define __Panzer_CellAverage_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 
66 
68  average = PHX::MDField<ScalarT,Cell>( p.get<std::string>("Average Name"), dl_cell);
69  scalar = PHX::MDField<const ScalarT,Cell,IP>( p.get<std::string>("Field Name"), ir->dl_scalar);
70 
71  this->addEvaluatedField(average);
72  this->addDependentField(scalar);
73 
74  multiplier = 1.0;
75  if(p.isType<double>("Multiplier"))
76  multiplier = p.get<double>("Multiplier");
77 
78  if (p.isType<Teuchos::RCP<const std::vector<std::string> > >("Field Multipliers")) {
79  const std::vector<std::string>& field_multiplier_names =
80  *(p.get<Teuchos::RCP<const std::vector<std::string> > >("Field Multipliers"));
81 
82  for (std::vector<std::string>::const_iterator name =
83  field_multiplier_names.begin();
84  name != field_multiplier_names.end(); ++name) {
86  field_multipliers.push_back(tmp_field);
87  }
88  }
89 
90  for (typename std::vector<PHX::MDField<const ScalarT,Cell,IP> >::iterator field = field_multipliers.begin();
91  field != field_multipliers.end(); ++field)
92  this->addDependentField(*field);
93 
94  std::string n = "CellAverage: " + average.fieldTag().name();
95  this->setName(n);
96 }
97 
98 //**********************************************************************
99 template<typename EvalT, typename Traits>
100 void
103  typename Traits::SetupData sd,
104  PHX::FieldManager<Traits>& /* fm */)
105 {
106  num_qp = scalar.extent(1);
107  quad_index = panzer::getIntegrationRuleIndex(quad_order,(*sd.worksets_)[0], this->wda);
108 }
109 
110 //**********************************************************************
111 template<typename EvalT, typename Traits>
112 void
115  typename Traits::EvalData workset)
116 {
117  for (index_t cell = 0; cell < workset.num_cells; ++cell) {
118 
119  // start with no average
120  average(cell) = 0.0;
121 
122  // loop over quadrture points, compute simple average
123  for (std::size_t qp = 0; qp < num_qp; ++qp) {
124  ScalarT current= multiplier * scalar(cell,qp);
125  for (typename std::vector<PHX::MDField<const ScalarT,Cell,IP> >::iterator field = field_multipliers.begin();
126  field != field_multipliers.end(); ++field)
127  current *= (*field)(cell,qp);
128 
129  // take first quad point value
130  average(cell) += current/num_qp;
131  }
132  }
133 }
134 
135 //**********************************************************************
136 template<typename EvalT, typename TRAITS>
139 {
141  p->set<std::string>("Average Name", "?");
142  p->set<std::string>("Field Name", "?");
143 
145  p->set("IR", ir);
146  p->set<double>("Multiplier", 1.0);
147 
149  p->set("Field Multipliers", fms);
150  return p;
151 }
152 
153 //**********************************************************************
154 
155 }
156 
157 #endif
int num_cells
DEPRECATED - use: numCells()
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
std::vector< int >::size_type getIntegrationRuleIndex(int ir_degree, const panzer::Workset &workset, WorksetDetailsAccessor &wda)
double multiplier
The scalar multiplier out in front of the integral ( ).
PHX::MDField< ScalarT, Cell > average
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void postRegistrationSetup(typename Traits::SetupData d, PHX::FieldManager< Traits > &fm)
Teuchos::RCP< PHX::DataLayout > dl_scalar
Data layout for scalar fields.
void evaluateFields(typename Traits::EvalData d)
void validateParameters(ParameterList const &validParamList, int const depth=1000, EValidateUsed const validateUsed=VALIDATE_USED_ENABLED, EValidateDefaults const validateDefaults=VALIDATE_DEFAULTS_ENABLED) const
PHX::MDField< const ScalarT, Cell, IP > scalar
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...
CellAverage(const Teuchos::ParameterList &p)
bool isType(const std::string &name) const
std::vector< PHX::MDField< const ScalarT, Cell, IP > > field_multipliers
Teuchos::RCP< Teuchos::ParameterList > getValidParameters() const
Teuchos::RCP< const std::vector< panzer::Workset > > worksets_