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