MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MueLu_ThresholdAFilterFactory_def.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // MueLu: A package for multigrid based preconditioning
4 //
5 // Copyright 2012 NTESS and the MueLu contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef MUELU_THRESHOLDAFILTERFACTORY_DEF_HPP
11 #define MUELU_THRESHOLDAFILTERFACTORY_DEF_HPP
12 
13 #include <Xpetra_Matrix.hpp>
14 #include <Xpetra_CrsMatrixWrap.hpp>
15 
17 
18 #include "MueLu_Level.hpp"
19 #include "MueLu_Monitor.hpp"
20 
21 namespace MueLu {
22 
23 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
24 ThresholdAFilterFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::ThresholdAFilterFactory(const std::string& ename, const magnitudeType threshold, const bool keepDiagonal, const GlobalOrdinal expectedNNZperRow)
25  : varName_(ename)
26  , threshold_(threshold)
27  , keepDiagonal_(keepDiagonal)
28  , expectedNNZperRow_(expectedNNZperRow) {}
29 
30 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
32  Input(currentLevel, varName_);
33 }
34 
35 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
37  Build(Level& currentLevel) const {
38  FactoryMonitor m(*this, "A filter (thresholding)", currentLevel);
39 
40  RCP<Matrix> Ain = Get<RCP<Matrix> >(currentLevel, varName_);
41  RCP<CrsMatrixWrap> Aout =
42  MueLu::Utilities<Scalar, LocalOrdinal, GlobalOrdinal, Node>::GetThresholdedMatrix(Ain, threshold_, keepDiagonal_, expectedNNZperRow_);
43 
44  GetOStream(Statistics0) << "Nonzeros in " << varName_ << "(input): " << Ain->getGlobalNumEntries() << ", Nonzeros after filtering " << varName_ << " (parameter: " << threshold_ << "): " << Aout->getGlobalNumEntries() << std::endl;
45  currentLevel.Set(varName_, Teuchos::rcp_dynamic_cast<Matrix>(Aout), this);
46 }
47 
48 } // namespace MueLu
49 
50 #endif // MUELU_THRESHOLDAFILTERFACTORY_DEF_HPP
void DeclareInput(Level &currentLevel) const
Input.
Timer to be used in factories. Similar to Monitor but with additional timers.
Print statistics that do not involve significant additional computation.
MueLu::DefaultGlobalOrdinal GlobalOrdinal
static RCP< CrsMatrixWrap > GetThresholdedMatrix(const RCP< Matrix > &Ain, const Magnitude threshold, const bool keepDiagonal=true, const GlobalOrdinal expectedNNZperRow=-1)
Threshold a matrix.
Class that holds all level-specific information.
Definition: MueLu_Level.hpp:63
ThresholdAFilterFactory(const std::string &ename, const magnitudeType threshold, const bool keepDiagonal=true, const GlobalOrdinal expectedNNZperRow=-1)
Constructor.
void Build(Level &currentLevel) const
Build an object with this factory.
typename Teuchos::ScalarTraits< Scalar >::magnitudeType magnitudeType