1 #ifndef _COMPADRE_UTILITIES_HPP_
2 #define _COMPADRE_UTILITIES_HPP_
4 #include "Compadre_Config.h"
11 Kokkos::single(Kokkos::PerThread(teamMember), [&] () {
12 auto num_nodes = cell_coordinates.extent(1)/dim;
13 for (
int j=0; j<dim; ++j) {
14 midpoint_storage(j) = 0;
15 for (
size_t i=0; i<num_nodes; ++i) {
16 midpoint_storage(j) += cell_coordinates(cell_num, i*dim + j) / (double)(num_nodes);
22 template <
typename view_type_1,
typename view_type_2>
23 KOKKOS_INLINE_FUNCTION
25 if (v1.extent(0)==3) {
27 double val = v1[1]*v2[2] - v1[2]*v2[1];
29 val = v1[2]*v2[0] - v1[0]*v2[2];
31 val = v1[0]*v2[1] - v1[1]*v2[0];
33 return std::sqrt(area);
34 }
else if (v1.extent(0)==2) {
36 double val = v1[0]*v2[1] - v1[1]*v2[0];
38 return std::sqrt(area);
45 template <
typename output_memory_space,
typename view_type_input_data,
typename output_array_layout =
typename view_type_input_data::array_layout,
typename index_type=
int>
46 Kokkos::View<int*, output_array_layout, output_memory_space>
47 filterViewByID(view_type_input_data input_data_host_or_device, index_type filtered_value) {
50 auto input_data_host = Kokkos::create_mirror_view(input_data_host_or_device);
51 Kokkos::deep_copy(input_data_host, input_data_host_or_device);
56 auto this_filtered_value = filtered_value;
60 for (
size_t i=0; i<input_data_host.extent(0); i++) {
61 if (input_data_host(i) == this_filtered_value) {
68 Kokkos::View<int*, output_array_layout, output_memory_space> filtered_view(
"filterd view", num_count);
70 int filtered_index = 0;
71 for (
size_t i=0; i<input_data_host.extent(0); i++) {
72 if (input_data_host(i) == this_filtered_value) {
73 filtered_view(filtered_index) = i;
80 typedef Kokkos::View<int*, output_array_layout, output_memory_space> output_view_type;
81 output_view_type filtered_view_output(
"output filtered view", num_count);
82 Kokkos::deep_copy(filtered_view_output, filtered_view);
85 return filtered_view_output;
90 template <
typename output_memory_space,
typename view_type_input_data,
typename view_type_index_data,
92 ||std::is_same<typename view_type_input_data::data_type, int**>::value,
int> = 0>
93 static Kokkos::View<typename view_type_input_data::data_type, typename view_type_input_data::array_layout, output_memory_space>
94 extractViewByIndex(view_type_input_data input_data_host_or_device, view_type_index_data index_data_host_or_device) {
96 typedef typename view_type_input_data::data_type output_data_type;
97 typedef typename view_type_input_data::array_layout output_array_layout;
100 auto input_data_host = Kokkos::create_mirror_view(input_data_host_or_device);
101 Kokkos::deep_copy(input_data_host, input_data_host_or_device);
105 auto index_data_host = Kokkos::create_mirror_view(index_data_host_or_device);
106 Kokkos::deep_copy(index_data_host, index_data_host_or_device);
110 Kokkos::View<output_data_type, output_array_layout, output_memory_space> extracted_view(
"extracted view",
111 index_data_host.extent(0), input_data_host.extent(1));
114 for (
size_t i=0; i<index_data_host.extent(0); i++) {
115 for (
size_t j=0; j<input_data_host.extent(1); j++) {
116 extracted_view(i, j) = input_data_host(index_data_host(i), j);
121 typedef Kokkos::View<output_data_type, output_array_layout, output_memory_space> output_view_type;
122 output_view_type extracted_view_output(
"output extracted view", extracted_view.extent(0), extracted_view.extent(1));
123 Kokkos::deep_copy(extracted_view_output, extracted_view);
126 return extracted_view_output;
129 template <
typename output_memory_space,
typename view_type_input_data,
typename view_type_index_data,
131 ||std::is_same<typename view_type_input_data::data_type, int*>::value,
int> = 0>
132 static Kokkos::View<double*, typename view_type_input_data::array_layout, output_memory_space>
133 extractViewByIndex(view_type_input_data input_data_host_or_device, view_type_index_data index_data_host_or_device) {
135 typedef typename view_type_input_data::data_type output_data_type;
136 typedef typename view_type_input_data::array_layout output_array_layout;
139 auto input_data_host = Kokkos::create_mirror_view(input_data_host_or_device);
140 Kokkos::deep_copy(input_data_host, input_data_host_or_device);
144 auto index_data_host = Kokkos::create_mirror_view(index_data_host_or_device);
145 Kokkos::deep_copy(index_data_host, index_data_host_or_device);
149 Kokkos::View<output_data_type, output_array_layout, output_memory_space> extracted_view(
"extracted view",
150 index_data_host.extent(0));
153 for (
size_t i=0; i<index_data_host.extent(0); i++) {
154 extracted_view(i) = input_data_host(index_data_host(i));
158 typedef Kokkos::View<output_data_type, output_array_layout, output_memory_space> output_view_type;
159 output_view_type extracted_view_output(
"output extracted view", extracted_view.extent(0));
160 Kokkos::deep_copy(extracted_view_output, extracted_view);
163 return extracted_view_output;
KOKKOS_INLINE_FUNCTION void getMidpointFromCellVertices(const member_type &teamMember, scratch_vector_type midpoint_storage, scratch_matrix_right_type cell_coordinates, const int cell_num, const int dim=3)
team_policy::member_type member_type
KOKKOS_INLINE_FUNCTION double getAreaFromVectors(const member_type &teamMember, view_type_1 v1, view_type_2 v2)
Kokkos::View< int *, output_array_layout, output_memory_space > filterViewByID(view_type_input_data input_data_host_or_device, index_type filtered_value)
typename std::enable_if< B, T >::type enable_if_t
Kokkos::View< double **, layout_right, Kokkos::MemoryTraits< Kokkos::Unmanaged > > scratch_matrix_right_type
Kokkos::View< double *, Kokkos::MemoryTraits< Kokkos::Unmanaged > > scratch_vector_type
#define compadre_kernel_assert_debug(condition)