Intrepid2
Intrepid2_ArrayToolsDefCloneScale.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Intrepid2 Package
4//
5// Copyright 2007 NTESS and the Intrepid2 contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
16#ifndef __INTREPID2_ARRAYTOOLS_DEF_CLONESCALE_HPP__
17#define __INTREPID2_ARRAYTOOLS_DEF_CLONESCALE_HPP__
18
19namespace Intrepid2 {
20
21 namespace FunctorArrayTools {
22
26 template<typename OutputViewType,
27 typename inputViewType,
28 ordinal_type valRank>
29 struct F_clone {
30 OutputViewType _output;
31 const inputViewType _input;
32
33 KOKKOS_INLINE_FUNCTION
34 F_clone(OutputViewType output_,
35 inputViewType input_)
36 : _output(output_),
37 _input(input_) {}
38
39 // clone data
40 KOKKOS_INLINE_FUNCTION
41 void
42 operator()(const ordinal_type cl,
43 const ordinal_type pt) const {
44 switch (valRank) {
45 case 0: {
46 _output.access(cl, pt) = _input.access(pt);
47 break;
48 }
49 case 1: {
50 const ordinal_type iend = _output.extent(2);
51 for (ordinal_type i=0;i<iend;++i)
52 _output.access(cl, pt, i) = _input.access(pt, i);
53 break;
54 }
55 case 2: {
56 const ordinal_type
57 iend = _output.extent(2),
58 jend = _output.extent(3);
59 for (ordinal_type i=0;i<iend;++i)
60 for (ordinal_type j=0;j<jend;++j)
61 _output.access(cl, pt, i, j) = _input.access(pt, i, j);
62 break;
63 }
64 }
65 }
66
67 // clone fields
68 KOKKOS_INLINE_FUNCTION
69 void
70 operator()(const ordinal_type cl,
71 const ordinal_type bf,
72 const ordinal_type pt) const {
73 switch (valRank) {
74 case 0: {
75 _output.access(cl, bf, pt) = _input.access(bf, pt);
76 break;
77 }
78 case 1: {
79 const ordinal_type iend = _output.extent(3);
80 for (ordinal_type i=0;i<iend;++i)
81 _output.access(cl, bf, pt, i) = _input.access(bf, pt, i);
82 break;
83 }
84 case 2: {
85 const ordinal_type
86 iend = _output.extent(3),
87 jend = _output.extent(4);
88 for (ordinal_type i=0;i<iend;++i)
89 for (ordinal_type j=0;j<jend;++j)
90 _output.access(cl, bf, pt, i, j) = _input.access(bf, pt, i, j);
91 break;
92 }
93 }
94 }
95 };
96 }
97
98 template<typename DeviceType>
99 template<typename outputValueType, class ...outputProperties,
100 typename inputValueType, class ...inputProperties>
102 cloneFields( Kokkos::DynRankView<outputValueType,outputProperties...> output,
103 const Kokkos::DynRankView<inputValueType, inputProperties...> input ) {
104#ifdef HAVE_INTREPID2_DEBUG
105 {
106 INTREPID2_TEST_FOR_EXCEPTION( ( input.rank() < 2 || input.rank() > 4 ), std::invalid_argument,
107 ">>> ERROR (ArrayTools::clone): Input fields container must have rank 2, 3, or 4.");
108 INTREPID2_TEST_FOR_EXCEPTION( ( output.rank() != (input.rank()+1) ), std::invalid_argument,
109 ">>> ERROR (ArrayTools::clone): The rank of the input fields container must be one less than the rank of the output fields container.");
110 for (size_type i=0;i< input.rank();++i) {
111 INTREPID2_TEST_FOR_EXCEPTION( (input.extent(i) != output.extent(i+1)), std::invalid_argument,
112 ">>> ERROR (ArrayTools::clone): Dimensions of input and output fields containers do not match.");
113 }
114 }
115#endif
116
117 typedef Kokkos::DynRankView<outputValueType,outputProperties...> OutputViewType;
118 typedef Kokkos::DynRankView<inputValueType, inputProperties...> inputViewType;
119
120 using range_policy_type = Kokkos::MDRangePolicy
121 < ExecSpaceType, Kokkos::Rank<3>, Kokkos::IndexType<ordinal_type> >;
122
123 range_policy_type policy( { 0, 0, 0 },
124 { /*C*/ output.extent(0), /*F*/ output.extent(1), /*P*/ output.extent(2) } );
125 const ordinal_type valRank = output.rank() - 3;
126 switch (valRank) {
127 case 0: {
128 typedef FunctorArrayTools::F_clone<OutputViewType,inputViewType,0> FunctorType;
129 Kokkos::parallel_for( policy, FunctorType(output, input) );
130 break;
131 }
132 case 1: {
133 typedef FunctorArrayTools::F_clone<OutputViewType,inputViewType,1> FunctorType;
134 Kokkos::parallel_for( policy, FunctorType(output, input) );
135 break;
136 }
137 case 2: {
138 typedef FunctorArrayTools::F_clone<OutputViewType,inputViewType,2> FunctorType;
139 Kokkos::parallel_for( policy, FunctorType(output, input) );
140 break;
141 }
142 }
143 }
144
145 template<typename DeviceType>
146 template<typename outputValueType, class ...outputProperties,
147 typename inputValueType, class ...inputProperties>
149 cloneData( Kokkos::DynRankView<outputValueType,outputProperties...> output,
150 const Kokkos::DynRankView<inputValueType, inputProperties...> input ) {
151#ifdef HAVE_INTREPID2_DEBUG
152 {
153 INTREPID2_TEST_FOR_EXCEPTION( ( input.rank() < 1 || input.rank() > 3 ), std::invalid_argument,
154 ">>> ERROR (ArrayTools::clone): Input fields container must have rank 1, 2, or 3.");
155 INTREPID2_TEST_FOR_EXCEPTION( ( output.rank() != (input.rank()+1) ), std::invalid_argument,
156 ">>> ERROR (ArrayTools::clone): The rank of the input fields container must be one less than the rank of the output fields container.");
157 for (ordinal_type i=0;i<input.rank();++i) {
158 INTREPID2_TEST_FOR_EXCEPTION( (input.extent(i) != output.extent(i+1)), std::invalid_argument,
159 ">>> ERROR (ArrayTools::clone): Dimensions of input and output fields containers do not match.");
160 }
161 }
162#endif
163
164 typedef Kokkos::DynRankView<outputValueType,outputProperties...> OutputViewType;
165 typedef Kokkos::DynRankView<inputValueType, inputProperties...> inputViewType;
166
167 using range_policy_type = Kokkos::MDRangePolicy
168 < ExecSpaceType, Kokkos::Rank<2>, Kokkos::IndexType<ordinal_type> >;
169
170 range_policy_type policy( { 0, 0 },
171 { /*C*/ output.extent(0), /*P*/ output.extent(1) } );
172 const ordinal_type valRank = output.rank() - 2;
173 switch (valRank) {
174 case 0: {
175 typedef FunctorArrayTools::F_clone<OutputViewType,inputViewType,0> FunctorType;
176 Kokkos::parallel_for( policy, FunctorType(output, input) );
177 break;
178 }
179 case 1: {
180 typedef FunctorArrayTools::F_clone<OutputViewType,inputViewType,1> FunctorType;
181 Kokkos::parallel_for( policy, FunctorType(output, input) );
182 break;
183 }
184 case 2: {
185 typedef FunctorArrayTools::F_clone<OutputViewType,inputViewType,2> FunctorType;
186 Kokkos::parallel_for( policy, FunctorType(output, input) );
187 break;
188 }
189 }
190 }
191
192} // end namespace Intrepid2
193
194#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.