MueLu Version of the Day
Loading...
Searching...
No Matches
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
21namespace MueLu {
22
23template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
24ThresholdAFilterFactory<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
30template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
32 Input(currentLevel, varName_);
33}
34
35template <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
MueLu::DefaultGlobalOrdinal GlobalOrdinal
Timer to be used in factories. Similar to Monitor but with additional timers.
Class that holds all level-specific information.
void Set(const std::string &ename, const T &entry, const FactoryBase *factory=NoFactory::get())
void Build(Level &currentLevel) const
Build an object with this factory.
void DeclareInput(Level &currentLevel) const
Input.
ThresholdAFilterFactory(const std::string &ename, const magnitudeType threshold, const bool keepDiagonal=true, const GlobalOrdinal expectedNNZperRow=-1)
Constructor.
typename Teuchos::ScalarTraits< Scalar >::magnitudeType magnitudeType
static RCP< CrsMatrixWrap > GetThresholdedMatrix(const RCP< Matrix > &Ain, const Magnitude threshold, const bool keepDiagonal=true, const GlobalOrdinal expectedNNZperRow=-1)
Threshold a matrix.
Namespace for MueLu classes and methods.
@ Statistics0
Print statistics that do not involve significant additional computation.