Stratimikos Package Browser (Single Doxygen Collection)
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
adapters
amesos2
src
Thyra_Amesos2LinearOpWithSolve_def.hpp
Go to the documentation of this file.
1
/*
2
// @HEADER
3
// ***********************************************************************
4
//
5
// Stratimikos: Thyra-based strategies for linear solvers
6
// Copyright (2006) Sandia Corporation
7
//
8
// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
9
// license for use of this work by or on behalf of the U.S. Government.
10
//
11
// Redistribution and use in source and binary forms, with or without
12
// modification, are permitted provided that the following conditions are
13
// met:
14
//
15
// 1. Redistributions of source code must retain the above copyright
16
// notice, this list of conditions and the following disclaimer.
17
//
18
// 2. Redistributions in binary form must reproduce the above copyright
19
// notice, this list of conditions and the following disclaimer in the
20
// documentation and/or other materials provided with the distribution.
21
//
22
// 3. Neither the name of the Corporation nor the names of the
23
// contributors may be used to endorse or promote products derived from
24
// this software without specific prior written permission.
25
//
26
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37
//
38
// Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
39
//
40
// ***********************************************************************
41
// @HEADER
42
*/
43
44
#include "
Thyra_Amesos2LinearOpWithSolve_decl.hpp
"
45
#include "Thyra_MultiVectorStdOps.hpp"
46
#include "Teuchos_TimeMonitor.hpp"
47
#include <Teuchos_RCP.hpp>
48
49
50
namespace
Thyra
{
51
52
53
// Constructors/initializers/accessors
54
55
56
template
<
typename
Scalar>
57
Amesos2LinearOpWithSolve<Scalar>::Amesos2LinearOpWithSolve
()
58
{}
59
60
61
template
<
typename
Scalar>
62
Amesos2LinearOpWithSolve<Scalar>::Amesos2LinearOpWithSolve
(
63
const
Teuchos::RCP<
const
LinearOpBase<Scalar> > &fwdOp,
64
const
Teuchos::RCP<
const
LinearOpSourceBase<Scalar> > &fwdOpSrc,
65
const
Teuchos::RCP< Solver > &amesos2Solver,
66
const
EOpTransp
/* amesos2SolverTransp */
,
67
const
Scalar
/* amesos2SolverScalar */
68
)
69
{
70
this->
initialize
(fwdOp,fwdOpSrc,amesos2Solver);
71
}
72
73
74
template
<
typename
Scalar>
75
void
Amesos2LinearOpWithSolve<Scalar>::initialize
(
76
const
Teuchos::RCP<
const
LinearOpBase<Scalar> > &fwdOp,
77
const
Teuchos::RCP<
const
LinearOpSourceBase<Scalar> > &fwdOpSrc,
78
const
Teuchos::RCP< Solver > &amesos2Solver
79
)
80
{
81
fwdOp_
= fwdOp;
82
fwdOpSrc_
= fwdOpSrc;
83
amesos2Solver_
= amesos2Solver;
84
const
std::string fwdOpLabel =
fwdOp_
->getObjectLabel();
85
if
(fwdOpLabel.length())
86
this->setObjectLabel(
"lows("
+fwdOpLabel+
")"
);
87
}
88
89
90
template
<
typename
Scalar>
91
Teuchos::RCP<const LinearOpSourceBase<Scalar> >
92
Amesos2LinearOpWithSolve<Scalar>::extract_fwdOpSrc
()
93
{
94
Teuchos::RCP<const LinearOpSourceBase<Scalar> >
95
_fwdOpSrc =
fwdOpSrc_
;
96
fwdOpSrc_
= Teuchos::null;
97
return
_fwdOpSrc;
98
}
99
100
101
// Overridden from LinearOpBase
102
103
104
template
<
typename
Scalar>
105
Teuchos::RCP< const VectorSpaceBase<Scalar> >
106
Amesos2LinearOpWithSolve<Scalar>::range
()
const
107
{
108
return
(
fwdOp_
.get() ?
fwdOp_
->range() : Teuchos::null );
109
}
110
111
112
template
<
typename
Scalar>
113
Teuchos::RCP< const VectorSpaceBase<Scalar> >
114
Amesos2LinearOpWithSolve<Scalar>::domain
()
const
115
{
116
return
(
fwdOp_
.get() ?
fwdOp_
->domain() : Teuchos::null );
117
}
118
119
120
template
<
typename
Scalar>
121
Teuchos::RCP<const LinearOpBase<Scalar> >
122
Amesos2LinearOpWithSolve<Scalar>::clone
()
const
123
{
124
return
Teuchos::null;
// Not supported yet but could be
125
}
126
127
128
// Overridden from Teuchos::Describable
129
130
131
template
<
typename
Scalar>
132
std::string
Amesos2LinearOpWithSolve<Scalar>::description
()
const
133
{
134
std::ostringstream oss;
135
oss << Teuchos::Describable::description();
136
if
(!is_null(
amesos2Solver_
)) {
137
oss
138
<<
"{fwdOp="
<<
fwdOp_
->description()
139
<<
",amesos2Solver="
<<typeName(*
amesos2Solver_
)<<
"}"
;
140
}
141
return
oss.str();
142
}
143
144
145
template
<
typename
Scalar>
146
void
Amesos2LinearOpWithSolve<Scalar>::describe
(
147
Teuchos::FancyOStream &out,
148
const
Teuchos::EVerbosityLevel verbLevel
149
)
const
150
{
151
using
Teuchos::OSTab;
152
using
Teuchos::typeName;
153
using
Teuchos::describe;
154
switch
(verbLevel) {
155
case
Teuchos::VERB_DEFAULT:
156
case
Teuchos::VERB_LOW:
157
out << this->
description
() << std::endl;
158
break
;
159
case
Teuchos::VERB_MEDIUM:
160
case
Teuchos::VERB_HIGH:
161
case
Teuchos::VERB_EXTREME:
162
{
163
out
164
<< Teuchos::Describable::description() <<
"{"
165
<<
"rangeDim="
<< this->
range
()->dim()
166
<<
",domainDim="
<< this->
domain
()->dim() <<
"}\n"
;
167
OSTab tab(out);
168
if
(!is_null(
fwdOp_
)) {
169
out <<
"fwdOp = "
<<
describe
(*
fwdOp_
,verbLevel);
170
}
171
if
(!is_null(
amesos2Solver_
)) {
172
out <<
"amesos2Solver="
<< typeName(*
amesos2Solver_
) <<
"\n"
;
173
}
174
break
;
175
}
176
default
:
177
TEUCHOS_TEST_FOR_EXCEPT(
true
);
// Should never get here!
178
}
179
}
180
181
182
// protected
183
184
185
// Overridden from LinearOpBase
186
187
188
template
<
typename
Scalar>
189
bool
Amesos2LinearOpWithSolve<Scalar>::opSupportedImpl
(EOpTransp M_trans)
const
190
{
191
return ::Thyra::opSupported(*
fwdOp_
,M_trans);
192
}
193
194
195
template
<
typename
Scalar>
196
void
Amesos2LinearOpWithSolve<Scalar>::applyImpl
(
197
const
EOpTransp M_trans,
198
const
MultiVectorBase<Scalar> &X,
199
const
Ptr<MultiVectorBase<Scalar> > &Y,
200
const
Scalar alpha,
201
const
Scalar beta
202
)
const
203
{
204
Thyra::apply( *
fwdOp_
, M_trans, X, Y, alpha, beta );
205
}
206
207
208
// Overridden from LinearOpWithSolveBase
209
210
template
<
typename
Scalar>
211
bool
Amesos2LinearOpWithSolve<Scalar>::solveSupportsImpl
(EOpTransp M_trans)
const
212
{
213
if
(Thyra::real_trans(M_trans) == Thyra::NOTRANS) {
214
// Assume every amesos2 solver supports a basic forward solve!
215
return
true
;
216
}
217
// dai: not sure how to query amesos2 transpose capability
218
return
false
;
219
}
220
221
222
template
<
typename
Scalar>
223
bool
Amesos2LinearOpWithSolve<Scalar>::solveSupportsSolveMeasureTypeImpl
(
224
EOpTransp
/* M_trans */
,
const
SolveMeasureType&
/* solveMeasureType */
225
)
const
226
{
227
return
true
;
// I am a direct solver so I should be able to do it all!
228
}
229
230
231
template
<
typename
Scalar>
232
SolveStatus<Scalar>
233
Amesos2LinearOpWithSolve<Scalar>::solveImpl
(
234
const
EOpTransp
/* M_trans */
,
235
const
MultiVectorBase<Scalar> &B,
236
const
Ptr<MultiVectorBase<Scalar> > &X,
237
const
Ptr<
const
SolveCriteria<Scalar> >
/* solveCriteria */
238
)
const
239
{
240
auto
Btpetra = ConverterT::getConstTpetraMultiVector(Teuchos::rcpFromRef(B));
241
242
auto
Xtpetra = ConverterT::getTpetraMultiVector(Teuchos::rcpFromPtr(X));
243
244
Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
245
Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
246
247
if
(out.get() &&
static_cast<
int
>
(verbLevel) >
static_cast<
int
>
(Teuchos::VERB_NONE))
248
*out <<
"\nSolving system using Amesos2 solver "
249
<< typeName(*
amesos2Solver_
) <<
" ...\n\n"
;
250
251
amesos2Solver_
->solve(Xtpetra.ptr(), Btpetra.ptr());
252
253
SolveStatus<Scalar> solveStatus;
254
solveStatus.solveStatus = SOLVE_STATUS_CONVERGED;
255
return
solveStatus;
256
}
257
258
259
}
// end namespace Thyra
Thyra_Amesos2LinearOpWithSolve_decl.hpp
Thyra::Amesos2LinearOpWithSolve::Amesos2LinearOpWithSolve
Amesos2LinearOpWithSolve()
Construct to uninitialized.
Definition
Thyra_Amesos2LinearOpWithSolve_def.hpp:57
Thyra::Amesos2LinearOpWithSolve::fwdOp_
Teuchos::RCP< const LinearOpBase< Scalar > > fwdOp_
Definition
Thyra_Amesos2LinearOpWithSolve_decl.hpp:178
Thyra::Amesos2LinearOpWithSolve::fwdOpSrc_
Teuchos::RCP< const LinearOpSourceBase< Scalar > > fwdOpSrc_
Definition
Thyra_Amesos2LinearOpWithSolve_decl.hpp:179
Thyra::Amesos2LinearOpWithSolve::applyImpl
virtual void applyImpl(const EOpTransp M_trans, const MultiVectorBase< Scalar > &X, const Ptr< MultiVectorBase< Scalar > > &Y, const Scalar alpha, const Scalar beta) const
Definition
Thyra_Amesos2LinearOpWithSolve_def.hpp:196
Thyra::Amesos2LinearOpWithSolve::solveSupportsImpl
virtual bool solveSupportsImpl(EOpTransp M_trans) const
Definition
Thyra_Amesos2LinearOpWithSolve_def.hpp:211
Thyra::Amesos2LinearOpWithSolve::solveImpl
SolveStatus< Scalar > solveImpl(const EOpTransp M_trans, const MultiVectorBase< Scalar > &B, const Ptr< MultiVectorBase< Scalar > > &X, const Ptr< const SolveCriteria< Scalar > > solveCriteria) const
Definition
Thyra_Amesos2LinearOpWithSolve_def.hpp:233
Thyra::Amesos2LinearOpWithSolve::describe
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
Definition
Thyra_Amesos2LinearOpWithSolve_def.hpp:146
Thyra::Amesos2LinearOpWithSolve::extract_fwdOpSrc
Teuchos::RCP< const LinearOpSourceBase< Scalar > > extract_fwdOpSrc()
Extract the forward LinearOpSourceBase<double> object so that it can be modified and remove it from t...
Definition
Thyra_Amesos2LinearOpWithSolve_def.hpp:92
Thyra::Amesos2LinearOpWithSolve::opSupportedImpl
virtual bool opSupportedImpl(EOpTransp M_trans) const
Definition
Thyra_Amesos2LinearOpWithSolve_def.hpp:189
Thyra::Amesos2LinearOpWithSolve::description
std::string description() const
Definition
Thyra_Amesos2LinearOpWithSolve_def.hpp:132
Thyra::Amesos2LinearOpWithSolve::range
Teuchos::RCP< const VectorSpaceBase< Scalar > > range() const
Definition
Thyra_Amesos2LinearOpWithSolve_def.hpp:106
Thyra::Amesos2LinearOpWithSolve::clone
Teuchos::RCP< const LinearOpBase< Scalar > > clone() const
Definition
Thyra_Amesos2LinearOpWithSolve_def.hpp:122
Thyra::Amesos2LinearOpWithSolve::amesos2Solver_
Teuchos::RCP< Solver > amesos2Solver_
Definition
Thyra_Amesos2LinearOpWithSolve_decl.hpp:180
Thyra::Amesos2LinearOpWithSolve::solveSupportsSolveMeasureTypeImpl
virtual bool solveSupportsSolveMeasureTypeImpl(EOpTransp M_trans, const SolveMeasureType &solveMeasureType) const
Definition
Thyra_Amesos2LinearOpWithSolve_def.hpp:223
Thyra::Amesos2LinearOpWithSolve::initialize
void initialize(const Teuchos::RCP< const LinearOpBase< Scalar > > &fwdOp, const Teuchos::RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, const Teuchos::RCP< Solver > &amesos2Solver)
Initialize after construction.
Definition
Thyra_Amesos2LinearOpWithSolve_def.hpp:75
Thyra::Amesos2LinearOpWithSolve::domain
Teuchos::RCP< const VectorSpaceBase< Scalar > > domain() const
Definition
Thyra_Amesos2LinearOpWithSolve_def.hpp:114
Thyra
Definition
Thyra_DefaultRealLinearSolverBuilder.hpp:48
Generated by
1.17.0