46 #include "Thyra_OperatorVectorClientSupport.hpp"
49 #include "Thyra_DefaultSpmdVectorSpace.hpp"
52 #include "Teuchos_CommandLineProcessor.hpp"
53 #include "Teuchos_VerboseObject.hpp"
54 #include "Teuchos_VerbosityLevelCommandLineProcessorHelpers.hpp"
55 #include "Teuchos_Time.hpp"
56 #include "Teuchos_StandardCatchMacros.hpp"
57 #include "Teuchos_as.hpp"
58 #include "Teuchos_GlobalMPISession.hpp"
103 template<
class Scalar>
104 int exampleImplicitlyComposedLinearOperators(
111 const bool testAdjoint
124 using Thyra::defaultSpmdVectorSpace;
125 using Thyra::randomize;
126 using Thyra::identity;
127 using Thyra::diagonal;
128 using Thyra::multiply;
130 using Thyra::subtract;
132 using Thyra::adjoint;
133 using Thyra::block1x2;
134 using Thyra::block2x2;
135 using Thyra::block2x2;
138 <<
"\n*** Demonstrating building linear operators for scalar type "
150 const RCP<const VectorSpaceBase<Scalar> >
151 space0 = defaultSpmdVectorSpace<Scalar>(n0),
152 space1 = defaultSpmdVectorSpace<Scalar>(n1),
153 space2 = defaultSpmdVectorSpace<Scalar>(n2);
156 const RCP<MultiVectorBase<Scalar> >
170 const RCP<VectorBase<Scalar> > d =
createMember(space2);
194 const RCP<const LinearOpBase<Scalar> >
207 out << describe(*A, verbLevel);
208 out << describe(*B, verbLevel);
209 out << describe(*C, verbLevel);
210 out << describe(*E, verbLevel);
211 out << describe(*F, verbLevel);
212 out << describe(*J, verbLevel);
213 out << describe(*K, verbLevel);
214 out << describe(*L, verbLevel);
215 out << describe(*N, verbLevel);
216 out << describe(*P, verbLevel);
217 out << describe(*Q, verbLevel);
224 const RCP<const LinearOpBase<Scalar> > I =
identity(space1,
"I");
227 const RCP<const LinearOpBase<Scalar> > D =
diagonal(d,
"D");
231 const RCP<const LinearOpBase<Scalar> > M00 =
240 out <<
"\nM00 = " << describe(*M00, verbLevel);
244 const RCP<const LinearOpBase<Scalar> > M01 =
251 out <<
"\nM01 = " << describe(*M01, verbLevel);
254 const RCP<const LinearOpBase<Scalar> > M10 =
260 out <<
"\nM10 = " << describe(*M10, verbLevel);
263 const RCP<const LinearOpBase<Scalar> > M11 =
266 out <<
"\nM11 = " << describe(*M11, verbLevel);
271 const RCP<const LinearOpBase<Scalar> > M =
278 out <<
"\nM = " << describe(*M, verbLevel);
287 linearOpTester.check_adjoint(testAdjoint);
289 linearOpTester.show_all_tests(
true);
291 linearOpTester.dump_all(
true);
293 const bool result = linearOpTester.
check(*M, Teuchos::inOutArg(out));
303 int main(
int argc,
char *argv[] )
323 CommandLineProcessor clp;
324 clp.throwExceptions(
false);
325 clp.addOutputSetupOptions(
true);
328 clp.setOption(
"n0", &n0 );
331 clp.setOption(
"n1", &n1 );
334 clp.setOption(
"n2", &n2 );
337 setVerbosityLevelOption(
"verb-level", &verbLevel,
338 "Top-level verbosity level. By default, this gets deincremented as you go deeper into numerical objects.",
341 CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
342 if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL )
return parse_return;
344 #if defined(HAVE_THYRA_FLOAT)
346 result = exampleImplicitlyComposedLinearOperators<float>(
347 n0, n1, n2, *out, verbLevel, 1e-5, true );
348 if (!result) success =
false;
352 result = exampleImplicitlyComposedLinearOperators<double>(
353 n0, n1, n2, *out, verbLevel, 1e-12, true );
354 if (!result) success =
false;
356 #ifdef HAVE_THYRA_COMPLEX
358 #if defined(HAVE_THYRA_FLOAT)
360 result = exampleImplicitlyComposedLinearOperators<std::complex<float> >(
361 n0, n1, n2, *out, verbLevel, 1e-5, false );
362 if (!result) success =
false;
368 #endif // defined(HAVE_THYRA_FLOAT)
372 result = exampleImplicitlyComposedLinearOperators<std::complex<double> >(
373 n0, n1, n2, *out, verbLevel, 1e-12, true );
374 if (!result) success =
false;
376 #endif // HAVE_THYRA_COMPLEX
378 #ifdef HAVE_TEUCHOS_GNU_MP
381 result = exampleImplicitlyComposedLinearOperators<mpf_class>(
382 n0, n1, n2, *out, verbLevel, 1e-20, true );
383 if (!result) success =
false;
385 #endif // HAVE_TEUCHOS_GNU_MP
391 *out << "\nCongratulations! All of the tests checked out!\n";
393 *out << "\nOh no! At least one of the tests failed!\n";
395 return success ? 0 : 1;
Testing class for LinearOpBase.
basic_OSTab< char > OSTab
RCP< const LinearOpBase< Scalar > > diagonal(const RCP< VectorBase< Scalar > > &diag, const std::string &label="")
Nonmember constructor function.
Teuchos::RCP< const LinearOpBase< Scalar > > block2x1(const Teuchos::RCP< const LinearOpBase< Scalar > > &A00, const Teuchos::RCP< const LinearOpBase< Scalar > > &A10, const std::string &label="")
Form an implicit block 2x1 linear operator [ A00; A10 ].
Abstract interface for objects that represent a space for vectors.
RCP< const LinearOpBase< Scalar > > scale(const Scalar &scalar, const RCP< const LinearOpBase< Scalar > > &Op, const std::string &label="")
Build an implicit const scaled linear operator.
Teuchos::RCP< const LinearOpBase< Scalar > > block1x2(const Teuchos::RCP< const LinearOpBase< Scalar > > &A00, const Teuchos::RCP< const LinearOpBase< Scalar > > &A01, const std::string &label="")
Form an implicit block 1x2 linear operator [ A00, A01 ].
RCP< const LinearOpBase< Scalar > > add(const RCP< const LinearOpBase< Scalar > > &A, const RCP< const LinearOpBase< Scalar > > &B, const std::string &label="")
Form an implicit addition of two linear operators: M = A + B.
Interface for a collection of column vectors called a multi-vector.
static RCP< FancyOStream > getDefaultOStream()
RCP< VectorBase< Scalar > > createMember(const RCP< const VectorSpaceBase< Scalar > > &vs, const std::string &label="")
Create a vector member from the vector space.
RCP< const LinearOpBase< Scalar > > subtract(const RCP< const LinearOpBase< Scalar > > &A, const RCP< const LinearOpBase< Scalar > > &B, const std::string &label="")
Form an implicit subtraction of two linear operators: M = A - B.
Abstract interface for finite-dimensional dense vectors.
Base class for all linear operators.
RCP< const LinearOpBase< Scalar > > adjoint(const RCP< const LinearOpBase< Scalar > > &Op, const std::string &label="")
Build an implicit const adjoined linear operator.
void randomize(Scalar l, Scalar u, const Ptr< MultiVectorBase< Scalar > > &V)
Generate a random multi-vector with elements uniformly distributed elements.
Teuchos::RCP< const LinearOpBase< Scalar > > block2x2(const Teuchos::RCP< const LinearOpBase< Scalar > > &A00, const Teuchos::RCP< const LinearOpBase< Scalar > > &A01, const Teuchos::RCP< const LinearOpBase< Scalar > > &A10, const Teuchos::RCP< const LinearOpBase< Scalar > > &A11, const std::string &label="")
Form an implicit block 2x2 linear operator [ A00, A01; A10, A11 ].
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.
RCP< const LinearOpBase< Scalar > > identity(const RCP< const VectorSpaceBase< Scalar > > &space, const std::string &label="")
Create an identity linear operator with given a vector space.
TypeTo as(const TypeFrom &t)
#define TEUCHOS_STANDARD_CATCH_STATEMENTS(VERBOSE, ERR_STREAM, SUCCESS_FLAG)
RCP< MultiVectorBase< Scalar > > createMembers(const RCP< const VectorSpaceBase< Scalar > > &vs, int numMembers, const std::string &label="")
Create a set of vector members (a MultiVectorBase) from the vector space.
void set_all_error_tol(const ScalarMag error_tol)
Set all the error tolerances to the same value.
RCP< const LinearOpBase< Scalar > > multiply(const RCP< const LinearOpBase< Scalar > > &A, const RCP< const LinearOpBase< Scalar > > &B, const std::string &M_label="")
Form an implicit multiplication of two linear operators: M = A.