43 #ifndef PANZER_EVALUATOR_GRADBASISCROSSVECTOR_IMPL_HPP
44 #define PANZER_EVALUATOR_GRADBASISCROSSVECTOR_IMPL_HPP
53 #include "Intrepid2_FunctionSpaceTools.hpp"
56 #include "Kokkos_ViewFactory.hpp"
70 template<
typename EvalT,
typename Traits>
74 const std::vector<std::string>& resNames,
75 const std::string& vecName,
79 const std::vector<std::string>& fmNames,
83 evalStyle_(evalStyle),
84 multiplier_(multiplier),
85 numDims_(resNames.size()),
86 numGradDims_(ir.dl_vector->extent(2)),
87 basisName_(basis.name())
98 using std::invalid_argument;
99 using std::logic_error;
106 "Integrator_GradBasisCrossVector called with the number of residual " \
107 "names not equal to three.")
108 for (
const auto& name : resNames)
110 "Integrator_GradBasisCrossVector called with an empty residual name.")
112 "Integrator_GradBasisCrossVector called with an empty vector name.")
115 "Error: Integrator_GradBasisCrossVector: Basis of type \""
116 << tmpBasis->name() <<
"\" does not support the gradient operator.")
122 tmpVecDL->extent(2) < ir.
dl_vector->extent(2), logic_error,
123 "Error: Integrator_GradBasisCrossVector: Dimension of space " \
124 "exceeds dimension of Vector Data Layout.")
126 static_cast<int>(vecDL->extent(2)), logic_error,
"Error: " \
127 "Integrator_GradBasisCrossVector: The vector must be the same " \
128 "length as the number of residuals.")
131 "Error: Integrator_GradBasisCrossVector: The vector must have at " \
132 "least as many components as there are dimensions in the mesh.")
135 vector_ = MDField<const ScalarT, Cell, IP, Dim>(vecName, tmpVecDL);
136 this->addDependentField(
vector_);
141 fields_ =
OuterView(
"Integrator_GradBasisCrossVector::fields_", resNames.size());
144 for (
const auto& name : resNames)
148 for (std::size_t i=0; i<
fields_.extent(0); ++i) {
151 this->addContributedField(
field);
153 this->addEvaluatedField(
field);
159 kokkosFieldMults_ = PHX::View<PHX::UnmanagedView<const ScalarT**>*>(
"GradBasisCrossVector::KokkosFieldMultipliers", fmNames.size());
160 for (
const auto& name : fmNames)
167 string n(
"Integrator_GradBasisCrossVector (");
174 n += resNames[j] +
", ";
175 n += resNames[resNames.size()-1] +
"}";
184 template<
typename EvalT,
typename Traits>
191 p.get<
const std::vector<std::string>>(
"Residual Names"),
192 p.get<std::string>(
"Vector Name"),
195 p.get<double>(
"Multiplier"),
196 p.isType<Teuchos::
RCP<
const std::vector<std::string>>>
197 (
"Field Multipliers") ?
198 (*p.get<Teuchos::
RCP<
const std::vector<std::string>>>
199 (
"Field Multipliers")) : std::vector<std::string>(),
200 p.isType<Teuchos::
RCP<PHX::DataLayout>>(
"Data Layout Vector") ?
201 p.get<Teuchos::
RCP<PHX::DataLayout>>(
"Data Layout Vector") :
217 template<
typename EvalT,
typename Traits>
228 auto fields_host_mirror_ = Kokkos::create_mirror_view(fields_);
229 for (
size_t i=0; i < fields_host_.size(); ++i) {
230 fields_host_mirror_(i) = fields_host_[i].get_static_view();
232 Kokkos::deep_copy(fields_,fields_host_mirror_);
235 auto field_mults_host_mirror_ = Kokkos::create_mirror_view(kokkosFieldMults_);
236 for (
size_t i=0; i < fieldMults_.size(); ++i)
237 field_mults_host_mirror_(i) = fieldMults_[i].get_static_view();
238 Kokkos::deep_copy(kokkosFieldMults_,field_mults_host_mirror_);
249 template<
typename EvalT,
typename Traits>
250 template<
int NUM_FIELD_MULT>
251 KOKKOS_INLINE_FUNCTION
256 const size_t& cell)
const
261 const int numBases(fields_[0].extent(1)), numQP(vector_.extent(1));
263 for (
int dim(0); dim < numDims_; ++dim)
264 for (
int basis(0); basis < numBases; ++basis)
265 fields_[dim](cell, basis) = 0.0;
270 const int X(0), Y(1), Z(2);
271 if (NUM_FIELD_MULT == 0)
273 if (numGradDims_ == 1)
275 for (
int qp(0); qp < numQP; ++qp)
277 tmp[Y] = multiplier_ * vector_(cell, qp, Y);
278 tmp[Z] = multiplier_ * vector_(cell, qp, Z);
279 for (
int basis(0); basis < numBases; ++basis)
281 fields_[Y](cell, basis) += tmp[Z] * basis_(cell, basis, qp, X);
282 fields_[Z](cell, basis) += -tmp[Y] * basis_(cell, basis, qp, X);
286 else if (numGradDims_ == 2)
288 for (
int qp(0); qp < numQP; ++qp)
290 tmp[X] = multiplier_ * vector_(cell, qp, X);
291 tmp[Y] = multiplier_ * vector_(cell, qp, Y);
292 tmp[Z] = multiplier_ * vector_(cell, qp, Z);
293 for (
int basis(0); basis < numBases; ++basis)
295 fields_[X](cell, basis) += -tmp[Z] * basis_(cell, basis, qp, Y);
296 fields_[Y](cell, basis) += tmp[Z] * basis_(cell, basis, qp, X);
297 fields_[Z](cell, basis) += tmp[X] * basis_(cell, basis, qp, Y) -
298 tmp[Y] * basis_(cell, basis, qp, X);
302 else if (numGradDims_ == 3)
304 for (
int qp(0); qp < numQP; ++qp)
306 tmp[X] = multiplier_ * vector_(cell, qp, X);
307 tmp[Y] = multiplier_ * vector_(cell, qp, Y);
308 tmp[Z] = multiplier_ * vector_(cell, qp, Z);
309 for (
int basis(0); basis < numBases; ++basis)
311 fields_[X](cell, basis) += tmp[Y] * basis_(cell, basis, qp, Z) -
312 tmp[Z] * basis_(cell, basis, qp, Y);
313 fields_[Y](cell, basis) += tmp[Z] * basis_(cell, basis, qp, X) -
314 tmp[X] * basis_(cell, basis, qp, Z);
315 fields_[Z](cell, basis) += tmp[X] * basis_(cell, basis, qp, Y) -
316 tmp[Y] * basis_(cell, basis, qp, X);
321 else if (NUM_FIELD_MULT == 1)
323 if (numGradDims_ == 1)
325 for (
int qp(0); qp < numQP; ++qp)
327 tmp[Y] = multiplier_ * kokkosFieldMults_(0)(cell, qp) *
328 vector_(cell, qp, Y);
329 tmp[Z] = multiplier_ * kokkosFieldMults_(0)(cell, qp) *
330 vector_(cell, qp, Z);
331 for (
int basis(0); basis < numBases; ++basis)
333 fields_[Y](cell, basis) += tmp[Z] * basis_(cell, basis, qp, X);
334 fields_[Z](cell, basis) += -tmp[Y] * basis_(cell, basis, qp, X);
338 else if (numGradDims_ == 2)
340 for (
int qp(0); qp < numQP; ++qp)
342 tmp[X] = multiplier_ * kokkosFieldMults_(0)(cell, qp) *
343 vector_(cell, qp, X);
344 tmp[Y] = multiplier_ * kokkosFieldMults_(0)(cell, qp) *
345 vector_(cell, qp, Y);
346 tmp[Z] = multiplier_ * kokkosFieldMults_(0)(cell, qp) *
347 vector_(cell, qp, Z);
348 for (
int basis(0); basis < numBases; ++basis)
350 fields_[X](cell, basis) += -tmp[Z] * basis_(cell, basis, qp, Y);
351 fields_[Y](cell, basis) += tmp[Z] * basis_(cell, basis, qp, X);
352 fields_[Z](cell, basis) += tmp[X] * basis_(cell, basis, qp, Y) -
353 tmp[Y] * basis_(cell, basis, qp, X);
357 else if (numGradDims_ == 3)
359 for (
int qp(0); qp < numQP; ++qp)
361 tmp[X] = multiplier_ * kokkosFieldMults_(0)(cell, qp) *
362 vector_(cell, qp, X);
363 tmp[Y] = multiplier_ * kokkosFieldMults_(0)(cell, qp) *
364 vector_(cell, qp, Y);
365 tmp[Z] = multiplier_ * kokkosFieldMults_(0)(cell, qp) *
366 vector_(cell, qp, Z);
367 for (
int basis(0); basis < numBases; ++basis)
369 fields_[X](cell, basis) += tmp[Y] * basis_(cell, basis, qp, Z) -
370 tmp[Z] * basis_(cell, basis, qp, Y);
371 fields_[Y](cell, basis) += tmp[Z] * basis_(cell, basis, qp, X) -
372 tmp[X] * basis_(cell, basis, qp, Z);
373 fields_[Z](cell, basis) += tmp[X] * basis_(cell, basis, qp, Y) -
374 tmp[Y] * basis_(cell, basis, qp, X);
381 const int numFieldMults(kokkosFieldMults_.extent(0));
382 if (numGradDims_ == 1)
384 for (
int qp(0); qp < numQP; ++qp)
386 tmp[Y] = multiplier_ * vector_(cell, qp, Y);
387 tmp[Z] = multiplier_ * vector_(cell, qp, Z);
388 for (
int fm(0); fm < numFieldMults; ++fm)
390 tmp[Y] *= kokkosFieldMults_(fm)(cell, qp);
391 tmp[Z] *= kokkosFieldMults_(fm)(cell, qp);
393 for (
int basis(0); basis < numBases; ++basis)
395 fields_[Y](cell, basis) += tmp[Z] * basis_(cell, basis, qp, X);
396 fields_[Z](cell, basis) += -tmp[Y] * basis_(cell, basis, qp, X);
400 else if (numGradDims_ == 2)
402 for (
int qp(0); qp < numQP; ++qp)
404 tmp[X] = multiplier_ * vector_(cell, qp, X);
405 tmp[Y] = multiplier_ * vector_(cell, qp, Y);
406 tmp[Z] = multiplier_ * vector_(cell, qp, Z);
407 for (
int fm(0); fm < numFieldMults; ++fm)
409 tmp[X] *= kokkosFieldMults_(fm)(cell, qp);
410 tmp[Y] *= kokkosFieldMults_(fm)(cell, qp);
411 tmp[Z] *= kokkosFieldMults_(fm)(cell, qp);
413 for (
int basis(0); basis < numBases; ++basis)
415 fields_[X](cell, basis) += -tmp[Z] * basis_(cell, basis, qp, Y);
416 fields_[Y](cell, basis) += tmp[Z] * basis_(cell, basis, qp, X);
417 fields_[Z](cell, basis) += tmp[X] * basis_(cell, basis, qp, Y) -
418 tmp[Y] * basis_(cell, basis, qp, X);
422 else if (numGradDims_ == 3)
424 for (
int qp(0); qp < numQP; ++qp)
426 tmp[X] = multiplier_ * vector_(cell, qp, X);
427 tmp[Y] = multiplier_ * vector_(cell, qp, Y);
428 tmp[Z] = multiplier_ * vector_(cell, qp, Z);
429 for (
int fm(0); fm < numFieldMults; ++fm)
431 tmp[X] *= kokkosFieldMults_(fm)(cell, qp);
432 tmp[Y] *= kokkosFieldMults_(fm)(cell, qp);
433 tmp[Z] *= kokkosFieldMults_(fm)(cell, qp);
435 for (
int basis(0); basis < numBases; ++basis)
437 fields_[X](cell, basis) += tmp[Y] * basis_(cell, basis, qp, Z) -
438 tmp[Z] * basis_(cell, basis, qp, Y);
439 fields_[Y](cell, basis) += tmp[Z] * basis_(cell, basis, qp, X) -
440 tmp[X] * basis_(cell, basis, qp, Z);
441 fields_[Z](cell, basis) += tmp[X] * basis_(cell, basis, qp, Y) -
442 tmp[Y] * basis_(cell, basis, qp, X);
454 template<
typename EvalT,
typename Traits>
460 using Kokkos::parallel_for;
461 using Kokkos::RangePolicy;
464 basis_ = this->wda(workset).bases[basisIndex_]->weighted_grad_basis;
469 if (fieldMults_.size() == 0)
471 else if (fieldMults_.size() == 1)
482 template<
typename EvalT,
typename TRAITS>
500 p->set(
"Residual Names", resNames);
501 p->set<
string>(
"Vector Name",
"?");
503 p->set(
"Basis", basis);
506 p->set<
double>(
"Multiplier", 1.0);
508 p->set(
"Field Multipliers", fms);
510 p->set(
"Data Layout Vector", vecDL);
517 #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_