Teko Version of the Day
Loading...
Searching...
No Matches
Teko_InvLSCStrategy.cpp
1/*
2// @HEADER
3//
4// ***********************************************************************
5//
6// Teko: A package for block and physics based preconditioning
7// Copyright 2010 Sandia Corporation
8//
9// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
10// the U.S. Government retains certain rights in this software.
11//
12// Redistribution and use in source and binary forms, with or without
13// modification, are permitted provided that the following conditions are
14// met:
15//
16// 1. Redistributions of source code must retain the above copyright
17// notice, this list of conditions and the following disclaimer.
18//
19// 2. Redistributions in binary form must reproduce the above copyright
20// notice, this list of conditions and the following disclaimer in the
21// documentation and/or other materials provided with the distribution.
22//
23// 3. Neither the name of the Corporation nor the names of the
24// contributors may be used to endorse or promote products derived from
25// this software without specific prior written permission.
26//
27// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
28// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
31// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38//
39// Questions? Contact Eric C. Cyr (eccyr@sandia.gov)
40//
41// ***********************************************************************
42//
43// @HEADER
44
45*/
46
47#include "NS/Teko_InvLSCStrategy.hpp"
48
49#include "Thyra_DefaultDiagonalLinearOp.hpp"
50#include "Thyra_VectorStdOps.hpp"
51
52#include "Teko_ConfigDefs.hpp"
53
54#ifdef TEKO_HAVE_EPETRA
55#include "Thyra_EpetraThyraWrappers.hpp"
56#include "Thyra_get_Epetra_Operator.hpp"
57#include "Thyra_EpetraLinearOp.hpp"
58#include "Epetra_Vector.h"
59#include "Epetra_Map.h"
60#include "EpetraExt_RowMatrixOut.h"
61#include "EpetraExt_MultiVectorOut.h"
62#include "EpetraExt_VectorOut.h"
63#include "Teko_EpetraHelpers.hpp"
64#include "Teko_EpetraOperatorWrapper.hpp"
65#endif
66
67#include "Teuchos_Time.hpp"
68#include "Teuchos_TimeMonitor.hpp"
69
70// Teko includes
71#include "Teko_Utilities.hpp"
72#include "NS/Teko_LSCPreconditionerFactory.hpp"
73
74#include "Teko_TpetraHelpers.hpp"
75
76#include "Thyra_TpetraLinearOp.hpp"
77
78using Teuchos::RCP;
79using Teuchos::rcp_dynamic_cast;
80using Teuchos::rcp_const_cast;
81
82namespace Teko {
83namespace NS {
84
86// InvLSCStrategy Implementation
88
89// constructors
91InvLSCStrategy::InvLSCStrategy()
92 : massMatrix_(Teuchos::null), invFactoryF_(Teuchos::null), invFactoryS_(Teuchos::null), eigSolveParam_(5)
93 , rowZeroingNeeded_(false), useFullLDU_(false), useMass_(false), useLumping_(false), useWScaling_(false), scaleType_(Diagonal)
94 , isSymmetric_(true), assumeStable_(false)
95{ }
96
97InvLSCStrategy::InvLSCStrategy(const Teuchos::RCP<InverseFactory> & factory,bool rzn)
98 : massMatrix_(Teuchos::null), invFactoryF_(factory), invFactoryS_(factory), eigSolveParam_(5), rowZeroingNeeded_(rzn)
99 , useFullLDU_(false), useMass_(false), useLumping_(false), useWScaling_(false), scaleType_(Diagonal)
100 , isSymmetric_(true), assumeStable_(false)
101{ }
102
103InvLSCStrategy::InvLSCStrategy(const Teuchos::RCP<InverseFactory> & invFactF,
104 const Teuchos::RCP<InverseFactory> & invFactS,
105 bool rzn)
106 : massMatrix_(Teuchos::null), invFactoryF_(invFactF), invFactoryS_(invFactS), eigSolveParam_(5), rowZeroingNeeded_(rzn)
107 , useFullLDU_(false), useMass_(false), useLumping_(false), useWScaling_(false), scaleType_(Diagonal)
108 , isSymmetric_(true), assumeStable_(false)
109{ }
110
111InvLSCStrategy::InvLSCStrategy(const Teuchos::RCP<InverseFactory> & factory,LinearOp & mass,bool rzn)
112 : massMatrix_(mass), invFactoryF_(factory), invFactoryS_(factory), eigSolveParam_(5), rowZeroingNeeded_(rzn)
113 , useFullLDU_(false), useMass_(false), useLumping_(false), useWScaling_(false), scaleType_(Diagonal)
114 , isSymmetric_(true), assumeStable_(false)
115{ }
116
117InvLSCStrategy::InvLSCStrategy(const Teuchos::RCP<InverseFactory> & invFactF,
118 const Teuchos::RCP<InverseFactory> & invFactS,
119 LinearOp & mass,bool rzn)
120 : massMatrix_(mass), invFactoryF_(invFactF), invFactoryS_(invFactS), eigSolveParam_(5), rowZeroingNeeded_(rzn)
121 , useFullLDU_(false), useMass_(false), useLumping_(false), useWScaling_(false), scaleType_(Diagonal)
122 , isSymmetric_(true), assumeStable_(false)
123{ }
124
126
127void InvLSCStrategy::buildState(BlockedLinearOp & A,BlockPreconditionerState & state) const
128{
129 Teko_DEBUG_SCOPE("InvLSCStrategy::buildState",10);
130
131 LSCPrecondState * lscState = dynamic_cast<LSCPrecondState*>(&state);
132 TEUCHOS_ASSERT(lscState!=0);
133
134 // if neccessary save state information
135 if(not lscState->isInitialized()) {
136 Teko_DEBUG_EXPR(Teuchos::Time timer(""));
137
138 // construct operators
139 {
140 Teko_DEBUG_SCOPE("LSC::buildState constructing operators",1);
141 Teko_DEBUG_EXPR(timer.start(true));
142
143 initializeState(A,lscState);
144
145 Teko_DEBUG_EXPR(timer.stop());
146 Teko_DEBUG_MSG("LSC::buildState BuildOpsTime = " << timer.totalElapsedTime(),1);
147 }
148
149 // Build the inverses
150 {
151 Teko_DEBUG_SCOPE("LSC::buildState calculating inverses",1);
152 Teko_DEBUG_EXPR(timer.start(true));
153
154 computeInverses(A,lscState);
155
156 Teko_DEBUG_EXPR(timer.stop());
157 Teko_DEBUG_MSG("LSC::buildState BuildInvTime = " << timer.totalElapsedTime(),1);
158 }
159 }
160}
161
162// functions inherited from LSCStrategy
163LinearOp InvLSCStrategy::getInvBQBt(const BlockedLinearOp & /* A */,BlockPreconditionerState & state) const
164{
165 return state.getInverse("invBQBtmC");
166}
167
168LinearOp InvLSCStrategy::getInvBHBt(const BlockedLinearOp & /* A */,BlockPreconditionerState & state) const
169{
170 return state.getInverse("invBHBtmC");
171}
172
173LinearOp InvLSCStrategy::getInvF(const BlockedLinearOp & /* A */,BlockPreconditionerState & state) const
174{
175 return state.getInverse("invF");
176}
177
178LinearOp InvLSCStrategy::getOuterStabilization(const BlockedLinearOp & /* A */,BlockPreconditionerState & state) const
179{
180 LSCPrecondState * lscState = dynamic_cast<LSCPrecondState*>(&state);
181 TEUCHOS_ASSERT(lscState!=0);
182 TEUCHOS_ASSERT(lscState->isInitialized())
183
184 return lscState->aiD_;
185}
186
187LinearOp InvLSCStrategy::getInvMass(const BlockedLinearOp & /* A */,BlockPreconditionerState & state) const
188{
189 LSCPrecondState * lscState = dynamic_cast<LSCPrecondState*>(&state);
190 TEUCHOS_ASSERT(lscState!=0);
191 TEUCHOS_ASSERT(lscState->isInitialized())
192
193 return lscState->invMass_;
194}
195
196LinearOp InvLSCStrategy::getHScaling(const BlockedLinearOp & A,BlockPreconditionerState & state) const
197{
198 if(hScaling_!=Teuchos::null) return hScaling_;
199 return getInvMass(A,state);
200}
201
203void InvLSCStrategy::initializeState(const BlockedLinearOp & A,LSCPrecondState * state) const
204{
205 Teko_DEBUG_SCOPE("InvLSCStrategy::initializeState",10);
206
207 const LinearOp F = getBlock(0,0,A);
208 const LinearOp Bt = getBlock(0,1,A);
209 const LinearOp B = getBlock(1,0,A);
210 const LinearOp C = getBlock(1,1,A);
211
212 LinearOp D = B;
213 LinearOp G = isSymmetric_ ? Bt : adjoint(D);
214
215 bool isStabilized = assumeStable_ ? false : (not isZeroOp(C));
216
217 // The logic follows like this
218 // if there is no mass matrix available --> build from F
219 // if there is a mass matrix and the inverse hasn't yet been built
220 // --> build from the mass matrix
221 // otherwise, there is already an invMass_ matrix that is appropriate
222 // --> use that one
223 if(massMatrix_==Teuchos::null) {
224 Teko_DEBUG_MSG("LSC::initializeState Build Scaling <F> type \""
225 << getDiagonalName(scaleType_) << "\"" ,1);
226 state->invMass_ = getInvDiagonalOp(F,scaleType_);
227 }
228 else if(state->invMass_==Teuchos::null) {
229 Teko_DEBUG_MSG("LSC::initializeState Build Scaling <mass> type \""
230 << getDiagonalName(scaleType_) << "\"" ,1);
231 state->invMass_ = getInvDiagonalOp(massMatrix_,scaleType_);
232 }
233 // else "invMass_" should be set and there is no reason to rebuild it
234
235 // compute BQBt
236 state->BQBt_ = explicitMultiply(B,state->invMass_,Bt,state->BQBt_);
237 Teko_DEBUG_MSG("Computed BQBt",10);
238
239 // if there is no H-Scaling
240 if(wScaling_!=Teuchos::null && hScaling_==Teuchos::null) {
241 // from W vector build H operator scaling
242 RCP<const Thyra::VectorBase<double> > w = wScaling_->col(0);
243 RCP<const Thyra::VectorBase<double> > iQu
244 = rcp_dynamic_cast<const Thyra::DiagonalLinearOpBase<double> >(state->invMass_)->getDiag();
245 RCP<Thyra::VectorBase<double> > h = Thyra::createMember(iQu->space());
246
247 Thyra::put_scalar(0.0,h.ptr());
248 Thyra::ele_wise_prod(1.0,*w,*iQu,h.ptr());
249 hScaling_ = Teuchos::rcp(new Thyra::DefaultDiagonalLinearOp<double>(h));
250 }
251
252 LinearOp H = hScaling_;
253 if(H==Teuchos::null && not isSymmetric_)
254 H = state->invMass_;
255
256 // setup the scaling operator
257 if(H==Teuchos::null)
258 state->BHBt_ = state->BQBt_;
259 else {
260 RCP<Teuchos::Time> time = Teuchos::TimeMonitor::getNewTimer("InvLSCStrategy::initializeState Build BHBt");
261 Teuchos::TimeMonitor timer(*time);
262
263 // compute BHBt
264 state->BHBt_ = explicitMultiply(D,H,G,state->BHBt_);
265 }
266
267 // if this is a stable discretization...we are done!
268 if(not isStabilized) {
269 state->addInverse("BQBtmC",state->BQBt_);
270 state->addInverse("BHBtmC",state->BHBt_);
271 state->gamma_ = 0.0;
272 state->alpha_ = 0.0;
273 state->aiD_ = Teuchos::null;
274
275 state->setInitialized(true);
276
277 return;
278 }
279
280 // for Epetra_CrsMatrix...zero out certain rows: this ensures spectral radius is correct
281 LinearOp modF = F;
282 if(!Teko::TpetraHelpers::isTpetraLinearOp(F)){ // Epetra
283#ifdef TEKO_HAVE_EPETRA
284 const RCP<const Epetra_Operator> epF = Thyra::get_Epetra_Operator(*F);
285 if(epF!=Teuchos::null && rowZeroingNeeded_) {
286 // try to get a CRS matrix
287 const RCP<const Epetra_CrsMatrix> crsF = rcp_dynamic_cast<const Epetra_CrsMatrix>(epF);
288
289 // if it is a CRS matrix get rows that need to be zeroed
290 if(crsF!=Teuchos::null) {
291 std::vector<int> zeroIndices;
292
293 // get rows in need of zeroing
294 Teko::Epetra::identityRowIndices(crsF->RowMap(), *crsF,zeroIndices);
295
296 // build an operator that zeros those rows
297 modF = Thyra::epetraLinearOp(rcp(new Teko::Epetra::ZeroedOperator(zeroIndices,crsF)));
298 }
299 }
300#else
301 throw std::logic_error("InvLSCStrategy::initializeState is trying to use "
302 "Epetra code, but TEKO is not built with Epetra!");
303#endif
304 } else { //Tpetra
305 ST scalar = 0.0;
306 bool transp = false;
307 RCP<const Tpetra::CrsMatrix<ST,LO,GO,NT> > crsF = Teko::TpetraHelpers::getTpetraCrsMatrix(F, &scalar, &transp);
308
309 std::vector<GO> zeroIndices;
310
311 // get rows in need of zeroing
312 Teko::TpetraHelpers::identityRowIndices(*crsF->getRowMap(), *crsF,zeroIndices);
313
314 // build an operator that zeros those rows
315 modF = Thyra::tpetraLinearOp<ST,LO,GO,NT>(Thyra::tpetraVectorSpace<ST,LO,GO,NT>(crsF->getDomainMap()),Thyra::tpetraVectorSpace<ST,LO,GO,NT>(crsF->getRangeMap()),rcp(new Teko::TpetraHelpers::ZeroedOperator(zeroIndices,crsF)));
316 }
317
318 // compute gamma
319 Teko_DEBUG_MSG("Calculating gamma",10);
320 LinearOp iQuF = multiply(state->invMass_,modF);
321
322 // do 6 power iterations to compute spectral radius: EHSST2007 Eq. 4.28
323 Teko::LinearOp stabMatrix; // this is the pressure stabilization matrix to use
324 state->gamma_ = std::fabs(Teko::computeSpectralRad(iQuF,5e-2,false,eigSolveParam_))/3.0;
325 Teko_DEBUG_MSG("Calculated gamma",10);
326 if(userPresStabMat_!=Teuchos::null) {
327 Teko::LinearOp invDGl = Teko::getInvDiagonalOp(userPresStabMat_);
328 Teko::LinearOp gammaOp = multiply(invDGl,C);
329 state->gamma_ *= std::fabs(Teko::computeSpectralRad(gammaOp,5e-2,false,eigSolveParam_));
330 stabMatrix = userPresStabMat_;
331 } else
332 stabMatrix = C;
333
334 // compute alpha scaled inv(D): EHSST2007 Eq. 4.29
335 // construct B_idF_Bt and save it for refilling later: This could reuse BQBt graph
336 LinearOp invDiagF = getInvDiagonalOp(F);
337 Teko::ModifiableLinearOp modB_idF_Bt = state->getInverse("BidFBt");
338 modB_idF_Bt = explicitMultiply(B,invDiagF,Bt,modB_idF_Bt);
339 state->addInverse("BidFBt",modB_idF_Bt);
340 const LinearOp B_idF_Bt = modB_idF_Bt;
341
342 MultiVector vec_D = getDiagonal(B_idF_Bt); // this memory could be reused
343 update(-1.0,getDiagonal(C),1.0,vec_D); // vec_D = diag(B*inv(diag(F))*Bt)-diag(C)
344 const LinearOp invD = buildInvDiagonal(vec_D,"inv(D)");
345
346 Teko_DEBUG_MSG("Calculating alpha",10);
347 const LinearOp BidFBtidD = multiply<double>(B_idF_Bt,invD);
348 double num = std::fabs(Teko::computeSpectralRad(BidFBtidD,5e-2,false,eigSolveParam_));
349 Teko_DEBUG_MSG("Calculated alpha",10);
350 state->alpha_ = 1.0/num;
351 state->aiD_ = Thyra::scale(state->alpha_,invD);
352
353 // now build B*Q*Bt-gamma*C
354 Teko::ModifiableLinearOp BQBtmC = state->getInverse("BQBtmC");
355 BQBtmC = explicitAdd(state->BQBt_,scale(-state->gamma_,stabMatrix),BQBtmC);
356 state->addInverse("BQBtmC",BQBtmC);
357
358 // now build B*H*Bt-gamma*C
359 Teko::ModifiableLinearOp BHBtmC = state->getInverse("BHBtmC");
360 if(H==Teuchos::null)
361 BHBtmC = BQBtmC;
362 else {
363 BHBtmC = explicitAdd(state->BHBt_,scale(-state->gamma_,stabMatrix),BHBtmC);
364 }
365 state->addInverse("BHBtmC",BHBtmC);
366
367 Teko_DEBUG_MSG_BEGIN(5)
368 DEBUG_STREAM << "LSC Gamma Parameter = " << state->gamma_ << std::endl;
369 DEBUG_STREAM << "LSC Alpha Parameter = " << state->alpha_ << std::endl;
370 Teko_DEBUG_MSG_END()
371
372 state->setInitialized(true);
373}
374
380void InvLSCStrategy::computeInverses(const BlockedLinearOp & A,LSCPrecondState * state) const
381{
382 Teko_DEBUG_SCOPE("InvLSCStrategy::computeInverses",10);
383 Teko_DEBUG_EXPR(Teuchos::Time invTimer(""));
384
385 const LinearOp F = getBlock(0,0,A);
386
388
389 // (re)build the inverse of F
390 Teko_DEBUG_MSG("LSC::computeInverses Building inv(F)",1);
391 Teko_DEBUG_EXPR(invTimer.start(true));
392 InverseLinearOp invF = state->getInverse("invF");
393 if(invF==Teuchos::null) {
394 invF = buildInverse(*invFactoryF_,F);
395 state->addInverse("invF",invF);
396 } else {
397 rebuildInverse(*invFactoryF_,F,invF);
398 }
399 Teko_DEBUG_EXPR(invTimer.stop());
400 Teko_DEBUG_MSG("LSC::computeInverses GetInvF = " << invTimer.totalElapsedTime(),1);
401
403
404 // (re)build the inverse of BQBt
405 Teko_DEBUG_MSG("LSC::computeInverses Building inv(BQBtmC)",1);
406 Teko_DEBUG_EXPR(invTimer.start(true));
407 const LinearOp BQBt = state->getInverse("BQBtmC");
408 InverseLinearOp invBQBt = state->getInverse("invBQBtmC");
409 if(invBQBt==Teuchos::null) {
410 invBQBt = buildInverse(*invFactoryS_,BQBt);
411 state->addInverse("invBQBtmC",invBQBt);
412 } else {
413 rebuildInverse(*invFactoryS_,BQBt,invBQBt);
414 }
415 Teko_DEBUG_EXPR(invTimer.stop());
416 Teko_DEBUG_MSG("LSC::computeInverses GetInvBQBt = " << invTimer.totalElapsedTime(),1);
417
419
420 // Compute the inverse of BHBt or just use BQBt
421 ModifiableLinearOp invBHBt = state->getInverse("invBHBtmC");
422 if(hScaling_!=Teuchos::null || not isSymmetric_) {
423 // (re)build the inverse of BHBt
424 Teko_DEBUG_MSG("LSC::computeInverses Building inv(BHBtmC)",1);
425 Teko_DEBUG_EXPR(invTimer.start(true));
426 const LinearOp BHBt = state->getInverse("BHBtmC");
427 if(invBHBt==Teuchos::null) {
428 invBHBt = buildInverse(*invFactoryS_,BHBt);
429 state->addInverse("invBHBtmC",invBHBt);
430 } else {
431 rebuildInverse(*invFactoryS_,BHBt,invBHBt);
432 }
433 Teko_DEBUG_EXPR(invTimer.stop());
434 Teko_DEBUG_MSG("LSC::computeInverses GetInvBHBt = " << invTimer.totalElapsedTime(),1);
435 }
436 else if(invBHBt==Teuchos::null) {
437 // just use the Q version
438 state->addInverse("invBHBtmC",invBQBt);
439 }
440}
441
443void InvLSCStrategy::initializeFromParameterList(const Teuchos::ParameterList & pl,const InverseLibrary & invLib)
444{
445 // get string specifying inverse
446 std::string invStr="", invVStr="", invPStr="";
447 bool rowZeroing = true;
448 bool useLDU = false;
449 scaleType_ = Diagonal;
450
451 // "parse" the parameter list
452 if(pl.isParameter("Inverse Type"))
453 invStr = pl.get<std::string>("Inverse Type");
454 if(pl.isParameter("Inverse Velocity Type"))
455 invVStr = pl.get<std::string>("Inverse Velocity Type");
456 if(pl.isParameter("Inverse Pressure Type"))
457 invPStr = pl.get<std::string>("Inverse Pressure Type");
458 if(pl.isParameter("Ignore Boundary Rows"))
459 rowZeroing = pl.get<bool>("Ignore Boundary Rows");
460 if(pl.isParameter("Use LDU"))
461 useLDU = pl.get<bool>("Use LDU");
462 if(pl.isParameter("Use Mass Scaling"))
463 useMass_ = pl.get<bool>("Use Mass Scaling");
464 // if(pl.isParameter("Use Lumping"))
465 // useLumping_ = pl.get<bool>("Use Lumping");
466 if(pl.isParameter("Use W-Scaling"))
467 useWScaling_ = pl.get<bool>("Use W-Scaling");
468 if(pl.isParameter("Eigen Solver Iterations"))
469 eigSolveParam_ = pl.get<int>("Eigen Solver Iterations");
470 if(pl.isParameter("Scaling Type")) {
471 scaleType_ = getDiagonalType(pl.get<std::string>("Scaling Type"));
472 TEUCHOS_TEST_FOR_EXCEPT(scaleType_==NotDiag);
473 }
474 if(pl.isParameter("Assume Stable Discretization"))
475 assumeStable_ = pl.get<bool>("Assume Stable Discretization");
476
477 Teko_DEBUG_MSG_BEGIN(5)
478 DEBUG_STREAM << "LSC Inverse Strategy Parameters: " << std::endl;
479 DEBUG_STREAM << " inv type = \"" << invStr << "\"" << std::endl;
480 DEBUG_STREAM << " inv v type = \"" << invVStr << "\"" << std::endl;
481 DEBUG_STREAM << " inv p type = \"" << invPStr << "\"" << std::endl;
482 DEBUG_STREAM << " bndry rows = " << rowZeroing << std::endl;
483 DEBUG_STREAM << " use ldu = " << useLDU << std::endl;
484 DEBUG_STREAM << " use mass = " << useMass_ << std::endl;
485 DEBUG_STREAM << " use w-scaling = " << useWScaling_ << std::endl;
486 DEBUG_STREAM << " assume stable = " << assumeStable_ << std::endl;
487 DEBUG_STREAM << " scale type = " << getDiagonalName(scaleType_) << std::endl;
488 DEBUG_STREAM << "LSC Inverse Strategy Parameter list: " << std::endl;
489 pl.print(DEBUG_STREAM);
490 Teko_DEBUG_MSG_END()
491
492 // set defaults as needed
493 if(invStr=="") invStr = "Amesos";
494 if(invVStr=="") invVStr = invStr;
495 if(invPStr=="") invPStr = invStr;
496
497 // build velocity inverse factory
498 invFactoryF_ = invLib.getInverseFactory(invVStr);
499 invFactoryS_ = invFactoryF_; // by default these are the same
500 if(invVStr!=invPStr) // if different, build pressure inverse factory
501 invFactoryS_ = invLib.getInverseFactory(invPStr);
502
503 // set other parameters
504 setUseFullLDU(useLDU);
505 setRowZeroing(rowZeroing);
506
507 if(useMass_) {
508 Teuchos::RCP<Teko::RequestHandler> rh = getRequestHandler();
509 rh->preRequest<Teko::LinearOp>(Teko::RequestMesg("Velocity Mass Matrix"));
510 Teko::LinearOp mass
511 = rh->request<Teko::LinearOp>(Teko::RequestMesg("Velocity Mass Matrix"));
512 setMassMatrix(mass);
513 }
514
515}
516
518Teuchos::RCP<Teuchos::ParameterList> InvLSCStrategy::getRequestedParameters() const
519{
520 Teuchos::RCP<Teuchos::ParameterList> result;
521 Teuchos::RCP<Teuchos::ParameterList> pl = rcp(new Teuchos::ParameterList());
522
523 // grab parameters from F solver
524 RCP<Teuchos::ParameterList> fList = invFactoryF_->getRequestedParameters();
525 if(fList!=Teuchos::null) {
526 Teuchos::ParameterList::ConstIterator itr;
527 for(itr=fList->begin();itr!=fList->end();++itr)
528 pl->setEntry(itr->first,itr->second);
529 result = pl;
530 }
531
532 // grab parameters from S solver
533 RCP<Teuchos::ParameterList> sList = invFactoryS_->getRequestedParameters();
534 if(sList!=Teuchos::null) {
535 Teuchos::ParameterList::ConstIterator itr;
536 for(itr=sList->begin();itr!=sList->end();++itr)
537 pl->setEntry(itr->first,itr->second);
538 result = pl;
539 }
540
541 // use the mass matrix
542 if(useWScaling_) {
543 pl->set<Teko::LinearOp>("W-Scaling Vector", Teuchos::null,"W-Scaling Vector");
544 result = pl;
545 }
546
547 return result;
548}
549
551bool InvLSCStrategy::updateRequestedParameters(const Teuchos::ParameterList & pl)
552{
553 Teko_DEBUG_SCOPE("InvLSCStrategy::updateRequestedParameters",10);
554 bool result = true;
555
556 // update requested parameters in solvers
557 result &= invFactoryF_->updateRequestedParameters(pl);
558 result &= invFactoryS_->updateRequestedParameters(pl);
559
560 // use W scaling matrix
561 if(useWScaling_) {
562 Teko::MultiVector wScale = pl.get<Teko::MultiVector>("W-Scaling Vector");
563
564 if(wScale==Teuchos::null)
565 result &= false;
566 else
567 setWScaling(wScale);
568 }
569
570 return result;
571}
572
573} // end namespace NS
574} // end namespace Teko
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)
@ 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.
LinearOp adjoint(ModifiableLinearOp &a)
Construct an implicit adjoint of the linear operators.
An implementation of a state object for block preconditioners.
Preconditioner state for the LSC factory.