16 #ifndef Intrepid2_VectorData_h
17 #define Intrepid2_VectorData_h
30 template<
class Scalar,
typename DeviceType>
34 using value_type = Scalar;
36 using FamilyVectorArray = Kokkos::Array< VectorArray, Parameters::MaxTensorComponents>;
38 FamilyVectorArray vectorComponents_;
39 bool axialComponents_;
42 Kokkos::Array<int, Parameters::MaxVectorComponents> dimToComponent_;
43 Kokkos::Array<int, Parameters::MaxVectorComponents> dimToComponentDim_;
44 Kokkos::Array<int, Parameters::MaxVectorComponents> numDimsForComponent_;
46 Kokkos::Array<int,Parameters::MaxTensorComponents> familyFieldUpperBound_;
48 unsigned numFamilies_;
49 unsigned numComponents_;
57 int lastFieldUpperBound = 0;
59 axialComponents_ =
true;
60 for (
unsigned i=0; i<numFamilies_; i++)
62 bool validEntryFoundForFamily =
false;
64 for (
unsigned j=0; j<numComponents_; j++)
66 if (vectorComponents_[i][j].
isValid())
68 if (!validEntryFoundForFamily)
70 numFieldsInFamily = vectorComponents_[i][j].extent_int(0);
71 validEntryFoundForFamily =
true;
75 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");
79 numPoints = vectorComponents_[i][j].extent_int(1);
83 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");
88 axialComponents_ =
false;
93 familyFieldUpperBound_[i] = lastFieldUpperBound;
94 INTREPID2_TEST_FOR_EXCEPTION(!validEntryFoundForFamily, std::invalid_argument,
"Each family must have at least one valid TensorData entry");
99 for (
unsigned j=0; j<numComponents_; j++)
101 bool validEntryFoundForComponent =
false;
103 for (
unsigned i=0; i<numFamilies_; i++)
105 if (vectorComponents_[i][j].
isValid())
107 if (!validEntryFoundForComponent)
109 validEntryFoundForComponent =
true;
110 numDimsForComponent = vectorComponents_[i][j].extent_int(2);
114 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");
118 if (!validEntryFoundForComponent)
121 numDimsForComponent = 1;
128 totalDimension_ = currentDim;
131 for (
unsigned j=0; j<numComponents_; j++)
136 dimToComponent_[currentDim+dim] = j;
137 dimToComponentDim_[currentDim+dim] = dim;
150 template<
size_t numFamilies,
size_t numComponents>
162 vectorComponents_[i][j] = vectorComponents[i][j];
176 numFamilies_ = vectorComponents.size();
177 INTREPID2_TEST_FOR_EXCEPTION(numFamilies_ <= 0, std::invalid_argument,
"numFamilies must be at least 1");
178 numComponents_ = vectorComponents[0].size();
179 for (
unsigned i=1; i<numFamilies_; i++)
181 INTREPID2_TEST_FOR_EXCEPTION(vectorComponents[i].size() != numComponents_, std::invalid_argument,
"each family must have the same number of components");
184 INTREPID2_TEST_FOR_EXCEPTION(numFamilies_ >
Parameters::MaxTensorComponents, std::invalid_argument,
"numFamilies must be at most Parameters::MaxTensorComponents");
185 INTREPID2_TEST_FOR_EXCEPTION(numComponents_ >
Parameters::MaxVectorComponents, std::invalid_argument,
"numComponents must be at most Parameters::MaxVectorComponents");
186 for (
unsigned i=0; i<numFamilies_; i++)
188 for (
unsigned j=0; j<numComponents_; j++)
190 vectorComponents_[i][j] = vectorComponents[i][j];
203 template<
size_t numComponents>
210 for (
unsigned d=0; d<numComponents_; d++)
212 vectorComponents_[d][d] = vectorComponents[d];
219 for (
unsigned d=0; d<numComponents_; d++)
221 vectorComponents_[0][d] = vectorComponents[d];
235 : numComponents_(vectorComponents.size())
239 numFamilies_ = numComponents_;
240 for (
unsigned d=0; d<numComponents_; d++)
242 vectorComponents_[d][d] = vectorComponents[d];
248 for (
unsigned d=0; d<numComponents_; d++)
250 vectorComponents_[0][d] = vectorComponents[d];
257 template<typename OtherDeviceType, class = typename std::enable_if< std::is_same<typename DeviceType::memory_space, typename OtherDeviceType::memory_space>::value>::type,
258 class = typename std::enable_if<!std::is_same<DeviceType,OtherDeviceType>::value>::type>
259 VectorData(const VectorData<Scalar,OtherDeviceType> &vectorData)
261 numFamilies_(vectorData.numFamilies()),
262 numComponents_(vectorData.numComponents())
264 if (vectorData.isValid())
266 for (
unsigned i=0; i<numFamilies_; i++)
268 for (
unsigned j=0; j<numComponents_; j++)
270 vectorComponents_[i][j] = vectorData.
getComponent(i, j);
278 template<typename OtherDeviceType, class = typename std::enable_if<!std::is_same<typename DeviceType::memory_space, typename OtherDeviceType::memory_space>::value>::type>
286 for (
unsigned i=0; i<numFamilies_; i++)
288 for (
unsigned j=0; j<numComponents_; j++)
290 vectorComponents_[i][j] = vectorData.
getComponent(i, j);
312 numFamilies_(0), numComponents_(0)
316 KOKKOS_INLINE_FUNCTION
319 return axialComponents_;
323 KOKKOS_INLINE_FUNCTION
326 return numDimsForComponent_[componentOrdinal];
330 KOKKOS_INLINE_FUNCTION
333 return familyFieldUpperBound_[numFamilies_-1];
337 KOKKOS_INLINE_FUNCTION
340 return (familyOrdinal == 0) ? 0 : familyFieldUpperBound_[familyOrdinal-1];
344 KOKKOS_INLINE_FUNCTION
351 KOKKOS_INLINE_FUNCTION
354 return totalDimension_;
358 KOKKOS_INLINE_FUNCTION
359 Scalar
operator()(
const int &fieldOrdinal,
const int &pointOrdinal,
const int &dim)
const
361 int fieldOrdinalInFamily = fieldOrdinal;
362 int familyForField = 0;
363 if (numFamilies_ > 1)
366 int previousFamilyEnd = -1;
367 int fieldAdjustment = 0;
369 for (
unsigned family=0; family<numFamilies_; family++)
371 const bool fieldInRange = (fieldOrdinal > previousFamilyEnd) && (fieldOrdinal < familyFieldUpperBound_[family]);
372 familyForField = fieldInRange ? family : familyForField;
373 fieldAdjustment = fieldInRange ? previousFamilyEnd + 1 : fieldAdjustment;
374 previousFamilyEnd = familyFieldUpperBound_[family] - 1;
376 #ifdef HAVE_INTREPID2_DEBUG
380 fieldOrdinalInFamily = fieldOrdinal - fieldAdjustment;
383 const int componentOrdinal = dimToComponent_[dim];
385 const auto &component = vectorComponents_[familyForField][componentOrdinal];
386 if (component.isValid())
388 const int componentRank = component.rank();
389 if (componentRank == 2)
391 return component(fieldOrdinalInFamily,pointOrdinal);
393 else if (componentRank == 3)
395 return component(fieldOrdinalInFamily,pointOrdinal,dimToComponentDim_[dim]);
413 KOKKOS_INLINE_FUNCTION
416 if (axialComponents_)
418 return vectorComponents_[componentOrdinal][componentOrdinal];
420 else if (numFamilies_ == 1)
422 return vectorComponents_[0][componentOrdinal];
429 return vectorComponents_[6][6];
437 KOKKOS_INLINE_FUNCTION
445 return vectorComponents_[familyOrdinal][componentOrdinal];
449 KOKKOS_INLINE_FUNCTION
455 else if (r == 2)
return totalDimension_;
456 else if (r > 2)
return 1;
463 KOKKOS_INLINE_FUNCTION
473 return numComponents_;
485 int matchingFamily = -1;
488 for (
int i=0; i<numFamilies_; i++)
490 const bool fieldIsBeyondPreviousFamily = (fieldOrdinal >= fieldsSoFar);
492 const bool fieldIsBeforeCurrentFamily = (fieldOrdinal < fieldsSoFar);
493 const bool fieldMatchesFamily = fieldIsBeyondPreviousFamily && fieldIsBeforeCurrentFamily;
494 matchingFamily = fieldMatchesFamily ? i : matchingFamily;
496 return matchingFamily;
504 for (
unsigned componentOrdinal=0; componentOrdinal<numComponents_; componentOrdinal++)
506 numFields = vectorComponents_[familyOrdinal][componentOrdinal].isValid() ? vectorComponents_[familyOrdinal][componentOrdinal].extent_int(0) :
numFields;
513 KOKKOS_INLINE_FUNCTION constexpr
bool isValid()
const
515 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...