DataTransferKit - Multiphysics Solution Transfer Services  2.0
DTK_CoarseGlobalSearch.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_COARSEGLOBALSEARCH_HPP
42 #define DTK_COARSEGLOBALSEARCH_HPP
43 
44 #include "DTK_DBC.hpp"
45 #include "DTK_EntityIterator.hpp"
46 #include "DTK_EntityLocalMap.hpp"
47 #include "DTK_Types.hpp"
48 
49 #include <Teuchos_Array.hpp>
50 #include <Teuchos_ArrayView.hpp>
51 #include <Teuchos_Comm.hpp>
52 #include <Teuchos_ParameterList.hpp>
53 #include <Teuchos_RCP.hpp>
54 #include <Teuchos_Tuple.hpp>
55 
56 namespace DataTransferKit
57 {
58 //---------------------------------------------------------------------------//
63 //---------------------------------------------------------------------------//
65 {
66  public:
67  // Constructor.
68  CoarseGlobalSearch( const Teuchos::RCP<const Teuchos::Comm<int>> &comm,
69  const int physical_dimension,
70  const EntityIterator &domain_iterator,
71  const Teuchos::ParameterList &parameters );
72 
73  // Redistribute a set of range entity centroid coordinates with their
74  // owner ranks to the owning domain process.
75  void search( const EntityIterator &range_iterator,
76  const Teuchos::RCP<EntityLocalMap> &range_local_map,
77  const Teuchos::ParameterList &parameters,
78  Teuchos::Array<EntityId> &range_entity_ids,
79  Teuchos::Array<int> &range_owner_ranks,
80  Teuchos::Array<double> &range_centroids ) const;
81 
89  Teuchos::ArrayView<const EntityId> getMissedRangeEntityIds() const;
90 
91  private:
92  // Assemble the local bounding box around an iterator.
93  void assembleBoundingBox( const EntityIterator &entity_iterator,
94  Teuchos::Tuple<double, 6> &bounding_box ) const;
95 
96  // Check if two bounding boxes have an intersection.
97  inline bool boxesIntersect( const Teuchos::Tuple<double, 6> &box_A,
98  const Teuchos::Tuple<double, 6> &box_B,
99  const double tolerance ) const;
100 
101  // Determine if a point is in a bounding box.
102  inline bool pointInBox( const Teuchos::ArrayView<const double> &point,
103  const Teuchos::Tuple<double, 6> &box,
104  const double tolerance ) const;
105 
106  private:
107  // Communicator.
108  Teuchos::RCP<const Teuchos::Comm<int>> d_comm;
109 
110  // Spatial dimension.
111  int d_space_dim;
112 
113  // Domain bounding boxes.
114  Teuchos::Array<Teuchos::Tuple<double, 6>> d_domain_boxes;
115 
116  // Boolean for tracking missed range entities.
117  bool d_track_missed_range_entities;
118 
119  // An array of range entity ids that were not mapped during the last call
120  // to setup.
121  mutable Teuchos::Array<EntityId> d_missed_range_entity_ids;
122 
123  // Point inclusion tolerance.
124  double d_inclusion_tol;
125 };
126 
127 //---------------------------------------------------------------------------//
128 // Inline functions.
129 //---------------------------------------------------------------------------//
130 // Check if two bounding boxes have an intersection.
131 bool CoarseGlobalSearch::boxesIntersect( const Teuchos::Tuple<double, 6> &box_A,
132  const Teuchos::Tuple<double, 6> &box_B,
133  const double tolerance ) const
134 {
135  double x_tol_A = ( box_A[3] - box_A[0] ) * tolerance;
136  double y_tol_A = ( box_A[4] - box_A[1] ) * tolerance;
137  double z_tol_A = ( box_A[5] - box_A[2] ) * tolerance;
138 
139  double x_tol_B = ( box_B[3] - box_B[0] ) * tolerance;
140  double y_tol_B = ( box_B[4] - box_B[1] ) * tolerance;
141  double z_tol_B = ( box_B[5] - box_B[2] ) * tolerance;
142 
143  return !( ( ( box_A[0] - x_tol_A ) > ( box_B[3] + x_tol_B ) ||
144  ( box_A[3] + x_tol_A ) < ( box_B[0] - x_tol_B ) ) ||
145  ( ( box_A[1] - y_tol_A ) > ( box_B[4] + y_tol_B ) ||
146  ( box_A[4] + y_tol_A ) < ( box_B[1] - y_tol_B ) ) ||
147  ( ( box_A[2] - z_tol_A ) > ( box_B[5] + z_tol_B ) ||
148  ( box_A[5] + z_tol_A ) < ( box_B[2] - z_tol_B ) ) );
149 }
150 
151 //---------------------------------------------------------------------------//
152 // Determine if a point is in a bounding box.
153 bool CoarseGlobalSearch::pointInBox(
154  const Teuchos::ArrayView<const double> &point,
155  const Teuchos::Tuple<double, 6> &box, const double tolerance ) const
156 {
157  double x_tol = ( box[3] - box[0] ) * tolerance;
158  double y_tol = ( box[4] - box[1] ) * tolerance;
159  double z_tol = ( box[5] - box[2] ) * tolerance;
160 
161  if ( 3 == point.size() )
162  {
163  if ( point[0] >= ( box[0] - x_tol ) && point[1] >= ( box[1] - y_tol ) &&
164  point[2] >= ( box[2] - z_tol ) && point[0] <= ( box[3] + x_tol ) &&
165  point[1] <= ( box[4] + y_tol ) && point[2] <= ( box[5] + z_tol ) )
166  {
167  return true;
168  }
169  }
170  else if ( 2 == point.size() )
171  {
172  if ( point[0] >= ( box[0] - x_tol ) && point[1] >= ( box[1] - y_tol ) &&
173  point[0] <= ( box[3] + x_tol ) && point[1] <= ( box[4] + y_tol ) )
174  {
175  return true;
176  }
177  }
178  else if ( 1 == point.size() )
179  {
180  if ( point[0] >= ( box[0] - x_tol ) && point[0] <= ( box[3] + x_tol ) )
181  {
182  return true;
183  }
184  }
185 
186  return false;
187 }
188 
189 //---------------------------------------------------------------------------//
190 
191 } // end namespace DataTransferKit
192 
193 #endif // DTK_COARSEGLOBALSEARCH_HPP
194 
195 //---------------------------------------------------------------------------//
196 // end CoarseGlobalSearch.hpp
197 //---------------------------------------------------------------------------//
Entity iterator interface.
Assertions and Design-by-Contract for error handling.
Teuchos::ArrayView< const EntityId > getMissedRangeEntityIds() const
Return the ids of the range entities that were not during the last search (i.e. those that are guaran...
A CoarseGlobalSearch data structure for global entity coarse search.
DTK_BasicEntitySet.cpp.