9 #ifndef _COMPADRE_UTILITIES_HPP_
10 #define _COMPADRE_UTILITIES_HPP_
12 #include "Compadre_Config.h"
17 KOKKOS_INLINE_FUNCTION
19 Kokkos::single(Kokkos::PerThread(teamMember), [&] () {
20 auto num_nodes = cell_coordinates.extent(1)/dim;
21 for (
int j=0; j<dim; ++j) {
22 midpoint_storage(j) = 0;
23 for (
size_t i=0; i<num_nodes; ++i) {
24 midpoint_storage(j) += cell_coordinates(cell_num, i*dim + j) / (double)(num_nodes);
30 template <
typename view_type_1,
typename view_type_2>
31 KOKKOS_INLINE_FUNCTION
33 if (v1.extent(0)==3) {
35 double val = v1[1]*v2[2] - v1[2]*v2[1];
37 val = v1[2]*v2[0] - v1[0]*v2[2];
39 val = v1[0]*v2[1] - v1[1]*v2[0];
41 return std::sqrt(area);
42 }
else if (v1.extent(0)==2) {
44 double val = v1[0]*v2[1] - v1[1]*v2[0];
46 return std::sqrt(area);
53 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>
54 Kokkos::View<int*, output_array_layout, output_memory_space>
55 filterViewByID(view_type_input_data input_data_host_or_device, index_type filtered_value) {
58 auto input_data_host = Kokkos::create_mirror_view(input_data_host_or_device);
59 Kokkos::deep_copy(input_data_host, input_data_host_or_device);
64 auto this_filtered_value = filtered_value;
68 for (
size_t i=0; i<input_data_host.extent(0); i++) {
69 if (input_data_host(i) == this_filtered_value) {
76 Kokkos::View<int*, output_array_layout, output_memory_space> filtered_view(
"filterd view", num_count);
78 int filtered_index = 0;
79 for (
size_t i=0; i<input_data_host.extent(0); i++) {
80 if (input_data_host(i) == this_filtered_value) {
81 filtered_view(filtered_index) = i;
88 typedef Kokkos::View<int*, output_array_layout, output_memory_space> output_view_type;
89 output_view_type filtered_view_output(
"output filtered view", num_count);
90 Kokkos::deep_copy(filtered_view_output, filtered_view);
93 return filtered_view_output;
98 template <
typename output_memory_space,
typename view_type_input_data,
typename view_type_index_data,
100 ||std::is_same<typename view_type_input_data::data_type, int**>::value,
int> = 0>
101 static Kokkos::View<typename view_type_input_data::data_type, typename view_type_input_data::array_layout, output_memory_space>
102 extractViewByIndex(view_type_input_data input_data_host_or_device, view_type_index_data index_data_host_or_device) {
104 typedef typename view_type_input_data::data_type output_data_type;
105 typedef typename view_type_input_data::array_layout output_array_layout;
108 auto input_data_host = Kokkos::create_mirror_view(input_data_host_or_device);
109 Kokkos::deep_copy(input_data_host, input_data_host_or_device);
113 auto index_data_host = Kokkos::create_mirror_view(index_data_host_or_device);
114 Kokkos::deep_copy(index_data_host, index_data_host_or_device);
118 Kokkos::View<output_data_type, output_array_layout, output_memory_space> extracted_view(
"extracted view",
119 index_data_host.extent(0), input_data_host.extent(1));
122 for (
size_t i=0; i<index_data_host.extent(0); i++) {
123 for (
size_t j=0; j<input_data_host.extent(1); j++) {
124 extracted_view(i, j) = input_data_host(index_data_host(i), j);
129 typedef Kokkos::View<output_data_type, output_array_layout, output_memory_space> output_view_type;
130 output_view_type extracted_view_output(
"output extracted view", extracted_view.extent(0), extracted_view.extent(1));
131 Kokkos::deep_copy(extracted_view_output, extracted_view);
134 return extracted_view_output;
137 template <
typename output_memory_space,
typename view_type_input_data,
typename view_type_index_data,
139 ||std::is_same<typename view_type_input_data::data_type, int*>::value,
int> = 0>
140 static Kokkos::View<double*, typename view_type_input_data::array_layout, output_memory_space>
141 extractViewByIndex(view_type_input_data input_data_host_or_device, view_type_index_data index_data_host_or_device) {
143 typedef typename view_type_input_data::data_type output_data_type;
144 typedef typename view_type_input_data::array_layout output_array_layout;
147 auto input_data_host = Kokkos::create_mirror_view(input_data_host_or_device);
148 Kokkos::deep_copy(input_data_host, input_data_host_or_device);
152 auto index_data_host = Kokkos::create_mirror_view(index_data_host_or_device);
153 Kokkos::deep_copy(index_data_host, index_data_host_or_device);
157 Kokkos::View<output_data_type, output_array_layout, output_memory_space> extracted_view(
"extracted view",
158 index_data_host.extent(0));
161 for (
size_t i=0; i<index_data_host.extent(0); i++) {
162 extracted_view(i) = input_data_host(index_data_host(i));
166 typedef Kokkos::View<output_data_type, output_array_layout, output_memory_space> output_view_type;
167 output_view_type extracted_view_output(
"output extracted view", extracted_view.extent(0));
168 Kokkos::deep_copy(extracted_view_output, extracted_view);
171 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)