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 // Panzer: A partial differential equation assembly
4 // engine for strongly coupled complex multiphysics systems
5 //
6 // Copyright 2011 NTESS and the Panzer contributors.
7 // SPDX-License-Identifier: BSD-3-Clause
8 // *****************************************************************************
9 // @HEADER
10 
11 #ifndef __Panzer_CellAverage_impl_hpp__
12 #define __Panzer_CellAverage_impl_hpp__
13 
14 #include <limits>
15 
16 #include "Intrepid2_FunctionSpaceTools.hpp"
19 #include "Phalanx_DataLayout_MDALayout.hpp"
20 
21 namespace panzer {
22 
23 //**********************************************************************
24 template<typename EvalT, typename Traits>
27  const Teuchos::ParameterList& p) : quad_index(0)
28 {
30  p.validateParameters(*valid_params);
31 
34 
36  average = PHX::MDField<ScalarT,Cell>( p.get<std::string>("Average Name"), dl_cell);
37  scalar = PHX::MDField<const ScalarT,Cell,IP>( p.get<std::string>("Field Name"), ir->dl_scalar);
38 
39  this->addEvaluatedField(average);
40  this->addDependentField(scalar);
41 
42  multiplier = 1.0;
43  if(p.isType<double>("Multiplier"))
44  multiplier = p.get<double>("Multiplier");
45 
46  if (p.isType<Teuchos::RCP<const std::vector<std::string> > >("Field Multipliers")) {
47  const std::vector<std::string>& field_multiplier_names =
48  *(p.get<Teuchos::RCP<const std::vector<std::string> > >("Field Multipliers"));
49 
50  for (std::vector<std::string>::const_iterator name =
51  field_multiplier_names.begin();
52  name != field_multiplier_names.end(); ++name) {
54  field_multipliers.push_back(tmp_field);
55  }
56  }
57 
58  for (typename std::vector<PHX::MDField<const ScalarT,Cell,IP> >::iterator field = field_multipliers.begin();
59  field != field_multipliers.end(); ++field)
60  this->addDependentField(*field);
61 
62  std::string n = "CellAverage: " + average.fieldTag().name();
63  this->setName(n);
64 }
65 
66 //**********************************************************************
67 template<typename EvalT, typename Traits>
68 void
71  typename Traits::SetupData sd,
72  PHX::FieldManager<Traits>& /* fm */)
73 {
74  num_qp = scalar.extent(1);
75  quad_index = panzer::getIntegrationRuleIndex(quad_order,(*sd.worksets_)[0], this->wda);
76 }
77 
78 //**********************************************************************
79 template<typename EvalT, typename Traits>
80 void
83  typename Traits::EvalData workset)
84 {
85  for (index_t cell = 0; cell < workset.num_cells; ++cell) {
86 
87  // start with no average
88  average(cell) = 0.0;
89 
90  // loop over quadrture points, compute simple average
91  for (std::size_t qp = 0; qp < num_qp; ++qp) {
92  ScalarT current= multiplier * scalar(cell,qp);
93  for (typename std::vector<PHX::MDField<const ScalarT,Cell,IP> >::iterator field = field_multipliers.begin();
94  field != field_multipliers.end(); ++field)
95  current *= (*field)(cell,qp);
96 
97  // take first quad point value
98  average(cell) += current/num_qp;
99  }
100  }
101 }
102 
103 //**********************************************************************
104 template<typename EvalT, typename TRAITS>
107 {
109  p->set<std::string>("Average Name", "?");
110  p->set<std::string>("Field Name", "?");
111 
113  p->set("IR", ir);
114  p->set<double>("Multiplier", 1.0);
115 
117  p->set("Field Multipliers", fms);
118  return p;
119 }
120 
121 //**********************************************************************
122 
123 }
124 
125 #endif
int num_cells
DEPRECATED - use: numCells()
T & get(const std::string &name, T def_value)
typename EvalT::ScalarT ScalarT
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
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_