11 #ifndef PANZER_EVALUATOR_GRADBASISCROSSVECTOR_IMPL_HPP
12 #define PANZER_EVALUATOR_GRADBASISCROSSVECTOR_IMPL_HPP
21 #include "Intrepid2_FunctionSpaceTools.hpp"
24 #include "Kokkos_ViewFactory.hpp"
38 template<
typename EvalT,
typename Traits>
42 const std::vector<std::string>& resNames,
43 const std::string& vecName,
47 const std::vector<std::string>& fmNames,
51 evalStyle_(evalStyle),
52 multiplier_(multiplier),
53 numDims_(resNames.size()),
54 numGradDims_(ir.dl_vector->extent(2)),
55 basisName_(basis.name())
66 using std::invalid_argument;
67 using std::logic_error;
74 "Integrator_GradBasisCrossVector called with the number of residual " \
75 "names not equal to three.")
76 for (
const auto& name : resNames)
78 "Integrator_GradBasisCrossVector called with an empty residual name.")
80 "Integrator_GradBasisCrossVector called with an empty vector name.")
83 "Error: Integrator_GradBasisCrossVector: Basis of type \""
84 << tmpBasis->name() <<
"\" does not support the gradient operator.")
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.")
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>
159 p.get<
const std::vector<std::string>>(
"Residual Names"),
160 p.get<std::string>(
"Vector Name"),
163 p.get<double>(
"Multiplier"),
164 p.isType<Teuchos::
RCP<
const std::vector<std::string>>>
165 (
"Field Multipliers") ?
166 (*p.get<Teuchos::
RCP<
const std::vector<std::string>>>
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") :
185 template<
typename EvalT,
typename Traits>
196 auto fields_host_mirror_ = Kokkos::create_mirror_view(fields_);
197 for (
size_t i=0; i < fields_host_.size(); ++i) {
198 fields_host_mirror_(i) = fields_host_[i].get_static_view();
200 Kokkos::deep_copy(fields_,fields_host_mirror_);
203 auto field_mults_host_mirror_ = Kokkos::create_mirror_view(kokkosFieldMults_);
204 for (
size_t i=0; i < fieldMults_.size(); ++i)
205 field_mults_host_mirror_(i) = fieldMults_[i].get_static_view();
206 Kokkos::deep_copy(kokkosFieldMults_,field_mults_host_mirror_);
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)
241 if (numGradDims_ == 1)
243 for (
int qp(0); qp < numQP; ++qp)
245 tmp[Y] = multiplier_ * vector_(cell, qp, Y);
246 tmp[Z] = multiplier_ * vector_(cell, qp, Z);
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);
254 else if (numGradDims_ == 2)
256 for (
int qp(0); qp < numQP; ++qp)
258 tmp[X] = multiplier_ * vector_(cell, qp, X);
259 tmp[Y] = multiplier_ * vector_(cell, qp, Y);
260 tmp[Z] = multiplier_ * vector_(cell, qp, Z);
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);
270 else if (numGradDims_ == 3)
272 for (
int qp(0); qp < numQP; ++qp)
274 tmp[X] = multiplier_ * vector_(cell, qp, X);
275 tmp[Y] = multiplier_ * vector_(cell, qp, Y);
276 tmp[Z] = multiplier_ * vector_(cell, qp, Z);
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)
291 if (numGradDims_ == 1)
293 for (
int qp(0); qp < numQP; ++qp)
295 tmp[Y] = multiplier_ * kokkosFieldMults_(0)(cell, qp) *
296 vector_(cell, qp, Y);
297 tmp[Z] = multiplier_ * kokkosFieldMults_(0)(cell, qp) *
298 vector_(cell, qp, Z);
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);
306 else if (numGradDims_ == 2)
308 for (
int qp(0); qp < numQP; ++qp)
310 tmp[X] = multiplier_ * kokkosFieldMults_(0)(cell, qp) *
311 vector_(cell, qp, X);
312 tmp[Y] = multiplier_ * kokkosFieldMults_(0)(cell, qp) *
313 vector_(cell, qp, Y);
314 tmp[Z] = multiplier_ * kokkosFieldMults_(0)(cell, qp) *
315 vector_(cell, qp, Z);
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);
325 else if (numGradDims_ == 3)
327 for (
int qp(0); qp < numQP; ++qp)
329 tmp[X] = multiplier_ * kokkosFieldMults_(0)(cell, qp) *
330 vector_(cell, qp, X);
331 tmp[Y] = multiplier_ * kokkosFieldMults_(0)(cell, qp) *
332 vector_(cell, qp, Y);
333 tmp[Z] = multiplier_ * kokkosFieldMults_(0)(cell, qp) *
334 vector_(cell, qp, Z);
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);
349 const int numFieldMults(kokkosFieldMults_.extent(0));
350 if (numGradDims_ == 1)
352 for (
int qp(0); qp < numQP; ++qp)
354 tmp[Y] = multiplier_ * vector_(cell, qp, Y);
355 tmp[Z] = multiplier_ * vector_(cell, qp, Z);
356 for (
int fm(0); fm < numFieldMults; ++fm)
358 tmp[Y] *= kokkosFieldMults_(fm)(cell, qp);
359 tmp[Z] *= kokkosFieldMults_(fm)(cell, qp);
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);
368 else if (numGradDims_ == 2)
370 for (
int qp(0); qp < numQP; ++qp)
372 tmp[X] = multiplier_ * vector_(cell, qp, X);
373 tmp[Y] = multiplier_ * vector_(cell, qp, Y);
374 tmp[Z] = multiplier_ * vector_(cell, qp, Z);
375 for (
int fm(0); fm < numFieldMults; ++fm)
377 tmp[X] *= kokkosFieldMults_(fm)(cell, qp);
378 tmp[Y] *= kokkosFieldMults_(fm)(cell, qp);
379 tmp[Z] *= kokkosFieldMults_(fm)(cell, qp);
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);
390 else if (numGradDims_ == 3)
392 for (
int qp(0); qp < numQP; ++qp)
394 tmp[X] = multiplier_ * vector_(cell, qp, X);
395 tmp[Y] = multiplier_ * vector_(cell, qp, Y);
396 tmp[Z] = multiplier_ * vector_(cell, qp, Z);
397 for (
int fm(0); fm < numFieldMults; ++fm)
399 tmp[X] *= kokkosFieldMults_(fm)(cell, qp);
400 tmp[Y] *= kokkosFieldMults_(fm)(cell, qp);
401 tmp[Z] *= kokkosFieldMults_(fm)(cell, qp);
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;
432 basis_ = this->wda(workset).bases[basisIndex_]->weighted_grad_basis;
437 if (fieldMults_.size() == 0)
439 else if (fieldMults_.size() == 1)
450 template<
typename EvalT,
typename TRAITS>
468 p->set(
"Residual Names", resNames);
469 p->set<
string>(
"Vector Name",
"?");
471 p->set(
"Basis", basis);
474 p->set<
double>(
"Multiplier", 1.0);
476 p->set(
"Field Multipliers", fms);
478 p->set(
"Data Layout Vector", vecDL);
485 #endif // PANZER_EVALUATOR_GRADBASISCROSSVECTOR_IMPL_HPP
Kokkos::DynRankView< typename InputArray::value_type, PHX::Device > createDynRankView(const InputArray &a, const std::string &name, const DimensionPack...dims)
Wrapper to simplify Panzer use of Sacado ViewFactory.
int num_cells
DEPRECATED - use: numCells()
std::vector< PHX::MDField< const ScalarT, Cell, IP > > fieldMults_
The (possibly empty) list of fields that are multipliers 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.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
This empty struct allows us to optimize operator()() depending on the number of field multipliers...
EvaluatorStyle
An indication of how an Evaluator will behave.
const panzer::EvaluatorStyle evalStyle_
An enum determining the behavior of this Evaluator.
void evaluateFields(typename Traits::EvalData d)
Evaluate Fields.
Teuchos::RCP< Teuchos::ParameterList > getValidParameters() const
Get Valid Parameters.
Teuchos::RCP< const PureBasis > getBasis() const
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::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...
PHX::MDField< const ScalarT, Cell, IP, Dim > vector_
A field representing the vector-valued function we're integrating ( ).
double multiplier
The scalar multiplier out in front of the integral ( ).
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::RCP< PHX::DataLayout > dl_scalar
Data layout for scalar fields.
panzer::EvaluatorStyle evalStyle
The EvaluatorStyle of the parent Integrator_CurlBasisDotVector object.
typename EvalT::ScalarT ScalarT
The scalar type.
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.
void validateParameters(ParameterList const &validParamList, int const depth=1000, EValidateUsed const validateUsed=VALIDATE_USED_ENABLED, EValidateDefaults const validateDefaults=VALIDATE_DEFAULTS_ENABLED) const
Teuchos::RCP< PHX::DataLayout > dl_vector
Data layout for vector fields.
KOKKOS_INLINE_FUNCTION void operator()(const FieldMultTag< NUM_FIELD_MULT > &tag, const std::size_t &cell) const
Perform the integration.
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...
void postRegistrationSetup(typename Traits::SetupData d, PHX::FieldManager< Traits > &fm)
Post-Registration Setup.
const std::vector< std::pair< int, LocalOrdinal > > &pid_and_lid const
int numDims_
The number of dimensions associated with the vector.
int numGradDims_
The number of dimensions associated with the gradient.
PHX::View< InnerView * > OuterView
Teuchos::RCP< PHX::DataLayout > functional
<Cell,Basis>
Teuchos::RCP< const std::vector< panzer::Workset > > worksets_