50 #ifndef Intrepid2_VectorData_h
51 #define Intrepid2_VectorData_h
64 template<
class Scalar,
typename DeviceType>
69 using FamilyVectorArray = Kokkos::Array< VectorArray, Parameters::MaxTensorComponents>;
71 FamilyVectorArray vectorComponents_;
72 bool axialComponents_;
75 Kokkos::Array<int, Parameters::MaxVectorComponents> dimToComponent_;
76 Kokkos::Array<int, Parameters::MaxVectorComponents> dimToComponentDim_;
77 Kokkos::Array<int, Parameters::MaxVectorComponents> numDimsForComponent_;
79 Kokkos::Array<int,Parameters::MaxTensorComponents> familyFieldUpperBound_;
81 unsigned numFamilies_;
82 unsigned numComponents_;
90 int lastFieldUpperBound = 0;
92 axialComponents_ =
true;
93 for (
unsigned i=0; i<numFamilies_; i++)
95 bool validEntryFoundForFamily =
false;
97 for (
unsigned j=0; j<numComponents_; j++)
99 if (vectorComponents_[i][j].
isValid())
101 if (!validEntryFoundForFamily)
103 numFieldsInFamily = vectorComponents_[i][j].extent_int(0);
104 validEntryFoundForFamily =
true;
108 INTREPID2_TEST_FOR_EXCEPTION(numFieldsInFamily != vectorComponents_[i][j].
extent_int(0), std::invalid_argument,
"Each valid TensorData entry within a family must agree with the others on the number of fields in the family");
112 numPoints = vectorComponents_[i][j].extent_int(1);
116 INTREPID2_TEST_FOR_EXCEPTION(numPoints != vectorComponents_[i][j].
extent_int(1), std::invalid_argument,
"Each valid TensorData entry must agree with the others on the number of points");
121 axialComponents_ =
false;
126 familyFieldUpperBound_[i] = lastFieldUpperBound;
127 INTREPID2_TEST_FOR_EXCEPTION(!validEntryFoundForFamily, std::invalid_argument,
"Each family must have at least one valid TensorData entry");
132 for (
unsigned j=0; j<numComponents_; j++)
134 bool validEntryFoundForComponent =
false;
136 for (
unsigned i=0; i<numFamilies_; i++)
138 if (vectorComponents_[i][j].
isValid())
140 if (!validEntryFoundForComponent)
142 validEntryFoundForComponent =
true;
143 numDimsForComponent = vectorComponents_[i][j].extent_int(2);
147 INTREPID2_TEST_FOR_EXCEPTION(numDimsForComponent != vectorComponents_[i][j].
extent_int(2), std::invalid_argument,
"Components in like positions must agree across families on the number of dimensions spanned by that component position");
151 if (!validEntryFoundForComponent)
154 numDimsForComponent = 1;
161 totalDimension_ = currentDim;
164 for (
unsigned j=0; j<numComponents_; j++)
169 dimToComponent_[currentDim+dim] = j;
170 dimToComponentDim_[currentDim+dim] = dim;
183 template<
size_t numFamilies,
size_t numComponents>
195 vectorComponents_[i][j] = vectorComponents[i][j];
209 numFamilies_ = vectorComponents.size();
210 INTREPID2_TEST_FOR_EXCEPTION(numFamilies_ <= 0, std::invalid_argument,
"numFamilies must be at least 1");
211 numComponents_ = vectorComponents[0].size();
212 for (
unsigned i=1; i<numFamilies_; i++)
214 INTREPID2_TEST_FOR_EXCEPTION(vectorComponents[i].size() != numComponents_, std::invalid_argument,
"each family must have the same number of components");
217 INTREPID2_TEST_FOR_EXCEPTION(numFamilies_ >
Parameters::MaxTensorComponents, std::invalid_argument,
"numFamilies must be at most Parameters::MaxTensorComponents");
218 INTREPID2_TEST_FOR_EXCEPTION(numComponents_ >
Parameters::MaxVectorComponents, std::invalid_argument,
"numComponents must be at most Parameters::MaxVectorComponents");
219 for (
unsigned i=0; i<numFamilies_; i++)
221 for (
unsigned j=0; j<numComponents_; j++)
223 vectorComponents_[i][j] = vectorComponents[i][j];
236 template<
size_t numComponents>
243 for (
unsigned d=0; d<numComponents_; d++)
245 vectorComponents_[d][d] = vectorComponents[d];
252 for (
unsigned d=0; d<numComponents_; d++)
254 vectorComponents_[0][d] = vectorComponents[d];
268 : numComponents_(vectorComponents.size())
272 numFamilies_ = numComponents_;
273 for (
unsigned d=0; d<numComponents_; d++)
275 vectorComponents_[d][d] = vectorComponents[d];
281 for (
unsigned d=0; d<numComponents_; d++)
283 vectorComponents_[0][d] = vectorComponents[d];
290 template<typename OtherDeviceType, class = typename std::enable_if< std::is_same<typename DeviceType::memory_space, typename OtherDeviceType::memory_space>::value>::type,
291 class = typename std::enable_if<!std::is_same<DeviceType,OtherDeviceType>::value>::type>
292 VectorData(const VectorData<Scalar,OtherDeviceType> &vectorData)
294 numFamilies_(vectorData.numFamilies()),
295 numComponents_(vectorData.numComponents())
297 if (vectorData.isValid())
299 for (
unsigned i=0; i<numFamilies_; i++)
301 for (
unsigned j=0; j<numComponents_; j++)
303 vectorComponents_[i][j] = vectorData.
getComponent(i, j);
311 template<typename OtherDeviceType, class = typename std::enable_if<!std::is_same<typename DeviceType::memory_space, typename OtherDeviceType::memory_space>::value>::type>
319 for (
unsigned i=0; i<numFamilies_; i++)
321 for (
unsigned j=0; j<numComponents_; j++)
323 vectorComponents_[i][j] = vectorData.
getComponent(i, j);
345 numFamilies_(0), numComponents_(0)
349 KOKKOS_INLINE_FUNCTION
352 return axialComponents_;
356 KOKKOS_INLINE_FUNCTION
359 return numDimsForComponent_[componentOrdinal];
363 KOKKOS_INLINE_FUNCTION
366 return familyFieldUpperBound_[numFamilies_-1];
370 KOKKOS_INLINE_FUNCTION
373 return (familyOrdinal == 0) ? 0 : familyFieldUpperBound_[familyOrdinal-1];
377 KOKKOS_INLINE_FUNCTION
384 KOKKOS_INLINE_FUNCTION
387 return totalDimension_;
391 KOKKOS_INLINE_FUNCTION
392 Scalar
operator()(
const int &fieldOrdinal,
const int &pointOrdinal,
const int &dim)
const
394 int fieldOrdinalInFamily = fieldOrdinal;
395 int familyForField = 0;
396 if (numFamilies_ > 1)
399 int previousFamilyEnd = -1;
400 int fieldAdjustment = 0;
402 for (
unsigned family=0; family<numFamilies_; family++)
404 const bool fieldInRange = (fieldOrdinal > previousFamilyEnd) && (fieldOrdinal < familyFieldUpperBound_[family]);
405 familyForField = fieldInRange ? family : familyForField;
406 fieldAdjustment = fieldInRange ? previousFamilyEnd + 1 : fieldAdjustment;
407 previousFamilyEnd = familyFieldUpperBound_[family] - 1;
409 #ifdef HAVE_INTREPID2_DEBUG
413 fieldOrdinalInFamily = fieldOrdinal - fieldAdjustment;
416 const int componentOrdinal = dimToComponent_[dim];
418 const auto &component = vectorComponents_[familyForField][componentOrdinal];
419 if (component.isValid())
421 const int componentRank = component.rank();
422 if (componentRank == 2)
424 return component(fieldOrdinalInFamily,pointOrdinal);
426 else if (componentRank == 3)
428 return component(fieldOrdinalInFamily,pointOrdinal,dimToComponentDim_[dim]);
446 KOKKOS_INLINE_FUNCTION
449 if (axialComponents_)
451 return vectorComponents_[componentOrdinal][componentOrdinal];
453 else if (numFamilies_ == 1)
455 return vectorComponents_[0][componentOrdinal];
462 return vectorComponents_[6][6];
470 KOKKOS_INLINE_FUNCTION
478 return vectorComponents_[familyOrdinal][componentOrdinal];
482 KOKKOS_INLINE_FUNCTION
488 else if (r == 2)
return totalDimension_;
489 else if (r > 2)
return 1;
496 KOKKOS_INLINE_FUNCTION
506 return numComponents_;
518 int matchingFamily = -1;
521 for (
int i=0; i<numFamilies_; i++)
523 const bool fieldIsBeyondPreviousFamily = (fieldOrdinal >= fieldsSoFar);
525 const bool fieldIsBeforeCurrentFamily = (fieldOrdinal < fieldsSoFar);
526 const bool fieldMatchesFamily = fieldIsBeyondPreviousFamily && fieldIsBeforeCurrentFamily;
527 matchingFamily = fieldMatchesFamily ? i : matchingFamily;
529 return matchingFamily;
537 for (
unsigned componentOrdinal=0; componentOrdinal<numComponents_; componentOrdinal++)
539 numFields = vectorComponents_[familyOrdinal][componentOrdinal].isValid() ? vectorComponents_[familyOrdinal][componentOrdinal].extent_int(0) :
numFields;
546 KOKKOS_INLINE_FUNCTION constexpr
bool isValid()
const
548 return numComponents_ > 0;
KOKKOS_INLINE_FUNCTION Scalar operator()(const int &fieldOrdinal, const int &pointOrdinal, const int &dim) const
Accessor for the container, which has shape (F,P,D).
KOKKOS_INLINE_FUNCTION int numFields() const
Returns the total number of fields; corresponds to the first dimension of this container.
KOKKOS_INLINE_FUNCTION int numFieldsInFamily(const unsigned &familyOrdinal) const
returns the number of fields in the specified family
VectorData(Kokkos::Array< Kokkos::Array< TensorData< Scalar, DeviceType >, numComponents >, numFamilies > vectorComponents)
Standard constructor for the arbitrary case, accepting a fixed-length array argument.
#define INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(test, x, msg)
VectorData(const std::vector< std::vector< TensorData< Scalar, DeviceType > > > &vectorComponents)
Standard constructor for the arbitrary case, accepting a variable-length std::vector argument...
VectorData(Kokkos::Array< TensorData< Scalar, DeviceType >, numComponents > vectorComponents, bool axialComponents)
Simplified constructor for gradients of HGRAD, and values of HDIV and HCURL vector bases...
void initialize()
Initialize members based on constructor parameters; all constructors should call this after populatin...
VectorData(Data< Scalar, DeviceType > data)
Simple 1-argument constructor for the case of trivial tensor product structure. The argument should h...
KOKKOS_INLINE_FUNCTION int numFamilies() const
returns the number of families
KOKKOS_INLINE_FUNCTION int numDimsForComponent(int &componentOrdinal) const
Returns the number of dimensions corresponding to the specified component.
KOKKOS_INLINE_FUNCTION const TensorData< Scalar, DeviceType > & getComponent(const int &familyOrdinal, const int &componentOrdinal) const
General component accessor.
VectorData(const VectorData< Scalar, OtherDeviceType > &vectorData)
copy-like constructor for differing execution spaces. This does a deep copy of underlying views...
KOKKOS_INLINE_FUNCTION const TensorData< Scalar, DeviceType > & getComponent(const int &componentOrdinal) const
Single-argument component accessor for the axial-component or the single-family case; in this case...
KOKKOS_INLINE_FUNCTION int extent_int(const int &r) const
Returns the extent in the specified dimension as an int.
static constexpr ordinal_type MaxVectorComponents
Maximum number of components that a VectorData object will store – 66 corresponds to OPERATOR_D10 on ...
KOKKOS_INLINE_FUNCTION constexpr bool isValid() const
returns true for containers that have data; false for those that don't (e.g., those that have been co...
VectorData(TensorData< Scalar, DeviceType > data)
Simple 1-argument constructor for the case of trivial tensor product structure. The argument should h...
KOKKOS_INLINE_FUNCTION int spaceDim() const
Returns the spatial dimension; corresponds to the third dimension of this container.
KOKKOS_INLINE_FUNCTION int familyFieldOrdinalOffset(const int &familyOrdinal) const
Returns the field ordinal offset for the specified family.
KOKKOS_INLINE_FUNCTION unsigned rank() const
Returns the rank of this container, which is 3.
VectorData(std::vector< TensorData< Scalar, DeviceType > > vectorComponents, bool axialComponents)
Simplified constructor for gradients of HGRAD, and values of HDIV and HCURL vector bases...
KOKKOS_INLINE_FUNCTION int familyForFieldOrdinal(const int &fieldOrdinal) const
Returns the family ordinal corresponding to the indicated field ordinal.
View-like interface to tensor data; tensor components are stored separately and multiplied together a...
KOKKOS_INLINE_FUNCTION bool axialComponents() const
Returns true only if the families are so structured that the first family has nonzeros only in the x ...
KOKKOS_INLINE_FUNCTION int numPoints() const
Returns the number of points; corresponds to the second dimension of this container.
KOKKOS_INLINE_FUNCTION int numComponents() const
returns the number of components
Reference-space field values for a basis, designed to support typical vector-valued bases...
static constexpr ordinal_type MaxTensorComponents
Maximum number of tensor/Cartesian products that can be taken: this allows hypercube basis in 7D to b...