NimbleSM
NimbleSM is a solid mechanics simulation code for dynamic systems
Loading...
Searching...
No Matches
arborx_utils.h
Go to the documentation of this file.
1/*
2//@HEADER
3// ************************************************************************
4//
5// NimbleSM
6// Copyright 2018
7// National Technology & Engineering Solutions of Sandia, LLC (NTESS)
8//
9// Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government
10// retains certain rights in this software.
11//
12// Redistribution and use in source and binary forms, with or without
13// modification, are permitted provided that the following conditions are
14// met:
15//
16// 1. Redistributions of source code must retain the above copyright
17// notice, this list of conditions and the following disclaimer.
18//
19// 2. Redistributions in binary form must reproduce the above copyright
20// notice, this list of conditions and the following disclaimer in the
21// documentation and/or other materials provided with the distribution.
22//
23// 3. Neither the name of the Corporation nor the names of the
24// contributors may be used to endorse or promote products derived from
25// this software without specific prior written permission.
26//
27// THIS SOFTWARE IS PROVIDED BY NTESS "AS IS" AND ANY EXPRESS OR IMPLIED
28// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
29// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
30// NO EVENT SHALL NTESS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
32// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37//
38// Questions? Contact David Littlewood (djlittl@sandia.gov)
39//
40// ************************************************************************
41//@HEADER
42*/
43
44#ifndef NIMBLESM_ARBORX_UTILS_H
45#define NIMBLESM_ARBORX_UTILS_H
46
48#include "nimble_defs.h"
49
50#ifdef NIMBLE_HAVE_ARBORX
51
52#include <ArborX.hpp>
53
54namespace nimble_kokkos {
55
56using HostContactEntityUnmanagedConstView =
57 Kokkos::View<const nimble::ContactEntity*, nimble_kokkos::kokkos_host, Kokkos::MemoryTraits<Kokkos::Unmanaged>>;
58
59}
60
61//
62// Need to specialize AccessTrait< ..., {PrimitivesTag, PredicatesTag} >
63// Here the first template parameter is a container of nimble::ContactEntity
64//
65// See https://github.com/arborx/ArborX/wiki/ArborX%3A%3AAccessTraits
66//
67namespace ArborX {
68
69template <>
70struct AccessTraits<nimble_kokkos::DeviceContactEntityArrayView, PrimitivesTag>
71{
72 // size returns the number of elements in the View
73 static std::size_t
75 {
76 return v.size();
77 }
78
79 /// Returns an ArborX::Box for each contact entity within the nimble view
80 ///
81 /// \param v
82 /// \param i
83 /// \return ArborX::Box
84 KOKKOS_FUNCTION static ArborX::Box
85 get(nimble_kokkos::DeviceContactEntityArrayView const& v, std::size_t i)
86 {
87 nimble::ContactEntity& e = v(i);
90 ArborX::Box box(point1, point2);
91
92 return box;
93 }
95};
96
97template <>
98struct AccessTraits<nimble_kokkos::DeviceContactEntityArrayView, PredicatesTag>
99{
100 static std::size_t
102 {
103 return v.size();
104 }
105
106 KOKKOS_FUNCTION static auto
107 get(nimble_kokkos::DeviceContactEntityArrayView const& v, std::size_t i)
108 {
109 nimble::ContactEntity& e = v(i);
110 ArborX::Point point1(e.bounding_box_x_min_, e.bounding_box_y_min_, e.bounding_box_z_min_);
111 ArborX::Point point2(e.bounding_box_x_max_, e.bounding_box_y_max_, e.bounding_box_z_max_);
112 ArborX::Box box(point1, point2);
113
114 //
115 // What does Intersects returns, how is it used afterwards?
116 // The intent with the "unspecified" return type in the doc
117 // (https://github.com/arborx/ArborX/wiki/ArborX%3A%3Aintersects)
118 // is to consider the return type as an implementation detail.
119 //
120 // If needed, `decltype(ArborX::intersects(ArborX::Box{}))` spells out the type.
121 //
122 return ArborX::attach(intersects(box), (int)i);
123 }
125};
126
127//
128// Specialization for HostContactEntityUnmanagedConstView
129//
130
131template <>
132struct AccessTraits<nimble_kokkos::HostContactEntityUnmanagedConstView, PrimitivesTag>
133{
134 // size returns the number of elements in the View
135 static std::size_t
136 size(nimble_kokkos::HostContactEntityUnmanagedConstView const& v)
137 {
138 return v.size();
139 }
140
141 /// Returns an ArborX::Box for each contact entity within the nimble view
142 ///
143 /// \param v
144 /// \param i
145 /// \return ArborX::Box
146 KOKKOS_FUNCTION static ArborX::Box
147 get(nimble_kokkos::HostContactEntityUnmanagedConstView const& v, std::size_t i)
148 {
149 const nimble::ContactEntity& e = v(i);
150 ArborX::Point point1(e.bounding_box_x_min_, e.bounding_box_y_min_, e.bounding_box_z_min_);
151 ArborX::Point point2(e.bounding_box_x_max_, e.bounding_box_y_max_, e.bounding_box_z_max_);
152 ArborX::Box box(point1, point2);
153 return box;
154 }
156};
157
158template <>
159struct AccessTraits<nimble_kokkos::HostContactEntityUnmanagedConstView, PredicatesTag>
160{
161 static std::size_t
162 size(nimble_kokkos::HostContactEntityUnmanagedConstView const& v)
163 {
164 return v.size();
165 }
166
167 KOKKOS_FUNCTION static auto
168 get(nimble_kokkos::HostContactEntityUnmanagedConstView const& v, std::size_t i)
169 {
170 const nimble::ContactEntity& e = v(i);
171 ArborX::Point point1(e.bounding_box_x_min_, e.bounding_box_y_min_, e.bounding_box_z_min_);
172 ArborX::Point point2(e.bounding_box_x_max_, e.bounding_box_y_max_, e.bounding_box_z_max_);
173 ArborX::Box box(point1, point2);
174 //
175 // What does Intersects returns, how is it used afterwards?
176 // The intent with the "unspecified" return type in the doc
177 // (https://github.com/arborx/ArborX/wiki/ArborX%3A%3Aintersects)
178 // is to consider the return type as an implementation detail.
179 //
180 // If needed, `decltype(ArborX::intersects(ArborX::Box{}))` spells out the type.
181 //
182 return ArborX::attach(intersects(box), (int)i);
183 }
185};
186
187} // namespace ArborX
188
189#endif // #ifdef NIMBLE_HAVE_ARBORX
190
191#endif // NIMBLESM_ARBORX_UTILS_H
double bounding_box_y_max_
Definition nimble_contact_entity.h:563
double bounding_box_z_min_
Definition nimble_contact_entity.h:564
double bounding_box_z_max_
Definition nimble_contact_entity.h:565
double bounding_box_y_min_
Definition nimble_contact_entity.h:562
double bounding_box_x_max_
Definition nimble_contact_entity.h:561
double bounding_box_x_min_
Definition nimble_contact_entity.h:560
Definition nimble_contact_manager.h:68
Kokkos::View< nimble::ContactEntity *, nimble_kokkos::kokkos_layout, nimble_kokkos::kokkos_device > DeviceContactEntityArrayView
Definition nimble_kokkos_contact_defs.h:15
Kokkos::Serial::memory_space kokkos_host_mirror_memory_space
Definition nimble_kokkos_defs.h:63
Kokkos::Serial::memory_space kokkos_device_memory_space
Definition nimble_kokkos_defs.h:82