Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_DOF_PointValues_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_DOF_IMPL_HPP
12 #define PANZER_DOF_IMPL_HPP
13 
14 #include <algorithm>
16 #include "Panzer_BasisIRLayout.hpp"
19 #include "Panzer_DOF_Functors.hpp"
21 
22 #include "Intrepid2_FunctionSpaceTools.hpp"
23 
24 namespace panzer {
25 
26 //**********************************************************************
27 //* DOF_PointValues evaluator
28 //**********************************************************************
29 
30 //**********************************************************************
31 // MOST EVALUATION TYPES
32 //**********************************************************************
33 
34 //**********************************************************************
35 template<typename EvalT, typename TRAITS>
38 {
39  const std::string fieldName = p.get<std::string>("Name");
40  basis = p.get< Teuchos::RCP<const PureBasis> >("Basis");
42  is_vector_basis = basis->isVectorBasis();
43 
44  std::string evalName = fieldName+"_"+pointRule->getName();
45  if(p.isType<bool>("Use DOF Name")) {
46  if(p.get<bool>("Use DOF Name"))
47  evalName = fieldName;
48  }
49 
50  dof_basis = PHX::MDField<const ScalarT,Cell,Point>(fieldName, basis->functional);
51 
52  this->addDependentField(dof_basis);
53 
54  // setup all basis fields that are required
55  Teuchos::RCP<BasisIRLayout> layout = Teuchos::rcp(new BasisIRLayout(basis,*pointRule));
56  basisValues = Teuchos::rcp(new BasisValues2<double>(basis->name()+"_"+pointRule->getName()+"_"));
57  basisValues->setupArrays(layout,false);
58 
59  // the field manager will allocate all of these field
60  // swap between scalar basis value, or vector basis value
61  if(basis->isScalarBasis()) {
62  dof_ip_scalar = PHX::MDField<ScalarT,Cell,Point>(
63  evalName,
64  pointRule->dl_scalar);
65  this->addEvaluatedField(dof_ip_scalar);
66  this->addNonConstDependentField(basisValues->basis_ref_scalar);
67  this->addNonConstDependentField(basisValues->basis_scalar);
68  }
69  else if(basis->isVectorBasis()) {
71  evalName,
72  pointRule->dl_vector);
73  this->addEvaluatedField(dof_ip_vector);
74  this->addNonConstDependentField(basisValues->basis_ref_vector);
75  this->addNonConstDependentField(basisValues->basis_vector);
76  }
77  else
78  { TEUCHOS_ASSERT(false); }
79 
80  std::string n = "DOF_PointValues: " + dof_basis.fieldTag().name();
81  this->setName(n);
82 }
83 
84 //**********************************************************************
85 template<typename EvalT, typename TRAITS>
87 postRegistrationSetup(typename TRAITS::SetupData /* sd */,
89 {
90  if(!is_vector_basis) {
91  this->utils.setFieldData(basisValues->basis_ref_scalar,fm);
92  this->utils.setFieldData(basisValues->basis_scalar,fm);
93  }
94  else {
95  this->utils.setFieldData(basisValues->basis_ref_vector,fm);
96  this->utils.setFieldData(basisValues->basis_vector,fm);
97  }
98 }
99 
100 //**********************************************************************
101 template<typename EvalT, typename TRAITS>
103 evaluateFields(typename TRAITS::EvalData workset)
104 {
105  const int vector_size = panzer::HP::inst().vectorSize<ScalarT>();
106 
107  if(is_vector_basis) {
108  int spaceDim = basisValues->basis_vector.extent(3);
109  if(spaceDim==3) {
110  dof_functors::EvaluateDOFWithSens_Vector<ScalarT,typename BasisValues2<double>::Array_CellBasisIPDim,3> functor(dof_basis.get_static_view(),dof_ip_vector.get_static_view(),basisValues->basis_vector);
111  Kokkos::parallel_for(Kokkos::TeamPolicy<PHX::Device>(workset.num_cells,Kokkos::AUTO(),vector_size),functor);
112  }
113  else {
114  dof_functors::EvaluateDOFWithSens_Vector<ScalarT,typename BasisValues2<double>::Array_CellBasisIPDim,2> functor(dof_basis.get_static_view(),dof_ip_vector.get_static_view(),basisValues->basis_vector);
115  Kokkos::parallel_for(Kokkos::TeamPolicy<PHX::Device>(workset.num_cells,Kokkos::AUTO(),vector_size),functor);
116  }
117  }
118  else {
119  dof_functors::EvaluateDOFWithSens_Scalar<ScalarT,typename BasisValues2<double>::Array_CellBasisIP> functor(dof_basis,dof_ip_scalar,basisValues->basis_scalar);
120  Kokkos::parallel_for(workset.num_cells,functor);
121  }
122 }
123 
124 //**********************************************************************
125 
126 //**********************************************************************
127 // JACOBIAN EVALUATION TYPES
128 //**********************************************************************
129 
130 //**********************************************************************
131 template<typename TRAITS>
134 {
135  const std::string fieldName = p.get<std::string>("Name");
136  basis = p.get< Teuchos::RCP<const PureBasis> >("Basis");
137  Teuchos::RCP<const PointRule> pointRule = p.get< Teuchos::RCP<const PointRule> >("Point Rule");
138  is_vector_basis = basis->isVectorBasis();
139 
140  if(p.isType<Teuchos::RCP<const std::vector<int> > >("Jacobian Offsets Vector")) {
141  const std::vector<int> & offsets = *p.get<Teuchos::RCP<const std::vector<int> > >("Jacobian Offsets Vector");
142 
143  // allocate and copy offsets vector to Kokkos array
144  offsets_array = PHX::View<int*>("offsets",offsets.size());
145  for(std::size_t i=0;i<offsets.size();i++)
146  offsets_array(i) = offsets[i];
147 
148  accelerate_jacobian = true; // short cut for identity matrix
149  }
150  else
151  accelerate_jacobian = false; // don't short cut for identity matrix
152 
153  std::string evalName = fieldName+"_"+pointRule->getName();
154  if(p.isType<bool>("Use DOF Name")) {
155  if(p.get<bool>("Use DOF Name"))
156  evalName = fieldName;
157  }
158 
159  dof_basis = PHX::MDField<const ScalarT,Cell,Point>(fieldName, basis->functional);
160 
161  this->addDependentField(dof_basis);
162 
163  // setup all basis fields that are required
164  Teuchos::RCP<BasisIRLayout> layout = Teuchos::rcp(new BasisIRLayout(basis,*pointRule));
165  basisValues = Teuchos::rcp(new BasisValues2<double>(basis->name()+"_"+pointRule->getName()+"_"));
166  basisValues->setupArrays(layout,false);
167 
168  // the field manager will allocate all of these field
169  // swap between scalar basis value, or vector basis value
170  if(basis->isScalarBasis()) {
172  evalName,
173  pointRule->dl_scalar);
174  this->addEvaluatedField(dof_ip_scalar);
175  this->addNonConstDependentField(basisValues->basis_ref_scalar);
176  this->addNonConstDependentField(basisValues->basis_scalar);
177  }
178  else if(basis->isVectorBasis()) {
180  evalName,
181  pointRule->dl_vector);
182  this->addEvaluatedField(dof_ip_vector);
183  this->addNonConstDependentField(basisValues->basis_ref_vector);
184  this->addNonConstDependentField(basisValues->basis_vector);
185  }
186  else
187  { TEUCHOS_ASSERT(false); }
188 
189  std::string n = "DOF_PointValues: " + dof_basis.fieldTag().name() + " Jacobian";
190  this->setName(n);
191 }
192 
193 //**********************************************************************
194 template<typename TRAITS>
196 postRegistrationSetup(typename TRAITS::SetupData /* sd */,
198 {
199  if(!is_vector_basis) {
200  this->utils.setFieldData(basisValues->basis_ref_scalar,fm);
201  this->utils.setFieldData(basisValues->basis_scalar,fm);
202  }
203  else {
204  this->utils.setFieldData(basisValues->basis_ref_vector,fm);
205  this->utils.setFieldData(basisValues->basis_vector,fm);
206  }
207 }
208 
209 //**********************************************************************
210 template<typename TRAITS>
212 evaluateFields(typename TRAITS::EvalData workset)
213 {
214  const int vector_size = panzer::HP::inst().vectorSize<ScalarT>();
215 
216  if(is_vector_basis) {
217  if(accelerate_jacobian) {
218  int spaceDim = basisValues->basis_vector.extent(3);
219  if(spaceDim==3) {
221  Kokkos::parallel_for(workset.num_cells,functor);
222  }
223  else {
225  Kokkos::parallel_for(workset.num_cells,functor);
226  }
227  }
228  else {
229  int spaceDim = basisValues->basis_vector.extent(3);
230  if(spaceDim==3) {
232  Kokkos::parallel_for(Kokkos::TeamPolicy<PHX::Device>(workset.num_cells,Kokkos::AUTO(),vector_size),functor);
233  }
234  else {
236  Kokkos::parallel_for(Kokkos::TeamPolicy<PHX::Device>(workset.num_cells,Kokkos::AUTO(),vector_size),functor);
237  }
238  }
239  }
240  else {
241  if(accelerate_jacobian) {
243  Kokkos::parallel_for(workset.num_cells,functor);
244  }
245  else {
247  Kokkos::parallel_for(workset.num_cells,functor);
248  }
249  }
250 }
251 
252 }
253 
254 #endif
T & get(const std::string &name, T def_value)
void evaluateFields(typename TRAITS::EvalData d)
PHX::MDField< ScalarT, Cell, Point, Dim > dof_ip_vector
PHX::View< const int * > offsets
PHX::MDField< const ScalarT, Cell, Point > dof_basis
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::RCP< const PureBasis > basis
void postRegistrationSetup(typename TRAITS::SetupData d, PHX::FieldManager< TRAITS > &fm)
int vectorSize() const
Returns the vector size. Specialized for AD scalar types.
bool isType(const std::string &name) const
static HP & inst()
Private ctor.
PHX::MDField< ScalarT, Cell, Point > dof_ip_scalar
Teuchos::RCP< BasisValues2< double > > basisValues
#define TEUCHOS_ASSERT(assertion_test)
DOF_PointValues(const Teuchos::ParameterList &p)