Intrepid2
Intrepid2_TransformedVectorData.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
50#ifndef Intrepid2_TransformedVectorData_h
51#define Intrepid2_TransformedVectorData_h
52
54
55#include "Intrepid2_ScalarView.hpp"
56
57namespace Intrepid2 {
63 template<class Scalar, typename DeviceType>
65 {
66 public:
68
69 Data<Scalar,DeviceType> transform_; // (C,P,D,D) jacobian or jacobian inverse; can also be unset for identity transform
70
71 VectorData<Scalar, DeviceType> vectorData_; // notionally (F,P,D) container
72
79 :
80 transform_(transform), vectorData_(vectorData)
81 {
82 // sanity check: when transform is diagonal, we expect there to be no pointwise variation.
83 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.");
84 }
85
91 :
92 vectorData_(vectorData)
93 {}
94
96 template<typename OtherDeviceType, class = typename std::enable_if<!std::is_same<DeviceType, OtherDeviceType>::value>::type>
98 :
99 transform_(transformedVectorData.transform()),
100 vectorData_(transformedVectorData.vectorData())
101 {}
102
104 KOKKOS_INLINE_FUNCTION bool axisAligned() const
105 {
106 if (!transform_.isValid())
107 {
108 // null transform is understood as the identity
109 return true;
110 }
111 else
112 {
113 return transform_.isDiagonal();
114 }
115 }
116
118 KOKKOS_INLINE_FUNCTION int cellDataExtent() const
119 {
120 return transform_.getDataExtent(0);
121 }
122
124 KOKKOS_INLINE_FUNCTION DataVariationType cellVariationType() const
125 {
126 return transform_.getVariationTypes()[0];
127 }
128
130 KOKKOS_INLINE_FUNCTION int numCells() const
131 {
132 return transform_.extent_int(0);
133 }
134
136 KOKKOS_INLINE_FUNCTION int numFields() const
137 {
138 return vectorData_.numFields();
139 }
140
142 KOKKOS_INLINE_FUNCTION int numPoints() const
143 {
144 return vectorData_.numPoints();
145 }
146
148 KOKKOS_INLINE_FUNCTION int spaceDim() const
149 {
150 return vectorData_.spaceDim();
151 }
152
154 KOKKOS_INLINE_FUNCTION Scalar operator()(const int &cellOrdinal, const int &fieldOrdinal, const int &pointOrdinal, const int &dim) const
155 {
156 if (!transform_.isValid())
157 {
158 // null transform is understood as the identity
159 return vectorData_(fieldOrdinal,pointOrdinal,dim);
160 }
161 else if (transform_.isDiagonal())
162 {
163 return transform_(cellOrdinal,pointOrdinal,dim,dim) * vectorData_(fieldOrdinal,pointOrdinal,dim);
164 }
165 else
166 {
167 Scalar value = 0.0;
168 for (int d2=0; d2<transform_.extent_int(2); d2++)
169 {
170 value += transform_(cellOrdinal,pointOrdinal,dim,d2) * vectorData_(fieldOrdinal,pointOrdinal,d2);
171 }
172 return value;
173 }
174 }
175
177 KOKKOS_INLINE_FUNCTION Scalar transformWeight(const int &cellOrdinal, const int &pointOrdinal, const int &dim1, const int &dim2) const
178 {
179 if (!transform_.isValid())
180 {
181 // null transform is understood as identity
182 return (dim1 == dim2) ? 1.0 : 0.0;
183 }
184 else
185 {
186 return transform_(cellOrdinal,pointOrdinal,dim1,dim2);
187 }
188 }
189
192 {
193 return transform_;
194 }
195
198 {
199 return vectorData_;
200 }
201
203 KOKKOS_INLINE_FUNCTION
204 constexpr unsigned rank() const
205 {
206 return 4; // shape is (C,F,P,D)
207 }
208
210 KOKKOS_INLINE_FUNCTION
211 int extent_int(const int &r) const
212 {
213 if (r == 0) return numCells();
214 else if (r == 1) return numFields();
215 else if (r == 2) return numPoints();
216 else if (r == 3) return spaceDim();
217 else if (r > 3) return 1;
218
219 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(true, std::invalid_argument, "Unsupported rank");
220 return -1; // unreachable return; here to avoid compiler warnings.
221 }
222 };
223}
224
225#endif /* Intrepid2_TransformedVectorData_h */
@ CONSTANT
does not vary
Reference-space field values for a basis, designed to support typical vector-valued bases.
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 bool axisAligned() const
Returns true if the transformation matrix is diagonal.
TransformedVectorData(const VectorData< Scalar, DeviceType > &vectorData)
Constructor for the case of an identity transform.
KOKKOS_INLINE_FUNCTION int numPoints() const
Returns the logical extent in the points dimension, which is the 2 dimension in this container.
const Data< Scalar, DeviceType > & transform() const
Returns the transform matrix. An invalid/empty container indicates the identity transform.
KOKKOS_INLINE_FUNCTION constexpr unsigned rank() const
Returns the rank of the container, which is 4.
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.
KOKKOS_INLINE_FUNCTION Scalar operator()(const int &cellOrdinal, const int &fieldOrdinal, const int &pointOrdinal, const int &dim) const
Accessor, with arguments (C,F,P,D).
const VectorData< Scalar, DeviceType > & vectorData() const
Returns the reference-space vector data.
KOKKOS_INLINE_FUNCTION int spaceDim() const
Returns the logical extent in the space dimension, which is the 3 dimension in this container.
KOKKOS_INLINE_FUNCTION int extent_int(const int &r) const
Returns the extent in the specified dimension as an int.
TransformedVectorData(const Data< Scalar, DeviceType > &transform, const VectorData< Scalar, DeviceType > &vectorData)
Standard constructor.
TransformedVectorData(const TransformedVectorData< Scalar, OtherDeviceType > &transformedVectorData)
copy-like constructor for differing device types. This may do a deep_copy of underlying views,...
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 DataVariationType cellVariationType() const
Returns the variation type corresponding to the cell dimension.
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.
KOKKOS_INLINE_FUNCTION int numPoints() const
Returns the number of points; corresponds to the second dimension of this container.
KOKKOS_INLINE_FUNCTION int spaceDim() const
Returns the spatial dimension; corresponds to the third dimension of this container.
KOKKOS_INLINE_FUNCTION int numFields() const
Returns the total number of fields; corresponds to the first dimension of this container.