21 #ifndef Intrepid2_LegendreBasis_HVOL_PYR_h
22 #define Intrepid2_LegendreBasis_HVOL_PYR_h
24 #include <Kokkos_DynRankView.hpp>
26 #include <Intrepid2_config.h>
33 #include "Teuchos_RCP.hpp"
42 template<
class DeviceType,
class OutputScalar,
class PointScalar,
43 class OutputFieldType,
class InputPointsType>
46 using ExecutionSpace =
typename DeviceType::execution_space;
47 using ScratchSpace =
typename ExecutionSpace::scratch_memory_space;
48 using OutputScratchView = Kokkos::View<OutputScalar*,ScratchSpace,Kokkos::MemoryTraits<Kokkos::Unmanaged>>;
49 using OutputScratchView2D = Kokkos::View<OutputScalar**,ScratchSpace,Kokkos::MemoryTraits<Kokkos::Unmanaged>>;
50 using PointScratchView = Kokkos::View<PointScalar*, ScratchSpace,Kokkos::MemoryTraits<Kokkos::Unmanaged>>;
52 using TeamPolicy = Kokkos::TeamPolicy<ExecutionSpace>;
53 using TeamMember =
typename TeamPolicy::member_type;
57 OutputFieldType output_;
58 InputPointsType inputPoints_;
61 int numFields_, numPoints_;
63 size_t fad_size_output_;
65 static const int numVertices = 5;
66 static const int numMixedEdges = 4;
67 static const int numTriEdges = 4;
68 static const int numEdges = 8;
72 const int edge_start_[numEdges] = {0,1,2,3,0,1,2,3};
73 const int edge_end_[numEdges] = {1,2,3,0,4,4,4,4};
76 static const int numQuadFaces = 1;
77 static const int numTriFaces = 4;
80 const int tri_face_vertex_0[numTriFaces] = {0,1,3,0};
81 const int tri_face_vertex_1[numTriFaces] = {1,2,2,3};
82 const int tri_face_vertex_2[numTriFaces] = {4,4,4,4};
86 : opType_(opType), output_(output), inputPoints_(inputPoints),
87 polyOrder_(polyOrder),
88 fad_size_output_(getScalarDimensionForView(output))
90 numFields_ = output.extent_int(0);
91 numPoints_ = output.extent_int(1);
92 const auto & p = polyOrder;
93 const auto p_plus_one_cubed = (p+1) * (p+1) * (p+1);
94 INTREPID2_TEST_FOR_EXCEPTION(numPoints_ != inputPoints.extent_int(0), std::invalid_argument,
"point counts need to match!");
95 INTREPID2_TEST_FOR_EXCEPTION(numFields_ != p_plus_one_cubed, std::invalid_argument,
"output field size does not match basis cardinality");
98 KOKKOS_INLINE_FUNCTION
99 void operator()(
const TeamMember & teamMember )
const
101 auto pointOrdinal = teamMember.league_rank();
102 OutputScratchView scratch1D_1, scratch1D_2, scratch1D_3;
103 OutputScratchView scratch1D_4, scratch1D_5, scratch1D_6;
104 OutputScratchView scratch1D_7, scratch1D_8, scratch1D_9;
105 OutputScratchView2D scratch2D_1, scratch2D_2, scratch2D_3;
106 const int numAlphaValues = (polyOrder_-1 > 1) ? (polyOrder_-1) : 1;
107 if (fad_size_output_ > 0) {
108 scratch1D_1 = OutputScratchView(teamMember.team_shmem(), polyOrder_ + 1, fad_size_output_);
109 scratch1D_2 = OutputScratchView(teamMember.team_shmem(), polyOrder_ + 1, fad_size_output_);
110 scratch1D_3 = OutputScratchView(teamMember.team_shmem(), polyOrder_ + 1, fad_size_output_);
111 scratch1D_4 = OutputScratchView(teamMember.team_shmem(), polyOrder_ + 1, fad_size_output_);
112 scratch1D_5 = OutputScratchView(teamMember.team_shmem(), polyOrder_ + 1, fad_size_output_);
113 scratch1D_6 = OutputScratchView(teamMember.team_shmem(), polyOrder_ + 1, fad_size_output_);
114 scratch1D_7 = OutputScratchView(teamMember.team_shmem(), polyOrder_ + 1, fad_size_output_);
115 scratch1D_8 = OutputScratchView(teamMember.team_shmem(), polyOrder_ + 1, fad_size_output_);
116 scratch1D_9 = OutputScratchView(teamMember.team_shmem(), polyOrder_ + 1, fad_size_output_);
117 scratch2D_1 = OutputScratchView2D(teamMember.team_shmem(), numAlphaValues, polyOrder_ + 1, fad_size_output_);
118 scratch2D_2 = OutputScratchView2D(teamMember.team_shmem(), numAlphaValues, polyOrder_ + 1, fad_size_output_);
119 scratch2D_3 = OutputScratchView2D(teamMember.team_shmem(), numAlphaValues, polyOrder_ + 1, fad_size_output_);
122 scratch1D_1 = OutputScratchView(teamMember.team_shmem(), polyOrder_ + 1);
123 scratch1D_2 = OutputScratchView(teamMember.team_shmem(), polyOrder_ + 1);
124 scratch1D_3 = OutputScratchView(teamMember.team_shmem(), polyOrder_ + 1);
125 scratch1D_4 = OutputScratchView(teamMember.team_shmem(), polyOrder_ + 1);
126 scratch1D_5 = OutputScratchView(teamMember.team_shmem(), polyOrder_ + 1);
127 scratch1D_6 = OutputScratchView(teamMember.team_shmem(), polyOrder_ + 1);
128 scratch1D_7 = OutputScratchView(teamMember.team_shmem(), polyOrder_ + 1);
129 scratch1D_8 = OutputScratchView(teamMember.team_shmem(), polyOrder_ + 1);
130 scratch1D_9 = OutputScratchView(teamMember.team_shmem(), polyOrder_ + 1);
131 scratch2D_1 = OutputScratchView2D(teamMember.team_shmem(), numAlphaValues, polyOrder_ + 1);
132 scratch2D_2 = OutputScratchView2D(teamMember.team_shmem(), numAlphaValues, polyOrder_ + 1);
133 scratch2D_3 = OutputScratchView2D(teamMember.team_shmem(), numAlphaValues, polyOrder_ + 1);
136 const auto & x = inputPoints_(pointOrdinal,0);
137 const auto & y = inputPoints_(pointOrdinal,1);
138 const auto & z = inputPoints_(pointOrdinal,2);
144 Kokkos::Array<PointScalar,3> coords;
145 transformToESEASPyramid<>(coords[0], coords[1], coords[2], x, y, z);
149 Array<PointScalar,5> lambda;
150 Array<Kokkos::Array<PointScalar,3>,5> lambdaGrad;
152 Array<Array<PointScalar,3>,2> mu;
153 Array<Array<Array<PointScalar,3>,3>,2> muGrad;
155 Array<Array<PointScalar,2>,3> nu;
156 Array<Array<Array<PointScalar,3>,2>,3> nuGrad;
158 affinePyramid(lambda, lambdaGrad, mu, muGrad, nu, nuGrad, coords);
166 ordinal_type fieldOrdinalOffset = 0;
167 auto & Pi = scratch1D_1;
168 auto & Pj = scratch1D_2;
169 auto & Pk = scratch1D_3;
171 Polynomials::shiftedScaledLegendreValues(Pi, polyOrder_, mu[1][0], mu[0][0] + mu[1][0]);
173 Polynomials::shiftedScaledLegendreValues(Pj, polyOrder_, mu[1][1], mu[0][1] + mu[1][1]);
175 Polynomials::shiftedScaledLegendreValues(Pk, polyOrder_, mu[1][2], mu[0][2] + mu[1][2]);
177 PointScalar grad_weight =
178 (nuGrad[1][0][1] * nuGrad[1][1][2] - nuGrad[1][0][2] * nuGrad[1][1][1]) * muGrad[1][2][0]
179 + (nuGrad[1][0][2] * nuGrad[1][1][0] - nuGrad[1][0][0] * nuGrad[1][1][2]) * muGrad[1][2][1]
180 + (nuGrad[1][0][0] * nuGrad[1][1][1] - nuGrad[1][0][1] * nuGrad[1][1][0]) * muGrad[1][2][2];
183 for (
int k=0; k<=polyOrder_; k++)
185 for (
int j=0; j<=polyOrder_; j++)
187 for (
int i=0; i<=polyOrder_; i++)
189 output_(fieldOrdinalOffset,pointOrdinal) = Pk(k) * Pi(i) * Pj(j) * grad_weight;
190 fieldOrdinalOffset++;
207 INTREPID2_TEST_FOR_ABORT(
true,
208 ">>> ERROR: (Intrepid2::Hierarchical_HVOL_PYR_Functor) Computing of derivatives is not supported");
211 device_assert(
false);
218 size_t team_shmem_size (
int team_size)
const
225 const int numAlphaValues = std::max(polyOrder_-1, 1);
226 size_t shmem_size = 0;
227 if (fad_size_output_ > 0)
230 shmem_size += 9 * OutputScratchView::shmem_size(polyOrder_ + 1, fad_size_output_);
232 shmem_size += 3 * OutputScratchView2D::shmem_size(numAlphaValues, polyOrder_ + 1, fad_size_output_);
237 shmem_size += 9 * OutputScratchView::shmem_size(polyOrder_ + 1);
239 shmem_size += 3 * OutputScratchView2D::shmem_size(numAlphaValues, polyOrder_ + 1);
257 template<
typename DeviceType,
258 typename OutputScalar = double,
259 typename PointScalar =
double>
261 :
public Basis<DeviceType,OutputScalar,PointScalar>
277 EPointType pointType_;
286 polyOrder_(polyOrder),
287 pointType_(pointType)
289 INTREPID2_TEST_FOR_EXCEPTION(pointType!=POINTTYPE_DEFAULT,std::invalid_argument,
"PointType not supported");
297 const int degreeLength = 1;
301 int fieldOrdinalOffset = 0;
304 const int numVolumes = 1;
305 for (
int volumeOrdinal=0; volumeOrdinal<numVolumes; volumeOrdinal++)
308 for (
int k=0; k<=polyOrder_; k++)
310 for (
int j=0; j<=polyOrder_; j++)
312 for (
int i=0; i<=polyOrder_; i++)
314 const int max_ij = std::max(i,j);
315 const int max_ijk = std::max(max_ij,k);
318 fieldOrdinalOffset++;
324 INTREPID2_TEST_FOR_EXCEPTION(fieldOrdinalOffset != this->
basisCardinality_, std::invalid_argument,
"Internal error: basis enumeration is incorrect");
331 const ordinal_type tagSize = 4;
332 const ordinal_type posScDim = 0;
333 const ordinal_type posScOrd = 1;
334 const ordinal_type posDfOrd = 2;
337 const ordinal_type volumeDim = 3;
339 for (ordinal_type i=0;i<cardinality;++i) {
340 tagView(i*tagSize+0) = volumeDim;
341 tagView(i*tagSize+1) = 0;
342 tagView(i*tagSize+2) = i;
343 tagView(i*tagSize+3) = cardinality;
364 return "Intrepid2_LegendreBasis_HVOL_PYR";
397 const EOperator operatorType = OPERATOR_VALUE )
const override
399 auto numPoints = inputPoints.extent_int(0);
403 FunctorType functor(operatorType, outputValues, inputPoints, polyOrder_);
405 const int outputVectorSize = getVectorSizeForHierarchicalParallelism<OutputScalar>();
406 const int pointVectorSize = getVectorSizeForHierarchicalParallelism<PointScalar>();
407 const int vectorSize = std::max(outputVectorSize,pointVectorSize);
408 const int teamSize = 1;
410 auto policy = Kokkos::TeamPolicy<ExecutionSpace>(numPoints,teamSize,vectorSize);
411 Kokkos::parallel_for(
"Hierarchical_HVOL_PYR_Functor", policy, functor);
422 BasisPtr<DeviceType,OutputScalar,PointScalar>
425 INTREPID2_TEST_FOR_EXCEPTION(
true,std::invalid_argument,
"Input parameters out of bounds");
432 virtual BasisPtr<typename Kokkos::HostSpace::device_type, OutputScalar, PointScalar>
434 using HostDeviceType =
typename Kokkos::HostSpace::device_type;
436 return Teuchos::rcp(
new HostBasisType(polyOrder_, pointType_) );
Functor for computing values for the LegendreBasis_HVOL_PYR class.
Kokkos::DynRankView< OutputValueType, Kokkos::LayoutStride, DeviceType > OutputViewType
View type for basis value output.
Kokkos::View< ordinal_type *, typename ExecutionSpace::array_layout, Kokkos::HostSpace > OrdinalTypeArray1DHost
View type for 1d host array.
LegendreBasis_HVOL_PYR(int polyOrder, const EPointType pointType=POINTTYPE_DEFAULT)
Constructor.
unsigned basisCellTopologyKey_
Identifier of the base topology of the cells for which the basis is defined. See the Shards package f...
EBasis basisType_
Type of the basis.
Kokkos::DynRankView< PointValueType, Kokkos::LayoutStride, DeviceType > PointViewType
View type for input points.
Defines several coordinates and their gradients on the pyramid; maps from Intrepid2 (shards) pyramid ...
An abstract base class that defines interface for concrete basis implementations for Finite Element (...
Kokkos::DynRankView< scalarType, Kokkos::LayoutStride, DeviceType > ScalarViewType
View type for scalars.
Free functions, callable from device code, that implement various polynomials useful in basis definit...
EFunctionSpace functionSpace_
The function space in which the basis is defined.
ordinal_type basisDegree_
Degree of the largest complete polynomial space that can be represented by the basis.
Basis defining integrated Legendre basis on the line, a polynomial subspace of H(grad) on the line...
virtual KOKKOS_INLINE_FUNCTION void getValues(OutputViewType, const PointViewType, const EOperator, const typename Kokkos::TeamPolicy< ExecutionSpace >::member_type &teamMember, const typename ExecutionSpace::scratch_memory_space &scratchStorage, const ordinal_type subcellDim=-1, const ordinal_type subcellOrdinal=-1) const
Team-level evaluation of basis functions on a reference cell.
Header function for Intrepid2::Util class and other utility functions.
virtual BasisPtr< typename Kokkos::HostSpace::device_type, OutputScalar, PointScalar > getHostBasis() const override
Creates and returns a Basis object whose DeviceType template argument is Kokkos::HostSpace::device_ty...
Kokkos::View< ordinal_type **, typename ExecutionSpace::array_layout, Kokkos::HostSpace > OrdinalTypeArray2DHost
View type for 2d host array.
Kokkos::DynRankView< OutputValueType, Kokkos::LayoutStride, DeviceType > OutputViewType
View type for basis value output.
const char * getName() const override
Returns basis name.
ordinal_type basisCardinality_
Cardinality of the basis, i.e., the number of basis functions/degrees-of-freedom. ...
Kokkos::View< ordinal_type *, typename ExecutionSpace::array_layout, Kokkos::HostSpace > OrdinalTypeArray1DHost
View type for 1d host array.
OrdinalTypeArray3DHost tagToOrdinal_
DoF tag to ordinal lookup table.
virtual void getValues(OutputViewType outputValues, const PointViewType inputPoints, const EOperator operatorType=OPERATOR_VALUE) const override
Evaluation of a FEM basis on a reference cell.
OrdinalTypeArray2DHost ordinalToTag_
"true" if tagToOrdinal_ and ordinalToTag_ have been initialized
ECoordinates basisCoordinates_
The coordinate system for which the basis is defined.
OrdinalTypeArray2DHost fieldOrdinalH1PolynomialDegree_
H^1 polynomial degree for each degree of freedom. Only defined for hierarchical bases right now...
OrdinalTypeArray2DHost fieldOrdinalPolynomialDegree_
Polynomial degree for each degree of freedom. Only defined for hierarchical bases right now...
void setOrdinalTagData(OrdinalTypeView3D &tagToOrdinal, OrdinalTypeView2D &ordinalToTag, const OrdinalTypeView1D tags, const ordinal_type basisCard, const ordinal_type tagSize, const ordinal_type posScDim, const ordinal_type posScOrd, const ordinal_type posDfOrd)
Fills ordinalToTag_ and tagToOrdinal_ by basis-specific tag data.
BasisPtr< DeviceType, OutputScalar, PointScalar > getSubCellRefBasis(const ordinal_type subCellDim, const ordinal_type subCellOrd) const override
returns the basis associated to a subCell.
Kokkos::DynRankView< PointValueType, Kokkos::LayoutStride, DeviceType > PointViewType
View type for input points.
Header file for the abstract base class Intrepid2::Basis.
typename DeviceType::execution_space ExecutionSpace
(Kokkos) Execution space for basis.
virtual bool requireOrientation() const override
True if orientation is required.