47 #include "NS/Teko_PresLaplaceLSCStrategy.hpp"
49 #include "Thyra_DefaultDiagonalLinearOp.hpp"
51 #include "Teuchos_Time.hpp"
52 #include "Teuchos_TimeMonitor.hpp"
56 #include "NS/Teko_LSCPreconditionerFactory.hpp"
59 using Teuchos::rcp_const_cast;
60 using Teuchos::rcp_dynamic_cast;
71 PresLaplaceLSCStrategy::PresLaplaceLSCStrategy()
72 : invFactoryV_(Teuchos::null),
73 invFactoryP_(Teuchos::null),
77 scaleType_(AbsRowSum) {}
79 PresLaplaceLSCStrategy::PresLaplaceLSCStrategy(
const Teuchos::RCP<InverseFactory>& factory)
80 : invFactoryV_(factory),
81 invFactoryP_(factory),
85 scaleType_(AbsRowSum) {}
87 PresLaplaceLSCStrategy::PresLaplaceLSCStrategy(
const Teuchos::RCP<InverseFactory>& invFactF,
88 const Teuchos::RCP<InverseFactory>& invFactS)
89 : invFactoryV_(invFactF),
90 invFactoryP_(invFactS),
94 scaleType_(AbsRowSum) {}
99 Teko_DEBUG_SCOPE(
"PresLaplaceLSCStrategy::buildState", 10);
102 TEUCHOS_ASSERT(lscState != 0);
106 Teko_DEBUG_EXPR(Teuchos::Time timer(
""));
110 Teko_DEBUG_SCOPE(
"PL-LSC::buildState constructing operators", 1);
111 Teko_DEBUG_EXPR(timer.start(
true));
113 initializeState(A, lscState);
115 Teko_DEBUG_EXPR(timer.stop());
116 Teko_DEBUG_MSG(
"PL-LSC::buildState BuildOpsTime = " << timer.totalElapsedTime(), 1);
121 Teko_DEBUG_SCOPE(
"PL-LSC::buildState calculating inverses", 1);
122 Teko_DEBUG_EXPR(timer.start(
true));
124 computeInverses(A, lscState);
126 Teko_DEBUG_EXPR(timer.stop());
127 Teko_DEBUG_MSG(
"PL-LSC::buildState BuildInvTime = " << timer.totalElapsedTime(), 1);
133 LinearOp PresLaplaceLSCStrategy::getInvBQBt(
const BlockedLinearOp& ,
138 LinearOp PresLaplaceLSCStrategy::getInvBHBt(
const BlockedLinearOp& ,
143 LinearOp PresLaplaceLSCStrategy::getInvF(
const BlockedLinearOp& ,
150 LinearOp PresLaplaceLSCStrategy::getOuterStabilization(
const BlockedLinearOp& ,
153 TEUCHOS_ASSERT(lscState != 0);
156 return lscState->
aiD_;
159 LinearOp PresLaplaceLSCStrategy::getInvMass(
const BlockedLinearOp& ,
162 TEUCHOS_ASSERT(lscState != 0);
168 LinearOp PresLaplaceLSCStrategy::getHScaling(
const BlockedLinearOp& A,
170 return getInvMass(A, state);
174 void PresLaplaceLSCStrategy::initializeState(
const BlockedLinearOp& A,
176 Teko_DEBUG_SCOPE(
"PresLaplaceLSCStrategy::initializeState", 10);
178 std::string velMassStr = getVelocityMassString();
180 const LinearOp F = getBlock(0, 0, A);
181 const LinearOp Bt = getBlock(0, 1, A);
182 const LinearOp B = getBlock(1, 0, A);
183 const LinearOp C = getBlock(1, 1, A);
188 bool isStabilized = (not isZeroOp(C));
191 LinearOp massMatrix = state->
getLinearOp(velMassStr);
199 if (massMatrix == Teuchos::null) {
201 "PL-LSC::initializeState Build Scaling <F> type \"" << getDiagonalName(scaleType_) <<
"\"",
203 state->
invMass_ = getInvDiagonalOp(F, scaleType_);
204 }
else if (state->
invMass_ == Teuchos::null) {
205 Teko_DEBUG_MSG(
"PL-LSC::initializeState Build Scaling <mass> type \""
206 << getDiagonalName(scaleType_) <<
"\"",
208 state->
invMass_ = getInvDiagonalOp(massMatrix, scaleType_);
213 if (not isStabilized) {
214 state->
aiD_ = Teuchos::null;
223 LinearOp invDiagF = getInvDiagonalOp(F);
224 Teko::ModifiableLinearOp& modB_idF_Bt = state->
getModifiableOp(
"BidFBt");
225 modB_idF_Bt = explicitMultiply(B, invDiagF, Bt, modB_idF_Bt);
226 const LinearOp B_idF_Bt = modB_idF_Bt;
228 MultiVector vec_D = getDiagonal(B_idF_Bt);
229 update(-1.0, getDiagonal(C), 1.0, vec_D);
230 const LinearOp invD = buildInvDiagonal(vec_D,
"inv(D)");
232 Teko_DEBUG_MSG(
"Calculating alpha", 10);
233 const LinearOp BidFBtidD = multiply<double>(B_idF_Bt, invD);
234 double num = std::fabs(Teko::computeSpectralRad(BidFBtidD, 5e-2,
false, eigSolveParam_));
235 Teko_DEBUG_MSG(
"Calculated alpha", 10);
236 state->
alpha_ = 1.0 / num;
237 state->
aiD_ = Thyra::scale(state->
alpha_, invD);
239 Teko_DEBUG_MSG_BEGIN(5) DEBUG_STREAM <<
"PL-LSC Alpha Parameter = " << state->
alpha_ << std::endl;
250 void PresLaplaceLSCStrategy::computeInverses(
const BlockedLinearOp& A,
252 Teko_DEBUG_SCOPE(
"PresLaplaceLSCStrategy::computeInverses", 10);
253 Teko_DEBUG_EXPR(Teuchos::Time invTimer(
""));
255 std::string presLapStr = getPressureLaplaceString();
257 const LinearOp F = getBlock(0, 0, A);
258 const LinearOp presLap = state->
getLinearOp(presLapStr);
263 Teko_DEBUG_MSG(
"PL-LSC::computeInverses Building inv(F)", 1);
264 Teko_DEBUG_EXPR(invTimer.start(
true));
266 if (invF == Teuchos::null) {
271 Teko_DEBUG_EXPR(invTimer.stop());
272 Teko_DEBUG_MSG(
"PL-LSC::computeInverses GetInvF = " << invTimer.totalElapsedTime(), 1);
277 Teko_DEBUG_MSG(
"PL-LSC::computeInverses Building inv(PresLap)", 1);
278 Teko_DEBUG_EXPR(invTimer.start(
true));
280 if (invPresLap == Teuchos::null) {
286 Teko_DEBUG_EXPR(invTimer.stop());
287 Teko_DEBUG_MSG(
"PL-LSC::computeInverses GetInvBQBt = " << invTimer.totalElapsedTime(), 1);
291 void PresLaplaceLSCStrategy::initializeFromParameterList(
const Teuchos::ParameterList& pl,
292 const InverseLibrary& invLib) {
294 std::string invStr =
"", invVStr =
"", invPStr =
"";
295 #if defined(Teko_ENABLE_Amesos)
297 #elif defined(Teko_ENABLE_Amesos2)
302 scaleType_ = AbsRowSum;
305 if (pl.isParameter(
"Inverse Type")) invStr = pl.get<std::string>(
"Inverse Type");
306 if (pl.isParameter(
"Inverse Velocity Type"))
307 invVStr = pl.get<std::string>(
"Inverse Velocity Type");
308 if (pl.isParameter(
"Inverse Pressure Type"))
309 invPStr = pl.get<std::string>(
"Inverse Pressure Type");
310 if (pl.isParameter(
"Use LDU")) useLDU = pl.get<
bool>(
"Use LDU");
311 if (pl.isParameter(
"Use Mass Scaling")) useMass_ = pl.get<
bool>(
"Use Mass Scaling");
312 if (pl.isParameter(
"Eigen Solver Iterations"))
313 eigSolveParam_ = pl.get<
int>(
"Eigen Solver Iterations");
314 if (pl.isParameter(
"Scaling Type")) {
315 scaleType_ = getDiagonalType(pl.get<std::string>(
"Scaling Type"));
316 TEUCHOS_TEST_FOR_EXCEPT(scaleType_ == NotDiag);
320 if (invVStr ==
"") invVStr = invStr;
321 if (invPStr ==
"") invPStr = invStr;
323 Teko_DEBUG_MSG_BEGIN(5) DEBUG_STREAM <<
"LSC Inverse Strategy Parameters: " << std::endl;
324 DEBUG_STREAM <<
" inv v type = \"" << invVStr <<
"\"" << std::endl;
325 DEBUG_STREAM <<
" inv p type = \"" << invPStr <<
"\"" << std::endl;
326 DEBUG_STREAM <<
" use ldu = " << useLDU << std::endl;
327 DEBUG_STREAM <<
" use mass = " << useMass_ << std::endl;
328 DEBUG_STREAM <<
" scale type = " << getDiagonalName(scaleType_) << std::endl;
329 DEBUG_STREAM <<
"LSC Pressure Laplace Strategy Parameter list: " << std::endl;
330 pl.print(DEBUG_STREAM);
334 invFactoryV_ = invLib.getInverseFactory(invVStr);
335 invFactoryP_ = invFactoryV_;
336 if (invVStr != invPStr)
337 invFactoryP_ = invLib.getInverseFactory(invPStr);
340 setUseFullLDU(useLDU);
344 Teuchos::RCP<Teuchos::ParameterList> PresLaplaceLSCStrategy::getRequestedParameters()
const {
345 Teko_DEBUG_SCOPE(
"PresLaplaceLSCStrategy::getRequestedParameters", 10);
346 Teuchos::RCP<Teuchos::ParameterList> pl = rcp(
new Teuchos::ParameterList());
349 RCP<Teuchos::ParameterList> fList = invFactoryV_->getRequestedParameters();
350 if (fList != Teuchos::null) {
351 Teuchos::ParameterList::ConstIterator itr;
352 for (itr = fList->begin(); itr != fList->end(); ++itr) pl->setEntry(itr->first, itr->second);
356 RCP<Teuchos::ParameterList> sList = invFactoryP_->getRequestedParameters();
357 if (sList != Teuchos::null) {
358 Teuchos::ParameterList::ConstIterator itr;
359 for (itr = sList->begin(); itr != sList->end(); ++itr) pl->setEntry(itr->first, itr->second);
363 if (useMass_) pl->set(getVelocityMassString(),
false,
"Velocity mass matrix");
364 pl->set(getPressureLaplaceString(),
false,
"Pressure Laplacian matrix");
370 bool PresLaplaceLSCStrategy::updateRequestedParameters(
const Teuchos::ParameterList& pl) {
371 Teko_DEBUG_SCOPE(
"PresLaplaceLSCStrategy::updateRequestedParameters", 10);
375 result &= invFactoryV_->updateRequestedParameters(pl);
376 result &= invFactoryP_->updateRequestedParameters(pl);
378 Teuchos::ParameterList hackList(pl);
381 bool plo = hackList.get<
bool>(getPressureLaplaceString(),
false);
384 if (useMass_) vmo = hackList.get<
bool>(getVelocityMassString(),
false);
387 Teko_DEBUG_MSG(
"User must acknowledge the use of the \"" << getPressureLaplaceString() <<
"\"!",
391 Teko_DEBUG_MSG(
"User must acknowledge the use of the \"" << getVelocityMassString() <<
"\"!",
395 result &= (plo & vmo);
void rebuildInverse(const InverseFactory &factory, const LinearOp &A, InverseLinearOp &invA)
An implementation of a state object for block preconditioners.
virtual Teko::LinearOp getLinearOp(const std::string &name)
Add a named operator to the state object.
virtual bool isInitialized() const
LinearOp invMass_
Inverse mass operator ( )
Preconditioner state for the LSC factory.
InverseLinearOp buildInverse(const InverseFactory &factory, const LinearOp &A)
Build an inverse operator using a factory and a linear operator.
virtual void setInitialized(bool init=true)
virtual Teko::ModifiableLinearOp & getModifiableOp(const std::string &name)
Add a named operator to the state object.