47 #include "NS/Teko_PresLaplaceLSCStrategy.hpp"
49 #include "Thyra_DefaultDiagonalLinearOp.hpp"
50 #include "Thyra_EpetraThyraWrappers.hpp"
51 #include "Thyra_get_Epetra_Operator.hpp"
52 #include "Thyra_EpetraLinearOp.hpp"
54 #include "Teuchos_Time.hpp"
55 #include "Teuchos_TimeMonitor.hpp"
59 #include "NS/Teko_LSCPreconditionerFactory.hpp"
62 using Teuchos::rcp_dynamic_cast;
63 using Teuchos::rcp_const_cast;
74 PresLaplaceLSCStrategy::PresLaplaceLSCStrategy()
75 : invFactoryV_(Teuchos::null), invFactoryP_(Teuchos::null)
76 , eigSolveParam_(5), useFullLDU_(false), useMass_(false), scaleType_(AbsRowSum)
79 PresLaplaceLSCStrategy::PresLaplaceLSCStrategy(
const Teuchos::RCP<InverseFactory> & factory)
80 : invFactoryV_(factory), invFactoryP_(factory)
81 , eigSolveParam_(5), useFullLDU_(false), useMass_(false), scaleType_(AbsRowSum)
84 PresLaplaceLSCStrategy::PresLaplaceLSCStrategy(
const Teuchos::RCP<InverseFactory> & invFactF,
85 const Teuchos::RCP<InverseFactory> & invFactS)
86 : invFactoryV_(invFactF), invFactoryP_(invFactS)
87 , eigSolveParam_(5), useFullLDU_(false), useMass_(false), scaleType_(AbsRowSum)
94 Teko_DEBUG_SCOPE(
"PresLaplaceLSCStrategy::buildState",10);
97 TEUCHOS_ASSERT(lscState!=0);
101 Teko_DEBUG_EXPR(Teuchos::Time timer(
""));
105 Teko_DEBUG_SCOPE(
"PL-LSC::buildState constructing operators",1);
106 Teko_DEBUG_EXPR(timer.start(
true));
108 initializeState(A,lscState);
110 Teko_DEBUG_EXPR(timer.stop());
111 Teko_DEBUG_MSG(
"PL-LSC::buildState BuildOpsTime = " << timer.totalElapsedTime(),1);
116 Teko_DEBUG_SCOPE(
"PL-LSC::buildState calculating inverses",1);
117 Teko_DEBUG_EXPR(timer.start(
true));
119 computeInverses(A,lscState);
121 Teko_DEBUG_EXPR(timer.stop());
122 Teko_DEBUG_MSG(
"PL-LSC::buildState BuildInvTime = " << timer.totalElapsedTime(),1);
147 TEUCHOS_ASSERT(lscState!=0);
150 return lscState->
aiD_;
156 TEUCHOS_ASSERT(lscState!=0);
164 return getInvMass(A,state);
168 void PresLaplaceLSCStrategy::initializeState(
const BlockedLinearOp & A,
LSCPrecondState * state)
const
170 Teko_DEBUG_SCOPE(
"PresLaplaceLSCStrategy::initializeState",10);
172 std::string velMassStr = getVelocityMassString();
174 const LinearOp F = getBlock(0,0,A);
175 const LinearOp Bt = getBlock(0,1,A);
176 const LinearOp B = getBlock(1,0,A);
177 const LinearOp C = getBlock(1,1,A);
182 bool isStabilized = (not isZeroOp(C));
185 LinearOp massMatrix = state->
getLinearOp(velMassStr);
193 if(massMatrix==Teuchos::null) {
194 Teko_DEBUG_MSG(
"PL-LSC::initializeState Build Scaling <F> type \""
195 << getDiagonalName(scaleType_) <<
"\"" ,1);
196 state->
invMass_ = getInvDiagonalOp(F,scaleType_);
198 else if(state->
invMass_==Teuchos::null) {
199 Teko_DEBUG_MSG(
"PL-LSC::initializeState Build Scaling <mass> type \""
200 << getDiagonalName(scaleType_) <<
"\"" ,1);
201 state->
invMass_ = getInvDiagonalOp(massMatrix,scaleType_);
206 if(not isStabilized) {
207 state->
aiD_ = Teuchos::null;
216 LinearOp invDiagF = getInvDiagonalOp(F);
217 Teko::ModifiableLinearOp & modB_idF_Bt = state->
getModifiableOp(
"BidFBt");
218 modB_idF_Bt = explicitMultiply(B,invDiagF,Bt,modB_idF_Bt);
219 const LinearOp B_idF_Bt = modB_idF_Bt;
221 MultiVector vec_D = getDiagonal(B_idF_Bt);
222 update(-1.0,getDiagonal(C),1.0,vec_D);
223 const LinearOp invD = buildInvDiagonal(vec_D,
"inv(D)");
225 Teko_DEBUG_MSG(
"Calculating alpha",10);
226 const LinearOp BidFBtidD = multiply<double>(B_idF_Bt,invD);
227 double num = std::fabs(Teko::computeSpectralRad(BidFBtidD,5e-2,
false,eigSolveParam_));
228 Teko_DEBUG_MSG(
"Calculated alpha",10);
230 state->
aiD_ = Thyra::scale(state->
alpha_,invD);
232 Teko_DEBUG_MSG_BEGIN(5)
233 DEBUG_STREAM <<
"PL-LSC Alpha Parameter = " << state->
alpha_ << std::endl;
244 void PresLaplaceLSCStrategy::computeInverses(
const BlockedLinearOp & A,
LSCPrecondState * state)
const
246 Teko_DEBUG_SCOPE(
"PresLaplaceLSCStrategy::computeInverses",10);
247 Teko_DEBUG_EXPR(Teuchos::Time invTimer(
""));
249 std::string presLapStr = getPressureLaplaceString();
251 const LinearOp F = getBlock(0,0,A);
252 const LinearOp presLap = state->
getLinearOp(presLapStr);
257 Teko_DEBUG_MSG(
"PL-LSC::computeInverses Building inv(F)",1);
258 Teko_DEBUG_EXPR(invTimer.start(
true));
260 if(invF==Teuchos::null) {
265 Teko_DEBUG_EXPR(invTimer.stop());
266 Teko_DEBUG_MSG(
"PL-LSC::computeInverses GetInvF = " << invTimer.totalElapsedTime(),1);
271 Teko_DEBUG_MSG(
"PL-LSC::computeInverses Building inv(PresLap)",1);
272 Teko_DEBUG_EXPR(invTimer.start(
true));
273 ModifiableLinearOp & invPresLap = state->
getModifiableOp(
"invPresLap");
274 if(invPresLap==Teuchos::null) {
280 Teko_DEBUG_EXPR(invTimer.stop());
281 Teko_DEBUG_MSG(
"PL-LSC::computeInverses GetInvBQBt = " << invTimer.totalElapsedTime(),1);
285 void PresLaplaceLSCStrategy::initializeFromParameterList(
const Teuchos::ParameterList & pl,
const InverseLibrary & invLib)
288 std::string invStr=
"Amesos", invVStr=
"", invPStr=
"";
290 scaleType_ = AbsRowSum;
293 if(pl.isParameter(
"Inverse Type"))
294 invStr = pl.get<std::string>(
"Inverse Type");
295 if(pl.isParameter(
"Inverse Velocity Type"))
296 invVStr = pl.get<std::string>(
"Inverse Velocity Type");
297 if(pl.isParameter(
"Inverse Pressure Type"))
298 invPStr = pl.get<std::string>(
"Inverse Pressure Type");
299 if(pl.isParameter(
"Use LDU"))
300 useLDU = pl.get<
bool>(
"Use LDU");
301 if(pl.isParameter(
"Use Mass Scaling"))
302 useMass_ = pl.get<
bool>(
"Use Mass Scaling");
303 if(pl.isParameter(
"Eigen Solver Iterations"))
304 eigSolveParam_ = pl.get<
int>(
"Eigen Solver Iterations");
305 if(pl.isParameter(
"Scaling Type")) {
306 scaleType_ = getDiagonalType(pl.get<std::string>(
"Scaling Type"));
307 TEUCHOS_TEST_FOR_EXCEPT(scaleType_==NotDiag);
311 if(invVStr==
"") invVStr = invStr;
312 if(invPStr==
"") invPStr = invStr;
314 Teko_DEBUG_MSG_BEGIN(5)
315 DEBUG_STREAM <<
"LSC Inverse Strategy Parameters: " << std::endl;
316 DEBUG_STREAM <<
" inv v type = \"" << invVStr <<
"\"" << std::endl;
317 DEBUG_STREAM <<
" inv p type = \"" << invPStr <<
"\"" << std::endl;
318 DEBUG_STREAM <<
" use ldu = " << useLDU << std::endl;
319 DEBUG_STREAM <<
" use mass = " << useMass_ << std::endl;
320 DEBUG_STREAM <<
" scale type = " << getDiagonalName(scaleType_) << std::endl;
321 DEBUG_STREAM <<
"LSC Pressure Laplace Strategy Parameter list: " << std::endl;
322 pl.print(DEBUG_STREAM);
326 invFactoryV_ = invLib.getInverseFactory(invVStr);
327 invFactoryP_ = invFactoryV_;
329 invFactoryP_ = invLib.getInverseFactory(invPStr);
332 setUseFullLDU(useLDU);
336 Teuchos::RCP<Teuchos::ParameterList> PresLaplaceLSCStrategy::getRequestedParameters()
const
338 Teko_DEBUG_SCOPE(
"PresLaplaceLSCStrategy::getRequestedParameters",10);
339 Teuchos::RCP<Teuchos::ParameterList> pl = rcp(
new Teuchos::ParameterList());
342 RCP<Teuchos::ParameterList> fList = invFactoryV_->getRequestedParameters();
343 if(fList!=Teuchos::null) {
344 Teuchos::ParameterList::ConstIterator itr;
345 for(itr=fList->begin();itr!=fList->end();++itr)
346 pl->setEntry(itr->first,itr->second);
350 RCP<Teuchos::ParameterList> sList = invFactoryP_->getRequestedParameters();
351 if(sList!=Teuchos::null) {
352 Teuchos::ParameterList::ConstIterator itr;
353 for(itr=sList->begin();itr!=sList->end();++itr)
354 pl->setEntry(itr->first,itr->second);
359 pl->set(getVelocityMassString(),
false,
"Velocity mass matrix");
360 pl->set(getPressureLaplaceString(),
false,
"Pressure Laplacian matrix");
366 bool PresLaplaceLSCStrategy::updateRequestedParameters(
const Teuchos::ParameterList & pl)
368 Teko_DEBUG_SCOPE(
"PresLaplaceLSCStrategy::updateRequestedParameters",10);
372 result &= invFactoryV_->updateRequestedParameters(pl);
373 result &= invFactoryP_->updateRequestedParameters(pl);
375 Teuchos::ParameterList hackList(pl);
378 bool plo = hackList.get<
bool>(getPressureLaplaceString(),
false);
382 vmo = hackList.get<
bool>(getVelocityMassString(),
false);
384 if(not plo) { Teko_DEBUG_MSG(
"User must acknowledge the use of the \"" << getPressureLaplaceString() <<
"\"!",0); }
385 if(not vmo) { Teko_DEBUG_MSG(
"User must acknowledge the use of the \"" << getVelocityMassString() <<
"\"!",0); }
387 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.