10 #include "Teko_TimingsSIMPLEPreconditionerFactory.hpp"
13 #include "Teko_InverseFactory.hpp"
14 #include "Teko_BlockLowerTriInverseOp.hpp"
15 #include "Teko_BlockUpperTriInverseOp.hpp"
16 #ifdef TEKO_HAVE_EPETRA
17 #include "Teko_DiagonalPreconditionerFactory.hpp"
20 #include "Teuchos_Time.hpp"
29 const RCP<InverseFactory>& inverse,
double alpha)
30 : invVelFactory_(inverse),
31 invPrsFactory_(inverse),
33 fInverseType_(Diagonal),
35 constrTotal_(
"SIMPLE Constr: Total"),
36 subTotal_(
"SIMPLE Constr: Subs"),
39 TimingsSIMPLEPreconditionerFactory ::TimingsSIMPLEPreconditionerFactory(
40 const RCP<InverseFactory>& invVFact,
const RCP<InverseFactory>& invPFact,
double alpha)
41 : invVelFactory_(invVFact),
42 invPrsFactory_(invPFact),
44 fInverseType_(Diagonal),
46 constrTotal_(
"SIMPLE Constr: Total"),
47 subTotal_(
"SIMPLE Constr: Subs"),
50 TimingsSIMPLEPreconditionerFactory::TimingsSIMPLEPreconditionerFactory()
52 fInverseType_(Diagonal),
54 constrTotal_(
"SIMPLE Constr: Total"),
55 subTotal_(
"SIMPLE Constr: Subs"),
59 if (constrTotal_.totalElapsedTime() > 0.0) {
60 Teuchos::FancyOStream out(Teuchos::rcpFromRef(std::cout));
61 out.setOutputToRootOnly(0);
63 out <<
"==========================================================================="
66 out <<
"SIMPLE Construction Count = " << constrCount_ << std::endl;
67 out <<
"SIMPLE Construction Total = " << constrTotal_.totalElapsedTime() << std::endl;
68 out <<
"SIMPLE Sub Components Total = " << subTotal_.totalElapsedTime() << std::endl;
70 out <<
"==========================================================================="
80 Teko_DEBUG_SCOPE(
"TimingsSIMPLEPreconditionerFactory::buildPreconditionerOperator", 10);
81 Teko_DEBUG_EXPR(Teuchos::Time timer(
""));
83 int rows = blockRowCount(blockOp);
84 int cols = blockColCount(blockOp);
86 TEUCHOS_ASSERT(rows == 2);
87 TEUCHOS_ASSERT(cols == 2);
89 bool buildExplicitSchurComplement =
true;
92 const LinearOp F = getBlock(0, 0, blockOp);
93 const LinearOp Bt = getBlock(0, 1, blockOp);
94 const LinearOp B = getBlock(1, 0, blockOp);
95 const LinearOp C = getBlock(1, 1, blockOp);
99 TEUCHOS_ASSERT(massMatrix_ != Teuchos::null);
104 std::string fApproxStr =
"<error>";
106 if (fInverseType_ == NotDiag) {
108 fApproxStr = customHFactory_->toString();
111 buildExplicitSchurComplement =
false;
112 }
else if (fInverseType_ == BlkDiag) {
113 #ifdef TEKO_HAVE_EPETRA
120 buildExplicitSchurComplement =
true;
123 throw std::logic_error(
124 "TimingsSIMPLEPreconditionerFactory fInverseType_ == "
125 "BlkDiag but EPETRA is turned off!");
130 H = getInvDiagonalOp(matF, fInverseType_);
132 fApproxStr = getDiagonalName(fInverseType_);
137 RCP<const Teuchos::ParameterList> pl = state.getParameterList();
139 if (pl->isParameter(
"stepsize")) {
141 double stepsize = pl->get<
double>(
"stepsize");
144 if (stepsize > 0.0) H = scale(stepsize, H);
151 if (buildExplicitSchurComplement) {
158 mHBt = explicitMultiply(H, Bt, mHBt);
164 BHBt = explicitMultiply(B, HBt, BHBt);
169 mhatS = explicitAdd(C, scale(-1.0, BHBt), mhatS);
174 HBt = multiply(H, Bt);
176 hatS = add(C, scale(-1.0, multiply(B, HBt)));
180 if (timed_HBt_ == Teuchos::null) {
183 timed_HBt_->setLinearOp(HBt);
187 if (timed_B_ == Teuchos::null) {
190 timed_B_->setLinearOp(B);
196 if (invF == Teuchos::null) {
203 timed_invF_->setLinearOp(invF);
210 if (invS == Teuchos::null) {
217 timed_invS_->setLinearOp(invS);
221 std::vector<LinearOp> invDiag(2);
224 BlockedLinearOp L = zeroBlockedOp(blockOp);
225 setBlock(1, 0, L, timed_B_);
228 invDiag[0] = timed_invF_;
229 invDiag[1] = timed_invS_;
230 LinearOp invL = createBlockLowerTriInverseOp(L, invDiag);
233 BlockedLinearOp U = zeroBlockedOp(blockOp);
234 setBlock(0, 1, U, scale<double>(1.0 / alpha_, timed_HBt_.getConst()));
237 invDiag[0] = identity(rangeSpace(invF));
238 invDiag[1] = scale(alpha_, identity(rangeSpace(invS)));
239 LinearOp invU = createBlockUpperTriInverseOp(U, invDiag);
242 Teko::LinearOp iU_t_iL = multiply(invU, invL,
"SIMPLE_" + fApproxStr);
245 if (timed_iU_t_iL_ == Teuchos::null)
246 timed_iU_t_iL_ = Teuchos::rcp(
new DiagnosticLinearOp(getOutputStream(), iU_t_iL,
"iU_t_iL"));
248 timed_iU_t_iL_->setLinearOp(iU_t_iL);
254 return timed_iU_t_iL_;
259 const Teuchos::ParameterList& pl) {
264 customHFactory_ = Teuchos::null;
265 fInverseType_ = Diagonal;
268 std::string invStr =
"", invVStr =
"", invPStr =
"";
272 if (pl.isParameter(
"Inverse Type")) invStr = pl.get<std::string>(
"Inverse Type");
273 if (pl.isParameter(
"Inverse Velocity Type"))
274 invVStr = pl.get<std::string>(
"Inverse Velocity Type");
275 if (pl.isParameter(
"Inverse Pressure Type"))
276 invPStr = pl.get<std::string>(
"Inverse Pressure Type");
277 if (pl.isParameter(
"Alpha")) alpha_ = pl.get<
double>(
"Alpha");
278 if (pl.isParameter(
"Explicit Velocity Inverse Type")) {
279 std::string fInverseStr = pl.get<std::string>(
"Explicit Velocity Inverse Type");
282 fInverseType_ = getDiagonalType(fInverseStr);
283 if (fInverseType_ == NotDiag) customHFactory_ = invLib->getInverseFactory(fInverseStr);
286 if (fInverseType_ == BlkDiag) BlkDiagList_ = pl.sublist(
"H options");
288 if (pl.isParameter(
"Use Mass Scaling")) useMass_ = pl.get<
bool>(
"Use Mass Scaling");
290 Teko_DEBUG_MSG_BEGIN(5) DEBUG_STREAM <<
"SIMPLE Parameters: " << std::endl;
291 DEBUG_STREAM <<
" inv type = \"" << invStr <<
"\"" << std::endl;
292 DEBUG_STREAM <<
" inv v type = \"" << invVStr <<
"\"" << std::endl;
293 DEBUG_STREAM <<
" inv p type = \"" << invPStr <<
"\"" << std::endl;
294 DEBUG_STREAM <<
" alpha = " << alpha_ << std::endl;
295 DEBUG_STREAM <<
" use mass = " << useMass_ << std::endl;
296 DEBUG_STREAM <<
" vel scaling = " << getDiagonalName(fInverseType_) << std::endl;
297 DEBUG_STREAM <<
"SIMPLE Parameter list: " << std::endl;
298 pl.print(DEBUG_STREAM);
302 #if defined(Teko_ENABLE_Amesos)
303 if (invStr ==
"") invStr =
"Amesos";
304 #elif defined(Teko_ENABLE_Amesos2)
305 if (invStr ==
"") invStr =
"Amesos2";
307 if (invVStr ==
"") invVStr = invStr;
308 if (invPStr ==
"") invPStr = invStr;
311 RCP<InverseFactory> invVFact, invPFact;
314 invVFact = invLib->getInverseFactory(invVStr);
316 if (invVStr != invPStr)
317 invPFact = invLib->getInverseFactory(invPStr);
320 invVelFactory_ = invVFact;
321 invPrsFactory_ = invPFact;
325 rh->preRequest<Teko::LinearOp>(Teko::RequestMesg(
"Velocity Mass Matrix"));
326 Teko::LinearOp mass = rh->request<Teko::LinearOp>(Teko::RequestMesg(
"Velocity Mass Matrix"));
334 Teuchos::RCP<Teuchos::ParameterList> result;
335 Teuchos::RCP<Teuchos::ParameterList> pl = rcp(
new Teuchos::ParameterList());
338 RCP<Teuchos::ParameterList> vList = invVelFactory_->getRequestedParameters();
339 if (vList != Teuchos::null) {
340 Teuchos::ParameterList::ConstIterator itr;
341 for (itr = vList->begin(); itr != vList->end(); ++itr) pl->setEntry(itr->first, itr->second);
346 RCP<Teuchos::ParameterList> pList = invPrsFactory_->getRequestedParameters();
347 if (pList != Teuchos::null) {
348 Teuchos::ParameterList::ConstIterator itr;
349 for (itr = pList->begin(); itr != pList->end(); ++itr) pl->setEntry(itr->first, itr->second);
354 if (customHFactory_ != Teuchos::null) {
355 RCP<Teuchos::ParameterList> hList = customHFactory_->getRequestedParameters();
356 if (hList != Teuchos::null) {
357 Teuchos::ParameterList::ConstIterator itr;
358 for (itr = hList->begin(); itr != hList->end(); ++itr) pl->setEntry(itr->first, itr->second);
368 const Teuchos::ParameterList& pl) {
369 Teko_DEBUG_SCOPE(
"InvLSCStrategy::updateRequestedParameters", 10);
373 result &= invVelFactory_->updateRequestedParameters(pl);
374 result &= invPrsFactory_->updateRequestedParameters(pl);
375 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.
virtual ~TimingsSIMPLEPreconditionerFactory()
Destructor that outputs construction timings.
TimingsSIMPLEPreconditionerFactory()
Default constructor.
virtual void setMassMatrix(Teko::LinearOp &mass)
Set the mass matrix for this factory.
virtual Teuchos::RCP< Teuchos::ParameterList > getRequestedParameters() const
For assisting in construction of the preconditioner.
virtual void initializeFromParameterList(const Teuchos::ParameterList &pl)
Initialize from a parameter list.
Preconditioner factory for building explcit inverse of diagonal operators. This includes block operat...
An implementation of a state object for block preconditioners.
This linear operator prints diagnostics about operator application and creation times. It is useful for debugging problems and determining bottle necks.
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.
Teuchos::RCP< const InverseLibrary > getInverseLibrary() const
Get the inverse library used by this preconditioner factory.
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.
LinearOp buildPreconditionerOperator(LinearOp &lo, PreconditionerState &state) const
virtual Teko::ModifiableLinearOp & getModifiableOp(const std::string &name)
Add a named operator to the state object.