Intrepid2
Intrepid2_ArrayToolsDefCloneScale.hpp
Go to the documentation of this file.
1// @HEADER
2// ************************************************************************
3//
4// Intrepid 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), or
38// Mauro Perego (mperego@sandia.gov)
39//
40// ************************************************************************
41// @HEADER
42
49#ifndef __INTREPID2_ARRAYTOOLS_DEF_CLONESCALE_HPP__
50#define __INTREPID2_ARRAYTOOLS_DEF_CLONESCALE_HPP__
51
52namespace Intrepid2 {
53
54 namespace FunctorArrayTools {
55
59 template<typename OutputViewType,
60 typename inputViewType,
61 ordinal_type valRank>
62 struct F_clone {
63 OutputViewType _output;
64 const inputViewType _input;
65
66 KOKKOS_INLINE_FUNCTION
67 F_clone(OutputViewType output_,
68 inputViewType input_)
69 : _output(output_),
70 _input(input_) {}
71
72 // clone data
73 KOKKOS_INLINE_FUNCTION
74 void
75 operator()(const ordinal_type cl,
76 const ordinal_type pt) const {
77 switch (valRank) {
78 case 0: {
79 _output.access(cl, pt) = _input.access(pt);
80 break;
81 }
82 case 1: {
83 const ordinal_type iend = _output.extent(2);
84 for (ordinal_type i=0;i<iend;++i)
85 _output.access(cl, pt, i) = _input.access(pt, i);
86 break;
87 }
88 case 2: {
89 const ordinal_type
90 iend = _output.extent(2),
91 jend = _output.extent(3);
92 for (ordinal_type i=0;i<iend;++i)
93 for (ordinal_type j=0;j<jend;++j)
94 _output.access(cl, pt, i, j) = _input.access(pt, i, j);
95 break;
96 }
97 }
98 }
99
100 // clone fields
101 KOKKOS_INLINE_FUNCTION
102 void
103 operator()(const ordinal_type cl,
104 const ordinal_type bf,
105 const ordinal_type pt) const {
106 switch (valRank) {
107 case 0: {
108 _output.access(cl, bf, pt) = _input.access(bf, pt);
109 break;
110 }
111 case 1: {
112 const ordinal_type iend = _output.extent(3);
113 for (ordinal_type i=0;i<iend;++i)
114 _output.access(cl, bf, pt, i) = _input.access(bf, pt, i);
115 break;
116 }
117 case 2: {
118 const ordinal_type
119 iend = _output.extent(3),
120 jend = _output.extent(4);
121 for (ordinal_type i=0;i<iend;++i)
122 for (ordinal_type j=0;j<jend;++j)
123 _output.access(cl, bf, pt, i, j) = _input.access(bf, pt, i, j);
124 break;
125 }
126 }
127 }
128 };
129 }
130
131 template<typename DeviceType>
132 template<typename outputValueType, class ...outputProperties,
133 typename inputValueType, class ...inputProperties>
135 cloneFields( Kokkos::DynRankView<outputValueType,outputProperties...> output,
136 const Kokkos::DynRankView<inputValueType, inputProperties...> input ) {
137#ifdef HAVE_INTREPID2_DEBUG
138 {
139 INTREPID2_TEST_FOR_EXCEPTION( ( input.rank() < 2 || input.rank() > 4 ), std::invalid_argument,
140 ">>> ERROR (ArrayTools::clone): Input fields container must have rank 2, 3, or 4.");
141 INTREPID2_TEST_FOR_EXCEPTION( ( output.rank() != (input.rank()+1) ), std::invalid_argument,
142 ">>> ERROR (ArrayTools::clone): The rank of the input fields container must be one less than the rank of the output fields container.");
143 for (size_type i=0;i< input.rank();++i) {
144 INTREPID2_TEST_FOR_EXCEPTION( (input.extent(i) != output.extent(i+1)), std::invalid_argument,
145 ">>> ERROR (ArrayTools::clone): Dimensions of input and output fields containers do not match.");
146 }
147 }
148#endif
149
150 typedef Kokkos::DynRankView<outputValueType,outputProperties...> OutputViewType;
151 typedef Kokkos::DynRankView<inputValueType, inputProperties...> inputViewType;
152
153 using range_policy_type = Kokkos::MDRangePolicy
154 < ExecSpaceType, Kokkos::Rank<3>, Kokkos::IndexType<ordinal_type> >;
155
156 range_policy_type policy( { 0, 0, 0 },
157 { /*C*/ output.extent(0), /*F*/ output.extent(1), /*P*/ output.extent(2) } );
158 const ordinal_type valRank = output.rank() - 3;
159 switch (valRank) {
160 case 0: {
161 typedef FunctorArrayTools::F_clone<OutputViewType,inputViewType,0> FunctorType;
162 Kokkos::parallel_for( policy, FunctorType(output, input) );
163 break;
164 }
165 case 1: {
166 typedef FunctorArrayTools::F_clone<OutputViewType,inputViewType,1> FunctorType;
167 Kokkos::parallel_for( policy, FunctorType(output, input) );
168 break;
169 }
170 case 2: {
171 typedef FunctorArrayTools::F_clone<OutputViewType,inputViewType,2> FunctorType;
172 Kokkos::parallel_for( policy, FunctorType(output, input) );
173 break;
174 }
175 }
176 }
177
178 template<typename DeviceType>
179 template<typename outputValueType, class ...outputProperties,
180 typename inputValueType, class ...inputProperties>
182 cloneData( Kokkos::DynRankView<outputValueType,outputProperties...> output,
183 const Kokkos::DynRankView<inputValueType, inputProperties...> input ) {
184#ifdef HAVE_INTREPID2_DEBUG
185 {
186 INTREPID2_TEST_FOR_EXCEPTION( ( input.rank() < 1 || input.rank() > 3 ), std::invalid_argument,
187 ">>> ERROR (ArrayTools::clone): Input fields container must have rank 1, 2, or 3.");
188 INTREPID2_TEST_FOR_EXCEPTION( ( output.rank() != (input.rank()+1) ), std::invalid_argument,
189 ">>> ERROR (ArrayTools::clone): The rank of the input fields container must be one less than the rank of the output fields container.");
190 for (ordinal_type i=0;i<input.rank();++i) {
191 INTREPID2_TEST_FOR_EXCEPTION( (input.extent(i) != output.extent(i+1)), std::invalid_argument,
192 ">>> ERROR (ArrayTools::clone): Dimensions of input and output fields containers do not match.");
193 }
194 }
195#endif
196
197 typedef Kokkos::DynRankView<outputValueType,outputProperties...> OutputViewType;
198 typedef Kokkos::DynRankView<inputValueType, inputProperties...> inputViewType;
199
200 using range_policy_type = Kokkos::MDRangePolicy
201 < ExecSpaceType, Kokkos::Rank<2>, Kokkos::IndexType<ordinal_type> >;
202
203 range_policy_type policy( { 0, 0 },
204 { /*C*/ output.extent(0), /*P*/ output.extent(1) } );
205 const ordinal_type valRank = output.rank() - 2;
206 switch (valRank) {
207 case 0: {
208 typedef FunctorArrayTools::F_clone<OutputViewType,inputViewType,0> FunctorType;
209 Kokkos::parallel_for( policy, FunctorType(output, input) );
210 break;
211 }
212 case 1: {
213 typedef FunctorArrayTools::F_clone<OutputViewType,inputViewType,1> FunctorType;
214 Kokkos::parallel_for( policy, FunctorType(output, input) );
215 break;
216 }
217 case 2: {
218 typedef FunctorArrayTools::F_clone<OutputViewType,inputViewType,2> FunctorType;
219 Kokkos::parallel_for( policy, FunctorType(output, input) );
220 break;
221 }
222 }
223 }
224
225} // end namespace Intrepid2
226
227#endif
static void cloneData(Kokkos::DynRankView< outputDataValueType, outputDataProperties... > outputData, const Kokkos::DynRankView< inputDataValueType, inputDataProperties... > inputData)
Replicates a rank-2, 3, or 4 container with dimensions (F,P), (F,P,D1) or (F,P,D1,...
static void cloneFields(Kokkos::DynRankView< outputFieldValueType, outputFieldProperties... > outputFields, const Kokkos::DynRankView< inputFieldValueType, inputFieldProperties... > inputFields)
Replicates a rank-2, 3, or 4 container with dimensions (F,P), (F,P,D1) or (F,P,D1,...
Functor for clone see Intrepid2::ArrayTools for more.