47#ifndef MUELU_SEGREGATEDAFACTORY_DEF_HPP
48#define MUELU_SEGREGATEDAFACTORY_DEF_HPP
50#include <Xpetra_Matrix.hpp>
51#include <Xpetra_MatrixFactory.hpp>
55#include "MueLu_FactoryManager.hpp"
62 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
64 RCP<ParameterList> validParamList = rcp(
new ParameterList());
66#define SET_VALID_ENTRY(name) validParamList->setEntry(name, MasterList::getEntry(name))
69 validParamList->set< RCP<const FactoryBase> >(
"A", Teuchos::null,
"Generating factory of the matrix A used for filtering");
71 validParamList->set< std::string > (
"map: name",
"",
"Name of map (Xpetra::Map) provided by user containing the special DOFs.");
72 validParamList->set< std::string > (
"map: factory",
"null",
"Name of generating factory for 'map: name'");
74 return validParamList;
77 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
79 Input(currentLevel,
"A");
81 const ParameterList& pL = GetParameterList();
82 std::string mapName = pL.get<std::string> (
"map: name");
83 std::string mapFact = pL.get<std::string> (
"map: factory");
84 if(mapFact ==
"NoFactory") {
86 }
else if (mapFact !=
"null") {
87 Teuchos::RCP<const FactoryBase> fact = currentLevel.
GetFactoryManager()->GetFactory(mapFact);
94 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
96 FactoryMonitor m(*
this,
"Matrix filtering (segregation)", currentLevel);
99 RCP<Matrix> Ain = Get< RCP<Matrix> >(currentLevel,
"A");
101 const ParameterList& pL = GetParameterList();
102 std::string mapName = pL.get<std::string> (
"map: name");
103 std::string mapFact = pL.get<std::string> (
"map: factory");
105 Teuchos::RCP<const FactoryBase> mapFactory = Teuchos::null;
106 if(mapFact ==
"NoFactory") {
108 }
else if (mapFact !=
"null") {
112 Teuchos::RCP<Map> map = currentLevel.
Get< Teuchos::RCP<Map> >(mapName,mapFactory.get());
115 Teuchos::RCP<Matrix> Aout = MatrixFactory::Build(Ain->getRowMap(), Ain->getGlobalMaxNumRowEntries());
117 size_t numLocalRows = Ain->getLocalNumRows();
118 for(
size_t row=0; row<numLocalRows; row++) {
119 GlobalOrdinal grid = Ain->getRowMap()->getGlobalElement(row);
120 bool isInMap = map->isNodeGlobalElement(grid);
123 Teuchos::ArrayView<const LocalOrdinal> indices;
124 Teuchos::ArrayView<const Scalar> vals;
125 Ain->getLocalRowView(row, indices, vals);
128 Teuchos::ArrayRCP<GlobalOrdinal> indout(indices.size(),Teuchos::ScalarTraits<GlobalOrdinal>::zero());
129 Teuchos::ArrayRCP<Scalar> valout(indices.size(),Teuchos::ScalarTraits<Scalar>::zero());
131 size_t nNonzeros = 0;
132 for(
size_t i=0; i<(size_t)indices.size(); i++) {
133 GlobalOrdinal gcid = Ain->getColMap()->getGlobalElement(indices[i]);
134 bool isInMap2 = map->isNodeGlobalElement(gcid);
136 if (isInMap == isInMap2) {
137 indout [nNonzeros] = gcid;
138 valout [nNonzeros] = vals[i];
142 indout.resize(nNonzeros);
143 valout.resize(nNonzeros);
145 Aout->insertGlobalValues(Ain->getRowMap()->getGlobalElement(row), indout.view(0,indout.size()), valout.view(0,valout.size()));
148 Aout->fillComplete(Ain->getDomainMap(), Ain->getRangeMap());
151 Aout->SetFixedBlockSize(Ain->GetFixedBlockSize());
153 GetOStream(
Statistics0, 0) <<
"Nonzeros in A (input): " << Ain->getGlobalNumEntries() <<
", Nonzeros after filtering A: " << Aout->getGlobalNumEntries() << std::endl;
155 Set(currentLevel,
"A", Aout);
MueLu::DefaultGlobalOrdinal GlobalOrdinal
Timer to be used in factories. Similar to Monitor but with additional timers.
Class that holds all level-specific information.
void DeclareInput(const std::string &ename, const FactoryBase *factory, const FactoryBase *requestedBy=NoFactory::get())
Callback from FactoryBase::CallDeclareInput() and FactoryBase::DeclareInput()
const RCP< const FactoryManagerBase > GetFactoryManager()
returns the current factory manager
T & Get(const std::string &ename, const FactoryBase *factory=NoFactory::get())
Get data without decrementing associated storage counter (i.e., read-only access)....
static const RCP< const NoFactory > getRCP()
Static Get() functions.
static const NoFactory * get()
void DeclareInput(Level ¤tLevel) const
Input.
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
void Build(Level ¤tLevel) const
Build method.
Namespace for MueLu classes and methods.
@ Statistics0
Print statistics that do not involve significant additional computation.