DataTransferKit - Multiphysics Solution Transfer Services  2.0
DTK_SplineInterpolationPairing_impl.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 /*
3  Copyright (c) 2012, Stuart R. Slattery
4  All rights reserved.
5 
6  Redistribution and use in source and binary forms, with or without
7  modification, are permitted provided that the following conditions are
8  met:
9 
10  *: Redistributions of source code must retain the above copyright
11  notice, this list of conditions and the following disclaimer.
12 
13  *: Redistributions in binary form must reproduce the above copyright
14  notice, this list of conditions and the following disclaimer in the
15  documentation and/or other materials provided with the distribution.
16 
17  *: Neither the name of the University of Wisconsin - Madison nor the
18  names of its contributors may be used to endorse or promote products
19  derived from this software without specific prior written permission.
20 
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33 //---------------------------------------------------------------------------//
39 //---------------------------------------------------------------------------//
40 
41 #ifndef DTK_SPLINEINTERPOLATIONPAIRING_IMPL_HPP
42 #define DTK_SPLINEINTERPOLATIONPAIRING_IMPL_HPP
43 
44 #include "DTK_DBC.hpp"
47 #include "DTK_StaticSearchTree.hpp"
48 
49 namespace DataTransferKit
50 {
51 //---------------------------------------------------------------------------//
55 template <int DIM>
57  const Teuchos::ArrayView<const double> &child_centers,
58  const Teuchos::ArrayView<const double> &parent_centers, const bool use_knn,
59  const unsigned num_neighbors, const double radius )
60 {
61  DTK_REQUIRE( 0 == child_centers.size() % DIM );
62  DTK_REQUIRE( 0 == parent_centers.size() % DIM );
63 
64  // Setup the kD-tree
65  unsigned leaf_size = 30;
66  NanoflannTree<DIM> tree( child_centers, leaf_size );
67 
68  // Allocate arrays
69  unsigned num_parents = parent_centers.size() / DIM;
70  d_pairings.resize( num_parents );
71  d_pair_sizes = Teuchos::ArrayRCP<EntityId>( num_parents );
72  d_radii.resize( num_parents );
73 
74  // Search for pairs
75  for ( unsigned i = 0; i < num_parents; ++i )
76  {
77  // If kNN do the nearest neighbor search for kNN and calculate a
78  // radius. The radius will be a small fraction larger than the
79  // farthest neighbor. An alternative to this would be to find the
80  // kNN+1 neighbors and use the last neighbor's distance as the
81  // radius.
82  if ( use_knn )
83  {
84  // Get the knn neighbors
85  d_pairings[i] =
86  tree.nnSearch( parent_centers( DIM * i, DIM ), num_neighbors );
87 
88  // Get the radius from kNN. Make it slightly larger so the last
89  // neighbor gives a non-zero contribution to the interpolant.
91  parent_centers( DIM * i, DIM ).getRawPtr(),
92  child_centers( DIM * d_pairings[i].back(), DIM ).getRawPtr() );
93  d_radii[i] *= 1.01;
94  }
95 
96  // Otherwise do the radius search.
97  else
98  {
99  d_pairings[i] =
100  tree.radiusSearch( parent_centers( DIM * i, DIM ), radius );
101  d_radii[i] = radius;
102  }
103 
104  // Get the size of the support.
105  d_pair_sizes[i] = d_pairings[i].size();
106  }
107 }
108 
109 //---------------------------------------------------------------------------//
114 template <int DIM>
115 Teuchos::ArrayView<const unsigned>
117  const unsigned parent_id ) const
118 {
119  DTK_REQUIRE( parent_id < d_pairings.size() );
120  Teuchos::ArrayView<const unsigned> id_view = d_pairings[parent_id]();
121  return id_view;
122 }
123 
124 //---------------------------------------------------------------------------//
125 /*
126  * \brief Get the support radius of a given parent.
127  */
128 template <int DIM>
130  const unsigned parent_id ) const
131 {
132  DTK_REQUIRE( parent_id < d_radii.size() );
133  return d_radii[parent_id];
134 }
135 
136 //---------------------------------------------------------------------------//
137 
138 } // end namespace DataTransferKit
139 
140 //---------------------------------------------------------------------------//
141 
142 #endif // end DTK_SPLINEINTERPOLATIONPAIRING_IMPL_HPP
143 
144 //---------------------------------------------------------------------------//
145 // end DTK_SplineInterpolationPairing_impl.hpp
146 //---------------------------------------------------------------------------//
Local source/parent center pairings.
Teuchos::Array< unsigned > nnSearch(const Teuchos::ArrayView< const double > &point, const unsigned num_neighbors) const
Perform an n-nearest neighbor search.
Spatial searching for point clouds.
Spatial searching for point clouds.
SplineInterpolationPairing(const Teuchos::ArrayView< const double > &child_centers, const Teuchos::ArrayView< const double > &parent_centers, const bool use_knn, const unsigned num_neighbors, const double radius)
Constructor.
Teuchos::Array< unsigned > radiusSearch(const Teuchos::ArrayView< const double > &point, const double radius) const
Perform a nearest neighbor search within a specified radius.
Assertions and Design-by-Contract for error handling.
Teuchos::ArrayView< const unsigned > childCenterIds(const unsigned parent_id) const
Given a parent center local id get the ids of the child centers within the given radius.
Euclidean distance function.
DTK_BasicEntitySet.cpp.