Teko Version of the Day
Loading...
Searching...
No Matches
Teko_SolveInverseFactory.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_SolveInverseFactory.hpp"
48
49// Thyra includes
50#include "Thyra_DefaultLinearOpSource.hpp"
51#include "Thyra_DefaultInverseLinearOp.hpp"
52#include "Thyra_DefaultPreconditioner.hpp"
53
54// Stratimikos includes
55#include "Stratimikos_DefaultLinearSolverBuilder.hpp"
56
57// Teko includes
58#include "Teko_Utilities.hpp"
59#include "Teko_BlockPreconditionerFactory.hpp"
60#include "Teko_Preconditioner.hpp"
61#include "Teko_PreconditionerLinearOp.hpp"
62
63using Teuchos::rcp;
64using Teuchos::rcp_const_cast;
65using Teuchos::rcp_dynamic_cast;
66using Teuchos::RCP;
67
68namespace Teko {
69
79SolveInverseFactory::SolveInverseFactory(const Teuchos::RCP<Thyra::LinearOpWithSolveFactoryBase<double> > & lowsFactory)
80 : lowsFactory_(lowsFactory)
81{ }
82
84SolveInverseFactory::SolveInverseFactory(const SolveInverseFactory & siFactory)
85 : lowsFactory_(siFactory.lowsFactory_)
86{ }
87
97InverseLinearOp SolveInverseFactory::buildInverse(const LinearOp & linearOp) const
98{
99 Teko_DEBUG_SCOPE("SolveInverseFactory::buildInverse(linearOp)",10);
100
101 // build and initialize inverse linear op with solve
102 Teuchos::RCP<Thyra::LinearOpWithSolveBase<double> > invLOWS = lowsFactory_->createOp();
103 lowsFactory_->initializeOp(Thyra::defaultLinearOpSource(linearOp),&*invLOWS,Thyra::SUPPORT_SOLVE_FORWARD_ONLY);
104
105 return Thyra::nonconstInverse<double>(invLOWS);
106}
107
120InverseLinearOp SolveInverseFactory::buildInverse(const LinearOp & linearOp,const LinearOp & precOp) const
121{
122 Teko_DEBUG_SCOPE("SolveInverseFactory::buildInverse(linearOp,precOp)",10);
123
124 // build and initialize inverse linear op with solve
125 Teuchos::RCP<Thyra::LinearOpWithSolveBase<double> > invLOWS = lowsFactory_->createOp();
126 lowsFactory_->initializePreconditionedOp(Thyra::defaultLinearOpSource(linearOp),
127 Thyra::unspecifiedPrec(precOp),
128 &*invLOWS,Thyra::SUPPORT_SOLVE_FORWARD_ONLY);
129
130 return Thyra::nonconstInverse<double>(invLOWS);
131}
132
144void SolveInverseFactory::rebuildInverse(const LinearOp & source,InverseLinearOp & dest) const
145{
146 RCP<Thyra::DefaultInverseLinearOp<double> > invDest = rcp_dynamic_cast<Thyra::DefaultInverseLinearOp<double> >(dest);
147 RCP<Thyra::LinearOpWithSolveBase<double> > lows = invDest->getNonconstLows();
148
149 // This stems from confusion of if the linear op with solve initializeAndResuseOp actually rebuilds
150 // the preconditioner. It seems not to and thus we have a fairly substantial problem.
151 // lowsFactory_->initializeAndReuseOp(Thyra::defaultLinearOpSource(source),&*lows);
152 lowsFactory_->initializeOp(Thyra::defaultLinearOpSource(source),&*lows);
153}
154
167void SolveInverseFactory::rebuildInverse(const LinearOp & source,const LinearOp & precOp,InverseLinearOp & dest) const
168{
169 RCP<Thyra::DefaultInverseLinearOp<double> > invDest = rcp_dynamic_cast<Thyra::DefaultInverseLinearOp<double> >(dest);
170 RCP<Thyra::LinearOpWithSolveBase<double> > lows = invDest->getNonconstLows();
171
172 // lowsFactory_->initializeAndReuseOp(Thyra::defaultLinearOpSource(source),&*lows);
173 lowsFactory_->initializePreconditionedOp(Thyra::defaultLinearOpSource(source),
174 Thyra::unspecifiedPrec(precOp),
175 &*lows,Thyra::SUPPORT_SOLVE_FORWARD_ONLY);
176}
177
186Teuchos::RCP<const Teuchos::ParameterList> SolveInverseFactory::getParameterList() const
187{
188 return lowsFactory_->getParameterList();
189}
190
191} // end namespace Teko