Teko  Version of the Day
 All Classes Files Functions Variables Pages
Teko_LU2x2PreconditionerFactory.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 "Teko_LU2x2PreconditionerFactory.hpp"
48 
49 // Teko includes
50 #include "Teko_LU2x2InverseOp.hpp"
51 #include "Teko_BlockUpperTriInverseOp.hpp"
52 
53 // default strategies
54 #include "Teko_LU2x2DiagonalStrategy.hpp"
55 #include "NS/Teko_PCDStrategy.hpp"
56 
57 using Teuchos::rcp;
58 using Teuchos::RCP;
59 
60 namespace Teko {
61 
62 // construct a PreconditionerFactory
64  : invOpsStrategy_(rcp(new StaticLU2x2Strategy(invA00, invA00, invS))), useFullLDU_(true) {}
65 
67 LU2x2PreconditionerFactory::LU2x2PreconditionerFactory(LinearOp& hatInvA00, LinearOp& tildeInvA00,
68  LinearOp& invS)
69  : invOpsStrategy_(rcp(new StaticLU2x2Strategy(hatInvA00, tildeInvA00, invS))),
70  useFullLDU_(true) {}
71 
72 LU2x2PreconditionerFactory::LU2x2PreconditionerFactory(const RCP<LU2x2Strategy>& strategy)
73  : invOpsStrategy_(strategy), useFullLDU_(true) {}
74 
76  : invOpsStrategy_(Teuchos::null), useFullLDU_(true) {}
77 
78 // for PreconditionerFactoryBase
80 
81 // initialize a newly created preconditioner object
83  BlockedLinearOp& A, BlockPreconditionerState& state) const {
84  Teko_DEBUG_SCOPE("LU2x2PreconditionerFactory::buildPreconditionerOperator", 10);
85  LinearOp hatInvA00 = invOpsStrategy_->getHatInvA00(A, state);
86  LinearOp tildeInvA00 = invOpsStrategy_->getTildeInvA00(A, state);
87  LinearOp invS = invOpsStrategy_->getInvS(A, state);
88 
89  // build the SchurSolve LinearOp
90  if (useFullLDU())
91  return createLU2x2InverseOp(A, hatInvA00, tildeInvA00, invS, "LU2x2-Full");
92  else {
93  std::vector<LinearOp> invDiag(2);
94  invDiag[0] = hatInvA00;
95  invDiag[1] = scale(-1.0, invS);
96  return createBlockUpperTriInverseOp(A, invDiag, "LU2x2-Upper");
97  }
98 }
99 
113  const Teuchos::ParameterList& settings) {
114  Teko_DEBUG_SCOPE("LU2x2PreconditionerFactory::initializeFromParameterList", 10);
115 
116  // use Golub & Wathen type or full LDU decomposition for inverse solve?
117  bool useLDU = true;
118  if (settings.isParameter("Use LDU")) useLDU = settings.get<bool>("Use LDU");
119  setFullLDU(useLDU);
120 
121  // build strategy object
122  std::string stratName = settings.get<std::string>("Strategy Name");
123  const Teuchos::ParameterList& pl = settings.sublist("Strategy Settings");
125 }
126 
141 Teuchos::RCP<Teuchos::ParameterList> LU2x2PreconditionerFactory::getRequestedParameters() const {
142  Teko_DEBUG_SCOPE("LU2x2PreconditionerFactory::getRequestedParameters", 0);
143  return invOpsStrategy_->getRequestedParameters();
144 }
145 
159 bool LU2x2PreconditionerFactory::updateRequestedParameters(const Teuchos::ParameterList& pl) {
160  Teko_DEBUG_SCOPE("LU2x2PreconditionerFactory::updateRequestedParameters", 0);
161  return invOpsStrategy_->updateRequestedParameters(pl);
162 }
163 
165 // Static members and methods
167 
169 CloneFactory<LU2x2Strategy> LU2x2PreconditionerFactory::strategyBuilder_;
170 
184  const std::string& name, const Teuchos::ParameterList& settings,
185  const RCP<const InverseLibrary>& invLib, const RCP<RequestHandler>& rh) {
186  Teko_DEBUG_SCOPE("LU2x2PreconditionerFactory::buildStrategy", 0);
187 
188  // initialize the defaults if necessary
189  if (strategyBuilder_.cloneCount() == 0) initializeStrategyBuilder();
190 
191  Teko_DEBUG_MSG_BEGIN(1) std::vector<std::string> names;
192  strategyBuilder_.getCloneNames(names);
193  DEBUG_STREAM << "Strategy names = ";
194  for (std::size_t i = 0; i < names.size(); i++) DEBUG_STREAM << names[i] << ", ";
195  DEBUG_STREAM << std::endl;
196  Teko_DEBUG_MSG_END()
197 
198  // request the preconditioner factory from the CloneFactory
199  RCP<LU2x2Strategy>
200  strategy = strategyBuilder_.build(name);
201 
202  if (strategy == Teuchos::null) {
203  Teko_DEBUG_MSG("Warning: Could not build LU2x2Strategy named \""
204  << name << "\"...pressing on, failure expected",
205  0) return Teuchos::null;
206  }
207 
208  // now that inverse library has been set,
209  // pass in the parameter list
210  strategy->setRequestHandler(rh);
211  strategy->initializeFromParameterList(settings, *invLib);
212 
213  return strategy;
214 }
215 
229 void LU2x2PreconditionerFactory::addStrategy(const std::string& name, const RCP<Cloneable>& clone) {
230  Teko_DEBUG_SCOPE("LU2x2PreconditionerFactory::addStrategy", 10);
231 
232  // initialize the defaults if necessary
233  if (strategyBuilder_.cloneCount() == 0) initializeStrategyBuilder();
234 
235  // add clone to builder
236  strategyBuilder_.addClone(name, clone);
237 }
238 
240 void LU2x2PreconditionerFactory::initializeStrategyBuilder() {
241  Teko_DEBUG_SCOPE("LU2x2PreconditionerFactory::initializeStrategyBuilder", 10);
242 
243  RCP<Cloneable> clone;
244 
245  // add various strategies to the factory
246  clone = rcp(new AutoClone<LU2x2DiagonalStrategy>());
247  strategyBuilder_.addClone("Diagonal Strategy", clone);
248 
249  // add various strategies to the factory
250  clone = rcp(new AutoClone<NS::PCDStrategy>());
251  strategyBuilder_.addClone("NS PCD Strategy", clone);
252 }
253 
254 } // end namespace Teko
LinearOp buildPreconditionerOperator(BlockedLinearOp &blo, BlockPreconditionerState &state) const
Create the LU 2x2 preconditioner operator.
virtual bool updateRequestedParameters(const Teuchos::ParameterList &pl)
Update this object with the fields from a parameter list.
static RCP< LU2x2Strategy > buildStrategy(const std::string &name, const Teuchos::ParameterList &settings, const RCP< const InverseLibrary > &invLib, const RCP< RequestHandler > &rh)
Builder function for creating strategies.
Teuchos::RCP< LU2x2Strategy > invOpsStrategy_
some members
An implementation of a state object for block preconditioners.
virtual void setFullLDU(bool value)
Set the type of inverse operation to use.
static void addStrategy(const std::string &name, const RCP< Cloneable > &clone)
Add a strategy to the builder. This is done using the clone pattern.
LU2x2PreconditionerFactory()
Default constructor for use with AutoClone.
Teuchos::RCP< const InverseLibrary > getInverseLibrary() const
Get the inverse library used by this preconditioner factory.
virtual bool useFullLDU() const
Determine the type of inverse operator to build.
A simple strategy for use with LU2x2PreconditionerFactory, that offers static objects for inv(F) and ...
Teuchos::RCP< RequestHandler > getRequestHandler() const
Get the request handler with pointers to the appropriate callbacks.
virtual Teuchos::RCP< Teuchos::ParameterList > getRequestedParameters() const
Request the additional parameters this preconditioner factory needs.
virtual void initializeFromParameterList(const Teuchos::ParameterList &settings)
This function builds the internals of the preconditioner factory from a parameter list...