46 #ifndef MUELU_SCHURCOMPLEMENTFACTORY_DEF_HPP_
47 #define MUELU_SCHURCOMPLEMENTFACTORY_DEF_HPP_
50 #include <Xpetra_MultiVectorFactory.hpp>
56 #include <Xpetra_CrsMatrixWrap.hpp>
65 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
72 validParamList->
set<
RCP<const FactoryBase>>(
"Ainv", Teuchos::null,
"Generating factory of the inverse matrix used in the Schur complement");
74 validParamList->
set<
SC>(
"omega", one,
"Scaling parameter in S = A(1,1) - 1/omega A(1,0) Ainv A(0,1)");
76 return validParamList;
79 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
81 Input(currentLevel,
"A");
88 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
92 RCP<Matrix> A = Get<RCP<Matrix>>(currentLevel,
"A");
96 "MueLu::SchurComplementFactory::Build: input matrix A is not of type BlockedCrsMatrix!");
98 "MueLu::SchurComplementFactory::Build: input matrix A is a " << bA->Rows() <<
"x" << bA->Cols() <<
" block matrix. We expect a 2x2 blocked operator.");
104 GetOStream(
Statistics1) <<
"S has " << S->getGlobalNumRows() <<
"x" << S->getGlobalNumCols() <<
" rows and columns." << std::endl;
108 Set(currentLevel,
"A", S);
111 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
115 const SC zero = STS::zero(), one = STS::one();
122 const bool isBlocked = (bA01 == Teuchos::null ?
false :
true);
128 "MueLu::SchurComplementFactory::Build: Scaling parameter omega must not be zero to avoid division by zero.");
136 Ainv->scale(Teuchos::as<Scalar>(-one / omega));
141 myparams->
set(
"compute global constants",
true);
144 TEUCHOS_TEST_FOR_EXCEPTION(A01->getRangeMap()->isSameAs(*(Ainv->getDomainMap())) ==
false,
Exceptions::RuntimeError,
145 "MueLu::SchurComplementFactory::Build: RangeMap of A01 and domain map of Ainv are not the same.");
146 RCP<Matrix> C = MatrixMatrix::Multiply(*Ainv,
false, *A01,
false, GetOStream(
Statistics2),
true,
true, std::string(
"SchurComplementFactory"), myparams);
150 "MueLu::SchurComplementFactory::Build: RangeMap of A10 and domain map A01 are not the same.");
151 D = MatrixMatrix::Multiply(*A10,
false, *C,
false, GetOStream(
Statistics2),
true,
true, std::string(
"SchurComplementFactory"), myparams);
154 auto bA10 = Teuchos::rcp_dynamic_cast<BlockedCrsMatrix>(A10);
155 auto bAinv = Teuchos::rcp_dynamic_cast<BlockedCrsMatrix>(Ainv);
157 "MueLu::SchurComplementFactory::Build: Casting Ainv to BlockedCrsMatrix not possible.");
161 "MueLu::SchurComplementFactory::Build: Block rows and cols of bA01 and bAinv are not compatible.");
166 "MueLu::SchurComplementFactory::Build: Block rows and cols of bA10 and bA01 are not compatible.");
167 D = MatrixMatrix::TwoMatrixMultiplyBlock(*bA10,
false, *C,
false, GetOStream(
Statistics2));
170 MatrixMatrix::TwoMatrixAdd(*A11,
false, one, *D,
false, one, S, GetOStream(
Statistics2));
174 "MueLu::SchurComplementFactory::Build: RangeMap of A11 and S are not the same.");
176 "MueLu::SchurComplementFactory::Build: DomainMap of A11 and S are not the same.");
178 S = MatrixFactory::BuildCopy(D);
182 S = MatrixFactory::BuildCopy(A11);
184 S = MatrixFactory::Build(A11->getRowMap(), 10 );
185 S->fillComplete(A11->getDomainMap(), A11->getRangeMap());
198 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)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
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)
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.
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()
static const RCP< const NoFactory > getRCP()
Static Get() functions.