diff --git a/packages/panzer/adapters-stk/src/stk_interface/Panzer_STK_Interface.hpp b/packages/panzer/adapters-stk/src/stk_interface/Panzer_STK_Interface.hpp index 2187bb864e17..44d148912f27 100644 --- a/packages/panzer/adapters-stk/src/stk_interface/Panzer_STK_Interface.hpp +++ b/packages/panzer/adapters-stk/src/stk_interface/Panzer_STK_Interface.hpp @@ -1213,7 +1213,7 @@ void STK_Interface::setCellFieldData(const std::string & fieldName,const std::st double * solnData = stk::mesh::field_data(*field,element); TEUCHOS_ASSERT(solnData!=0); // only needed if blockId is not specified - solnData[0] = scaleValue*solutionValues(cell,0); + solnData[0] = scaleValue*solutionValues.access(cell,0); } } diff --git a/packages/phalanx/src/Phalanx_Field.hpp b/packages/phalanx/src/Phalanx_Field.hpp index 24ea3bd9db6c..d2f9263a050c 100644 --- a/packages/phalanx/src/Phalanx_Field.hpp +++ b/packages/phalanx/src/Phalanx_Field.hpp @@ -133,6 +133,11 @@ namespace PHX { typename PHX::FieldReturnType::return_type operator()(const index_pack&...) const; + template + KOKKOS_INLINE_FUNCTION + typename PHX::FieldReturnType::return_type + access(const index_pack&...) const; + KOKKOS_INLINE_FUNCTION size_type rank() const; diff --git a/packages/phalanx/src/Phalanx_Field_Def.hpp b/packages/phalanx/src/Phalanx_Field_Def.hpp index 4a6d19f95631..25caea4732d3 100644 --- a/packages/phalanx/src/Phalanx_Field_Def.hpp +++ b/packages/phalanx/src/Phalanx_Field_Def.hpp @@ -173,6 +173,21 @@ PHX::Field::operator()(const index_pack&... indices) const return m_field_data(indices...); } +// ********************************************************************** +template +template +KOKKOS_INLINE_FUNCTION +typename PHX::FieldReturnType::array_type>::return_type +PHX::Field::access(const index_pack&... indices) const +{ +#if defined( PHX_DEBUG) && !defined (__CUDA_ARCH__ ) + static_assert(Rank == sizeof...(indices), "PHX::Field::operator(const index_pack&... indices) : must have number of indices equal to rank!"); + TEUCHOS_TEST_FOR_EXCEPTION(!m_data_set, std::logic_error, m_field_data_error_msg); +#endif + + return m_field_data.access(indices...); +} + // ********************************************************************** template KOKKOS_INLINE_FUNCTION diff --git a/packages/phalanx/src/Phalanx_MDField.hpp b/packages/phalanx/src/Phalanx_MDField.hpp index 1e73934ad46a..838ae7625775 100644 --- a/packages/phalanx/src/Phalanx_MDField.hpp +++ b/packages/phalanx/src/Phalanx_MDField.hpp @@ -349,6 +349,17 @@ namespace PHX { return m_view(indices...); } + template + KOKKOS_FORCEINLINE_FUNCTION + typename PHX::MDFieldReturnType::return_type + access(const index_pack&... indices) const + { +#if defined( PHX_DEBUG) && !defined (__CUDA_ARCH__ ) + TEUCHOS_TEST_FOR_EXCEPTION(!m_data_set, std::logic_error, fieldDataErrorMsg()); +#endif + return m_view.access(indices...); + } + template KOKKOS_FORCEINLINE_FUNCTION typename PHX::MDFieldReturnType::return_type diff --git a/packages/phalanx/test/Field/Field.cpp b/packages/phalanx/test/Field/Field.cpp index b6ef156b54ab..7b12975bb8fa 100644 --- a/packages/phalanx/test/Field/Field.cpp +++ b/packages/phalanx/test/Field/Field.cpp @@ -295,6 +295,30 @@ TEUCHOS_UNIT_TEST(field, all) cout << "passed!" << endl; + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // Check the access() function + for (size_type i=0; i < f7.extent(0); ++i) { + f1(i) = cf1.access(i); + for (size_type j=0; j < f7.extent(1); ++j) { + f2(i,j) = cf2.access(i,j); + for (size_type k=0; k < f7.extent(2); ++k) { + f3(i,j,k) = cf3.access(i,j,k); + for (size_type l=0; l < f7.extent(3); ++l) { + f4(i,j,k,l) = cf4.access(i,j,k,l); + for (size_type m=0; m < f7.extent(4); ++m) { + f5(i,j,k,l,m) = cf5.access(i,j,k,l,m); + for (size_type n=0; n < f7.extent(5); ++n) { + f6(i,j,k,l,m,n) = cf6.access(i,j,k,l,m,n); + for (size_type o=0; o < f7.extent(6); ++o) { + f7(i,j,k,l,m,n,o) = cf7.access(i,j,k,l,m,n,o); + } + } + } + } + } + } + } + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // check for const mdfield assignment from non-const factory // PHX::any. the field manager always stores the non-const diff --git a/packages/phalanx/test/Field/MDField_Compiletime.cpp b/packages/phalanx/test/Field/MDField_Compiletime.cpp index fa66471e53cf..e4966e1115ca 100644 --- a/packages/phalanx/test/Field/MDField_Compiletime.cpp +++ b/packages/phalanx/test/Field/MDField_Compiletime.cpp @@ -375,6 +375,30 @@ TEUCHOS_UNIT_TEST(mdfield, CompileTimeChecked) cout << "passed!" << endl; + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // Check the access() function + for (size_type i=0; i < f7.dimension(0); ++i) { + f1(i) = cf1.access(i); + for (size_type j=0; j < f7.dimension(1); ++j) { + f2(i,j) = cf2.access(i,j); + for (size_type k=0; k < f7.dimension(2); ++k) { + f3(i,j,k) = cf3.access(i,j,k); + for (size_type l=0; l < f7.dimension(3); ++l) { + f4(i,j,k,l) = cf4.access(i,j,k,l); + for (size_type m=0; m < f7.dimension(4); ++m) { + f5(i,j,k,l,m) = cf5.access(i,j,k,l,m); + for (size_type n=0; n < f7.dimension(5); ++n) { + f6(i,j,k,l,m,n) = cf6.access(i,j,k,l,m,n); + for (size_type o=0; o < f7.dimension(6); ++o) { + f7(i,j,k,l,m,n,o) = cf7.access(i,j,k,l,m,n,o); + } + } + } + } + } + } + } + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // check for const mdfield assignment from non-const factory // PHX::any. the field manager always stores the non-const diff --git a/packages/phalanx/test/Field/MDField_Runtime.cpp b/packages/phalanx/test/Field/MDField_Runtime.cpp index 7e4b2324f843..68d9a209dd8d 100644 --- a/packages/phalanx/test/Field/MDField_Runtime.cpp +++ b/packages/phalanx/test/Field/MDField_Runtime.cpp @@ -398,6 +398,30 @@ TEUCHOS_UNIT_TEST(mdfield, RuntimeTimeChecked) } } + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // Check the access() function + for (size_type i=0; i < f7.dimension(0); ++i) { + f1(i) = cf1.access(i); + for (size_type j=0; j < f7.dimension(1); ++j) { + f2(i,j) = cf2.access(i,j); + for (size_type k=0; k < f7.dimension(2); ++k) { + f3(i,j,k) = cf3.access(i,j,k); + for (size_type l=0; l < f7.dimension(3); ++l) { + f4(i,j,k,l) = cf4.access(i,j,k,l); + for (size_type m=0; m < f7.dimension(4); ++m) { + f5(i,j,k,l,m) = cf5.access(i,j,k,l,m); + for (size_type n=0; n < f7.dimension(5); ++n) { + f6(i,j,k,l,m,n) = cf6.access(i,j,k,l,m,n); + for (size_type o=0; o < f7.dimension(6); ++o) { + f7(i,j,k,l,m,n,o) = cf7.access(i,j,k,l,m,n,o); + } + } + } + } + } + } + } + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // check for const mdfield assignment from non-const factory // PHX::any. the field manager always sotres the non-const