DataTransferKit - Multiphysics Solution Transfer Services  2.0
DTK_ParallelSearch.hpp
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_PARALLELSEARCH_HPP
42 #define DTK_PARALLELSEARCH_HPP
43 
44 #include <unordered_map>
45 
48 #include "DTK_EntityIterator.hpp"
49 #include "DTK_EntityLocalMap.hpp"
50 #include "DTK_FineLocalSearch.hpp"
51 #include "DTK_Types.hpp"
52 
53 #include <Teuchos_Comm.hpp>
54 #include <Teuchos_RCP.hpp>
55 
56 namespace DataTransferKit
57 {
58 //---------------------------------------------------------------------------//
73 //---------------------------------------------------------------------------//
75 {
76  public:
80  ParallelSearch( const Teuchos::RCP<const Teuchos::Comm<int>> &comm,
81  const int physical_dimension,
82  const EntityIterator &domain_iterator,
83  const Teuchos::RCP<EntityLocalMap> &domain_local_map,
84  const Teuchos::ParameterList &parameters );
85 
86  /*
87  * \brief Search the domain with the range entity centroids and construct
88  * the graph. This will update the state of the object.
89  */
90  void search( const EntityIterator &range_iterator,
91  const Teuchos::RCP<EntityLocalMap> &range_local_map,
92  const Teuchos::ParameterList &parameters );
93 
98  void
99  getRangeEntitiesFromDomain( const EntityId domain_id,
100  Teuchos::Array<EntityId> &range_ids ) const;
101 
106  void
107  getDomainEntitiesFromRange( const EntityId range_id,
108  Teuchos::Array<EntityId> &domain_ids ) const;
109 
113  int rangeEntityOwnerRank( const EntityId range_id ) const;
114 
118  int domainEntityOwnerRank( const EntityId domain_id ) const;
119 
125  const EntityId domain_id, const EntityId range_id,
126  Teuchos::ArrayView<const double> &parametric_coords ) const;
127 
135  Teuchos::ArrayView<const EntityId> getMissedRangeEntityIds() const;
136 
137  private:
138  // Parallel communicator.
139  Teuchos::RCP<const Teuchos::Comm<int>> d_comm;
140 
141  // Phyiscal dimension.
142  int d_physical_dim;
143 
144  // Empty domain flag.
145  bool d_empty_domain;
146 
147  // Empty range flag.
148  bool d_empty_range;
149 
150  // Coarse global search.
151  Teuchos::RCP<CoarseGlobalSearch> d_coarse_global_search;
152 
153  // Coarse local search.
154  Teuchos::RCP<CoarseLocalSearch> d_coarse_local_search;
155 
156  // Fine local search.
157  Teuchos::RCP<FineLocalSearch> d_fine_local_search;
158 
159  // Range owner rank map.
160  std::unordered_map<EntityId, int> d_range_owner_ranks;
161 
162  // Domain owner rank map.
163  std::unordered_map<EntityId, int> d_domain_owner_ranks;
164 
165  // Domain-to-range entity map.
166  std::unordered_multimap<EntityId, EntityId> d_domain_to_range_map;
167 
168  // Range-to-domain entity map.
169  std::unordered_multimap<EntityId, EntityId> d_range_to_domain_map;
170 
171  // Parametric coordinates of the range entities in the domain
172  // entities. The first key is the range id, the second key is the domain
173  // id.
174  std::unordered_map<EntityId,
175  std::unordered_map<EntityId, Teuchos::Array<double>>>
176  d_parametric_coords;
177 
178  // Boolean for tracking missed range entities.
179  bool d_track_missed_range_entities;
180 
181  // An array of range entity ids that were not mapped during the last call
182  // to setup.
183  mutable Teuchos::Array<EntityId> d_missed_range_entity_ids;
184 };
185 
186 //---------------------------------------------------------------------------//
187 
188 } // end namespace DataTransferKit
189 
190 //---------------------------------------------------------------------------//
191 
192 #endif // end DTK_PARALLELSEARCH_HPP
193 
194 //---------------------------------------------------------------------------//
195 // end DTK_ParallelSearch.hpp
196 //---------------------------------------------------------------------------//
FineLocalSearch declaration.
void getRangeEntitiesFromDomain(const EntityId domain_id, Teuchos::Array< EntityId > &range_ids) const
Given a domain entity id on a domain process, get the ids of the range entities that mapped to it...
CoarseGlobalSearch declaration.
int rangeEntityOwnerRank(const EntityId range_id) const
Get the owner rank of a given range entity on a domain process.
Entity iterator interface.
int domainEntityOwnerRank(const EntityId domain_id) const
Get the owner rank of a given domain entity on a rank process.
void rangeParametricCoordinatesInDomain(const EntityId domain_id, const EntityId range_id, Teuchos::ArrayView< const double > &parametric_coords) const
Get the parametric coordinates of the range entities in the domain entities on a domain process...
unsigned long int EntityId
Entity id type.
Definition: DTK_Types.hpp:50
void getDomainEntitiesFromRange(const EntityId range_id, Teuchos::Array< EntityId > &domain_ids) const
Given a range entity id on a range process, get the ids of the domain entities that it mapped to...
ParallelSearch(const Teuchos::RCP< const Teuchos::Comm< int >> &comm, const int physical_dimension, const EntityIterator &domain_iterator, const Teuchos::RCP< EntityLocalMap > &domain_local_map, const Teuchos::ParameterList &parameters)
Constructor.
CoarseLocalSearch declaration.
DTK_BasicEntitySet.cpp.
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...