Compadre 1.5.5
Loading...
Searching...
No Matches
Compadre_PointConnections.hpp
Go to the documentation of this file.
1#ifndef _COMPADRE_POINTCONNECTIONS_HPP_
2#define _COMPADRE_POINTCONNECTIONS_HPP_
3
5#include <Kokkos_Core.hpp>
6
7namespace Compadre {
8
9//! Combines NeighborLists with the PointClouds from which it was derived
10//! Assumed that memory_space is the same as device, but it can be set to
11//! host, if desired.
12template <typename view_type_1, typename view_type_2, typename nla_type, typename memory_space = device_memory_space>
14
15 //! source site coordinates on device
16 typedef decltype(Kokkos::create_mirror_view<memory_space>(
17 memory_space(), view_type_1()))
19
20 //! target site coordinates on device
21 typedef decltype(Kokkos::create_mirror_view<memory_space>(
22 memory_space(), view_type_2()))
24
27 nla_type _nla;
28
29/** @name Constructors
30 */
31///@{
32
33 //! \brief Constructor for PointConnections
34 PointConnections(view_type_1 target_coordinates,
35 view_type_2 source_coordinates,
36 nla_type nla) : _nla(nla) {
37
38 _target_coordinates = Kokkos::create_mirror_view<memory_space>(
39 memory_space(), target_coordinates);
40 _source_coordinates = Kokkos::create_mirror_view<memory_space>(
41 memory_space(), source_coordinates);
42 Kokkos::deep_copy(_target_coordinates, target_coordinates);
43 Kokkos::deep_copy(_source_coordinates, source_coordinates);
44
45 }
46
48
49 // copy constructor (can be used to move data from device to host or vice-versa)
50 template <typename other_type_1, typename other_type_2, typename other_type_3>
53
54///@}
55
56/** @name Public Utility
57 *
58 */
59///@{
60
61 //! Returns a component of the local coordinate after transformation from global to local under the orthonormal basis V.
62 KOKKOS_INLINE_FUNCTION
63 static double convertGlobalToLocalCoordinate(const XYZ global_coord, const int dim, const scratch_matrix_right_type& V) {
65 // only written for 2d manifold in 3d space or 2D problem with 1D manifold
66 double val = 0;
67 val += global_coord.x * V(dim, 0);
68 if (V.extent_int(1)>1) val += global_coord.y * V(dim, 1);
69 if (V.extent_int(1)>2) val += global_coord.z * V(dim, 2);
70 return val;
71 }
72
73 //! Returns a component of the global coordinate after transformation from local to global under the orthonormal basis V^T.
74 KOKKOS_INLINE_FUNCTION
75 static double convertLocalToGlobalCoordinate(const XYZ local_coord, const int dim, const scratch_matrix_right_type& V) {
76 double val = 0.0;
77 if (dim == 0 && V.extent_int(0)==1) { // 2D problem with 1D manifold
78 val = local_coord.x * V(0, dim);
79 } else { // 3D problem with 2D manifold
80 val = local_coord.x * V(0, dim) + local_coord.y * V(1, dim);
81 }
82 return val;
83 }
84
85 //! Returns Euclidean norm of a vector
86 KOKKOS_INLINE_FUNCTION
87 static double EuclideanVectorLength(const XYZ& delta_vector, const int dimension) {
88 double inside_val = delta_vector.x*delta_vector.x;
89 switch (dimension) {
90 case 3:
91 inside_val += delta_vector.z*delta_vector.z;
92 // no break is intentional
93 case 2:
94 inside_val += delta_vector.y*delta_vector.y;
95 // no break is intentional
96 default:
97 break;
98 }
99 return std::sqrt(inside_val);
100 }
101
102
103///@}
104
105/** @name Public Modifiers
106 * Private function because information lives on the device
107 */
108///@{
109
110 //! Update only target coordinates
111 void setTargetCoordinates(view_type_1 target_coordinates) {
112 _target_coordinates = Kokkos::create_mirror_view<memory_space>(
113 memory_space(), target_coordinates);
114 Kokkos::deep_copy(_target_coordinates, target_coordinates);
115 }
116
117 //! Update only source coordinates
118 void setSourceCoordinates(view_type_2 source_coordinates) {
119 _source_coordinates = Kokkos::create_mirror_view<memory_space>(
120 memory_space(), source_coordinates);
121 Kokkos::deep_copy(_source_coordinates, source_coordinates);
122 }
123
124 //! Update only target coordinates
125 void setNeighborLists(nla_type nla) {
126 _nla = nla;
127 }
128
129
130///@}
131
132/** @name Public Accessors
133 */
134///@{
135
136 //! Returns one component of the target coordinate for a particular target. Whether global or local coordinates
137 //! depends upon V being specified
138 KOKKOS_INLINE_FUNCTION
139 double getTargetCoordinate(const int target_index, const int dim, const scratch_matrix_right_type* V = NULL) const {
140 compadre_kernel_assert_debug((_target_coordinates.extent(0) >= (size_t)target_index) && "Target index is out of range for _target_coordinates.");
141 if (V==NULL) {
142 return _target_coordinates(target_index, dim);
143 } else {
144 XYZ target_coord = XYZ(_target_coordinates(target_index, 0), 0, 0);
145 if (_target_coordinates.extent_int(1)>1) target_coord[1] = _target_coordinates(target_index, 1);
146 if (_target_coordinates.extent_int(1)>2) target_coord[2] = _target_coordinates(target_index, 2);
147 return this->convertGlobalToLocalCoordinate(target_coord, dim, *V);
148 }
149 }
150
151 //! Returns one component of the neighbor coordinate for a particular target. Whether global or local coordinates
152 //! depends upon V being specified
153 KOKKOS_INLINE_FUNCTION
154 double getNeighborCoordinate(const int target_index, const int neighbor_list_num, const int dim, const scratch_matrix_right_type* V = NULL) const {
155 compadre_kernel_assert_debug((_source_coordinates.extent(0) >= (size_t)(this->getNeighborIndex(target_index, neighbor_list_num))) && "Source index is out of range for _source_coordinates.");
156 if (V==NULL) {
157 return _source_coordinates(this->getNeighborIndex(target_index, neighbor_list_num), dim);
158 } else {
159 XYZ neighbor_coord
160 = XYZ(_source_coordinates(this->getNeighborIndex(target_index, neighbor_list_num), 0), 0, 0);
161 if (_source_coordinates.extent_int(1)>1) neighbor_coord[1]
162 = _source_coordinates(this->getNeighborIndex(target_index, neighbor_list_num), 1);
163 if (_source_coordinates.extent_int(1)>2) neighbor_coord[2]
164 = _source_coordinates(this->getNeighborIndex(target_index, neighbor_list_num), 2);
165 return this->convertGlobalToLocalCoordinate(neighbor_coord, dim, *V);
166 }
167 }
168
169 //! Returns the relative coordinate as a vector between the target site and the neighbor site.
170 //! Whether global or local coordinates depends upon V being specified
171 KOKKOS_INLINE_FUNCTION
172 XYZ getRelativeCoord(const int target_index, const int neighbor_list_num, const int dimension, const scratch_matrix_right_type* V = NULL) const {
173 XYZ coordinate_delta;
174
175 coordinate_delta.x = this->getNeighborCoordinate(target_index, neighbor_list_num, 0, V) - this->getTargetCoordinate(target_index, 0, V);
176 if (dimension>1) coordinate_delta.y = this->getNeighborCoordinate(target_index, neighbor_list_num, 1, V) - this->getTargetCoordinate(target_index, 1, V);
177 if (dimension>2) coordinate_delta.z = this->getNeighborCoordinate(target_index, neighbor_list_num, 2, V) - this->getTargetCoordinate(target_index, 2, V);
178
179 return coordinate_delta;
180 }
181
182 //! Mapping from [0,number of neighbors for a target] to the row that contains the source coordinates for
183 //! that neighbor
184 KOKKOS_INLINE_FUNCTION
185 int getNeighborIndex(const int target_index, const int neighbor_list_num) const {
186 return _nla.getNeighborDevice(target_index, neighbor_list_num);
187 }
188
189///@}
190
191}; // PointConnections
192
193} // Compadre namespace
194
195#endif
196
#define compadre_kernel_assert_debug(condition)
Kokkos::View< double **, layout_right, Kokkos::MemoryTraits< Kokkos::Unmanaged > > scratch_matrix_right_type
Combines NeighborLists with the PointClouds from which it was derived Assumed that memory_space is th...
PointConnections(const PointConnections< other_type_1, other_type_2, other_type_3 > &other)
static KOKKOS_INLINE_FUNCTION double EuclideanVectorLength(const XYZ &delta_vector, const int dimension)
Returns Euclidean norm of a vector.
decltype(Kokkos::create_mirror_view< memory_space >(memory_space(), view_type_1())) device_mirror_target_view_type
source site coordinates on device
static KOKKOS_INLINE_FUNCTION double convertLocalToGlobalCoordinate(const XYZ local_coord, const int dim, const scratch_matrix_right_type &V)
Returns a component of the global coordinate after transformation from local to global under the orth...
static KOKKOS_INLINE_FUNCTION double convertGlobalToLocalCoordinate(const XYZ global_coord, const int dim, const scratch_matrix_right_type &V)
Returns a component of the local coordinate after transformation from global to local under the ortho...
KOKKOS_INLINE_FUNCTION XYZ getRelativeCoord(const int target_index, const int neighbor_list_num, const int dimension, const scratch_matrix_right_type *V=NULL) const
Returns the relative coordinate as a vector between the target site and the neighbor site.
void setSourceCoordinates(view_type_2 source_coordinates)
Update only source coordinates.
KOKKOS_INLINE_FUNCTION double getNeighborCoordinate(const int target_index, const int neighbor_list_num, const int dim, const scratch_matrix_right_type *V=NULL) const
Returns one component of the neighbor coordinate for a particular target.
void setNeighborLists(nla_type nla)
Update only target coordinates.
decltype(Kokkos::create_mirror_view< memory_space >(memory_space(), view_type_2())) device_mirror_source_view_type
target site coordinates on device
void setTargetCoordinates(view_type_1 target_coordinates)
Update only target coordinates.
KOKKOS_INLINE_FUNCTION double getTargetCoordinate(const int target_index, const int dim, const scratch_matrix_right_type *V=NULL) const
Returns one component of the target coordinate for a particular target.
device_mirror_source_view_type _source_coordinates
device_mirror_target_view_type _target_coordinates
PointConnections(view_type_1 target_coordinates, view_type_2 source_coordinates, nla_type nla)
Constructor for PointConnections.
KOKKOS_INLINE_FUNCTION int getNeighborIndex(const int target_index, const int neighbor_list_num) const
Mapping from [0,number of neighbors for a target] to the row that contains the source coordinates for...