11#include "Thyra_OperatorVectorClientSupport.hpp"
14#include "Thyra_DefaultSpmdVectorSpace.hpp"
17#include "Teuchos_CommandLineProcessor.hpp"
18#include "Teuchos_VerboseObject.hpp"
19#include "Teuchos_VerbosityLevelCommandLineProcessorHelpers.hpp"
20#include "Teuchos_Time.hpp"
21#include "Teuchos_StandardCatchMacros.hpp"
22#include "Teuchos_as.hpp"
23#include "Teuchos_GlobalMPISession.hpp"
69int exampleImplicitlyComposedLinearOperators(
76 const bool testAdjoint
89 using Thyra::defaultSpmdVectorSpace;
90 using Thyra::randomize;
91 using Thyra::identity;
92 using Thyra::diagonal;
93 using Thyra::multiply;
95 using Thyra::subtract;
98 using Thyra::block1x2;
99 using Thyra::block2x2;
100 using Thyra::block2x2;
103 <<
"\n*** Demonstrating building linear operators for scalar type "
115 const RCP<const VectorSpaceBase<Scalar> >
116 space0 = defaultSpmdVectorSpace<Scalar>(n0),
117 space1 = defaultSpmdVectorSpace<Scalar>(n1),
118 space2 = defaultSpmdVectorSpace<Scalar>(n2);
121 const RCP<MultiVectorBase<Scalar> >
122 mvA = createMembers(space2, n0,
"A"),
123 mvB = createMembers(space0, n2,
"B"),
124 mvC = createMembers(space0, n0,
"C"),
125 mvE = createMembers(space0, n1,
"E"),
126 mvF = createMembers(space0, n1,
"F"),
127 mvJ = createMembers(space2, n1,
"J"),
128 mvK = createMembers(space1, n2,
"K"),
129 mvL = createMembers(space2, n1,
"L"),
130 mvN = createMembers(space0, n1,
"N"),
131 mvP = createMembers(space2, n1,
"P"),
132 mvQ = createMembers(space0, n2,
"Q");
135 const RCP<VectorBase<Scalar> > d = createMember(space2);
145 randomize( -one, +one, mvA.ptr() );
146 randomize( -one, +one, mvB.ptr() );
147 randomize( -one, +one, mvC.ptr() );
148 randomize( -one, +one, d.ptr() );
149 randomize( -one, +one, mvE.ptr() );
150 randomize( -one, +one, mvF.ptr() );
151 randomize( -one, +one, mvJ.ptr() );
152 randomize( -one, +one, mvK.ptr() );
153 randomize( -one, +one, mvL.ptr() );
154 randomize( -one, +one, mvN.ptr() );
155 randomize( -one, +one, mvP.ptr() );
156 randomize( -one, +one, mvQ.ptr() );
159 const RCP<const LinearOpBase<Scalar> >
172 out << describe(*A, verbLevel);
173 out << describe(*B, verbLevel);
174 out << describe(*C, verbLevel);
175 out << describe(*E, verbLevel);
176 out << describe(*F, verbLevel);
177 out << describe(*J, verbLevel);
178 out << describe(*K, verbLevel);
179 out << describe(*L, verbLevel);
180 out << describe(*N, verbLevel);
181 out << describe(*P, verbLevel);
182 out << describe(*Q, verbLevel);
189 const RCP<const LinearOpBase<Scalar> > I = identity(space1,
"I");
192 const RCP<const LinearOpBase<Scalar> > D = diagonal(d,
"D");
196 const RCP<const LinearOpBase<Scalar> > M00 =
199 add( scale(gamma,multiply(B,A)), C ), add( E, F ),
200 multiply(adjoint(J),A), I
205 out <<
"\nM00 = " << describe(*M00, verbLevel);
209 const RCP<const LinearOpBase<Scalar> > M01 =
216 out <<
"\nM01 = " << describe(*M01, verbLevel);
219 const RCP<const LinearOpBase<Scalar> > M10 =
221 multiply(L,adjoint(N)), scale(eta,P),
225 out <<
"\nM10 = " << describe(*M10, verbLevel);
228 const RCP<const LinearOpBase<Scalar> > M11 =
229 subtract( D, multiply(adjoint(Q),Q),
"M11" );
231 out <<
"\nM11 = " << describe(*M11, verbLevel);
236 const RCP<const LinearOpBase<Scalar> > M =
243 out <<
"\nM = " << describe(*M, verbLevel);
252 linearOpTester.check_adjoint(testAdjoint);
254 linearOpTester.show_all_tests(
true);
256 linearOpTester.dump_all(
true);
258 const bool result = linearOpTester.
check(*M, Teuchos::inOutArg(out));
268int main(
int argc,
char *argv[] )
288 CommandLineProcessor clp;
289 clp.throwExceptions(
false);
290 clp.addOutputSetupOptions(
true);
293 clp.setOption(
"n0", &n0 );
296 clp.setOption(
"n1", &n1 );
299 clp.setOption(
"n2", &n2 );
302 setVerbosityLevelOption(
"verb-level", &verbLevel,
303 "Top-level verbosity level. By default, this gets deincremented as you go deeper into numerical objects.",
306 CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
307 if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL )
return parse_return;
309#if defined(HAVE_TEUCHOS_INST_FLOAT)
311 result = exampleImplicitlyComposedLinearOperators<float>(
312 n0, n1, n2, *out, verbLevel, 1e-5,
true );
313 if (!result) success =
false;
317 result = exampleImplicitlyComposedLinearOperators<double>(
318 n0, n1, n2, *out, verbLevel, 1e-12,
true );
319 if (!result) success =
false;
321#if defined(HAVE_TEUCHOS_INST_COMPLEX_FLOAT) && defined(HAVE_TEUCHOS_INST_FLOAT)
323 result = exampleImplicitlyComposedLinearOperators<std::complex<float> >(
324 n0, n1, n2, *out, verbLevel, 1e-5, false );
325 if (!result) success =
false;
333#if defined(HAVE_TEUCHOS_INST_COMPLEX_DOUBLE)
335 result = exampleImplicitlyComposedLinearOperators<std::complex<double> >(
336 n0, n1, n2, *out, verbLevel, 1e-12, true );
337 if (!result) success =
false;
340#ifdef HAVE_TEUCHOS_GNU_MP
343 result = exampleImplicitlyComposedLinearOperators<mpf_class>(
344 n0, n1, n2, *out, verbLevel, 1e-20,
true );
345 if (!result) success =
false;
353 *out <<
"\nCongratulations! All of the tests checked out!\n";
355 *out <<
"\nOh no! At least one of the tests failed!\n";
357 return success ? 0 : 1;
static RCP< FancyOStream > getDefaultOStream()
Base class for all linear operators.
Testing class for LinearOpBase.
void set_all_error_tol(const ScalarMag error_tol)
Set all the error tolerances to the same value.
bool check(const LinearOpBase< Scalar > &op, const Ptr< MultiVectorRandomizerBase< Scalar > > &rangeRandomizer, const Ptr< MultiVectorRandomizerBase< Scalar > > &domainRandomizer, const Ptr< FancyOStream > &out) const
Check a linear operator.
Interface for a collection of column vectors called a multi-vector.
Abstract interface for finite-dimensional dense vectors.
Abstract interface for objects that represent a space for vectors.
TypeTo as(const TypeFrom &t)
#define TEUCHOS_STANDARD_CATCH_STATEMENTS(VERBOSE, ERR_STREAM, SUCCESS_FLAG)
basic_OSTab< char > OSTab