16 #ifndef Intrepid2_VectorData_h
17 #define Intrepid2_VectorData_h
30 template<
class Scalar,
typename DeviceType>
35 using FamilyVectorArray = Kokkos::Array< VectorArray, Parameters::MaxTensorComponents>;
37 FamilyVectorArray vectorComponents_;
38 bool axialComponents_;
41 Kokkos::Array<int, Parameters::MaxVectorComponents> dimToComponent_;
42 Kokkos::Array<int, Parameters::MaxVectorComponents> dimToComponentDim_;
43 Kokkos::Array<int, Parameters::MaxVectorComponents> numDimsForComponent_;
45 Kokkos::Array<int,Parameters::MaxTensorComponents> familyFieldUpperBound_;
47 unsigned numFamilies_;
48 unsigned numComponents_;
56 int lastFieldUpperBound = 0;
58 axialComponents_ =
true;
59 for (
unsigned i=0; i<numFamilies_; i++)
61 bool validEntryFoundForFamily =
false;
63 for (
unsigned j=0; j<numComponents_; j++)
65 if (vectorComponents_[i][j].
isValid())
67 if (!validEntryFoundForFamily)
69 numFieldsInFamily = vectorComponents_[i][j].extent_int(0);
70 validEntryFoundForFamily =
true;
74 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");
78 numPoints = vectorComponents_[i][j].extent_int(1);
82 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");
87 axialComponents_ =
false;
92 familyFieldUpperBound_[i] = lastFieldUpperBound;
93 INTREPID2_TEST_FOR_EXCEPTION(!validEntryFoundForFamily, std::invalid_argument,
"Each family must have at least one valid TensorData entry");
98 for (
unsigned j=0; j<numComponents_; j++)
100 bool validEntryFoundForComponent =
false;
102 for (
unsigned i=0; i<numFamilies_; i++)
104 if (vectorComponents_[i][j].
isValid())
106 if (!validEntryFoundForComponent)
108 validEntryFoundForComponent =
true;
109 numDimsForComponent = vectorComponents_[i][j].extent_int(2);
113 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");
117 if (!validEntryFoundForComponent)
120 numDimsForComponent = 1;
127 totalDimension_ = currentDim;
130 for (
unsigned j=0; j<numComponents_; j++)
135 dimToComponent_[currentDim+dim] = j;
136 dimToComponentDim_[currentDim+dim] = dim;
149 template<
size_t numFamilies,
size_t numComponents>
161 vectorComponents_[i][j] = vectorComponents[i][j];
175 numFamilies_ = vectorComponents.size();
176 INTREPID2_TEST_FOR_EXCEPTION(numFamilies_ <= 0, std::invalid_argument,
"numFamilies must be at least 1");
177 numComponents_ = vectorComponents[0].size();
178 for (
unsigned i=1; i<numFamilies_; i++)
180 INTREPID2_TEST_FOR_EXCEPTION(vectorComponents[i].size() != numComponents_, std::invalid_argument,
"each family must have the same number of components");
183 INTREPID2_TEST_FOR_EXCEPTION(numFamilies_ >
Parameters::MaxTensorComponents, std::invalid_argument,
"numFamilies must be at most Parameters::MaxTensorComponents");
184 INTREPID2_TEST_FOR_EXCEPTION(numComponents_ >
Parameters::MaxVectorComponents, std::invalid_argument,
"numComponents must be at most Parameters::MaxVectorComponents");
185 for (
unsigned i=0; i<numFamilies_; i++)
187 for (
unsigned j=0; j<numComponents_; j++)
189 vectorComponents_[i][j] = vectorComponents[i][j];
202 template<
size_t numComponents>
209 for (
unsigned d=0; d<numComponents_; d++)
211 vectorComponents_[d][d] = vectorComponents[d];
218 for (
unsigned d=0; d<numComponents_; d++)
220 vectorComponents_[0][d] = vectorComponents[d];
234 : numComponents_(vectorComponents.size())
238 numFamilies_ = numComponents_;
239 for (
unsigned d=0; d<numComponents_; d++)
241 vectorComponents_[d][d] = vectorComponents[d];
247 for (
unsigned d=0; d<numComponents_; d++)
249 vectorComponents_[0][d] = vectorComponents[d];
256 template<typename OtherDeviceType, class = typename std::enable_if< std::is_same<typename DeviceType::memory_space, typename OtherDeviceType::memory_space>::value>::type,
257 class = typename std::enable_if<!std::is_same<DeviceType,OtherDeviceType>::value>::type>
258 VectorData(const VectorData<Scalar,OtherDeviceType> &vectorData)
260 numFamilies_(vectorData.numFamilies()),
261 numComponents_(vectorData.numComponents())
263 if (vectorData.isValid())
265 for (
unsigned i=0; i<numFamilies_; i++)
267 for (
unsigned j=0; j<numComponents_; j++)
269 vectorComponents_[i][j] = vectorData.
getComponent(i, j);
277 template<typename OtherDeviceType, class = typename std::enable_if<!std::is_same<typename DeviceType::memory_space, typename OtherDeviceType::memory_space>::value>::type>
285 for (
unsigned i=0; i<numFamilies_; i++)
287 for (
unsigned j=0; j<numComponents_; j++)
289 vectorComponents_[i][j] = vectorData.
getComponent(i, j);
311 numFamilies_(0), numComponents_(0)
315 KOKKOS_INLINE_FUNCTION
318 return axialComponents_;
322 KOKKOS_INLINE_FUNCTION
325 return numDimsForComponent_[componentOrdinal];
329 KOKKOS_INLINE_FUNCTION
332 return familyFieldUpperBound_[numFamilies_-1];
336 KOKKOS_INLINE_FUNCTION
339 return (familyOrdinal == 0) ? 0 : familyFieldUpperBound_[familyOrdinal-1];
343 KOKKOS_INLINE_FUNCTION
350 KOKKOS_INLINE_FUNCTION
353 return totalDimension_;
357 KOKKOS_INLINE_FUNCTION
358 Scalar
operator()(
const int &fieldOrdinal,
const int &pointOrdinal,
const int &dim)
const
360 int fieldOrdinalInFamily = fieldOrdinal;
361 int familyForField = 0;
362 if (numFamilies_ > 1)
365 int previousFamilyEnd = -1;
366 int fieldAdjustment = 0;
368 for (
unsigned family=0; family<numFamilies_; family++)
370 const bool fieldInRange = (fieldOrdinal > previousFamilyEnd) && (fieldOrdinal < familyFieldUpperBound_[family]);
371 familyForField = fieldInRange ? family : familyForField;
372 fieldAdjustment = fieldInRange ? previousFamilyEnd + 1 : fieldAdjustment;
373 previousFamilyEnd = familyFieldUpperBound_[family] - 1;
375 #ifdef HAVE_INTREPID2_DEBUG
379 fieldOrdinalInFamily = fieldOrdinal - fieldAdjustment;
382 const int componentOrdinal = dimToComponent_[dim];
384 const auto &component = vectorComponents_[familyForField][componentOrdinal];
385 if (component.isValid())
387 const int componentRank = component.rank();
388 if (componentRank == 2)
390 return component(fieldOrdinalInFamily,pointOrdinal);
392 else if (componentRank == 3)
394 return component(fieldOrdinalInFamily,pointOrdinal,dimToComponentDim_[dim]);
412 KOKKOS_INLINE_FUNCTION
415 if (axialComponents_)
417 return vectorComponents_[componentOrdinal][componentOrdinal];
419 else if (numFamilies_ == 1)
421 return vectorComponents_[0][componentOrdinal];
428 return vectorComponents_[6][6];
436 KOKKOS_INLINE_FUNCTION
444 return vectorComponents_[familyOrdinal][componentOrdinal];
448 KOKKOS_INLINE_FUNCTION
454 else if (r == 2)
return totalDimension_;
455 else if (r > 2)
return 1;
462 KOKKOS_INLINE_FUNCTION
472 return numComponents_;
484 int matchingFamily = -1;
487 for (
int i=0; i<numFamilies_; i++)
489 const bool fieldIsBeyondPreviousFamily = (fieldOrdinal >= fieldsSoFar);
491 const bool fieldIsBeforeCurrentFamily = (fieldOrdinal < fieldsSoFar);
492 const bool fieldMatchesFamily = fieldIsBeyondPreviousFamily && fieldIsBeforeCurrentFamily;
493 matchingFamily = fieldMatchesFamily ? i : matchingFamily;
495 return matchingFamily;
503 for (
unsigned componentOrdinal=0; componentOrdinal<numComponents_; componentOrdinal++)
505 numFields = vectorComponents_[familyOrdinal][componentOrdinal].isValid() ? vectorComponents_[familyOrdinal][componentOrdinal].extent_int(0) :
numFields;
512 KOKKOS_INLINE_FUNCTION constexpr
bool isValid()
const
514 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...