15 #ifndef Intrepid2_IntegratedLegendreBasis_HGRAD_LINE_h
16 #define Intrepid2_IntegratedLegendreBasis_HGRAD_LINE_h
18 #include <Kokkos_DynRankView.hpp>
20 #include <Intrepid2_config.h>
33 template<
class DeviceType,
class OutputScalar,
class PointScalar,
34 class OutputFieldType,
class InputPointsType>
37 using ExecutionSpace =
typename DeviceType::execution_space;
38 using ScratchSpace =
typename ExecutionSpace::scratch_memory_space;
39 using OutputScratchView = Kokkos::View<OutputScalar*,ScratchSpace,Kokkos::MemoryTraits<Kokkos::Unmanaged>>;
40 using PointScratchView = Kokkos::View<PointScalar*, ScratchSpace,Kokkos::MemoryTraits<Kokkos::Unmanaged>>;
42 using TeamPolicy = Kokkos::TeamPolicy<ExecutionSpace>;
43 using TeamMember =
typename TeamPolicy::member_type;
47 OutputFieldType output_;
48 InputPointsType inputPoints_;
51 bool defineVertexFunctions_;
52 int numFields_, numPoints_;
54 size_t fad_size_output_;
57 int polyOrder,
bool defineVertexFunctions)
58 : opType_(opType), output_(output), inputPoints_(inputPoints),
59 polyOrder_(polyOrder), defineVertexFunctions_(defineVertexFunctions),
60 fad_size_output_(getScalarDimensionForView(output))
62 numFields_ = output.extent_int(0);
63 numPoints_ = output.extent_int(1);
64 INTREPID2_TEST_FOR_EXCEPTION(numPoints_ != inputPoints.extent_int(0), std::invalid_argument,
"point counts need to match!");
65 INTREPID2_TEST_FOR_EXCEPTION(numFields_ != polyOrder_+1, std::invalid_argument,
"output field size does not match basis cardinality");
68 KOKKOS_INLINE_FUNCTION
69 void operator()(
const TeamMember & teamMember )
const
71 auto pointOrdinal = teamMember.league_rank();
72 OutputScratchView field_values_at_point;
73 if (fad_size_output_ > 0) {
74 field_values_at_point = OutputScratchView(teamMember.team_shmem(), numFields_, fad_size_output_);
77 field_values_at_point = OutputScratchView(teamMember.team_shmem(), numFields_);
80 const auto & input_x = inputPoints_(pointOrdinal,0);
81 const bool taking_derivative = (opType_ != OPERATOR_VALUE);
82 const bool callingShiftedScaledLegendre = (opType_ == OPERATOR_VALUE) || (opType_ == OPERATOR_GRAD) || (opType_ == OPERATOR_D1);
85 const PointScalar x = callingShiftedScaledLegendre ? PointScalar((input_x + 1.0)/2.0) : PointScalar(input_x);
86 const double legendreScaling = 1.0;
87 const double outputScaling = taking_derivative ? 0.5 : 1.0;
94 Polynomials::shiftedScaledIntegratedLegendreValues(field_values_at_point, polyOrder_, x, legendreScaling);
99 if (defineVertexFunctions_)
101 field_values_at_point(0) = 1. - x;
102 field_values_at_point(1) = x;
109 Polynomials::shiftedScaledIntegratedLegendreValues_dx(field_values_at_point, polyOrder_, x, legendreScaling);
114 if (defineVertexFunctions_)
116 field_values_at_point(0) = -1.0;
117 field_values_at_point(1) = 1.0;
130 auto derivativeOrder = getOperatorOrder(opType_) - 1;
131 Polynomials::legendreDerivativeValues(field_values_at_point, polyOrder_, x, derivativeOrder);
136 OutputScalar Pn_minus_one = field_values_at_point(1);
137 for (
int fieldOrdinal=2; fieldOrdinal<numFields_; fieldOrdinal++)
139 OutputScalar Pn = field_values_at_point(fieldOrdinal);
140 field_values_at_point(fieldOrdinal) = Pn_minus_one;
144 if (numFields_ >= 1) field_values_at_point(0) = 0.0;
145 if (numFields_ >= 2) field_values_at_point(1) = 0.0;
153 device_assert(
false);
157 for (
int fieldOrdinal=0; fieldOrdinal<numFields_; fieldOrdinal++)
160 output_.access(fieldOrdinal,pointOrdinal,0) = outputScaling * field_values_at_point(fieldOrdinal);
167 size_t team_shmem_size (
int team_size)
const
170 size_t shmem_size = 0;
171 if (fad_size_output_ > 0)
172 shmem_size += OutputScratchView::shmem_size(numFields_, fad_size_output_);
174 shmem_size += OutputScratchView::shmem_size(numFields_);
197 template<
typename DeviceType,
198 typename OutputScalar = double,
199 typename PointScalar = double,
200 bool defineVertexFunctions =
true,
201 bool useMinusOneToOneReferenceElement =
true>
203 :
public Basis<DeviceType,OutputScalar,PointScalar>
220 bool defineVertexFunctions_;
221 EPointType pointType_;
235 polyOrder_(polyOrder),
236 pointType_(pointType)
238 INTREPID2_TEST_FOR_EXCEPTION(pointType!=POINTTYPE_DEFAULT,std::invalid_argument,
"PointType not supported");
247 const int degreeLength = 1;
258 if (defineVertexFunctions)
269 const ordinal_type tagSize = 4;
270 const ordinal_type posScDim = 0;
271 const ordinal_type posScOrd = 1;
272 const ordinal_type posDfOrd = 2;
276 if (defineVertexFunctions) {
278 const ordinal_type v0 = 0;
279 tagView(v0*tagSize+0) = 0;
280 tagView(v0*tagSize+1) = 0;
281 tagView(v0*tagSize+2) = 0;
282 tagView(v0*tagSize+3) = 1;
284 const ordinal_type v1 = 1;
285 tagView(v1*tagSize+0) = 0;
286 tagView(v1*tagSize+1) = 1;
287 tagView(v1*tagSize+2) = 0;
288 tagView(v1*tagSize+3) = 1;
290 const ordinal_type iend = cardinality - 2;
291 for (ordinal_type i=0;i<iend;++i) {
292 const auto e = i + 2;
293 tagView(e*tagSize+0) = 1;
294 tagView(e*tagSize+1) = 0;
295 tagView(e*tagSize+2) = i;
296 tagView(e*tagSize+3) = iend;
300 for (ordinal_type i=0;i<cardinality;++i) {
301 tagView(i*tagSize+0) = 1;
302 tagView(i*tagSize+1) = 0;
303 tagView(i*tagSize+2) = i;
304 tagView(i*tagSize+3) = cardinality;
313 this->basisCardinality_,
326 return "Intrepid2_IntegratedLegendreBasis_HGRAD_LINE";
359 const EOperator operatorType = OPERATOR_VALUE )
const override
361 auto numPoints = inputPoints.extent_int(0);
365 FunctorType functor(operatorType, outputValues, inputPoints, polyOrder_, defineVertexFunctions);
367 const int outputVectorSize = getVectorSizeForHierarchicalParallelism<OutputScalar>();
368 const int pointVectorSize = getVectorSizeForHierarchicalParallelism<PointScalar>();
369 const int vectorSize = std::max(outputVectorSize,pointVectorSize);
370 const int teamSize = 1;
372 auto policy = Kokkos::TeamPolicy<ExecutionSpace>(numPoints,teamSize,vectorSize);
373 Kokkos::parallel_for(
"Hierarchical_HGRAD_LINE_Functor", policy, functor);
380 virtual BasisPtr<typename Kokkos::HostSpace::device_type, OutputScalar, PointScalar>
382 using HostDeviceType =
typename Kokkos::HostSpace::device_type;
384 return Teuchos::rcp(
new HostBasisType(polyOrder_, pointType_) );
Kokkos::View< ordinal_type *, typename ExecutionSpace::array_layout, Kokkos::HostSpace > OrdinalTypeArray1DHost
View type for 1d host array.
virtual bool requireOrientation() const override
True if orientation is required.
Kokkos::View< ordinal_type *, typename ExecutionSpace::array_layout, Kokkos::HostSpace > OrdinalTypeArray1DHost
View type for 1d host array.
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.
virtual void getValues(OutputViewType outputValues, const PointViewType inputPoints, const EOperator operatorType=OPERATOR_VALUE) const override
Evaluation of a FEM basis on a reference cell.
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...
IntegratedLegendreBasis_HGRAD_LINE(int polyOrder, EPointType pointType=POINTTYPE_DEFAULT)
Constructor.
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.
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.
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.
Basis defining integrated Legendre basis on the line, a polynomial subspace of H(grad) on the line...
Kokkos::DynRankView< PointValueType, Kokkos::LayoutStride, DeviceType > PointViewType
View type for input points.
ordinal_type basisCardinality_
Cardinality of the basis, i.e., the number of basis functions/degrees-of-freedom. ...
Kokkos::DynRankView< OutputValueType, Kokkos::LayoutStride, DeviceType > OutputViewType
View type for basis value output.
OrdinalTypeArray3DHost tagToOrdinal_
DoF tag to ordinal lookup table.
const char * getName() const override
Returns basis name.
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...
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...
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.
Functor for computing values for the IntegratedLegendreBasis_HGRAD_LINE class.
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.