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