41 #ifndef DTK_MOVINGLEASTSQUARERECONSTRUCTIONOPERATOR_IMPL_HPP 42 #define DTK_MOVINGLEASTSQUARERECONSTRUCTIONOPERATOR_IMPL_HPP 44 #include "DTK_BasicEntityPredicates.hpp" 49 #include "DTK_PredicateComposition.hpp" 52 #include <Teuchos_ArrayRCP.hpp> 53 #include <Teuchos_CommHelpers.hpp> 54 #include <Teuchos_ParameterList.hpp> 55 #include <Teuchos_Ptr.hpp> 57 #include <Tpetra_MultiVector.hpp> 63 template <
class Basis,
int DIM>
66 const Teuchos::RCP<const TpetraMap> &domain_map,
67 const Teuchos::RCP<const TpetraMap> &range_map,
68 const Teuchos::ParameterList ¶meters )
69 :
Base( domain_map, range_map )
73 , d_domain_entity_dim( 0 )
74 , d_range_entity_dim( 0 )
77 if ( parameters.isParameter(
"Type of Search" ) )
79 if (
"Radius" == parameters.get<std::string>(
"Type of Search" ) )
83 else if (
"Nearest Neighbor" ==
84 parameters.get<std::string>(
"Type of Search" ) )
98 DTK_REQUIRE( parameters.isParameter(
"Num Neighbors" ) );
99 d_knn = parameters.get<
int>(
"Num Neighbors" );
105 DTK_REQUIRE( parameters.isParameter(
"RBF Radius" ) );
106 d_radius = parameters.get<
double>(
"RBF Radius" );
111 if ( parameters.isParameter(
"Domain Entity Dimension" ) )
113 d_domain_entity_dim = parameters.get<
int>(
"Domain Entity Dimension" );
115 if ( parameters.isParameter(
"Range Entity Dimension" ) )
117 d_range_entity_dim = parameters.get<
int>(
"Range Entity Dimension" );
123 template <
class Basis,
int DIM>
125 const Teuchos::RCP<FunctionSpace> &domain_space,
126 const Teuchos::RCP<FunctionSpace> &range_space )
128 DTK_REQUIRE( Teuchos::nonnull( domain_space ) );
129 DTK_REQUIRE( Teuchos::nonnull( range_space ) );
132 const Teuchos::RCP<const typename Base::TpetraMap> domain_map =
133 this->getDomainMap();
134 const Teuchos::RCP<const typename Base::TpetraMap> range_map =
138 Teuchos::RCP<const Teuchos::Comm<int>> comm = domain_map->getComm();
141 bool nonnull_domain = Teuchos::nonnull( domain_space->entitySet() );
142 bool nonnull_range = Teuchos::nonnull( range_space->entitySet() );
145 Teuchos::ArrayRCP<double> source_centers;
146 Teuchos::ArrayRCP<GO> source_support_ids;
147 getNodeCoordsAndIds( domain_space, d_domain_entity_dim, source_centers,
148 source_support_ids );
151 Teuchos::ArrayRCP<double> target_centers;
152 Teuchos::ArrayRCP<GO> target_support_ids;
153 getNodeCoordsAndIds( range_space, d_range_entity_dim, target_centers,
154 target_support_ids );
160 double target_proximity = 0.0;
164 Teuchos::Tuple<double, 6> local_box;
165 range_space->entitySet()->localBoundingBox( local_box );
168 target_proximity = local_box[3] - local_box[0];
169 for (
int d = 1; d < DIM; ++d )
172 std::max( target_proximity, local_box[d + 3] - local_box[d] );
176 target_proximity *= 0.1;
180 target_proximity = d_radius;
185 Teuchos::Array<double> dist_sources;
187 target_centers(), target_proximity,
193 Teuchos::Array<GO> dist_source_support_ids( distributor.getNumImports() );
194 Teuchos::ArrayView<const GO> source_support_ids_view = source_support_ids();
195 distributor.
distribute( source_support_ids_view,
196 dist_source_support_ids() );
200 d_use_knn, d_knn, d_radius );
206 Teuchos::ArrayRCP<SupportId> children_per_parent =
207 pairings.childrenPerParent();
208 SupportId max_entries_per_row = *std::max_element(
209 children_per_parent.begin(), children_per_parent.end() );
210 d_coupling_matrix = Teuchos::rcp(
new Tpetra::CrsMatrix<Scalar, LO, GO>(
211 range_map, max_entries_per_row ) );
212 Teuchos::ArrayView<const double> target_view;
213 Teuchos::Array<GO> indices( max_entries_per_row );
214 Teuchos::ArrayView<const double> values;
215 Teuchos::ArrayView<const unsigned> pair_gids;
217 int local_num_tgt = target_support_ids.size();
218 for (
int i = 0; i < local_num_tgt; ++i )
225 target_view = target_centers( i * DIM, DIM );
230 pairings.parentSupportRadius( i ) );
233 values = local_problem.shapeFunction();
238 for (
int j = 0; j < nn; ++j )
240 indices[j] = dist_source_support_ids[pair_gids[j]];
242 d_coupling_matrix->insertGlobalValues( target_support_ids[i],
243 indices( 0, nn ), values );
246 d_coupling_matrix->fillComplete( domain_map, range_map );
247 DTK_ENSURE( d_coupling_matrix->isFillComplete() );
252 template <
class Basis,
int DIM>
254 const TpetraMultiVector &X, TpetraMultiVector &Y, Teuchos::ETransp mode,
255 double alpha,
double beta )
const 257 d_coupling_matrix->apply( X, Y, mode, alpha, beta );
262 template <
class Basis,
int DIM>
264 DIM>::hasTransposeApplyImpl()
const 271 template <
class Basis,
int DIM>
273 const Teuchos::RCP<FunctionSpace> &space,
const int entity_dim,
274 Teuchos::ArrayRCP<double> ¢ers,
275 Teuchos::ArrayRCP<GO> &support_ids )
const 279 if ( Teuchos::nonnull( space->entitySet() ) )
281 LocalEntityPredicate local_predicate(
282 space->entitySet()->communicator()->getRank() );
284 space->selectFunction(), local_predicate.getFunction() );
285 iterator = space->entitySet()->entityIterator( entity_dim, predicate );
289 int local_num_node = iterator.size();
290 centers = Teuchos::ArrayRCP<double>( DIM * local_num_node );
291 support_ids = Teuchos::ArrayRCP<GO>( local_num_node );
292 Teuchos::Array<SupportId> node_supports;
295 int entity_counter = 0;
297 ++entity, ++entity_counter )
299 space->shapeFunction()->entitySupportIds( *entity, node_supports );
300 DTK_CHECK( 1 == node_supports.size() );
301 support_ids[entity_counter] = node_supports[0];
302 space->localMap()->centroid( *entity,
303 centers( DIM * entity_counter, DIM ) );
313 #endif // end DTK_MOVINGLEASTSQUARERECONSTRUCTIONOPERATOR_IMPL_HPP MovingLeastSquareReconstructionOperator(const Teuchos::RCP< const TpetraMap > &domain_map, const Teuchos::RCP< const TpetraMap > &range_map, const Teuchos::ParameterList ¶meters)
Constructor.
Local moving least square problem.
Local source/parent center pairings.
Parallel moving least square interpolator.
Parallel moving least square interpolator MapOperator implementation.
void applyImpl(const TpetraMultiVector &X, TpetraMultiVector &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, double alpha=Teuchos::ScalarTraits< double >::one(), double beta=Teuchos::ScalarTraits< double >::zero()) const override
Apply the operator.
Entity iterator interface.
unsigned long int SupportId
Support id type.
static Teuchos::RCP< RadialBasis > create()
Creation method.
Assertions and Design-by-Contract for error handling.
MapOperator Base
Typedefs.
std::function< bool(Entity)> PredicateFunction
Predicate function typedef.
Global source distributor.
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.
Global center distributor.
Local moving least square problem about a single target center using quadratic polynomials.
Local child/parent center pairings.
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.