11#ifndef PANZER_EVALUATOR_GRADBASISCROSSVECTOR_IMPL_HPP
12#define PANZER_EVALUATOR_GRADBASISCROSSVECTOR_IMPL_HPP
21#include "Intrepid2_FunctionSpaceTools.hpp"
24#include "Sacado_Fad_Kokkos_ViewFactory.hpp"
38 template<
typename EvalT,
typename Traits>
42 const std::vector<std::string>& resNames,
43 const std::string& vecName,
46 const double& multiplier,
47 const std::vector<std::string>& fmNames,
49 const Teuchos::RCP<PHX::DataLayout>& vecDL )
62 using PHX::DataLayout;
66 using std::invalid_argument;
67 using std::logic_error;
73 TEUCHOS_TEST_FOR_EXCEPTION(
numDims_ != 3, invalid_argument,
"Error: " \
74 "Integrator_GradBasisCrossVector called with the number of residual " \
75 "names not equal to three.")
76 for (
const auto& name : resNames)
77 TEUCHOS_TEST_FOR_EXCEPTION(name ==
"", invalid_argument,
"Error: " \
78 "Integrator_GradBasisCrossVector called with an empty residual name.")
79 TEUCHOS_TEST_FOR_EXCEPTION(vecName ==
"", invalid_argument,
"Error: " \
80 "Integrator_GradBasisCrossVector called with an empty vector name.")
81 RCP<const PureBasis> tmpBasis = basis.
getBasis();
82 TEUCHOS_TEST_FOR_EXCEPTION(not tmpBasis->supportsGrad(), logic_error,
83 "Error: Integrator_GradBasisCrossVector: Basis of type \""
84 << tmpBasis->name() <<
"\" does not support the gradient operator.")
86 if (not vecDL.is_null())
89 TEUCHOS_TEST_FOR_EXCEPTION(
90 tmpVecDL->extent(2) < ir.
dl_vector->extent(2), logic_error,
91 "Error: Integrator_GradBasisCrossVector: Dimension of space " \
92 "exceeds dimension of Vector Data Layout.")
93 TEUCHOS_TEST_FOR_EXCEPTION(
numDims_ !=
94 static_cast<int>(vecDL->extent(2)), logic_error,
"Error: " \
95 "Integrator_GradBasisCrossVector: The vector must be the same " \
96 "length as the number of residuals.")
99 "Error: Integrator_GradBasisCrossVector: The vector must have at " \
100 "least as many components as there are dimensions in the mesh.")
103 vector_ = MDField<const ScalarT, Cell, IP, Dim>(vecName, tmpVecDL);
104 this->addDependentField(
vector_);
109 fields_ =
OuterView(
"Integrator_GradBasisCrossVector::fields_", resNames.size());
112 for (
const auto& name : resNames)
116 for (std::size_t i=0; i<
fields_.extent(0); ++i) {
119 this->addContributedField(field);
121 this->addEvaluatedField(field);
127 kokkosFieldMults_ = PHX::View<PHX::UnmanagedView<const ScalarT**>*>(
"GradBasisCrossVector::KokkosFieldMultipliers", fmNames.size());
128 for (
const auto& name : fmNames)
135 string n(
"Integrator_GradBasisCrossVector (");
142 n += resNames[j] +
", ";
143 n += resNames[resNames.size()-1] +
"}";
152 template<
typename EvalT,
typename Traits>
155 const Teuchos::ParameterList& p)
159 p.get<const
std::vector<
std::string>>(
"Residual Names"),
160 p.get<
std::string>(
"Vector Name"),
163 p.get<double>(
"Multiplier"),
165 (
"Field Multipliers") ?
167 (
"Field Multipliers")) :
std::vector<
std::string>(),
168 p.isType<
Teuchos::RCP<
PHX::DataLayout>>(
"Data Layout Vector") ?
169 p.get<
Teuchos::RCP<
PHX::DataLayout>>(
"Data Layout Vector") :
172 using Teuchos::ParameterList;
177 p.validateParameters(*validParams);
185 template<
typename EvalT,
typename Traits>
192 using Sacado::createDynRankView;
196 auto fields_host_mirror_ = Kokkos::create_mirror_view(
fields_);
198 fields_host_mirror_(i) =
fields_host_[i].get_static_view();
200 Kokkos::deep_copy(
fields_,fields_host_mirror_);
205 field_mults_host_mirror_(i) =
fieldMults_[i].get_static_view();
217 template<
typename EvalT,
typename Traits>
218 template<
int NUM_FIELD_MULT>
219 KOKKOS_INLINE_FUNCTION
224 const size_t& cell)
const
229 const int numBases(
fields_[0].extent(1)), numQP(
vector_.extent(1));
231 for (
int dim(0); dim <
numDims_; ++dim)
232 for (
int basis(0); basis < numBases; ++basis)
233 fields_[dim](cell, basis) = 0.0;
238 const int X(0), Y(1), Z(2);
239 if (NUM_FIELD_MULT == 0)
243 for (
int qp(0); qp < numQP; ++qp)
247 for (
int basis(0); basis < numBases; ++basis)
249 fields_[Y](cell, basis) += tmp[Z] *
basis_(cell, basis, qp, X);
250 fields_[Z](cell, basis) += -tmp[Y] *
basis_(cell, basis, qp, X);
256 for (
int qp(0); qp < numQP; ++qp)
261 for (
int basis(0); basis < numBases; ++basis)
263 fields_[X](cell, basis) += -tmp[Z] *
basis_(cell, basis, qp, Y);
264 fields_[Y](cell, basis) += tmp[Z] *
basis_(cell, basis, qp, X);
265 fields_[Z](cell, basis) += tmp[X] *
basis_(cell, basis, qp, Y) -
266 tmp[Y] *
basis_(cell, basis, qp, X);
272 for (
int qp(0); qp < numQP; ++qp)
277 for (
int basis(0); basis < numBases; ++basis)
279 fields_[X](cell, basis) += tmp[Y] *
basis_(cell, basis, qp, Z) -
280 tmp[Z] *
basis_(cell, basis, qp, Y);
281 fields_[Y](cell, basis) += tmp[Z] *
basis_(cell, basis, qp, X) -
282 tmp[X] *
basis_(cell, basis, qp, Z);
283 fields_[Z](cell, basis) += tmp[X] *
basis_(cell, basis, qp, Y) -
284 tmp[Y] *
basis_(cell, basis, qp, X);
289 else if (NUM_FIELD_MULT == 1)
293 for (
int qp(0); qp < numQP; ++qp)
299 for (
int basis(0); basis < numBases; ++basis)
301 fields_[Y](cell, basis) += tmp[Z] *
basis_(cell, basis, qp, X);
302 fields_[Z](cell, basis) += -tmp[Y] *
basis_(cell, basis, qp, X);
308 for (
int qp(0); qp < numQP; ++qp)
316 for (
int basis(0); basis < numBases; ++basis)
318 fields_[X](cell, basis) += -tmp[Z] *
basis_(cell, basis, qp, Y);
319 fields_[Y](cell, basis) += tmp[Z] *
basis_(cell, basis, qp, X);
320 fields_[Z](cell, basis) += tmp[X] *
basis_(cell, basis, qp, Y) -
321 tmp[Y] *
basis_(cell, basis, qp, X);
327 for (
int qp(0); qp < numQP; ++qp)
335 for (
int basis(0); basis < numBases; ++basis)
337 fields_[X](cell, basis) += tmp[Y] *
basis_(cell, basis, qp, Z) -
338 tmp[Z] *
basis_(cell, basis, qp, Y);
339 fields_[Y](cell, basis) += tmp[Z] *
basis_(cell, basis, qp, X) -
340 tmp[X] *
basis_(cell, basis, qp, Z);
341 fields_[Z](cell, basis) += tmp[X] *
basis_(cell, basis, qp, Y) -
342 tmp[Y] *
basis_(cell, basis, qp, X);
352 for (
int qp(0); qp < numQP; ++qp)
356 for (
int fm(0); fm < numFieldMults; ++fm)
361 for (
int basis(0); basis < numBases; ++basis)
363 fields_[Y](cell, basis) += tmp[Z] *
basis_(cell, basis, qp, X);
364 fields_[Z](cell, basis) += -tmp[Y] *
basis_(cell, basis, qp, X);
370 for (
int qp(0); qp < numQP; ++qp)
375 for (
int fm(0); fm < numFieldMults; ++fm)
381 for (
int basis(0); basis < numBases; ++basis)
383 fields_[X](cell, basis) += -tmp[Z] *
basis_(cell, basis, qp, Y);
384 fields_[Y](cell, basis) += tmp[Z] *
basis_(cell, basis, qp, X);
385 fields_[Z](cell, basis) += tmp[X] *
basis_(cell, basis, qp, Y) -
386 tmp[Y] *
basis_(cell, basis, qp, X);
392 for (
int qp(0); qp < numQP; ++qp)
397 for (
int fm(0); fm < numFieldMults; ++fm)
403 for (
int basis(0); basis < numBases; ++basis)
405 fields_[X](cell, basis) += tmp[Y] *
basis_(cell, basis, qp, Z) -
406 tmp[Z] *
basis_(cell, basis, qp, Y);
407 fields_[Y](cell, basis) += tmp[Z] *
basis_(cell, basis, qp, X) -
408 tmp[X] *
basis_(cell, basis, qp, Z);
409 fields_[Z](cell, basis) += tmp[X] *
basis_(cell, basis, qp, Y) -
410 tmp[Y] *
basis_(cell, basis, qp, X);
422 template<
typename EvalT,
typename Traits>
428 using Kokkos::parallel_for;
429 using Kokkos::RangePolicy;
450 template<
typename EvalT,
typename TRAITS>
451 Teuchos::RCP<Teuchos::ParameterList>
457 using PHX::DataLayout;
460 using Teuchos::ParameterList;
465 RCP<ParameterList> p = rcp(
new ParameterList);
467 RCP<const vector<string>> resNames;
468 p->set(
"Residual Names", resNames);
469 p->set<
string>(
"Vector Name",
"?");
470 RCP<BasisIRLayout> basis;
471 p->set(
"Basis", basis);
472 RCP<IntegrationRule> ir;
474 p->set<
double>(
"Multiplier", 1.0);
475 RCP<const vector<string>> fms;
476 p->set(
"Field Multipliers", fms);
477 RCP<DataLayout> vecDL;
478 p->set(
"Data Layout Vector", vecDL);
Teuchos::RCP< PHX::DataLayout > functional
<Cell,Basis>
Teuchos::RCP< const PureBasis > getBasis() const
WorksetDetailsAccessor wda
PHX::MDField< const ScalarT, Cell, IP, Dim > vector_
A field representing the vector-valued function we're integrating ( ).
PHX::View< InnerView * > OuterView
Teuchos::RCP< Teuchos::ParameterList > getValidParameters() const
Get Valid Parameters.
std::vector< PHX::MDField< const ScalarT, Cell, IP > > fieldMults_
The (possibly empty) list of fields that are multipliers out in front of the integral ( ,...
void evaluateFields(typename Traits::EvalData d)
Evaluate Fields.
void postRegistrationSetup(typename Traits::SetupData d, PHX::FieldManager< Traits > &fm)
Post-Registration Setup.
PHX::View< PHX::UnmanagedView< const ScalarT ** > * > kokkosFieldMults_
The PHX::View representation of the (possibly empty) list of fields that are multipliers out in front...
std::size_t basisIndex_
The index in the Workset bases for our particular BasisIRLayout name.
typename EvalT::ScalarT ScalarT
The scalar type.
std::string basisName_
The name of the basis we're using.
PHX::MDField< double, panzer::Cell, panzer::BASIS, panzer::IP, panzer::Dim > basis_
The gradient vector basis information necessary for integration.
double multiplier_
The scalar multiplier out in front of the integral ( ).
Integrator_GradBasisCrossVector(const panzer::EvaluatorStyle &evalStyle, const std::vector< std::string > &resNames, const std::string &vecName, 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.
const panzer::EvaluatorStyle evalStyle_
An enum determining the behavior of this Evaluator.
int numDims_
The number of dimensions associated with the vector.
KOKKOS_INLINE_FUNCTION void operator()(const FieldMultTag< NUM_FIELD_MULT > &tag, const std::size_t &cell) const
Perform the integration.
std::vector< PHX::MDField< ScalarT, Cell, BASIS > > fields_host_
The fields to which we'll contribute, or in which we'll store, the result of computing this integral.
int numGradDims_
The number of dimensions associated with the gradient.
Teuchos::RCP< PHX::DataLayout > dl_vector
Data layout for vector fields.
Teuchos::RCP< PHX::DataLayout > dl_scalar
Data layout for scalar fields.
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.
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().