46 #ifndef MUELU_THRESHOLDAFILTERFACTORY_DEF_HPP 47 #define MUELU_THRESHOLDAFILTERFACTORY_DEF_HPP 49 #include <Xpetra_Matrix.hpp> 50 #include <Xpetra_CrsMatrixWrap.hpp> 59 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
61 : varName_(ename), threshold_(threshold)
64 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
67 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
69 Input(currentLevel, varName_);
72 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
78 typedef Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> OMatrix;
79 typedef Xpetra::CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node> CrsOMatrix;
81 RCP<OMatrix> Ain = Get< RCP<OMatrix> >(currentLevel, varName_);
84 RCP<CrsOMatrix> Aout =
rcp(
new CrsOMatrix(Ain->getRowMap(),Ain->getGlobalMaxNumRowEntries(),Xpetra::StaticProfile));
87 for(
size_t row=0; row<Ain->getNodeNumRows(); row++)
89 size_t nnz = Ain->getNumEntriesInLocalRow(row);
93 Ain->getLocalRowView(row, indices, vals);
100 for(
size_t i=0; i<(size_t)indices.
size(); i++) {
102 indout[nNonzeros] = Ain->getColMap()->getGlobalElement(indices[i]);
103 valout[nNonzeros] = vals[i];
109 valout.resize(nNonzeros);
111 Aout->insertGlobalValues(Ain->getRowMap()->getGlobalElement(row), indout.view(0,indout.size()), valout.view(0,valout.size()));
114 Aout->fillComplete(Ain->getDomainMap(), Ain->getRangeMap());
116 GetOStream(
Statistics0) <<
"Nonzeros in " << varName_ <<
"(input): " << Ain->getGlobalNumEntries() <<
", Nonzeros after filtering " << varName_ <<
" (parameter: " << threshold_ <<
"): " << Aout->getGlobalNumEntries() << std::endl;
118 currentLevel.Set(varName_, Teuchos::rcp_dynamic_cast<OMatrix>(Aout),
this);
123 #endif // MUELU_THRESHOLDAFILTERFACTORY_DEF_HPP Timer to be used in factories. Similar to Monitor but with additional timers.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Namespace for MueLu classes and methods.
void resize(const size_type n, const T &val=T())
Print statistics that do not involve significant additional computation.
void Build(Level ¤tLevel) const
Build an object with this factory.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Class that holds all level-specific information.
virtual ~ThresholdAFilterFactory()
Destructor.
void DeclareInput(Level ¤tLevel) const
Input.
ThresholdAFilterFactory(const std::string &ename, const Scalar threshold)
Constructor.
static magnitudeType magnitude(T a)
Exception throws to report errors in the internal logical of the program.