10 #ifndef MUELU_SCHURCOMPLEMENTFACTORY_DEF_HPP_
11 #define MUELU_SCHURCOMPLEMENTFACTORY_DEF_HPP_
14 #include <Xpetra_MultiVectorFactory.hpp>
20 #include <Xpetra_CrsMatrixWrap.hpp>
29 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
36 validParamList->
set<
RCP<const FactoryBase>>(
"Ainv", Teuchos::null,
"Generating factory of the inverse matrix used in the Schur complement");
38 validParamList->
set<
SC>(
"omega", one,
"Scaling parameter in S = A(1,1) - 1/omega A(1,0) Ainv A(0,1)");
40 return validParamList;
43 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
45 Input(currentLevel,
"A");
52 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
56 RCP<Matrix> A = Get<RCP<Matrix>>(currentLevel,
"A");
60 "MueLu::SchurComplementFactory::Build: input matrix A is not of type BlockedCrsMatrix!");
62 "MueLu::SchurComplementFactory::Build: input matrix A is a " << bA->Rows() <<
"x" << bA->Cols() <<
" block matrix. We expect a 2x2 blocked operator.");
68 GetOStream(
Statistics1) <<
"S has " << S->getGlobalNumRows() <<
"x" << S->getGlobalNumCols() <<
" rows and columns." << std::endl;
72 Set(currentLevel,
"A", S);
75 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
79 const SC zero = STS::zero(), one = STS::one();
86 const bool isBlocked = (bA01 == Teuchos::null ?
false :
true);
92 "MueLu::SchurComplementFactory::Build: Scaling parameter omega must not be zero to avoid division by zero.");
100 Ainv->scale(Teuchos::as<Scalar>(-one / omega));
105 myparams->
set(
"compute global constants",
true);
108 TEUCHOS_TEST_FOR_EXCEPTION(A01->getRangeMap()->isSameAs(*(Ainv->getDomainMap())) ==
false,
Exceptions::RuntimeError,
109 "MueLu::SchurComplementFactory::Build: RangeMap of A01 and domain map of Ainv are not the same.");
110 RCP<Matrix> C = MatrixMatrix::Multiply(*Ainv,
false, *A01,
false, GetOStream(
Statistics2),
true,
true, std::string(
"SchurComplementFactory"), myparams);
114 "MueLu::SchurComplementFactory::Build: RangeMap of A10 and domain map A01 are not the same.");
115 D = MatrixMatrix::Multiply(*A10,
false, *C,
false, GetOStream(
Statistics2),
true,
true, std::string(
"SchurComplementFactory"), myparams);
118 auto bA10 = Teuchos::rcp_dynamic_cast<BlockedCrsMatrix>(A10);
119 auto bAinv = Teuchos::rcp_dynamic_cast<BlockedCrsMatrix>(Ainv);
121 "MueLu::SchurComplementFactory::Build: Casting Ainv to BlockedCrsMatrix not possible.");
125 "MueLu::SchurComplementFactory::Build: Block rows and cols of bA01 and bAinv are not compatible.");
130 "MueLu::SchurComplementFactory::Build: Block rows and cols of bA10 and bA01 are not compatible.");
131 D = MatrixMatrix::TwoMatrixMultiplyBlock(*bA10,
false, *C,
false, GetOStream(
Statistics2));
134 MatrixMatrix::TwoMatrixAdd(*A11,
false, one, *D,
false, one, S, GetOStream(
Statistics2));
138 "MueLu::SchurComplementFactory::Build: RangeMap of A11 and S are not the same.");
140 "MueLu::SchurComplementFactory::Build: DomainMap of A11 and S are not the same.");
142 S = MatrixFactory::BuildCopy(D);
146 S = MatrixFactory::BuildCopy(A11);
149 "MueLu::SchurComplementFactory::Build: Constructing Schur complement for matrix with zero block row or column.");
162 if (bS != Teuchos::null && bS->Rows() == 1 && bS->Cols() == 1) {
Exception indicating invalid cast attempted.
RCP< Matrix > ComputeSchurComplement(RCP< BlockedCrsMatrix > &bA, RCP< Matrix > &Ainv) const
Schur complement calculation method.
T & get(const std::string &name, T def_value)
Timer to be used in factories. Similar to Monitor but with additional timers.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void swap(RCP< T > &r_ptr)
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
void DeclareInput(Level ¤tLevel) const
Input.
Print even more statistics.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
MueLu::DefaultScalar Scalar
Class that holds all level-specific information.
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
void Build(Level ¤tLevel) const
Build an object with this factory.
static const RCP< const NoFactory > getRCP()
Static Get() functions.
Exception throws to report errors in the internal logical of the program.
void DeclareInput(const std::string &ename, const FactoryBase *factory, const FactoryBase *requestedBy=NoFactory::get())
Callback from FactoryBase::CallDeclareInput() and FactoryBase::DeclareInput()