43 #ifndef __Panzer_Integrator_GradBasisDotVector_impl_hpp__ 44 #define __Panzer_Integrator_GradBasisDotVector_impl_hpp__ 65 template<
typename EvalT,
typename Traits>
69 const std::string& resName,
70 const std::string& fluxName,
74 const std::vector<std::string>& fmNames,
76 const Teuchos::RCP<PHX::DataLayout>& vecDL )
80 basisName_(basis.name())
87 using PHX::DataLayout;
89 using std::invalid_argument;
90 using std::logic_error;
95 TEUCHOS_TEST_FOR_EXCEPTION(resName ==
"", invalid_argument,
"Error: " \
96 "Integrator_GradBasisDotVector called with an empty residual name.")
97 TEUCHOS_TEST_FOR_EXCEPTION(fluxName ==
"", invalid_argument,
"Error: " \
98 "Integrator_GradBasisDotVector called with an empty flux name.")
99 RCP<const PureBasis> tmpBasis = basis.
getBasis();
100 TEUCHOS_TEST_FOR_EXCEPTION(not tmpBasis->supportsGrad(), logic_error,
101 "Error: Integrator_GradBasisDotVector: Basis of type \"" 102 << tmpBasis->name() <<
"\" does not support the gradient operator.")
104 if (not vecDL.is_null())
107 TEUCHOS_TEST_FOR_EXCEPTION(
108 tmpVecDL->extent(2) < ir.
dl_vector->extent(2), logic_error,
109 "Integrator_GradBasisDotVector: Dimension of space exceeds " \
110 "dimension of Vector Data Layout.");
114 vector_ = MDField<const ScalarT, Cell, IP, Dim>(fluxName, tmpVecDL);
115 this->addDependentField(
vector_);
121 this->addContributedField(
field_);
123 this->addEvaluatedField(
field_);
128 kokkosFieldMults_ = View<View<const ScalarT**>*>(
"GradBasisDotVector::KokkosFieldMultipliers",
130 for (
const auto& name : fmNames)
137 string n(
"Integrator_GradBasisDotVector (");
142 n +=
"): " +
field_.fieldTag().name();
151 template<
typename EvalT,
typename Traits>
154 const Teuchos::ParameterList& p)
158 p.get<
std::string>(
"Residual Name"),
159 p.get<
std::string>(
"Flux Name"),
162 p.get<double>(
"Multiplier"),
164 (
"Field Multipliers") ?
166 (
"Field Multipliers")) :
std::vector<
std::string>(),
167 p.isType<
Teuchos::RCP<
PHX::DataLayout>>(
"Vector Data Layout") ?
168 p.get<
Teuchos::RCP<
PHX::DataLayout>>(
"Vector Data Layout") :
171 using Teuchos::ParameterList;
176 p.validateParameters(*validParams);
184 template<
typename EvalT,
typename Traits>
195 for (
size_t i(0); i < fieldMults_.size(); ++i)
196 kokkosFieldMults_(i) = fieldMults_[i].get_static_view();
207 template<
typename EvalT,
typename Traits>
208 template<
int NUM_FIELD_MULT>
209 KOKKOS_INLINE_FUNCTION
214 const Kokkos::TeamPolicy<PHX::exec_space>::member_type& team)
const 217 const int cell = team.league_rank();
220 const int numQP(vector_.extent(1)), numDim(vector_.extent(2)),
221 numBases(basis_.extent(1));
223 Kokkos::parallel_for(Kokkos::TeamThreadRange(team,0,numBases),KOKKOS_LAMBDA (
const int& basis) {
224 field_(cell, basis) = 0.0;
230 if (NUM_FIELD_MULT == 0)
235 for (
int qp(0); qp < numQP; ++qp)
237 for (
int dim(0); dim < numDim; ++dim)
239 tmp = multiplier_ * vector_(cell, qp, dim);
240 Kokkos::parallel_for(Kokkos::TeamThreadRange(team,0,numBases),KOKKOS_LAMBDA (
const int& basis) {
241 field_(cell, basis) += basis_(cell, basis, qp, dim) * tmp;
246 else if (NUM_FIELD_MULT == 1)
251 for (
int qp(0); qp < numQP; ++qp)
253 for (
int dim(0); dim < numDim; ++dim)
255 tmp = multiplier_ * vector_(cell, qp, dim) *
256 kokkosFieldMults_(0)(cell, qp);
257 Kokkos::parallel_for(Kokkos::TeamThreadRange(team,0,numBases),KOKKOS_LAMBDA (
const int& basis) {
258 field_(cell, basis) += basis_(cell, basis, qp, dim) * tmp;
270 const int numFieldMults(kokkosFieldMults_.extent(0));
271 for (
int qp(0); qp < numQP; ++qp)
274 for (
int fm(0); fm < numFieldMults; ++fm)
275 fieldMultsTotal *= kokkosFieldMults_(fm)(cell, qp);
276 for (
int dim(0); dim < numDim; ++dim)
278 tmp = multiplier_ * vector_(cell, qp, dim) * fieldMultsTotal;
279 Kokkos::parallel_for(Kokkos::TeamThreadRange(team,0,numBases),KOKKOS_LAMBDA (
const int& basis) {
280 field_(cell, basis) += basis_(cell, basis, qp, dim) * tmp;
292 template<
typename EvalT,
typename Traits>
293 template<
int NUM_FIELD_MULT>
294 KOKKOS_INLINE_FUNCTION
299 const Kokkos::TeamPolicy<PHX::exec_space>::member_type& team)
const 302 const int cell = team.league_rank();
303 const int numQP = vector_.extent(1);
304 const int numDim = vector_.extent(2);
305 const int numBases = basis_.extent(1);
306 const int fadSize = Kokkos::dimension_scalar(field_.get_view());
310 if (Sacado::IsADType<ScalarT>::value) {
312 tmp_field =
scratch_view(team.team_shmem(),numBases,fadSize);
320 Kokkos::parallel_for(Kokkos::TeamThreadRange(team,0,numBases),KOKKOS_LAMBDA (
const int& basis) {
321 tmp_field(basis) = 0.0;
326 if (NUM_FIELD_MULT == 0)
331 for (
int qp(0); qp < numQP; ++qp)
333 for (
int dim(0); dim < numDim; ++dim)
336 tmp(0) = multiplier_ * vector_(cell, qp, dim);
337 Kokkos::parallel_for(Kokkos::TeamThreadRange(team,0,numBases),KOKKOS_LAMBDA (
const int& basis) {
338 tmp_field(basis) += basis_(cell, basis, qp, dim) * tmp(0);
343 else if (NUM_FIELD_MULT == 1)
348 for (
int qp(0); qp < numQP; ++qp)
350 for (
int dim(0); dim < numDim; ++dim)
353 tmp(0) = multiplier_ * vector_(cell, qp, dim) *
354 kokkosFieldMults_(0)(cell, qp);
355 Kokkos::parallel_for(Kokkos::TeamThreadRange(team,0,numBases),KOKKOS_LAMBDA (
const int& basis) {
356 tmp_field(basis) += basis_(cell, basis, qp, dim) * tmp(0);
368 const int numFieldMults(kokkosFieldMults_.extent(0));
369 for (
int qp(0); qp < numQP; ++qp)
372 for (
int fm(0); fm < numFieldMults; ++fm)
373 fieldMultsTotal *= kokkosFieldMults_(fm)(cell, qp);
374 for (
int dim(0); dim < numDim; ++dim)
377 tmp(0) = multiplier_ * vector_(cell, qp, dim) * fieldMultsTotal;
378 Kokkos::parallel_for(Kokkos::TeamThreadRange(team,0,numBases),KOKKOS_LAMBDA (
const int& basis) {
379 tmp_field(basis) += basis_(cell, basis, qp, dim) * tmp(0);
387 Kokkos::parallel_for(Kokkos::TeamThreadRange(team,0,numBases),[&] (
const int& basis) {
388 field_(cell,basis) = tmp_field(basis);
392 Kokkos::parallel_for(Kokkos::TeamThreadRange(team,0,numBases),[&] (
const int& basis) {
393 field_(cell,basis) += tmp_field(basis);
404 template<
typename EvalT,
typename Traits>
410 using Kokkos::parallel_for;
411 using Kokkos::TeamPolicy;
414 basis_ = this->wda(workset).bases[basisIndex_]->weighted_grad_basis;
417 if (use_shared_memory) {
419 if (Sacado::IsADType<ScalarT>::value) {
420 const int fadSize = Kokkos::dimension_scalar(field_.get_view());
421 bytes = scratch_view::shmem_size(1,fadSize) + scratch_view::shmem_size(basis_.extent(1),fadSize);
424 bytes = scratch_view::shmem_size(1) + scratch_view::shmem_size(basis_.extent(1));
429 if (fieldMults_.size() == 0) {
431 parallel_for(policy, *
this, this->getName());
432 }
else if (fieldMults_.size() == 1) {
434 parallel_for(policy, *
this, this->getName());
437 parallel_for(policy, *
this, this->getName());
444 if (fieldMults_.size() == 0) {
446 parallel_for(policy, *
this, this->getName());
447 }
else if (fieldMults_.size() == 1) {
449 parallel_for(policy, *
this, this->getName());
452 parallel_for(policy, *
this, this->getName());
462 template<
typename EvalT,
typename TRAITS>
463 Teuchos::RCP<Teuchos::ParameterList>
469 using PHX::DataLayout;
472 using Teuchos::ParameterList;
477 RCP<ParameterList> p = rcp(
new ParameterList);
478 p->set<
string>(
"Residual Name",
"?");
479 p->set<
string>(
"Flux Name",
"?");
480 RCP<BasisIRLayout> basis;
481 p->set(
"Basis", basis);
482 RCP<IntegrationRule> ir;
484 p->set<
double>(
"Multiplier", 1.0);
485 RCP<const vector<string>> fms;
486 p->set(
"Field Multipliers", fms);
487 RCP<DataLayout> vecDL;
488 p->set(
"Vector Data Layout", vecDL);
494 #endif // __Panzer_Integrator_GradBasisDotVector_impl_hpp__ int num_cells
DEPRECATED - use: numCells()
PHX::View< PHX::View< const ScalarT ** > *> kokkosFieldMults_
The PHX::View representation of the (possibly empty) list of fields that are multipliers out in front...
PHX::MDField< const ScalarT, panzer::Cell, panzer::IP, panzer::Dim > vector_
A field representing the vector-valued function we're integrating ( ).
bool useSharedMemory() const
typename EvalT::ScalarT ScalarT
The scalar type.
Integrator_GradBasisDotVector(const panzer::EvaluatorStyle &evalStyle, const std::string &resName, const std::string &fluxName, const panzer::BasisIRLayout &basis, const panzer::IntegrationRule &ir, const double &multiplier=1, const std::vector< std::string > &fmNames=std::vector< std::string >(), const Teuchos::RCP< PHX::DataLayout > &vecDL=Teuchos::null)
Main Constructor.
Kokkos::TeamPolicy< TeamPolicyProperties... > teamPolicy(const int &league_size)
Returns a TeamPolicy for hierarchic parallelism.
PHX::MDField< ScalarT, panzer::Cell, panzer::BASIS > field_
A field to which we'll contribute, or in which we'll store, the result of computing this integral...
Teuchos::RCP< Teuchos::ParameterList > getValidParameters() const
Get Valid Parameters.
This empty struct allows us to optimize operator()() depending on the number of field multipliers...
Teuchos::RCP< const PureBasis > getBasis() const
EvaluatorStyle
An indication of how an Evaluator will behave.
const panzer::EvaluatorStyle evalStyle_
An enum determining the behavior of this Evaluator.
Kokkos::View< ScalarT *,typename PHX::DevLayout< ScalarT >::type, typename PHX::exec_space::scratch_memory_space, Kokkos::MemoryUnmanaged > scratch_view
Type for shared memory.
std::vector< PHX::MDField< const ScalarT, panzer::Cell, panzer::IP > > fieldMults_
The (possibly empty) list of fields that are multipliers out in front of the integral ( ...
double multiplier
The scalar multiplier out in front of the integral ( ).
Teuchos::RCP< PHX::DataLayout > dl_scalar
Data layout for scalar fields.
panzer::EvaluatorStyle evalStyle
The EvaluatorStyle of the parent Integrator_CurlBasisDotVector object.
std::vector< std::string >::size_type getBasisIndex(std::string basis_name, const panzer::Workset &workset, WorksetDetailsAccessor &wda)
Returns the index in the workset bases for a particular BasisIRLayout name.
KOKKOS_INLINE_FUNCTION void operator()(const FieldMultTag< NUM_FIELD_MULT > &tag, const Kokkos::TeamPolicy< PHX::exec_space >::member_type &team) const
Perform the integration.
void evaluateFields(typename Traits::EvalData d)
Evaluate Fields.
void postRegistrationSetup(typename Traits::SetupData d, PHX::FieldManager< Traits > &fm)
Post-Registration Setup.
Teuchos::RCP< PHX::DataLayout > dl_vector
Data layout for vector fields.
static HP & inst()
Private ctor.
This empty struct allows us to optimize operator()() depending on the number of field multipliers...
Teuchos::RCP< PHX::DataLayout > functional
<Cell,Basis>
Teuchos::RCP< const std::vector< panzer::Workset > > worksets_