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"
22 using Teuchos::rcp_const_cast;
23 using Teuchos::rcp_dynamic_cast;
34 PresLaplaceLSCStrategy::PresLaplaceLSCStrategy()
35 : invFactoryV_(Teuchos::null),
36 invFactoryP_(Teuchos::null),
40 scaleType_(AbsRowSum) {}
42 PresLaplaceLSCStrategy::PresLaplaceLSCStrategy(
const Teuchos::RCP<InverseFactory>& factory)
43 : invFactoryV_(factory),
44 invFactoryP_(factory),
48 scaleType_(AbsRowSum) {}
50 PresLaplaceLSCStrategy::PresLaplaceLSCStrategy(
const Teuchos::RCP<InverseFactory>& invFactF,
51 const Teuchos::RCP<InverseFactory>& invFactS)
52 : invFactoryV_(invFactF),
53 invFactoryP_(invFactS),
57 scaleType_(AbsRowSum) {}
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));
76 initializeState(A, lscState);
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));
87 computeInverses(A, lscState);
89 Teko_DEBUG_EXPR(timer.stop());
90 Teko_DEBUG_MSG(
"PL-LSC::buildState BuildInvTime = " << timer.totalElapsedTime(), 1);
96 LinearOp PresLaplaceLSCStrategy::getInvBQBt(
const BlockedLinearOp& ,
101 LinearOp PresLaplaceLSCStrategy::getInvBHBt(
const BlockedLinearOp& ,
106 LinearOp PresLaplaceLSCStrategy::getInvF(
const BlockedLinearOp& ,
113 LinearOp PresLaplaceLSCStrategy::getOuterStabilization(
const BlockedLinearOp& ,
116 TEUCHOS_ASSERT(lscState != 0);
119 return lscState->
aiD_;
122 LinearOp PresLaplaceLSCStrategy::getInvMass(
const BlockedLinearOp& ,
125 TEUCHOS_ASSERT(lscState != 0);
131 LinearOp PresLaplaceLSCStrategy::getHScaling(
const BlockedLinearOp& A,
133 return getInvMass(A, state);
137 void PresLaplaceLSCStrategy::initializeState(
const BlockedLinearOp& A,
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;
213 void PresLaplaceLSCStrategy::computeInverses(
const BlockedLinearOp& A,
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) {
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) {
249 Teko_DEBUG_EXPR(invTimer.stop());
250 Teko_DEBUG_MSG(
"PL-LSC::computeInverses GetInvBQBt = " << invTimer.totalElapsedTime(), 1);
254 void PresLaplaceLSCStrategy::initializeFromParameterList(
const Teuchos::ParameterList& pl,
255 const InverseLibrary& invLib) {
257 std::string invStr =
"", invVStr =
"", invPStr =
"";
258 #if defined(Teko_ENABLE_Amesos)
260 #elif defined(Teko_ENABLE_Amesos2)
265 scaleType_ = AbsRowSum;
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);
303 setUseFullLDU(useLDU);
307 Teuchos::RCP<Teuchos::ParameterList> PresLaplaceLSCStrategy::getRequestedParameters()
const {
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");
333 bool PresLaplaceLSCStrategy::updateRequestedParameters(
const Teuchos::ParameterList& pl) {
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);
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.