Intrepid2
Intrepid2_TransformedBasisValues.hpp
Go to the documentation of this file.
1// @HEADER
2// ************************************************************************
3//
4// Intrepid2 Package
5// Copyright (2007) Sandia Corporation
6//
7// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8// license for use of this work by or on behalf of the U.S. Government.
9//
10// Redistribution and use in source and binary forms, with or without
11// modification, are permitted provided that the following conditions are
12// met:
13//
14// 1. Redistributions of source code must retain the above copyright
15// notice, this list of conditions and the following disclaimer.
16//
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// 3. Neither the name of the Corporation nor the names of the
22// contributors may be used to endorse or promote products derived from
23// this software without specific prior written permission.
24//
25// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36//
37// Questions? Contact Kyungjoo Kim (kyukim@sandia.gov),
38// Mauro Perego (mperego@sandia.gov), or
39// Nate Roberts (nvrober@sandia.gov)
40//
41// ************************************************************************
42// @HEADER
43
52#ifndef Intrepid2_TransformedBasisValues_h
53#define Intrepid2_TransformedBasisValues_h
54
56#include "Intrepid2_ScalarView.hpp"
57
58namespace Intrepid2 {
64 template<class Scalar, typename DeviceType>
66 {
67 public:
68 ordinal_type numCells_;
69
70 Data<Scalar,DeviceType> transform_; // vector case: (C,P,D,D) jacobian or jacobian inverse; can also be unset for identity transform. Scalar case: (C,P), or unset for identity.
71
73
80 :
81 numCells_(transform.extent_int(0)),
82 transform_(transform),
83 basisValues_(basisValues)
84 {
85 // sanity check: when transform is diagonal, we expect there to be no pointwise variation.
86 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(transform_.isDiagonal() && (transform_.getVariationTypes()[1] != CONSTANT), std::invalid_argument, "When transform is diagonal, we assume in various places that there is no pointwise variation; the transform_ Data should have CONSTANT as its variation type in dimension 1.");
87 }
88
93 TransformedBasisValues(const ordinal_type &numCells, const BasisValues<Scalar,DeviceType> &basisValues)
94 :
95 numCells_(numCells),
96 basisValues_(basisValues)
97 {}
98
100 template<typename OtherDeviceType, class = typename std::enable_if<!std::is_same<DeviceType, OtherDeviceType>::value>::type>
102 :
103 numCells_(transformedVectorData.numCells()),
104 transform_(transformedVectorData.transform()),
105 basisValues_(transformedVectorData.basisValues())
106 {}
107
112 :
113 numCells_(-1)
114 {}
115
117 KOKKOS_INLINE_FUNCTION bool axisAligned() const
118 {
119 if (!transform_.isValid())
120 {
121 // null transform is understood as the identity
122 return true;
123 }
124 else
125 {
126 return transform_.isDiagonal();
127 }
128 }
129
130 BasisValues<Scalar, DeviceType> basisValues() const
131 {
132 return basisValues_;
133 }
134
136 KOKKOS_INLINE_FUNCTION int cellDataExtent() const
137 {
138 return transform_.getDataExtent(0);
139 }
140
142 KOKKOS_INLINE_FUNCTION DataVariationType cellVariationType() const
143 {
144 return transform_.getVariationTypes()[0];
145 }
146
148 KOKKOS_INLINE_FUNCTION int numCells() const
149 {
150 return numCells_;
151 }
152
154 KOKKOS_INLINE_FUNCTION int numFields() const
155 {
156 return basisValues_.extent_int(0);
157 }
158
160 KOKKOS_INLINE_FUNCTION int numPoints() const
161 {
162 return basisValues_.extent_int(1);
163 }
164
166 KOKKOS_INLINE_FUNCTION int spaceDim() const
167 {
168 return basisValues_.extent_int(2);
169 }
170
172 KOKKOS_INLINE_FUNCTION Scalar operator()(const int &cellOrdinal, const int &fieldOrdinal, const int &pointOrdinal) const
173 {
174 if (!transform_.isValid())
175 {
176 // null transform is understood as the identity
177 return basisValues_(fieldOrdinal,pointOrdinal);
178 }
179 else
180 {
181 return transform_(cellOrdinal,pointOrdinal) * basisValues_(fieldOrdinal,pointOrdinal);
182 }
183 }
184
186 KOKKOS_INLINE_FUNCTION Scalar operator()(const int &cellOrdinal, const int &fieldOrdinal, const int &pointOrdinal, const int &dim) const
187 {
188 if (!transform_.isValid())
189 {
190 // null transform is understood as the identity
191 return basisValues_(fieldOrdinal,pointOrdinal,dim);
192 }
193 else if (transform_.isDiagonal())
194 {
195 return transform_(cellOrdinal,pointOrdinal,dim,dim) * basisValues_(fieldOrdinal,pointOrdinal,dim);
196 }
197 else
198 {
199 Scalar value = 0.0;
200 for (int d2=0; d2<transform_.extent_int(2); d2++)
201 {
202 value += transform_(cellOrdinal,pointOrdinal,dim,d2) * basisValues_(fieldOrdinal,pointOrdinal,d2);
203 }
204 return value;
205 }
206 }
207
209 KOKKOS_INLINE_FUNCTION Scalar transformWeight(const int &cellOrdinal, const int &pointOrdinal) const
210 {
211 if (!transform_.isValid())
212 {
213 // null transform is understood as identity
214 return 1.0;
215 }
216 else
217 {
218 return transform_(cellOrdinal,pointOrdinal);
219 }
220 }
221
223 KOKKOS_INLINE_FUNCTION Scalar transformWeight(const int &cellOrdinal, const int &pointOrdinal, const int &dim1, const int &dim2) const
224 {
225 if (!transform_.isValid())
226 {
227 // null transform is understood as identity
228 return (dim1 == dim2) ? 1.0 : 0.0;
229 }
230 else
231 {
232 return transform_(cellOrdinal,pointOrdinal,dim1,dim2);
233 }
234 }
235
238 {
239 return transform_;
240 }
241
244 {
245 return basisValues_.vectorData();
246 }
247
249 KOKKOS_INLINE_FUNCTION
250 unsigned rank() const
251 {
252 return basisValues_.rank() + 1; // transformation adds a cell dimension
253 }
254
256 KOKKOS_INLINE_FUNCTION
257 int extent_int(const int &r) const
258 {
259 if (r == 0) return numCells();
260 else if (r == 1) return numFields();
261 else if (r == 2) return numPoints();
262 else if (r == 3) return spaceDim();
263 else if (r > 3) return 1;
264
265 return -1; // unreachable return; here to avoid compiler warnings.
266 }
267 };
268}
269
270#endif /* Intrepid2_TransformedBasisValues_h */
Header file for the data-wrapper class Intrepid2::BasisValues.
@ CONSTANT
does not vary
#define INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(test, x, msg)
The data containers in Intrepid2 that support sum factorization and other reduced-data optimizations ...
const VectorDataType & vectorData() const
VectorData accessor.
Wrapper around a Kokkos::View that allows data that is constant or repeating in various logical dimen...
KOKKOS_INLINE_FUNCTION int extent_int(const int &r) const
Returns the logical extent in the specified dimension.
KOKKOS_INLINE_FUNCTION constexpr bool isValid() const
returns true for containers that have data; false for those that don't (namely, those that have been ...
KOKKOS_INLINE_FUNCTION bool isDiagonal() const
returns true for containers that have two dimensions marked as BLOCK_PLUS_DIAGONAL for which the non-...
KOKKOS_INLINE_FUNCTION const Kokkos::Array< DataVariationType, 7 > & getVariationTypes() const
Returns an array with the variation types in each logical dimension.
KOKKOS_INLINE_FUNCTION int getDataExtent(const ordinal_type &d) const
returns the true extent of the data corresponding to the logical dimension provided; if the data does...
Structure-preserving representation of transformed vector data; reference space values and transforma...
KOKKOS_INLINE_FUNCTION int cellDataExtent() const
Returns the true data extent in the cell dimension (e.g., will be 1 for transform matrices that do no...
KOKKOS_INLINE_FUNCTION DataVariationType cellVariationType() const
Returns the variation type corresponding to the cell dimension.
TransformedBasisValues(const Data< Scalar, DeviceType > &transform, const BasisValues< Scalar, DeviceType > &basisValues)
Standard constructor.
KOKKOS_INLINE_FUNCTION bool axisAligned() const
Returns true if the transformation matrix is diagonal.
KOKKOS_INLINE_FUNCTION Scalar transformWeight(const int &cellOrdinal, const int &pointOrdinal) const
Returns the specified entry in the (scalar) transform. (Only valid for scalar-valued BasisValues; see...
KOKKOS_INLINE_FUNCTION int extent_int(const int &r) const
Returns the extent in the specified dimension as an int.
KOKKOS_INLINE_FUNCTION unsigned rank() const
Returns the rank of the container, which is 3 for scalar values, and 4 for vector values.
const VectorData< Scalar, DeviceType > & vectorData() const
Returns the reference-space vector data.
KOKKOS_INLINE_FUNCTION Scalar operator()(const int &cellOrdinal, const int &fieldOrdinal, const int &pointOrdinal, const int &dim) const
Vector accessor, with arguments (C,F,P,D).
KOKKOS_INLINE_FUNCTION int spaceDim() const
Returns the logical extent in the space dimension, which is the 3 dimension in this container.
TransformedBasisValues(const ordinal_type &numCells, const BasisValues< Scalar, DeviceType > &basisValues)
Constructor for the case of an identity transform.
KOKKOS_INLINE_FUNCTION Scalar transformWeight(const int &cellOrdinal, const int &pointOrdinal, const int &dim1, const int &dim2) const
Returns the specified entry in the transform matrix.
const Data< Scalar, DeviceType > & transform() const
Returns the transform matrix. An invalid/empty container indicates the identity transform.
KOKKOS_INLINE_FUNCTION int numCells() const
Returns the logical extent in the cell dimension, which is the 0 dimension in this container.
KOKKOS_INLINE_FUNCTION int numPoints() const
Returns the logical extent in the points dimension, which is the 2 dimension in this container.
TransformedBasisValues()
Default constructor; an invalid container. Will return -1 for numCells().
TransformedBasisValues(const TransformedBasisValues< Scalar, OtherDeviceType > &transformedVectorData)
copy-like constructor for differing device types. This may do a deep_copy of underlying views,...
KOKKOS_INLINE_FUNCTION Scalar operator()(const int &cellOrdinal, const int &fieldOrdinal, const int &pointOrdinal) const
Scalar accessor, with arguments (C,F,P).
KOKKOS_INLINE_FUNCTION int numFields() const
Returns the logical extent in the fields dimension, which is the 1 dimension in this container.
Reference-space field values for a basis, designed to support typical vector-valued bases.