46 #ifndef MUELU_MAXWELL_UTILS_DEF_HPP
47 #define MUELU_MAXWELL_UTILS_DEF_HPP
53 #include "Xpetra_Map.hpp"
60 #include "MueLu_ThresholdAFilterFactory.hpp"
61 #include "MueLu_Utilities.hpp"
62 #include "MueLu_RAPFactory.hpp"
66 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
71 Kokkos::View<bool*, typename Node::device_type::memory_space>& BCrowsKokkos_,
72 Kokkos::View<bool*, typename Node::device_type::memory_space>& BCcolsKokkos_,
73 Kokkos::View<bool*, typename Node::device_type::memory_space>& BCdomainKokkos_,
79 bool& allEdgesBoundary_,
80 bool& allNodesBoundary_) {
93 BCcolsKokkos_ = Kokkos::View<bool*, typename Node::device_type>(Kokkos::ViewAllocateWithoutInitializing(
"dirichletCols"), D0_Matrix_->getColMap()->getLocalNumElements());
94 BCdomainKokkos_ = Kokkos::View<bool*, typename Node::device_type>(Kokkos::ViewAllocateWithoutInitializing(
"dirichletDomains"), D0_Matrix_->getDomainMap()->getLocalNumElements());
97 auto BCrowsKokkos = BCrowsKokkos_;
98 Kokkos::parallel_reduce(
99 BCrowsKokkos_.size(), KOKKOS_LAMBDA(
int i,
int& sum) {
105 auto BCdomainKokkos = BCdomainKokkos_;
106 Kokkos::parallel_reduce(
107 BCdomainKokkos_.size(), KOKKOS_LAMBDA(
int i,
int& sum) {
108 if (BCdomainKokkos(i))
118 BCcols_.
resize(D0_Matrix_->getColMap()->getLocalNumElements());
119 BCdomain_.
resize(D0_Matrix_->getDomainMap()->getLocalNumElements());
122 for (
auto it = BCrows_.
begin(); it != BCrows_.
end(); ++it)
125 for (
auto it = BCdomain_.
begin(); it != BCdomain_.
end(); ++it)
130 MueLu_sumAll(SM_Matrix_->getRowMap()->getComm(), BCedgesLocal, BCedges_);
131 MueLu_sumAll(SM_Matrix_->getRowMap()->getComm(), BCnodesLocal, BCnodes_);
133 allEdgesBoundary_ = Teuchos::as<Xpetra::global_size_t>(BCedges_) >= D0_Matrix_->getRangeMap()->getGlobalNumElements();
134 allNodesBoundary_ = Teuchos::as<Xpetra::global_size_t>(BCnodes_) >= D0_Matrix_->getDomainMap()->getGlobalNumElements();
137 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
141 Kokkos::View<bool*, typename Node::device_type::memory_space>& BCrowsKokkos_,
142 Kokkos::View<bool*, typename Node::device_type::memory_space>& BCcolsKokkos_,
143 Kokkos::View<bool*, typename Node::device_type::memory_space>& BCdomainKokkos_,
146 bool& allEdgesBoundary_,
147 bool& allNodesBoundary_) {
152 int BCedgesLocal = 0;
153 int BCnodesLocal = 0;
160 BCcolsKokkos_ = Kokkos::View<bool*, typename Node::device_type>(Kokkos::ViewAllocateWithoutInitializing(
"dirichletCols"), D0_Matrix_->getColMap()->getLocalNumElements());
161 BCdomainKokkos_ = Kokkos::View<bool*, typename Node::device_type>(Kokkos::ViewAllocateWithoutInitializing(
"dirichletDomains"), D0_Matrix_->getDomainMap()->getLocalNumElements());
164 auto BCrowsKokkos = BCrowsKokkos_;
165 Kokkos::parallel_reduce(
166 BCrowsKokkos_.size(), KOKKOS_LAMBDA(
int i,
int& sum) {
172 auto BCdomainKokkos = BCdomainKokkos_;
173 Kokkos::parallel_reduce(
174 BCdomainKokkos_.size(), KOKKOS_LAMBDA(
int i,
int& sum) {
175 if (BCdomainKokkos(i))
181 MueLu_sumAll(SM_Matrix_->getRowMap()->getComm(), BCedgesLocal, BCedges_);
182 MueLu_sumAll(SM_Matrix_->getRowMap()->getComm(), BCnodesLocal, BCnodes_);
184 allEdgesBoundary_ = Teuchos::as<Xpetra::global_size_t>(BCedges_) >= D0_Matrix_->getRangeMap()->getGlobalNumElements();
185 allNodesBoundary_ = Teuchos::as<Xpetra::global_size_t>(BCnodes_) >= D0_Matrix_->getDomainMap()->getGlobalNumElements();
188 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
192 const bool keepDiagonal,
193 const size_t expectedNNZperRow) {
197 fineLevel.
Set(
"A", A);
198 fineLevel.
setlib(A->getDomainMap()->lib());
201 ThreshFact->
Build(fineLevel);
205 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
211 bool defaultFilter =
false;
216 if (parameterList_.
get<
bool>(
"refmaxwell: filter D0",
true) && D0_Matrix_->getLocalMaxNumRowEntries() > 2) {
217 D0_Matrix_ = removeExplicitZeros(D0_Matrix_, 1e-8,
false, 2);
220 defaultFilter =
true;
223 if (!M1_Matrix_.
is_null() && parameterList_.
get<
bool>(
"refmaxwell: filter M1", defaultFilter)) {
224 RCP<Vector> diag = VectorFactory::Build(M1_Matrix_->getRowMap());
226 M1_Matrix_->getLocalDiagCopy(*diag);
229 M1_Matrix_ = removeExplicitZeros(M1_Matrix_, threshold,
true);
232 if (!Ms_Matrix_.
is_null() && parameterList_.
get<
bool>(
"refmaxwell: filter Ms", defaultFilter)) {
233 RCP<Vector> diag = VectorFactory::Build(Ms_Matrix_->getRowMap());
235 Ms_Matrix_->getLocalDiagCopy(*diag);
238 Ms_Matrix_ = removeExplicitZeros(Ms_Matrix_, threshold,
true);
241 if (!SM_Matrix_.
is_null() && parameterList_.
get<
bool>(
"refmaxwell: filter SM", defaultFilter)) {
242 RCP<Vector> diag = VectorFactory::Build(SM_Matrix_->getRowMap());
244 SM_Matrix_->getLocalDiagCopy(*diag);
247 SM_Matrix_ = removeExplicitZeros(SM_Matrix_, threshold,
true);
251 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
255 using ATS = Kokkos::ArithTraits<Scalar>;
256 using impl_Scalar =
typename ATS::val_type;
257 using impl_ATS = Kokkos::ArithTraits<impl_Scalar>;
258 using range_type = Kokkos::RangePolicy<LO, typename NO::execution_space>;
260 const impl_Scalar impl_SC_ONE = impl_ATS::one();
261 const impl_Scalar impl_SC_ZERO = impl_ATS::zero();
264 auto lclMat = A->getLocalMatrixDevice();
265 Kokkos::parallel_for(
267 range_type(0, lclMat.nnz()),
268 KOKKOS_LAMBDA(
const size_t i) {
269 if (impl_ATS::magnitude(lclMat.values(i)) > threshold)
270 lclMat.values(i) = impl_SC_ONE;
272 lclMat.values(i) = impl_SC_ZERO;
277 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
282 xpImporter->setDistributorParameters(matvecParams);
285 xpExporter->setDistributorParameters(matvecParams);
288 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
292 Level fineLevel, coarseLevel;
298 fineLevel.
Set(
"A", A);
299 coarseLevel.
Set(
"P", P);
300 coarseLevel.
setlib(A->getDomainMap()->lib());
301 fineLevel.
setlib(A->getDomainMap()->lib());
307 rapList.
set(
"transpose: use implicit",
true);
308 rapList.
set(
"rap: fix zero diagonals", params.
get<
bool>(
"rap: fix zero diagonals",
true));
310 rapList.
set(
"rap: triple product", params.
get<
bool>(
"rap: triple product",
false));
320 #define MUELU_MAXWELL_UTILS_SHORT
321 #endif // ifdef MUELU_MAXWELL_UTILS_DEF_HPP
static RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > PtAPWrapper(const RCP< Matrix > &A, const RCP< Matrix > &P, Teuchos::ParameterList ¶ms, std::string &label)
Performs an P^T AP.
static void DetectDirichletColsAndDomains(const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Teuchos::ArrayRCP< bool > &dirichletRows, Teuchos::ArrayRCP< bool > dirichletCols, Teuchos::ArrayRCP< bool > dirichletDomain)
Detects Dirichlet columns & domains from a list of Dirichlet rows.
#define MueLu_sumAll(rcpComm, in, out)
T & Get(const std::string &ename, const FactoryBase *factory=NoFactory::get())
Get data without decrementing associated storage counter (i.e., read-only access). Usage: Level->Get< RCP<Matrix> >("A", factory) if factory == NULL => use default factory.
T & get(const std::string &name, T def_value)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
static void ApplyRowSumCriterion(const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Magnitude rowSumTol, Teuchos::ArrayRCP< bool > &dirichletRows)
Apply Rowsum Criterion.
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
void SetPreviousLevel(const RCP< Level > &previousLevel)
void SetFactoryManager(const RCP< const FactoryManagerBase > &factoryManager)
Set default factories (used internally by Hierarchy::SetLevel()).
void setlib(Xpetra::UnderlyingLib lib2)
void resize(const size_type n, const T &val=T())
virtual void SetParameterList(const Teuchos::ParameterList ¶mList)
Set parameters from a parameter list and return with default values.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Class that holds all level-specific information.
Teuchos::ScalarTraits< Scalar >::magnitudeType magnitudeType
static void setMatvecParams(Matrix &A, RCP< ParameterList > matvecParams)
Sets matvec params on a matrix.
static Teuchos::ArrayRCP< const bool > DetectDirichletRows(const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Magnitude &tol=Teuchos::ScalarTraits< Magnitude >::zero(), bool count_twos_as_dirichlet=false)
Detect Dirichlet rows.
virtual void setObjectLabel(const std::string &objectLabel)
static void detectBoundaryConditionsSM(RCP< Matrix > &SM_Matrix, RCP< Matrix > &D0_Matrix, magnitudeType rowSumTol, bool useKokkos_, Kokkos::View< bool *, typename Node::device_type::memory_space > &BCrowsKokkos, Kokkos::View< bool *, typename Node::device_type::memory_space > &BCcolsKokkos, Kokkos::View< bool *, typename Node::device_type::memory_space > &BCdomainKokkos, int &BCedges, int &BCnodes, Teuchos::ArrayRCP< bool > &BCrows, Teuchos::ArrayRCP< bool > &BCcols, Teuchos::ArrayRCP< bool > &BCdomain, bool &allEdgesBoundary, bool &allNodesBoundary)
Detect Dirichlet boundary conditions.
void Set(const std::string &ename, const T &entry, const FactoryBase *factory=NoFactory::get())
void Build(Level ¤tLevel) const
Build an object with this factory.
void SetLevelID(int levelID)
Set level number.
Factory for building coarse matrices.
static void thresholdedAbs(const RCP< Matrix > &A, const magnitudeType thresholded)
static Kokkos::View< bool *, typename NO::device_type::memory_space > DetectDirichletRows_kokkos(const Matrix &A, const Magnitude &tol=Teuchos::ScalarTraits< typename Teuchos::ScalarTraits< SC >::magnitudeType >::zero(), const bool count_twos_as_dirichlet=false)
Detect Dirichlet rows.
Factory for building a thresholded operator.
static RCP< Matrix > removeExplicitZeros(const RCP< Matrix > &A, const magnitudeType tolerance, const bool keepDiagonal=true, const size_t expectedNNZperRow=0)
Remove explicit zeros.
void Request(const FactoryBase &factory)
Increment the storage counter for all the inputs of a factory.