10 #include "Teko_SIMPLEPreconditionerFactory.hpp"
13 #include "Teko_InverseFactory.hpp"
14 #include "Teko_BlockLowerTriInverseOp.hpp"
15 #include "Teko_BlockUpperTriInverseOp.hpp"
17 #ifdef TEKO_HAVE_EPETRA
18 #include "Teko_DiagonalPreconditionerFactory.hpp"
21 #include "Teuchos_Time.hpp"
31 : invVelFactory_(inverse),
32 invPrsFactory_(inverse),
34 fInverseType_(Diagonal),
37 SIMPLEPreconditionerFactory ::SIMPLEPreconditionerFactory(
const RCP<InverseFactory>& invVFact,
38 const RCP<InverseFactory>& invPFact,
40 : invVelFactory_(invVFact),
41 invPrsFactory_(invPFact),
43 fInverseType_(Diagonal),
46 SIMPLEPreconditionerFactory::SIMPLEPreconditionerFactory()
47 : alpha_(1.0), fInverseType_(Diagonal), useMass_(false) {}
52 Teko_DEBUG_SCOPE(
"SIMPLEPreconditionerFactory::buildPreconditionerOperator", 10);
53 Teko_DEBUG_EXPR(Teuchos::Time timer(
""));
55 int rows = blockRowCount(blockOp);
56 int cols = blockColCount(blockOp);
58 TEUCHOS_ASSERT(rows == 2);
59 TEUCHOS_ASSERT(cols == 2);
61 bool buildExplicitSchurComplement =
true;
64 const LinearOp F = getBlock(0, 0, blockOp);
65 const LinearOp Bt = getBlock(0, 1, blockOp);
66 const LinearOp B = getBlock(1, 0, blockOp);
67 const LinearOp C = getBlock(1, 1, blockOp);
71 TEUCHOS_ASSERT(massMatrix_ != Teuchos::null);
76 std::string fApproxStr =
"<error>";
78 if (fInverseType_ == NotDiag) {
80 fApproxStr = customHFactory_->toString();
83 buildExplicitSchurComplement =
false;
84 }
else if (fInverseType_ == BlkDiag) {
85 #ifdef TEKO_HAVE_EPETRA
98 buildExplicitSchurComplement =
true;
101 throw std::logic_error(
102 "SIMPLEPreconditionerFactory fInverseType_ == "
103 "BlkDiag but EPETRA is turned off!");
108 H = getInvDiagonalOp(matF, fInverseType_);
109 fApproxStr = getDiagonalName(fInverseType_);
114 RCP<const Teuchos::ParameterList> pl = state.getParameterList();
116 if (pl->isParameter(
"stepsize")) {
118 double stepsize = pl->get<
double>(
"stepsize");
121 if (stepsize > 0.0) H = scale(stepsize, H);
128 if (buildExplicitSchurComplement) {
134 mHBt = explicitMultiply(H, Bt, mHBt);
138 BHBt = explicitMultiply(B, HBt, BHBt);
141 mhatS = explicitAdd(C, scale(-1.0, BHBt), mhatS);
145 HBt = multiply(H, Bt);
147 hatS = add(C, scale(-1.0, multiply(B, HBt)));
150 Teko::ModifiableLinearOp& precInvF = state.
getModifiableOp(
"precInvF");
151 if (precVelFactory_) {
152 if (precInvF == Teuchos::null) {
153 precInvF = precVelFactory_->buildInverse(F);
162 if (invF == Teuchos::null) {
163 if (precInvF.is_null()) {
169 if (precInvF.is_null()) {
176 Teko::ModifiableLinearOp& precInvS = state.
getModifiableOp(
"precInvS");
177 if (precPrsFactory_) {
178 if (precInvS == Teuchos::null) {
179 precInvS = precPrsFactory_->buildInverse(hatS);
188 if (invS == Teuchos::null) {
189 if (precInvS == Teuchos::null) {
195 if (precInvS == Teuchos::null) {
202 std::vector<LinearOp> invDiag(2);
205 BlockedLinearOp L = zeroBlockedOp(blockOp);
206 setBlock(1, 0, L, B);
211 LinearOp invL = createBlockLowerTriInverseOp(L, invDiag);
214 BlockedLinearOp U = zeroBlockedOp(blockOp);
215 setBlock(0, 1, U, scale(1.0 / alpha_, HBt));
218 invDiag[0] = identity(rangeSpace(invF));
219 invDiag[1] = scale(alpha_, identity(rangeSpace(invS)));
220 LinearOp invU = createBlockUpperTriInverseOp(U, invDiag);
223 return multiply(invU, invL,
"SIMPLE_" + fApproxStr);
232 customHFactory_ = Teuchos::null;
233 fInverseType_ = Diagonal;
236 std::string invStr =
"", invVStr =
"", invPStr =
"", precVStr =
"", precPStr =
"";
240 if (pl.isParameter(
"Inverse Type")) invStr = pl.get<std::string>(
"Inverse Type");
241 if (pl.isParameter(
"Inverse Velocity Type"))
242 invVStr = pl.get<std::string>(
"Inverse Velocity Type");
243 if (pl.isParameter(
"Preconditioner Velocity Type"))
244 precVStr = pl.get<std::string>(
"Preconditioner Velocity Type");
245 if (pl.isParameter(
"Inverse Pressure Type"))
246 invPStr = pl.get<std::string>(
"Inverse Pressure Type");
247 if (pl.isParameter(
"Preconditioner Pressure Type"))
248 precPStr = pl.get<std::string>(
"Preconditioner Pressure Type");
249 if (pl.isParameter(
"Alpha")) alpha_ = pl.get<
double>(
"Alpha");
250 if (pl.isParameter(
"Explicit Velocity Inverse Type")) {
251 std::string fInverseStr = pl.get<std::string>(
"Explicit Velocity Inverse Type");
254 fInverseType_ = getDiagonalType(fInverseStr);
255 if (fInverseType_ == NotDiag) customHFactory_ = invLib->getInverseFactory(fInverseStr);
258 if (fInverseType_ == BlkDiag) BlkDiagList_ = pl.sublist(
"H options");
260 if (pl.isParameter(
"Use Mass Scaling")) useMass_ = pl.get<
bool>(
"Use Mass Scaling");
262 Teko_DEBUG_MSG_BEGIN(5) DEBUG_STREAM <<
"SIMPLE Parameters: " << std::endl;
263 DEBUG_STREAM <<
" inv type = \"" << invStr <<
"\"" << std::endl;
264 DEBUG_STREAM <<
" inv v type = \"" << invVStr <<
"\"" << std::endl;
265 DEBUG_STREAM <<
" prec v type = \"" << precVStr <<
"\"" << std::endl;
266 DEBUG_STREAM <<
" inv p type = \"" << invPStr <<
"\"" << std::endl;
267 DEBUG_STREAM <<
" prec p type = \"" << precPStr <<
"\"" << std::endl;
268 DEBUG_STREAM <<
" alpha = " << alpha_ << std::endl;
269 DEBUG_STREAM <<
" use mass = " << useMass_ << std::endl;
270 DEBUG_STREAM <<
" vel scaling = " << getDiagonalName(fInverseType_) << std::endl;
271 DEBUG_STREAM <<
"SIMPLE Parameter list: " << std::endl;
272 pl.print(DEBUG_STREAM);
276 #if defined(Teko_ENABLE_Amesos)
277 if (invStr ==
"") invStr =
"Amesos";
278 #elif defined(Teko_ENABLE_Amesos2)
279 if (invStr ==
"") invStr =
"Amesos2";
282 if (invVStr ==
"") invVStr = invStr;
283 if (invPStr ==
"") invPStr = invStr;
286 RCP<InverseFactory> invVFact, invPFact;
289 invVFact = invLib->getInverseFactory(invVStr);
291 if (invVStr != invPStr)
292 invPFact = invLib->getInverseFactory(invPStr);
294 RCP<InverseFactory> precVFact, precPFact;
295 if (precVStr !=
"") precVFact = invLib->getInverseFactory(precVStr);
297 if (precPStr !=
"") precPFact = invLib->getInverseFactory(precPStr);
300 invVelFactory_ = invVFact;
301 invPrsFactory_ = invPFact;
303 precVelFactory_ = precVFact;
304 precPrsFactory_ = precPFact;
308 rh->preRequest<Teko::LinearOp>(Teko::RequestMesg(
"Velocity Mass Matrix"));
309 Teko::LinearOp mass = rh->request<Teko::LinearOp>(Teko::RequestMesg(
"Velocity Mass Matrix"));
316 Teuchos::RCP<Teuchos::ParameterList> result;
317 Teuchos::RCP<Teuchos::ParameterList> pl = rcp(
new Teuchos::ParameterList());
321 RCP<Teuchos::ParameterList> vList = invVelFactory_->getRequestedParameters();
322 if (vList != Teuchos::null) {
323 Teuchos::ParameterList::ConstIterator itr;
324 for (itr = vList->begin(); itr != vList->end(); ++itr) pl->setEntry(itr->first, itr->second);
329 if (precVelFactory_ != Teuchos::null) {
330 RCP<Teuchos::ParameterList> vList = precVelFactory_->getRequestedParameters();
331 if (vList != Teuchos::null) {
332 Teuchos::ParameterList::ConstIterator itr;
333 for (itr = vList->begin(); itr != vList->end(); ++itr) pl->setEntry(itr->first, itr->second);
340 RCP<Teuchos::ParameterList> pList = invPrsFactory_->getRequestedParameters();
341 if (pList != Teuchos::null) {
342 Teuchos::ParameterList::ConstIterator itr;
343 for (itr = pList->begin(); itr != pList->end(); ++itr) pl->setEntry(itr->first, itr->second);
348 if (precPrsFactory_ != Teuchos::null) {
349 RCP<Teuchos::ParameterList> pList = precPrsFactory_->getRequestedParameters();
350 if (pList != Teuchos::null) {
351 Teuchos::ParameterList::ConstIterator itr;
352 for (itr = pList->begin(); itr != pList->end(); ++itr) pl->setEntry(itr->first, itr->second);
358 if (customHFactory_ != Teuchos::null) {
359 RCP<Teuchos::ParameterList> hList = customHFactory_->getRequestedParameters();
360 if (hList != Teuchos::null) {
361 Teuchos::ParameterList::ConstIterator itr;
362 for (itr = hList->begin(); itr != hList->end(); ++itr) pl->setEntry(itr->first, itr->second);
372 Teko_DEBUG_SCOPE(
"InvLSCStrategy::updateRequestedParameters", 10);
376 result &= invVelFactory_->updateRequestedParameters(pl);
377 result &= invPrsFactory_->updateRequestedParameters(pl);
378 if (precVelFactory_) result &= precVelFactory_->updateRequestedParameters(pl);
379 if (precPrsFactory_) result &= precPrsFactory_->updateRequestedParameters(pl);
380 if (customHFactory_ != Teuchos::null) result &= customHFactory_->updateRequestedParameters(pl);
void rebuildInverse(const InverseFactory &factory, const LinearOp &A, InverseLinearOp &invA)
virtual bool updateRequestedParameters(const Teuchos::ParameterList &pl)
For assisting in construction of the preconditioner.
Preconditioner factory for building explcit inverse of diagonal operators. This includes block operat...
An implementation of a state object for block preconditioners.
virtual void setMassMatrix(Teko::LinearOp &mass)
Set the mass matrix for this factory.
virtual void addModifiableOp(const std::string &name, const Teko::ModifiableLinearOp &mlo)
Add a named operator to the state object.
InverseLinearOp buildInverse(const InverseFactory &factory, const LinearOp &A)
Build an inverse operator using a factory and a linear operator.
virtual void initializeFromParameterList(const Teuchos::ParameterList &pl)
Initialize from a parameter list.
virtual void initializeFromParameterList(const Teuchos::ParameterList &pl)
Initialize from a parameter list.
Teuchos::RCP< const InverseLibrary > getInverseLibrary() const
Get the inverse library used by this preconditioner factory.
virtual Teuchos::RCP< Teuchos::ParameterList > getRequestedParameters() const
For assisting in construction of the preconditioner.
LinearOp buildPreconditionerOperator(BlockedLinearOp &blo, BlockPreconditionerState &state) const
Function that is called to build the preconditioner for the linear operator that is passed in...
Teuchos::RCP< RequestHandler > getRequestHandler() const
Get the request handler with pointers to the appropriate callbacks.
SIMPLEPreconditionerFactory()
Default constructor.
LinearOp buildPreconditionerOperator(LinearOp &lo, PreconditionerState &state) const
virtual Teko::ModifiableLinearOp & getModifiableOp(const std::string &name)
Add a named operator to the state object.