17 template <
typename ExecSpace>
19 static const bool value =
false;
22 #ifdef KOKKOS_ENABLE_CUDA
25 static const bool value =
true;
29 template <
typename scalar>
32 const size_t n2,
const size_t n3,
const int fad_size,
33 const size_t i0,
const size_t i1,
34 const size_t i2,
const size_t i3,
37 const scalar x0 = 10.0 + scalar(n0) / scalar(i0+1);
38 const scalar x1 = 100.0 + scalar(n1) / scalar(i1+1);
39 const scalar x2 = 1000.0 + scalar(n2) / scalar(i2+1);
40 const scalar x3 = 10000.0 + scalar(n3) / scalar(i3+1);
41 const scalar
x = x0 + x1 + x2 + x3;
42 if (i_fad == fad_size)
44 const scalar x_fad = 1.0 + scalar(fad_size) / scalar(i_fad+1);
48 template <
typename V1,
typename V2,
typename V3,
typename V4,
typename V5>
49 void init_fad(
const V1& v1,
const V2& v2,
const V3& v3,
const V4& v4,
52 typedef typename V1::non_const_value_type::value_type scalar;
54 const int ncells = v1.extent(0);
55 const int num_basis = v1.extent(1);
56 const int num_points = v1.extent(2);
57 const int ndim = v1.extent(3);
58 const int N = Kokkos::dimension_scalar(v1)-1;
65 auto v1_h = Kokkos::create_mirror_view(v1);
66 auto v2_h = Kokkos::create_mirror_view(v2);
67 auto v3_h = Kokkos::create_mirror_view(v3);
68 auto v4_h = Kokkos::create_mirror_view(v4);
69 for (
int cell=0; cell<ncells; ++cell) {
70 for (
int basis=0; basis<num_basis; ++basis) {
71 for (
int qp=0; qp<num_points; ++qp) {
72 for (
int dim=0; dim<ndim; ++dim) {
73 for (
int i=0;
i<
N; ++
i)
74 v1_h(cell,basis,qp,dim).fastAccessDx(
i) =
75 generate_fad<scalar>(ncells,num_basis,num_points,ndim,
N,cell,basis,qp,dim,
i);
76 v1_h(cell,basis,qp,dim).val() =
77 generate_fad<scalar>(ncells,num_basis,num_points,ndim,
N,cell,basis,qp,dim,
N);
79 for (
int i=0;
i<
N; ++
i)
80 v2_h(cell,basis,qp).fastAccessDx(
i) =
81 generate_fad<scalar>(ncells,num_basis,num_points,1,
N,cell,basis,qp,0,
i);
82 v2_h(cell,basis,qp).val() =
83 generate_fad<scalar>(ncells,num_basis,num_points,1,
N,cell,basis,qp,0,
N);
86 for (
int qp=0; qp<num_points; ++qp) {
87 for (
int dim=0; dim<ndim; ++dim) {
88 for (
int i=0;
i<
N; ++
i)
89 v3_h(cell,qp,dim).fastAccessDx(
i) =
90 generate_fad<scalar>(ncells,1,num_points,ndim,
N,cell,0,qp,dim,
i);
91 v3_h(cell,qp,dim).val() =
92 generate_fad<scalar>(ncells,1,num_points,ndim,
N,cell,0,qp,dim,
N);
94 for (
int i=0;
i<
N; ++
i)
95 v4_h(cell,qp).fastAccessDx(
i) =
96 generate_fad<scalar>(ncells,1,num_points,1,
N,cell,0,qp,0,
i);
98 generate_fad<scalar>(ncells,1,num_points,1,
N,cell,0,qp,0,
N);
102 Kokkos::deep_copy( v1, v1_h );
103 Kokkos::deep_copy( v2, v2_h );
104 Kokkos::deep_copy( v3, v3_h );
105 Kokkos::deep_copy( v4, v4_h );
107 Kokkos::deep_copy(
typename V5::array_type(v5), 0.0);
110 template <
typename V1,
typename V2,
typename V3,
typename V4,
typename V5>
111 void init_array(
const V1& v1,
const V2& v2,
const V3& v3,
const V4& v4,
114 typedef typename V1::non_const_value_type scalar;
116 const int ncells = v1.extent(0);
117 const int num_basis = v1.extent(1);
118 const int num_points = v1.extent(2);
119 const int ndim = v1.extent(3);
120 const int N = v1.extent(4)-1;
127 auto v1_h = Kokkos::create_mirror_view(v1);
128 auto v2_h = Kokkos::create_mirror_view(v2);
129 auto v3_h = Kokkos::create_mirror_view(v3);
130 auto v4_h = Kokkos::create_mirror_view(v4);
131 for (
int cell=0; cell<ncells; ++cell) {
132 for (
int basis=0; basis<num_basis; ++basis) {
133 for (
int qp=0; qp<num_points; ++qp) {
134 for (
int dim=0; dim<ndim; ++dim) {
135 for (
int i=0;
i<
N; ++
i)
136 v1_h(cell,basis,qp,dim,
i) =
137 generate_fad<scalar>(ncells,num_basis,num_points,ndim,
N,cell,basis,qp,dim,
i);
138 v1_h(cell,basis,qp,dim,N) =
139 generate_fad<scalar>(ncells,num_basis,num_points,ndim,
N,cell,basis,qp,dim,
N);
141 for (
int i=0;
i<
N; ++
i)
142 v2_h(cell,basis,qp,
i) =
143 generate_fad<scalar>(ncells,num_basis,num_points,1,
N,cell,basis,qp,0,
i);
144 v2_h(cell,basis,qp,N) =
145 generate_fad<scalar>(ncells,num_basis,num_points,1,
N,cell,basis,qp,0,
N);
148 for (
int qp=0; qp<num_points; ++qp) {
149 for (
int dim=0; dim<ndim; ++dim) {
150 for (
int i=0;
i<
N; ++
i)
151 v3_h(cell,qp,dim,
i) =
152 generate_fad<scalar>(ncells,1,num_points,ndim,
N,cell,0,qp,dim,
i);
153 v3_h(cell,qp,dim,N) =
154 generate_fad<scalar>(ncells,1,num_points,ndim,
N,cell,0,qp,dim,
N);
156 for (
int i=0;
i<
N; ++
i)
158 generate_fad<scalar>(ncells,1,num_points,1,
N,cell,0,qp,0,
i);
160 generate_fad<scalar>(ncells,1,num_points,1,
N,cell,0,qp,0,
N);
164 Kokkos::deep_copy( v1, v1_h );
165 Kokkos::deep_copy( v2, v2_h );
166 Kokkos::deep_copy( v3, v3_h );
167 Kokkos::deep_copy( v4, v4_h );
169 Kokkos::deep_copy(
typename V5::array_type(v5), 0.0);
172 template <
typename View1,
typename View2>
174 check(
const View1& v_gold,
const View2& v,
const double tol)
177 typename View1::HostMirror v_gold_h = Kokkos::create_mirror_view(v_gold);
178 typename View2::HostMirror v_h = Kokkos::create_mirror_view(v);
179 Kokkos::deep_copy(v_gold_h, v_gold);
180 Kokkos::deep_copy(v_h, v);
182 typedef typename View1::value_type value_type;
184 const size_t n0 = v_gold_h.extent(0);
185 const size_t n1 = v_gold_h.extent(1);
186 const size_t n2 = v_gold_h.extent(2);
189 for (
size_t i0 = 0 ; i0 < n0 ; ++i0 ) {
190 for (
size_t i1 = 0 ; i1 < n1 ; ++i1 ) {
191 for (
size_t i2 = 0 ; i2 < n2 ; ++i2 ) {
192 value_type x_gold = v_gold_h(i0,i1,i2);
193 value_type
x = v_h(i0,i1,i2);
195 std::cout <<
"Comparison failed! x_gold("
196 << i0 <<
"," << i1 <<
"," << i2 <<
") = "
197 << x_gold <<
" , x = " << x
208 template <
typename View1,
typename View2>
210 check(
const View1& v_gold,
const View2& v,
const double tol)
213 typename View1::HostMirror v_gold_h = Kokkos::create_mirror_view(v_gold);
214 typename View2::HostMirror v_h = Kokkos::create_mirror_view(v);
215 Kokkos::deep_copy(v_gold_h, v_gold);
216 Kokkos::deep_copy(v_h, v);
218 typedef typename View1::value_type value_type;
220 const size_t n0 = v_gold_h.extent(0);
221 const size_t n1 = v_gold_h.extent(1);
222 const size_t n2 = v_gold_h.extent(2);
225 for (
size_t i0 = 0 ; i0 < n0 ; ++i0 ) {
226 for (
size_t i1 = 0 ; i1 < n1 ; ++i1 ) {
227 for (
size_t i2 = 0 ; i2 < n2 ; ++i2 ) {
228 value_type x_gold = v_gold_h(i0,i1,i2);
229 value_type
x = (i2 == n2-1) ? v_h(i0,i1).val() : v_h(i0,i1).dx(i2);
231 std::cout <<
"Comparison failed! x_gold("
232 << i0 <<
"," << i1 <<
"," << i2 <<
") = "
233 << x_gold <<
" , x = " << x
244 template<
typename FluxView,
typename WgbView,
typename SrcView,
246 Kokkos::View<double***,typename FluxView::execution_space>
248 const FluxView& flux,
const WgbView& wgb,
const SrcView& src,
252 typedef typename FluxView::execution_space execution_space;
254 const size_t num_cells = wgb.extent(0);
255 const int num_basis = wgb.extent(1);
256 const int num_points = wgb.extent(2);
257 const int num_dim = wgb.extent(3);
258 const int N = Kokkos::dimension_scalar(wgb)-1;
260 Kokkos::View<double***,typename FluxView::execution_space> residual(
261 "",num_cells,num_basis,N+1);
263 Kokkos::parallel_for(Kokkos::RangePolicy<execution_space>( 0,num_cells ),
264 KOKKOS_LAMBDA (
const size_t cell)
266 double value, value2;
269 for (
int basis=0; basis<num_basis; ++basis) {
270 value = value2 = 0.0;
271 for (
int qp=0; qp<num_points; ++qp) {
272 for (
int dim=0; dim<num_dim; ++dim)
273 value += flux(cell,qp,dim).
val()*wgb(cell,basis,qp,dim).
val();
274 value2 += src(cell,qp).val()*wbs(cell,basis,qp).val();
276 residual(cell,basis,N) = value+value2;
280 for (
int k=0; k<
N; ++k) {
281 for (
int basis=0; basis<num_basis; ++basis) {
282 value = value2 = 0.0;
283 for (
int qp=0; qp<num_points; ++qp) {
284 for (
int dim=0; dim<num_dim; ++dim)
286 flux(cell,qp,dim).val()*wgb(cell,basis,qp,dim).dx(k) +
287 flux(cell,qp,dim).dx(k)*wgb(cell,basis,qp,dim).val();
289 src(cell,qp).val()*wbs(cell,basis,qp).dx(k) +
290 src(cell,qp).dx(k)*wbs(cell,basis,qp).val();
292 residual(cell,basis,k) = value+value2;
300 template<
typename FluxView,
typename WgbView,
typename SrcView,
302 Kokkos::View<double***,typename FluxView::execution_space>
304 const FluxView& flux,
const WgbView& wgb,
const SrcView& src,
308 typedef typename FluxView::execution_space execution_space;
310 const size_t num_cells = wgb.extent(0);
311 const int num_basis = wgb.extent(1);
312 const int num_points = wgb.extent(2);
313 const int num_dim = wgb.extent(3);
314 const int N = wgb.extent(4)-1;
316 Kokkos::View<double***,typename FluxView::execution_space> residual(
317 "",num_cells,num_basis,N+1);
319 Kokkos::parallel_for(Kokkos::RangePolicy<execution_space>( 0,num_cells ),
320 KOKKOS_LAMBDA (
const size_t cell)
322 double value, value2;
325 for (
int basis=0; basis<num_basis; ++basis) {
326 value = value2 = 0.0;
327 for (
int qp=0; qp<num_points; ++qp) {
328 for (
int dim=0; dim<num_dim; ++dim)
329 value += flux(cell,qp,dim,N)*wgb(cell,basis,qp,dim,N);
330 value2 += src(cell,qp,N)*wbs(cell,basis,qp,N);
332 residual(cell,basis,N) = value+value2;
336 for (
int k=0; k<
N; ++k) {
337 for (
int basis=0; basis<num_basis; ++basis) {
338 value = value2 = 0.0;
339 for (
int qp=0; qp<num_points; ++qp) {
340 for (
int dim=0; dim<num_dim; ++dim)
342 flux(cell,qp,dim,N)*wgb(cell,basis,qp,dim,k) +
343 flux(cell,qp,dim,k)*wgb(cell,basis,qp,dim,N);
345 src(cell,qp,N)*wbs(cell,basis,qp,k) +
346 src(cell,qp,k)*wbs(cell,basis,qp,N);
348 residual(cell,basis,k) = value+value2;
356 template<
typename FluxView,
typename WgbView,
typename SrcView,
357 typename WbsView,
typename ResidualView>
359 const SrcView& src,
const WbsView& wbs,
360 const ResidualView& residual)
366 const double tol = 1.0e-14;
367 check(residual_gold, residual, tol);
std::enable_if< !Kokkos::is_view_fad< View2 >::value, bool >::type check(const View1 &v_gold, const View2 &v, const double tol)
scalar generate_fad(const size_t n0, const size_t n1, const size_t n2, const size_t n3, const int fad_size, const size_t i0, const size_t i1, const size_t i2, const size_t i3, const int i_fad)
Sacado::Fad::SFad< double, fad_dim > SFadType
Kokkos::View< double ***, typename FluxView::execution_space > compute_gold_residual(const FluxView &flux, const WgbView &wgb, const SrcView &src, const WbsView &wbs, typename std::enable_if< Kokkos::is_view_fad< FluxView >::value >::type *=0)
void init_array(const V1 &v1, const V2 &v2, const V3 &v3, const V4 &v4, const V5 &v5)
void init_fad(const V1 &v1, const V2 &v2, const V3 &v3, const V4 &v4, const V5 &v5)
Sacado::Fad::SLFad< double, fad_dim > SLFadType
Sacado::Fad::DFad< double > DFadType
void check_residual(const FluxView &flux, const WgbView &wgb, const SrcView &src, const WbsView &wbs, const ResidualView &residual)