Teko Version of the Day
Loading...
Searching...
No Matches
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
51#include "Teko_BlockUpperTriInverseOp.hpp"
52
53// default strategies
54#include "Teko_LU2x2DiagonalStrategy.hpp"
55#include "NS/Teko_PCDStrategy.hpp"
56
57using Teuchos::rcp;
58using Teuchos::RCP;
59
60namespace Teko {
61
62// construct a PreconditionerFactory
64 : invOpsStrategy_(rcp(new StaticLU2x2Strategy(invA00,invA00,invS))), useFullLDU_(true)
65{ }
66
68LU2x2PreconditionerFactory::LU2x2PreconditionerFactory(LinearOp & hatInvA00,LinearOp & tildeInvA00,LinearOp & invS)
69 : invOpsStrategy_(rcp(new StaticLU2x2Strategy(hatInvA00,tildeInvA00,invS))), useFullLDU_(true)
70{ }
71
72LU2x2PreconditionerFactory::LU2x2PreconditionerFactory(const RCP<LU2x2Strategy> & strategy)
73 : invOpsStrategy_(strategy), useFullLDU_(true)
74{ }
75
77 : invOpsStrategy_(Teuchos::null), useFullLDU_(true)
78{ }
79
80// for PreconditionerFactoryBase
82
83// initialize a newly created preconditioner object
85{
86 Teko_DEBUG_SCOPE("LU2x2PreconditionerFactory::buildPreconditionerOperator",10);
87 LinearOp hatInvA00 = invOpsStrategy_->getHatInvA00(A,state);
88 LinearOp tildeInvA00 = invOpsStrategy_->getTildeInvA00(A,state);
89 LinearOp invS = invOpsStrategy_->getInvS(A,state);
90
91 // build the SchurSolve LinearOp
92 if(useFullLDU())
93 return createLU2x2InverseOp(A,hatInvA00,tildeInvA00,invS,"LU2x2-Full");
94 else {
95 std::vector<LinearOp> invDiag(2);
96 invDiag[0] = hatInvA00;
97 invDiag[1] = scale(-1.0,invS);
98 return createBlockUpperTriInverseOp(A,invDiag,"LU2x2-Upper");
99 }
100}
101
114void LU2x2PreconditionerFactory::initializeFromParameterList(const Teuchos::ParameterList & settings)
115{
116 Teko_DEBUG_SCOPE("LU2x2PreconditionerFactory::initializeFromParameterList",10);
117
118 // use Golub & Wathen type or full LDU decomposition for inverse solve?
119 bool useLDU = true;
120 if(settings.isParameter("Use LDU"))
121 useLDU = settings.get<bool>("Use LDU");
122 setFullLDU(useLDU);
123
124 // build strategy object
125 std::string stratName = settings.get<std::string>("Strategy Name");
126 const Teuchos::ParameterList & pl = settings.sublist("Strategy Settings");
128}
129
144Teuchos::RCP<Teuchos::ParameterList> LU2x2PreconditionerFactory::getRequestedParameters() const
145{
146 Teko_DEBUG_SCOPE("LU2x2PreconditionerFactory::getRequestedParameters",0);
147 return invOpsStrategy_->getRequestedParameters();
148}
149
163bool LU2x2PreconditionerFactory::updateRequestedParameters(const Teuchos::ParameterList & pl)
164{
165 Teko_DEBUG_SCOPE("LU2x2PreconditionerFactory::updateRequestedParameters",0);
166 return invOpsStrategy_->updateRequestedParameters(pl);
167}
168
170// Static members and methods
172
174CloneFactory<LU2x2Strategy> LU2x2PreconditionerFactory::strategyBuilder_;
175
188RCP<LU2x2Strategy> LU2x2PreconditionerFactory::buildStrategy(const std::string & name,
189 const Teuchos::ParameterList & settings,
190 const RCP<const InverseLibrary> & invLib,
191 const RCP<RequestHandler> & rh)
192{
193 Teko_DEBUG_SCOPE("LU2x2PreconditionerFactory::buildStrategy",0);
194
195 // initialize the defaults if necessary
196 if(strategyBuilder_.cloneCount()==0) initializeStrategyBuilder();
197
198 Teko_DEBUG_MSG_BEGIN(1)
199 std::vector<std::string> names;
200 strategyBuilder_.getCloneNames(names);
201 DEBUG_STREAM << "Strategy names = ";
202 for(std::size_t i=0;i<names.size();i++)
203 DEBUG_STREAM << names[i] << ", ";
204 DEBUG_STREAM << std::endl;
205 Teko_DEBUG_MSG_END()
206
207 // request the preconditioner factory from the CloneFactory
208 RCP<LU2x2Strategy> strategy = strategyBuilder_.build(name);
209
210 if(strategy==Teuchos::null) {
211 Teko_DEBUG_MSG("Warning: Could not build LU2x2Strategy named \""
212 << name << "\"...pressing on, failure expected",0)
213 return Teuchos::null;
214 }
215
216 // now that inverse library has been set,
217 // pass in the parameter list
218 strategy->setRequestHandler(rh);
219 strategy->initializeFromParameterList(settings,*invLib);
220
221 return strategy;
222}
223
237void LU2x2PreconditionerFactory::addStrategy(const std::string & name,const RCP<Cloneable> & clone)
238{
239 Teko_DEBUG_SCOPE("LU2x2PreconditionerFactory::addStrategy",10);
240
241 // initialize the defaults if necessary
242 if(strategyBuilder_.cloneCount()==0) initializeStrategyBuilder();
243
244 // add clone to builder
245 strategyBuilder_.addClone(name,clone);
246}
247
249void LU2x2PreconditionerFactory::initializeStrategyBuilder()
250{
251 Teko_DEBUG_SCOPE("LU2x2PreconditionerFactory::initializeStrategyBuilder",10);
252
253 RCP<Cloneable> clone;
254
255 // add various strategies to the factory
256 clone = rcp(new AutoClone<LU2x2DiagonalStrategy>());
257 strategyBuilder_.addClone("Diagonal Strategy",clone);
258
259 // add various strategies to the factory
260 clone = rcp(new AutoClone<NS::PCDStrategy>());
261 strategyBuilder_.addClone("NS PCD Strategy",clone);
262}
263
264} // end namespace Teko
void scale(const double alpha, MultiVector &x)
Scale a multivector by a constant.
An implementation of a state object for block preconditioners.
virtual Teuchos::RCP< Teuchos::ParameterList > getRequestedParameters() const
Request the additional parameters this preconditioner factory needs.
LU2x2PreconditionerFactory()
Default constructor for use with AutoClone.
virtual void initializeFromParameterList(const Teuchos::ParameterList &settings)
This function builds the internals of the preconditioner factory from a parameter list.
virtual void setFullLDU(bool value)
Set the type of inverse operation to use.
Teuchos::RCP< LU2x2Strategy > invOpsStrategy_
some members
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.
virtual bool useFullLDU() const
Determine the type of inverse operator to build.
static void addStrategy(const std::string &name, const RCP< Cloneable > &clone)
Add a strategy to the builder. This is done using the clone pattern.
LinearOp buildPreconditionerOperator(BlockedLinearOp &blo, BlockPreconditionerState &state) const
Create the LU 2x2 preconditioner operator.
Teuchos::RCP< const InverseLibrary > getInverseLibrary() const
Get the inverse library used by this preconditioner factory.
Teuchos::RCP< RequestHandler > getRequestHandler() const
Get the request handler with pointers to the appropriate callbacks.
A simple strategy for use with LU2x2PreconditionerFactory, that offers static objects for inv(F) and ...