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"
68 template<
class Scalar>
69 int 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> >
135 const RCP<VectorBase<Scalar> > d =
createMember(space2);
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 =
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 =
225 out <<
"\nM10 = " << describe(*M10, verbLevel);
228 const RCP<const LinearOpBase<Scalar> > 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));
268 int 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;
347 #endif // HAVE_TEUCHOS_GNU_MP
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;
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.