Teko  Version of the Day
 All Classes Files Functions Variables Pages
Teko_ModALPreconditionerFactory.cpp
1 // @HEADER
2 // *****************************************************************************
3 // Teko: A package for block and physics based preconditioning
4 //
5 // Copyright 2010 NTESS and the Teko contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 /*
11  * Author: Zhen Wang
12  * Email: wangz@ornl.gov
13  * zhen.wang@alum.emory.edu
14  */
15 
16 #include "Teko_ModALPreconditionerFactory.hpp"
17 
18 #include "Thyra_DefaultMultipliedLinearOp.hpp"
19 #include "Thyra_DefaultAddedLinearOp.hpp"
20 #include "Thyra_DefaultIdentityLinearOp.hpp"
21 #include "Thyra_DefaultZeroLinearOp.hpp"
22 
23 #include "Teko_LU2x2InverseOp.hpp"
24 #include "Teko_Utilities.hpp"
25 #include "Teko_BlockLowerTriInverseOp.hpp"
26 #include "Teko_BlockUpperTriInverseOp.hpp"
27 #include "Teko_StaticLSCStrategy.hpp"
28 #include "Teko_InvLSCStrategy.hpp"
29 #include "Teko_PresLaplaceLSCStrategy.hpp"
30 
31 #include "Teuchos_Time.hpp"
32 
33 namespace Teko {
34 
35 namespace NS {
36 
37 ModALPrecondState::ModALPrecondState()
38  : pressureMassMatrix_(Teuchos::null), invPressureMassMatrix_(Teuchos::null) {}
39 
40 ModALPreconditionerFactory::ModALPreconditionerFactory(const Teuchos::RCP<InverseFactory>& factory)
41  : invOpsStrategy_(Teuchos::rcp(new InvModALStrategy(factory))), isSymmetric_(true) {}
42 
43 ModALPreconditionerFactory::ModALPreconditionerFactory(
44  const Teuchos::RCP<InverseFactory>& invFactoryA,
45  const Teuchos::RCP<InverseFactory>& invFactoryS)
46  : invOpsStrategy_(Teuchos::rcp(new InvModALStrategy(invFactoryA, invFactoryS))),
47  isSymmetric_(true) {}
48 
49 ModALPreconditionerFactory::ModALPreconditionerFactory(const Teuchos::RCP<InverseFactory>& factory,
50  LinearOp& pressureMassMatrix)
51  : invOpsStrategy_(Teuchos::rcp(new InvModALStrategy(factory, pressureMassMatrix))),
52  isSymmetric_(true) {}
53 
54 ModALPreconditionerFactory::ModALPreconditionerFactory(
55  const Teuchos::RCP<InverseFactory>& invFactoryA,
56  const Teuchos::RCP<InverseFactory>& invFactoryS, LinearOp& pressureMassMatrix)
57  : invOpsStrategy_(
58  Teuchos::rcp(new InvModALStrategy(invFactoryA, invFactoryS, pressureMassMatrix))),
59  isSymmetric_(true) {}
60 
61 // Construct from a strategy.
62 ModALPreconditionerFactory::ModALPreconditionerFactory(
63  const Teuchos::RCP<InvModALStrategy>& strategy)
64  : invOpsStrategy_(strategy), isSymmetric_(true) {}
65 
66 LinearOp ModALPreconditionerFactory::buildPreconditionerOperator(
67  BlockedLinearOp& alOp, BlockPreconditionerState& state) const {
68  Teko_DEBUG_SCOPE("ModALPreconditionerFactory::buildPreconditionerOperator()", 10);
69  Teko_DEBUG_EXPR(Teuchos::Time timer(""));
70  Teko_DEBUG_EXPR(Teuchos::Time totalTimer(""));
71  Teko_DEBUG_EXPR(totalTimer.start());
72 
73  // Only for 2D or 3D problems.
74  int dim = blockRowCount(alOp) - 1;
75  TEUCHOS_ASSERT(dim == 2 || dim == 3);
76 
77  // Build what is necessary for the state object.
78  Teko_DEBUG_EXPR(timer.start(true));
79  invOpsStrategy_->buildState(alOp, state);
80  Teko_DEBUG_EXPR(timer.stop());
81  Teko_DEBUG_MSG("ModALPreconditionerFactory::buildPreconditionerOperator():BuildStateTime = "
82  << timer.totalElapsedTime(),
83  2);
84 
85  // Extract inverse operators from strategy
86  Teko_DEBUG_EXPR(timer.start(true));
87  LinearOp invA11p = invOpsStrategy_->getInvA11p(state);
88  LinearOp invA22p = invOpsStrategy_->getInvA22p(state);
89  LinearOp invA33p;
90  if (dim == 3) {
91  invA33p = invOpsStrategy_->getInvA33p(state);
92  }
93 
94  // The inverse of S can be built from strategy,
95  // or just a diagonal matrix.
96  ModALPrecondState* modALState = dynamic_cast<ModALPrecondState*>(&state);
97  TEUCHOS_ASSERT(modALState != NULL);
98  LinearOp invS;
99  if (modALState->isStabilized_) {
100  invS = invOpsStrategy_->getInvS(state);
101  } else {
102  invS = scale(modALState->gamma_, modALState->invPressureMassMatrix_);
103  }
104 
105  Teko_DEBUG_EXPR(timer.stop());
106  Teko_DEBUG_MSG(
107  "ModALPrecFact::buildPreconditionerOperator(): GetInvTime = " << timer.totalElapsedTime(), 2);
108 
109  // Build diagonal operations.
110  std::vector<LinearOp> invDiag;
111  invDiag.resize(dim + 1);
112  invDiag[0] = invA11p;
113  invDiag[1] = invA22p;
114  if (dim == 2) {
115  invDiag[2] = scale(-1.0, invS);
116  } else if (dim == 3) {
117  invDiag[2] = invA33p;
118  invDiag[3] = scale(-1.0, invS);
119  }
120 
121  // Get the upper triangular matrix.
122  BlockedLinearOp U = getUpperTriBlocks(alOp);
123 
124  Teko_DEBUG_EXPR(totalTimer.stop());
125  Teko_DEBUG_MSG(
126  "ModALPrecFact::buildPreconditionerOperator TotalTime = " << totalTimer.totalElapsedTime(),
127  2);
128 
129  // Create the preconditioner
130  return createBlockUpperTriInverseOp(U, invDiag, "Modified AL preconditioner-Upper");
131 }
132 
133 } // end namespace NS
134 
135 } // end namespace Teko
An implementation of a state object for block preconditioners.
Class for saving state variables for ModALPreconditionerFactory.