17 #ifndef KOKKOS_EXAMPLE_FENLFUNCTORS_HPP
18 #define KOKKOS_EXAMPLE_FENLFUNCTORS_HPP
29 #include <Kokkos_Pair.hpp>
30 #include <Kokkos_UnorderedMap.hpp>
32 #include <Kokkos_Timer.hpp>
53 Dim3(
const size_t x_,
const size_t y_ = 1,
const size_t z_ = 1) :
54 x(x_),
y(y_),
z(z_) {}
62 const size_t threads_per_block_x_ = 0,
63 const size_t threads_per_block_y_ = 0,
64 const size_t threads_per_block_z_ = 1) :
65 block_dim(threads_per_block_x_,threads_per_block_y_,threads_per_block_z_),
71 template<
typename ValueType ,
class Space >
73 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE // Don't remove this until Kokkos has removed the deprecated code path probably around September 2018
74 typedef Kokkos::StaticCrsGraph< unsigned , Space , void , unsigned >
StaticCrsGraphType ;
87 ,
values(
"crs_matrix_values" , arg_graph.entries.extent(0) )
93 template <
typename ViewType,
typename Enabled =
void>
103 KOKKOS_INLINE_FUNCTION
105 const unsigned local_rank)
109 #if defined( KOKKOS_ENABLE_CUDA )
111 template <
typename ViewType>
112 struct LocalViewTraits<
114 typename std::enable_if< std::is_same<typename ViewType::execution_space,
115 Kokkos::Cuda>::value &&
116 Kokkos::is_view_mp_vector<ViewType>::value
123 KOKKOS_INLINE_FUNCTION
125 const unsigned local_rank)
127 return Kokkos::partition<1>(v, local_rank);
134 template <
typename ScalarType>
144 template <
typename StorageType>
149 static const unsigned VectorSize = StorageType::static_size;
150 #if defined( KOKKOS_ENABLE_CUDA )
151 enum { is_cuda = std::is_same< execution_space, Kokkos::Cuda >::value };
153 enum { is_cuda =
false };
166 template<
class ElemNodeIdView ,
class CrsGraphType ,
unsigned ElemNode >
173 typedef Kokkos::UnorderedMap< key_type, void , execution_space >
SetType ;
174 typedef typename CrsGraphType::row_map_type::non_const_type
RowMapType ;
178 typedef Kokkos::View< unsigned*[ElemNode][ElemNode] , execution_space >
213 const unsigned arg_node_count,
229 Kokkos::Timer wall_clock ;
235 size_t set_capacity = (((28ull *
node_count) / 2ull)*4ull)/3ull;
267 unsigned graph_entry_count = 0 ;
273 graph.entries =
typename CrsGraphType::entries_type(
"graph_entries" , graph_entry_count );
319 KOKKOS_INLINE_FUNCTION
323 for (
unsigned row_local_node = 0 ; row_local_node <
elem_node_id.extent(1) ; ++row_local_node ) {
325 const unsigned row_node =
elem_node_id( ielem , row_local_node );
327 for (
unsigned col_local_node = row_local_node ; col_local_node <
elem_node_id.extent(1) ; ++col_local_node ) {
329 const unsigned col_node =
elem_node_id( ielem , col_local_node );
335 const key_type key = (row_node < col_node) ? make_pair( row_node, col_node ) : make_pair( col_node, row_node ) ;
337 const typename SetType::insert_result result =
node_node_set.insert( key );
339 if ( result.success() ) {
348 KOKKOS_INLINE_FUNCTION
353 const unsigned row_node = key.first ;
354 const unsigned col_node = key.second ;
358 graph.entries( offset ) = col_node ;
361 if ( col_node <
row_count.extent(0) && col_node != row_node ) {
363 graph.entries( offset ) = row_node ;
368 KOKKOS_INLINE_FUNCTION
371 typedef typename CrsGraphType::size_type size_type;
372 const size_type row_beg =
graph.row_map( irow );
373 const size_type row_end =
graph.row_map( irow + 1 );
374 for ( size_type i = row_beg + 1 ; i < row_end ; ++i ) {
375 const typename CrsGraphType::data_type col =
graph.entries(i);
377 for ( ; row_beg < j && col <
graph.entries(j-1) ; --
j ) {
380 graph.entries(j) = col ;
384 KOKKOS_INLINE_FUNCTION
387 typedef typename CrsGraphType::data_type entry_type;
388 for (
unsigned row_local_node = 0 ; row_local_node <
elem_node_id.extent(1) ; ++row_local_node ) {
390 const unsigned row_node =
elem_node_id( ielem , row_local_node );
392 for (
unsigned col_local_node = 0 ; col_local_node <
elem_node_id.extent(1) ; ++col_local_node ) {
394 const unsigned col_node =
elem_node_id( ielem , col_local_node );
396 entry_type entry = 0 ;
398 if ( row_node + 1 <
graph.row_map.extent(0) ) {
400 const entry_type entry_end =
static_cast<entry_type
> (
graph.row_map( row_node + 1 ));
402 entry =
graph.row_map( row_node );
404 for ( ; entry < entry_end &&
graph.entries(entry) !=
static_cast<entry_type
> (col_node) ; ++entry );
406 if ( entry == entry_end ) entry = ~0u ;
409 elem_graph( ielem , row_local_node , col_local_node ) = entry ;
414 KOKKOS_INLINE_FUNCTION
436 KOKKOS_INLINE_FUNCTION
452 KOKKOS_INLINE_FUNCTION
455 KOKKOS_INLINE_FUNCTION
456 void join(
unsigned &
update ,
const unsigned & input )
const { update += input ; }
477 KOKKOS_INLINE_FUNCTION
478 double operator()(
double pt[],
unsigned ensemble_rank)
const
489 template <
typename Scalar,
typename MeshScalar,
typename Device >
494 template <
typename T1,
typename T2 = MeshScalar,
typename T3 = Device>
501 typedef typename RandomVariableView::size_type
size_type;
518 const MeshScalar mean ,
519 const MeshScalar variance ,
520 const MeshScalar correlation_length ,
529 solverParams.
set(
"Number of KL Terms",
int(num_rv));
530 solverParams.
set(
"Mean", mean);
531 solverParams.
set(
"Standard Deviation",
std::sqrt(variance));
534 correlation_lengths(ndim, correlation_length);
535 solverParams.
set(
"Domain Upper Bounds", domain_upper);
536 solverParams.
set(
"Domain Lower Bounds", domain_lower);
537 solverParams.
set(
"Correlation Lengths", correlation_lengths);
550 KOKKOS_INLINE_FUNCTION
553 KOKKOS_INLINE_FUNCTION
556 KOKKOS_INLINE_FUNCTION
570 class CoordinateMap ,
typename ScalarType >
585 typedef Kokkos::View< scalar_type* , Kokkos::LayoutLeft, execution_space >
vector_type ;
599 typedef Kokkos::View< scalar_type*[FunctionCount][FunctionCount] , execution_space >
elem_matrices_type ;
650 KOKKOS_INLINE_FUNCTION
658 double dpsidz[] )
const
660 enum { j11 = 0 , j12 = 1 , j13 = 2 ,
661 j21 = 3 , j22 = 4 , j23 = 5 ,
662 j31 = 6 , j32 = 7 , j33 = 8 };
666 double J[
TensorDim ] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
669 const double x1 = x[i] ;
670 const double x2 = y[i] ;
671 const double x3 = z[i] ;
673 const double g1 = grad[0][i] ;
674 const double g2 = grad[1][i] ;
675 const double g3 = grad[2][i] ;
693 static_cast<double>( J[j22] * J[j33] - J[j23] * J[j32] ) ,
694 static_cast<double>( J[j13] * J[j32] - J[j12] * J[j33] ) ,
695 static_cast<double>( J[j12] * J[j23] - J[j13] * J[j22] ) ,
697 static_cast<double>( J[j23] * J[j31] - J[j21] * J[j33] ) ,
698 static_cast<double>( J[j11] * J[j33] - J[j13] * J[j31] ) ,
699 static_cast<double>( J[j13] * J[j21] - J[j11] * J[j23] ) ,
701 static_cast<double>( J[j21] * J[j32] - J[j22] * J[j31] ) ,
702 static_cast<double>( J[j12] * J[j31] - J[j11] * J[j32] ) ,
703 static_cast<double>( J[j11] * J[j22] - J[j12] * J[j21] ) };
705 const double detJ = J[j11] * invJ[j11] +
709 const double detJinv = 1.0 / detJ ;
711 for (
unsigned i = 0 ; i <
TensorDim ; ++i ) { invJ[i] *= detJinv ; }
716 const double g0 = grad[0][i];
717 const double g1 = grad[1][i];
718 const double g2 = grad[2][i];
720 dpsidx[i] = g0 * invJ[j11] + g1 * invJ[j12] + g2 * invJ[j13];
721 dpsidy[i] = g0 * invJ[j21] + g1 * invJ[j22] + g2 * invJ[j23];
722 dpsidz[i] = g0 * invJ[j31] + g1 * invJ[j32] + g2 * invJ[j33];
737 template<
class FiniteElementMeshType ,
738 class SparseMatrixType ,
740 class CoeffFunctionType = ElementComputationConstantCoefficient
745 class CoordinateMap ,
typename ScalarType ,
class CoeffFunctionType >
748 CrsMatrix< ScalarType , ExecutionSpace > ,
769 coeff_function( rhs.coeff_function ) ,
770 dev_config( rhs.dev_config ) {}
774 const CoeffFunctionType & arg_coeff_function ,
780 base_type(arg_mesh, arg_solution, arg_elem_graph, arg_jacobian,
782 coeff_function( arg_coeff_function ) ,
783 dev_config( arg_dev_config ) {}
790 parallel_for( nelem , *
this );
793 KOKKOS_INLINE_FUNCTION
796 unsigned node_index[],
797 double x[],
double y[],
double z[],
819 KOKKOS_INLINE_FUNCTION
821 const unsigned node_index[],
826 const unsigned row = node_index[i] ;
827 if ( row < this->
residual.extent(0) ) {
831 const unsigned entry = this->
elem_graph( ielem , i ,
j );
832 if ( entry != ~0u ) {
840 KOKKOS_INLINE_FUNCTION
850 double coeff_src = 1.234;
851 double advection[] = { 1.1, 1.2, 1.3 };
855 double pt[] = {0.0, 0.0, 0.0};
860 if ( ! coeff_function.is_constant ) {
867 coeff_k = coeff_function(pt, 0);
874 dpsidx , dpsidy , dpsidz );
875 const double detJ_weight = detJ * integ_weight;
876 const scalar_type detJ_weight_coeff_k = detJ_weight * coeff_k;
883 value_at_pt += dof_values[m] * bases_vals[m] ;
884 gradx_at_pt += dof_values[m] * dpsidx[m] ;
885 grady_at_pt += dof_values[m] * dpsidy[m] ;
886 gradz_at_pt += dof_values[m] * dpsidz[m] ;
890 coeff_src * value_at_pt * value_at_pt ;
892 2.0 * coeff_src * value_at_pt ;
899 advection_x*gradx_at_pt +
900 advection_y*grady_at_pt +
901 advection_z*gradz_at_pt ;
905 const double bases_val_m = bases_vals[m] * detJ_weight ;
906 const double dpsidx_m = dpsidx[m] ;
907 const double dpsidy_m = dpsidy[m] ;
908 const double dpsidz_m = dpsidz[m] ;
911 detJ_weight_coeff_k * ( dpsidx_m * gradx_at_pt +
912 dpsidy_m * grady_at_pt +
913 dpsidz_m * gradz_at_pt ) +
914 bases_val_m * ( advection_term + source_term ) ;
917 const double dpsidx_n = dpsidx[
n] ;
918 const double dpsidy_n = dpsidy[
n] ;
919 const double dpsidz_n = dpsidz[
n] ;
921 detJ_weight_coeff_k * ( dpsidx_m * dpsidx_n +
922 dpsidy_m * dpsidy_n +
923 dpsidz_m * dpsidz_n ) +
924 bases_val_m * ( advection_x * dpsidx_n +
925 advection_y * dpsidy_n +
926 advection_z * dpsidz_n +
927 source_deriv * bases_vals[
n] ) ;
933 KOKKOS_INLINE_FUNCTION
946 gatherSolution(ielem, val, node_index, x, y, z, elem_res, elem_mat);
949 computeElementResidualJacobian( val, x, y, z, elem_res , elem_mat );
952 scatterResidual( ielem, node_index, elem_res, elem_mat );
957 class CoordinateMap ,
typename ScalarType ,
class CoeffFunctionType >
960 CrsMatrix< ScalarType , ExecutionSpace > ,
984 coeff_function( rhs.coeff_function ) ,
985 dev_config( rhs.dev_config ) {}
989 const CoeffFunctionType & arg_coeff_function ,
995 base_type(arg_mesh, arg_solution, arg_elem_graph,
996 arg_jacobian, arg_residual),
997 coeff_function( arg_coeff_function ) ,
998 dev_config( arg_dev_config ) {}
1005 parallel_for( nelem , *
this );
1008 KOKKOS_INLINE_FUNCTION
1011 unsigned node_index[],
1012 double x[],
double y[],
double z[],
1018 node_index[i] = ni ;
1024 val[i].val() = this->
solution( ni );
1029 KOKKOS_INLINE_FUNCTION
1031 const unsigned node_index[],
1035 const unsigned row = node_index[i] ;
1036 if ( row < this->
residual.extent(0) ) {
1040 const unsigned entry = this->
elem_graph( ielem , i ,
j );
1041 if ( entry != ~0u ) {
1043 res[i].fastAccessDx(
j) );
1050 template <
typename local_scalar_type>
1051 KOKKOS_INLINE_FUNCTION
1056 local_scalar_type elem_res[] )
const
1059 double coeff_src = 1.234;
1060 double advection[] = { 1.1, 1.2, 1.3 };
1064 double pt[] = {0.0, 0.0, 0.0};
1069 if ( ! coeff_function.is_constant ) {
1076 coeff_k = coeff_function(pt, 0);
1083 dpsidx , dpsidy , dpsidz );
1084 const double detJ_weight = detJ * integ_weight;
1085 const scalar_type detJ_weight_coeff_k = detJ_weight * coeff_k;
1087 local_scalar_type value_at_pt = 0 ;
1088 local_scalar_type gradx_at_pt = 0 ;
1089 local_scalar_type grady_at_pt = 0 ;
1090 local_scalar_type gradz_at_pt = 0 ;
1092 value_at_pt += dof_values[m] * bases_vals[m] ;
1093 gradx_at_pt += dof_values[m] * dpsidx[m] ;
1094 grady_at_pt += dof_values[m] * dpsidy[m] ;
1095 gradz_at_pt += dof_values[m] * dpsidz[m] ;
1098 const local_scalar_type source_term =
1099 coeff_src * value_at_pt * value_at_pt ;
1101 const local_scalar_type advection_term =
1102 advection[0]*gradx_at_pt +
1103 advection[1]*grady_at_pt +
1104 advection[2]*gradz_at_pt;
1107 const double bases_val_m = bases_vals[m] * detJ_weight ;
1108 const double dpsidx_m = dpsidx[m] ;
1109 const double dpsidy_m = dpsidy[m] ;
1110 const double dpsidz_m = dpsidz[m] ;
1113 detJ_weight_coeff_k * ( dpsidx_m * gradx_at_pt +
1114 dpsidy_m * grady_at_pt +
1115 dpsidz_m * gradz_at_pt ) +
1116 bases_val_m * ( advection_term + source_term ) ;
1121 KOKKOS_INLINE_FUNCTION
1133 gatherSolution( ielem, val, node_index, x, y, z, elem_res );
1136 computeElementResidual( val, x, y, z, elem_res );
1139 scatterResidual( ielem, node_index, elem_res );
1144 class CoordinateMap ,
typename ScalarType ,
class CoeffFunctionType >
1147 CrsMatrix< ScalarType , ExecutionSpace > ,
1149 public ElementComputation< Kokkos::Example::BoxElemFixture< ExecutionSpace , Order , CoordinateMap > ,
1150 CrsMatrix< ScalarType , ExecutionSpace > ,
1151 FadElement, CoeffFunctionType > {
1172 const CoeffFunctionType & arg_coeff_function ,
1178 base_type(arg_mesh, arg_coeff_function, arg_solution, arg_elem_graph,
1179 arg_jacobian, arg_residual, arg_dev_config) {}
1186 parallel_for( nelem , *
this );
1189 KOKKOS_INLINE_FUNCTION
1192 unsigned node_index[],
1193 double x[],
double y[],
double z[],
1199 node_index[i] = ni ;
1209 template <
typename local_scalar_type>
1210 KOKKOS_INLINE_FUNCTION
1215 local_scalar_type elem_res[] )
const
1218 double coeff_src = 1.234;
1219 double advection[] = { 1.1, 1.2, 1.3 };
1223 double pt[] = {0.0, 0.0, 0.0};
1228 if ( ! this->coeff_function.is_constant ) {
1235 coeff_k = this->coeff_function(pt, 0);
1242 dpsidx , dpsidy , dpsidz );
1243 const double detJ_weight = detJ * integ_weight;
1244 const scalar_type detJ_weight_coeff_k = detJ_weight * coeff_k;
1251 value_at_pt.val() += dof_values[m] * bases_vals[m] ;
1252 value_at_pt.fastAccessDx(m) = bases_vals[m] ;
1254 gradx_at_pt.val() += dof_values[m] * dpsidx[m] ;
1255 gradx_at_pt.fastAccessDx(m) = dpsidx[m] ;
1257 grady_at_pt.val() += dof_values[m] * dpsidy[m] ;
1258 grady_at_pt.fastAccessDx(m) = dpsidy[m] ;
1260 gradz_at_pt.val() += dof_values[m] * dpsidz[m] ;
1261 gradz_at_pt.fastAccessDx(m) = dpsidz[m] ;
1264 const local_scalar_type source_term =
1265 coeff_src * value_at_pt * value_at_pt ;
1267 const local_scalar_type advection_term =
1268 advection[0]*gradx_at_pt +
1269 advection[1]*grady_at_pt +
1270 advection[2]*gradz_at_pt;
1273 const double bases_val_m = bases_vals[m] * detJ_weight ;
1274 const double dpsidx_m = dpsidx[m] ;
1275 const double dpsidy_m = dpsidy[m] ;
1276 const double dpsidz_m = dpsidz[m] ;
1279 detJ_weight_coeff_k * ( dpsidx_m * gradx_at_pt +
1280 dpsidy_m * grady_at_pt +
1281 dpsidz_m * gradz_at_pt ) +
1282 bases_val_m * ( advection_term + source_term ) ;
1287 KOKKOS_INLINE_FUNCTION
1299 gatherSolution( ielem, val, node_index, x, y, z, elem_res );
1302 computeElementResidual( val, x, y, z, elem_res );
1305 this->scatterResidual( ielem, node_index, elem_res );
1310 class CoordinateMap ,
typename ScalarType ,
class CoeffFunctionType >
1313 CrsMatrix< ScalarType , ExecutionSpace > ,
1315 public ElementComputation< Kokkos::Example::BoxElemFixture< ExecutionSpace , Order , CoordinateMap > ,
1316 CrsMatrix< ScalarType , ExecutionSpace > ,
1317 Analytic , CoeffFunctionType > {
1338 const CoeffFunctionType & arg_coeff_function ,
1344 base_type(arg_mesh, arg_coeff_function, arg_solution, arg_elem_graph,
1345 arg_jacobian, arg_residual, arg_dev_config) {}
1352 parallel_for( nelem , *
this );
1355 KOKKOS_INLINE_FUNCTION
1365 double coeff_src = 1.234;
1366 double advection[] = { 1.1, 1.2, 1.3 };
1370 double pt[] = {0.0, 0.0, 0.0};
1380 if ( ! this->coeff_function.is_constant ) {
1387 coeff_k = this->coeff_function(pt, 0);
1394 dpsidx , dpsidy , dpsidz );
1395 const double detJ_weight = detJ * integ_weight;
1396 const scalar_type detJ_weight_coeff_k = detJ_weight * coeff_k;
1398 value_at_pt.val() = 0.0 ;
1399 gradx_at_pt.val() = 0.0 ;
1400 grady_at_pt.val() = 0.0 ;
1401 gradz_at_pt.val() = 0.0 ;
1403 value_at_pt.val() += dof_values[m] * bases_vals[m] ;
1404 gradx_at_pt.val() += dof_values[m] * dpsidx[m] ;
1405 grady_at_pt.val() += dof_values[m] * dpsidy[m] ;
1406 gradz_at_pt.val() += dof_values[m] * dpsidz[m] ;
1410 coeff_src * value_at_pt * value_at_pt ;
1413 advection[0]*gradx_at_pt +
1414 advection[1]*grady_at_pt +
1415 advection[2]*gradz_at_pt;
1418 const double bases_val_m = bases_vals[m] * detJ_weight ;
1420 detJ_weight_coeff_k * ( dpsidx[m] * gradx_at_pt +
1421 dpsidy[m] * grady_at_pt +
1422 dpsidz[m] * gradz_at_pt ) +
1423 bases_val_m * ( advection_term + source_term ) ;
1425 elem_res[m] += res.val();
1429 mat[
n] += res.fastAccessDx(0) * bases_vals[
n] +
1430 res.fastAccessDx(1) * dpsidx[
n] +
1431 res.fastAccessDx(2) * dpsidy[
n] +
1432 res.fastAccessDx(3) * dpsidz[
n];
1438 KOKKOS_INLINE_FUNCTION
1451 this->gatherSolution( ielem, val, node_index, x, y, z, elem_res, elem_mat );
1454 computeElementResidualJacobian( val, x, y, z, elem_res, elem_mat );
1457 this->scatterResidual( ielem, node_index, elem_res, elem_mat );
1462 template<
class FiniteElementMeshType ,
class SparseMatrixType
1463 ,
class CoeffFunctionType = ElementComputationConstantCoefficient
1465 class ElementComputation ;
1469 typename ScalarType ,
class CoeffFunctionType >
1470 class ElementComputation
1473 , CoeffFunctionType >
1488 typedef Kokkos::View< scalar_type* , Kokkos::LayoutLeft, execution_space >
vector_type ;
1492 typedef LocalViewTraits< vector_type > local_vector_view_traits;
1493 typedef LocalViewTraits< matrix_values_type> local_matrix_view_traits;
1494 typedef typename local_vector_view_traits::local_view_type local_vector_type;
1495 typedef typename local_matrix_view_traits::local_view_type local_matrix_type;
1496 typedef typename local_vector_view_traits::local_value_type local_scalar_type;
1497 static const bool use_team = local_vector_view_traits::use_team;
1509 typedef Kokkos::View< scalar_type*[FunctionCount][FunctionCount] , execution_space >
elem_matrices_type ;
1510 typedef Kokkos::View< scalar_type*[FunctionCount] , execution_space >
elem_vectors_type ;
1512 typedef LocalViewTraits< elem_matrices_type > local_elem_matrices_traits;
1513 typedef LocalViewTraits< elem_vectors_type > local_elem_vectors_traits;
1514 typedef typename local_elem_matrices_traits::local_view_type local_elem_matrices_type;
1515 typedef typename local_elem_vectors_traits::local_view_type local_elem_vectors_type;
1517 typedef typename NodeNodeGraph< elem_node_type , sparse_graph_type , ElemNodeCount >::ElemGraphType
elem_graph_type ;
1534 const CoeffFunctionType coeff_function ;
1537 ElementComputation(
const ElementComputation & rhs )
1547 , coeff_function( rhs.coeff_function )
1548 , dev_config( rhs.dev_config )
1553 ElementComputation(
const mesh_type & arg_mesh ,
1554 const CoeffFunctionType & arg_coeff_function ,
1569 , coeff_function( arg_coeff_function )
1570 , dev_config( arg_dev_config )
1579 const size_t team_size = dev_config.block_dim.x * dev_config.block_dim.y;
1580 const size_t league_size =
1581 (nelem + dev_config.block_dim.y-1) / dev_config.block_dim.y;
1582 Kokkos::TeamPolicy< execution_space > config( league_size, team_size );
1583 parallel_for( config , *
this );
1586 parallel_for( nelem , *
this );
1592 static const unsigned FLOPS_transform_gradients =
1597 KOKKOS_INLINE_FUNCTION
1605 double dpsidz[] )
const
1607 enum { j11 = 0 , j12 = 1 , j13 = 2 ,
1608 j21 = 3 , j22 = 4 , j23 = 5 ,
1609 j31 = 6 , j32 = 7 , j33 = 8 };
1613 double J[
TensorDim ] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
1616 const double x1 = x[i] ;
1617 const double x2 = y[i] ;
1618 const double x3 = z[i] ;
1620 const double g1 = grad[0][i] ;
1621 const double g2 = grad[1][i] ;
1622 const double g3 = grad[2][i] ;
1640 static_cast<double>( J[j22] * J[j33] - J[j23] * J[j32] ) ,
1641 static_cast<double>( J[j13] * J[j32] - J[j12] * J[j33] ) ,
1642 static_cast<double>( J[j12] * J[j23] - J[j13] * J[j22] ) ,
1644 static_cast<double>( J[j23] * J[j31] - J[j21] * J[j33] ) ,
1645 static_cast<double>( J[j11] * J[j33] - J[j13] * J[j31] ) ,
1646 static_cast<double>( J[j13] * J[j21] - J[j11] * J[j23] ) ,
1648 static_cast<double>( J[j21] * J[j32] - J[j22] * J[j31] ) ,
1649 static_cast<double>( J[j12] * J[j31] - J[j11] * J[j32] ) ,
1650 static_cast<double>( J[j11] * J[j22] - J[j12] * J[j21] ) };
1652 const double detJ = J[j11] * invJ[j11] +
1653 J[j21] * invJ[j12] +
1654 J[j31] * invJ[j13] ;
1656 const double detJinv = 1.0 / detJ ;
1658 for (
unsigned i = 0 ; i <
TensorDim ; ++i ) { invJ[i] *= detJinv ; }
1663 const double g0 = grad[0][i];
1664 const double g1 = grad[1][i];
1665 const double g2 = grad[2][i];
1667 dpsidx[i] = g0 * invJ[j11] + g1 * invJ[j12] + g2 * invJ[j13];
1668 dpsidy[i] = g0 * invJ[j21] + g1 * invJ[j22] + g2 * invJ[j23];
1669 dpsidz[i] = g0 * invJ[j31] + g1 * invJ[j32] + g2 * invJ[j33];
1675 KOKKOS_INLINE_FUNCTION
1676 void contributeResidualJacobian(
1677 const local_scalar_type dof_values[] ,
1678 const double dpsidx[] ,
1679 const double dpsidy[] ,
1680 const double dpsidz[] ,
1682 const local_scalar_type coeff_k ,
1683 const double integ_weight ,
1684 const double bases_vals[] ,
1685 local_scalar_type elem_res[] ,
1686 local_scalar_type elem_mat[][ FunctionCount ] )
const
1688 local_scalar_type value_at_pt = 0 ;
1689 local_scalar_type gradx_at_pt = 0 ;
1690 local_scalar_type grady_at_pt = 0 ;
1691 local_scalar_type gradz_at_pt = 0 ;
1694 value_at_pt += dof_values[m] * bases_vals[m] ;
1695 gradx_at_pt += dof_values[m] * dpsidx[m] ;
1696 grady_at_pt += dof_values[m] * dpsidy[m] ;
1697 gradz_at_pt += dof_values[m] * dpsidz[m] ;
1700 const local_scalar_type k_detJ_weight = coeff_k * detJ * integ_weight ;
1701 const local_scalar_type res_val = value_at_pt * value_at_pt * detJ * integ_weight ;
1702 const local_scalar_type mat_val = 2.0 * value_at_pt * detJ * integ_weight ;
1708 local_scalar_type *
const mat = elem_mat[m] ;
1709 const double bases_val_m = bases_vals[m];
1710 const double dpsidx_m = dpsidx[m] ;
1711 const double dpsidy_m = dpsidy[m] ;
1712 const double dpsidz_m = dpsidz[m] ;
1714 elem_res[m] += k_detJ_weight * ( dpsidx_m * gradx_at_pt +
1715 dpsidy_m * grady_at_pt +
1716 dpsidz_m * gradz_at_pt ) +
1717 res_val * bases_val_m ;
1721 mat[
n] += k_detJ_weight * ( dpsidx_m * dpsidx[
n] +
1722 dpsidy_m * dpsidy[
n] +
1723 dpsidz_m * dpsidz[
n] ) +
1724 mat_val * bases_val_m * bases_vals[n];
1729 KOKKOS_INLINE_FUNCTION
1730 void operator()(
const typename TeamPolicy< execution_space >::member_type & dev )
const
1733 const unsigned num_ensemble_threads = dev_config.block_dim.x ;
1734 const unsigned num_element_threads = dev_config.block_dim.y ;
1735 const unsigned element_rank = dev.team_rank() / num_ensemble_threads ;
1736 const unsigned ensemble_rank = dev.team_rank() % num_ensemble_threads ;
1738 const unsigned ielem =
1739 dev.league_rank() * num_element_threads + element_rank;
1744 (*this)( ielem, ensemble_rank );
1748 KOKKOS_INLINE_FUNCTION
1749 void operator()(
const unsigned ielem ,
1750 const unsigned ensemble_rank = 0 )
const
1752 local_vector_type local_solution =
1753 local_vector_view_traits::create_local_view(
solution,
1755 local_vector_type local_residual =
1756 local_vector_view_traits::create_local_view(
residual,
1758 local_matrix_type local_jacobian_values =
1773 node_index[i] = ni ;
1779 val[i] = local_solution( ni );
1789 elem_mat[i][
j] = 0 ;
1799 local_scalar_type coeff_k = 0 ;
1802 double pt[] = {0.0, 0.0, 0.0};
1806 if ( ! coeff_function.is_constant ) {
1815 coeff_k = coeff_function(pt, ensemble_rank);
1820 dpsidx , dpsidy , dpsidz );
1822 contributeResidualJacobian( val , dpsidx , dpsidy , dpsidz ,
1826 elem_vec , elem_mat );
1830 const unsigned row = node_index[i] ;
1832 atomic_add( & local_residual( row ) , elem_vec[i] );
1835 const unsigned entry =
elem_graph( ielem , i ,
j );
1836 if ( entry != ~0u ) {
1837 atomic_add( & local_jacobian_values( entry ) , elem_mat[i][
j] );
1848 template<
class FixtureType ,
class SparseMatrixType >
1852 typename ScalarType >
1877 static const bool use_team = local_vector_view_traits::use_team;
1902 const unsigned arg_bc_plane ,
1910 , bc_lower_value( arg_bc_lower_value )
1911 , bc_upper_value( arg_bc_upper_value )
1914 , bc_plane( arg_bc_plane )
1915 , node_count( arg_mesh.node_count_owned() )
1917 , dev_config( arg_dev_config )
1919 parallel_for( node_count , *
this );
1926 const size_t team_size = dev_config.block_dim.x * dev_config.block_dim.y;
1927 const size_t league_size =
1928 (node_count + dev_config.block_dim.y-1) / dev_config.block_dim.y;
1929 Kokkos::TeamPolicy< execution_space > config( league_size, team_size );
1930 parallel_for( config , *
this );
1933 parallel_for( node_count , *
this );
1938 KOKKOS_INLINE_FUNCTION
1939 void operator()(
const typename TeamPolicy< execution_space >::member_type & dev )
const
1942 const unsigned num_ensemble_threads = dev_config.block_dim.x ;
1943 const unsigned num_node_threads = dev_config.block_dim.y ;
1944 const unsigned node_rank = dev.team_rank() / num_ensemble_threads ;
1945 const unsigned ensemble_rank = dev.team_rank() % num_ensemble_threads ;
1947 const unsigned inode = dev.league_rank() * num_node_threads + node_rank;
1949 if (inode >= node_count)
1952 (*this)( inode, ensemble_rank );
1956 KOKKOS_INLINE_FUNCTION
1958 const unsigned ensemble_rank = 0)
const
1961 local_vector_view_traits::create_local_view(
residual,
1976 const bool bc_lower = c <= bc_lower_limit ;
1977 const bool bc_upper = bc_upper_limit <= c ;
1980 solution(inode) = bc_lower ? bc_lower_value : (
1981 bc_upper ? bc_upper_value : 0 );
1984 if ( bc_lower || bc_upper ) {
1986 local_residual(inode) = 0 ;
1991 for(
unsigned i = iBeg ; i < iEnd ; ++i ) {
1992 local_jacobian_values(i) = int(inode) == int(
jacobian.
graph.entries(i)) ? 1 : 0 ;
2000 for(
unsigned i = iBeg ; i < iEnd ; ++i ) {
2004 if ( ( cc <= bc_lower_limit ) || ( bc_upper_limit <= cc ) ) {
2005 local_jacobian_values(i) = 0 ;
2020 #if defined( __CUDACC__ )
double weights[integration_count]
static KOKKOS_INLINE_FUNCTION local_view_type create_local_view(const view_type &v, const unsigned local_rank)
KOKKOS_INLINE_FUNCTION PCE< Storage > sqrt(const PCE< Storage > &a)
LocalViewTraits< vector_type > local_vector_view_traits
ExponentialKLCoefficient(const ExponentialKLCoefficient &rhs)
const scalar_coord_type bc_upper_limit
static const unsigned SpatialDim
Kokkos::View< scalar_type *, execution_space > vector_type
const Kokkos::Example::FENL::DeviceConfig dev_config
KOKKOS_INLINE_FUNCTION void setRandomVariables(const RandomVariableView &rv)
LocalViewTraits< matrix_values_type > local_matrix_view_traits
Sacado::Fad::SLFad< scalar_type, FunctionCount > fad_scalar_type
const unsigned node_count
KOKKOS_INLINE_FUNCTION void computeElementResidualJacobian(const scalar_type dof_values[], const double x[], const double y[], const double z[], scalar_type elem_res[], scalar_type elem_mat[][FunctionCount]) const
ElementComputation(const ElementComputation &rhs)
LocalViewTraits< RandomVariableView > local_rv_view_traits
KOKKOS_INLINE_FUNCTION Teuchos::PromotionTraits< typename rv_type::value_type, value_type >::promote evaluate(const point_type &point, const rv_type &random_variables) const
Evaluate random field at a point.
const elem_vectors_type elem_residuals
KOKKOS_INLINE_FUNCTION void fill_graph_entries(const unsigned iset) const
const vector_type solution
static const bool use_team
Kokkos::View< scalar_type *[FunctionCount], execution_space > elem_vectors_type
static const unsigned element_node_count
CrsMatrix< ScalarType, ExecutionSpace > sparse_matrix_type
const elem_matrices_type elem_jacobians
view_type::value_type local_value_type
static const unsigned function_count
KOKKOS_INLINE_FUNCTION void join(unsigned &update, const unsigned &input) const
static void eval(Kokkos::Example::FENL::DeviceConfig &dev_config_elem, Kokkos::Example::FENL::DeviceConfig &dev_config_bc)
ElementComputation(const typename base_type::mesh_type &arg_mesh, const CoeffFunctionType &arg_coeff_function, const typename base_type::vector_type &arg_solution, const typename base_type::elem_graph_type &arg_elem_graph, const typename base_type::sparse_matrix_type &arg_jacobian, const typename base_type::vector_type &arg_residual, const Kokkos::Example::FENL::DeviceConfig arg_dev_config)
base_type::execution_space execution_space
ElementComputationBase< ExecutionSpace, Order, CoordinateMap, ScalarType > base_type
Kokkos::View< const double *[SpaceDim], Device > node_coord_type
Kokkos::DefaultExecutionSpace execution_space
double gradients[integration_count][spatial_dimension][function_count]
Kokkos::View< const unsigned *[ElemNode], Device > elem_node_type
static const unsigned ElemNodeCount
Sacado::Fad::SLFad< scalar_type, 4 > fad_scalar_type
KOKKOS_INLINE_FUNCTION RandomVariableView getRandomVariables() const
static void eval(Kokkos::Example::FENL::DeviceConfig &dev_config_elem, Kokkos::Example::FENL::DeviceConfig &dev_config_bc)
const Kokkos::Example::FENL::DeviceConfig dev_config
const CoeffFunctionType coeff_function
ExecutionSpace execution_space
ElementComputation(const ElementComputation &rhs)
KOKKOS_INLINE_FUNCTION void scatterResidual(const unsigned ielem, const unsigned node_index[], fad_scalar_type res[]) const
Kokkos::View< scalar_type *, Kokkos::LayoutLeft, execution_space > vector_type
KOKKOS_INLINE_FUNCTION void atomic_add(volatile Sacado::UQ::PCE< Storage > *const dest, const Sacado::UQ::PCE< Storage > &src)
const vector_type residual
const bc_scalar_type bc_lower_value
ElementComputation(const typename base_type::mesh_type &arg_mesh, const CoeffFunctionType &arg_coeff_function, const typename base_type::vector_type &arg_solution, const typename base_type::elem_graph_type &arg_elem_graph, const typename base_type::sparse_matrix_type &arg_jacobian, const typename base_type::vector_type &arg_residual, const Kokkos::Example::FENL::DeviceConfig arg_dev_config)
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Kokkos::View< Scalar *, Kokkos::LayoutLeft, Device > RandomVariableView
const elem_node_type elem_node_ids
const vector_type residual
const unsigned node_count
KOKKOS_INLINE_FUNCTION void computeElementResidualJacobian(const scalar_type dof_values[], const double x[], const double y[], const double z[], scalar_type elem_res[], scalar_type elem_mat[][FunctionCount]) const
const bc_scalar_type bc_upper_value
base_type::scalar_type scalar_type
base_type::execution_space execution_space
KOKKOS_INLINE_FUNCTION local_scalar_type operator()(const MeshScalar point[], const size_type ensemble_rank) const
KOKKOS_INLINE_FUNCTION void operator()(const unsigned ielem) const
NodeNodeGraph< elem_node_type, sparse_graph_type, ElemNodeCount >::ElemGraphType elem_graph_type
const vector_type solution
const MeshScalar m_variance
local_rv_view_traits::local_view_type local_rv_view_type
ElementComputation< Kokkos::Example::BoxElemFixture< ExecutionSpace, Order, CoordinateMap >, CrsMatrix< ScalarType, ExecutionSpace >, Analytic, CoeffFunctionType > base_type
mesh_type::node_coord_type node_coord_type
ElemNodeIdView::execution_space execution_space
node_coord_type::value_type scalar_coord_type
static const unsigned TensorDim
KOKKOS_INLINE_FUNCTION void operator()(const unsigned irow, unsigned &update, const bool final) const
ElementComputationConstantCoefficient(const ElementComputationConstantCoefficient &rhs)
RandomVariableView::size_type size_type
KOKKOS_INLINE_FUNCTION void init(unsigned &update) const
ExecutionSpace execution_space
double sort_graph_entries
size_t num_threads_per_block
double fill_graph_entries
KOKKOS_INLINE_FUNCTION void operator()(const unsigned ielem) const
ElementComputationBase(const ElementComputationBase &rhs)
KOKKOS_INLINE_FUNCTION void fill_elem_graph_map(const unsigned ielem) const
Dim3(const size_t x_, const size_t y_=1, const size_t z_=1)
Kokkos::Example::HexElement_Data< mesh_type::ElemNode > element_data_type
CrsGraphType::row_map_type::non_const_type RowMapType
base_type::scalar_type scalar_type
const element_data_type elem_data
const MeshScalar m_corr_len
ElementComputationBase(const mesh_type &arg_mesh, const vector_type &arg_solution, const elem_graph_type &arg_elem_graph, const sparse_matrix_type &arg_jacobian, const vector_type &arg_residual)
KOKKOS_INLINE_FUNCTION void operator()(const typename TeamPolicy< execution_space >::member_type &dev) const
ElementComputation(const ElementComputation &rhs)
base_type::execution_space execution_space
CrsMatrix(const StaticCrsGraphType &arg_graph)
const sparse_matrix_type jacobian
Kokkos::StaticCrsGraph< unsigned, Space, void, void, unsigned > StaticCrsGraphType
KOKKOS_INLINE_FUNCTION double transform_gradients(const double grad[][FunctionCount], const double x[], const double y[], const double z[], double dpsidx[], double dpsidy[], double dpsidz[]) const
double values[integration_count][function_count]
mesh_type::elem_node_type elem_node_type
Kokkos::Example::FENL::CrsMatrix< ScalarType, ExecutionSpace > sparse_matrix_type
void deep_copy(const Stokhos::CrsMatrix< ValueType, DstDevice, Layout > &dst, const Stokhos::CrsMatrix< ValueType, SrcDevice, Layout > &src)
KOKKOS_INLINE_FUNCTION void operator()(const unsigned inode, const unsigned ensemble_rank=0) const
KOKKOS_INLINE_FUNCTION void operator()(const unsigned iwork) const
base_type::execution_space execution_space
KOKKOS_INLINE_FUNCTION double operator()(double pt[], unsigned ensemble_rank) const
base_type::scalar_type scalar_type
KOKKOS_INLINE_FUNCTION void gatherSolution(const unsigned ielem, scalar_type val[], unsigned node_index[], double x[], double y[], double z[], fad_scalar_type res[]) const
const CoeffFunctionType coeff_function
const scalar_coord_type bc_lower_limit
const ElemNodeIdView elem_node_id
static const unsigned integration_count
base_type::scalar_type scalar_type
Kokkos::Example::BoxElemFixture< ExecutionSpace, Order, CoordinateMap > mesh_type
mesh_type::node_coord_type node_coord_type
const elem_graph_type elem_graph
sparse_matrix_type::StaticCrsGraphType sparse_graph_type
const Kokkos::Example::FENL::DeviceConfig dev_config
Kokkos::Example::BoxElemFixture< ExecutionSpace, Order, CoordinateMap > mesh_type
const view_type & local_view_type
NodeNodeGraph(const ElemNodeIdView &arg_elem_node_id, const unsigned arg_node_count, Times &results)
const sparse_matrix_type jacobian
const node_coord_type node_coords
static const unsigned FunctionCount
KOKKOS_INLINE_FUNCTION void gatherSolution(const unsigned ielem, scalar_type val[], unsigned node_index[], double x[], double y[], double z[], scalar_type res[], scalar_type mat[][FunctionCount]) const
ElementComputation< Kokkos::Example::BoxElemFixture< ExecutionSpace, Order, CoordinateMap >, CrsMatrix< ScalarType, ExecutionSpace >, FadElement, CoeffFunctionType > base_type
sparse_matrix_type::StaticCrsGraphType sparse_graph_type
Kokkos::View< unsigned, execution_space > UnsignedValue
const node_coord_type node_coords
DeviceConfig(const size_t num_blocks_=0, const size_t threads_per_block_x_=0, const size_t threads_per_block_y_=0, const size_t threads_per_block_z_=1)
ExponentialKLCoefficient< T1, T2, T3 > type
KOKKOS_INLINE_FUNCTION void operator()(const unsigned ielem) const
ElementComputation(const typename base_type::mesh_type &arg_mesh, const CoeffFunctionType &arg_coeff_function, const typename base_type::vector_type &arg_solution, const typename base_type::elem_graph_type &arg_elem_graph, const typename base_type::sparse_matrix_type &arg_jacobian, const typename base_type::vector_type &arg_residual, const Kokkos::Example::FENL::DeviceConfig arg_dev_config)
KOKKOS_INLINE_FUNCTION void gatherSolution(const unsigned ielem, fad_scalar_type val[], unsigned node_index[], double x[], double y[], double z[], fad_scalar_type res[]) const
local_rv_view_traits::local_value_type local_scalar_type
DirichletComputation(const mesh_type &arg_mesh, const vector_type &arg_solution, const sparse_matrix_type &arg_jacobian, const vector_type &arg_residual, const unsigned arg_bc_plane, const bc_scalar_type arg_bc_lower_value, const bc_scalar_type arg_bc_upper_value, const Kokkos::Example::FENL::DeviceConfig arg_dev_config)
ElementComputationBase< ExecutionSpace, Order, CoordinateMap, ScalarType > base_type
KOKKOS_INLINE_FUNCTION PCE< Storage > sin(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION void scatterResidual(const unsigned ielem, const unsigned node_index[], const scalar_type res[], const scalar_type mat[][FunctionCount]) const
ElementComputation(const typename base_type::mesh_type &arg_mesh, const CoeffFunctionType &arg_coeff_function, const typename base_type::vector_type &arg_solution, const typename base_type::elem_graph_type &arg_elem_graph, const typename base_type::sparse_matrix_type &arg_jacobian, const typename base_type::vector_type &arg_residual, const Kokkos::Example::FENL::DeviceConfig arg_dev_config)
View< ValueType *, Space > values_type
StorageType::execution_space execution_space
local_matrix_view_traits::local_view_type local_matrix_type
KOKKOS_INLINE_FUNCTION void sort_graph_entries(const unsigned irow) const
double fill_element_graph
Kokkos::View< scalar_type *[FunctionCount][FunctionCount], execution_space > elem_matrices_type
const unsigned VectorSize
KOKKOS_INLINE_FUNCTION void fill_set(const unsigned ielem) const
ElementComputationConstantCoefficient(const double val)
Kokkos::View< unsigned *[ElemNode][ElemNode], execution_space > ElemGraphType
Sacado::Fad::SLFad< scalar_type, FunctionCount > fad_scalar_type
Generate a distributed unstructured finite element mesh from a partitioned NX*NY*NZ box of elements...
Stokhos::KL::ExponentialRandomField< MeshScalar, Device > rf_type
sparse_matrix_type::values_type matrix_values_type
ExponentialKLCoefficient(const MeshScalar mean, const MeshScalar variance, const MeshScalar correlation_length, const size_type num_rv)
KOKKOS_INLINE_FUNCTION void operator()(const unsigned ielem) const
local_vector_view_traits::local_view_type local_vector_type
KOKKOS_INLINE_FUNCTION void computeElementResidual(const local_scalar_type dof_values[], const double x[], const double y[], const double z[], local_scalar_type elem_res[]) const
ElementComputation(const ElementComputation &rhs)
void update(const ValueType &alpha, VectorType &x, const ValueType &beta, const VectorType &y)
Kokkos::UnorderedMap< key_type, void, execution_space > SetType
pair< unsigned, unsigned > key_type
KOKKOS_INLINE_FUNCTION void computeElementResidual(const scalar_type dof_values[], const double x[], const double y[], const double z[], local_scalar_type elem_res[]) const
static const unsigned IntegrationCount
static const unsigned spatial_dimension