11#ifndef __Panzer_Integrator_DivBasisTimesScalar_impl_hpp__
12#define __Panzer_Integrator_DivBasisTimesScalar_impl_hpp__
21#include "Intrepid2_FunctionSpaceTools.hpp"
24#include "Sacado_Fad_Kokkos_ViewFactory.hpp"
39 template<
typename EvalT,
typename Traits>
43 const std::string& resName,
44 const std::string& valName,
47 const double& multiplier,
48 const std::vector<std::string>& fmNames
62 using std::invalid_argument;
63 using std::logic_error;
68 TEUCHOS_TEST_FOR_EXCEPTION(resName ==
"", invalid_argument,
"Error: " \
69 "Integrator_DivBasisTimesScalar called with an empty residual name.")
70 TEUCHOS_TEST_FOR_EXCEPTION(valName ==
"", invalid_argument,
"Error: " \
71 "Integrator_DivBasisTimesScalar called with an empty value name.")
72 RCP<const PureBasis> tmpBasis = basis.
getBasis();
73 TEUCHOS_TEST_FOR_EXCEPTION(not tmpBasis->supportsDiv(), logic_error,
74 "Error: Integrator_DivBasisTimesScalar: Basis of type \""
75 << tmpBasis->name() <<
"\" does not support DIV.")
76 TEUCHOS_TEST_FOR_EXCEPTION(not tmpBasis->requiresOrientations(), logic_error,
77 "Error: Integration_DivBasisTimesScalar: Basis of type \""
78 << tmpBasis->name() <<
"\" should require orientations.")
82 this->addDependentField(
scalar_);
88 this->addContributedField(
field_);
90 this->addEvaluatedField(
field_);
96 View<PHX::UnmanagedView<const ScalarT**>*>(
"DivBasisTimesScalar::KokkosFieldMultipliers",
98 for (
const auto& name : fmNames)
105 string n(
"Integrator_DivBasisTimesScalar (");
110 n +=
"): " +
field_.fieldTag().name();
119 template<
typename EvalT,
typename Traits>
122 const Teuchos::ParameterList& p)
126 p.get<
std::string>(
"Residual Name"),
127 p.get<
std::string>(
"Value Name"),
130 p.get<double>(
"Multiplier"),
132 (
"Field Multipliers") ?
134 (
"Field Multipliers")) :
std::vector<
std::string>())
136 using Teuchos::ParameterList;
141 p.validateParameters(*validParams);
149 template<
typename EvalT,
typename Traits>
156 using Sacado::createDynRankView;
163 kokkosFieldMults_h(i) =
fieldMults_[i].get_static_view();
169 if (!use_shared_memory) {
170 if (Sacado::IsADType<ScalarT>::value) {
171 const auto fadSize = Sacado::dimension_scalar(
field_.get_view());
172 tmp_ = PHX::View<ScalarT*>(
"panzer::Integrator::DivBasisTimesScalar::tmp_",
field_.extent(0),fadSize);
174 tmp_ = PHX::View<ScalarT*>(
"panzer::Integrator::DivBasisTimesScalar::tmp_",
field_.extent(0));
187 template<
typename EvalT,
typename Traits>
188 template<
int NUM_FIELD_MULT>
189 KOKKOS_INLINE_FUNCTION
194 const Kokkos::TeamPolicy<PHX::ExecutionSpace>::member_type& team)
const
197 const int cell = team.league_rank();
200 const int numQP(
scalar_.extent(1)), numBases(
basis_.extent(1));
202 Kokkos::parallel_for(Kokkos::TeamThreadRange(team,0,numBases), [&] (
const int basis) {
203 field_(cell, basis) = 0.0;
209 if constexpr (NUM_FIELD_MULT == 0)
214 for (
int qp(0); qp < numQP; ++qp)
216 Kokkos::parallel_for(Kokkos::TeamThreadRange(team,0,numBases), [&] (
const int basis) {
221 else if constexpr (NUM_FIELD_MULT == 1)
226 for (
int qp(0); qp < numQP; ++qp)
228 Kokkos::parallel_for(Kokkos::TeamThreadRange(team,0,numBases), [&] (
const int basis) {
240 for (
int qp(0); qp < numQP; ++qp)
246 if (team.team_rank() == 0) {
248 for (
int fm(0); fm < numFieldMults; ++fm)
252 Kokkos::parallel_for(Kokkos::TeamThreadRange(team,0,numBases),[&] (
const int& basis) {
264 template<
typename EvalT,
typename Traits>
265 template<
int NUM_FIELD_MULT>
266 KOKKOS_INLINE_FUNCTION
271 const Kokkos::TeamPolicy<PHX::ExecutionSpace>::member_type& team)
const
274 const int cell = team.league_rank();
275 const int numQP =
scalar_.extent(1);
276 const int numBases =
basis_.extent(1);
277 const int fadSize = Sacado::dimension_scalar(
field_.get_view());
281 if (Sacado::IsADType<ScalarT>::value) {
283 tmp_field =
scratch_view(team.team_shmem(),numBases,fadSize);
291 Kokkos::parallel_for(Kokkos::TeamThreadRange(team,0,numBases),[&] (
const int& basis) {
292 tmp_field(basis) = 0.0;
297 if constexpr (NUM_FIELD_MULT == 0)
302 for (
int qp(0); qp < numQP; ++qp)
304 Kokkos::parallel_for(Kokkos::TeamThreadRange(team,0,numBases),[&] (
const int& basis) {
309 else if constexpr (NUM_FIELD_MULT == 1)
314 for (
int qp(0); qp < numQP; ++qp)
316 Kokkos::parallel_for(Kokkos::TeamThreadRange(team,0,numBases),[&] (
const int& basis) {
328 for (
int qp(0); qp < numQP; ++qp)
334 if (team.team_rank() == 0) {
336 for (
int fm(0); fm < numFieldMults; ++fm)
340 Kokkos::parallel_for(Kokkos::TeamThreadRange(team,0,numBases),[&] (
const int& basis) {
341 tmp_field(basis) +=
basis_(cell, basis, qp) * tmp(0);
348 Kokkos::parallel_for(Kokkos::TeamThreadRange(team,0,numBases),[&] (
const int& basis) {
349 field_(cell,basis) = tmp_field(basis);
353 Kokkos::parallel_for(Kokkos::TeamThreadRange(team,0,numBases),[&] (
const int& basis) {
354 field_(cell,basis) += tmp_field(basis);
365 template<
typename EvalT,
typename Traits>
371 using Kokkos::parallel_for;
372 using Kokkos::TeamPolicy;
379 if (use_shared_memory) {
381 if (Sacado::IsADType<ScalarT>::value) {
382 const int fadSize = Sacado::dimension_scalar(
field_.get_view());
383 bytes = scratch_view::shmem_size(1,fadSize) + scratch_view::shmem_size(
basis_.extent(1),fadSize);
386 bytes = scratch_view::shmem_size(1) + scratch_view::shmem_size(
basis_.extent(1));
393 parallel_for(this->getName(), policy, *
this);
396 parallel_for(this->getName(), policy, *
this);
399 parallel_for(this->getName(), policy, *
this);
408 parallel_for(this->getName(), policy, *
this);
411 parallel_for(this->getName(), policy, *
this);
414 parallel_for(this->getName(), policy, *
this);
424 template<
typename EvalT,
typename TRAITS>
425 Teuchos::RCP<Teuchos::ParameterList>
432 using Teuchos::ParameterList;
437 RCP<ParameterList> p = rcp(
new ParameterList);
438 p->set<
string>(
"Residual Name",
"?");
439 p->set<
string>(
"Value Name",
"?");
440 p->set<
string>(
"Test Field Name",
"?");
441 RCP<BasisIRLayout> basis;
442 p->set(
"Basis", basis);
443 RCP<IntegrationRule> ir;
445 p->set<
double>(
"Multiplier", 1.0);
446 RCP<const vector<string>> fms;
447 p->set(
"Field Multipliers", fms);
Teuchos::RCP< PHX::DataLayout > functional
<Cell,Basis>
Teuchos::RCP< const PureBasis > getBasis() const
WorksetDetailsAccessor wda
static HP & inst()
Private ctor.
bool useSharedMemory() const
Kokkos::TeamPolicy< TeamPolicyProperties... > teamPolicy(const int &league_size)
Returns a TeamPolicy for hierarchic parallelism.
PHX::MDField< const ScalarT, Cell, IP > scalar_
A field representing the scalar function we're integrating ( ).
Teuchos::RCP< Teuchos::ParameterList > getValidParameters() const
Get Valid Parameters.
PHX::MDField< double, panzer::Cell, panzer::BASIS, panzer::IP > basis_
The scalar basis information necessary for integration.
Integrator_DivBasisTimesScalar(const panzer::EvaluatorStyle &evalStyle, const std::string &resName, const std::string &valName, const panzer::BasisIRLayout &basis, const panzer::IntegrationRule &ir, const double &multiplier=1, const std::vector< std::string > &fmNames=std::vector< std::string >())
Main Constructor.
void postRegistrationSetup(typename Traits::SetupData d, PHX::FieldManager< Traits > &fm)
Post-Registration Setup.
std::string basisName_
The name of the basis we're using.
void evaluateFields(typename Traits::EvalData d)
Evaluate Fields.
PHX::View< ScalarT * > tmp_
Temporary for non-shared calculations.
KOKKOS_INLINE_FUNCTION void operator()(const FieldMultTag< NUM_FIELD_MULT > &tag, const Kokkos::TeamPolicy< PHX::ExecutionSpace >::member_type &team) const
Perform the integration. Main memory version.
const panzer::EvaluatorStyle evalStyle_
An enum determining the behavior of this Evaluator.
Kokkos::View< ScalarT *,typename PHX::DevLayout< ScalarT >::type, typename PHX::ExecutionSpace::scratch_memory_space, Kokkos::MemoryUnmanaged > scratch_view
Type for shared memory.
double multiplier_
The scalar multiplier out in front of the integral ( ).
std::size_t basisIndex_
The index in the Workset bases for our particular BasisIRLayout name.
PHX::MDField< ScalarT, Cell, BASIS > field_
A field to which we'll contribute, or in which we'll store, the result of computing this integral.
PHX::View< PHX::UnmanagedView< const ScalarT ** > * > kokkosFieldMults_
The PHX::View representation of the (possibly empty) list of fields that are multipliers out in front...
typename EvalT::ScalarT ScalarT
The scalar type.
std::vector< PHX::MDField< const ScalarT, Cell, IP > > fieldMults_
The (possibly empty) list of fields that are multipliers out in front of the integral ( ,...
Teuchos::RCP< PHX::DataLayout > dl_scalar
Data layout for scalar fields.
Description and data layouts associated with a particular basis.
int num_cells
DEPRECATED - use: numCells().
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.
EvaluatorStyle
An indication of how an Evaluator will behave.
This empty struct allows us to optimize operator()() depending on the number of field multipliers.
This empty struct allows us to optimize operator()() depending on the number of field multipliers.
Teuchos::RCP< const std::vector< panzer::Workset > > worksets_
All worksets that will be evaluated over the lifetime of this evaluator.
const panzer::Workset & EvalData
Data type passed to PHX::Evaluator::evaluateFields(): a single workset holding the cell data for one ...
const SD & SetupData
Data type passed to PHX::Evaluator::postRegistrationSetup().