Intrepid2
Intrepid2_TensorBasis.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Intrepid2 Package
4//
5// Copyright 2007 NTESS and the Intrepid2 contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
14
15#ifndef Intrepid2_TensorBasis_h
16#define Intrepid2_TensorBasis_h
17
18#include <Kokkos_DynRankView.hpp>
19
20#include <Teuchos_RCP.hpp>
21
22#include <Intrepid2_config.h>
23
24#include <array>
25#include <map>
26#include <memory>
27#include <mutex>
28#include <set>
29#include <vector>
30
31#include "Intrepid2_Basis.hpp"
35#include "Intrepid2_Utils.hpp" // defines FAD_VECTOR_SIZE, VECTOR_SIZE
36
38
39namespace Intrepid2
40{
41 template<ordinal_type spaceDim>
42 KOKKOS_INLINE_FUNCTION
43 ordinal_type getDkEnumeration(const Kokkos::Array<int,spaceDim> &entries);
44
45 template<ordinal_type spaceDim>
46 KOKKOS_INLINE_FUNCTION
47 void getDkEnumerationInverse(Kokkos::Array<int,spaceDim> &entries, const ordinal_type dkEnum, const ordinal_type operatorOrder);
48
49 template<>
50 KOKKOS_INLINE_FUNCTION
51 void getDkEnumerationInverse<1>(Kokkos::Array<int,1> &entries, const ordinal_type dkEnum, const ordinal_type operatorOrder)
52 {
53 entries[0] = operatorOrder;
54 }
55
56 template<>
57 KOKKOS_INLINE_FUNCTION
58 void getDkEnumerationInverse<2>(Kokkos::Array<int,2> &entries, const ordinal_type dkEnum, const ordinal_type operatorOrder)
59 {
60 entries[0] = operatorOrder - dkEnum;
61 entries[1] = dkEnum;
62 }
63
64 template<>
65 KOKKOS_INLINE_FUNCTION
66 void getDkEnumerationInverse<3>(Kokkos::Array<int,3> &entries, const ordinal_type dkEnum, const ordinal_type operatorOrder)
67 {
68 // formula is zMult + (yMult+zMult)*(yMult+zMult+1)/2; where xMult+yMult+zMult = operatorOrder
69 // it seems complicated to work out a formula that will invert this. For the present we just take a brute force approach,
70 // using getDkEnumeration() to check each possibility
71 for (ordinal_type yMult=0; yMult<=operatorOrder; yMult++)
72 {
73 for (ordinal_type zMult=0; zMult<=operatorOrder-yMult; zMult++)
74 {
75 const ordinal_type xMult = operatorOrder-(zMult+yMult);
76 if (dkEnum == getDkEnumeration<3>(xMult,yMult,zMult))
77 {
78 entries[0] = xMult;
79 entries[1] = yMult;
80 entries[2] = zMult;
81 return;
82 }
83 }
84 }
85 }
86
87 template<ordinal_type spaceDim>
88 KOKKOS_INLINE_FUNCTION
89 void getDkEnumerationInverse(Kokkos::Array<int,spaceDim> &entries, const ordinal_type dkEnum, const ordinal_type operatorOrder)
90 {
91 // for operator order k, the recursive formula defining getDkEnumeration is:
92 // getDkEnumeration(k0,k1,…,k_{n-1}) = getDkCardinality(k - k0) + getDkEnumeration(k1,…,k_{n-1})
93 // The entries are in reverse lexicographic order. We search for k0, by incrementing k0 until getDkEnumeration(k0,0,…,0) <= dkEnum
94 // Then we recursively call getDkEnumerationInverse<spaceDim-1>({k1,…,k_{n-1}}, dkEnum - getDkEnumeration(k0,0,…,0) - 1)
95
96 for (int k0=0; k0<=operatorOrder; k0++)
97 {
98 entries[0] = k0;
99 for (int d=1; d<spaceDim-1; d++)
100 {
101 entries[d] = 0;
102 }
103 // sum of entries must be equal to operatorOrder
104 if (spaceDim > 1) entries[spaceDim-1] = operatorOrder - k0;
105 else if (k0 != operatorOrder) continue; // if spaceDim == 1, then the only way the sum of the entries is operatorOrder is if k0 == operatorOrder
106 const ordinal_type dkEnumFor_k0 = getDkEnumeration<spaceDim>(entries);
107
108 if (dkEnumFor_k0 > dkEnum) continue; // next k0
109 else if (dkEnumFor_k0 == dkEnum) return; // entries has (k0,0,…,0), and this has dkEnum as its enumeration value
110 else
111 {
112 // (k0,0,…,0) is prior to the dkEnum entry, which means that the dkEnum entry starts with k0-1.
113 entries[0] = k0 - 1;
114
115 // We determine the rest of the entries through a recursive call to getDkEnumerationInverse<spaceDim - 1>().
116
117 // ensure that we don't try to allocate an empty array…
118 constexpr ordinal_type sizeForSubArray = (spaceDim > 2) ? spaceDim - 1 : 1;
119 Kokkos::Array<int,sizeForSubArray> subEntries = {};
120
121 // the -1 in sub-entry enumeration value accounts for the fact that the entry is the one *after* (k0,0,…,0)
122 getDkEnumerationInverse<spaceDim-1>(subEntries, dkEnum - dkEnumFor_k0 - 1, operatorOrder - entries[0]);
123
124 for (int i=1; i<spaceDim; i++)
125 {
126 entries[i] = subEntries[i-1];
127 }
128 return;
129 }
130 }
131 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(true, std::invalid_argument, "entries corresponding to dkEnum not found");
132 }
133
134 template<>
135 KOKKOS_INLINE_FUNCTION
136 ordinal_type getDkEnumeration<1>(const Kokkos::Array<int,1> &entries)
137 {
138 return getDkEnumeration<1>(entries[0]);
139 }
140
141 template<ordinal_type spaceDim>
142 KOKKOS_INLINE_FUNCTION
143 ordinal_type getDkEnumeration(const Kokkos::Array<int,spaceDim> &entries)
144 {
145 ordinal_type k_minus_k0 = 0; // sum of all the entries but the first
146
147 // recursive formula in general is: getDkEnumeration(k0,k1,…,k_{n-1}) = getDkCardinality(k - k0) + getDkEnumeration(k1,…,k_{n-1})
148 // ensure that we don't try to allocate an empty array…
149 constexpr ordinal_type sizeForSubArray = (spaceDim > 2) ? spaceDim - 1 : 1;
150 Kokkos::Array<int,sizeForSubArray> remainingEntries;
151 for (int i=1; i<spaceDim; i++)
152 {
153 k_minus_k0 += entries[i];
154 remainingEntries[i-1] = entries[i];
155 }
156
157 if (k_minus_k0 == 0)
158 {
159 return 0;
160 }
161 else
162 {
163 EOperator opFor_k_minus_k0_minus_1 = (k_minus_k0 > 1) ? EOperator(OPERATOR_D1 + k_minus_k0 - 2) : EOperator(OPERATOR_VALUE);
164 const ordinal_type dkCardinality = getDkCardinality(opFor_k_minus_k0_minus_1, spaceDim);
165 const ordinal_type dkEnum = dkCardinality + getDkEnumeration<sizeForSubArray>(remainingEntries);
166 return dkEnum;
167 }
168 }
169
170 template<ordinal_type spaceDim1, ordinal_type spaceDim2>
171 KOKKOS_INLINE_FUNCTION
172 ordinal_type getDkTensorIndex(const ordinal_type dkEnum1, const ordinal_type operatorOrder1,
173 const ordinal_type dkEnum2, const ordinal_type operatorOrder2)
174 {
175 Kokkos::Array<int,spaceDim1> entries1 = {};
176 getDkEnumerationInverse<spaceDim1>(entries1, dkEnum1, operatorOrder1);
177
178 Kokkos::Array<int,spaceDim2> entries2 = {};
179 getDkEnumerationInverse<spaceDim2>(entries2, dkEnum2, operatorOrder2);
180
181 const int spaceDim = spaceDim1 + spaceDim2;
182 Kokkos::Array<int,spaceDim> entries;
183
184 for (ordinal_type d=0; d<spaceDim1; d++)
185 {
186 entries[d] = entries1[d];
187 }
188
189 for (ordinal_type d=0; d<spaceDim2; d++)
190 {
191 entries[d+spaceDim1] = entries2[d];
192 }
193
194 return getDkEnumeration<spaceDim>(entries);
195 }
196
197template<typename BasisBase>
199
203struct OperatorTensorDecomposition
204{
205 // if we want to make this usable on device, we could switch to Kokkos::Array instead of std::vector. But this is not our immediate use case.
206 std::vector< std::vector<EOperator> > ops; // outer index: vector entry ordinal; inner index: basis component ordinal. (scalar-valued operators have a single entry in outer vector)
207 std::vector<double> weights; // weights for each vector entry
208 ordinal_type numBasisComponents_;
209 bool rotateXYNinetyDegrees_ = false; // if true, indicates that something that otherwise would have values (f_x, f_y, …) should be mapped to (-f_y, f_x, …). This is used for H(curl) wedges (specifically, for OPERATOR_CURL).
210
211 OperatorTensorDecomposition(const std::vector<EOperator> &opsBasis1, const std::vector<EOperator> &opsBasis2, const std::vector<double> vectorComponentWeights)
212 :
213 weights(vectorComponentWeights),
214 numBasisComponents_(2)
215 {
216 const ordinal_type size = opsBasis1.size();
217 const ordinal_type opsBasis2Size = opsBasis2.size();
218 const ordinal_type weightsSize = weights.size();
219 INTREPID2_TEST_FOR_EXCEPTION(size != opsBasis2Size, std::invalid_argument, "opsBasis1.size() != opsBasis2.size()");
220 INTREPID2_TEST_FOR_EXCEPTION(size != weightsSize, std::invalid_argument, "opsBasis1.size() != weights.size()");
221
222 for (ordinal_type i=0; i<size; i++)
223 {
224 ops.push_back(std::vector<EOperator>{opsBasis1[i],opsBasis2[i]});
225 }
226 }
227
228 OperatorTensorDecomposition(const std::vector< std::vector<EOperator> > &vectorEntryOps, const std::vector<double> &vectorComponentWeights)
229 :
230 ops(vectorEntryOps),
231 weights(vectorComponentWeights)
232 {
233 const ordinal_type numVectorComponents = ops.size();
234 const ordinal_type weightsSize = weights.size();
235 INTREPID2_TEST_FOR_EXCEPTION(numVectorComponents != weightsSize, std::invalid_argument, "opsBasis1.size() != weights.size()");
236
237 INTREPID2_TEST_FOR_EXCEPTION(numVectorComponents == 0, std::invalid_argument, "must have at least one entry!");
238
239 ordinal_type numBases = 0;
240 for (ordinal_type i=0; i<numVectorComponents; i++)
241 {
242 if (numBases == 0)
243 {
244 numBases = ops[i].size();
245 }
246 else if (ops[i].size() != 0)
247 {
248 const ordinal_type opsiSize = ops[i].size();
249 INTREPID2_TEST_FOR_EXCEPTION(numBases != opsiSize, std::invalid_argument, "must have one operator for each basis in each nontrivial entry in vectorEntryOps");
250 }
251 }
252 INTREPID2_TEST_FOR_EXCEPTION(numBases == 0, std::invalid_argument, "at least one vectorEntryOps entry must be non-trivial");
253 numBasisComponents_ = numBases;
254 }
255
256 OperatorTensorDecomposition(const std::vector<EOperator> &basisOps, const double weight = 1.0)
257 :
258 ops({basisOps}),
259 weights({weight}),
260 numBasisComponents_(basisOps.size())
261 {}
262
263 OperatorTensorDecomposition(const EOperator &opBasis1, const EOperator &opBasis2, double weight = 1.0)
264 :
265 ops({ std::vector<EOperator>{opBasis1, opBasis2} }),
266 weights({weight}),
267 numBasisComponents_(2)
268 {}
269
270 OperatorTensorDecomposition(const EOperator &opBasis1, const EOperator &opBasis2, const EOperator &opBasis3, double weight = 1.0)
271 :
272 ops({ std::vector<EOperator>{opBasis1, opBasis2, opBasis3} }),
273 weights({weight}),
274 numBasisComponents_(3)
275 {}
276
277 ordinal_type numVectorComponents() const
278 {
279 return ops.size(); // will match weights.size()
280 }
281
282 ordinal_type numBasisComponents() const
283 {
284 return numBasisComponents_;
285 }
286
287 double weight(const ordinal_type &vectorComponentOrdinal) const
288 {
289 return weights[vectorComponentOrdinal];
290 }
291
292 bool identicallyZeroComponent(const ordinal_type &vectorComponentOrdinal) const
293 {
294 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(vectorComponentOrdinal < 0, std::invalid_argument, "vectorComponentOrdinal is out of bounds");
295 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(vectorComponentOrdinal >= numVectorComponents(), std::invalid_argument, "vectorComponentOrdinal is out of bounds");
296 return ops[vectorComponentOrdinal].size() == 0;
297 }
298
299 EOperator op(const ordinal_type &vectorComponentOrdinal, const ordinal_type &basisOrdinal) const
300 {
301 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(vectorComponentOrdinal < 0, std::invalid_argument, "vectorComponentOrdinal is out of bounds");
302 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(vectorComponentOrdinal >= numVectorComponents(), std::invalid_argument, "vectorComponentOrdinal is out of bounds");
303 if (identicallyZeroComponent(vectorComponentOrdinal))
304 {
305 return OPERATOR_MAX; // by convention: zero in this component
306 }
307 else
308 {
309 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(basisOrdinal < 0, std::invalid_argument, "basisOrdinal is out of bounds");
310 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(basisOrdinal >= numBasisComponents_, std::invalid_argument, "basisOrdinal is out of bounds");
311 return ops[vectorComponentOrdinal][basisOrdinal];
312 }
313 }
314
316 template<typename DeviceType, typename OutputValueType, class PointValueType>
317 OperatorTensorDecomposition expandedDecomposition(std::vector< Teuchos::RCP<Basis<DeviceType,OutputValueType,PointValueType> > > &bases)
318 {
319 const ordinal_type basesSize = bases.size();
320 INTREPID2_TEST_FOR_EXCEPTION(basesSize != numBasisComponents_, std::invalid_argument, "The number of bases provided must match the number of basis components in this decomposition");
321
322 ordinal_type numExpandedBasisComponents = 0;
324 using TensorBasis = Basis_TensorBasis<BasisBase>;
325 std::vector<TensorBasis*> basesAsTensorBasis(numBasisComponents_);
326 for (ordinal_type basisComponentOrdinal=0; basisComponentOrdinal<numBasisComponents_; basisComponentOrdinal++)
327 {
328 TensorBasis* basisAsTensorBasis = dynamic_cast<TensorBasis*>(bases[basisComponentOrdinal].get());
329 basesAsTensorBasis[basisComponentOrdinal] = basisAsTensorBasis;
330 if (basisAsTensorBasis)
331 {
332 numExpandedBasisComponents += basisAsTensorBasis->getTensorBasisComponents().size();
333 }
334 else
335 {
336 numExpandedBasisComponents += 1;
337 }
338 }
339
340 std::vector< std::vector<EOperator> > expandedOps; // outer index: vector entry ordinal; inner index: basis component ordinal.
341 std::vector<double> expandedWeights;
342 const ordinal_type opsSize = ops.size();
343 for (ordinal_type simpleVectorEntryOrdinal=0; simpleVectorEntryOrdinal<opsSize; simpleVectorEntryOrdinal++)
344 {
345 if (identicallyZeroComponent(simpleVectorEntryOrdinal))
346 {
347 expandedOps.push_back(std::vector<EOperator>{});
348 expandedWeights.push_back(0.0);
349 continue;
350 }
351
352 std::vector< std::vector<EOperator> > expandedBasisOpsForSimpleVectorEntry(1); // start out with one outer entry; expands if a component is vector-valued
353
354 // this lambda appends an op to each of the vector components
355 auto addExpandedOp = [&expandedBasisOpsForSimpleVectorEntry](const EOperator &op)
356 {
357 const ordinal_type size = expandedBasisOpsForSimpleVectorEntry.size();
358 for (ordinal_type i=0; i<size; i++)
359 {
360 expandedBasisOpsForSimpleVectorEntry[i].push_back(op);
361 }
362 };
363
364 // this lambda takes a scalar-valued (single outer entry) expandedBasisOps and expands it
365 // according to the number of vector entries coming from the vector-valued component basis
366 auto vectorizeExpandedOps = [&expandedBasisOpsForSimpleVectorEntry](const int &numSubVectors)
367 {
368 // we require that this only gets called once per simpleVectorEntryOrdinal -- i.e., only one basis component gets to be vector-valued.
369 INTREPID2_TEST_FOR_EXCEPTION(expandedBasisOpsForSimpleVectorEntry.size() != 1, std::invalid_argument, "multiple basis components may not be vector-valued!");
370 for (ordinal_type i=1; i<numSubVectors; i++)
371 {
372 expandedBasisOpsForSimpleVectorEntry.push_back(expandedBasisOpsForSimpleVectorEntry[0]);
373 }
374 };
375
376 std::vector<EOperator> subVectorOps; // only used if one of the components is vector-valued
377 std::vector<double> subVectorWeights {weights[simpleVectorEntryOrdinal]};
378 for (ordinal_type basisComponentOrdinal=0; basisComponentOrdinal<numBasisComponents_; basisComponentOrdinal++)
379 {
380 const auto &op = ops[simpleVectorEntryOrdinal][basisComponentOrdinal];
381
382 if (! basesAsTensorBasis[basisComponentOrdinal])
383 {
384 addExpandedOp(op);
385 }
386 else
387 {
388 OperatorTensorDecomposition basisOpDecomposition = basesAsTensorBasis[basisComponentOrdinal]->getOperatorDecomposition(op);
389 if (basisOpDecomposition.numVectorComponents() > 1)
390 {
391 // We don't currently support a use case where we have multiple component bases that are vector-valued:
392 INTREPID2_TEST_FOR_EXCEPTION(subVectorWeights.size() > 1, std::invalid_argument, "Unhandled case: multiple component bases are vector-valued");
393 // We do support a single vector-valued case, though; this splits the current simpleVectorEntryOrdinal into an appropriate number of components that come in order in the expanded vector
394 ordinal_type numSubVectors = basisOpDecomposition.numVectorComponents();
395 vectorizeExpandedOps(numSubVectors);
396
397 double weightSoFar = subVectorWeights[0];
398 for (ordinal_type subVectorEntryOrdinal=1; subVectorEntryOrdinal<numSubVectors; subVectorEntryOrdinal++)
399 {
400 subVectorWeights.push_back(weightSoFar * basisOpDecomposition.weight(subVectorEntryOrdinal));
401 }
402 subVectorWeights[0] *= basisOpDecomposition.weight(0);
403 for (ordinal_type subVectorEntryOrdinal=0; subVectorEntryOrdinal<numSubVectors; subVectorEntryOrdinal++)
404 {
405 for (ordinal_type subComponentBasis=0; subComponentBasis<basisOpDecomposition.numBasisComponents(); subComponentBasis++)
406 {
407 const auto &basisOp = basisOpDecomposition.op(subVectorEntryOrdinal, subComponentBasis);
408 expandedBasisOpsForSimpleVectorEntry[subVectorEntryOrdinal].push_back(basisOp);
409 }
410 }
411 }
412 else
413 {
414 double componentWeight = basisOpDecomposition.weight(0);
415 const ordinal_type size = subVectorWeights.size();
416 for (ordinal_type i=0; i<size; i++)
417 {
418 subVectorWeights[i] *= componentWeight;
419 }
420 ordinal_type subVectorEntryOrdinal = 0;
421 const ordinal_type numBasisComponents = basisOpDecomposition.numBasisComponents();
422 for (ordinal_type subComponentBasis=0; subComponentBasis<numBasisComponents; subComponentBasis++)
423 {
424 const auto &basisOp = basisOpDecomposition.op(subVectorEntryOrdinal, basisComponentOrdinal);
425 addExpandedOp( basisOp );
426 }
427 }
428 }
429 }
430
431 // sanity check on the new expandedOps entries:
432 for (ordinal_type i=0; i<static_cast<ordinal_type>(expandedBasisOpsForSimpleVectorEntry.size()); i++)
433 {
434 const ordinal_type size = expandedBasisOpsForSimpleVectorEntry[i].size();
435 INTREPID2_TEST_FOR_EXCEPTION(size != numExpandedBasisComponents, std::logic_error, "each vector in expandedBasisOpsForSimpleVectorEntry should have as many entries as there are expanded basis components");
436 }
437
438 expandedOps.insert(expandedOps.end(), expandedBasisOpsForSimpleVectorEntry.begin(), expandedBasisOpsForSimpleVectorEntry.end());
439 expandedWeights.insert(expandedWeights.end(), subVectorWeights.begin(), subVectorWeights.end());
440 }
441 // check that vector lengths agree:
442 INTREPID2_TEST_FOR_EXCEPTION(expandedOps.size() != expandedWeights.size(), std::logic_error, "expandedWeights and expandedOps do not agree on the number of vector components");
443
444 OperatorTensorDecomposition result(expandedOps, expandedWeights);
445 result.setRotateXYNinetyDegrees(rotateXYNinetyDegrees_);
446 return result;
447 }
448
451 {
452 return rotateXYNinetyDegrees_;
453 }
454
455 void setRotateXYNinetyDegrees(const bool &value)
456 {
457 rotateXYNinetyDegrees_ = value;
458 }
459};
460
466 template<class ExecutionSpace, class OutputScalar, class OutputFieldType>
467 class TensorViewFunctor
468 {
469 using ScratchSpace = typename ExecutionSpace::scratch_memory_space;
470 using OutputScratchView = Kokkos::View<OutputScalar*,ScratchSpace,Kokkos::MemoryTraits<Kokkos::Unmanaged>>;
471
472 using TeamPolicy = Kokkos::TeamPolicy<ExecutionSpace>;
473 using TeamMember = typename TeamPolicy::member_type;
474
476 using RankCombinationType = typename TensorViewIteratorType::RankCombinationType;
477
478 OutputFieldType output_; // F,P[,D…]
479 OutputFieldType input1_; // F1,P[,D…] or F1,P1[,D…]
480 OutputFieldType input2_; // F2,P[,D…] or F2,P2[,D…]
481
482 int numFields_, numPoints_;
483 int numFields1_, numPoints1_;
484 int numFields2_, numPoints2_;
485
486 bool tensorPoints_; // if true, input1 and input2 refer to values at decomposed points, and P = P1 * P2. If false, then the two inputs refer to points in the full-dimensional space, and their point lengths are the same as that of the final output.
487
488 using RankCombinationViewType = typename TensorViewIteratorType::RankCombinationViewType;
489 RankCombinationViewType rank_combinations_;// indicates the policy by which the input views will be combined in output view
490
491 double weight_;
492
493 public:
494
495 TensorViewFunctor(OutputFieldType output, OutputFieldType inputValues1, OutputFieldType inputValues2,
496 bool tensorPoints, double weight)
497 : output_(output), input1_(inputValues1), input2_(inputValues2), tensorPoints_(tensorPoints), weight_(weight)
498 {
499 numFields_ = output.extent_int(0);
500 numPoints_ = output.extent_int(1);
501
502 numFields1_ = inputValues1.extent_int(0);
503 numPoints1_ = inputValues1.extent_int(1);
504
505 numFields2_ = inputValues2.extent_int(0);
506 numPoints2_ = inputValues2.extent_int(1);
507
508 if (!tensorPoints_)
509 {
510 // then the point counts should all match
511 INTREPID2_TEST_FOR_EXCEPTION(numPoints_ != numPoints1_, std::invalid_argument, "incompatible point counts");
512 INTREPID2_TEST_FOR_EXCEPTION(numPoints_ != numPoints2_, std::invalid_argument, "incompatible point counts");
513 }
514 else
515 {
516 INTREPID2_TEST_FOR_EXCEPTION(numPoints_ != numPoints1_ * numPoints2_, std::invalid_argument, "incompatible point counts");
517 }
518
519 INTREPID2_TEST_FOR_EXCEPTION(numFields_ != numFields1_ * numFields2_, std::invalid_argument, "incompatible field sizes");
520
521 const ordinal_type max_rank = std::max(inputValues1.rank(),inputValues2.rank());
522 // at present, no supported case will result in an output rank greater than both input ranks
523
524 const ordinal_type outputRank = output.rank();
525 INTREPID2_TEST_FOR_EXCEPTION(outputRank > max_rank, std::invalid_argument, "Unsupported view combination.");
526 rank_combinations_ = RankCombinationViewType("Rank_combinations_", max_rank);
527 auto rank_combinations_host = Kokkos::create_mirror_view(rank_combinations_);
528
529 rank_combinations_host[0] = TensorViewIteratorType::TENSOR_PRODUCT; // field combination is always tensor product
530 rank_combinations_host[1] = tensorPoints ? TensorViewIteratorType::TENSOR_PRODUCT : TensorViewIteratorType::DIMENSION_MATCH; // tensorPoints controls interpretation of the point dimension
531 for (ordinal_type d=2; d<max_rank; d++)
532 {
533 // d >= 2 have the interpretation of spatial dimensions (gradients, etc.)
534 // we let the extents of the containers determine what we're doing here
535 if ((inputValues1.extent_int(d) == inputValues2.extent_int(d)) && (output.extent_int(d) == 1))
536 {
537 rank_combinations_host[d] = TensorViewIteratorType::TENSOR_CONTRACTION;
538 }
539 else if (((inputValues1.extent_int(d) == output.extent_int(d)) && (inputValues2.extent_int(d) == 1))
540 || ((inputValues2.extent_int(d) == output.extent_int(d)) && (inputValues1.extent_int(d) == 1))
541 )
542 {
543 // this looks like multiplication of a vector by a scalar, resulting in a vector
544 // this can be understood as a tensor product
545 rank_combinations_host[d] = TensorViewIteratorType::TENSOR_PRODUCT;
546 }
547 else if ((inputValues1.extent_int(d) == inputValues2.extent_int(d)) && (output.extent_int(d) == inputValues1.extent_int(d) * inputValues2.extent_int(d)))
548 {
549 // this is actually a generalization of the above case: a tensor product, something like a vector outer product
550 rank_combinations_host[d] = TensorViewIteratorType::TENSOR_PRODUCT;
551 }
552 else if ((inputValues1.extent_int(d) == inputValues2.extent_int(d)) && (output.extent_int(d) == inputValues1.extent_int(d)))
553 {
554 // it's a bit weird (I'm not aware of the use case, in the present context), but we can handle this case by adopting DIMENSION_MATCH here
555 // this is something like MATLAB's .* and .+ operators, which operate entry-wise
556 rank_combinations_host[d] = TensorViewIteratorType::DIMENSION_MATCH;
557 }
558 else
559 {
560 std::cout << "inputValues1.extent_int(" << d << ") = " << inputValues1.extent_int(d) << std::endl;
561 std::cout << "inputValues2.extent_int(" << d << ") = " << inputValues2.extent_int(d) << std::endl;
562 std::cout << "output.extent_int(" << d << ") = " << output.extent_int(d) << std::endl;
563 INTREPID2_TEST_FOR_EXCEPTION(true, std::invalid_argument, "unable to find an interpretation for this combination of views");
564 }
565 }
566 Kokkos::deep_copy(rank_combinations_,rank_combinations_host);
567 }
568
569 KOKKOS_INLINE_FUNCTION
570 void operator()( const TeamMember & teamMember ) const
571 {
572 auto fieldOrdinal1 = teamMember.league_rank();
573
574 Kokkos::parallel_for(Kokkos::TeamThreadRange(teamMember,0,numFields2_), [&] (const int& fieldOrdinal2) {
575 TensorViewIteratorType it(output_,input1_,input2_,rank_combinations_);
576 const int FIELD_ORDINAL_DIMENSION = 0;
577 it.setLocation({fieldOrdinal1,0,0,0,0,0,0},{fieldOrdinal2,0,0,0,0,0,0});
578 int next_increment_rank = FIELD_ORDINAL_DIMENSION; // used to initialize prev_increment_rank at the start of the do/while loop. Notionally, we last incremented in the field ordinal rank to get to the {fieldOrdinal1,0,0,0,0,0,0},{fieldOrdinal2,0,0,0,0,0,0} location.
579 OutputScalar accumulator = 0;
580
581 do
582 {
583 accumulator += weight_ * it.getView1Entry() * it.getView2Entry();
584 next_increment_rank = it.nextIncrementRank();
585
586 if ((next_increment_rank < 0) || (rank_combinations_[next_increment_rank] != TensorViewIteratorType::TENSOR_CONTRACTION))
587 {
588 // then we've finished the accumulation and should set the value
589 it.set(accumulator);
590 // reset the accumulator:
591 accumulator = 0;
592 }
593 } while (it.increment() > FIELD_ORDINAL_DIMENSION);
594 });
595 }
596 };
597
611 template<typename BasisBaseClass = void>
613 :
614 public BasisBaseClass
615 {
616 public:
617 using BasisBase = BasisBaseClass;
618 using BasisPtr = Teuchos::RCP<BasisBase>;
619
620 protected:
621 BasisPtr basis1_;
622 BasisPtr basis2_;
623
624 std::vector<BasisPtr> tensorComponents_;
625
626 std::string name_; // name of the basis
627
628 int numTensorialExtrusions_; // relative to cell topo returned by getBaseCellTopology().
629 bool useShardsCellTopologyAndTags_; // if true, use shards topology/tag numbering for low-dimensional tensor products.
631 mutable std::map<std::pair<ordinal_type,ordinal_type>, std::array<ordinal_type,4>> compositeSubcellToComponents_;
632 mutable bool compositeSubcellMapBuilt_ = false;
633
642 std::shared_ptr<std::recursive_mutex> lazyInitializationMutex_ = std::make_shared<std::recursive_mutex>();
643 public:
644 using DeviceType = typename BasisBase::DeviceType;
645 using ExecutionSpace = typename BasisBase::ExecutionSpace;
646 using OutputValueType = typename BasisBase::OutputValueType;
647 using PointValueType = typename BasisBase::PointValueType;
648
649 using OrdinalTypeArray1DHost = typename BasisBase::OrdinalTypeArray1DHost;
650 using OrdinalTypeArray2DHost = typename BasisBase::OrdinalTypeArray2DHost;
651 using OrdinalTypeArrayStride1DHost = typename BasisBase::OrdinalTypeArrayStride1DHost;
652 using OutputViewType = typename BasisBase::OutputViewType;
653 using PointViewType = typename BasisBase::PointViewType;
654 using TensorBasis = Basis_TensorBasis<BasisBaseClass>;
655 public:
662 Basis_TensorBasis(BasisPtr basis1, BasisPtr basis2, EFunctionSpace functionSpace = FUNCTION_SPACE_MAX,
663 const bool useShardsCellTopologyAndTags = false)
664 :
665 basis1_(basis1),basis2_(basis2),useShardsCellTopologyAndTags_(useShardsCellTopologyAndTags)
666 {
667 this->functionSpace_ = functionSpace;
668
669 Basis_TensorBasis* basis1AsTensor = dynamic_cast<Basis_TensorBasis*>(basis1_.get());
670 if (basis1AsTensor)
671 {
672 auto basis1Components = basis1AsTensor->getTensorBasisComponents();
673 tensorComponents_.insert(tensorComponents_.end(), basis1Components.begin(), basis1Components.end());
674 }
675 else
676 {
677 tensorComponents_.push_back(basis1_);
678 }
679
680 Basis_TensorBasis* basis2AsTensor = dynamic_cast<Basis_TensorBasis*>(basis2_.get());
681 if (basis2AsTensor)
682 {
683 auto basis2Components = basis2AsTensor->getTensorBasisComponents();
684 tensorComponents_.insert(tensorComponents_.end(), basis2Components.begin(), basis2Components.end());
685 }
686 else
687 {
688 tensorComponents_.push_back(basis2_);
689 }
690
691 this->basisCardinality_ = basis1->getCardinality() * basis2->getCardinality();
692 this->basisDegree_ = std::max(basis1->getDegree(), basis2->getDegree());
693
694 {
695 std::ostringstream basisName;
696 basisName << basis1->getName() << " x " << basis2->getName();
697 name_ = basisName.str();
698 }
699
700 // set cell topology
701 this->basisCellTopologyKey_ = tensorComponents_[0]->getBaseCellTopology().getKey();
702 this->numTensorialExtrusions_ = tensorComponents_.size() - 1;
703
704 this->basisType_ = basis1_->getBasisType();
705 this->basisCoordinates_ = COORDINATES_CARTESIAN;
706
707 ordinal_type spaceDim2 = basis2_->getDomainDimension();
708
709 INTREPID2_TEST_FOR_EXCEPTION(spaceDim2 != 1, std::invalid_argument, "TensorBasis only supports 1D bases in basis2_ position");
710
711 if (this->getBasisType() == BASIS_FEM_HIERARCHICAL)
712 {
713 // fill in degree lookup:
714 int degreeSize = basis1_->getPolynomialDegreeLength() + basis2_->getPolynomialDegreeLength();
715 this->fieldOrdinalPolynomialDegree_ = OrdinalTypeArray2DHost("TensorBasis - field ordinal polynomial degree", this->basisCardinality_, degreeSize);
716 this->fieldOrdinalH1PolynomialDegree_ = OrdinalTypeArray2DHost("TensorBasis - field ordinal polynomial H^1 degree", this->basisCardinality_, degreeSize);
717
718 const ordinal_type basis1Cardinality = basis1_->getCardinality();
719 const ordinal_type basis2Cardinality = basis2_->getCardinality();
720
721 int degreeLengthField1 = basis1_->getPolynomialDegreeLength();
722 int degreeLengthField2 = basis2_->getPolynomialDegreeLength();
723
724 for (ordinal_type fieldOrdinal1 = 0; fieldOrdinal1 < basis1Cardinality; fieldOrdinal1++)
725 {
726 OrdinalTypeArray1DHost degreesField1 = basis1_->getPolynomialDegreeOfField(fieldOrdinal1);
727 OrdinalTypeArray1DHost h1DegreesField1 = basis1_->getH1PolynomialDegreeOfField(fieldOrdinal1);
728 for (ordinal_type fieldOrdinal2 = 0; fieldOrdinal2 < basis2Cardinality; fieldOrdinal2++)
729 {
730 OrdinalTypeArray1DHost degreesField2 = basis2_->getPolynomialDegreeOfField(fieldOrdinal2);
731 OrdinalTypeArray1DHost h1DegreesField2 = basis2_->getH1PolynomialDegreeOfField(fieldOrdinal2);
732 const ordinal_type tensorFieldOrdinal = fieldOrdinal2 * basis1Cardinality + fieldOrdinal1;
733
734 for (int d3=0; d3<degreeLengthField1; d3++)
735 {
736 this->fieldOrdinalPolynomialDegree_ (tensorFieldOrdinal,d3) = degreesField1(d3);
737 this->fieldOrdinalH1PolynomialDegree_(tensorFieldOrdinal,d3) = h1DegreesField1(d3);
738 }
739 for (int d3=0; d3<degreeLengthField2; d3++)
740 {
741 this->fieldOrdinalPolynomialDegree_ (tensorFieldOrdinal,d3+degreeLengthField1) = degreesField2(d3);
742 this->fieldOrdinalH1PolynomialDegree_(tensorFieldOrdinal,d3+degreeLengthField1) = h1DegreesField2(d3);
743 }
744 }
745 }
746 }
747
748 if (useShardsCellTopologyAndTags)
749 {
750 setShardsTopology();
751 }
752 // Dense tag tables are intentionally not built here. TensorBasis answers
753 // scalar tag queries from its factorized component bases below, and only
754 // materializes the full tables if a compatibility view is requested.
755 }
756
757 void setShardsTopology()
758 {
759 shards::CellTopology cellTopo1 = basis1_->getBaseCellTopology();
760 shards::CellTopology cellTopo2 = basis2_->getBaseCellTopology();
761
762 auto cellKey1 = basis1_->getBaseCellTopology().getKey();
763 auto cellKey2 = basis2_->getBaseCellTopology().getKey();
764
765 const int numTensorialExtrusions = basis1_->getNumTensorialExtrusions() + basis2_->getNumTensorialExtrusions();
766 if ((cellKey1 == shards::Line<2>::key) && (cellKey2 == shards::Line<2>::key) && (numTensorialExtrusions == 0))
767 {
768 this->basisCellTopologyKey_ = shards::Quadrilateral<4>::key;
769 }
770 else if ( ((cellKey1 == shards::Quadrilateral<4>::key) && (cellKey2 == shards::Line<2>::key))
771 || ((cellKey2 == shards::Quadrilateral<4>::key) && (cellKey1 == shards::Line<2>::key))
772 || ((cellKey1 == shards::Line<2>::key) && (cellKey2 == shards::Line<2>::key) && (numTensorialExtrusions == 1))
773 )
774 {
775 this->basisCellTopologyKey_ = shards::Hexahedron<8>::key;
776 }
777 else if ((cellKey1 == shards::Triangle<3>::key) && (cellKey2 == shards::Line<2>::key))
778 {
779 this->basisCellTopologyKey_ = shards::Wedge<6>::key;
780 }
781 else
782 {
783 INTREPID2_TEST_FOR_EXCEPTION(true, std::invalid_argument, "Cell topology combination not yet supported");
784 }
785
786 // numTensorialExtrusions_ is relative to the baseCellTopology; what we've just done is found a cell topology of the same spatial dimension as the extruded topology, so now numTensorialExtrusions_ should be 0.
787 numTensorialExtrusions_ = 0;
788 }
789
790 ordinal_type getCompositeSubcellOrdinal(const ordinal_type subcellDim1,
791 const ordinal_type subcellOrd1,
792 const ordinal_type subcellDim2,
793 const ordinal_type subcellOrd2) const
794 {
795 if (useShardsCellTopologyAndTags_)
796 {
797 TensorTopologyMap topoMap(basis1_->getBaseCellTopology(), basis2_->getBaseCellTopology());
798 return topoMap.getCompositeSubcellOrdinal(subcellDim1, subcellOrd1, subcellDim2, subcellOrd2);
799 }
800 else
801 {
802 const ordinal_type tensorialDegree = tensorComponents_.size() - 1;
803 auto cellTopo = CellTopology::cellTopology(tensorComponents_[0]->getBaseCellTopology(), tensorialDegree);
804 const ordinal_type spaceDim = basis1_->getDomainDimension() + basis2_->getDomainDimension();
805 const ordinal_type sideDim = spaceDim - 1;
806 if (subcellDim2 == 0)
807 {
808 ordinal_type sideOrdinal = cellTopo->getTensorialComponentSideOrdinal(subcellOrd2);
809 return CellTopology::getSubcellOrdinalMap(cellTopo, sideDim, sideOrdinal, subcellDim1, subcellOrd1);
810 }
811 else
812 {
813 return cellTopo->getExtrudedSubcellOrdinal(subcellDim1, subcellOrd1);
814 }
815 }
816 }
817
818 void fillDofTag(const ordinal_type dofOrd, OrdinalTypeArray2DHost tag, const ordinal_type row) const
819 {
820 const ordinal_type basis1Cardinality = basis1_->getCardinality();
821 const ordinal_type fieldOrdinal1 = dofOrd % basis1Cardinality;
822 const ordinal_type fieldOrdinal2 = dofOrd / basis1Cardinality;
823
824 auto tag1 = basis1_->getDofTag(fieldOrdinal1);
825 const ordinal_type subcellDim1 = tag1(0);
826 const ordinal_type subcellOrd1 = tag1(1);
827 const ordinal_type dofOrd1 = tag1(2);
828 const ordinal_type subcellDfCnt1 = tag1(3);
829 auto tag2 = basis2_->getDofTag(fieldOrdinal2);
830 const ordinal_type subcellDim2 = tag2(0);
831 const ordinal_type subcellOrd2 = tag2(1);
832 const ordinal_type dofOrd2 = tag2(2);
833 const ordinal_type subcellDfCnt2 = tag2(3);
834
835 tag(row,0) = subcellDim1 + subcellDim2;
836 tag(row,1) = getCompositeSubcellOrdinal(subcellDim1, subcellOrd1, subcellDim2, subcellOrd2);
837 tag(row,2) = dofOrd2 * subcellDfCnt1 + dofOrd1;
838 tag(row,3) = subcellDfCnt1 * subcellDfCnt2;
839 }
840
841 void setTensorProductTags()
842 {
843 // Build the legacy dense table only when a compatibility view asks for it.
844 const auto & cardinality = this->basisCardinality_;
845 const ordinal_type tagSize = 4;
846 const ordinal_type posScDim = 0;
847 const ordinal_type posScOrd = 1;
848 const ordinal_type posDfOrd = 2;
849
850 OrdinalTypeArray2DHost tagRows("tag rows", cardinality, tagSize);
851 OrdinalTypeArray1DHost tagView("tag view", cardinality*tagSize);
852 for (ordinal_type tensorFieldOrdinal=0; tensorFieldOrdinal<cardinality; tensorFieldOrdinal++)
853 {
854 fillDofTag(tensorFieldOrdinal, tagRows, tensorFieldOrdinal);
855 for (ordinal_type tagEntry=0; tagEntry<tagSize; tagEntry++)
856 {
857 tagView(tagSize*tensorFieldOrdinal + tagEntry) = tagRows(tensorFieldOrdinal,tagEntry);
858 }
859 }
860
861 this->setOrdinalTagData(this->tagToOrdinal_,
862 this->ordinalToTag_,
863 tagView,
864 this->basisCardinality_,
865 tagSize,
866 posScDim,
867 posScOrd,
868 posDfOrd);
869 }
870
872 virtual void requireTags() const override
873 {
874 std::lock_guard<std::recursive_mutex> lock(*lazyInitializationMutex_);
875 if (this->ordinalToTag_.extent(0) == 0 || this->tagToOrdinal_.extent(0) == 0)
876 {
877 TensorBasis* self = const_cast<TensorBasis*>(this);
878 if (useShardsCellTopologyAndTags_)
879 self->setShardsTopologyAndTags();
880 else
881 self->setTensorProductTags();
882 }
883 }
884
887 {
888 std::lock_guard<std::recursive_mutex> lock(*lazyInitializationMutex_);
889 if (compositeSubcellMapBuilt_) return;
890 const shards::CellTopology cellTopo1 = basis1_->getBaseCellTopology();
891 const ordinal_type spaceDim1 = basis1_->getDomainDimension();
892 const ordinal_type spaceDim2 = basis2_->getDomainDimension(); // 1 (checked at construction)
893 for (ordinal_type d1=0; d1<=spaceDim1; d1++)
894 {
895 // a component basis with tensorial extrusions has a base topology of lower dimension, so we count its subcells via
896 // CellTopology, which knows about extrusions
897 auto topo1 = CellTopology::cellTopology(cellTopo1, basis1_->getNumTensorialExtrusions());
898 const ordinal_type subcellCount1 = useShardsCellTopologyAndTags_ ? cellTopo1.getSubcellCount(d1) : topo1->getSubcellCount(d1);
899 for (ordinal_type s1=0; s1<subcellCount1; s1++)
900 {
901 for (ordinal_type d2=0; d2<=spaceDim2; d2++)
902 {
903 const ordinal_type subcellCount2 = (d2 == 0) ? 2 : 1; // line: two vertices and one edge
904 for (ordinal_type s2=0; s2<subcellCount2; s2++)
905 {
906 const ordinal_type compositeOrdinal = getCompositeSubcellOrdinal(d1, s1, d2, s2);
907 compositeSubcellToComponents_[{d1 + d2, compositeOrdinal}] = {d1, s1, d2, s2};
908 }
909 }
910 }
911 }
912 compositeSubcellMapBuilt_ = true;
913 }
914
917 virtual ordinal_type getDofCount( const ordinal_type subcDim,
918 const ordinal_type subcOrd ) const override
919 {
921 const auto entry = compositeSubcellToComponents_.find({subcDim, subcOrd});
922 if (entry == compositeSubcellToComponents_.end()) return 0;
923 const auto &c = entry->second;
924 return basis1_->getDofCount(c[0], c[1]) * basis2_->getDofCount(c[2], c[3]);
925 }
926
929 virtual ordinal_type getDofOrdinal( const ordinal_type subcDim,
930 const ordinal_type subcOrd,
931 const ordinal_type subcDofOrd ) const override
932 {
934 const auto entry = compositeSubcellToComponents_.find({subcDim, subcOrd});
935 ordinal_type result = -1;
936 if (entry != compositeSubcellToComponents_.end())
937 {
938 const auto &c = entry->second;
939 const ordinal_type count1 = basis1_->getDofCount(c[0], c[1]);
940 const ordinal_type count2 = basis2_->getDofCount(c[2], c[3]);
941 if ((count1 > 0) && (subcDofOrd >= 0) && (subcDofOrd < count1 * count2))
942 {
943 // local DoF ordinal is dofOrd2 * count1 + dofOrd1 (see fillDofTag())
944 const ordinal_type fieldOrdinal1 = basis1_->getDofOrdinal(c[0], c[1], subcDofOrd % count1);
945 const ordinal_type fieldOrdinal2 = basis2_->getDofOrdinal(c[2], c[3], subcDofOrd / count1);
946 result = fieldOrdinal2 * basis1_->getCardinality() + fieldOrdinal1;
947 }
948 }
949#ifdef HAVE_INTREPID2_DEBUG
950 INTREPID2_TEST_FOR_EXCEPTION( result == -1, std::runtime_error,
951 ">>> ERROR (Basis_TensorBasis::getDofOrdinal): Invalid DoF tag is found.");
952#endif
953 return result;
954 }
955
956 virtual const OrdinalTypeArray2DHost getAllDofTags() const override
957 {
958 this->requireTags();
959 return this->ordinalToTag_;
960 }
961
962 void setShardsTopologyAndTags()
963 {
964 useShardsCellTopologyAndTags_ = true;
965 setShardsTopology();
966 shards::CellTopology cellTopo1 = basis1_->getBaseCellTopology();
967 shards::CellTopology cellTopo2 = basis2_->getBaseCellTopology();
968
969 // initialize tags
970 {
971 const auto & cardinality = this->basisCardinality_;
972
973 // Basis-dependent initializations
974 const ordinal_type tagSize = 4; // size of DoF tag, i.e., number of fields in the tag
975 const ordinal_type posScDim = 0; // position in the tag, counting from 0, of the subcell dim
976 const ordinal_type posScOrd = 1; // position in the tag, counting from 0, of the subcell ordinal
977 const ordinal_type posDfOrd = 2; // position in the tag, counting from 0, of DoF ordinal relative to the subcell
978
979 OrdinalTypeArray1DHost tagView("tag view", cardinality*tagSize);
980
981 shards::CellTopology cellTopo = this->getBaseCellTopology();
982
983 ordinal_type tensorSpaceDim = cellTopo.getDimension();
984 ordinal_type spaceDim1 = cellTopo1.getDimension();
985 ordinal_type spaceDim2 = cellTopo2.getDimension();
986
987 TensorTopologyMap topoMap(cellTopo1, cellTopo2);
988
989 for (ordinal_type d=0; d<=tensorSpaceDim; d++) // d: tensorial dimension
990 {
991 ordinal_type d2_max = std::min(spaceDim2, d);
992 for (ordinal_type d2=0; d2<=d2_max; d2++)
993 {
994 ordinal_type d1 = d-d2;
995 if (d1 > spaceDim1) continue;
996
997 ordinal_type subcellCount2 = cellTopo2.getSubcellCount(d2);
998 ordinal_type subcellCount1 = cellTopo1.getSubcellCount(d1);
999 for (ordinal_type subcellOrdinal2=0; subcellOrdinal2<subcellCount2; subcellOrdinal2++)
1000 {
1001 ordinal_type subcellDofCount2 = basis2_->getDofCount(d2, subcellOrdinal2);
1002 for (ordinal_type subcellOrdinal1=0; subcellOrdinal1<subcellCount1; subcellOrdinal1++)
1003 {
1004 ordinal_type subcellDofCount1 = basis1_->getDofCount(d1, subcellOrdinal1);
1005 ordinal_type tensorLocalDofCount = subcellDofCount1 * subcellDofCount2;
1006 for (ordinal_type localDofID2 = 0; localDofID2<subcellDofCount2; localDofID2++)
1007 {
1008 ordinal_type fieldOrdinal2 = basis2_->getDofOrdinal(d2, subcellOrdinal2, localDofID2);
1009 OrdinalTypeArray1DHost degreesField2;
1010 if (this->basisType_ == BASIS_FEM_HIERARCHICAL) degreesField2 = basis2_->getPolynomialDegreeOfField(fieldOrdinal2);
1011 for (ordinal_type localDofID1 = 0; localDofID1<subcellDofCount1; localDofID1++)
1012 {
1013 ordinal_type fieldOrdinal1 = basis1_->getDofOrdinal(d1, subcellOrdinal1, localDofID1);
1014 ordinal_type tensorLocalDofID = localDofID2 * subcellDofCount1 + localDofID1;
1015 ordinal_type tensorFieldOrdinal = fieldOrdinal2 * basis1_->getCardinality() + fieldOrdinal1;
1016 tagView(tensorFieldOrdinal*tagSize+0) = d; // subcell dimension
1017 tagView(tensorFieldOrdinal*tagSize+1) = topoMap.getCompositeSubcellOrdinal(d1, subcellOrdinal1, d2, subcellOrdinal2);
1018 tagView(tensorFieldOrdinal*tagSize+2) = tensorLocalDofID;
1019 tagView(tensorFieldOrdinal*tagSize+3) = tensorLocalDofCount;
1020 } // localDofID1
1021 } // localDofID2
1022 } // subcellOrdinal1
1023 } // subcellOrdinal2
1024 }
1025 }
1026
1027 // // Basis-independent function sets tag and enum data in tagToOrdinal_ and ordinalToTag_ arrays:
1028 // // tags are constructed on host
1029 this->setOrdinalTagData(this->tagToOrdinal_,
1030 this->ordinalToTag_,
1031 tagView,
1032 this->basisCardinality_,
1033 tagSize,
1034 posScDim,
1035 posScOrd,
1036 posDfOrd);
1037 }
1038 }
1039
1040 virtual int getNumTensorialExtrusions() const override
1041 {
1042 return numTensorialExtrusions_;
1043 }
1044
1053 ordinal_type getTensorDkEnumeration(ordinal_type dkEnum1, ordinal_type operatorOrder1,
1054 ordinal_type dkEnum2, ordinal_type operatorOrder2) const
1055 {
1056 ordinal_type spaceDim1 = basis1_->getDomainDimension();
1057 ordinal_type spaceDim2 = basis2_->getDomainDimension();
1058
1059 // We support total spaceDim <= 7.
1060 switch (spaceDim1)
1061 {
1062 case 0:
1063 {
1064 INTREPID2_TEST_FOR_EXCEPTION(operatorOrder1 > 0, std::invalid_argument, "For spaceDim1 = 0, operatorOrder1 must be 0.");
1065 return dkEnum2;
1066 }
1067 case 1:
1068 switch (spaceDim2)
1069 {
1070 case 1: return getDkTensorIndex<1, 1>(dkEnum1, operatorOrder1, dkEnum2, operatorOrder2);
1071 case 2: return getDkTensorIndex<1, 2>(dkEnum1, operatorOrder1, dkEnum2, operatorOrder2);
1072 case 3: return getDkTensorIndex<1, 3>(dkEnum1, operatorOrder1, dkEnum2, operatorOrder2);
1073 case 4: return getDkTensorIndex<1, 4>(dkEnum1, operatorOrder1, dkEnum2, operatorOrder2);
1074 case 5: return getDkTensorIndex<1, 5>(dkEnum1, operatorOrder1, dkEnum2, operatorOrder2);
1075 case 6: return getDkTensorIndex<1, 6>(dkEnum1, operatorOrder1, dkEnum2, operatorOrder2);
1076 default:
1077 INTREPID2_TEST_FOR_EXCEPTION(true, std::invalid_argument, "Unsupported dimension combination");
1078 }
1079 case 2:
1080 switch (spaceDim2)
1081 {
1082 case 1: return getDkTensorIndex<2, 1>(dkEnum1, operatorOrder1, dkEnum2, operatorOrder2);
1083 case 2: return getDkTensorIndex<2, 2>(dkEnum1, operatorOrder1, dkEnum2, operatorOrder2);
1084 case 3: return getDkTensorIndex<2, 3>(dkEnum1, operatorOrder1, dkEnum2, operatorOrder2);
1085 case 4: return getDkTensorIndex<2, 4>(dkEnum1, operatorOrder1, dkEnum2, operatorOrder2);
1086 case 5: return getDkTensorIndex<2, 5>(dkEnum1, operatorOrder1, dkEnum2, operatorOrder2);
1087 default:
1088 INTREPID2_TEST_FOR_EXCEPTION(true, std::invalid_argument, "Unsupported dimension combination");
1089 }
1090 case 3:
1091 switch (spaceDim2)
1092 {
1093 case 1: return getDkTensorIndex<3, 1>(dkEnum1, operatorOrder1, dkEnum2, operatorOrder2);
1094 case 2: return getDkTensorIndex<3, 2>(dkEnum1, operatorOrder1, dkEnum2, operatorOrder2);
1095 case 3: return getDkTensorIndex<3, 3>(dkEnum1, operatorOrder1, dkEnum2, operatorOrder2);
1096 case 4: return getDkTensorIndex<3, 4>(dkEnum1, operatorOrder1, dkEnum2, operatorOrder2);
1097 default:
1098 INTREPID2_TEST_FOR_EXCEPTION(true, std::invalid_argument, "Unsupported dimension combination");
1099 }
1100 case 4:
1101 switch (spaceDim2)
1102 {
1103 case 1: return getDkTensorIndex<4, 1>(dkEnum1, operatorOrder1, dkEnum2, operatorOrder2);
1104 case 2: return getDkTensorIndex<4, 2>(dkEnum1, operatorOrder1, dkEnum2, operatorOrder2);
1105 case 3: return getDkTensorIndex<4, 3>(dkEnum1, operatorOrder1, dkEnum2, operatorOrder2);
1106 default:
1107 INTREPID2_TEST_FOR_EXCEPTION(true, std::invalid_argument, "Unsupported dimension combination");
1108 }
1109 case 5:
1110 switch (spaceDim2)
1111 {
1112 case 1: return getDkTensorIndex<5, 1>(dkEnum1, operatorOrder1, dkEnum2, operatorOrder2);
1113 case 2: return getDkTensorIndex<5, 2>(dkEnum1, operatorOrder1, dkEnum2, operatorOrder2);
1114 default:
1115 INTREPID2_TEST_FOR_EXCEPTION(true, std::invalid_argument, "Unsupported dimension combination");
1116 }
1117 case 6:
1118 switch (spaceDim2)
1119 {
1120 case 1: return getDkTensorIndex<6, 1>(dkEnum1, operatorOrder1, dkEnum2, operatorOrder2);
1121 default:
1122 INTREPID2_TEST_FOR_EXCEPTION(true, std::invalid_argument, "Unsupported dimension combination");
1123 }
1124 default:
1125 INTREPID2_TEST_FOR_EXCEPTION(true, std::invalid_argument, "Unsupported dimension combination");
1126 }
1127 }
1128
1133 virtual OperatorTensorDecomposition getSimpleOperatorDecomposition(const EOperator &operatorType) const
1134 {
1135 const int spaceDim = this->getDomainDimension();
1136
1137 const EOperator VALUE = Intrepid2::OPERATOR_VALUE;
1138
1139 std::vector< std::vector<EOperator> > opsVALUE{{VALUE, VALUE}};
1140
1141 std::vector< std::vector<EOperator> > ops(spaceDim);
1142
1143 switch (operatorType)
1144 {
1145 case VALUE:
1146 ops = opsVALUE;
1147 break;
1148 case OPERATOR_DIV:
1149 case OPERATOR_CURL:
1150 // DIV and CURL are multi-family bases; subclasses are required to override
1151 INTREPID2_TEST_FOR_EXCEPTION(true, std::invalid_argument, "Unsupported operator type - TensorBasis subclass should override");
1152 break;
1153 case OPERATOR_GRAD:
1154 case OPERATOR_D1:
1155 case OPERATOR_D2:
1156 case OPERATOR_D3:
1157 case OPERATOR_D4:
1158 case OPERATOR_D5:
1159 case OPERATOR_D6:
1160 case OPERATOR_D7:
1161 case OPERATOR_D8:
1162 case OPERATOR_D9:
1163 case OPERATOR_D10:
1164 case OPERATOR_Dn:
1165 {
1166 auto opOrder = getOperatorOrder(operatorType); // number of derivatives that we take in total
1167 const int dkCardinality = getDkCardinality(operatorType, 2); // 2 because we have two tensor component bases, basis1_ and basis2_
1168
1169 ops = std::vector< std::vector<EOperator> >(dkCardinality);
1170
1171 // the Dk enumeration happens in lexicographic order (reading from left to right: x, y, z, etc.)
1172 // this governs the nesting order of the dkEnum1, dkEnum2 for loops below: dkEnum2 should increment fastest.
1173 for (int derivativeCountComp2=0; derivativeCountComp2<=opOrder; derivativeCountComp2++)
1174 {
1175 int derivativeCountComp1=opOrder-derivativeCountComp2;
1176 EOperator op1 = (derivativeCountComp1 == 0) ? OPERATOR_VALUE : EOperator(OPERATOR_D1 + (derivativeCountComp1 - 1));
1177 EOperator op2 = (derivativeCountComp2 == 0) ? OPERATOR_VALUE : EOperator(OPERATOR_D1 + (derivativeCountComp2 - 1));
1178
1179 int dkCardinality1 = getDkCardinality(op1, 1); // use dim = 1 because this is a "simple" decomposition -- full decomposition will expand within the dimensions of basis1_
1180 int dkCardinality2 = getDkCardinality(op2, 1); // use dim = 1 because this is a "simple" decomposition -- full decomposition will expand within the dimensions of basis2_
1181
1182 for (int dkEnum1=0; dkEnum1<dkCardinality1; dkEnum1++)
1183 {
1184 for (int dkEnum2=0; dkEnum2<dkCardinality2; dkEnum2++)
1185 {
1186 ordinal_type dkTensorIndex = getDkTensorIndex<1, 1>(dkEnum1, derivativeCountComp1, dkEnum2, derivativeCountComp2);
1187 ops[dkTensorIndex] = std::vector<EOperator>{op1, op2};
1188 }
1189 }
1190 }
1191 }
1192 break;
1193 }
1194
1195 std::vector<double> weights(ops.size(), 1.0);
1196 return OperatorTensorDecomposition(ops, weights);
1197 }
1198
1201 virtual OperatorTensorDecomposition getOperatorDecomposition(const EOperator operatorType) const
1202 {
1203 if (((operatorType >= OPERATOR_D1) && (operatorType <= OPERATOR_D10)) || (operatorType == OPERATOR_GRAD))
1204 {
1205 // ordering of the operators is reverse-lexicographic, reading left to right (highest-dimension is fastest-moving).
1206 // first entry will be (operatorType, VALUE, …, VALUE)
1207 // next will be (operatorType - 1, OP_D1, VALUE, …, VALUE)
1208 // then (operatorType - 1, VALUE, OP_D1, …, VALUE)
1209
1210 ordinal_type numBasisComponents = tensorComponents_.size();
1211
1212 auto opOrder = getOperatorOrder(operatorType); // number of derivatives that we take in total
1213 const int dkCardinality = getDkCardinality(operatorType, numBasisComponents);
1214
1215 std::vector< std::vector<EOperator> > ops(dkCardinality);
1216
1217 std::vector<EOperator> prevEntry(numBasisComponents, OPERATOR_VALUE);
1218 prevEntry[0] = operatorType;
1219
1220 ops[0] = prevEntry;
1221
1222 for (ordinal_type dkOrdinal=1; dkOrdinal<dkCardinality; dkOrdinal++)
1223 {
1224 std::vector<EOperator> entry = prevEntry;
1225
1226 // decrement to follow reverse lexicographic ordering:
1227 /*
1228 How to tell when it is time to decrement the nth entry:
1229 1. Let a be the sum of the opOrders for entries 0 through n-1.
1230 2. Let b be the sum of the nth entry and the final entry.
1231 3. If opOrder == a + b, then the nth entry should be decremented.
1232 */
1233 ordinal_type cumulativeOpOrder = 0;
1234 ordinal_type finalOpOrder = getOperatorOrder(entry[numBasisComponents-1]);
1235 for (ordinal_type compOrdinal=0; compOrdinal<numBasisComponents; compOrdinal++)
1236 {
1237 const ordinal_type thisOpOrder = getOperatorOrder(entry[compOrdinal]);
1238 cumulativeOpOrder += thisOpOrder;
1239 if (cumulativeOpOrder + finalOpOrder == opOrder)
1240 {
1241 // decrement this
1242 EOperator decrementedOp;
1243 if (thisOpOrder == 1)
1244 {
1245 decrementedOp = OPERATOR_VALUE;
1246 }
1247 else
1248 {
1249 decrementedOp = static_cast<EOperator>(OPERATOR_D1 + ((thisOpOrder - 1) - 1));
1250 }
1251 entry[compOrdinal] = decrementedOp;
1252 const ordinal_type remainingOpOrder = opOrder - cumulativeOpOrder + 1;
1253 entry[compOrdinal+1] = static_cast<EOperator>(OPERATOR_D1 + (remainingOpOrder - 1));
1254 for (ordinal_type i=compOrdinal+2; i<numBasisComponents; i++)
1255 {
1256 entry[i] = OPERATOR_VALUE;
1257 }
1258 break;
1259 }
1260 }
1261 ops[dkOrdinal] = entry;
1262 prevEntry = entry;
1263 }
1264 std::vector<double> weights(dkCardinality, 1.0);
1265
1266 return OperatorTensorDecomposition(ops, weights);
1267 }
1268 else
1269 {
1270 OperatorTensorDecomposition opSimpleDecomposition = this->getSimpleOperatorDecomposition(operatorType);
1271 std::vector<BasisPtr> componentBases {basis1_, basis2_};
1272 return opSimpleDecomposition.expandedDecomposition(componentBases);
1273 }
1274 }
1275
1280 virtual BasisValues<OutputValueType,DeviceType> allocateBasisValues( TensorPoints<PointValueType,DeviceType> points, const EOperator operatorType = OPERATOR_VALUE) const override
1281 {
1282 const bool operatorIsDk = (operatorType >= OPERATOR_D1) && (operatorType <= OPERATOR_D10);
1283 const bool operatorSupported = (operatorType == OPERATOR_VALUE) || (operatorType == OPERATOR_GRAD) || (operatorType == OPERATOR_CURL) || (operatorType == OPERATOR_DIV) || operatorIsDk;
1284 INTREPID2_TEST_FOR_EXCEPTION(!operatorSupported, std::invalid_argument, "operator is not supported by allocateBasisValues");
1285
1286 // check that points's spatial dimension matches the basis
1287 const int spaceDim = this->getDomainDimension();
1288 INTREPID2_TEST_FOR_EXCEPTION(spaceDim != points.extent_int(1), std::invalid_argument, "points must be shape (P,D), with D equal to the dimension of the basis domain");
1289
1290 // check that points has enough tensor components
1291 ordinal_type numBasisComponents = tensorComponents_.size();
1292 if (numBasisComponents > points.numTensorComponents())
1293 {
1294 // Then we require points to have a trivial tensor structure. (Subclasses could be more sophisticated.)
1295 // (More sophisticated approaches are possible here, too, but likely the most common use case in which there is not a one-to-one correspondence
1296 // between basis components and point components will involve trivial tensor structure in the points...)
1297 INTREPID2_TEST_FOR_EXCEPTION(points.numTensorComponents() != 1, std::invalid_argument, "If points does not have the same number of tensor components as the basis, then it should have trivial tensor structure.");
1298 const ordinal_type numPoints = points.extent_int(0);
1299 auto outputView = this->allocateOutputView(numPoints, operatorType);
1300
1301 Data<OutputValueType,DeviceType> outputData(outputView);
1302 TensorData<OutputValueType,DeviceType> outputTensorData(outputData);
1303
1304 return BasisValues<OutputValueType,DeviceType>(outputTensorData);
1305 }
1306 INTREPID2_TEST_FOR_EXCEPTION(numBasisComponents > points.numTensorComponents(), std::invalid_argument, "points must have at least as many tensorial components as basis.");
1307
1308 OperatorTensorDecomposition opDecomposition = getOperatorDecomposition(operatorType);
1309
1310 ordinal_type numVectorComponents = opDecomposition.numVectorComponents();
1311 const bool useVectorData = numVectorComponents > 1;
1312
1313 std::vector<ordinal_type> componentPointCounts(numBasisComponents);
1314 ordinal_type pointComponentNumber = 0;
1315 for (ordinal_type r=0; r<numBasisComponents; r++)
1316 {
1317 const ordinal_type compSpaceDim = tensorComponents_[r]->getDomainDimension();
1318 ordinal_type dimsSoFar = 0;
1319 ordinal_type numPointsForBasisComponent = 1;
1320 while (dimsSoFar < compSpaceDim)
1321 {
1322 INTREPID2_TEST_FOR_EXCEPTION(pointComponentNumber >= points.numTensorComponents(), std::invalid_argument, "Error in processing points container; perhaps it is mis-sized?");
1323 const int numComponentPoints = points.componentPointCount(pointComponentNumber);
1324 const int numComponentDims = points.getTensorComponent(pointComponentNumber).extent_int(1);
1325 numPointsForBasisComponent *= numComponentPoints;
1326 dimsSoFar += numComponentDims;
1327 INTREPID2_TEST_FOR_EXCEPTION(dimsSoFar > points.numTensorComponents(), std::invalid_argument, "Error in processing points container; perhaps it is mis-sized?");
1328 pointComponentNumber++;
1329 }
1330 componentPointCounts[r] = numPointsForBasisComponent;
1331 }
1332
1333 if (useVectorData)
1334 {
1335 const int numFamilies = 1;
1336 std::vector< std::vector<TensorData<OutputValueType,DeviceType> > > vectorComponents(numFamilies, std::vector<TensorData<OutputValueType,DeviceType> >(numVectorComponents));
1337
1338 const int familyOrdinal = 0;
1339 for (ordinal_type vectorComponentOrdinal=0; vectorComponentOrdinal<numVectorComponents; vectorComponentOrdinal++)
1340 {
1341 if (!opDecomposition.identicallyZeroComponent(vectorComponentOrdinal))
1342 {
1343 std::vector< Data<OutputValueType,DeviceType> > componentData;
1344 for (ordinal_type r=0; r<numBasisComponents; r++)
1345 {
1346 const int numComponentPoints = componentPointCounts[r];
1347 const EOperator op = opDecomposition.op(vectorComponentOrdinal, r);
1348 auto componentView = tensorComponents_[r]->allocateOutputView(numComponentPoints, op);
1349 componentData.push_back(Data<OutputValueType,DeviceType>(componentView));
1350 }
1351 vectorComponents[familyOrdinal][vectorComponentOrdinal] = TensorData<OutputValueType,DeviceType>(componentData);
1352 }
1353 }
1354 VectorData<OutputValueType,DeviceType> vectorData(vectorComponents);
1355 return BasisValues<OutputValueType,DeviceType>(vectorData);
1356 }
1357 else
1358 {
1359 // TensorData: single tensor product
1360 std::vector< Data<OutputValueType,DeviceType> > componentData;
1361
1362 const ordinal_type vectorComponentOrdinal = 0;
1363 for (ordinal_type r=0; r<numBasisComponents; r++)
1364 {
1365 const int numComponentPoints = componentPointCounts[r];
1366 const EOperator op = opDecomposition.op(vectorComponentOrdinal, r);
1367 auto componentView = tensorComponents_[r]->allocateOutputView(numComponentPoints, op);
1368
1369 const int rank = 2; // (F,P) -- TensorData-only BasisValues are always scalar-valued. Use VectorData for vector-valued.
1370 // (we need to be explicit about the rank argument because GRAD, even in 1D, elevates to rank 3), so e.g. DIV of HDIV uses a componentView that is rank 3;
1371 // we want Data to insulate us from that fact)
1372 const Kokkos::Array<int,7> extents {componentView.extent_int(0), componentView.extent_int(1), 1,1,1,1,1};
1373 Kokkos::Array<DataVariationType,7> variationType {GENERAL, GENERAL, CONSTANT, CONSTANT, CONSTANT, CONSTANT, CONSTANT };
1374 componentData.push_back(Data<OutputValueType,DeviceType>(componentView, rank, extents, variationType));
1375 }
1376
1377 TensorData<OutputValueType,DeviceType> tensorData(componentData);
1378
1379 std::vector< TensorData<OutputValueType,DeviceType> > tensorDataEntries {tensorData};
1380 return BasisValues<OutputValueType,DeviceType>(tensorDataEntries);
1381 }
1382 }
1383
1384 // since the getValues() below only overrides the FEM variant, we specify that
1385 // we use the base class's getValues(), which implements the FVD variant by throwing an exception.
1386 // (It's an error to use the FVD variant on this basis.)
1387 using BasisBase::getValues;
1388
1400 void getComponentPoints(const PointViewType inputPoints, const bool attemptTensorDecomposition,
1401 PointViewType & inputPoints1, PointViewType & inputPoints2, bool &tensorDecompositionSucceeded) const
1402 {
1403 INTREPID2_TEST_FOR_EXCEPTION(attemptTensorDecomposition, std::invalid_argument, "tensor decomposition not yet supported");
1404
1405 // for inputPoints that are actually tensor-product of component quadrature points (say),
1406 // having just the one input (which will have a lot of redundant point data) is suboptimal
1407 // The general case can have unique x/y/z coordinates at every point, though, so we have to support that
1408 // when this interface is used. But we may try detecting that the data is tensor-product and compressing
1409 // from there... Ultimately, we should also add a getValues() variant that takes multiple input point containers,
1410 // one for each tensorial dimension.
1411
1412 // this initial implementation is intended to simplify development of 2D and 3D bases, while also opening
1413 // the possibility of higher-dimensional bases. It is not necessarily optimized for speed/memory. There
1414 // are things we can do in this regard, which may become important for matrix-free computations wherein
1415 // basis values don't get stored but are computed dynamically.
1416
1417 int spaceDim1 = basis1_->getDomainDimension();
1418 int spaceDim2 = basis2_->getDomainDimension();
1419
1420 int totalSpaceDim = inputPoints.extent_int(1);
1421
1422 TEUCHOS_ASSERT(spaceDim1 + spaceDim2 == totalSpaceDim);
1423
1424 // first pass: just take subviews to get input points -- this will result in redundant computations when points are themselves tensor product (i.e., inputPoints itself contains redundant data)
1425
1426 inputPoints1 = Kokkos::subview(inputPoints,Kokkos::ALL(),std::make_pair(0,spaceDim1));
1427 inputPoints2 = Kokkos::subview(inputPoints,Kokkos::ALL(),std::make_pair(spaceDim1,totalSpaceDim));
1428
1429 // std::cout << "inputPoints : " << inputPoints.extent(0) << " x " << inputPoints.extent(1) << std::endl;
1430 // std::cout << "inputPoints1 : " << inputPoints1.extent(0) << " x " << inputPoints1.extent(1) << std::endl;
1431 // std::cout << "inputPoints2 : " << inputPoints2.extent(0) << " x " << inputPoints2.extent(1) << std::endl;
1432
1433 tensorDecompositionSucceeded = false;
1434 }
1435
1444 virtual void getDofCoords( typename BasisBase::ScalarViewType dofCoords ) const override
1445 {
1446 int spaceDim1 = basis1_->getBaseCellTopology().getDimension();
1447 int spaceDim2 = basis2_->getBaseCellTopology().getDimension();
1448
1449 using ValueType = typename BasisBase::ScalarViewType::value_type;
1450 using ResultLayout = typename DeduceLayout< typename BasisBase::ScalarViewType >::result_layout;
1451 using ViewType = Kokkos::DynRankView<ValueType, ResultLayout, DeviceType >;
1452
1453 const ordinal_type basisCardinality1 = basis1_->getCardinality();
1454 const ordinal_type basisCardinality2 = basis2_->getCardinality();
1455
1456 ViewType dofCoords1("dofCoords1",basisCardinality1,spaceDim1);
1457 ViewType dofCoords2("dofCoords2",basisCardinality2,spaceDim2);
1458
1459 basis1_->getDofCoords(dofCoords1);
1460 basis2_->getDofCoords(dofCoords2);
1461
1462 Kokkos::RangePolicy<ExecutionSpace> policy(0, basisCardinality2);
1463 Kokkos::parallel_for(policy, KOKKOS_LAMBDA (const int fieldOrdinal2)
1464 {
1465 for (int fieldOrdinal1=0; fieldOrdinal1<basisCardinality1; fieldOrdinal1++)
1466 {
1467 const ordinal_type fieldOrdinal = fieldOrdinal1 + fieldOrdinal2 * basisCardinality1;
1468 for (int d1=0; d1<spaceDim1; d1++)
1469 {
1470 dofCoords(fieldOrdinal,d1) = dofCoords1(fieldOrdinal1,d1);
1471 }
1472 for (int d2=0; d2<spaceDim2; d2++)
1473 {
1474 dofCoords(fieldOrdinal,spaceDim1+d2) = dofCoords2(fieldOrdinal2,d2);
1475 }
1476 }
1477 });
1478 }
1479
1480
1490 virtual void getDofCoeffs( typename BasisBase::ScalarViewType dofCoeffs ) const override
1491 {
1492 using ValueType = typename BasisBase::ScalarViewType::value_type;
1493 using ResultLayout = typename DeduceLayout< typename BasisBase::ScalarViewType >::result_layout;
1494 using ViewType = Kokkos::DynRankView<ValueType, ResultLayout, DeviceType >;
1495
1496 const ordinal_type basisCardinality1 = basis1_->getCardinality();
1497 const ordinal_type basisCardinality2 = basis2_->getCardinality();
1498
1499 bool isVectorBasis1 = getFieldRank(basis1_->getFunctionSpace()) == 1;
1500 bool isVectorBasis2 = getFieldRank(basis2_->getFunctionSpace()) == 1;
1501
1502 INTREPID2_TEST_FOR_EXCEPTION(isVectorBasis1 && isVectorBasis2, std::invalid_argument, "the case in which basis1 and basis2 are vector bases is not supported");
1503
1504 int basisDim1 = isVectorBasis1 ? basis1_->getBaseCellTopology().getDimension() : 1;
1505 int basisDim2 = isVectorBasis2 ? basis2_->getBaseCellTopology().getDimension() : 1;
1506
1507 auto dofCoeffs1 = isVectorBasis1 ? ViewType("dofCoeffs1",basis1_->getCardinality(), basisDim1) : ViewType("dofCoeffs1",basis1_->getCardinality());
1508 auto dofCoeffs2 = isVectorBasis2 ? ViewType("dofCoeffs2",basis2_->getCardinality(), basisDim2) : ViewType("dofCoeffs2",basis2_->getCardinality());
1509
1510 basis1_->getDofCoeffs(dofCoeffs1);
1511 basis2_->getDofCoeffs(dofCoeffs2);
1512
1513 Kokkos::RangePolicy<ExecutionSpace> policy(0, basisCardinality2);
1514 Kokkos::parallel_for(policy, KOKKOS_LAMBDA (const int fieldOrdinal2)
1515 {
1516 for (int fieldOrdinal1=0; fieldOrdinal1<basisCardinality1; fieldOrdinal1++)
1517 {
1518 const ordinal_type fieldOrdinal = fieldOrdinal1 + fieldOrdinal2 * basisCardinality1;
1519 for (int d1 = 0; d1 <basisDim1; d1++) {
1520 for (int d2 = 0; d2 <basisDim2; d2++) {
1521 dofCoeffs.access(fieldOrdinal,d1+d2) = dofCoeffs1.access(fieldOrdinal1,d1);
1522 dofCoeffs.access(fieldOrdinal,d1+d2) *= dofCoeffs2.access(fieldOrdinal2,d2);
1523 }
1524 }
1525 }
1526 });
1527 }
1528
1533 virtual
1534 const char*
1535 getName() const override {
1536 return name_.c_str();
1537 }
1538
1539 std::vector<BasisPtr> getTensorBasisComponents() const
1540 {
1541 return tensorComponents_;
1542 }
1543
1555 virtual
1556 void
1559 const EOperator operatorType = OPERATOR_VALUE ) const override
1560 {
1561 const ordinal_type numTensorComponents = tensorComponents_.size();
1562 if (inputPoints.numTensorComponents() < numTensorComponents)
1563 {
1564 // then we require that both inputPoints and outputValues trivial tensor structure
1565 INTREPID2_TEST_FOR_EXCEPTION( inputPoints.numTensorComponents() != 1, std::invalid_argument, "If inputPoints differs from the tensor basis in component count, then inputPoints must have trivial tensor product structure" );
1566 INTREPID2_TEST_FOR_EXCEPTION( outputValues.numFamilies() != 1, std::invalid_argument, "If inputPoints differs from the tensor basis in component count, outputValues must have a single family with trivial tensor product structure" );
1567 INTREPID2_TEST_FOR_EXCEPTION( outputValues.tensorData().numTensorComponents() != 1, std::invalid_argument, "If inputPoints differs from the tensor basis in component count, outputValues must have a single family with trivial tensor product structure" );
1568
1569 OutputViewType outputView = outputValues.tensorData().getTensorComponent(0).getUnderlyingView();
1570 PointViewType pointView = inputPoints.getTensorComponent(0);
1571 this->getValues(outputView, pointView, operatorType);
1572 return;
1573 }
1574
1575 OperatorTensorDecomposition operatorDecomposition = getOperatorDecomposition(operatorType);
1576
1577 const ordinal_type numVectorComponents = operatorDecomposition.numVectorComponents();
1578 const bool useVectorData = numVectorComponents > 1;
1579 const ordinal_type numBasisComponents = operatorDecomposition.numBasisComponents();
1580
1581 for (ordinal_type vectorComponentOrdinal=0; vectorComponentOrdinal<numVectorComponents; vectorComponentOrdinal++)
1582 {
1583 const double weight = operatorDecomposition.weight(vectorComponentOrdinal);
1584 ordinal_type pointComponentOrdinal = 0;
1585 for (ordinal_type basisOrdinal=0; basisOrdinal<numBasisComponents; basisOrdinal++, pointComponentOrdinal++)
1586 {
1587 const EOperator op = operatorDecomposition.op(vectorComponentOrdinal, basisOrdinal);
1588 // by convention, op == OPERATOR_MAX signals a zero component; skip
1589 if (op != OPERATOR_MAX)
1590 {
1591 const int vectorFamily = 0; // TensorBasis always has just a single family; multiple families arise in DirectSumBasis
1592 auto tensorData = useVectorData ? outputValues.vectorData().getComponent(vectorFamily,vectorComponentOrdinal) : outputValues.tensorData();
1593 INTREPID2_TEST_FOR_EXCEPTION( ! tensorData.getTensorComponent(basisOrdinal).isValid(), std::invalid_argument, "Invalid output component encountered");
1594
1595 const Data<OutputValueType,DeviceType> & outputData = tensorData.getTensorComponent(basisOrdinal);
1596
1597 auto basisValueView = outputData.getUnderlyingView();
1598 PointViewType pointView = inputPoints.getTensorComponent(pointComponentOrdinal);
1599 const ordinal_type basisDomainDimension = tensorComponents_[basisOrdinal]->getDomainDimension();
1600 if (pointView.extent_int(1) == basisDomainDimension)
1601 {
1602 tensorComponents_[basisOrdinal]->getValues(basisValueView, pointView, op);
1603 }
1604 else
1605 {
1606 // we need to wrap the basisValueView in a BasisValues container, and to wrap the point components in a TensorPoints container.
1607
1608 // combine point components to build up to basisDomainDimension
1609 ordinal_type dimsSoFar = 0;
1610 std::vector< ScalarView<PointValueType,DeviceType> > basisPointComponents;
1611 while (dimsSoFar < basisDomainDimension)
1612 {
1613 INTREPID2_TEST_FOR_EXCEPTION(pointComponentOrdinal >= inputPoints.numTensorComponents(), std::invalid_argument, "Error in processing points container; perhaps it is mis-sized?");
1614 const auto & pointComponent = inputPoints.getTensorComponent(pointComponentOrdinal);
1615 const ordinal_type numComponentDims = pointComponent.extent_int(1);
1616 dimsSoFar += numComponentDims;
1617 INTREPID2_TEST_FOR_EXCEPTION(dimsSoFar > inputPoints.numTensorComponents(), std::invalid_argument, "Error in processing points container; perhaps it is mis-sized?");
1618 basisPointComponents.push_back(pointComponent);
1619 if (dimsSoFar < basisDomainDimension)
1620 {
1621 // we will pass through this loop again, so we should increment the point component ordinal
1622 pointComponentOrdinal++;
1623 }
1624 }
1625
1626 TensorPoints<PointValueType, DeviceType> basisPoints(basisPointComponents);
1627
1628 bool useVectorData2 = (basisValueView.rank() == 3);
1629
1631 if (useVectorData2)
1632 {
1633 VectorData<OutputValueType,DeviceType> vectorData(outputData);
1634 basisValues = BasisValues<OutputValueType,DeviceType>(vectorData);
1635 }
1636 else
1637 {
1638 TensorData<OutputValueType,DeviceType> tensorData2(outputData);
1639 basisValues = BasisValues<OutputValueType,DeviceType>(tensorData2);
1640 }
1641
1642 tensorComponents_[basisOrdinal]->getValues(basisValues, basisPoints, op);
1643 }
1644
1645 // op.rotateXYNinetyDegrees() is set to true for one of the H(curl) wedge families
1646 // (due to the fact that Intrepid2::EOperator does not allow us to extract individual vector components
1647 // via, e.g., OPERATOR_X, OPERATOR_Y, etc., we don't have a way of expressing the decomposition
1648 // just in terms of EOperator and component-wise scalar weights; we could also do this via component-wise
1649 // matrix weights, but this would involve a more intrusive change to the implementation).
1650 const bool spansXY = (vectorComponentOrdinal == 0) && (basisValueView.extent_int(2) == 2);
1651 if (spansXY && operatorDecomposition.rotateXYNinetyDegrees())
1652 {
1653 // map from (f_x,f_y) --> (-f_y,f_x)
1654 auto policy = Kokkos::MDRangePolicy<ExecutionSpace,Kokkos::Rank<2>>({0,0},{basisValueView.extent_int(0),basisValueView.extent_int(1)});
1655 Kokkos::parallel_for("rotateXYNinetyDegrees", policy,
1656 KOKKOS_LAMBDA (const int &fieldOrdinal, const int &pointOrdinal) {
1657 const auto f_x = basisValueView(fieldOrdinal,pointOrdinal,0); // copy
1658 const auto &f_y = basisValueView(fieldOrdinal,pointOrdinal,1); // reference
1659 basisValueView(fieldOrdinal,pointOrdinal,0) = -f_y;
1660 basisValueView(fieldOrdinal,pointOrdinal,1) = f_x;
1661 });
1662 }
1663
1664 // if weight is non-trivial (not 1.0), then we need to multiply one of the component views by weight.
1665 // we do that for the first basisOrdinal's values
1666 if ((weight != 1.0) && (basisOrdinal == 0))
1667 {
1668 if (basisValueView.rank() == 2)
1669 {
1670 auto policy = Kokkos::MDRangePolicy<ExecutionSpace,Kokkos::Rank<2>>({0,0},{basisValueView.extent_int(0),basisValueView.extent_int(1)});
1671 Kokkos::parallel_for("multiply basisValueView by weight", policy,
1672 KOKKOS_LAMBDA (const int &fieldOrdinal, const int &pointOrdinal) {
1673 basisValueView(fieldOrdinal,pointOrdinal) *= weight;
1674 });
1675 }
1676 else if (basisValueView.rank() == 3)
1677 {
1678 auto policy = Kokkos::MDRangePolicy<ExecutionSpace,Kokkos::Rank<3>>({0,0,0},{basisValueView.extent_int(0),basisValueView.extent_int(1),basisValueView.extent_int(2)});
1679 Kokkos::parallel_for("multiply basisValueView by weight", policy,
1680 KOKKOS_LAMBDA (const int &fieldOrdinal, const int &pointOrdinal, const int &d) {
1681 basisValueView(fieldOrdinal,pointOrdinal,d) *= weight;
1682 });
1683 }
1684 else
1685 {
1686 INTREPID2_TEST_FOR_EXCEPTION(true, std::invalid_argument, "Unsupported rank for basisValueView");
1687 }
1688 }
1689 }
1690 }
1691 }
1692 }
1693
1712 void getValues( OutputViewType outputValues, const PointViewType inputPoints,
1713 const EOperator operatorType = OPERATOR_VALUE ) const override
1714 {
1715 bool tensorPoints; // true would mean that we take the tensor product of inputPoints1 and inputPoints2 (and that this would be equivalent to inputPoints as given -- i.e., inputPoints1 and inputPoints2 would be a tensor decomposition of inputPoints)
1716 bool attemptTensorDecomposition = false; // support for this not yet implemented
1717 PointViewType inputPoints1, inputPoints2;
1718 getComponentPoints(inputPoints, attemptTensorDecomposition, inputPoints1, inputPoints2, tensorPoints);
1719
1720 const auto functionSpace = this->getFunctionSpace();
1721
1722 if ((functionSpace == FUNCTION_SPACE_HVOL) || (functionSpace == FUNCTION_SPACE_HGRAD))
1723 {
1724 // then we can handle VALUE, GRAD, and Op_Dn without reference to subclass
1725 switch (operatorType)
1726 {
1727 case OPERATOR_VALUE:
1728 case OPERATOR_GRAD:
1729 case OPERATOR_D1:
1730 case OPERATOR_D2:
1731 case OPERATOR_D3:
1732 case OPERATOR_D4:
1733 case OPERATOR_D5:
1734 case OPERATOR_D6:
1735 case OPERATOR_D7:
1736 case OPERATOR_D8:
1737 case OPERATOR_D9:
1738 case OPERATOR_D10:
1739 {
1740 auto opOrder = getOperatorOrder(operatorType); // number of derivatives that we take in total
1741 // the Dk enumeration happens in lexicographic order (reading from left to right: x, y, z, etc.)
1742 // this governs the nesting order of the dkEnum1, dkEnum2 for loops below: dkEnum2 should increment fastest.
1743 for (int derivativeCountComp2=0; derivativeCountComp2<=opOrder; derivativeCountComp2++)
1744 {
1745 int derivativeCountComp1=opOrder-derivativeCountComp2;
1746 EOperator op1 = (derivativeCountComp1 == 0) ? OPERATOR_VALUE : EOperator(OPERATOR_D1 + (derivativeCountComp1 - 1));
1747 EOperator op2 = (derivativeCountComp2 == 0) ? OPERATOR_VALUE : EOperator(OPERATOR_D1 + (derivativeCountComp2 - 1));
1748
1749 int spaceDim1 = inputPoints1.extent_int(1);
1750 int spaceDim2 = inputPoints2.extent_int(1);
1751
1752 int dkCardinality1 = (op1 != OPERATOR_VALUE) ? getDkCardinality(op1, spaceDim1) : 1;
1753 int dkCardinality2 = (op2 != OPERATOR_VALUE) ? getDkCardinality(op2, spaceDim2) : 1;
1754
1755 int basisCardinality1 = basis1_->getCardinality();
1756 int basisCardinality2 = basis2_->getCardinality();
1757
1758 int totalPointCount = tensorPoints ? inputPoints1.extent_int(0) * inputPoints2.extent_int(0) : inputPoints1.extent_int(0);
1759
1760 int pointCount1, pointCount2;
1761 if (tensorPoints)
1762 {
1763 pointCount1 = inputPoints1.extent_int(0);
1764 pointCount2 = inputPoints2.extent_int(0);
1765 }
1766 else
1767 {
1768 pointCount1 = totalPointCount;
1769 pointCount2 = totalPointCount;
1770 }
1771
1772 OutputViewType outputValues1, outputValues2;
1773 if (op1 == OPERATOR_VALUE)
1774 outputValues1 = Impl::createMatchingDynRankView(outputValues, "output values - basis 1",basisCardinality1,pointCount1);
1775 else
1776 outputValues1 = Impl::createMatchingDynRankView(outputValues, "output values - basis 1",basisCardinality1,pointCount1,dkCardinality1);
1777
1778 if (op2 == OPERATOR_VALUE)
1779 outputValues2 = Impl::createMatchingDynRankView(outputValues, "output values - basis 2",basisCardinality2,pointCount2);
1780 else
1781 outputValues2 = Impl::createMatchingDynRankView(outputValues, "output values - basis 2",basisCardinality2,pointCount2,dkCardinality2);
1782
1783 basis1_->getValues(outputValues1,inputPoints1,op1);
1784 basis2_->getValues(outputValues2,inputPoints2,op2);
1785
1786 const int outputVectorSize = getVectorSizeForHierarchicalParallelism<OutputValueType>();
1787 const int pointVectorSize = getVectorSizeForHierarchicalParallelism<PointValueType>();
1788 const int vectorSize = std::max(outputVectorSize,pointVectorSize);
1789
1790 auto policy = Kokkos::TeamPolicy<ExecutionSpace>(basisCardinality1,Kokkos::AUTO(),vectorSize);
1791
1792 double weight = 1.0;
1794
1795 for (int dkEnum1=0; dkEnum1<dkCardinality1; dkEnum1++)
1796 {
1797 auto outputValues1_dkEnum1 = (op1 != OPERATOR_VALUE) ? Kokkos::subview(outputValues1,Kokkos::ALL(),Kokkos::ALL(),dkEnum1)
1798 : Kokkos::subview(outputValues1,Kokkos::ALL(),Kokkos::ALL());
1799 for (int dkEnum2=0; dkEnum2<dkCardinality2; dkEnum2++)
1800 {
1801 auto outputValues2_dkEnum2 = (op2 != OPERATOR_VALUE) ? Kokkos::subview(outputValues2,Kokkos::ALL(),Kokkos::ALL(),dkEnum2)
1802 : Kokkos::subview(outputValues2,Kokkos::ALL(),Kokkos::ALL());
1803
1804 ordinal_type dkTensorIndex = getTensorDkEnumeration(dkEnum1, derivativeCountComp1, dkEnum2, derivativeCountComp2);
1805 auto outputValues_dkTensor = Kokkos::subview(outputValues,Kokkos::ALL(),Kokkos::ALL(),dkTensorIndex);
1806 // Note that there may be performance optimizations available here:
1807 // - could eliminate interior for loop in favor of having a vector-valued outputValues1_dk
1808 // - could add support to TensorViewFunctor (and probably TensorViewIterator) for this kind of tensor Dk type of traversal
1809 // (this would allow us to eliminate both for loops here)
1810 // At the moment, we defer such optimizations on the idea that this may not ever become a performance bottleneck.
1811 FunctorType functor(outputValues_dkTensor, outputValues1_dkEnum1, outputValues2_dkEnum2, tensorPoints, weight);
1812 Kokkos::parallel_for("TensorViewFunctor", policy , functor);
1813 }
1814 }
1815 }
1816 }
1817 break;
1818 default: // non-OPERATOR_Dn case must be handled by subclass.
1819 this->getValues(outputValues, operatorType, inputPoints1, inputPoints2, tensorPoints);
1820 }
1821 }
1822 else
1823 {
1824 // not HVOL or HGRAD; subclass must handle
1825 this->getValues(outputValues, operatorType, inputPoints1, inputPoints2, tensorPoints);
1826 }
1827 }
1828
1854 virtual void getValues(OutputViewType outputValues, const EOperator operatorType,
1855 const PointViewType inputPoints1, const PointViewType inputPoints2,
1856 bool tensorPoints) const
1857 {
1858 INTREPID2_TEST_FOR_EXCEPTION(true, std::invalid_argument, "one-operator, two-inputPoints getValues should be overridden by TensorBasis subclasses");
1859 }
1860
1884 void getValues( OutputViewType outputValues,
1885 const PointViewType inputPoints1, const EOperator operatorType1,
1886 const PointViewType inputPoints2, const EOperator operatorType2,
1887 bool tensorPoints, double weight=1.0) const
1888 {
1889 int basisCardinality1 = basis1_->getCardinality();
1890 int basisCardinality2 = basis2_->getCardinality();
1891
1892 int totalPointCount = tensorPoints ? inputPoints1.extent_int(0) * inputPoints2.extent_int(0) : inputPoints1.extent_int(0);
1893
1894 int pointCount1, pointCount2;
1895 if (tensorPoints)
1896 {
1897 pointCount1 = inputPoints1.extent_int(0);
1898 pointCount2 = inputPoints2.extent_int(0);
1899 }
1900 else
1901 {
1902 pointCount1 = totalPointCount;
1903 pointCount2 = totalPointCount;
1904 }
1905
1906 const ordinal_type spaceDim1 = inputPoints1.extent_int(1);
1907 const ordinal_type spaceDim2 = inputPoints2.extent_int(1);
1908
1909 INTREPID2_TEST_FOR_EXCEPTION(!tensorPoints && (totalPointCount != inputPoints2.extent_int(0)),
1910 std::invalid_argument, "If tensorPoints is false, the point counts must match!");
1911
1912 const ordinal_type opRank1 = getOperatorRank(basis1_->getFunctionSpace(), operatorType1, spaceDim1);
1913 const ordinal_type opRank2 = getOperatorRank(basis2_->getFunctionSpace(), operatorType2, spaceDim2);
1914
1915 const ordinal_type outputRank1 = opRank1 + getFieldRank(basis1_->getFunctionSpace());
1916 const ordinal_type outputRank2 = opRank2 + getFieldRank(basis2_->getFunctionSpace());
1917
1918 OutputViewType outputValues1, outputValues2;
1919 if (outputRank1 == 0)
1920 {
1921 outputValues1 = Impl::createMatchingDynRankView(outputValues,"output values - basis 1",basisCardinality1,pointCount1);
1922 }
1923 else if (outputRank1 == 1)
1924 {
1925 outputValues1 = Impl::createMatchingDynRankView(outputValues,"output values - basis 1",basisCardinality1,pointCount1,spaceDim1);
1926 }
1927 else
1928 {
1929 INTREPID2_TEST_FOR_EXCEPTION(true, std::invalid_argument, "Unsupported opRank1");
1930 }
1931
1932 if (outputRank2 == 0)
1933 {
1934 outputValues2 = Impl::createMatchingDynRankView(outputValues,"output values - basis 2",basisCardinality2,pointCount2);
1935 }
1936 else if (outputRank2 == 1)
1937 {
1938 outputValues2 = Impl::createMatchingDynRankView(outputValues,"output values - basis 2",basisCardinality2,pointCount2,spaceDim2);
1939 }
1940 else
1941 {
1942 INTREPID2_TEST_FOR_EXCEPTION(true, std::invalid_argument, "Unsupported opRank2");
1943 }
1944
1945 basis1_->getValues(outputValues1,inputPoints1,operatorType1);
1946 basis2_->getValues(outputValues2,inputPoints2,operatorType2);
1947
1948 const int outputVectorSize = getVectorSizeForHierarchicalParallelism<OutputValueType>();
1949 const int pointVectorSize = getVectorSizeForHierarchicalParallelism<PointValueType>();
1950 const int vectorSize = std::max(outputVectorSize,pointVectorSize);
1951
1952 auto policy = Kokkos::TeamPolicy<ExecutionSpace>(basisCardinality1,Kokkos::AUTO(),vectorSize);
1953
1955
1956 FunctorType functor(outputValues, outputValues1, outputValues2, tensorPoints, weight);
1957 Kokkos::parallel_for("TensorViewFunctor", policy , functor);
1958 }
1959
1965 getHostBasis() const override {
1966 TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument, "TensorBasis subclasses must override getHostBasis");
1967 }
1968 }; // Basis_TensorBasis
1969
1977 template<class ExecutionSpace, class OutputScalar, class OutputFieldType>
1978 struct TensorBasis3_Functor
1979 {
1980 using ScratchSpace = typename ExecutionSpace::scratch_memory_space;
1981 using OutputScratchView = Kokkos::View<OutputScalar*,ScratchSpace,Kokkos::MemoryTraits<Kokkos::Unmanaged>>;
1982
1983 using TeamPolicy = Kokkos::TeamPolicy<ExecutionSpace>;
1984 using TeamMember = typename TeamPolicy::member_type;
1985
1986 OutputFieldType output_; // F,P
1987 OutputFieldType input1_; // F1,P[,D] or F1,P1[,D]
1988 OutputFieldType input2_; // F2,P[,D] or F2,P2[,D]
1989 OutputFieldType input3_; // F2,P[,D] or F2,P2[,D]
1990
1991 int numFields_, numPoints_;
1992 int numFields1_, numPoints1_;
1993 int numFields2_, numPoints2_;
1994 int numFields3_, numPoints3_;
1995
1996 bool tensorPoints_; // if true, input1, input2, input3 refer to values at decomposed points, and P = P1 * P2 * P3. If false, then the three inputs refer to points in the full-dimensional space, and their point lengths are the same as that of the final output.
1997
1998 double weight_;
1999
2000 TensorBasis3_Functor(OutputFieldType output, OutputFieldType inputValues1, OutputFieldType inputValues2, OutputFieldType inputValues3,
2001 bool tensorPoints, double weight)
2002 : output_(output), input1_(inputValues1), input2_(inputValues2), input3_(inputValues3), tensorPoints_(tensorPoints), weight_(weight)
2003 {
2004 numFields_ = output.extent_int(0);
2005 numPoints_ = output.extent_int(1);
2006
2007 numFields1_ = inputValues1.extent_int(0);
2008 numPoints1_ = inputValues1.extent_int(1);
2009
2010 numFields2_ = inputValues2.extent_int(0);
2011 numPoints2_ = inputValues2.extent_int(1);
2012
2013 numFields3_ = inputValues3.extent_int(0);
2014 numPoints3_ = inputValues3.extent_int(1);
2015 /*
2016 We don't yet support tensor-valued bases here (only vector and scalar). The main design question is how the layouts
2017 of the input containers relates to the layout of the output container. The work we've done in TensorViewIterator basically
2018 shows the choices that can be made. It does appear that in most cases (at least (most of?) those supported by TensorViewIterator),
2019 we can infer from the dimensions of input/output containers what choice should be made in each dimension.
2020 */
2021 INTREPID2_TEST_FOR_EXCEPTION(inputValues1.rank() > 3, std::invalid_argument, "ranks greater than 3 not yet supported");
2022 INTREPID2_TEST_FOR_EXCEPTION(inputValues2.rank() > 3, std::invalid_argument, "ranks greater than 3 not yet supported");
2023 INTREPID2_TEST_FOR_EXCEPTION(inputValues3.rank() > 3, std::invalid_argument, "ranks greater than 3 not yet supported");
2024 INTREPID2_TEST_FOR_EXCEPTION((inputValues1.rank() == 3) && (inputValues2.rank() == 3), std::invalid_argument, "two vector-valued input ranks not yet supported");
2025 INTREPID2_TEST_FOR_EXCEPTION((inputValues1.rank() == 3) && (inputValues3.rank() == 3), std::invalid_argument, "two vector-valued input ranks not yet supported");
2026 INTREPID2_TEST_FOR_EXCEPTION((inputValues2.rank() == 3) && (inputValues3.rank() == 3), std::invalid_argument, "two vector-valued input ranks not yet supported");
2027
2028 if (!tensorPoints_)
2029 {
2030 // then the point counts should all match
2031 INTREPID2_TEST_FOR_EXCEPTION(numPoints_ != numPoints1_, std::invalid_argument, "incompatible point counts");
2032 INTREPID2_TEST_FOR_EXCEPTION(numPoints_ != numPoints2_, std::invalid_argument, "incompatible point counts");
2033 INTREPID2_TEST_FOR_EXCEPTION(numPoints_ != numPoints3_, std::invalid_argument, "incompatible point counts");
2034 }
2035 else
2036 {
2037 INTREPID2_TEST_FOR_EXCEPTION(numPoints_ != numPoints1_ * numPoints2_ * numPoints3_, std::invalid_argument, "incompatible point counts");
2038 }
2039
2040 INTREPID2_TEST_FOR_EXCEPTION(numFields_ != numFields1_ * numFields2_ * numFields3_, std::invalid_argument, "incompatible field sizes");
2041 }
2042
2043 KOKKOS_INLINE_FUNCTION
2044 void operator()( const TeamMember & teamMember ) const
2045 {
2046 auto fieldOrdinal1 = teamMember.league_rank();
2047
2048 if (!tensorPoints_)
2049 {
2050 if ((input1_.rank() == 2) && (input2_.rank() == 2) && (input3_.rank() == 2))
2051 {
2052 Kokkos::parallel_for(Kokkos::TeamThreadRange(teamMember,0,numFields2_), [&] (const int& fieldOrdinal2) {
2053 for (int fieldOrdinal3=0; fieldOrdinal3 < numFields3_; fieldOrdinal3++)
2054 {
2055 int fieldOrdinal = (fieldOrdinal3 * numFields2_ + fieldOrdinal2) * numFields1_ + fieldOrdinal1;
2056 for (int pointOrdinal=0; pointOrdinal<numPoints_; pointOrdinal++)
2057 {
2058 output_(fieldOrdinal,pointOrdinal) = weight_ * input1_(fieldOrdinal1,pointOrdinal) * input2_(fieldOrdinal2,pointOrdinal) * input3_(fieldOrdinal3,pointOrdinal);
2059 }
2060 }
2061 });
2062 }
2063 else if (input1_.rank() == 3)
2064 {
2065 int spaceDim = input1_.extent_int(2);
2066 Kokkos::parallel_for(Kokkos::TeamThreadRange(teamMember,0,numFields2_), [&] (const int& fieldOrdinal2) {
2067 for (int fieldOrdinal3=0; fieldOrdinal3 < numFields3_; fieldOrdinal3++)
2068 {
2069 int fieldOrdinal = (fieldOrdinal3 * numFields2_ + fieldOrdinal2) * numFields1_ + fieldOrdinal1;
2070 for (int pointOrdinal=0; pointOrdinal<numPoints_; pointOrdinal++)
2071 {
2072 for (int d=0; d<spaceDim; d++)
2073 {
2074 output_.access(fieldOrdinal,pointOrdinal,d) = weight_ * input1_(fieldOrdinal1,pointOrdinal,d) * input2_(fieldOrdinal2,pointOrdinal) * input3_(fieldOrdinal3,pointOrdinal);
2075 }
2076 }
2077 }
2078 });
2079 }
2080 else if (input2_.rank() == 3)
2081 {
2082 int spaceDim = input2_.extent_int(2);
2083 Kokkos::parallel_for(Kokkos::TeamThreadRange(teamMember,0,numFields2_), [&] (const int& fieldOrdinal2) {
2084 for (int fieldOrdinal3=0; fieldOrdinal3 < numFields3_; fieldOrdinal3++)
2085 {
2086 int fieldOrdinal = (fieldOrdinal3 * numFields2_ + fieldOrdinal2) * numFields1_ + fieldOrdinal1;
2087 for (int pointOrdinal=0; pointOrdinal<numPoints_; pointOrdinal++)
2088 {
2089 for (int d=0; d<spaceDim; d++)
2090 {
2091 output_.access(fieldOrdinal,pointOrdinal,d) = weight_ * input1_(fieldOrdinal1,pointOrdinal) * input2_(fieldOrdinal2,pointOrdinal,d) * input3_(fieldOrdinal3,pointOrdinal);
2092 }
2093 }
2094 }
2095 });
2096 }
2097 else if (input3_.rank() == 3)
2098 {
2099 int spaceDim = input3_.extent_int(2);
2100 Kokkos::parallel_for(Kokkos::TeamThreadRange(teamMember,0,numFields2_), [&] (const int& fieldOrdinal2) {
2101 for (int fieldOrdinal3=0; fieldOrdinal3 < numFields3_; fieldOrdinal3++)
2102 {
2103 int fieldOrdinal = (fieldOrdinal3 * numFields2_ + fieldOrdinal2) * numFields1_ + fieldOrdinal1;
2104 for (int pointOrdinal=0; pointOrdinal<numPoints_; pointOrdinal++)
2105 {
2106 for (int d=0; d<spaceDim; d++)
2107 {
2108 output_.access(fieldOrdinal,pointOrdinal,d) = weight_ * input1_(fieldOrdinal1,pointOrdinal) * input2_(fieldOrdinal2,pointOrdinal) * input3_(fieldOrdinal3,pointOrdinal,d);
2109 }
2110 }
2111 }
2112 });
2113 }
2114 else
2115 {
2116 // unsupported rank combination -- enforced in constructor
2117 }
2118 }
2119 else
2120 {
2121 if ((input1_.rank() == 2) && (input2_.rank() == 2) && (input3_.rank() == 2) )
2122 {
2123 Kokkos::parallel_for(Kokkos::TeamThreadRange(teamMember,0,numFields2_), [&] (const int& fieldOrdinal2) {
2124 for (int fieldOrdinal3=0; fieldOrdinal3 < numFields3_; fieldOrdinal3++)
2125 {
2126 int fieldOrdinal = (fieldOrdinal3 * numFields2_ + fieldOrdinal2) * numFields1_ + fieldOrdinal1;
2127 for (int pointOrdinal3=0; pointOrdinal3<numPoints3_; pointOrdinal3++)
2128 {
2129 for (int pointOrdinal2=0; pointOrdinal2<numPoints2_; pointOrdinal2++)
2130 {
2131 for (int pointOrdinal1=0; pointOrdinal1<numPoints1_; pointOrdinal1++)
2132 {
2133 int pointOrdinal = (pointOrdinal3 * numPoints2_ + pointOrdinal2) * numPoints1_ + pointOrdinal1;
2134 output_(fieldOrdinal,pointOrdinal) = weight_ * input1_(fieldOrdinal1,pointOrdinal1) * input2_(fieldOrdinal2,pointOrdinal2) * input3_(fieldOrdinal3,pointOrdinal3);
2135 }
2136 }
2137 }
2138 }
2139 });
2140 }
2141 else if (input1_.rank() == 3) // based on constructor requirements, this means the others are rank 2
2142 {
2143 int spaceDim = input1_.extent_int(2);
2144 Kokkos::parallel_for(Kokkos::TeamThreadRange(teamMember,0,numFields2_), [&] (const int& fieldOrdinal2) {
2145 for (int fieldOrdinal3=0; fieldOrdinal3 < numFields3_; fieldOrdinal3++)
2146 {
2147 int fieldOrdinal = (fieldOrdinal3 * numFields2_ + fieldOrdinal2) * numFields1_ + fieldOrdinal1;
2148 for (int pointOrdinal3=0; pointOrdinal3<numPoints3_; pointOrdinal3++)
2149 {
2150 for (int pointOrdinal2=0; pointOrdinal2<numPoints2_; pointOrdinal2++)
2151 {
2152 for (int pointOrdinal1=0; pointOrdinal1<numPoints1_; pointOrdinal1++)
2153 {
2154 int pointOrdinal = (pointOrdinal3 * numPoints2_ + pointOrdinal2) * numPoints1_ + pointOrdinal1;
2155 for (int d=0; d<spaceDim; d++)
2156 {
2157 output_(fieldOrdinal,pointOrdinal,d) = weight_ * input1_(fieldOrdinal1,pointOrdinal1,d) * input2_(fieldOrdinal2,pointOrdinal2) * input3_(fieldOrdinal3,pointOrdinal3);
2158 }
2159 }
2160 }
2161 }
2162 }
2163 });
2164 }
2165 else if (input2_.rank() == 3) // based on constructor requirements, this means the others are rank 2
2166 {
2167 int spaceDim = input2_.extent_int(2);
2168 Kokkos::parallel_for(Kokkos::TeamThreadRange(teamMember,0,numFields2_), [&] (const int& fieldOrdinal2) {
2169 for (int fieldOrdinal3=0; fieldOrdinal3 < numFields3_; fieldOrdinal3++)
2170 {
2171 int fieldOrdinal = (fieldOrdinal3 * numFields2_ + fieldOrdinal2) * numFields1_ + fieldOrdinal1;
2172 for (int pointOrdinal3=0; pointOrdinal3<numPoints3_; pointOrdinal3++)
2173 {
2174 for (int pointOrdinal2=0; pointOrdinal2<numPoints2_; pointOrdinal2++)
2175 {
2176 for (int pointOrdinal1=0; pointOrdinal1<numPoints1_; pointOrdinal1++)
2177 {
2178 int pointOrdinal = (pointOrdinal3 * numPoints2_ + pointOrdinal2) * numPoints1_ + pointOrdinal1;
2179 for (int d=0; d<spaceDim; d++)
2180 {
2181 output_(fieldOrdinal,pointOrdinal,d) = weight_ * input1_(fieldOrdinal1,pointOrdinal1) * input2_(fieldOrdinal2,pointOrdinal2,d) * input3_(fieldOrdinal3,pointOrdinal3);
2182 }
2183 }
2184 }
2185 }
2186 }
2187 });
2188 }
2189 else if (input3_.rank() == 3) // based on constructor requirements, this means the others are rank 2
2190 {
2191 int spaceDim = input3_.extent_int(2);
2192 Kokkos::parallel_for(Kokkos::TeamThreadRange(teamMember,0,numFields2_), [&] (const int& fieldOrdinal2) {
2193 for (int fieldOrdinal3=0; fieldOrdinal3 < numFields3_; fieldOrdinal3++)
2194 {
2195 int fieldOrdinal = (fieldOrdinal3 * numFields2_ + fieldOrdinal2) * numFields1_ + fieldOrdinal1;
2196 for (int pointOrdinal3=0; pointOrdinal3<numPoints3_; pointOrdinal3++)
2197 {
2198 for (int pointOrdinal2=0; pointOrdinal2<numPoints2_; pointOrdinal2++)
2199 {
2200 for (int pointOrdinal1=0; pointOrdinal1<numPoints1_; pointOrdinal1++)
2201 {
2202 int pointOrdinal = (pointOrdinal3 * numPoints2_ + pointOrdinal2) * numPoints1_ + pointOrdinal1;
2203 for (int d=0; d<spaceDim; d++)
2204 {
2205 output_(fieldOrdinal,pointOrdinal,d) = weight_ * input1_(fieldOrdinal1,pointOrdinal1) * input2_(fieldOrdinal2,pointOrdinal2) * input3_(fieldOrdinal3,pointOrdinal3,d);
2206 }
2207 }
2208 }
2209 }
2210 }
2211 });
2212 }
2213 else
2214 {
2215 // unsupported rank combination -- enforced in constructor
2216 }
2217 }
2218 }
2219 }; // TensorBasis3_Functor
2220
2221
2222 template<typename BasisBaseClass = void>
2223 class Basis_TensorBasis3
2224 : public Basis_TensorBasis<BasisBaseClass>
2225 {
2226 using BasisBase = BasisBaseClass;
2227 using TensorBasis = Basis_TensorBasis<BasisBase>;
2228 public:
2229 using typename BasisBase::OutputViewType;
2230 using typename BasisBase::PointViewType;
2231 using typename BasisBase::ScalarViewType;
2232
2233 using typename BasisBase::OutputValueType;
2234 using typename BasisBase::PointValueType;
2235
2236 using typename BasisBase::ExecutionSpace;
2237
2238 using BasisPtr = Teuchos::RCP<BasisBase>;
2239 protected:
2240 BasisPtr basis1_;
2241 BasisPtr basis2_;
2242 BasisPtr basis3_;
2243 public:
2244 Basis_TensorBasis3(BasisPtr basis1, BasisPtr basis2, BasisPtr basis3, const bool useShardsCellTopologyAndTags = false)
2245 :
2246 TensorBasis(Teuchos::rcp( new TensorBasis(basis1,basis2,FUNCTION_SPACE_MAX,useShardsCellTopologyAndTags)),
2247 basis3,
2248 FUNCTION_SPACE_MAX,useShardsCellTopologyAndTags),
2249 basis1_(basis1),
2250 basis2_(basis2),
2251 basis3_(basis3)
2252 {}
2253
2260 virtual OperatorTensorDecomposition getOperatorDecomposition(const EOperator operatorType) const override
2261 {
2262 OperatorTensorDecomposition opSimpleDecomposition = this->getSimpleOperatorDecomposition(operatorType);
2263 std::vector<BasisPtr> componentBases {basis1_, basis2_, basis3_};
2264 return opSimpleDecomposition.expandedDecomposition(componentBases);
2265 }
2266
2268
2293 virtual void getValues(OutputViewType outputValues, const EOperator operatorType,
2294 const PointViewType inputPoints12, const PointViewType inputPoints3,
2295 bool tensorPoints) const override
2296 {
2297 // TODO: rework this to use superclass's getComponentPoints.
2298
2299 int spaceDim1 = basis1_->getDomainDimension();
2300 int spaceDim2 = basis2_->getDomainDimension();
2301
2302 int totalSpaceDim12 = inputPoints12.extent_int(1);
2303
2304 TEUCHOS_ASSERT(spaceDim1 + spaceDim2 == totalSpaceDim12);
2305
2306 if (!tensorPoints)
2307 {
2308 auto inputPoints1 = Kokkos::subview(inputPoints12,Kokkos::ALL(),std::make_pair(0,spaceDim1));
2309 auto inputPoints2 = Kokkos::subview(inputPoints12,Kokkos::ALL(),std::make_pair(spaceDim1,totalSpaceDim12));
2310
2311 this->getValues(outputValues, operatorType, inputPoints1, inputPoints2, inputPoints3, tensorPoints);
2312 }
2313 else
2314 {
2315 // superclass doesn't (yet) have a clever way to detect tensor points in a single container
2316 // we'd need something along those lines here to detect them in inputPoints12.
2317 // if we do add such a mechanism to superclass, it should be simple enough to call that from here
2318 INTREPID2_TEST_FOR_EXCEPTION(true, std::invalid_argument, "This method does not yet handle tensorPoints=true");
2319 }
2320 }
2321
2349 virtual void getValues(OutputViewType outputValues, const EOperator operatorType,
2350 const PointViewType inputPoints1, const PointViewType inputPoints2, const PointViewType inputPoints3,
2351 bool tensorPoints) const = 0;
2352
2380 void getValues( OutputViewType outputValues,
2381 const PointViewType inputPoints1, const EOperator operatorType1,
2382 const PointViewType inputPoints2, const EOperator operatorType2,
2383 const PointViewType inputPoints3, const EOperator operatorType3,
2384 bool tensorPoints, double weight=1.0) const
2385 {
2386 int basisCardinality1 = basis1_->getCardinality();
2387 int basisCardinality2 = basis2_->getCardinality();
2388 int basisCardinality3 = basis3_->getCardinality();
2389
2390 int spaceDim1 = inputPoints1.extent_int(1);
2391 int spaceDim2 = inputPoints2.extent_int(1);
2392 int spaceDim3 = inputPoints3.extent_int(1);
2393
2394 int totalPointCount;
2395 int pointCount1, pointCount2, pointCount3;
2396 if (tensorPoints)
2397 {
2398 pointCount1 = inputPoints1.extent_int(0);
2399 pointCount2 = inputPoints2.extent_int(0);
2400 pointCount3 = inputPoints3.extent_int(0);
2401 totalPointCount = pointCount1 * pointCount2 * pointCount3;
2402 }
2403 else
2404 {
2405 totalPointCount = inputPoints1.extent_int(0);
2406 pointCount1 = totalPointCount;
2407 pointCount2 = totalPointCount;
2408 pointCount3 = totalPointCount;
2409
2410 INTREPID2_TEST_FOR_EXCEPTION((totalPointCount != inputPoints2.extent_int(0)) || (totalPointCount != inputPoints3.extent_int(0)),
2411 std::invalid_argument, "If tensorPoints is false, the point counts must match!");
2412 }
2413
2414 // structure of this implementation:
2415 /*
2416 - allocate output1, output2, output3 containers
2417 - either:
2418 1. split off the tensor functor call into its own method in TensorBasis, and
2419 - call it once with output1, output2, placing these in another newly allocated output12, then
2420 - call it again with output12, output3
2421 OR
2422 2. create a 3-argument tensor functor and call it with output1,output2,output3
2423
2424 At the moment, the 3-argument functor seems like a better approach. It's likely more code, but somewhat
2425 more efficient and easier to understand/debug. And the code is fairly straightforward to produce.
2426 */
2427
2428 // copied from the 2-argument TensorBasis implementation:
2429
2430 OutputViewType outputValues1, outputValues2, outputValues3;
2431
2432 //Note: the gradient of HGRAD basis on a line has an output vector of rank 3, the last dimension being of size 1.
2433 // in particular this holds even when computing the divergence of an HDIV basis, which is scalar and has rank 2.
2434 if ((spaceDim1 == 1) && (operatorType1 == OPERATOR_VALUE))
2435 {
2436 // use a rank 2 container for basis1
2437 outputValues1 = Impl::createMatchingDynRankView(outputValues,"output values - basis 1",basisCardinality1,pointCount1);
2438 }
2439 else
2440 {
2441 outputValues1 = Impl::createMatchingDynRankView(outputValues,"output values - basis 1",basisCardinality1,pointCount1,spaceDim1);
2442 }
2443 if ((spaceDim2 == 1) && (operatorType2 == OPERATOR_VALUE))
2444 {
2445 // use a rank 2 container for basis2
2446 outputValues2 = Impl::createMatchingDynRankView(outputValues,"output values - basis 2",basisCardinality2,pointCount2);
2447 }
2448 else
2449 {
2450 outputValues2 = Impl::createMatchingDynRankView(outputValues,"output values - basis 2",basisCardinality2,pointCount2,spaceDim2);
2451 }
2452 if ((spaceDim3 == 1) && (operatorType3 == OPERATOR_VALUE))
2453 {
2454 // use a rank 2 container for basis2
2455 outputValues3 = Impl::createMatchingDynRankView(outputValues,"output values - basis 3",basisCardinality3,pointCount3);
2456 }
2457 else
2458 {
2459 outputValues3 = Impl::createMatchingDynRankView(outputValues,"output values - basis 3",basisCardinality3,pointCount3,spaceDim3);
2460 }
2461
2462 basis1_->getValues(outputValues1,inputPoints1,operatorType1);
2463 basis2_->getValues(outputValues2,inputPoints2,operatorType2);
2464 basis3_->getValues(outputValues3,inputPoints3,operatorType3);
2465
2466 const int outputVectorSize = getVectorSizeForHierarchicalParallelism<OutputValueType>();
2467 const int pointVectorSize = getVectorSizeForHierarchicalParallelism<PointValueType>();
2468 const int vectorSize = std::max(outputVectorSize,pointVectorSize);
2469
2470 auto policy = Kokkos::TeamPolicy<ExecutionSpace>(basisCardinality1,Kokkos::AUTO(),vectorSize);
2471
2473 FunctorType functor(outputValues, outputValues1, outputValues2, outputValues3, tensorPoints, weight);
2474 Kokkos::parallel_for("TensorBasis3_Functor", policy , functor);
2475 }
2476
2484 virtual void getDofCoeffs( typename BasisBase::ScalarViewType dofCoeffs ) const override
2485 {
2486 using ValueType = typename BasisBase::ScalarViewType::value_type;
2487 using ResultLayout = typename DeduceLayout< typename BasisBase::ScalarViewType >::result_layout;
2488 using ViewType = Kokkos::DynRankView<ValueType, ResultLayout, typename TensorBasis::DeviceType >;
2489
2490 const ordinal_type basisCardinality1 = basis1_->getCardinality();
2491 const ordinal_type basisCardinality2 = basis2_->getCardinality();
2492 const ordinal_type basisCardinality3 = basis3_->getCardinality();
2493
2494 auto dofCoeffs1 = ViewType("dofCoeffs1",basisCardinality1);
2495 auto dofCoeffs2 = ViewType("dofCoeffs2",basisCardinality2);
2496 auto dofCoeffs3 = ViewType("dofCoeffs3",basisCardinality3);
2497
2498 basis1_->getDofCoeffs(dofCoeffs1);
2499 basis2_->getDofCoeffs(dofCoeffs2);
2500 basis3_->getDofCoeffs(dofCoeffs3);
2501
2502 Kokkos::RangePolicy<ExecutionSpace> policy(0, basisCardinality3);
2503 Kokkos::parallel_for(policy, KOKKOS_LAMBDA (const int fieldOrdinal3)
2504 {
2505 for (int fieldOrdinal2=0; fieldOrdinal2<basisCardinality2; fieldOrdinal2++)
2506 for (int fieldOrdinal1=0; fieldOrdinal1<basisCardinality1; fieldOrdinal1++)
2507 {
2508 const ordinal_type fieldOrdinal = fieldOrdinal1 + fieldOrdinal2 * basisCardinality1 + fieldOrdinal3 * (basisCardinality1*basisCardinality2);
2509 dofCoeffs(fieldOrdinal) = dofCoeffs1(fieldOrdinal1);
2510 dofCoeffs(fieldOrdinal) *= dofCoeffs2(fieldOrdinal2) * dofCoeffs3(fieldOrdinal3);
2511 }
2512 });
2513 }
2514
2520 getHostBasis() const override {
2521 TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument, "TensorBasis3 subclasses must override getHostBasis");
2522 }
2523 };
2524} // end namespace Intrepid2
2525
2526#endif /* Intrepid2_TensorBasis_h */
Header file for the abstract base class Intrepid2::Basis.
BasisPtr< typename Kokkos::HostSpace::device_type, OutputType, PointType > HostBasisPtr
Pointer to a Basis whose device type is on the host (Kokkos::HostSpace::device_type),...
KOKKOS_INLINE_FUNCTION ordinal_type getOperatorRank(const EFunctionSpace spaceType, const EOperator operatorType, const ordinal_type spaceDim)
Returns rank of an operator.
KOKKOS_INLINE_FUNCTION ordinal_type getFieldRank(const EFunctionSpace spaceType)
Returns the rank of fields in a function space of the specified type.
KOKKOS_INLINE_FUNCTION ordinal_type getOperatorOrder(const EOperator operatorType)
Returns order of an operator.
KOKKOS_INLINE_FUNCTION ordinal_type getDkCardinality(const EOperator operatorType, const ordinal_type spaceDim)
Returns multiplicities of dx, dy, and dz based on the enumeration of the partial derivative,...
KOKKOS_INLINE_FUNCTION ordinal_type getDkEnumeration(const ordinal_type xMult, const ordinal_type yMult=-1, const ordinal_type zMult=-1)
Returns the ordinal of a partial derivative of order k based on the multiplicities of the partials dx...
Implements arbitrary-dimensional extrusion of a base shards::CellTopology.
@ GENERAL
arbitrary variation
Implementation of an assert that can safely be called from device code.
Class that defines mappings from component cell topologies to their tensor product topologies.
Implementation of support for traversing component views alongside a view that represents a combinati...
Header function for Intrepid2::Util class and other utility functions.
DeduceDynRankView< InViewType >::type createMatchingDynRankView(const InViewType &view, const CtorProp &prop, const Dims... dims)
Creates and returns a view that matches the value_type of the provided view The output view type is d...
constexpr int getVectorSizeForHierarchicalParallelism()
Returns a vector size to be used for the provided Scalar type in the context of hierarchically-parall...
#define INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(test, x, msg)
virtual HostBasisPtr< OutputValueType, PointValueType > getHostBasis() const override
Creates and returns a Basis object whose DeviceType template argument is Kokkos::HostSpace::device_ty...
virtual void getValues(OutputViewType outputValues, const EOperator operatorType, const PointViewType inputPoints12, const PointViewType inputPoints3, bool tensorPoints) const override
Evaluation of a tensor FEM basis on a reference cell.
virtual void getDofCoeffs(typename BasisBase::ScalarViewType dofCoeffs) const override
Fills in coefficients of degrees of freedom on the reference cell.
virtual void getValues(OutputViewType outputValues, const EOperator operatorType, const PointViewType inputPoints1, const PointViewType inputPoints2, const PointViewType inputPoints3, bool tensorPoints) const =0
Evaluation of a tensor FEM basis on a reference cell; subclasses should override this.
void getValues(OutputViewType outputValues, const PointViewType inputPoints1, const EOperator operatorType1, const PointViewType inputPoints2, const EOperator operatorType2, const PointViewType inputPoints3, const EOperator operatorType3, bool tensorPoints, double weight=1.0) const
Evaluation of a tensor FEM basis on a reference cell; subclasses should override this.
virtual OperatorTensorDecomposition getOperatorDecomposition(const EOperator operatorType) const override
Returns a full decomposition of the specified operator. (Full meaning that all TensorBasis components...
Basis defined as the tensor product of two component bases.
virtual ordinal_type getDofOrdinal(const ordinal_type subcDim, const ordinal_type subcOrd, const ordinal_type subcDofOrd) const override
DoF tag to ordinal lookup, computed from the component bases (without building dense tag tables).
virtual OperatorTensorDecomposition getSimpleOperatorDecomposition(const EOperator &operatorType) const
Returns a simple decomposition of the specified operator: what operator(s) should be applied to basis...
virtual OperatorTensorDecomposition getOperatorDecomposition(const EOperator operatorType) const
Returns a full decomposition of the specified operator. (Full meaning that all TensorBasis components...
virtual void getDofCoords(typename BasisBase::ScalarViewType dofCoords) const override
Fills in spatial locations (coordinates) of degrees of freedom (nodes) on the reference cell.
std::shared_ptr< std::recursive_mutex > lazyInitializationMutex_
virtual void getDofCoeffs(typename BasisBase::ScalarViewType dofCoeffs) const override
Fills in coefficients of degrees of freedom on the reference cell.
virtual void requireTags() const override
materializes the dense tag tables on first request (thread-safe)
virtual BasisValues< OutputValueType, DeviceType > allocateBasisValues(TensorPoints< PointValueType, DeviceType > points, const EOperator operatorType=OPERATOR_VALUE) const override
Allocate BasisValues container suitable for passing to the getValues() variant that takes a TensorPoi...
void requireCompositeSubcellMap() const
builds compositeSubcellToComponents_ (once; thread-safe)
virtual ordinal_type getDofCount(const ordinal_type subcDim, const ordinal_type subcOrd) const override
DoF count for the specified subcell, computed from the component bases (without building dense tag ta...
std::map< std::pair< ordinal_type, ordinal_type >, std::array< ordinal_type, 4 > > compositeSubcellToComponents_
virtual void getValues(OutputViewType outputValues, const EOperator operatorType, const PointViewType inputPoints1, const PointViewType inputPoints2, bool tensorPoints) const
Evaluation of a tensor FEM basis on a reference cell; subclasses should override this.
virtual const char * getName() const override
Returns basis name.
virtual HostBasisPtr< OutputValueType, PointValueType > getHostBasis() const override
Creates and returns a Basis object whose DeviceType template argument is Kokkos::HostSpace::device_ty...
void getValues(OutputViewType outputValues, const PointViewType inputPoints1, const EOperator operatorType1, const PointViewType inputPoints2, const EOperator operatorType2, bool tensorPoints, double weight=1.0) const
Evaluation of a tensor FEM basis on a reference cell.
ordinal_type getTensorDkEnumeration(ordinal_type dkEnum1, ordinal_type operatorOrder1, ordinal_type dkEnum2, ordinal_type operatorOrder2) const
Given "Dk" enumeration indices for the component bases, returns a Dk enumeration index for the compos...
Basis_TensorBasis(BasisPtr basis1, BasisPtr basis2, EFunctionSpace functionSpace=FUNCTION_SPACE_MAX, const bool useShardsCellTopologyAndTags=false)
Constructor.
void getComponentPoints(const PointViewType inputPoints, const bool attemptTensorDecomposition, PointViewType &inputPoints1, PointViewType &inputPoints2, bool &tensorDecompositionSucceeded) const
Method to extract component points from composite points.
void getValues(OutputViewType outputValues, const PointViewType inputPoints, const EOperator operatorType=OPERATOR_VALUE) const override
Evaluation of a FEM basis on a reference cell.
virtual void getValues(BasisValues< OutputValueType, DeviceType > outputValues, const TensorPoints< PointValueType, DeviceType > inputPoints, const EOperator operatorType=OPERATOR_VALUE) const override
Evaluation of a FEM basis on a reference cell, using point and output value containers that allow pre...
An abstract base class that defines interface for concrete basis implementations for Finite Element (...
The data containers in Intrepid2 that support sum factorization and other reduced-data optimizations ...
const VectorDataType & vectorData() const
VectorData accessor.
KOKKOS_INLINE_FUNCTION int numFamilies() const
For valid vectorData, returns the number of families in vectorData; otherwise, returns number of Tens...
TensorDataType & tensorData()
TensorData accessor for single-family scalar data.
static CellTopoPtr cellTopology(const shards::CellTopology &shardsCellTopo, ordinal_type tensorialDegree=0)
static accessor that returns a CellTopoPtr; these are lazily constructed and cached.
static ordinal_type getSubcellOrdinalMap(CellTopoPtr cellTopo, ordinal_type subcdim, ordinal_type subcord, ordinal_type subsubcdim, ordinal_type subsubcord)
Maps the from a subcell within a subcell of the present CellTopology to the subcell in the present Ce...
Wrapper around a Kokkos::View that allows data that is constant or repeating in various logical dimen...
KOKKOS_INLINE_FUNCTION enable_if_t< rank==1, const Kokkos::View< typename RankExpander< DataScalar, rank >::value_type, DeviceType > & > getUnderlyingView() const
Returns the underlying view. Throws an exception if the underlying view is not rank 1.
View-like interface to tensor data; tensor components are stored separately and multiplied together a...
KOKKOS_INLINE_FUNCTION const Data< Scalar, DeviceType > & getTensorComponent(const ordinal_type &r) const
Returns the requested tensor component.
KOKKOS_INLINE_FUNCTION ordinal_type numTensorComponents() const
Return the number of tensorial components.
View-like interface to tensor points; point components are stored separately; the appropriate coordin...
KOKKOS_INLINE_FUNCTION ordinal_type numTensorComponents() const
Returns the number of tensorial components.
KOKKOS_INLINE_FUNCTION ScalarView< PointScalar, DeviceType > getTensorComponent(const ordinal_type &r) const
Returns the requested tensor component.
KOKKOS_INLINE_FUNCTION std::enable_if< std::is_integral< iType >::value, int >::type extent_int(const iType &r) const
Returns the logical extent in the requested dimension.
ordinal_type componentPointCount(const ordinal_type &tensorComponentOrdinal) const
Returns the number of points in the indicated component.
Functor for computing values for the TensorBasis class.
A helper class that allows iteration over three Kokkos Views simultaneously, according to tensor comb...
KOKKOS_INLINE_FUNCTION ScalarType getView1Entry()
KOKKOS_INLINE_FUNCTION int nextIncrementRank()
KOKKOS_INLINE_FUNCTION void setLocation(const Kokkos::Array< int, 7 > location)
KOKKOS_INLINE_FUNCTION void set(ScalarType value)
KOKKOS_INLINE_FUNCTION ScalarType getView2Entry()
Reference-space field values for a basis, designed to support typical vector-valued bases.
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,...
For a multi-component tensor basis, specifies the operators to be applied to the components to produc...
bool rotateXYNinetyDegrees() const
If true, this flag indicates that a vector component that spans the first two dimensions should be ro...
OperatorTensorDecomposition expandedDecomposition(std::vector< Teuchos::RCP< Basis< DeviceType, OutputValueType, PointValueType > > > &bases)
takes as argument bases that are components in this decomposition, and decomposes them further if the...
Functor for computing values for the TensorBasis3 class.