10 #ifndef MUELU_DISTANCELAPLACIANDROPPING_HPP
11 #define MUELU_DISTANCELAPLACIANDROPPING_HPP
13 #include "Kokkos_Macros.hpp"
14 #include "KokkosBatched_LU_Decl.hpp"
15 #include "KokkosBatched_LU_Serial_Impl.hpp"
16 #include "KokkosBatched_Trsv_Decl.hpp"
17 #include "KokkosBatched_Trsv_Serial_Impl.hpp"
19 #include "Kokkos_Core.hpp"
20 #include "Kokkos_ArithTraits.hpp"
24 #include "Xpetra_MultiVectorFactory.hpp"
26 namespace MueLu::DistanceLaplacian {
32 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
39 using ATS = Kokkos::ArithTraits<scalar_type>;
41 using implATS = Kokkos::ArithTraits<impl_scalar_type>;
43 using magATS = Kokkos::ArithTraits<magnitudeType>;
57 if (!importer.is_null()) {
68 KOKKOS_FORCEINLINE_FUNCTION
72 for (
size_t j = 0; j <
coords.extent(1); ++j) {
80 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
87 using ATS = Kokkos::ArithTraits<scalar_type>;
89 using implATS = Kokkos::ArithTraits<impl_scalar_type>;
91 using magATS = Kokkos::ArithTraits<magnitudeType>;
114 if (!importer.is_null()) {
133 KOKKOS_INLINE_FUNCTION
143 for (
size_t j = 0; j <
coords.extent(1); ++j) {
151 return Kokkos::max(d_row, d_col);
155 template <
class local_ordinal_type,
class material_vector_type,
class material_matrix_type>
162 TensorInversion(material_vector_type& material_vector_, material_matrix_type& material_matrix_)
166 KOKKOS_FORCEINLINE_FUNCTION
173 auto matrix_material = Kokkos::subview(
material_matrix, i, Kokkos::ALL(), Kokkos::ALL());
174 KokkosBatched::SerialLU<KokkosBatched::Algo::LU::Unblocked>::invoke(matrix_material);
178 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
185 using ATS = Kokkos::ArithTraits<scalar_type>;
187 using implATS = Kokkos::ArithTraits<impl_scalar_type>;
189 using magATS = Kokkos::ArithTraits<magnitudeType>;
215 if (!importer.is_null()) {
227 if (!importer.is_null()) {
231 ghostedMaterial = material_;
234 using execution_space =
typename Node::execution_space;
235 using range_type = Kokkos::RangePolicy<LocalOrdinal, execution_space>;
238 auto lclMaterial = ghostedMaterial->getDeviceLocalView(Xpetra::Access::ReadOnly);
242 Kokkos::parallel_for(
"MueLu:TensorMaterialDistanceFunctor::inversion", range_type(0, lclMaterial.extent(0)), functor);
246 KOKKOS_INLINE_FUNCTION
255 auto matrix_row_material = Kokkos::subview(
material, row, Kokkos::ALL(), Kokkos::ALL());
256 auto dist = Kokkos::subview(
lcl_dist, row, Kokkos::ALL());
258 for (
size_t j = 0; j <
coords.extent(1); ++j) {
262 KokkosBatched::SerialTrsv<KokkosBatched::Uplo::Lower, KokkosBatched::Trans::NoTranspose, KokkosBatched::Diag::Unit, KokkosBatched::Algo::Trsv::Unblocked>::invoke(
one, matrix_row_material, dist);
263 KokkosBatched::SerialTrsv<KokkosBatched::Uplo::Upper, KokkosBatched::Trans::NoTranspose, KokkosBatched::Diag::NonUnit, KokkosBatched::Algo::Trsv::Unblocked>::invoke(
one, matrix_row_material, dist);
265 for (
size_t j = 0; j <
coords.extent(1); ++j) {
273 auto matrix_col_material = Kokkos::subview(
material, col, Kokkos::ALL(), Kokkos::ALL());
274 auto dist = Kokkos::subview(
lcl_dist, row, Kokkos::ALL());
276 for (
size_t j = 0; j <
coords.extent(1); ++j) {
280 KokkosBatched::SerialTrsv<KokkosBatched::Uplo::Lower, KokkosBatched::Trans::NoTranspose, KokkosBatched::Diag::Unit, KokkosBatched::Algo::Trsv::Unblocked>::invoke(
one, matrix_col_material, dist);
281 KokkosBatched::SerialTrsv<KokkosBatched::Uplo::Upper, KokkosBatched::Trans::NoTranspose, KokkosBatched::Diag::NonUnit, KokkosBatched::Algo::Trsv::Unblocked>::invoke(
one, matrix_col_material, dist);
283 for (
size_t j = 0; j <
coords.extent(1); ++j) {
288 return Kokkos::max(implATS::magnitude(d_row), implATS::magnitude(d_col));
295 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class DistanceFunctorType>
298 DistanceFunctorType& distFunctor) {
299 using scalar_type =
Scalar;
302 using node_type =
Node;
303 using ATS = Kokkos::ArithTraits<scalar_type>;
304 using impl_scalar_type =
typename ATS::val_type;
305 using implATS = Kokkos::ArithTraits<impl_scalar_type>;
306 using magnitudeType =
typename implATS::magnitudeType;
307 using execution_space =
typename Node::execution_space;
308 using range_type = Kokkos::RangePolicy<LocalOrdinal, execution_space>;
312 auto lclA = A.getLocalMatrixDevice();
313 auto lclDiag = diag->getDeviceLocalView(Xpetra::Access::OverwriteAll);
315 Kokkos::parallel_for(
316 "MueLu:CoalesceDropF:Build:scalar_filter:laplacian_diag",
317 range_type(0, lclA.numRows()),
318 KOKKOS_LAMBDA(
const local_ordinal_type& row) {
319 auto rowView = lclA.rowConst(row);
320 auto length = rowView.length;
323 impl_scalar_type d2 = implATS::zero();
324 for (local_ordinal_type colID = 0; colID < length; colID++) {
325 auto col = rowView.colidx(colID);
327 d = distFunctor.distance2(row, col);
328 d2 += implATS::one() / d;
331 lclDiag(row, 0) = d2;
335 if (!importer.is_null()) {
354 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class DistanceFunctorType>
363 using diag_view_type =
typename Kokkos::DualView<const scalar_type*, Kokkos::LayoutStride, typename Node::device_type, Kokkos::MemoryUnmanaged>::t_dev;
367 using ATS = Kokkos::ArithTraits<scalar_type>;
381 :
A(A_.getLocalMatrixDevice())
386 auto lclDiag2d =
diagVec->getDeviceLocalView(Xpetra::Access::ReadOnly);
387 diag = Kokkos::subview(lclDiag2d, Kokkos::ALL(), 0);
390 KOKKOS_FORCEINLINE_FUNCTION
392 auto row =
A.rowConst(rlid);
393 const size_t offset =
A.graph.row_map(rlid);
395 auto clid = row.colidx(k);
399 val =
one /
dist2.distance2(rlid, clid);
403 auto aiiajj = ATS::magnitude(
diag(rlid)) * ATS::magnitude(
diag(clid));
404 auto aij2 = ATS::magnitude(val) * ATS::magnitude(val);
Drops entries the unscaled distance Laplacian.
typename matrix_type::local_matrix_type local_matrix_type
typename matrix_type::local_matrix_type local_matrix_type
local_coords_type ghostedCoords
typename material_type::dual_view_type_const::t_dev local_material_type
Teuchos::RCP< diag_vec_type > diagVec
MueLu::DefaultLocalOrdinal LocalOrdinal
UnweightedDistanceFunctor(matrix_type &A, Teuchos::RCP< coords_type > &coords_)
Teuchos::RCP< coords_type > coordsMV
material_vector_type material_vector
Teuchos::RCP< material_type > materialMV
static Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node >> &map, size_t NumVectors, bool zeroOut=true)
typename coords_type::dual_view_type_const::t_dev local_coords_type
DropFunctor(matrix_type &A_, magnitudeType threshold, DistanceFunctorType &dist2_, results_view &results_)
Kokkos::ArithTraits< magnitudeType > magATS
Kokkos::ArithTraits< scalar_type > ATS
Kokkos::ArithTraits< scalar_type > ATS
typename local_matrix_type::memory_space memory_space
typename Kokkos::DualView< const scalar_type *, Kokkos::LayoutStride, typename Node::device_type, Kokkos::MemoryUnmanaged >::t_dev diag_view_type
typename ATS::val_type impl_scalar_type
typename coords_type::dual_view_type_const::t_dev local_coords_type
typename matrix_type::local_matrix_type local_matrix_type
typename ATS::val_type impl_scalar_type
KOKKOS_INLINE_FUNCTION magnitudeType distance2(const local_ordinal_type row, const local_ordinal_type col) const
typename local_matrix_type::value_type scalar_type
typename implATS::magnitudeType magnitudeType
KOKKOS_INLINE_FUNCTION magnitudeType distance2(const local_ordinal_type row, const local_ordinal_type col) const
Teuchos::RCP< material_type > ghostedMaterialMV
Teuchos::RCP< coords_type > ghostedCoordsMV
typename implATS::magnitudeType magnitudeType
local_material_type ghostedMaterial
Teuchos::RCP< coords_type > coordsMV
typename matrix_type::local_matrix_type local_matrix_type
virtual void doImport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &source, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)=0
Kokkos::ArithTraits< impl_scalar_type > implATS
Teuchos::RCP< coords_type > ghostedCoordsMV
TensorMaterialDistanceFunctor(matrix_type &A, Teuchos::RCP< coords_type > &coords_, Teuchos::RCP< material_type > &material_)
typename local_matrix_type::memory_space memory_space
local_material_type material
MueLu::DefaultScalar Scalar
MueLu::DefaultGlobalOrdinal GlobalOrdinal
Kokkos::ArithTraits< impl_scalar_type > implATS
LocalOrdinal local_ordinal_type
typename local_matrix_type::value_type scalar_type
TensorInversion(material_vector_type &material_vector_, material_matrix_type &material_matrix_)
Kokkos::View< DecisionType *, memory_space > results_view
typename coords_type::dual_view_type_const::t_dev local_coords_type
typename local_matrix_type::value_type scalar_type
ScalarMaterialDistanceFunctor(matrix_type &A, Teuchos::RCP< coords_type > &coords_, Teuchos::RCP< material_type > &material_)
LocalOrdinal local_ordinal_type
typename ATS::val_type impl_scalar_type
Kokkos::View< const bool *, memory_space > boundary_nodes_view
Kokkos::ArithTraits< impl_scalar_type > implATS
KOKKOS_FORCEINLINE_FUNCTION magnitudeType distance2(const local_ordinal_type row, const local_ordinal_type col) const
typename implATS::magnitudeType magnitudeType
Kokkos::View< impl_scalar_type **, memory_space > local_dist_type
virtual RCP< const CrsGraph > getCrsGraph() const =0
local_material_type material
typename ATS::magnitudeType magnitudeType
Kokkos::ArithTraits< scalar_type > ATS
typename local_matrix_type::ordinal_type local_ordinal_type
typename local_matrix_type::value_type scalar_type
Kokkos::ArithTraits< magnitudeType > magATS
DistanceFunctorType dist2
local_coords_type ghostedCoords
KOKKOS_FORCEINLINE_FUNCTION void operator()(local_ordinal_type i) const
local_coords_type ghostedCoords
Teuchos::RCP< Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getDiagonal(Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, DistanceFunctorType &distFunctor)
Kokkos::View< impl_scalar_type ***, memory_space > local_material_type
Teuchos::RCP< coords_type > ghostedCoordsMV
LocalOrdinal local_ordinal_type
virtual size_t getNumVectors() const =0
material_matrix_type material_matrix
Teuchos::RCP< coords_type > coordsMV
KOKKOS_FORCEINLINE_FUNCTION void operator()(local_ordinal_type rlid) const
Kokkos::ArithTraits< scalar_type > ATS
Kokkos::ArithTraits< magnitudeType > magATS