41 #ifndef DTK_CENTERDISTRIBUTOR_IMPL_HPP 42 #define DTK_CENTERDISTRIBUTOR_IMPL_HPP 47 #include <Teuchos_Array.hpp> 48 #include <Teuchos_CommHelpers.hpp> 60 const Teuchos::RCP<
const Teuchos::Comm<int>> &comm,
61 const Teuchos::ArrayView<const double> &source_centers,
62 const Teuchos::ArrayView<const double> &target_centers,
const double radius,
63 Teuchos::Array<double> &target_decomp_source_centers )
64 : d_distributor( new Tpetra::Distributor( comm ) )
66 DTK_REQUIRE( 0 == source_centers.size() % DIM );
67 DTK_REQUIRE( 0 == target_centers.size() % DIM );
70 Teuchos::Array<int> export_procs;
73 double radius_tol = 1.0e-2;
74 double radius_expand = radius * ( 1.0 + radius_tol );
78 localCloudDomain( target_centers );
79 local_target_domain.expand( radius_expand );
80 Teuchos::Array<CloudDomain<DIM>> global_target_domains(
82 Teuchos::gatherAll<int, CloudDomain<DIM>>(
83 *comm, 1, &local_target_domain, global_target_domains.size(),
84 global_target_domains.getRawPtr() );
88 localCloudDomain( source_centers );
89 Teuchos::Array<CloudDomain<DIM>> neighbor_target_domains;
90 Teuchos::Array<int> neighbor_ranks;
91 for (
unsigned i = 0; i < global_target_domains.size(); ++i )
93 if ( local_source_domain.checkForIntersection(
94 global_target_domains[i] ) )
96 neighbor_target_domains.push_back( global_target_domains[i] );
97 neighbor_ranks.push_back( i );
100 global_target_domains.clear();
103 Teuchos::ArrayView<const double> source_point;
104 for (
unsigned source_id = 0; source_id < source_centers.size() / DIM;
107 source_point = source_centers.view( DIM * source_id, DIM );
108 for (
unsigned b = 0; b < neighbor_target_domains.size(); ++b )
110 if ( neighbor_target_domains[b].pointInDomain( source_point ) )
112 export_procs.push_back( neighbor_ranks[b] );
113 d_export_ids.push_back( source_id );
118 DTK_CHECK( d_export_ids.size() == export_procs.size() );
119 d_num_exports = d_export_ids.size();
122 Teuchos::ArrayView<int> export_procs_view = export_procs();
123 d_num_imports = d_distributor->createFromSends( export_procs_view );
124 export_procs.clear();
128 Teuchos::Array<unsigned>::const_iterator export_id_it;
129 Teuchos::Array<double> src_coords( d_num_exports * DIM );
130 for (
int n = 0; n < d_num_exports; ++n )
132 src_coords( DIM * n, DIM )
133 .assign( source_centers( DIM * d_export_ids[n], DIM ) );
137 Teuchos::ArrayView<const double> src_coords_view = src_coords();
138 target_decomp_source_centers.resize( d_num_imports * DIM );
139 d_distributor->doPostsAndWaits( src_coords_view, DIM,
140 target_decomp_source_centers() );
151 const Teuchos::ArrayView<const T> &source_decomp_data,
152 const Teuchos::ArrayView<T> &target_decomp_data )
const 154 DTK_REQUIRE( d_num_imports == target_decomp_data.size() );
158 Teuchos::Array<unsigned>::const_iterator export_id_it;
159 Teuchos::Array<T> src_data( d_num_exports );
160 typename Teuchos::Array<T>::iterator src_it;
161 for ( export_id_it = d_export_ids.begin(), src_it = src_data.begin();
162 export_id_it != d_export_ids.end(); ++export_id_it, ++src_it )
164 DTK_CHECK( *export_id_it < source_decomp_data.size() );
165 *src_it = source_decomp_data[*export_id_it];
169 Teuchos::ArrayView<const T> src_view = src_data();
170 d_distributor->doPostsAndWaits( src_view, 1, target_decomp_data );
179 const Teuchos::ArrayView<const double> ¢ers )
const 181 Teuchos::Array<double> bounds( 2 * DIM, 0.0 );
183 if ( centers.size() > 0 )
185 for (
int d = 0; d < DIM; ++d )
187 bounds[2 * d] = std::numeric_limits<double>::max();
188 bounds[2 * d + 1] = std::numeric_limits<double>::min();
192 Teuchos::ArrayView<const double>::const_iterator center_it;
193 for ( center_it = centers.begin(); center_it != centers.end(); )
195 for (
int d = 0; d < DIM; ++d )
197 bounds[2 * d] = std::min( bounds[2 * d], *( center_it + d ) );
199 std::max( bounds[2 * d + 1], *( center_it + d ) );
213 #endif // end DTK_CENTERDISTRIBUTOR_IMPL_HPP CenterDistributor(const Teuchos::RCP< const Teuchos::Comm< int >> &comm, const Teuchos::ArrayView< const double > &source_centers, const Teuchos::ArrayView< const double > &target_centers, const double radius, Teuchos::Array< double > &target_decomp_source_centers)
Constructor.
Assertions and Design-by-Contract for error handling.
Global source distributor.
Axis-aligned Cartesian cloud domain container.
void distribute(const Teuchos::ArrayView< const T > &source_decomp_data, const Teuchos::ArrayView< T > &target_decomp_data) const
Given a set of scalar values at the given source centers in the source decomposition, distribute them to the target decomposition.