47#include "Teko_LSCSIMPLECStrategy.hpp"
49#include "Thyra_DefaultDiagonalLinearOp.hpp"
50#include "Thyra_VectorStdOps.hpp"
52#include "Teuchos_Time.hpp"
53#include "Teuchos_TimeMonitor.hpp"
57#include "Teko_LSCPreconditionerFactory.hpp"
60using Teuchos::rcp_dynamic_cast;
61using Teuchos::rcp_const_cast;
72LSCSIMPLECStrategy::LSCSIMPLECStrategy()
73 : invFactoryF_(Teuchos::null), invFactoryS_(Teuchos::null)
74 , useFullLDU_(false), scaleType_(
Diagonal)
81 Teko_DEBUG_SCOPE(
"LSCSIMPLECStrategy::buildState",10);
84 TEUCHOS_ASSERT(lscState!=0);
88 Teko_DEBUG_EXPR(Teuchos::Time timer(
""));
92 Teko_DEBUG_SCOPE(
"LSC-SIMPLEC::buildState constructing operators",1);
93 Teko_DEBUG_EXPR(timer.start(
true));
95 initializeState(A,lscState);
97 Teko_DEBUG_EXPR(timer.stop());
98 Teko_DEBUG_MSG(
"LSC-SIMPLEC::buildState BuildOpsTime = " << timer.totalElapsedTime(),1);
103 Teko_DEBUG_SCOPE(
"LSC-SIMPLEC::buildState calculating inverses",1);
104 Teko_DEBUG_EXPR(timer.start(
true));
106 computeInverses(A,lscState);
108 Teko_DEBUG_EXPR(timer.stop());
109 Teko_DEBUG_MSG(
"LSC-SIMPLEC::buildState BuildInvTime = " << timer.totalElapsedTime(),1);
122 return state.
getInverse(
"invBQBtmC").getConst();
133 TEUCHOS_ASSERT(lscState!=0);
137 return scale(-1.0,C);
144 TEUCHOS_ASSERT(lscState!=0);
152 return getInvMass(A,state);
156void LSCSIMPLECStrategy::initializeState(
const BlockedLinearOp & A,
LSCPrecondState * state)
const
158 Teko_DEBUG_SCOPE(
"LSCSIMPLECStrategy::initializeState",10);
161 const LinearOp Bt =
getBlock(0,1,A);
165 bool isStabilized = (not isZeroOp(C));
167 state->
invMass_ = getInvDiagonalOp(F,scaleType_);
173 Teko::ModifiableLinearOp BQBtmC = state->
getInverse(
"BQBtmC");
174 BQBtmC = explicitAdd(state->
BQBt_,
scale(-1.0,C),BQBtmC);
177 Teko_DEBUG_MSG(
"Computed BQBt",10);
187void LSCSIMPLECStrategy::computeInverses(
const BlockedLinearOp & A,
LSCPrecondState * state)
const
189 Teko_DEBUG_SCOPE(
"LSCSIMPLECStrategy::computeInverses",10);
190 Teko_DEBUG_EXPR(Teuchos::Time invTimer(
""));
197 Teko_DEBUG_MSG(
"LSC-SIMPLEC::computeInverses Building inv(F)",1);
198 Teko_DEBUG_EXPR(invTimer.start(
true));
199 InverseLinearOp invF = state->
getInverse(
"invF");
200 if(invF==Teuchos::null) {
206 Teko_DEBUG_EXPR(invTimer.stop());
207 Teko_DEBUG_MSG(
"LSC-SIMPLEC::computeInverses GetInvF = " << invTimer.totalElapsedTime(),1);
212 Teko_DEBUG_MSG(
"LSC-SIMPLEC::computeInverses Building inv(BQBtmC)",1);
213 Teko_DEBUG_EXPR(invTimer.start(
true));
214 const LinearOp BQBt = state->
getInverse(
"BQBtmC");
215 InverseLinearOp invBQBt = state->
getInverse(
"invBQBtmC");
216 if(invBQBt==Teuchos::null) {
222 Teko_DEBUG_EXPR(invTimer.stop());
223 Teko_DEBUG_MSG(
"LSC-SIMPLEC::computeInverses GetInvBQBt = " << invTimer.totalElapsedTime(),1);
227void LSCSIMPLECStrategy::initializeFromParameterList(
const Teuchos::ParameterList & pl,
const InverseLibrary & invLib)
230 std::string invStr=
"", invVStr=
"", invPStr=
"";
235 if(pl.isParameter(
"Inverse Type"))
236 invStr = pl.get<std::string>(
"Inverse Type");
237 if(pl.isParameter(
"Inverse Velocity Type"))
238 invVStr = pl.get<std::string>(
"Inverse Velocity Type");
239 if(pl.isParameter(
"Inverse Pressure Type"))
240 invPStr = pl.get<std::string>(
"Inverse Pressure Type");
241 if(pl.isParameter(
"Use LDU"))
242 useLDU = pl.get<
bool>(
"Use LDU");
243 if(pl.isParameter(
"Scaling Type")) {
244 scaleType_ = getDiagonalType(pl.get<std::string>(
"Scaling Type"));
245 TEUCHOS_TEST_FOR_EXCEPT(scaleType_==
NotDiag);
248 Teko_DEBUG_MSG_BEGIN(0)
249 DEBUG_STREAM <<
"LSC Inverse Strategy Parameters: " << std::endl;
250 DEBUG_STREAM <<
" inv type = \"" << invStr <<
"\"" << std::endl;
251 DEBUG_STREAM <<
" inv v type = \"" << invVStr <<
"\"" << std::endl;
252 DEBUG_STREAM <<
" inv p type = \"" << invPStr <<
"\"" << std::endl;
253 DEBUG_STREAM <<
" use ldu = " << useLDU << std::endl;
254 DEBUG_STREAM <<
" scale type = " << getDiagonalName(scaleType_) << std::endl;
255 DEBUG_STREAM <<
"LSC Inverse Strategy Parameter list: " << std::endl;
256 pl.print(DEBUG_STREAM);
260 if(invStr==
"") invStr =
"Amesos";
261 if(invVStr==
"") invVStr = invStr;
262 if(invPStr==
"") invPStr = invStr;
265 invFactoryF_ = invLib.getInverseFactory(invVStr);
266 invFactoryS_ = invFactoryF_;
268 invFactoryS_ = invLib.getInverseFactory(invPStr);
271 setUseFullLDU(useLDU);
InverseLinearOp buildInverse(const InverseFactory &factory, const LinearOp &A)
Build an inverse operator using a factory and a linear operator.
void rebuildInverse(const InverseFactory &factory, const LinearOp &A, InverseLinearOp &invA)
void scale(const double alpha, MultiVector &x)
Scale a multivector by a constant.
@ NotDiag
For user convenience, if Teko recieves this value, exceptions will be thrown.
@ Diagonal
Specifies that just the diagonal is used.
MultiVector getBlock(int i, const BlockedMultiVector &bmv)
Get the ith block from a BlockedMultiVector object.
An implementation of a state object for block preconditioners.
Preconditioner state for the LSC factory.
LinearOp invMass_
Inverse mass operator ( )
virtual bool isInitialized() const
virtual void addInverse(const std::string &name, const Teko::InverseLinearOp &ilo)
Add a named inverse to the state object.
virtual void setInitialized(bool init=true)
virtual Teko::InverseLinearOp getInverse(const std::string &name) const
Get a named inverse from the state object.