10#include "NS/Teko_PresLaplaceLSCStrategy.hpp"
12#include "Thyra_DefaultDiagonalLinearOp.hpp"
14#include "Teuchos_Time.hpp"
15#include "Teuchos_TimeMonitor.hpp"
19#include "NS/Teko_LSCPreconditionerFactory.hpp"
22using Teuchos::rcp_const_cast;
23using Teuchos::rcp_dynamic_cast;
34PresLaplaceLSCStrategy::PresLaplaceLSCStrategy()
35 : invFactoryV_(Teuchos::null),
36 invFactoryP_(Teuchos::null),
42PresLaplaceLSCStrategy::PresLaplaceLSCStrategy(
const Teuchos::RCP<InverseFactory>& factory)
43 : invFactoryV_(factory),
44 invFactoryP_(factory),
50PresLaplaceLSCStrategy::PresLaplaceLSCStrategy(
const Teuchos::RCP<InverseFactory>& invFactF,
51 const Teuchos::RCP<InverseFactory>& invFactS)
52 : invFactoryV_(invFactF),
53 invFactoryP_(invFactS),
62 Teko_DEBUG_SCOPE(
"PresLaplaceLSCStrategy::buildState", 10);
65 TEUCHOS_ASSERT(lscState != 0);
69 Teko_DEBUG_EXPR(Teuchos::Time timer(
""));
73 Teko_DEBUG_SCOPE(
"PL-LSC::buildState constructing operators", 1);
74 Teko_DEBUG_EXPR(timer.start(
true));
78 Teko_DEBUG_EXPR(timer.stop());
79 Teko_DEBUG_MSG(
"PL-LSC::buildState BuildOpsTime = " << timer.totalElapsedTime(), 1);
84 Teko_DEBUG_SCOPE(
"PL-LSC::buildState calculating inverses", 1);
85 Teko_DEBUG_EXPR(timer.start(
true));
89 Teko_DEBUG_EXPR(timer.stop());
90 Teko_DEBUG_MSG(
"PL-LSC::buildState BuildInvTime = " << timer.totalElapsedTime(), 1);
116 TEUCHOS_ASSERT(lscState != 0);
119 return lscState->
aiD_;
125 TEUCHOS_ASSERT(lscState != 0);
139 Teko_DEBUG_SCOPE(
"PresLaplaceLSCStrategy::initializeState", 10);
141 std::string velMassStr = getVelocityMassString();
143 const LinearOp F =
getBlock(0, 0, A);
144 const LinearOp Bt =
getBlock(0, 1, A);
145 const LinearOp B =
getBlock(1, 0, A);
146 const LinearOp C =
getBlock(1, 1, A);
151 bool isStabilized = (not isZeroOp(C));
154 LinearOp massMatrix = state->
getLinearOp(velMassStr);
162 if (massMatrix == Teuchos::null) {
164 "PL-LSC::initializeState Build Scaling <F> type \"" << getDiagonalName(scaleType_) <<
"\"",
166 state->
invMass_ = getInvDiagonalOp(F, scaleType_);
167 }
else if (state->
invMass_ == Teuchos::null) {
168 Teko_DEBUG_MSG(
"PL-LSC::initializeState Build Scaling <mass> type \""
169 << getDiagonalName(scaleType_) <<
"\"",
171 state->
invMass_ = getInvDiagonalOp(massMatrix, scaleType_);
176 if (not isStabilized) {
177 state->
aiD_ = Teuchos::null;
186 LinearOp invDiagF = getInvDiagonalOp(F);
187 Teko::ModifiableLinearOp& modB_idF_Bt = state->
getModifiableOp(
"BidFBt");
188 modB_idF_Bt = explicitMultiply(B, invDiagF, Bt, modB_idF_Bt);
189 const LinearOp B_idF_Bt = modB_idF_Bt;
191 MultiVector vec_D = getDiagonal(B_idF_Bt);
192 update(-1.0, getDiagonal(C), 1.0, vec_D);
193 const LinearOp invD = buildInvDiagonal(vec_D,
"inv(D)");
195 Teko_DEBUG_MSG(
"Calculating alpha", 10);
196 const LinearOp BidFBtidD = multiply<double>(B_idF_Bt, invD);
197 double num = std::fabs(Teko::computeSpectralRad(BidFBtidD, 5e-2,
false, eigSolveParam_));
198 Teko_DEBUG_MSG(
"Calculated alpha", 10);
199 state->
alpha_ = 1.0 / num;
200 state->
aiD_ = Thyra::scale(state->
alpha_, invD);
202 Teko_DEBUG_MSG_BEGIN(5) DEBUG_STREAM <<
"PL-LSC Alpha Parameter = " << state->
alpha_ << std::endl;
215 Teko_DEBUG_SCOPE(
"PresLaplaceLSCStrategy::computeInverses", 10);
216 Teko_DEBUG_EXPR(Teuchos::Time invTimer(
""));
218 std::string presLapStr = getPressureLaplaceString();
220 const LinearOp F =
getBlock(0, 0, A);
221 const LinearOp presLap = state->
getLinearOp(presLapStr);
226 Teko_DEBUG_MSG(
"PL-LSC::computeInverses Building inv(F)", 1);
227 Teko_DEBUG_EXPR(invTimer.start(
true));
229 if (invF == Teuchos::null) {
230 invF = buildInverse(*invFactoryV_, F);
232 rebuildInverse(*invFactoryV_, F, invF);
234 Teko_DEBUG_EXPR(invTimer.stop());
235 Teko_DEBUG_MSG(
"PL-LSC::computeInverses GetInvF = " << invTimer.totalElapsedTime(), 1);
240 Teko_DEBUG_MSG(
"PL-LSC::computeInverses Building inv(PresLap)", 1);
241 Teko_DEBUG_EXPR(invTimer.start(
true));
243 if (invPresLap == Teuchos::null) {
244 invPresLap = buildInverse(*invFactoryP_, presLap);
249 Teko_DEBUG_EXPR(invTimer.stop());
250 Teko_DEBUG_MSG(
"PL-LSC::computeInverses GetInvBQBt = " << invTimer.totalElapsedTime(), 1);
255 const InverseLibrary& invLib) {
257 std::string invStr =
"", invVStr =
"", invPStr =
"";
258#if defined(Teko_ENABLE_Amesos)
260#elif defined(Teko_ENABLE_Amesos2)
268 if (pl.isParameter(
"Inverse Type")) invStr = pl.get<std::string>(
"Inverse Type");
269 if (pl.isParameter(
"Inverse Velocity Type"))
270 invVStr = pl.get<std::string>(
"Inverse Velocity Type");
271 if (pl.isParameter(
"Inverse Pressure Type"))
272 invPStr = pl.get<std::string>(
"Inverse Pressure Type");
273 if (pl.isParameter(
"Use LDU")) useLDU = pl.get<
bool>(
"Use LDU");
274 if (pl.isParameter(
"Use Mass Scaling")) useMass_ = pl.get<
bool>(
"Use Mass Scaling");
275 if (pl.isParameter(
"Eigen Solver Iterations"))
276 eigSolveParam_ = pl.get<
int>(
"Eigen Solver Iterations");
277 if (pl.isParameter(
"Scaling Type")) {
278 scaleType_ = getDiagonalType(pl.get<std::string>(
"Scaling Type"));
279 TEUCHOS_TEST_FOR_EXCEPT(scaleType_ ==
NotDiag);
283 if (invVStr ==
"") invVStr = invStr;
284 if (invPStr ==
"") invPStr = invStr;
286 Teko_DEBUG_MSG_BEGIN(5) DEBUG_STREAM <<
"LSC Inverse Strategy Parameters: " << std::endl;
287 DEBUG_STREAM <<
" inv v type = \"" << invVStr <<
"\"" << std::endl;
288 DEBUG_STREAM <<
" inv p type = \"" << invPStr <<
"\"" << std::endl;
289 DEBUG_STREAM <<
" use ldu = " << useLDU << std::endl;
290 DEBUG_STREAM <<
" use mass = " << useMass_ << std::endl;
291 DEBUG_STREAM <<
" scale type = " << getDiagonalName(scaleType_) << std::endl;
292 DEBUG_STREAM <<
"LSC Pressure Laplace Strategy Parameter list: " << std::endl;
293 pl.print(DEBUG_STREAM);
297 invFactoryV_ = invLib.getInverseFactory(invVStr);
298 invFactoryP_ = invFactoryV_;
299 if (invVStr != invPStr)
300 invFactoryP_ = invLib.getInverseFactory(invPStr);
308 Teko_DEBUG_SCOPE(
"PresLaplaceLSCStrategy::getRequestedParameters", 10);
309 Teuchos::RCP<Teuchos::ParameterList> pl = rcp(
new Teuchos::ParameterList());
312 RCP<Teuchos::ParameterList> fList = invFactoryV_->getRequestedParameters();
313 if (fList != Teuchos::null) {
314 Teuchos::ParameterList::ConstIterator itr;
315 for (itr = fList->begin(); itr != fList->end(); ++itr) pl->setEntry(itr->first, itr->second);
319 RCP<Teuchos::ParameterList> sList = invFactoryP_->getRequestedParameters();
320 if (sList != Teuchos::null) {
321 Teuchos::ParameterList::ConstIterator itr;
322 for (itr = sList->begin(); itr != sList->end(); ++itr) pl->setEntry(itr->first, itr->second);
326 if (useMass_) pl->set(getVelocityMassString(),
false,
"Velocity mass matrix");
327 pl->set(getPressureLaplaceString(),
false,
"Pressure Laplacian matrix");
334 Teko_DEBUG_SCOPE(
"PresLaplaceLSCStrategy::updateRequestedParameters", 10);
338 result &= invFactoryV_->updateRequestedParameters(pl);
339 result &= invFactoryP_->updateRequestedParameters(pl);
341 Teuchos::ParameterList hackList(pl);
344 bool plo = hackList.get<
bool>(getPressureLaplaceString(),
false);
347 if (useMass_) vmo = hackList.get<
bool>(getVelocityMassString(),
false);
350 Teko_DEBUG_MSG(
"User must acknowledge the use of the \"" << getPressureLaplaceString() <<
"\"!",
354 Teko_DEBUG_MSG(
"User must acknowledge the use of the \"" << getVelocityMassString() <<
"\"!",
358 result &= (plo & vmo);
@ NotDiag
For user convenience, if Teko recieves this value, exceptions will be thrown.
@ AbsRowSum
Specifies that the diagonal entry is .
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 void initializeFromParameterList(const Teuchos::ParameterList &pl, const InverseLibrary &invLib)
Initialize from a parameter list.
virtual void initializeState(const BlockedLinearOp &A, LSCPrecondState *state) const
Initialize the state object using this blocked linear operator.
virtual LinearOp getHScaling(const BlockedLinearOp &A, BlockPreconditionerState &state) const
virtual LinearOp getInvMass(const BlockedLinearOp &A, BlockPreconditionerState &state) const
virtual bool updateRequestedParameters(const Teuchos::ParameterList &pl)
For assiting in construction of the preconditioner.
virtual LinearOp getInvBQBt(const BlockedLinearOp &A, BlockPreconditionerState &state) const
virtual Teuchos::RCP< Teuchos::ParameterList > getRequestedParameters() const
For assiting in construction of the preconditioner.
virtual LinearOp getInvF(const BlockedLinearOp &A, BlockPreconditionerState &state) const
void computeInverses(const BlockedLinearOp &A, LSCPrecondState *state) const
virtual LinearOp getOuterStabilization(const BlockedLinearOp &A, BlockPreconditionerState &state) const
virtual void buildState(BlockedLinearOp &A, BlockPreconditionerState &state) const
Functions inherited from LSCStrategy.
virtual void setUseFullLDU(bool val)
Set to true to use the Full LDU decomposition, false otherwise.
virtual LinearOp getInvBHBt(const BlockedLinearOp &A, BlockPreconditionerState &state) const
virtual bool isInitialized() const
virtual Teko::ModifiableLinearOp & getModifiableOp(const std::string &name)
Add a named operator to the state object.
virtual Teko::LinearOp getLinearOp(const std::string &name)
Add a named operator to the state object.
virtual void setInitialized(bool init=true)