45 #include <Teuchos_CommHelpers.hpp> 47 #include <Tpetra_Distributor.hpp> 53 CoarseGlobalSearch::CoarseGlobalSearch(
54 const Teuchos::RCP<
const Teuchos::Comm<int>> &comm,
55 const int physical_dimension,
const EntityIterator &domain_iterator,
56 const Teuchos::ParameterList ¶meters )
58 , d_space_dim( physical_dimension )
59 , d_track_missed_range_entities( false )
60 , d_missed_range_entity_ids( 0 )
61 , d_inclusion_tol( 1.0e-6 )
64 if ( parameters.isParameter(
"Track Missed Range Entities" ) )
66 d_track_missed_range_entities =
67 parameters.get<
bool>(
"Track Missed Range Entities" );
71 if ( parameters.isParameter(
"Point Inclusion Tolerance" ) )
73 d_inclusion_tol = parameters.get<
double>(
"Point Inclusion Tolerance" );
77 Teuchos::Tuple<double, 6> domain_box;
78 assembleBoundingBox( domain_iterator, domain_box );
81 int comm_size = d_comm->getSize();
82 Teuchos::Array<double> all_bounds( 6 * comm_size );
83 Teuchos::gatherAll<int, double>( *d_comm, 6, domain_box.getRawPtr(),
85 all_bounds.getRawPtr() );
88 d_domain_boxes.resize( comm_size );
90 for (
int n = 0; n < comm_size; ++n )
93 d_domain_boxes[n] = Teuchos::tuple(
94 all_bounds[
id], all_bounds[
id + 1], all_bounds[
id + 2],
95 all_bounds[
id + 3], all_bounds[
id + 4], all_bounds[
id + 5] );
102 void CoarseGlobalSearch::search(
103 const EntityIterator &range_iterator,
104 const Teuchos::RCP<EntityLocalMap> &range_local_map,
105 const Teuchos::ParameterList ¶meters,
106 Teuchos::Array<EntityId> &range_entity_ids,
107 Teuchos::Array<int> &range_owner_ranks,
108 Teuchos::Array<double> &range_centroids )
const 111 Teuchos::Tuple<double, 6> range_box;
112 assembleBoundingBox( range_iterator, range_box );
115 Teuchos::Array<int> neighbor_ranks;
116 Teuchos::Array<Teuchos::Tuple<double, 6>> neighbor_boxes;
117 int num_domains = d_domain_boxes.size();
118 for (
int n = 0; n < num_domains; ++n )
120 if ( boxesIntersect( range_box, d_domain_boxes[n], d_inclusion_tol ) )
122 neighbor_ranks.push_back( n );
123 neighbor_boxes.push_back( d_domain_boxes[n] );
128 int num_neighbors = neighbor_boxes.size();
129 EntityIterator range_begin = range_iterator.begin();
130 EntityIterator range_end = range_iterator.end();
131 EntityIterator range_it;
132 Teuchos::Array<EntityId> send_ids;
133 Teuchos::Array<int> send_ranks;
134 Teuchos::Array<double> send_centroids;
135 Teuchos::Array<double> centroid( d_space_dim );
136 bool found_entity =
false;
137 for ( range_it = range_begin; range_it != range_end; ++range_it )
140 range_local_map->centroid( *range_it, centroid() );
143 found_entity =
false;
144 for (
int n = 0; n < num_neighbors; ++n )
147 if ( pointInBox( centroid(), neighbor_boxes[n], d_inclusion_tol ) )
150 send_ids.push_back( range_it->id() );
151 send_ranks.push_back( neighbor_ranks[n] );
152 for (
int d = 0; d < d_space_dim; ++d )
154 send_centroids.push_back( centroid[d] );
161 if ( d_track_missed_range_entities && !found_entity )
163 d_missed_range_entity_ids.push_back( range_it->id() );
166 int num_send = send_ranks.size();
167 Teuchos::Array<int> range_ranks( num_send, d_comm->getRank() );
170 Tpetra::Distributor distributor( d_comm );
171 int num_range_import = distributor.createFromSends( send_ranks() );
174 Teuchos::ArrayView<const EntityId> send_ids_view = send_ids();
175 range_entity_ids.resize( num_range_import );
176 distributor.doPostsAndWaits( send_ids_view, 1, range_entity_ids() );
179 Teuchos::ArrayView<const int> range_ranks_view = range_ranks();
180 range_owner_ranks.resize( num_range_import );
181 distributor.doPostsAndWaits( range_ranks_view, 1, range_owner_ranks() );
184 range_centroids.resize( d_space_dim * num_range_import );
185 Teuchos::ArrayView<const double> send_centroids_view = send_centroids();
186 distributor.doPostsAndWaits( send_centroids_view, d_space_dim,
194 Teuchos::ArrayView<const EntityId>
197 return d_missed_range_entity_ids();
202 void CoarseGlobalSearch::assembleBoundingBox(
204 Teuchos::Tuple<double, 6> &bounding_box )
const 206 if ( entity_iterator.size() > 0 )
208 double max = std::numeric_limits<double>::max();
209 bounding_box = Teuchos::tuple( max, max, max, -max, -max, -max );
210 Teuchos::Tuple<double, 6> entity_bounds;
214 for ( entity_it = entity_begin; entity_it != entity_end; ++entity_it )
217 for (
int n = 0; n < 3; ++n )
219 bounding_box[n] = std::min( bounding_box[n], entity_bounds[n] );
220 bounding_box[n + 3] =
221 std::max( bounding_box[n + 3], entity_bounds[n + 3] );
227 bounding_box = Teuchos::tuple( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 );
CoarseGlobalSearch declaration.
void boundingBox(Teuchos::Tuple< double, 6 > &bounds) const
Return the Cartesian bounding box around an entity.
Entity iterator interface.
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...