50LinearOp SIMPLEPreconditionerFactory ::buildPreconditionerOperator(
52 Teko_DEBUG_SCOPE(
"SIMPLEPreconditionerFactory::buildPreconditionerOperator", 10);
53 Teko_DEBUG_EXPR(Teuchos::Time timer(
""));
55 int rows = blockRowCount(blockOp);
56 int cols = blockColCount(blockOp);
58 TEUCHOS_ASSERT(rows == 2);
59 TEUCHOS_ASSERT(cols == 2);
61 bool buildExplicitSchurComplement =
true;
64 const LinearOp F =
getBlock(0, 0, blockOp);
65 const LinearOp Bt =
getBlock(0, 1, blockOp);
66 const LinearOp B =
getBlock(1, 0, blockOp);
67 const LinearOp C =
getBlock(1, 1, blockOp);
71 TEUCHOS_ASSERT(massMatrix_ != Teuchos::null);
76 std::string fApproxStr =
"<error>";
79 H = buildInverse(*customHFactory_, matF);
80 fApproxStr = customHFactory_->toString();
83 buildExplicitSchurComplement =
false;
84 }
else if (fInverseType_ ==
BlkDiag) {
85#ifdef TEKO_HAVE_EPETRA
98 buildExplicitSchurComplement =
true;
101 throw std::logic_error(
102 "SIMPLEPreconditionerFactory fInverseType_ == "
103 "BlkDiag but EPETRA is turned off!");
108 H = getInvDiagonalOp(matF, fInverseType_);
109 fApproxStr = getDiagonalName(fInverseType_);
114 RCP<const Teuchos::ParameterList> pl = state.getParameterList();
116 if (pl->isParameter(
"stepsize")) {
118 double stepsize = pl->get<
double>(
"stepsize");
121 if (stepsize > 0.0) H = scale(stepsize, H);
128 if (buildExplicitSchurComplement) {
134 mHBt = explicitMultiply(H, Bt, mHBt);
138 BHBt = explicitMultiply(B, HBt, BHBt);
141 mhatS = explicitAdd(C, scale(-1.0, BHBt), mhatS);
145 HBt = multiply(H, Bt);
147 hatS = add(C, scale(-1.0, multiply(B, HBt)));
150 Teko::ModifiableLinearOp& precInvF = state.
getModifiableOp(
"precInvF");
151 if (precVelFactory_) {
152 if (precInvF == Teuchos::null) {
153 precInvF = precVelFactory_->buildInverse(F);
156 Teko::rebuildInverse(*precVelFactory_, F, precInvF);
162 if (invF == Teuchos::null) {
163 if (precInvF.is_null()) {
164 invF = Teko::buildInverse(*invVelFactory_, F);
166 invF = Teko::buildInverse(*invVelFactory_, F, precInvF);
169 if (precInvF.is_null()) {
170 Teko::rebuildInverse(*invVelFactory_, F, invF);
172 Teko::rebuildInverse(*invVelFactory_, F, precInvF, invF);
176 Teko::ModifiableLinearOp& precInvS = state.
getModifiableOp(
"precInvS");
177 if (precPrsFactory_) {
178 if (precInvS == Teuchos::null) {
179 precInvS = precPrsFactory_->buildInverse(hatS);
182 Teko::rebuildInverse(*precPrsFactory_, hatS, precInvS);
188 if (invS == Teuchos::null) {
189 if (precInvS == Teuchos::null) {
190 invS = Teko::buildInverse(*invPrsFactory_, hatS);
192 invS = Teko::buildInverse(*invPrsFactory_, hatS, precInvS);
195 if (precInvS == Teuchos::null) {
196 Teko::rebuildInverse(*invPrsFactory_, hatS, invS);
198 Teko::rebuildInverse(*invPrsFactory_, hatS, precInvS, invS);
202 std::vector<LinearOp> invDiag(2);
205 BlockedLinearOp L = zeroBlockedOp(blockOp);
206 setBlock(1, 0, L, B);
211 LinearOp invL = createBlockLowerTriInverseOp(L, invDiag);
214 BlockedLinearOp U = zeroBlockedOp(blockOp);
215 setBlock(0, 1, U, scale(1.0 / alpha_, HBt));
218 invDiag[0] = identity(rangeSpace(invF));
219 invDiag[1] = scale(alpha_, identity(rangeSpace(invS)));
220 LinearOp invU = createBlockUpperTriInverseOp(U, invDiag);
223 return multiply(invU, invL,
"SIMPLE_" + fApproxStr);
232 customHFactory_ = Teuchos::null;
236 std::string invStr =
"", invVStr =
"", invPStr =
"", precVStr =
"", precPStr =
"";
240 if (pl.isParameter(
"Inverse Type")) invStr = pl.get<std::string>(
"Inverse Type");
241 if (pl.isParameter(
"Inverse Velocity Type"))
242 invVStr = pl.get<std::string>(
"Inverse Velocity Type");
243 if (pl.isParameter(
"Preconditioner Velocity Type"))
244 precVStr = pl.get<std::string>(
"Preconditioner Velocity Type");
245 if (pl.isParameter(
"Inverse Pressure Type"))
246 invPStr = pl.get<std::string>(
"Inverse Pressure Type");
247 if (pl.isParameter(
"Preconditioner Pressure Type"))
248 precPStr = pl.get<std::string>(
"Preconditioner Pressure Type");
249 if (pl.isParameter(
"Alpha")) alpha_ = pl.get<
double>(
"Alpha");
250 if (pl.isParameter(
"Explicit Velocity Inverse Type")) {
251 std::string fInverseStr = pl.get<std::string>(
"Explicit Velocity Inverse Type");
254 fInverseType_ = getDiagonalType(fInverseStr);
255 if (fInverseType_ ==
NotDiag) customHFactory_ = invLib->getInverseFactory(fInverseStr);
258 if (fInverseType_ ==
BlkDiag) BlkDiagList_ = pl.sublist(
"H options");
260 if (pl.isParameter(
"Use Mass Scaling")) useMass_ = pl.get<
bool>(
"Use Mass Scaling");
262 Teko_DEBUG_MSG_BEGIN(5) DEBUG_STREAM <<
"SIMPLE Parameters: " << std::endl;
263 DEBUG_STREAM <<
" inv type = \"" << invStr <<
"\"" << std::endl;
264 DEBUG_STREAM <<
" inv v type = \"" << invVStr <<
"\"" << std::endl;
265 DEBUG_STREAM <<
" prec v type = \"" << precVStr <<
"\"" << std::endl;
266 DEBUG_STREAM <<
" inv p type = \"" << invPStr <<
"\"" << std::endl;
267 DEBUG_STREAM <<
" prec p type = \"" << precPStr <<
"\"" << std::endl;
268 DEBUG_STREAM <<
" alpha = " << alpha_ << std::endl;
269 DEBUG_STREAM <<
" use mass = " << useMass_ << std::endl;
270 DEBUG_STREAM <<
" vel scaling = " << getDiagonalName(fInverseType_) << std::endl;
271 DEBUG_STREAM <<
"SIMPLE Parameter list: " << std::endl;
272 pl.print(DEBUG_STREAM);
276#if defined(Teko_ENABLE_Amesos)
277 if (invStr ==
"") invStr =
"Amesos";
278#elif defined(Teko_ENABLE_Amesos2)
279 if (invStr ==
"") invStr =
"Amesos2";
282 if (invVStr ==
"") invVStr = invStr;
283 if (invPStr ==
"") invPStr = invStr;
286 RCP<InverseFactory> invVFact, invPFact;
289 invVFact = invLib->getInverseFactory(invVStr);
291 if (invVStr != invPStr)
292 invPFact = invLib->getInverseFactory(invPStr);
294 RCP<InverseFactory> precVFact, precPFact;
295 if (precVStr !=
"") precVFact = invLib->getInverseFactory(precVStr);
297 if (precPStr !=
"") precPFact = invLib->getInverseFactory(precPStr);
300 invVelFactory_ = invVFact;
301 invPrsFactory_ = invPFact;
303 precVelFactory_ = precVFact;
304 precPrsFactory_ = precPFact;
308 rh->preRequest<Teko::LinearOp>(Teko::RequestMesg(
"Velocity Mass Matrix"));
309 Teko::LinearOp mass = rh->request<Teko::LinearOp>(Teko::RequestMesg(
"Velocity Mass Matrix"));
316 Teuchos::RCP<Teuchos::ParameterList> result;
317 Teuchos::RCP<Teuchos::ParameterList> pl = rcp(
new Teuchos::ParameterList());
321 RCP<Teuchos::ParameterList> vList = invVelFactory_->getRequestedParameters();
322 if (vList != Teuchos::null) {
323 Teuchos::ParameterList::ConstIterator itr;
324 for (itr = vList->begin(); itr != vList->end(); ++itr) pl->setEntry(itr->first, itr->second);
329 if (precVelFactory_ != Teuchos::null) {
330 RCP<Teuchos::ParameterList> vList = precVelFactory_->getRequestedParameters();
331 if (vList != Teuchos::null) {
332 Teuchos::ParameterList::ConstIterator itr;
333 for (itr = vList->begin(); itr != vList->end(); ++itr) pl->setEntry(itr->first, itr->second);
340 RCP<Teuchos::ParameterList> pList = invPrsFactory_->getRequestedParameters();
341 if (pList != Teuchos::null) {
342 Teuchos::ParameterList::ConstIterator itr;
343 for (itr = pList->begin(); itr != pList->end(); ++itr) pl->setEntry(itr->first, itr->second);
348 if (precPrsFactory_ != Teuchos::null) {
349 RCP<Teuchos::ParameterList> pList = precPrsFactory_->getRequestedParameters();
350 if (pList != Teuchos::null) {
351 Teuchos::ParameterList::ConstIterator itr;
352 for (itr = pList->begin(); itr != pList->end(); ++itr) pl->setEntry(itr->first, itr->second);
358 if (customHFactory_ != Teuchos::null) {
359 RCP<Teuchos::ParameterList> hList = customHFactory_->getRequestedParameters();
360 if (hList != Teuchos::null) {
361 Teuchos::ParameterList::ConstIterator itr;
362 for (itr = hList->begin(); itr != hList->end(); ++itr) pl->setEntry(itr->first, itr->second);